;------------------------------------------------------------- ;+ ; NAME: ; GTE_WRITEBIN ; ; PURPOSE: ; Write GTE data in binary format. This routine is ; a caller to WRITE_BDT0001. Information on the LODTYPE ; and LLODVAL of each variable is stored in the data ; coded as negative julian day numbers -1 and -2. ; Information about experiment name, number, revision date, ; and original filename can be stored together with comments. ; ; CATEGORY: ; GTE Tools ; ; CALLING SEQUENCE: ; GTE_WRITEBIN,filename,data,vardesc [,keywords] ; ; INPUTS: ; FILENAME -> A filename or template to select a file or ; preselect the choice in the PICKFILE dialog (see OPEN_FILE) ; ; DATA -> The data array to write (lines,vars) ; ; VARDESC -> A variable descriptor structure list (see ; GTE_VARDESC) ; ; KEYWORD PARAMETERS: ; SELECTION -> A string list of variable names OR an index list ; for variables to be written to the file. Note that variables ; 0-3 (JDAY, STARTHOUR, STARTTIME, STOPTIME) will always be included. ; ; NO_LOD -> Set this keyword if you do not want LOD information ; stored in the file. ; ; EXPERIMENT_NAME -> A string containing the name of the experiment. ; This should not be longer than 40 characters since it will ; be stored together with EXPERIMENT_NUMBER, ORIGINAL_FILE, ; and REVISION_DATE as first comment line. ; ; EXPERIMENT_NUMBER -> number of the experiment or flight number ; ; EXPERIMENT_DATE -> date of experiment ; ; ORIGINAL_FILE -> filename of original ASCII file ; ; REVISION_DATE -> data revision date as contained in the ; file descriptor of a GTE ASCII file. ; ; COMMENTS -> A string (array) with comments to be stored in the ; file. If any of the above four keywords is supplied, it ; will be added to comments as first line. ; ; _EXTRA -> all extra keywords are passed on to WRITE_BDT0001. ; E.g. /PICKFILE, /NO_PICKFILE ; ; OUTPUTS: ; ; SUBROUTINES: ; ; REQUIREMENTS: ; Uses WRITE_BDT0001 which uses OPEN_FILE ; ; NOTES: ; ; EXAMPLE: ; GTE_WRITEBIN,'~/data/*.bdt',data,vardesc ; ; MODIFICATION HISTORY: ; mgs, 28 Aug 1998: VERSION 1.00 ; ;- ; Copyright (C) 1998, Martin Schultz, Harvard University ; This software is provided as is without any warranty ; whatsoever. It may be freely used, copied or distributed ; for non-commercial purposes. This copyright notice must be ; kept with any copy of this software. If this software shall ; be used commercially or sold as part of a larger package, ; please contact the author to arrange payment. ; Bugs and comments should be directed to mgs@io.harvard.edu ; with subject "IDL routine gte_writebin" ;------------------------------------------------------------- pro gte_writebin,filename,data,vardesc,selection=selection,no_lod=no_lod, $ experiment_name=experiment_name, $ experiment_number=experiment_number, $ experiment_date=experiment_date, $ original_file=original_file,revision_date=revision_date, $ comments=comments, $ _EXTRA=e ; caller for WRITE_BDT0001 ; - convert name selection to index asrray ; - special coding for variable's LODTYPE and LLODVAL as ; JDAY = -1 and -2 (1st column always assumed to be JDAY ! ; extract variable names and units from descriptor structure if (not chkstru(vardesc,['name','unit'])) then begin message,'Invalid variable descriptor!',/CONT return endif names = vardesc.name ; Make sure, first four columns contain JDAY, STARTHOUR, STARTSEC, ; and STOPSEC test = ( names[0] eq 'JDAY' AND names[1] eq 'STARTHOUR' AND $ names[2] eq 'STARTSEC' AND names[3] eq 'STOPSEC' ) if (not test) then begin message,'Invalid variables in first 4 columns! Must be '+ $ 'JDAY, STARTHOUR, STARTSEC, STOPSEC.',/CONT return endif ; Create temporary copy of DATA - make sure its FLOAT ; (don't need double !) tmpdat = float(data) ; Extract LOD information no_lod = keyword_set(no_lod) if (not chkstru(vardesc,['lodtype','llodval'])) then no_lod = 1 if (not no_lod) then begin lodtype = vardesc.lodtype llodval = vardesc.llodval message,'LodType and LLodVal extracted.',/INFO ; set special codes in first column (JDAY) lodtype[0] = -1. llodval[0] = -2. ; add lodtype and lodval to temporary data copy tmpdat = [ transpose(lodtype), transpose(llodval), temporary(tmpdat) ] endif ; Test if selection is of type string. If so, convert to index array if ( size(selection,/type) eq 0 ) then $ numsel = make_selection(names,selection,/ONLY_VALID) $ else $ numsel = long(selection) ; Spruce up comments (create first line) com0 = '||' if (n_elements(experiment_name) gt 0) then $ com0 = com0+experiment_name com0 = com0 + '|' if (n_elements(experiment_number) gt 0) then $ com0 = com0+strtrim(experiment_number,2) com0 = com0 + '|' if (n_elements(experiment_date) gt 0) then $ com0 = com0+experiment_date com0 = com0 + '|' if (n_elements(original_file) gt 0) then $ com0 = com0+original_file com0 = com0 + '|' if (n_elements(revision_date) gt 0) then $ com0 = com0+revision_date com0 = com0 + '||' if (strlen(com0) gt 80) then $ message,'File descriptor line too long! Will not be able '+ $ 'to retrieve items.',/INFO ; Make comment line to save or store as first line of comments if (com0 ne '|||||||') then $ if (n_elements(comments) gt 0) then $ scomments = [ com0, comments ] $ else $ scomments = com0 ; Write binary data write_bdt0001,filename,tmpdat,vardesc,selection=selection, $ comments=scomments,_EXTRA=e return end