;+ ; NAME: ; vu_check ; PURPOSE: ; Checks whether file names conforms to the syntax used for output files from ; the tomography programs ; CATEGORY: ; sat/idl/util/vupack ; CALLING SEQUENCE: FUNCTION vu_check, files, times, imark, count=count, marker=marker, $ prefixlen=prefixlen, str_message=str_message, offset=offset ; INPUTS: ; files array; type: string ; list of file names ; OPTIONAL INPUT PARAMETERS: ; prefixlen=prefixlen ; scalar; type: integer; default: 4 ; length of the prefix preceding the Carrington variable in the file ; name (i.e., 4 for 'nv3d2003.1234') ; offset=offset ; scalar; type: ??; default: 0 ; ????? ; OUTPUTS: ; Result status?? ; files array; type: string ; list of file names that conform. File names that don't conform ; are removed from the input list ; times array; type: double ; times coded into the file names (Carrington variablej) ; imark array; type: integer ; marker value coded into file name (for time-dependent tomography ; files only) ; OPTIONAL OUTPUT PARAMETERS: ; count=count scalar; type: integer ; # conforming file names (i.e. size of arrays files, times and imark) ; str_message=str_message ; scalar; type: string ; message describing return status ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, SetFileSpec, GetFileSpec, flt_string, SuperArray ; PROCEDURE: ; MODIFICATION HISTORY: ; OCT-2002, Paul Hick (UCSD/CASS) ; JUN-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added check for names of gzipped files (with .gz extension) ;- InitVar, marker , /key InitVar, prefixlen , 4 ; Length of file name prefix (nv3d, nv3f) InitVar, offset , 0 InitVar, count , n_elements(files) len_marker = 5 ; Length of marker in file type len_fract = 4 ; Length of Carrington fraction in file type ;======================== ; First we check the file name to try to exclude files which do not contain ; tomography data. The test checks whether the file name includes a string of ; type 1234.6789_00001 SetFileSpec, files names = GetFileSpec(part='name') types = GetFileSpec(part='type') ; This should deal with double file types like .0000.gz. tmp = where(types EQ '.gz') IF tmp[0] NE -1 THEN BEGIN SetFileSpec, names[tmp] names[tmp] = GetFileSpec(part='name') types[tmp] = GetFileSpec(part='type') ENDIF ; The marker keyword is set here automatically only if ALL or NONE of the files have markers. tmp = where(strlen(names) GT prefixlen AND strlen(types) EQ 1+len_fract , not_marked) tmp = where(strlen(names) GT prefixlen AND strlen(types) EQ 1+len_fract+1+len_marker, are_marked) CASE count OF not_marked: marker = 0 are_marked: marker = 1 ELSE : InitVar, marker, /key ENDCASE tmp = where(strlen(names) GT prefixlen AND strlen(types) EQ 1+len_fract+(1+len_marker)*marker, count) IF count EQ 0 THEN BEGIN fmtr = '(F'+strcompress(5+len_fract,/rem)+'.'+strcompress(len_fract)+')' fmti = '(I'+strcompress(len_marker ,/rem)+'.'+strcompress(len_marker,/rem)+')' str_message = ', names must match template nv3d'+ $ string(2000.0, format=fmtr)+' or nv3d'+ $ string(2000.0, format=fmtr)+'_'+string(1,format=fmti) ENDIF ELSE BEGIN files = files[tmp] names = names[tmp] types = strmid(types[tmp],1) ; Drop starting dot ;====== ; The following two statements work, but are slow for big string arrays ; Using flt_string on a single array element is faster but assumes that the ; same format can be applied to all array elements. ;iname = flt_string(names) ; # from file names (last number is integer Carrington var ;itype = flt_string(types) ; # from file types (Fraction of Carrington var and marker value ; The prefix could contain numbers. We don't want those. ; In fmt0 the prefix is accounted for by a nX (n=length of prefix). iname = flt_string(strmid(names[0],prefixlen),fmt=fmt0, /xfora, /double) IF prefixlen GT 0 then fmt0 = '('+strcompress(prefixlen,/rem)+'X,'+strmid(fmt0,1) iname = SuperArray(iname, /trail, count) reads, names, format=fmt0, iname itype = flt_string(types[0],fmt=fmt0, /xfora, /double) itype = SuperArray(itype, /trail, count) reads, types, format=fmt0, itype InitVar, iname, [iname], count=1 InitVar, itype, [itype], count=1 iname = reform(iname, n_elements(iname)/count, count, /overwrite) itype = reform(itype, n_elements(itype)/count, count, /overwrite) tmp = where( total(iname, 1, /nan) NE 0 AND (NOT marker OR total(itype,1, /nan) NE 0), count) IF count GT 0 THEN BEGIN files = files[tmp] names = names[tmp] types = types[tmp] iname = iname[*,tmp] itype = itype[*,tmp] sname = size(iname) stype = size(itype) IF marker AND stype[1] EQ 1 THEN BEGIN count = 0 ENDIF ELSE BEGIN icarr = reform(iname[sname[1]-1,*]) ; Integer part of Carrington variable fcarr = reform(itype[0,*]) ; Fraction of Carrington var IF marker THEN imark = reform(itype[1,*]) ; Marker value CASE marker OF 0: tmp = where( finite(icarr) AND finite(fcarr), count) 1: tmp = where( finite(icarr) AND finite(fcarr) AND finite(imark), count) ENDCASE IF count GT 0 THEN BEGIN IF marker THEN imark = round(imark) files = files[tmp] names = names[tmp] types = types[tmp] icarr = icarr[tmp] fcarr = fcarr[tmp] IF marker THEN imark = imark[tmp] fmt0 = strcompress(len_fract, /rem) fmt0 = '(I'+fmt0+'.'+fmt0+')' times = strarr(count) icarr = round(offset+icarr) fcarr = round(fcarr) FOR i=0,count-1,1024 DO BEGIN j = (i+1023) < (count-1) times[i:j] = string(format='(I4.4)',icarr[i:j])+'.'+string(format=fmt0,fcarr[i:j]) ENDFOR tmp = times IF marker THEN BEGIN fmt1 = strcompress(len_marker, /rem) fmt1 = '(I'+fmt1+'.'+fmt1+')' FOR i=0,count-1,1024 DO BEGIN j = (i+1023) < (count-1) tmp[i:j] = tmp[i:j]+'_'+string(format=fmt1,imark[i:j]) ENDFOR ENDIF times = double(times) IF offset EQ 0 THEN BEGIN FOR i=0,count-1 DO names[i] = strmid(names[i], strlen(names[i])-4, 4) names = names+'.'+types tmp = where(tmp EQ names, count) ENDIF IF count GT 0 THEN BEGIN files = files[tmp] times = times[tmp] IF marker THEN imark = imark[tmp] ENDIF ENDIF ENDELSE ENDIF ENDELSE RETURN, count GT 0 & END