;+ ; NAME: ; CMSV_TEST ; ; AUTHOR: ; Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 ; craigm@lheamail.gsfc.nasa.gov ; ; PURPOSE: ; Test the CMSVLIB library ; ; CALLING SEQUENCE: ; CMSV_TEST, FILENAME, USER_VALUE=UVALUE ; ; DESCRIPTION: ; ; CMSV_TEST performs a standard test of the CMSVLIB library. It ; reads and writes a save file using several different methods in an ; attempt to test the different ways that the library can be used. ; The test procedure can be used to verify that the library is ; functioning properly. ; ; By default, this procedure provides standard values to be written, ; but the user can provide one of them with the USER_VALUE keyword. ; If the user's data contains pointers, they must expect tests ; listed under CMSVREAD and CMSVWRITE to fail. ; ; By default the file is written in the current directory, but this ; can be changed with the FILENAME parameter. ; ; This procedure is part of the CMSVLIB SAVE library for IDL by ; Craig Markwardt. You must have the full CMSVLIB core package ; installed in order for this procedure to function properly. ; ; ; ================================================================== ; Research Systems, Inc. has issued a separate license intended ; to resolve any potential conflict between this software and the ; IDL End User License Agreement. The text of that license ; can be found in the file LICENSE.RSI, included with this ; software library. ; ================================================================== ; ; INPUTS: ; ; FILENAME - a scalar string, the output path. ; Default: 'CMSVTEST.SAV' in current directory ; ; KEYWORDS: ; ; USER_VALUE - any IDL variable to be saved, in place of variable ; "C" in the test. ; ; EXAMPLE: ; ; ; SEE ALSO: ; ; CMRESTORE, SAVE, RESTORE, CMSVLIB ; ; MODIFICATION HISTORY: ; Written, 2000 ; Documented, 24 Jan 2001 ; Resolve all routines at start, and add VMS keyword, 14 Feb 2001, CM ; Make version checks with correct precision, 19 Jul 2001, CM ; Added notification about RSI License, 13 May 2002, CM ; Changed test so that 'DEADBEEF'XL is not used, which apparently ; causes problems on 'FL', 01 Aug 2009 ; Add test for strings >127 characters (v1.7), 2012-04-05, CM ; ; $Id: cmsv_test.pro,v 1.11 2012/04/05 20:43:09 cmarkwar Exp $ ; ;- ; Copyright (C) 2000-2001, 2009, 2012, Craig Markwardt ; This software is provided as is without any warranty whatsoever. ; Permission to use, copy, modify, and distribute modified or ; unmodified copies is granted, provided this copyright and disclaimer ; are included unchanged. ;- ; print, '/-------------' cmsavedir, filename, status=status, errmsg=errmsg, n_var=nvar, $ var_names=vnames, types=vtypes, /quiet ; print, '\-------------' if status EQ 0 then begin print, ' ** Failed to read file. Error message follows:' message, errmsg, /info endif else begin if nvar NE 5 then $ message, ' ** Incorrect number of variables' if vnames(0) NE 'A' OR vnames(1) NE 'B' OR vnames(2) NE 'C' $ OR vnames(3) NE 'D' OR vnames(4) NE 'E' then $ message, ' ** Variable names not correct' if total(size(a) NE vtypes(*,0)) NE 0 then $ message, ' ** Variable "A" type incorrect' if total(size(b) NE vtypes(*,1)) NE 0 then $ message, ' ** Variable "B" type incorrect' if total(size(c) NE vtypes(*,2)) NE 0 then $ message, ' ** Variable "C" type incorrect' if total(size(d) NE vtypes(*,3)) NE 0 then $ message, ' ** Variable "D" type incorrect' if total(size(e) NE vtypes(*,4)) NE 0 then $ message, ' ** Variable "E" type incorrect' print, ' ** CMSAVEDIR succeeded' endelse print, '' print, 'Testing CMRESTORE' cmsv_test_unset, a, b, c, d, e print, ' Using IMPLICIT method...', format='(A,$)' cmrestore, filename, status=status, errmsg=errmsg if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' endelse cmsv_test_unset, a, b, c, d, e print, ' Using ARG method...', format='(A,$)' cmrestore, filename, a, b, c, d, e, status=status, errmsg=errmsg, $ /quiet if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' endelse if ver GE 5D then begin cmsv_test_unset, a, b, c, d, e print, ' Using POINTER method...', format='(A,$)' cmrestore, filename, names=['A','B','C','D','E'], $ status=status, errmsg=errmsg, data=data, pass_meth='POINTER', /quiet if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin cmd = ('cmsv_test_comp, *(data(0)), *(data(1)), *(data(2)), '+ $ '*(data(3)), *(data(4)), result, failed') dummy = execute(cmd) if result EQ 0 OR dummy EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' endelse if total(ptr_valid(data)) GT 0 then $ ptr_free, data cmsv_test_unset, a, b, c, d, e print, ' Using POINTER method with reversed names...', format='(A,$)' cmrestore, filename, names=['E','D','C','B','A'], $ status=status, errmsg=errmsg, data=data, pass_meth='POINTER', /quiet if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin cmd = ('cmsv_test_comp, *(data(4)), *(data(3)), *(data(2)), '+ $ '*(data(1)), *(data(0)), result, failed') dummy = execute(cmd) if result EQ 0 OR dummy EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' endelse if total(ptr_valid(data)) GT 0 then $ ptr_free, data endif cmsv_test_unset, a, b, c, d, e print, ' Using STRUCT method...', format='(A,$)' cmrestore, filename, names=['A','B','C','D','E'], $ status=status, errmsg=errmsg, data=data, pass_meth='STRUCT', /quiet, $ version=cmrestore_version if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin cmsv_test_comp, data.(0), data.(1), data.(2), data.(3), data.(4), $ result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' print, ' ... using version '+cmrestore_version endelse print, '' print, 'Testing CMSAVE' cmsv_test_set, a, b, c, d, e print, ' Using ARG method...', format='(A,$)' cmsave, a, b, c, d, e, file=filename, status=status, errmsg=errmsg, $ /quiet, compat=compat, version=cmsave_version if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin restore, filename cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' print, ' ... using version '+cmsave_version endelse if ver GE 5D then begin cmsv_test_set, a, b, c, d, e print, ' Using POINTER method...', format='(A,$)' pheap = [ptr_new(a), ptr_new(b), ptr_new(c), ptr_new(d), ptr_new(e)] cmsave, file=filename, data=pheap, names=['A','B','C','D','E'], $ status=status, errmsg=errmsg, /nocatch if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin restore, filename cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' endelse if total(ptr_valid(pheap)) GT 0 then $ ptr_free, pheap endif cmsv_test_set, a, b, c, d, e print, ' Using UNIT method...', format='(A,$)' cmsave, a, b, c, d, e, file=filename, /useunit, $ status=status, errmsg=errmsg, /quiet, compat=compat if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin restore, filename cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' endelse cmsv_test_set, a, b, c, d, e print, ' Using STRUCT method...', format='(A,$)' pheap = {a:a, b:b, c:c, d:d, e:e} cmsave, file=filename, data=pheap, $ status=status, errmsg=errmsg, /quiet, compat=compat if status EQ 0 then begin print, 'FAILED' message, errmsg, /info endif else begin restore, filename cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' endelse get_lun, unit print, '' print, 'Testing CMSVREAD' cmsv_test_set, a, b, c, d, e sz = size(c) if sz(sz(0)+1) EQ 10 then $ print, ' WARNING: data of type POINTER was found; expect failures!!' print, ' Saving template file...', format='(A,$)' save, a, b, c, d, e, file=filename print, 'done' openr, unit, filename, error=err if err NE 0 then begin print, ' ERROR: could not open '+filename return endif print, ' Reading file with CMSVREAD...', format='(A,$)' cmsvread, unit, a, name='A', /quiet cmsvread, unit, b, name='B', /quiet cmsvread, unit, c, name='C', /quiet cmsvread, unit, d, name='D', /quiet cmsvread, unit, e, name='E', /quiet, status=status close, unit free_lun, unit if status NE 1 then print, 'FAILED' $ else print, 'done' print, ' Checking results...', format='(A,$)' cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' print, '' print, 'Testing CMSVWRITE' openw, unit, filename, error=err, /STREAM ;; STREAM for VMS if err NE 0 then begin print, ' ERROR: could not open '+filename return endif print, ' Writing file...', format='(A,$)' cmsv_test_set, a, b, c, d, e cmsvwrite, unit, a, name='A', /quiet, compat=compat cmsvwrite, unit, b, name='B', /quiet, /NO_END ;; Test this keyword cmsvwrite, unit, c, name='C', /quiet, /NO_END cmsvwrite, unit, d, name='D', /quiet cmsvwrite, unit, e, name='E', /quiet, status=status close, unit if status NE 1 then print, 'FAILED' $ else print, 'done' print, ' Checking results...', format='(A,$)' cmsv_test_unset, a, b, c, d, e restore, filename cmsv_test_comp, a, b, c, d, e, result, failed if result EQ 0 then print, 'FAILED test '+failed $ else print, 'succeeded' end