function writeAd3, filename, data, trailer, data_xyz=dx, write_xyz=dw, force_no_gz=fng, wise_gz=wgz COMPILE_OPT IDL2 ON_ERROR, 2 if n_params() eq 0 then begin print, 'Syntax: writeAd3(filename, data, trailer, reorder=[0/1])' print, 'filename - ad3 file to write to' print, ' data - data cube to write' print, ' trailer - array to put ad3 trailer' print, ' data_xyz - 0: data is received in zxy format' print, ' 1: data is received in xyz format' print, ' default : 0' print, 'write_xyz - 0: data is to be written in zxy format' print, ' 1: data is to be written in xyz format' print, ' default : 0' print, ' WARNING: ADHOC does not support xyz ordered files correctly...' return, -1 endif if n_elements(dx) eq 0 then dx = 0 if n_elements(dw) eq 0 then dw = 0 if dw eq 1 then print, 'WARNING: ADHOC does not support xyz ordered files correctly...' if n_elements(fng) eq 0 then fng=0 if n_elements(wgz) eq 0 then wgz=0 realfilename = filename if n_elements(trailer) eq 0 then begin was_compressed = 0 endif else begin was_compressed = trailer.was_compressed trailer.was_compressed = 0 endelse testgz = strsplit(realfilename, '.', /extract) testgz = testgz[n_elements(testgz)-1] if was_compressed ne 0 then begin if testgz ne 'gz' then begin if wgz eq 1 then begin ; La switch wise_gz signifie que ; si un fichier du nom qu'on veut ; ecrire (*.ad3) existe sous la forme ; *.ad3.gz, on l'ecrit sous forme compressee, ; sinon on le ne compresse pas info = file_info(realfilename + '.gz') if (info.exists eq 1) and (info.write eq 1) then begin realfilename = filename + '.gz' testgz = 'gz' endif else begin was_compressed = 0 testgz = '' endelse endif else begin realfilename = filename + '.gz' testgz = 'gz' endelse endif endif if testgz eq 'gz' then begin was_compressed = 1 if (!version.os_family ne 'unix') or (fng eq 1) then begin was_compressed = 0 testgz = strsplit(realfilename, '.') realfilename = string((byte(realfilename))[0:testgz[n_elements(testgz)-1]-2]) testgz = '' endif endif info = file_info(realfilename) if (info.exists eq 1) and (info.write eq 0) then begin print, 'Not allowed to write to ' + filename return, -1 endif if was_compressed ne 0 then begin openw, unit, realfilename, /get_lun, /compress, /swap_if_big_endian endif else begin openw, unit, realfilename, /get_lun, /swap_if_big_endian endelse if (n_elements(unit) eq 0) then begin print, 'Unable to open ' + realfilename + ' for writing' return, -1 endif if (n_elements(trailer) eq 0) then begin trailer = {ad3_trailer} endif sz = size(data) if sz[0] ne 3 then return, -1 if dx eq 0 then begin trailer.lx = sz[2] trailer.ly = sz[3] trailer.lz = sz[1] endif else begin trailer.lx = sz[1] trailer.ly = sz[2] trailer.lz = sz[3] endelse ; d = data ; switch data to correct order if (dx eq 1) and (dw eq 0) then begin writeu, unit, transpose(data, [2, 0, 1]) endif else if (dx eq 0) and (dw eq 1) then begin writeu, unit, transpose(data, [1, 2, 0]) endif else begin writeu, unit, data endelse ; We modify only data dimensions of ; the trailer. We leave everything else untouched if dw eq 1 then begin trailer.nbdim = -3 endif else begin trailer.nbdim = 3 endelse writeu, unit, trailer free_lun, unit ; if was_compressed then wait, 0.1 ; On attend que gzip termine, sinon ca nous cause des problemes si on relit immediatement trailer.was_compressed = was_compressed return, 0 end