SXI GDS Image Algorithms
Created by Steven M. Hill at Mon Aug 06 15:41:53 2001
add_tag.pro
append_arr.pro
arr2str.pro
bad_pix.pro
boost_array.pro ; Append one array onto a destination array
boost_tag.pro
break_path.pro ; Breaks up a path string into its component directories.
check_fits.pro ; Check that keywords in a FITS header array match the associated data
check_int_time.pro
chklog.pro
concat_dir.pro ; To concatenate directory and file names for current OS.
convolve.pro ; Convolution of an image with a Point Spread Function (PSF)
curdir.pro
dark_db_query.pro
datatype.pro
data_chk.pro
date2mjd.pro
delvarx.pro ; Delete variables for memory management (can call from routines)
deriv_arr.pro ; Procedure to return the rate of change of the
est_db_query.pro
exist.pro
fake_images.pro ; This program generates a solar image and substitutes it for a
find_all_dir.pro ; Finds all directories under a specified directory.
find_with_def.pro ; Searches for files with a default path and extension.
fitshead2struct.pro
flat_fake.pro
fmt_tag.pro ; Converts a data structure (as represented by the IDL SIZE
fxaddpar.pro
fxpar.pro ; Obtain the value of a parameter in a FITS header.
fxparpos.pro
fxposit.pro ; Return the unit number of a FITS file positioned at specified extension
gauss_distr.pro
gettok.pro ; Retrieve the first part of the string up to a specified character
get_delim.pro
get_leap_sec.pro
get_logenv.pro
get_month.pro
get_rid.pro
get_temp_dir.pro
get_utc.pro
head2stc.pro
headfits.pro ; Read a FITS (primary or extension) header into a string array.
host_to_ieee.pro ; Translate an IDL variable from host to IEEE representation
idl_release.pro
id_esc.pro ; To bijectively map character strings to identifiers, allowing
id_esc_init.pro ; Initialize the common blocks used by id_esc and id_unesc
id_unesc.pro ; Convert identifiers escaped with id_esc back into strings.
ieee_to_host.pro ; Translate an IDL variable from IEEE-754 to host representation
image_stats.pro ; Compute statistcs of a floating point image
img_scl.pro
int2utc.pro
isvalid.pro ; Returns validity flag for its argument
is_dir.pro
is_fits.pro
is_ieee_big.pro ; Determine if the current machine is use IEEE, big-endian numbers.
is_member.pro
is_number.pro ; Test string (or array of strings) to see if it is a number
line_noise.pro
long_time_str.pro
make_browse.pro ; Generate byte images for browsing and real-time display.
make_str.pro ; Control dynamic structure building - avoids collision of
match_struct.pro
merge_struct.pro
mod_img.pro
mrd_hread.pro ; Reads a FITS header from an opened disk file or Unix pipe
nint.pro
os_family.pro
path_delimiter.pro
prstr.pro
psf_gaussian.pro ; Create a 1-d, 2-d, or 3-d Gaussian with specified FWHM, center
psf_moffit.pro
readfits.pro ; Read a FITS file into IDL data and header variables.
rem_elem.pro
reverse.pro ; Reverse the order of rows or columns in an array or vector.
since_version.pro
sswfits_struct.pro
str2arr.pro ; Convert delimited string into string array
str2utc.pro
strarrcompress.pro
strep.pro
strjustify.pro
strlastchar.pro
strnumber.pro ; Function to determine if a string is a valid numeric value.
strspecial.pro
strstat.pro
str_checks.pro
str_replace.pro
sun_fake.pro
sxaddpar.pro ; Add or modify a parameter in a FITS header array.
sxdelpar.pro
sxim_despike.pro ; Remove spikes and particle tracks from SXI raw images.
sxim_lincal.pro ; Remove line noise from SXI-M background images.
sxim_prep.pro ; Apply corrections and calibrations to raw images.
sxim_strsplit.pro
sxim_uniq.pro ; Return the subscripts of the unique elements in an array.
sxi_021_hdr.pro ; Convert a Level-0 FITS header to a Level-1 FITS header.
sxi_interp.pro
sxi_make_name.pro
sxi_parse_name.pro
sxi_sxmodpar.pro ; Add or modify a parameter in a FITS header array.
sxpar.pro ; Obtain the value of a parameter in a FITS header
tag_exist.pro
tag_index.pro
tai2utc.pro
test_dir.pro
test_open.pro
tracks.pro
trim.pro ; Converts numbers to strings, without trailing zeros.
utc2int.pro
utc2sec.pro
utc2tai.pro
valid_num.pro
vertical_check.pro
wc_where.pro
where_negzero.pro ; Find positions of IEEE -0.0 values.
writefits.pro ; Write IDL array and header variables to a disk FITS file.
write_dir.pro
;+
; Project : SDAC
;
; Name : ADD_TAG
;
; Purpose : add a tag to a structure
;
; Explanation :
;
; Use : NEW_STRUCT=ADD_TAG(STRUCT,TAG,TAG_NAME)
;
; Inputs : STRUCT = input structure (array or scalar)
; : TAG_VALUE = tag variable to add
; : TAG_NAME = tag name
;
; Opt. Inputs : None.
;
; Outputs : NEW_STRUCT = new structure
;
; Opt. Outputs: None.
;
; Keywords : NAME = new name for structure
; INDEX = index or tag name where to append new tag [def = last]
; ERR = error message [blank if ok]
; DUPLICATE = set to allow duplicate tag names
; TOP_LEVEL = If set, then only the top level is searched to
; determine if the tag already exists.
; NO_COPY = do not make copy of input TAG variable
; (it will be destroyed after input)
;
; Restrictions: Cannot add more than one tag at a time
;
; Side effects: None.
;
; Category : Structure handling
;
; Prev. Hist. : None.
;
; Written : Dominic Zarro (ARC)
;
; Version : Version 1.0, 7 November 1994 -- written
; Version 2.0, 16 June 1996 -- cleaned up
; Version 3, 11-Aug-1997, William Thompson, GSFC
; Added keyword TOP_LEVEL
; Version 4 8-Oct-1998, Zarro (SMA/GSFC) - converted to using
; CREATE_STRUCT
;-
;----------------------------------------------------------------------------
function add_tag_err,val,err
mess='syntax --> NEW_STRUCT=ADD_TAG(STRUCT,TAG_VALUE,TAG_NAME)'
err=mess & message,err,/cont
if exist(val) then return,val else return,0
end
;----------------------------------------------------------------------------
function add_tag,struct,tag_value,tag_name,name=name,index=index,err=err,$
duplicate=duplicate,top_level=top_level,no_copy=no_copy
on_error,1
err=''
if not exist(tag_value) then return,add_tag_err(struct,err)
if datatype(name) ne 'STR' then name=''
;-- just tag value and name entered
new_struct=-1
if (n_params() eq 2) then begin
if (datatype(tag_value) eq 'STR') then begin
if (trim(tag_value) ne '') then begin
if datatype(struct) ne 'STC' then begin
new_struct=create_struct(tag_value,struct,name=name)
goto,done
endif
endif
endif
return,add_tag_err(struct,err)
endif
;-- no tag name was entered
if datatype(tag_name) eq 'STR' then tname=tag_name else tname=''
tname=strtrim(tname(0),2)
if tname eq '' then begin
err='tag name must be non-blank string'
message,err,/cont
if exist(struct) then return,struct else return,0
endif
tname=strupcase(tname)
if n_elements(tname) ne 1 then begin
err='restricted to adding one tag at a time'
message,err,/cont
if exist(struct) then return,struct else return,0
endif
;-- input structure undefined
if (datatype(struct) ne 'STC') and exist(tag_value) then begin
new_struct=create_struct(tname,tag_value,name=name)
goto,done
endif
;-- does tag already exist
idl5=idl_release(lower=5)
if (not keyword_set(duplicate) or idl5) then begin
if datatype(struct) eq 'STC' then begin
if tag_exist(struct,tname,top_level=top_level) then begin
if idl5 then message,'duplicate tag - '+tname+' - not added',/cont
return,struct
endif
endif
endif
;-- determine location of added tag
;+
; Project : SOHO - CDS
;
; Name : APPEND_ARR
;
; Category : Utility
;
; Purpose : Manageable method for concatanating arrays
;
; Syntax : IDL> result=append_arr(input,extra)
;
; Inputs : INPUT = array (or scalar) that requires appending
; EXTRA = array (or scalar) to append
;
; Outputs : concatanated arrays
;
; Keywords : SAME = set to force matching same array types
; NO_COPY = set to not create internal copy of
; INPUT (it will be destroyed)
;
; History : Written: 1-Oct-1998, Zarro (SM&A/GSFC)
; Modified: 26-March-2000, Zarro - sped up with SIZE and CATCH
;
;
; Contact : DZARRO@SOLAR.STANFORD.EDU
;-
function append_arr,input,extra,same=same,no_copy=no_copy
;-- instead of checking each input, just trap any errors
; and bailout gracefully
error=0
catch,error
if error ne 0 then begin
catch,/cancel
goto,cleanup
endif
;-- only do this check if /SAME is set
;+
; Project : SSW
;
; Name : ARR2STR()
;
; Purpose : Convert an array to a delimited string.
;
; Explanation :
;
; Use : IDL> s = arr2str(array,'-')
; s = arr2str(array,delim='-')
;
; Inputs : arr - input data array which is to be converted
; to a simple string.
;
; Opt. Inputs : delim - an alternative positional parameter to specify the
; delimiter.
;
; Outputs : Function returns a simple string using the delimiter to
; separate the elements of the original array.
;
; Opt. Outputs:
;
; Keywords : delimiter - specify the delimiter to be used, default
; delimiter is ','
; trim_str - If set, call STRTRIM when converting to string
; compress - If set, call STRCOMPRESS after converting
; no_duplicate If set, inhibit having string with consecutive
; delimiters such as //
;
; Calls :
;
; Restrictions: None
;
; Side effects: None
;
; Category : Util, string
;
; Prev. Hist. : Sam Freeland 11/19/91
; (Various Slf,MDM,DP mods)
;
; Written : Sam Freeland
;
; Modified : Version 2, William Thompson, GSFC, 15 June 1995
; Added /TRIM keyword to be compatible with Yohkoh
; version. Added /COMPRESS keyword
; Version 2.1, Sam Freeland, SSW merge
; Version 3, Zarro (SAC/GSFC) - added /NO_DUPLICATE &
; renamed TRIM keyword to TRIM_STR to avoid
; name conflict with TRIM function
;
; Version : Version 3
;-
;+
; NAME:
; BOOST_ARRAY
; PURPOSE:
; Append one array onto a destination array
; EXPLANATION:
; Add array APPEND to array DESTINATION, allowing the dimensions of
; DESTINATION to adjust to accomodate it. If both input arrays have the
; same number of dimensions, then the output array will have one
; additional dimension. Otherwise, the last dimension of DESTINATION
; will be incremented by one.
; CATEGOBY:
; Utility
; CALLING SEQUENCE:
; BOOST_ARRAY, DESTINATION, APPEND
; INPUT:
; DESTINATION = Array to be expanded.
; APPEND = Array to append to DESTINATION.
; OUTPUTS:
; DESTINATION = Expanded output array.
; RESTRICTIONS:
; DESTINATION and APPEND have to be either both of type string or both of
; numerical types.
;
; APPEND cannot have more dimensions than DESTINATION.
;
; MODIFICATION HISTOBY:
; Written Aug'88 (DMZ, ARC)
; Modified Sep'89 to handle byte arrays (DMZ)
; Modifed to version 2, Paul Hick (ARC), Feb 1991
; Removed restriction to 2D arrays, William Thompson (ARC), Feb 1992.
; Converted to IDL V5.0 W. Landsman September 1997
;-
;+
; Project : SOHO - CDS
;
; Name : BOOST_TAG
;
; Category : Utility
;
; Purpose : boost a tag value
;
; Explanation : Useful for updating history tags in structures
;
; Syntax : IDL> new_struct=boost_tag(struct,value,tag_name)
;
; Inputs : STRUCT = structure to modify
; TAG_VALUE = value to boost current value
; TAG_NAME = tag name to boost
;
; Outputs : NEW_STRUCT = modified structure
;
; Keywords : ERR = error string
; NAME = optional new name for output structure
; QUIET = don't echo messages
; RECURSE = recursively search for tag name
;
; History : Version 1, 13-April-1997, D.M. Zarro. Written
; Version 2, 29-Sept-2000, Zarro (added /NO_RECURSE)
;
; Contact : DZARRO@SOLAR.STANFORD.EDU
;-
function boost_tag,struct,tag_value,tag_name,name=name,err=err,$
quiet=quiet,no_recurse=no_recurse,$
no_check=no_check
on_error,1
err=''
verbose=1-keyword_set(quiet)
recurse=1-keyword_set(no_recurse)
do_check=1-keyword_set(no_check)
if do_check then begin
if (not exist(tag_value)) or (not is_string(tag_name)) then begin
pr_syntax,'new_struct=boost_tag(struct,tag_value,tag_name)'
if exist(struct) then return,struct else return,0
endif
if n_elements(tag_name) ne 1 then begin
if verbose then message,'restricted to boosting one tag at a time',/cont
if exist(struct) then return,struct else return,0
endif
endif
tags=tag_names(struct) & ntags=n_elements(tags)
;-- create if doesn't exist
if is_string(tag_name) then begin
if not have_tag(struct,tag_name,/exact) then $
return,add_tag(struct,tag_value,tag_name)
str_tag_name=trup(tag_name)
tag_no=get_tag_index(struct,str_tag_name,/valid)
endif else begin
tag_no=get_tag_index(struct,tag_name,/valid,err=err)
if err ne '' then begin
if verbose then message,err,/cont
return,struct
endif
str_tag_name=tags(tag_no)
endelse
new_ver=idl_release(lower=5,/inc)
if new_ver then copier='struct_assign' else copier='copy_struct'
;-- loop thru each structure
nstruct=n_elements(struct)
for i=0,nstruct-1 do begin
new_struct=struct(i)
if recurse then begin
for k=0,ntags-1 do begin
if (k ne tag_no) then begin
if datatype(struct(0).(k)) eq 'STC' then begin
tstruct=boost_tag(new_struct.(k),tag_value,str_tag_name,err=err,$
/no_check)
if err eq '' then begin
new_struct=rep_tag_value(new_struct,tstruct,tags(k),/no_copy,$
/no_check,/no_recurse)
endif
endif
endif
endfor
endif
if tag_no gt -1 then begin
;-- some checks first
old_value=new_struct.(tag_no)
if datatype(old_value) ne datatype(tag_value) then begin
if (datatype(old_value,2) gt 5) or (datatype(tag_value,2) gt 5) then begin
err='new tag value must be of same type as old value'
if verbose then message,err,/cont
return,struct
endif
endif
if datatype(old_value) eq 'STC' then begin
new_value=merge_struct(old_value,tag_value,err=err)
if err ne '' then begin
if verbose then message,err,/cont
return,struct
endif
endif else new_value=[old_value,tag_value]
;-- replace here
err=''
temp_struct=rep_tag_value(new_struct,new_value,str_tag_name,$
err=err,/no_copy,/no_recurse,/quiet)
if err ne '' then begin
if verbose then message,err,/cont
return,struct
endif
new_struct=copy_var(temp_struct)
endif
;-- have to use COPY_STRUCT in case of nested anonymous structures
;+
; NAME:
; BREAK_PATH()
;
; PURPOSE:
; Breaks up a path string into its component directories.
;
; CALLING SEQUENCE:
; Result = BREAK_PATH( PATHS [ /NoCurrent])
;
; INPUTS:
; PATHS = A string containing one or more directory paths. The
; individual paths are separated by commas, although in UNIX,
; colons can also be used. In other words, PATHS has the same
; format as !PATH, except that commas can be used as a separator
; regardless of operating system.
;
; A leading $ can be used in any path to signal that what follows
; is an environmental variable, but the $ is not necessary. (In
; VMS the $ can either be part of the path, or can signal logical
; names for compatibility with Unix.) Environmental variables
; can themselves contain multiple paths.
;
; OUTPUT:
; The result of the function is a string array of directories.
; Unless the NOCURRENT keyword is set, the first element of the array is
; always the null string, representing the current directory. All the
; other directories will end in the correct separator character for the
; current operating system.
;
; OPTIONAL INPUT KEYWORD:
; /NOCURRENT = If set, then the current directory (represented by
; the null string) will not automatically be prepended to the
; output.
;
; PROCEDURE CALLS:
; Functions: DATATYPE(), STR_SEP()
;
; REVISION HISTORY:
; Version 1, William Thompson, GSFC, 6 May 1993.
; Added IDL for Windows compatibility.
; Version 2, William Thompson, GSFC, 16 May 1995
; Added keyword NOCURRENT
; Version 3, William Thompson, GSFC, 29 August 1995
; Modified to use OS_FAMILY
; Version 4, Zarro, GSFC, 4 August 1997
; Added trim to input
; Converted to IDL V5.0 W. Landsman 25-Nov-1997
; Fix directory character on Macintosh system A. Ferro February 2000
;-
;+
; NAME:
; CHECK_FITS
; PURPOSE:
; Check that keywords in a FITS header array match the associated data
; EXPLANATION:
; Given a FITS array IM, and a associated FITS or STSDAS header HDR, this
; procedure will check that
; (1) HDR is a string array, and IM is defined and numeric
; (2) The NAXISi values in HDR are appropriate to the dimensions
; of IM
; (3) The BITPIX value in HDR is appropriate to the datatype of IM
; If HDR contains a DATATYPE keyword (as in STSDAS headers), then this is
; also checked against the datatype of of IM
; If the /UPDATE keyword is present, then FITS header will be modified, if
; necessary, to force agreement with the image array
;
; CALLING SEQUENCE:
; check_FITS, im, hdr, [ dimen, idltype, /UPDATE, /NOTYPE, /SDAS, /SILENT
; ERRMSG = ]'
;
; INPUT PARAMETERS:
; IM - FITS (or STSDAS) array, e.g. as read by READFITS
; HDR - FITS (or STSDAS) header (string array) associated with IM
;
; OPTIONAL OUTPUTS:
; dimen - vector containing actual array dimensions
; idltype- data type of the FITS array as specified in the IDL SIZE
; function (1 for BYTE, 2 for INTEGER*2, 3 for INTEGER*4, etc.)
;
; OPTIONAL KEYWORD INPUTS:
; /NOTYPE - If this keyword is set, then only agreement of the array
; dimensions with the FITS header are checked, and not the
; data type.
; /UPDATE - If this keyword is set then the BITPIX, NAXIS and DATATYPE
; FITS keywords will be updated to agree with the array
; /SDAS - If this keyword is set then the header is assumed to be from
; an SDAS (.hhh) file. CHECK_FITS will then ensure that (1)
; a DATATYPE keyword is included in the header and (2) BITPIX
; is always written with positive values.
; /FITS - If this keyword is present then CHECK_FITS assumes that it is
; dealing with a FITS header and not an SDAS header, see notes
; below.
; /SILENT - If keyword is set and nonzero, the informational messages
; will not be printed
; OPTIONAL KEYWORD OUTPUT:
; ERRMSG = If this keyword is present, then any error messages will be
; returned to the user in this parameter rather than
; depending on the MESSAGE routine in IDL. If no errors are
; encountered, then a null string is returned.
;
; SYSTEM VARIABLE:
; For consistency with previous versions, CHECK_FITS sets the obsolete
; !ERR keyword, although its use is discouraged in favor of the ERRMSG
; keyword. If there is a fatal problem with the FITS array or header
; then !ERR is set to -1. ( If the UPDATE keyword was supplied, and the
; header could be fixed, then !ERR = 0.)
;
; PROCEDURE:
; Program checks the NAXIS1 and NAXIS2 parameters in the header to
; see if they match the image array dimensions.
;
; NOTES:
; An important distinction between an STSDAS header and a FITS header
; is that the BITPIX value in an STSDAS header is always positive,
; e.g. BITPIX=32 for REAL*4 data. Users should use either the /SDAS
; or the /FITS keyword if it is important whether the STSDAS or FITS
; convention for REAL*4 data is used. Otherwise, CHECK_FITS assumes
; that if a DATATYPE keyword is present then it is dealing with an
; STSDAS header.
;
; PROCEDURE CALLS:
; STRN(),SXADDPAR, SXPAR()
; MODIFICATION HISTORY:
; Written, December 1991 W. Landsman Hughes/STX to replace CHKIMHD
; No error returned if NAXIS=0 and IM is a scalar W. Landsman Feb 93
; Fixed bug for REAL*8 STSDAS data W. Landsman July 93
; Make sure NAXIS agrees with NAXISi W. Landsman October 93
; Converted to IDL V5.0 W. Landsman September 1997
; Allow unsigned data types W. Landsman December 1999
; Allow BZERO = 0 for unsigned data types W. Landsman January 2000
; Added ERRMSG keyword, W. Landsman February 2000
;-
;+
; Project : SOHO - CDS
;
; Name : CHECK_INT_TIME
;
; Purpose : Checks CDS internal time values for logical consistency.
;
; Explanation : This procedure checks time values in CDS internal format to
; ensure that the milliseconds of day is neither negative nor
; larger than the number of milliseconds in the day in question.
; If either is true, then the day and time is repaired. Leap
; seconds are taken into account.
;
; This procedure should be called whenever the internal time is
; modified.
;
; Use : CHECK_INT_TIME, INT
;
; Inputs : INT = The UTC date/time as a data structure with the
; elements:
;
; MJD = The Modified Julian Day number
; TIME = The time of day, in milliseconds
; since the start of the day.
;
; Both are long integers.
;
; Opt. Inputs : None.
;
; Outputs : The input array will be repaired to reflect the correct number
; of milliseconds in the day.
;
; Opt. Outputs: None.
;
; Keywords : ERRMSG = If defined and passed, then any error messages
; will be returned to the user in this parameter
; rather than using IDL's MESSAGE utility. If no
; errors are encountered, then a null string is
; returned. In order to use this feature, the
; string ERRMSG must be defined first, e.g.,
;
; ERRMSG = ''
; CHECK_INT_TIME, INT, ERRMSG=ERRMSG
; IF ERRMSG NE '' THEN ...
;
; Calls : DATATYPE, GET_LEAP_SEC
;
; Common : None.
;
; Restrictions: Not valid for dates before 1 January 1972.
;
; This procedure requires a file containing the dates of all leap
; second insertions starting with 31 December 1971. This file
; must have the name 'leap_seconds.dat', and must be in the
; directory given by the environment variable TIME_CONV. It must
; be properly updated as new leap seconds are announced.
;
; Side effects: None.
;
; Category : Utilities, Time.
;
; Prev. Hist. : Based on CHECK_TIME by M. Morrison, LPARL.
;
; Written : William Thompson, GSFC, 29 September 1993.
;
; Modified : Version 1, William Thompson, GSFC, 29 September 1993.
; Version 2, Donald G. Luttermoser, GSFC/ARC, 20 December 1994
; Added the keyword ERRMSG. Added a check for the
; STRUCTURE-TAG names.
; Version 3, Donald G. Luttermoser, GSFC/ARC, 30 January 1995
; Added ERRMSG keyword to internally called procedures.
; Made the error handling routine more robust. Note
; that this procedure can handle both vectors and
; scalars.
; Version 4, William Thompson, GSFC, 28 January 1997
; Allow for long input arrays.
;
; Version : Version 4, 28 January 1997
;-
;+
; Project : SOHO - CDS
;
; Name :
; CHKLOG
; Purpose :
; Determine actual name of logical or environment variable.
; Explanation :
; This routine determines the actual name of a logical name (VMS) or
; environment variable (UNIX). In VMS the routine TRNLOG,/FULL is used;
; otherwise GETENV is used.
; Use :
; Result = CHKLOG( VAR [, OS ] )
; Inputs :
; VAR = String containing the name of the variable to be translated.
; Opt. Inputs :
; None.
; Outputs :
; The result of the function is the translated name, or (in VMS) an array
; containing the translated names.
; Opt. Outputs:
; OS = The name of the operating system, from !VERSION.OS.
; Keywords :
; DELIM = delimiter to use for separating substrings
; FULL = do full translation (VMS only)
; PRESERVE = return input name if no translation found
; Category :
; Utilities, Operating_system.
; Prev. Hist. :
; Written - DMZ (ARC) May 1991
; Modified - DMZ (ARC) Nov 1992, to use GETENV
; Written :
; D. Zarro, GSFC/SDAC, May 1991.
; Modified :
; Version 1, Zarro, ARC/GSFC 23 April 1993.
; Version 2, GSFC, 1 August 1994.
; Added capability for vector inputs
; Version 3, Liyun Wang, GSFC/ARC, January 3, 1995
; Added capability of interpreting the "~" character under UNIX
; Version 4, Zarro, GSFC/ARC, February 17 1997
; Added call to EXPAND_TILDE, corrected many potential bugs
; Version 5, Zarro, GSFC/SAC, June 9 1998
; Added recursive call for environment variables embedded
; in input
; Version 6, Zarro, GSFC/SAC, August 10 1998
; Added recursive call for nested environment variables
; (after RAS broke it)
; Version 7, Zarro, SM&A/GSFC, 16 May 1999
; Added check for "naked" "$" or "~" inputs
; Version 8, Zarro, SM&A/GSFC, 10 June 1999
; Added check for different OS delimiters and made Windows
; friendly
; Version 9, 9-Sep-1999, William Thompson, GSFC
; Fixed bug with TRNLOG,FULL=FULL under version 4 in VMS.
; Version 10, 14-dec-1999, richard.schwartz@gsfc.nasa.gov
; Switched get_path_delim to get_delim and allowed
; both slashes under Windows, '/' and '\'.
; Version 11, 20-Dec-1999, Zarro
; Fixed bug when recursing on delimited input
; Version 12, 07-Mar-2000, William Thompson, GSFC
; Don't translate terminal logical names in VMS, i.e. those which
; end in the characters ".]"
; Version 13, 25-April-2000, Zarro (SM&/GSFC)
; Added another level of recursion for multiply-defined
; env's, i.e., env's defined in terms of other env's, which
; somehow stopped working after version 5.
; e.g., $SSW_HESSI -> $SSW/hessi/idl -> /ssw/hessi/idl
; Version 14, 28-Jul-2000, R.D.Bentley (MSSL)
; Suppress replacement of \\ with \ for windows
; Version 15, 22-Aug-2000, Zarro (EIT/GSFC)
; Removed calls to DATATYPE
;
;-
function chklog,var,os,norecurse=norecurse,delim=delim,full=full,$
preserve=preserve
on_error,1
sz=size(var)
vtype=sz(n_elements(sz)-2)
if vtype ne 7 then begin
message,'undefined input',/contin
if exist(var) then return,var else return,''
endif
preserve=keyword_set(preserve)
recurse=1-keyword_set(norecurse)
full=keyword_set(full)
flim=get_delim()
var=trim(var)
;-- recurse on array inputs
nvar=n_elements(var)
if nvar gt 1 then begin
for i=0,nvar-1 do begin
out=chklog(var(i),os,norecurse=norecurse,delim=delim,full=full,preserve=preserve)
ovar=append_arr(ovar,out,/no_copy)
endfor
return,ovar
endif
;-- parse out delimiters
sz=size(delim)
dtype=sz(n_elements(sz)-2)
if dtype eq 7 then begin
lvar=str2arr(var,delim=delim)
if n_elements(lvar) gt 1 then begin
result=chklog(lvar,os,norecurse=norecurse,full=full,/preserve)
return,arr2str(result,delim=delim)
endif
endif
;-- check OS
os=strlowcase(os_family())
vms=(os eq 'vms')
svar=var
;-- check if recursing on delimited elements in string
; If Windows, then check for possibility of a UNIX delimiter
dvar=var
if os eq 'windows' then dvar=str_replace(dvar,'/',flim)
dvar=str2arr(var,delim=flim)
nt=n_elements(dvar)
if (nt gt 1) and (recurse) then begin
for k=0,nt-1 do begin
temp=chklog(dvar(k),os,full=full,/preserve,norecurse=(k gt 0))
tvar=append_arr(tvar,temp,/no_copy)
endfor
name=arr2str(tvar,delim=flim)
if name eq svar then name=''
goto,done
endif
;-- do VMS check
name=''
if os eq 'vms' then begin
s=execute('v=trnlog(svar,name,full=full)')
if (v mod 2) eq 0 then name=''
if strmid(name,strlen(name)-2,2) eq '.]' then name=''
goto,done
endif
;-- check for preceding $
doll=strpos(svar,'$')
if doll eq 0 then begin
name=trim(getenv(svar))
if name eq '' then begin
tvar=strmid(svar,1,strlen(svar))
name=trim(getenv(tvar))
endif
endif else begin
if recurse then name=trim(getenv(svar))
endelse
;-- finally expand tildes
if os eq 'unix' then begin
if name ne '' then temp=name else temp=svar
tilde=strpos(temp,'~')
if (tilde gt -1) then status=execute('name=expand_tilde(temp)')
endif
done:
if n_elements(name) eq 1 then name=name(0)
name=trim(name)
translated=name(0) ne ''
if preserve and (not translated) then name(0)=var
if (os ne 'windows') and (name ne '') then name=str_replace(name,flim+flim,flim)
;-- check for remaining $
;+
; NAME:
; CONCAT_DIR
;
; PURPOSE:
; To concatenate directory and file names for current OS.
; EXPLANATION:
; The given file name is appended to the given directory name with the
; format appropriate to the current operating system.
;
; CALLING SEQUENCE:
; result = concat_dir( directory, file)
;
; INPUTS:
; directory - the directory path (string)
; file - the basic file name and extension (string)
; can be an array of filenames.
;
; OUTPUTS:
; The function returns the concatenated string. If the file input
; is a string array then the output will be a string array also.
;
; EXAMPLES:
; IDL> pixfile = concat_dir('$DIR_GIS_MODEL','pixels.dat')
;
; IDL> file = ['f1.dat','f2.dat','f3.dat']
; IDL> dir = '$DIR_NIS_CAL'
; IDL> f = concat_dir(dir,file)
;
; RESTRICTIONS:
; Assumes Unix type format if os is not vms, MacOS or Windows.
;
; The version of CONCAT_DIR available at
; http://sohowww.nascom.nasa.gov/solarsoft/gen/idl/system/concat_dir.pro
; includes additional VMS-specific keywords.
;
; CATEGORY
; Utilities, Strings
;
; REVISION HISTORY:
; Prev Hist. : Yohkoh routine by M. Morrison
; Written : CDS version by C D Pike, RAL, 19/3/93
; Version : Version 1 19/3/93
; Documentation modified Nov-94 W. Landsman
; Add V4.0 support for Windows W. Landsman Aug 95
; Converted to IDL V5.0 W. Landsman September 1997
; Changed loops to long integer W. Landsman December 1998
; Added Mac support, translate Windows environment variables,
; & treat case where dirname ends in '/' W. Landsman Feb. 2000
;-
;+
; NAME:
; CONVOLVE
; PURPOSE:
; Convolution of an image with a Point Spread Function (PSF)
; EXPLANATION:
; The default is to compute the convolution using a product of
; Fourier transforms (for speed).
;
; CALLING SEQUENCE:
;
; imconv = convolve( image1, psf, FT_PSF = psf_FT )
; or:
; correl = convolve( image1, image2, /CORREL )
; or:
; correl = convolve( image, /AUTO )
;
; INPUTS:
; image = 2-D array (matrix) to be convolved with psf
; psf = the Point Spread Function, (size < or = to size of image).
;
; OPTIONAL INPUT KEYWORDS:
;
; FT_PSF = passes out/in the Fourier transform of the PSF,
; (so that it can be re-used the next time function is called).
; FT_IMAGE = passes out/in the Fourier transform of image.
;
; /CORRELATE uses the conjugate of the Fourier transform of PSF,
; to compute the cross-correlation of image and PSF,
; (equivalent to IDL function convol() with NO rotation of PSF)
;
; /AUTO_CORR computes the auto-correlation function of image using FFT.
;
; /NO_FT overrides the use of FFT, using IDL function convol() instead.
; (then PSF is rotated by 180 degrees to give same result)
; METHOD:
; When using FFT, PSF is centered & expanded to size of image.
; HISTORY:
; written, Frank Varosi, NASA/GSFC 1992.
; Converted to IDL V5.0 W. Landsman September 1997
;-
;+
; Name: curdir
;
; Purpose: return current directory
;
; Output
; History:
; slf, circa 1-Dec-1992
; slf, 9-mar-1993 ; use cd, not spawn
; slf, 23-jan-1996 ; problem with UNIX 4.01 (which OS??)
; ; use spawn for those...
; slf, 7-nov-1996 ; force output->scalar ("cd" consistent)
;-
;+
;
; 001.001 Modified by SMH 5/3/2001
; Simplified to used MS SQL stored procedure
;-
;+ Name: data_chk
;
; Purpose: checks input data for type, ndimension, etc
; (uses IDL size function results)
;
; Keyword Parameters:
; type - if set, return idl data type (0,1,2..8) from size function
; ndimen - if set, return number dimensions (size(0))
; nimages - if set, return #images (1->2D, NI->3D, else 0)
; xsize - if set, return X size (size(data))(1)
; nx - synonym for xsize
; ysize - if set, return Y size (size(data))(2)
; ny - synonym for ysize
; orr - if set, return value is OR of all boolean flags (def=AND)
; string/struct/undefined - if set, return true if type matches
; scalar, vector - if set, true if data of specified variety
;
; Calling Examples:
; if (data_chk(p1,/type) eq data_chk(p2,/type)) then...
; case data_chk(data,/type) of...
; if data_chk(data,/string,/scalar) then ...
; if data_chk(data,/string,/struct,/undef,/orr)
; case data_chk(maybe_cube,/nimages) of...
;
; History:
; 27-Apr-1993 (SLF)
; 21-Mar-1994 (SLF) documentation header
; 10-oct-1996 (SLF) add SCALAR (synonym for the historical mispell SCALER)
; 2-oct-1997 (SLF) add NIMAGES
; 15-nov-1997 (SLF) add XSIZE and YSIZE keyword and function
;
; Restrictions:
; some keywords are mutually exclusive - for self-documenting code
; and reduction of code duplicataion
;-
;+
; Project : SOHO - CDS
;
; Name : DATE2MJD()
;
; Purpose : Convert calendar dates to Modified Julian Days.
;
; Explanation : This procedure calculates the Modified Julian Day number from
; the year, month and day, or from the year, day-of-year.
;
; Use : Result = DATE2MJD(YEAR, MONTH, DAY)
; Result = DATE2MJD(YEAR, DOY)
;
; Inputs : YEAR = Calendar year, e.g. 1989. All four digits are
; required.
;
; Opt. Inputs : MONTH = Calendar month, from 1-12.
; DAY = Calendar day, from 1-31, depending on the month.
;
; or
;
; DOY = Day-of-year, from 1-365 or 1-366, depending on the
; year.
;
; Either MONTH and DAY, or DOY must be passed.
;
; Outputs : The result of the function is the Modified Julian Day number
; for the date in question. It is an integral number--fractional
; days are not considered.
;
; Opt. Outputs: None.
;
; Keywords : ERRMSG = If defined and passed, then any error messages
; will be returned to the user in this parameter
; rather than being handled by the IDL MESSAGE
; utility. If no errors are encountered, then a null
; string is returned. In order to use this feature,
; the string ERRMSG must be defined first, e.g.,
;
; ERRMSG = ''
; MJD = DATE2MJD ( YEAR, MONTH, DAY, ERRMSG=ERRMSG )
; IF ERRMSG NE '' THEN ...
;
; Calls : DATATYPE
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: If number of parameters sent is invalid, ERRMSG is returned as
; a string array of 2 elements if the keyword ERRMSG is set.
; Also, the result returned has a value of -1.
;
; Category : Utilities, Time.
;
; Prev. Hist. : None. However, part of the logic of this routine is based on
; JDCNV by B. Pfarr, GSFC.
;
; Written : William Thompson, GSFC, 13 September 1993.
;
; Modified : Version 1, William Thompson, GSFC, 13 September 1993.
; Version 2, Donald G. Luttermoser, GSFC/ARC, 20 December 1994.
; Added the keyword ERRMSG. Added test for month to
; make sure a string is not passed. Note that there are
; no internal procedures called that use the ERRMSG
; keyword.
; Version 3, Donald G. Luttermoser, GSFC/ARC, 30 January 1995.
; Made the error handling routine more robust. Note
; this routine can handle both vector and scalar input.
;
; Version : Version 3, 30 January 1995.
;-
;+
; NAME:
; DELVARX
; PURPOSE:
; Delete variables for memory management (can call from routines)
; EXPLANATION:
; Like intrinsic DELVAR function, but can be used from any calling level
;
; CALLING SEQUENCE:
; DELVARX, a [,b,c,d,e,f,g,h,i,j]
;
; INPUTS:
; p0, p1...p9 - variables to delete
;
; RESTRICTIONS:
; Can't use recursively due to EXECUTE function
;
; METHOD:
; Uses EXECUTE and TEMPORARY function
;
; REVISION HISTORY:
; Copied from the Solar library, written by slf, 25-Feb-1993
; Added to Astronomy Library, September 1995
; Converted to IDL V5.0 W. Landsman September 1997
;-
;+
;NAME:
; deriv_arr
;PURPOSE:
; Procedure to return the rate of change of the
; input array
;INPUT:
; inarr - the vector to find the derivative of
;OUTPUT:
; returns - If the input is "n" elements, the
; output is "n-1" elements.
;HISTORY:
; Written 1988 by M.Morrison
; 17-Apr-92 (MDM) - Changed to be a "lindgen"
; 8-Sep-93 (MDM) - Return value as scalar if only one value
;-
;+
; Project : SDAC
;
; Name : EXIST
;
; Purpose : To See if variable Exists
;
; Explanation : So obvious, that explaining it will take more
; lines than the code.
;
; Use : A=EXIST(VAR)
;
; Inputs : VAR = variable name
;
; Opt. Inputs : None.
;
; Outputs : 1/0 if variable exists or not
;
; Opt. Outputs: None.
;
; Keywords : None.
;
; Calls : None.
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: None.
;
; Category : Useful stuff
;
; Prev. Hist. : None.
;
; Written : Dominic Zarro (ARC)
;
; Version : Version 1.0, 18 September 1993
;-
;+
; PROJECT:
; SXI-M Ground Data System - Test Software
;
; NAME:
; FAKE_IMAGES
;
; PURPOSE:
; This program generates a solar image and substitutes it for a
; preprocessor Level-0 FITS file primary data array.
;
; EXPLANATION:
; TBS
;
; CALLING SEQUENCE:
; result=FAKE_IMAGES,file_name,new_fake,replace_file
;
; INPUTS:
; file_name = Level-0 FITS file to have its data array replaced
; new_fake = Flag to indicate whether a new fake image is necessary
; (currently this needs to be true always because of
; a bug in the code)
; replace_file = Flag to indicate whether the FITS input file should
; be overwritten
;
; OUTPUTS:
; result = Fake image array (int, 512x512)
;
; OPTIONAL INPUT KEYWORDS:
; N/A
;
; EXTERNAL CALLS:
; EST_DB_QUERY,index.EXP_INDX,image_type
; HEAD2STC,header (function)
; MOD_IMG,image (function)
; READFITS,input_filename,header,exten_no=exten_no (function)
; STR2UTC,datetime (function)
; SUN_FAKE,size,range=range,fwhm=fwhm,n_freq=n_freq (function)
; WRITEFITS,output_filename,image,header
;
; CALLED BY:
; SXIM_PREP
;
; METHOD:
; TBS
;
; HISTORY:
; 001.001 Written by Steven Hill at NOAA/SEC, 30 Jan 2001
; 001.002 Modified by SMH, 4/4/2001
; Turned into a function that returns the fake image
; array. Allows files to not be overwritten.
; 001.003 Modified by SMH, 4/6/2001
; Bug in included installation package associated (probably)
; with dependencies of IS_FITS.PRO. Removed this function
; as adequate tests for valid files should already be present.
; 001.004 Modified by SMH, 4/10/2001
; Removed file size checker as this is done above SXIM_PREP.PRO
; 001.005 Modified by SMH, 4/10/2001
; Trimmed image_type and added else to case statement
; 001.006 Modified by SMH, 7/10/2001
; Added code for 'de-registration'
;
;-
;+
; NAME:
; FIND_ALL_DIR()
; PURPOSE:
; Finds all directories under a specified directory.
; EXPLANATION:
; This routine finds all the directories in a directory tree when the
; root of the tree is specified. This provides the same functionality as
; having a directory with a plus in front of it in the environment
; variable IDL_PATH.
;
; CALLING SEQUENCE:
; Result = FIND_ALL_DIR( PATH )
;
; PATHS = FIND_ALL_DIR('+mypath', /PATH_FORMAT)
; PATHS = FIND_ALL_DIR('+mypath1:+mypath2')
;
; INPUTS:
; PATH = The path specification for the top directory in the tree.
; Optionally this may begin with the '+' character but the action
; is the same unless the PLUS_REQUIRED keyword is set.
;
; One can also path a series of directories separated
; by the correct character ("," for VMS, ":" for Unix)
;
; OUTPUTS:
; The result of the function is a list of directories starting from the
; top directory passed and working downward from there. Normally, this
; will be a string array with one directory per array element, but if
; the PATH_FORMAT keyword is set, then a single string will be returned,
; in the correct format to be incorporated into !PATH.
;
; OPTIONAL INPUT KEYWORDS:
; PATH_FORMAT = If set, then a single string is returned, in
; the format of !PATH.
;
; PLUS_REQUIRED = If set, then a leading plus sign is required
; in order to expand out a directory tree.
; This is especially useful if the input is a
; series of directories, where some components
; should be expanded, but others shouldn't.
;
; RESET = Often FIND_ALL_DIR is used with logical names. It
; can be rather slow to search through these subdirectories.
; The /RESET keyword can be used to redefine an environment
; variable so that subsequent calls don't need to look for the
; subdirectories.
;
; To use /RESET, the PATH parameter must contain the name of a
; *single* environment variable. For example
;
; setenv,'FITS_DATA=+/datadisk/fits'
; dir = find_all_dir('FITS_DATA',/reset,/plus)
;
; The /RESET keyword is usually combined with /PLUS_REQUIRED.
;
; PROCEDURE CALLS:
; DEF_DIRLIST, FIND_WITH_DEF(), BREAK_PATH()
;
; RESTRICTIONS:
; PATH must point to a directory that actually exists.
;
; On VMS computers this routine calls a command file, FIND_ALL_DIR.COM
; (available only on VMS distribution) to find the directories. This
; command file must be in one of the directories in IDL's standard search
; path, !PATH.
;
; REVISION HISTORY:
; Written : William Thompson, GSFC, 3 May 1993.
; Version 6 William Thompson, GSFC, 20 August 1996
; Version 7, William Thompson, GSFC, 13 February 1998
; Include Windows and MacOS seperators.
; Converted to V5.0, March 1998
;-
;+
; NAME:
; FIND_WITH_DEF()
; PURPOSE:
; Searches for files with a default path and extension.
; EXPLANATION:
; Finds files using default paths and extensions, similar to using the
; DEFAULT keyword with the OPEN statement in VMS. Using this routine
; together with environment variables allows an OS-independent approach
; to finding files.
; CALLING SEQUENCE:
; Result = FIND_WITH_DEF( FILENAME, PATHS [, EXTENSIONS ] )
;
; INPUTS:
; FILENAME = Name of file to be searched for. It may either be a
; complete filename, or the path or extension could be left
; off, in which case the routine will attempt to find the
; file using the default paths and extensions.
;
; PATHS = One or more default paths to use in the search in case
; FILENAME does not contain a path itself. The individual
; paths are separated by commas, although in UNIX, colons
; can also be used. In other words, PATHS has the same
; format as !PATH, except that commas can be used as a
; separator regardless of operating system. The current
; directory is always searched first, unless the keyword
; NOCURRENT is set.
;
; A leading $ can be used in any path to signal that what
; follows is an environmental variable, but the $ is not
; necessary. (In VMS the $ can either be part of the path,
; or can signal logical names for compatibility with Unix.)
; Environmental variables can themselves contain multiple
; paths.
;
; OPTIONAL INPUTS:
; EXTENSIONS = One or more extensions to append to end of filename if the
; filename does not contain one (e.g. ".dat"). The period
; is optional. Multiple extensions can be separated by
; commas or colons.
; OUTPUTS:
; The result of the function is the name of the file if successful, or
; the null string if unsuccessful.
; OPTIONAL INPUT KEYWORDS:
; NOCURRENT = If set, then the current directory is not searched.
;
; RESET = The FIND_WITH_DEF routine supports paths which are
; preceeded with the plus sign to signal that all
; subdirectories should also be searched. Often this is
; used with logical names. It can be rather slow to search
; through these subdirectories. The /RESET keyword can be
; used to redefine an environment variable so that
; subsequent calls don't need to look for the
; subdirectories.
;
; To use /RESET, the PATHS parameter must contain the name
; of a *single* environment variable. For example
;
; setenv,'FITS_DATA=+/datadisk/fits'
; file = find_with_def('test.fits','FITS_DATA',/reset)
;
; EXAMPLE:
;
; FILENAME = ''
; READ, 'File to open: ', FILENAME
; FILE = FIND_WITH_DEF( FILENAME, 'SERTS_DATA', '.fix' )
; IF FILE NE '' THEN ...
;
;
; PROCEDURE CALLS:
; BREAK_PATH(), FIND_ALL_DIR(), STR_SEP()
; REVISION HISTORY:
; Version 1, William Thompson, GSFC, 3 May 1993.
; Removed trailing / and : characters.
; Fixed bugs
; Allow for commas within values of logical names.
; Added keyword NOCURRENT.
; Changed to call BREAK_PATH
; Version 2, William Thompson, GSFC, 3 November 1994
; Made EXTENSIONS optional.
; Version 3, William Thompson, GSFC, 30 April 1996
; Call FIND_ALL_DIR to resolve any plus signs.
; Version 4, S.V. Haugan, UiO, 5 June 1996
; Using OPENR,..,ERROR=ERROR to avoid an IDL 3.6
; internal nesting error.
; Version 5, R.A. Schwartz, GSFC, 11 July 1996
; Use SPEC_DIR to interpret PATH under VMS
; Version 6, William Thompson, GSFC, 5 August 1996
; Took out call to SPEC_DIR (i.e., reverted to version 4). The
; use of SPEC_DIR was required to support logical names defined
; via SETLOG,/CONFINE. However, it conflicted with the ability
; to use logical names with multiple values. Removing the
; /CONFINE made it unnecessary to call SPEC_DIR in this routine.
; Version 7, William Thompson, GSFC, 6 August 1996
; Added keyword RESET
; Converted to IDL V5.0 W. Landsman October 1997
; Use STRTRIM instead of TRIM, W. Landsman November 1998
;-
;+
; Name: fitshead2struct
;
; Purpose: convert FITS header->struct, optionally add useful standard TAGS
;
; Input Parameters:
; head - FITs header array (ex: output from )
; template - use this template structure (after first call, for example)
;
; Keyword Parameters:
; ncomment - set maximum number of COMMENT records expected
; nhistory - set maxinum number of HISTORY records expected
; (default for ncomment and nhistory is acutal# X padding)
; add_standard - if switch, add some standard tags, including
; TIME, DAY, MJD fields (if not present)
; if add_struct is a STRUCTURE, add these fields
;
; Calling Sequence:
; struct=fitshead2struct(header)
; struct=fitshead2struct(header, /add_standard) ; include SSW standards
;
; History:
; 24-feb-1997 - S.L.Freeland - based upon some other SSW routines...
; (inspired by fits_interp.pro by Barry Labonte)
; 27-feb-1997 - improve ADD_STANDARD logic (use tags)
; increased protection against malformed headers
; 9-apr-1997 - Allow user specified structure for ADD_STANDARD
; 19-Jan-1998 - Added id_esc to the tagname conversion -- CED
; 14-Jun-1998 - Added check for error-causing non-numeric structure fields (Zarro, SAC/GSFC)
; 2-Mar-1999 - Use 'id_unesc' in fxpar calls
; 19-mar-1999 - per DMZ, assure predefined tags expand to fit input
; 10-Dec-1999 - S.L.Freeland, per Barry Labonte - fixed logic bug
; which would 'miss' keywords 1 character in length
;
; Motivation:
; use by mreadfits if no structure template is passed
; (to permit vectorized FITS file header operations)
;
; Routines Called:
; fxpar, fxaddpar, make_str, data_chk, sxim_strsplit, str_replace,
; strjustify, fmt_tag, sxim_uniq, rem_elem, prstr, id_esc
;
; Restrictions:
; NEED TO RESOLVE DATE-OBS/DATE_OBS mapping
; (scheduled for 28-feb-1997) (Done, CED 19-Jan-1998)
;-
;+
; NAME:
; FMT_TAG
;
; PURPOSE:
; Converts a data structure (as represented by the IDL SIZE
; its to string representation for dynamic structure building
;
; CALLING SEQUENCE:
; user_value = FMT_TAG( SIZE (data_structure))
;
; INPUTS:
; DSIZE - size vector for desired data structure
;
; RETURN VALUE:
; Character string representing data structure
;
; EXAMPLES:
; if user variable X was created by: FINDGEN(2,3,4,5), then
; then FMT_TAG(SIZE(X)) returns string 'FLTARR(2, 3, 4, 5)'
;
; FILE I/O:
; NONE
;
; COMMON BLOCKS;
; NONE
;
; RESTRICTIONS:
; Structures not yet implemented
;
; MODIFICATION HISTORY:
; Version 1 - SLF, 3/5/91
; 29-Jul-97 (MDM) - Changed the i6 format statement to i8
; because it was ending up with "******"
; 5-Nov-99 - Added new IDL 5.1 types, A. Csillaghy
; csillag@ssl.berkeley.edu
;-
;+
; Name :
; FXADDPAR
; Purpose :
; Add or modify a parameter in a FITS header array.
; Explanation :
; This version of FXADDPAR will write string values longer than 68
; characters using the FITS continuation convention described at
; http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/ofwg_recomm/r13.html
; Use :
; FXADDPAR, HEADER, NAME, VALUE, COMMENT
; Inputs :
; HEADER = String array containing FITS header. The maximum string
; length must be equal to 80. If not defined, then FXADDPAR
; will create an empty FITS header array.
;
; NAME = Name of parameter. If NAME is already in the header the
; value and possibly comment fields are modified. Otherwise a
; new record is added to the header. If NAME is equal to
; either "COMMENT" or "HISTORY" then the value will be added to
; the record without replacement. In this case the comment
; parameter is ignored.
;
; VALUE = Value for parameter. The value expression must be of the
; correct type, e.g. integer, floating or string.
; String values of 'T' or 'F' are considered logical
; values. If the value is a string and is "long"
; (more than 69 characters), then it may be continued
; over more than one line using the OGIP CONTINUE
; standard.
;
; Opt. Inputs :
; COMMENT = String field. The '/' is added by this routine. Added
; starting in position 31. If not supplied, or set equal to ''
; (the null string), then any previous comment field in the
; header for that keyword is retained (when found).
; Outputs :
; HEADER = Updated header array.
; Opt. Outputs:
; None.
; Keywords :
; BEFORE = Keyword string name. The parameter will be placed before the
; location of this keyword. For example, if BEFORE='HISTORY'
; then the parameter will be placed before the first history
; location. This applies only when adding a new keyword;
; keywords already in the header are kept in the same position.
;
; AFTER = Same as BEFORE, but the parameter will be placed after the
; location of this keyword. This keyword takes precedence over
; BEFORE.
;
; FORMAT = Specifies FORTRAN-like format for parameter, e.g. "F7.3". A
; scalar string should be used. For complex numbers the format
; should be defined so that it can be applied separately to the
; real and imaginary parts.
; /NOCONTINUE = By default, FXADDPAR will break strings longer than 68
; characters into multiple lines using the continuation
; convention. If this keyword is set, then the line will
; instead be truncated to 68 characters. This was the default
; behaviour of FXADDPAR prior to December 1999.
; Calls :
; FXPAR(), FXPARPOS()
; Common :
; None.
; Restrictions:
; Warning -- Parameters and names are not checked against valid FITS
; parameter names, values and types.
;
; The required FITS keywords SIMPLE (or XTENSION), BITPIX, NAXIS, NAXIS1,
; NAXIS2, etc., must be entered in order. The actual values of these
; keywords are not checked for legality and consistency, however.
;
; Side effects:
; All HISTORY records are inserted in order at the end of the header.
;
; All COMMENT records are also inserted in order at the end of the
; header, but before the HISTORY records. The BEFORE and AFTER keywords
; can override this.
;
; All records with no keyword (blank) are inserted in order at the end of
; the header, but before the COMMENT and HISTORY records. The BEFORE and
; AFTER keywords can override this.
;
; All other records are inserted before any of the HISTORY, COMMENT, or
; "blank" records. The BEFORE and AFTER keywords can override this.
;
; String values longer than 68 characters will be split into multiple
; lines using the OGIP CONTINUE convention, unless the /NOCONTINUE keyword
; is set. For a description of the CONTINUE convention see
; http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/ofwg_recomm/r13.htm
; Category :
; Data Handling, I/O, FITS, Generic.
; Prev. Hist. :
; William Thompson, Jan 1992, from SXADDPAR by D. Lindler and J. Isensee.
; Differences include:
;
; * LOCATION parameter replaced with keywords BEFORE and AFTER.
; * Support for COMMENT and "blank" FITS keywords.
; * Better support for standard FITS formatting of string and
; complex values.
; * Built-in knowledge of the proper position of required
; keywords in FITS (although not necessarily SDAS/Geis) primary
; headers, and in TABLE and BINTABLE extension headers.
;
; William Thompson, May 1992, fixed bug when extending length of header,
; and new record is COMMENT, HISTORY, or blank.
; Written :
; William Thompson, GSFC, January 1992.
; Modified :
; Version 1, William Thompson, GSFC, 12 April 1993.
; Incorporated into CDS library.
; Version 2, William Thompson, GSFC, 5 September 1997
; Fixed bug replacing strings that contain "/" character--it
; interpreted the following characters as a comment.
; Version 3, Craig Markwardt, GSFC, December 1997
; Allow long values to extend over multiple lines
; Version :
; Version 3, 1 December 1999
;-
;+
; NAME:
; FXPAR()
; PURPOSE:
; Obtain the value of a parameter in a FITS header.
; EXPLANATION:
; The first 8 chacters of each element of HDR are searched for a match to
; NAME. If the keyword is one of those allowed to take multiple values
; ("HISTORY", "COMMENT", or " " (blank)), then the value is taken
; as the next 72 characters. Otherwise, it is assumed that the next
; character is "=", and the value (and optional comment) is then parsed
; from the last 71 characters. An error occurs if there is no parameter
; with the given name.
;
; If the value is too long for one line, it may be continued on to the
; the next input card, using the OGIP CONTINUE convention. For more info,
; http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/ofwg_recomm/r13.html
;
; Complex numbers are recognized as two numbers separated by one or more
; space characters.
;
; If a numeric value has no decimal point (or E or D) it is returned as
; type LONG. If it contains more than 8 numerals, or contains the
; character 'D', then it is returned as type DOUBLE. Otherwise it is
; returned as type FLOAT. If an integer is too large to be stored as
; type LONG, then it is returned as DOUBLE.
;
; CALLING SEQUENCE:
; Result = FXPAR( HDR, NAME [, ABORT, COUNT=, COMMENT=, /NOCONTINUE ] )
;
; Result = FXPAR(HEADER,'DATE') ;Finds the value of DATE
; Result = FXPAR(HEADER,'NAXIS*') ;Returns array dimensions as
; ;vector
; REQUIRED INPUTS:
; HDR = FITS header string array (e.g. as returned by FXREAD). Each
; element should have a length of 80 characters
; NAME = String name of the parameter to return. If NAME is of the
; form 'keyword*' then an array is returned containing values
; of keywordN where N is an integer. The value of keywordN
; will be placed in RESULT(N-1). The data type of RESULT will
; be the type of the first valid match of keywordN found.
; OPTIONAL INPUT:
; ABORT = String specifying that FXPAR should do a RETALL if a
; parameter is not found. ABORT should contain a string to be
; printed if the keyword parameter is not found. If not
; supplied, FXPAR will return with a negative !err if a keyword
; is not found.
; START = A best-guess starting position of the sought-after
; keyword in the header. If specified, then FXPAR
; first searches for scalar keywords in the header in
; the index range bounded by START-PRECHECK and
; START+POSTCHECK. This can speed up keyword searches
; in large headers. If the keyword is not found, then
; FXPAR searches the entire header.
;
; If not specified then the entire header is searched.
; Searches of the form 'keyword*' also search the
; entire header and ignore START.
;
; Upon return START is changed to be the position of
; the newly found keyword. Thus the best way to
; search for a series of keywords is to search for
; them in the order they appear in the header like
; this:
;
; START = 0L
; P1 = FXPAR('P1', START=START)
; P2 = FXPAR('P2', START=START)
; PRECHECK = If START is specified, then PRECHECK is the number
; of keywords preceding START to be searched.
; Default: 5
; POSTCHECK = If START is specified, then POSTCHECK is the number
; of keywords after START to be searched.
; Default: 20
; OUTPUT:
; The returned value of the function is the value(s) associated with the
; requested keyword in the header array.
;
; If the parameter is complex, double precision, floating point, long or
; string, then the result is of that type. Apostrophes are stripped from
; strings. If the parameter is logical, 1 is returned for T, and 0 is
; returned for F.
;
; If NAME was of form 'keyword*' then a vector of values are returned.
;
; OPTIONAL INPUT KEYWORDS:
; /NOCONTINUE = If set, then continuation lines will not be read, even
; if present in the header
; OPTIONAL OUTPUT KEYWORD:
; COUNT = Optional keyword to return a value equal to the number of
; parameters found by FXPAR.
; COMMENTS= Array of comments associated with the returned values.
;
; PROCEDURE CALLS:
; GETTOK(), VALID_NUM
; SIDE EFFECTS:
;
; The system variable !err is set to -1 if parameter not found, 0 for a
; scalar value returned. If a vector is returned it is set to the number
; of keyword matches found.
;
; If a keyword occurs more than once in a header, a warning is given,
; and the first occurence is used. However, if the keyword is "HISTORY",
; "COMMENT", or " " (blank), then multiple values are returned.
;
; NOTES:
; The functions SXPAR() and FXPAR() are nearly identical, although
; FXPAR() has slightly more sophisticated parsing. There is no
; particular reason for having two nearly identical procedures, but
; both are too widely used to drop either one.
;
; REVISION HISTORY:
; Version 1, William Thompson, GSFC, 12 April 1993.
; Adapted from SXPAR
; Version 2, William Thompson, GSFC, 14 October 1994
; Modified to use VALID_NUM instead of STRNUMBER. Inserted
; additional call to VALID_NUM to trap cases where character
; strings did not contain quotation marks.
; Version 3, William Thompson, GSFC, 22 December 1994
; Fixed bug with blank keywords, following suggestion by Wayne
; Landsman.
; Version 4, Mons Morrison, LMSAL, 9-Jan-98
; Made non-trailing ' for string tag just be a warning (not
; a fatal error). It was needed because "sxaddpar" had an
; error which did not write tags properly for long strings
; (over 68 characters)
; Version 5, Wayne Landsman GSFC, 29 May 1998
; Fixed potential problem with overflow of LONG values
; Version 6, Craig Markwardt, GSFC, 28 Jan 1998,
; Added CONTINUE parsing
; Version 7, Craig Markwardt, GSFC, 18 Nov 1999,
; Added START, PRE/POSTCHECK keywords for better performance
;-
;+
; Project : SOHO - CDS
;
; Name :
; FXPARPOS()
; Purpose :
; Finds position to insert record into FITS header.
; Explanation :
; Finds the position to insert a record into a FITS header. Called from
; FXADDPAR.
; Use :
; Result = FXPARPOS(KEYWRD, IEND [, BEFORE=BEFORE ] [, AFTER=AFTER ])
; Inputs :
; KEYWRD = Array of eight-character keywords in header.
; IEND = Position of END keyword.
; Opt. Inputs :
; None.
; Outputs :
; Result of function is position to insert record.
; Opt. Outputs:
; None.
; Keywords :
; BEFORE = Keyword string name. The parameter will be placed before the
; location of this keyword. For example, if BEFORE='HISTORY'
; then the parameter will be placed before the first history
; location. This applies only when adding a new keyword;
; keywords already in the header are kept in the same position.
;
; AFTER = Same as BEFORE, but the parameter will be placed after the
; location of this keyword. This keyword takes precedence over
; BEFORE.
;
; If neither BEFORE or AFTER keywords are passed, then IEND is returned.
;
; Calls :
; None.
; Common :
; None.
; Restrictions:
; KEYWRD and IEND must be consistent with the relevant FITS header.
; Side effects:
; None.
; Category :
; Data Handling, I/O, FITS, Generic.
; Prev. Hist. :
; William Thompson, Jan 1992.
; Written :
; William Thompson, GSFC, January 1992.
; Modified :
; Version 1, William Thompson, GSFC, 12 April 1993.
; Incorporated into CDS library.
; Version :
; Version 1, 12 April 1993.
; Converted to IDL V5.0 W. Landsman September 1997
;-
;+
; NAME:
; FXPOSIT
; PURPOSE:
; Return the unit number of a FITS file positioned at specified extension
; EXPLANATION:
; The FITS file will be ready to be read at the beginning of the
; specified extension.
;
; CALLING SEQUENCE:
; unit=FXPOSIT(FILE, EXT_NO, /READONLY)
;
; INPUT PARAMETERS:
; FILE = FITS file name, scalar string
; EXT_NO = Extension to be moved to, scalar nonnegative integer
;
; RETURNS:
; Unit number of file or -1 if an error is detected.
;
; OPTIONAL KEYWORD PARAMETER:
; /READONLY - If this keyword is set and non-zero, then OPENR rather
; than OPENU will be used to open the FITS file.
;
; COMMON BLOCKS:
; None.
; SIDE EFFECTS:
; Opens and returns the descriptor of a file.
; PROCEDURE:
; Each FITS header is read in and parsed, and the file pointer is moved
; to where the next FITS extension header until the desired
; extension is reached.
; PROCEDURE CALLS:
; FXPAR(), MRD_HREAD, MRD_SKIP
; MODIFICATION HISTORY:
; Derived from William Thompson's FXFINDEND routine.
; Modified by T.McGlynn, 5-October-1994.
; Modified by T.McGlynn, 25-Feb-1995 to handle compressed
; files. Pipes cannot be accessed using FXHREAD so
; MRD_HREAD was written.
; W. Landsman 23-Apr-1997 Force the /bin/sh shell when uncompressing
; W. Landsman 26-May-1997 Non-unix is not just VMS
; T. McGlynn 22-Apr-1999 Add /binary modifier needed for Windows
; T. McGlynn 03-June-1999 Use /noshell option to get rid of processes left by spawn.
; Use findfile to retain ability to use wildcards
; W. Landsman 03-Aug-1999 Use EXPAND_TILDE under Unix to find file
;-
;+
; NAME:
; GETTOK
; PURPOSE:
; Retrieve the first part of the string up to a specified character
; EXPLANATION:
; GET TOKen - Retrieve first part of string until the character char
; is encountered.
;
; CALLING SEQUENCE:
; token = gettok( st, char )
;
; INPUT:
; char - character separating tokens, scalar string
;
; INPUT-OUTPUT:
; st - (scalar) string to get token from (on output token is removed)
;
; OUTPUT:
; token - scalar string value is returned
;
; EXAMPLE:
; If ST is 'abc=999' then gettok(ST,'=') would return
; 'abc' and ST would be left as '999'
;
; HISTORY
; version 1 by D. Lindler APR,86
; Remove leading blanks W. Landsman (from JKF) Aug. 1991
; Converted to IDL V5.0 W. Landsman September 1997
;-
;+
; Project : SOHO - CDS
;
; Name : GET_LEAP_SEC
;
; Purpose : Returns the dates of all known leap seconds.
;
; Explanation : The routine returns the Modified Julian Day number of all known
; leap seconds. The dates are taken from the file
; 'leap_seconds.dat' in the directory given by the environment
; variable TIME_CONV. That file is read in the first time that
; GET_LEAP_SEC is called. These values are then stored in an
; internal common block for subsequent calls. The file is also
; reread whenever the current day number changes.
;
; Use : GET_LEAP_SEC, MJD
;
; Inputs : None.
;
; Opt. Inputs : None.
;
; Outputs : MJD = An array containing the Modified Julian Day numbers
; for all dates on which a leap second was inserted,
; starting with 31 December 1971.
;
; Opt. Outputs: None.
;
; Keywords : ERRMSG = If defined and passed, then any error messages
; will be returned to the user in this parameter
; rather than using the IDL MESSAGE utility. If no
; errors are encountered, then a null string is
; returned. In order to use this feature, the
; string ERRMSG must be defined first, e.g.,
;
; ERRMSG = ''
; GET_LEAP_SEC, MJD, ERRMSG=ERRMSG
; IF ERRMSG NE '' THEN ...
;
; Calls : FIND_WITH_DEF, GET_UTC
;
; Common : LEAP_SECONDS is an internal common block.
;
; Restrictions: This procedure requires a file containing the dates of all leap
; second insertions starting with 31 December 1971. This file
; must have the name 'leap_seconds.dat', and must be in the
; directory given by the environment variable TIME_CONV. It must
; be properly updated as new leap seconds are announced.
;
; Side effects: None.
;
; Category : Utilities, time.
;
; Prev. Hist. : None.
;
; Written : William Thompson, GSFC, 21 September 1993.
;
; Modified : Version 1, William Thompson, GSFC, 21 September 1993.
; Version 2, William Thompson, GSFC, 14 November 1994
; Changed .DAY to .MJD
; Version 3, Donald G. Luttermoser, GSFC/ARC, 20 December 1994
; Added the keyword ERRMSG.
; Version 4, Donald G. Luttermoser, GSFC/ARC, 30 January 1995
; Added ERRMSG keyword to internally called procedures.
; Made the error handling procedures more robust.
; Version 5, William Thompson, GSFC, 15 March 1995
; Changed CDS_TIME to TIME_CONV
; Version 6, Zarro, SM&A/GSFC 6 May 1999
; Added /CONT to MESSAGE
;
; Version : Version 6
;-
;+
; Name: get_logenv
;
; Purpose: provide system independent front end to get_env and trn_log
;
; Input Parameters:
; logenvs - string or string array of vms logicals or unix environments
; (may contain wild cards)
;
; Output Parameters:
; function returns equivilence string/string array
;
; Optional Keyword Parameters:
; outenv - actual environmentals (output) - may differ from logenvs
; if wild cards were used (null if associated env not defined)
;
; Calling Sequence:
; envs=get_logenv(logenvs [,count=count, outenv=outenv,
;
; Calling Examples:
; sfddirs=get_logenv('DIR_SFD*') ; sfd directories
; gendirs=get_logenv('dir_gen*',/case_ignor) ; all DIR_GENxxxxx
; home =get_logenv(/home) ; home directory
; curdir =get_logenv(/curdirq) ; current [same as curdir()]
; ysenvs =get_logenv('ys_*',/environ) ; environmentals form ys_...
; ysflags=get_logenv('ys_*') ; same, only translated value
;
; Optional Keyword Parameters
; count (output) - number of non-null elements returned
; status (output) - boolean success vector (1:match, 0:nomatch)
; outenv (output) - string array - actual environmentals found
; environ(input) - switch - return logical/environ, not translation
; (could be useful if logenvs contains wild card)
; home (input) - switch, if set, return home directory translation
; curdir (input) - if set, return current directory
; case_ignore (input) if set, case INsensitive (only functional in unix)
;
; History:
; slf - 5-apr-1993
; SLF - 13-Jan-1993 (use /noshell on printenv for speed)
; SLF - 16-Jan-1993 (work around for multiple line envs)
; SLF - 30-Mar-1994 fix VMS bug
; DMZ - 20-May-1994 added check for '$' in first character
; SLF - 21-May-1994 added a semicolon to comment (4 man-months effort)
; SLF - 2-Jun-1994 fix (define allenv if wild cards used)
; JSN - 03-Jun-1998 changed loops to long integer
;
; Restrictions:
; if logenvs is an array with one or more elements containg a wild
; card AND more than one env/log satisfies the wildcard, then only
; one match is returned (maintains 1 to 1 correspond between
; input and