pro smei_frm_write, hdri, data, filename, count=count ;+ ; NAME: ; smei_frm_write ; PURPOSE: ; Write SMEI data into nic file ; CATEGORY: ; camera/idl/buf ; CALLING SEQUENCE: ; status = smei_frn_write(hdri, data, filename, count=count) ; INPUTS: ; hdri array[1]; type: frame header structure ; frame header for frame to be written to file ; data array[n,m]; type: unsigned integer (??) ; data to be written ; filename scalar; type: string ; fully-qualified name for output file ; OPTIONAL INPUT PARAMETERS: ; count array[3]; type: integer ; file counters; one or more of the counters are incremented by one ; count[0]: # frames written to disk as .nic or .fits file ; count[1]: # frames skipped because file already exists ; count[2]: # frames with times earlier than the most recent frame ; that are written to disk (these should be frames from the second dump; ; if the second dump contains the same frames as the first the number ; of these frames should be small) ; OUTPUTS: ; count array[3]; type: integer ; updated file counters (only count[0] is updated) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; GetFileSpec, smei_frm_cvhdr ; RESTRICTIONS: ; If /split_dir is set then a 'mkdir --parents' is spawned to to create subdirectories, ; and gzip is spawned to compress files. This will probably work under Linux, but not ; in Windows without some modifications. ; PROCEDURE: ; This thing still needs an I/O error handler ; MODIFICATION HISTORY: ; MAR-2003, Paul Hick (UCSD/CASS) ; MAY-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added explicit check for existence of directory ; and create it if not. ;- cam_dir = GetFileSpec(filename, upto='directory') ; When writing into the SMEI data base the camera subdirectory may not ; exist already. Create it here. IF NOT CheckDir(cam_dir,/silent) THEN BEGIN spawn, 'mkdir '+cam_dir IF NOT CheckDir(cam_dir,/silent) THEN BEGIN message, /info, 'error creating '+hide_env(cam_dir) RETURN ENDIF message, /info, hide_env(cam_dir)+' created' ENDIF CASE GetFileSpec(filename, part='type') OF '.nic': BEGIN ;on_ioerror, cleanup openw, /get_lun, iu, filename writeu, iu, [uint(size(data,/dim)),uint(2),reform(data,n_elements(data))] type = 'buf' ; type = strmid(GetFileSpec(part='name'),2,3) ; if type eq 'frm' then type = 'buf' writeu, iu, byte(type), smei_frm_cvhdr(from_hdr=hdri, /to_byte, length=512-3) ; nic trailer is 512 bytes free_lun, iu ;on_ioerror, NULL END '.fts': BEGIN writefits, filename, data, smei_frm_cvhdr(from_hdr=hdri, /to_fits) END ENDCASE IF IsType(count, /defined) THEN count[0] = count[0]+1 ;return ;cleanup: ;on_ioerror, NULL ;if IsType(iu, /defined) then free_lun, iu ;message, /info, 'write error on '+filename RETURN & END