;+ ; NAME: ; bin_write ; PURPOSE: ; Write array to binary file ; CALLING SEQUENCE: PRO bin_write, File, Array, silent=silent, block=block, trailer=trailer ; INPUTS: ; File string file name ; Array array to be written into binary file `file'. ; By default the array is written into a fixed-length ; file with record length determined by the first ; dimension of the array. If the /block keyword is set, ; then the file is written in VMS block mode. ; OPTIONAL INPUT PARAMETERS: ; /block write in VMS block mode ; OUTPUTS: ; (None) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, SetFileSpec, GetFileSpec, IsType ; RESTRICTIONS: ; PROCEDURE: ; File name extension '.nic': ; ; These are assumed to be files from the SMEI camera. The Array is written to ; file as an unsigned short integer array (irrespective of input type) with the ; proper 6 byte header. It is the users responsibility that the conversion to ; unsigned integer does not have any adverse effects on the array. A 512 byte ; trailer is added using the 'trailer' keyword (padded to 512 bytes with NULL ; characters, or truncated, if necessary). ; ; File name extension '.pph' ; ; The file is written with a header containing the IDL 'size' vector. ; The trailer is added at the end. ; ; In all other cases the array is written using a single binary write statement. ; The trailer is ignored. ; MODIFICATION HISTORY: ; APR-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, silent, 0 InitVar, block , /key SetFileSpec, File ext = strlowcase( GetFileSpec(from='type', upto='type') ) CASE ext OF '.nic': sz = IsType(uint(Array[0]), bytes=bytes, name=name) ELSE : sz = IsType(Array, bytes=bytes, name=name) ENDCASE sz = size(Array) IF NOT silent THEN message, /info, name+ $ ' array A('+strjoin(strcompress(sz[1:sz[0]],/rem),',')+') to '+File CASE block OF 0: openw, /get_lun, iu, File, sz[1]*bytes 1: openw, /get_lun, iu, File, /block ENDCASE CASE ext OF '.nic': BEGIN btrailer = bytarr(512) IF IsType(trailer,/defined) THEN IF strlen(trailer) GT 0 THEN btrailer[0:strlen(trailer)-1] = byte(trailer) writeu, iu, fix([sz[1:sz[0]], bytes]), uint( Array ), btrailer END '.pph': BEGIN IF IsType(trailer,/defined) THEN IF strlen(trailer) GT 0 THEN btrailer = byte(trailer) CASE IsType(btrailer, /defined) OF 0: writeu, iu, sz, Array 1: writeu, iu, sz, Array, btrailer ENDCASE END ELSE: writeu, iu, Array ENDCASE free_lun, iu RETURN & END