;+ ; NAME: ; smei_frm_cp ; PURPOSE: ; Copy SMEI frames from SMEI data base ; CATEGORY: ; ucsd/camera/idl/frm ; CALLING SEQUENCE: PRO smei_frm_cp, trange, destination=destination, unzip=unzip, camera=camera, mkdir=mkdir, _extra=_extra ; INPUTS: ; trange array[2]; type: time structure ; time range to be copied (see href=TimeSet=) ; OPTIONAL INPUT PARAMETERS: ; camera=camera scalar, or array[n] (n=1,2,3); default: [1,2,3] ; cameras to be copied ; /unzip if set files are unzipped ; /mkdir if set then the destination directory specified using ; the'destination' keyword is created if it doesn't exist already ; ; Passed to smei_getfile: ; ; silent=silent controls informational messages ; mode=mode scalar, or array[n] (n=0,1,2); default: none ; if set only the specified modes are selected ; OUTPUTS: ; (none) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType, smei_getfile, CheckDir, GetFileSpec, do_file, hide_env ; RESTRICTIONS: ; Files are copied in groups of typically about 4000 frames at a time. ; See href=do_file= for more details. The limitation arises from a restriction ; on the length of a shell command (usually 128 kB). ; PROCEDURE: ; > Files for camera 1 are copied into subdirectory c1 of destination ; directory (the subdirectory is created if it does not exist yet). ; Same for cameras 2 and 3. ; > Specifying the mode keyword requires that file headers need to be read ; to determine the mode (the camera number is coded into the file name). ; This slows down the copy operation considerably. ; EXAMPLES: ; Copy files for cameras 1 and 2 from between 0 UT on doy 110 to 0 UT on doy 115 ; for 4x4 binning (mode 2) to the $TUB directory: Unzip files after copy ; is complete. ; ; tt = TimeSet(yr=2004,doy=[110,115]) ; smei_frm_cp, tt,destination=getenv('TUB'), /unzip, camera=[1,2], mode=2 ; ; ; Copy all frames for the specified time period for all cameras to ; '/zulu/zone/2003_110_115', creating the subdirectory 2003_110_115 if it ; doesn't exist already; suppress informational messages: ; ; tt = TimeSet(yr=2004,doy=[110,115]) ; smei_frm_cp, tt,destination=getenv('TUB'), /unzip, silent=1 ; ; See href=TimeSet= for other ways to specify begin and end time. ; MODIFICATION HISTORY: ; JUL-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, camera , [1,2,3] InitVar, unzip , /key InitVar, destination, '' InitVar, mkdir , /key IF destination EQ '' THEN BEGIN message, /info, 'no destination directory specified' RETURN ENDIF IF strupcase(destination) EQ 'CURRENT' then begin cd, current=destination message, /info, 'copy to '+hide_env(destination) ENDIF uday = TimeUnit(/day) usec = TimeUnit(/sec) CASE IsTime(trange) OF 0: BEGIN IF NOT CheckDir(destination) THEN BEGIN message, /info, 'destination does not exist: '+hide_env(destination) RETURN ENDIF files = smei_getfile(trange, count=count, _extra=_extra) IF do_file(/copy, files, destination, _extra=_extra) THEN BEGIN list = filepath(root=destination, 'file_list.txt') openw, /get_lun, iu, list, /append printf, iu, strjoin(filepath(root=destination, GetFileSpec(files, part='name')), string(10B)) free_lun, iu ENDIF END 1: BEGIN ndays = TimeGet( TimeGet(trange, /bot, uday), uday, /full) FOR n=0L,n_elements(camera)-1 DO BEGIN ; Loop over cameras cam = camera[n] list = filepath(root=destination, 'file_list_cam'+strcompress(cam,/rem)+'.txt') ; Create destination directories if necessary ; The top directory 'destination' is created only if /mkdir is set. subdir = filepath( root=destination, 'c'+strcompress(cam,/rem) ) IF NOT CheckDir(subdir) THEN BEGIN spawn, 'mkdir '+(['','-p'])[mkdir]+' '+subdir IF NOT CheckDir(subdir) THEN BEGIN message, /info, 'error creating '+hide_env(subdir) RETURN ENDIF message, /info, 'created '+hide_env(subdir) ENDIF FOR day=ndays[0],ndays[1] DO BEGIN ; Loop over days ; Set up time range needed in each day (the first and last day may ; be only a fraction of a day). CASE 1 OF day EQ ndays[0] and day eq ndays[1]: tt = trange ; Whole time rangee in one day day EQ ndays[0]: tt = [trange[0], TimeSet(day+1,uday)] ; 1st day: start time to end of day day EQ ndays[1]: tt = [TimeSet(day,uday), trange[1]] ; last day: start of day to end time ELSE: tt = TimeSet(day+[0,1],uday) ; Whole day ENDCASE IF TimeOp(/subtract, tt[0],tt[1],uday) ne 0 then begin ; Make sure time range is not empty files = smei_getfile( tt, camera=cam, count=count, _extra=_extra ) IF count GT 0 THEN BEGIN ; # files found in time interval ; Copy files to destination, and, if successful append name to list. IF do_file(/copy, files, subdir, _extra=_extra) THEN BEGIN openw, /get_lun, iu, list, /append printf, iu, strjoin(filepath(root=subdir, GetFileSpec(files, part='name')), string(10B)) free_lun, iu ENDIF ENDIF ENDIF ENDFOR IF unzip THEN BEGIN message, /info, 'gunzip -rf '+hide_env(subdir) spawn, 'gunzip -rf '+subdir ENDIF ENDFOR END ENDCASE RETURN & END