;+ ; NAME: ; vu_write ; PURPOSE: ; Write tomography t3d* or b3d* file ; CATEGORY: ; Tomography: I/O ; CALLING SEQUENCE: PRO vu_write, in_hdr, in_ff , $ userinfo = userinfo , $ destination = destination , $ silent = silent , $ gzip = gzip ; INPUTS: ; in_hdr ; in_ff ; OPTIONAL INPUT PARAMETERS: ; destination=destination ; scalar; type: string ; destination directory for output file ; /gzip compresses output files with gzip ; userinfo ; OUTPUTS: ; See PROCEDURE ; OPTIONAL OUTPUT PARAMETERS: ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType, CarringtonT, TimeGet, TimeSystem, TimeUnit ; vu_filename, vu_get, gzip_file, hide_env ; SIDE EFFECTS: ; RESTRICTIONS: ; SEE PROCEDURE ; EXAMPLE: ; PROCEDURE: ; The file name specified in in_hdr.file is ignored (usually ; it is a blank string anyway). The filename is build from the ; destination keywords in combination with the time hdr.time, ; hdr.marker and hdr.prefix ; MODIFICATION HISTORY: ; MAR-2001, Paul Hick (UCSD/CASS) ; JUL-2002, Paul Hick (UCSD/CASS) ; V1.03; added nl, nlos, dlos and binx ; NOV-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added /gzip keyword. ; Also added a trick to avoid having two tomography files ; for the same time present in the directory while the ; new file is being written. ;- InitVar, silent, /key InitVar, gzip , /key hdr = in_hdr ff = in_ff IF IsType(destination, /undef) THEN BEGIN message, /info, 'no destination directory specified' RETURN ENDIF ;CASE finite(hdr.bad) OF ;0: Bad = -9999.9990 ;1: Bad = hdr.bad ;ENDCASE Bad = -9999.9990d0 cBad = string(Bad, format='(F10.4)') cFmt = '(F9.4)' hdr.file = vu_filename(hdr.prefix,hdr.uttime,marker=hdr.marker,root=destination,format=cFmt) NCoff = floor((vu_get(hdr,/array))[0]) itt =[vu_get(hdr, /time_index), vu_get(hdr, /ntim)] nltot = vu_get(hdr, /nltot) nlos = vu_get(hdr, /nlos) dlos = vu_get(hdr, /dlos) binx = vu_get(hdr, /binx) chdr = [ hdr.file+' created on ' + TimeGet( TimeSystem(/silent), /vms), $ 'Bad value flag: ' + cBad, $ 'T3D_header, v1.04 IDL', $ 'File name prefix: ' + vu_get(hdr, /prefix), $ 'Carrington offset: ' + strcompress(NCoff, /rem), $ 'Carrington time: ' + TimeGet(vu_get(hdr,/uttime),/ydoy), $ 'Carrington limits of array (start/end): ' + strjoin(strcompress(string(vu_get(hdr,/array )-NCoff, format=cFmt),/rem), ' '),$ 'Carrington limits of region of interest (start/end): ' + strjoin(strcompress(string(vu_get(hdr,/roi )-NCoff, format=cFmt),/rem), ' '),$ 'Carrington start time: ' + strcompress(string(vu_get(hdr,/start_time)-NCoff, format=cFmt),/rem),$ 'Carrington time resolution: ' + strcompress(vu_get(hdr,/time_step), /rem), $ 'Carrington forecast time: ' + TimeGet(vu_get(hdr,/forecast_time),/ydoy), $ 'Latitude range (degrees): ' + strjoin(strcompress(vu_get(hdr,/latitude_range,/degrees), /rem), ' '), $ 'Radial reference distance (AU): ' + strcompress(vu_get(hdr,/start_distance), /rem), $ 'Radial resolution (AU): ' + strcompress(vu_get(hdr,/distance_step ), /rem), $ 'Power index of density dependence of density fluctuations (V-data,G-data): ' + $ strjoin(strcompress(vu_get(hdr,/power_density) , /rem), ' '), $ 'Power index of radial dependence of density fluctuations (V-data,G-data): ' + $ strjoin(strcompress(vu_get(hdr,/power_distance), /rem), ' '), $ 'Density at 1 AU (cm^-3): ' + strcompress(vu_get(hdr,/density_at_1AU), /rem), $ 'Spatial filters for smoothing velocity and density (degrees): '+ $ strjoin(strcompress(vu_get(hdr,/smooth_filter,/degrees), /rem), ' '), $ 'Spatial filters for filling velocity and density (degrees): ' + $ strjoin(strcompress(vu_get(hdr,/fill_filter,/degrees), /rem), ' '), $ 'Temporal filters for velocity and density (days): ' + strjoin(strcompress(vu_get(hdr,/time_filter) , /rem), ' '), $ 'Clip longitude (degrees): ' + strcompress(vu_get(hdr,/clip_long,/degrees), /rem), $ 'Dimensions (nLng,nLat,nRad,nTim): ' + strjoin(strcompress(vu_get(hdr,/dimension) , /rem), ' '), $ 'Iteration: ' + strjoin(strcompress(vu_get(hdr,/iteration) , /rem), '/'), $ 'Time index: ' + strjoin(strcompress(itt, /rem), '/') , $ '# Velocity lines of sight: ' + strcompress(nltot[0] , /rem) , $ '# G-level lines of sight: ' + strcompress(nltot[1] , /rem) , $ '# Line-of-sight segments for velocity: ' + strcompress(nlos [0] , /rem) , $ '# Line-of-sight segments for g-level: ' + strcompress(nlos [1] , /rem) , $ 'Line-of-sight resolution for velocity: ' + strcompress(dlos [0] , /rem) , $ 'Line-of-sight resolution for g-level: ' + strcompress(dlos [1] , /rem) , $ '# segments/bin for velocity: ' + strcompress(binx [0] , /rem) , $ '# segments/bin for density: ' + strcompress(binx [1] , /rem) , $ 'Linear scaling constants: ' + strjoin(strcompress((vu_get(hdr,/scale ))[*] , /rem), ' '),$ 'Power for radial normalization: ' + strjoin(strcompress(vu_get(hdr,/power_norm), /rem), ' '), $ 'Rotation counter: ' + strcompress(vu_get(hdr, /marker), /rem) ] IF vu_get(hdr,/user_info) ne '' THEN chdr = [chdr, 'User: '+vu_get(hdr,/user_info)] IF IsType(userinfo,/defined) THEN chdr = [chdr, 'User: '+userinfo] IF vu_get(hdr, /plasma ) THEN ctype = 'Velocity (km s^-1)/normalized density (cm^-3)' IF vu_get(hdr, /magnetic) THEN ctype = 'Radial (r^2*B_r)/tangential (r*B_t) magnetic field' chdr = '; '+[chdr, ctype] tmp = where( finite(ff) EQ 0 ) IF tmp[0] NE -1 THEN ff[tmp] = Bad fmt = '('+strcompress(vu_get(hdr,/nlng),/rem)+'F10.4)' file = vu_get(hdr, /file) ; The '*' should intercept gzipped files also. update = (['','u'])[(file_search(file+'*'))[0] ne ''] ; 'u' = updated IF NOT silent THEN message, /info, $ hide_env(file)+' ('+TimeGet(vu_get(hdr,/uttime),/ymd,upto=TimeUnit(/minute))+')'+update ; The file written is an unzipped file. It is possible that an earlier copy of the same ; file in zipped form already exists in the destination directory. To avoid having two files ; present (the old zipped and the new unzipped version) a prefix is added temporarily, that ; effectively makes the new file an invalid tomography file. ; After the new file has been zipped, the file is renamed by removing the prefix. At this ; point the old zipped file is overwritten by the new zipped file. IF gzip THEN BEGIN status = gzip_file(file, new_file, /nozip) file = filepath(root=destination,'_gzip_'+GetFileSpec(file,from='name')) ENDIF openw, /get_lun, iu, file FOR i=0,n_elements(chdr)-1 DO printf, iu, chdr[i] printf, iu, format=fmt, ff free_lun, iu IF gzip THEN $ IF gzip_file(file, zipfile) THEN $ status = do_file(/move, zipfile, new_file, /silent) RETURN & END