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

add_tag.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

append_arr.pro

;+
; 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

arr2str.pro

;+
; 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
;-

bad_pix.pro



boost_array.pro

;+
; 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
;-

boost_tag.pro

;+
; 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

break_path.pro

;+
; 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
;-

check_fits.pro

;+
; 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
;-

check_int_time.pro

;+
; 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
;-

chklog.pro

;+
; 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 $

concat_dir.pro

;+
; 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
;-

convolve.pro

;+
; 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
;-

curdir.pro

;+
; 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)
;-

dark_db_query.pro

;+
;
; 001.001 Modified by SMH 5/3/2001
; Simplified to used MS SQL stored procedure
;-

datatype.pro



data_chk.pro

;+ 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
;-

date2mjd.pro

;+
; 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.
;-

delvarx.pro

;+
; 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
;-

deriv_arr.pro

;+
;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
;-

est_db_query.pro



exist.pro

;+
; 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
;-

fake_images.pro

;+
; 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'
;
;-

find_all_dir.pro

;+
; 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
;-

find_with_def.pro

;+
; 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
;-

fitshead2struct.pro

;+
; 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)
;-

flat_fake.pro



fmt_tag.pro

;+
; 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
;-

fxaddpar.pro

;+
; 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
;-

fxpar.pro

;+
; 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
;-

fxparpos.pro

;+
; 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
;-

fxposit.pro

;+
; 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
;-

gauss_distr.pro



gettok.pro

;+
; 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
;-

get_delim.pro



get_leap_sec.pro

;+
; 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
;-

get_logenv.pro

;+
; 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
; Does not yet handle multiple line environmentals (1st line returned)
;-
env=keyword_set(environ)

sav_logenvs=logenvs ;-- save inputs to avoid clobbering

;-- remove '$' in first character so that UNIX getenv/printenv

get_month.pro

;+
; Project : HESSI
;
; Name : GET_MONTH
;
; Purpose : get month name
;
; Category : utility date time
;
; Syntax : month=get_month(id)
;
; Inputs : ID = month number (0 for Jan, 1 for Feb, etc)
; or month name (Jan, Feb, etc)
;
; Outputs : MONTH = string month corresponding to ID
; or month number corresponding to month
;
; Keywords : TRUNCATE = truncate to 3 characters
;
; History : Written 6 Jan 1999, D. Zarro (SM&A/GSFC)
;
; Contact : dzarro@solar.stanford.edu
;-

get_rid.pro

;+
; Project : HESSI
;
; Name : GET_RID
;
; Purpose : return a random ID
;
; Category : system utility
;
; Explanation : uses combination of current time and random function
;
; Syntax : IDL> id=get_rid()
;
; Inputs : None
;
; Outputs : ID = random id
;
; Keywords : /TIME = include a time part
;
; History : 29-Nov-1999, Zarro (SM&A/GSFC), written
;
; Contact : dzarro@solar.stanford.edu
;-

get_temp_dir.pro

;+
; Project : HESSI
;
; Name : GET_TEMP_DIR
;
; Purpose : return system dependent temporary directory
;
; Category : system utility
;
; Explanation :
;
; Syntax : IDL> temp=get_temp_dir()
;
; Outputs : TEMP = temporary directory pertinent to OS
;
; History : Version 1, 25-May-1999, D.M. Zarro (SM&A/GSFC), Written
; 17 April 2000, Zarro (SM&A/GSFC) - added alternative WINXX
; temporary directory choices
;
; Contact : DZARRO@SOLAR.STANFORD.EDU
;-


function get_temp_dir,dummy,reset=reset

common get_temp_dir,temp_dir

if keyword_set(reset) then delvarx,temp_dir
if exist(temp_dir) then return,temp_dir

;-- search logical places for temp directory
choices=['user_tmp','/tmp',curdir(),'c:\tmp','c:\temp','c:\windows\temp',$
'c:\windows\tmp','c:\winnt\tmp','c:\winnt\temp','tmp','temp','home','SYS$SCRATCH']
;return,'GET_TEMP_DIR:'+string(n_elements(choices))
;end
;pro tslsl

;for i=0,n_elements(choices)-1 do begin
; chk=test_dir(choices(i),out=tdir,/quiet)
; if chk then begin
; temp_dir=tdir & return,temp_dir
; endif
;endfor

;-- some defaults in case above fails

get_utc.pro

;+
; Project : SOHO - CDS
;
; Name : GET_UTC
;
; Purpose : Gets the current date/time in UTC.
;
; Explanation : This procedure uses the IDL SYSTIME() function to calculate
; the current UTC date/time, and formats it into one of the CDS
; standard UTC time formats. For notes on various time formats,
; see file aaareadme.txt.
;
; Use : GET_UTC, UTC
; GET_UTC, UTC, /EXTERNAL
; GET_UTC, UTC, /CCSDS
; GET_UTC, UTC, /ECS
;
; Inputs : None.
;
; Opt. Inputs : None.
;
; Outputs : UTC = The UTC current calendar time in one of several formats,
; depending on the keywords passed.
;
; Internal: A structure containing the tags:
;
; MJD: The Modified Julian Day number.
; TIME: The time of day, in milliseconds since
; the beginning of the day.
;
; Both are long integers. This is the default
; format.
;
; External: A structure containing the integer tags
; YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, and
; MILLISECOND.
;
; CCSDS: An ASCII string containing the UTC time to
; millisecond accuracy in the format
; recommended by the Consultative Committee
; for Space Data Systems (ISO 8601), e.g.
;
; "1988-01-18T17:20:43.123Z"
;
; ECS: Similar to CCSDS, except that the date has
; the format:
;
; "1988/01/18 17:20:43.123"
;
; VMS: The date and time has the format
;
; "18-JAN-1988 17:20:43.123"
;
; STIME: The date and time has the format
;
; "18-JAN-1988 17:20:43.12"
;
; See UTC2STR for more information
;
; Opt. Outputs: None.
;
; Keywords : EXTERNAL = If set, then the output is in external format, as
; explained above.
;
; CCSDS = If set, then the output is in CCSDS format, as
; explained above.
;
; ECS = If set, then the output is in ECS format, as
; explained above.
;
; VMS = If set, then the output will be in VMS format, as
; described above.
;
; STIME = If set, then the output will be in STIME format, as
; described above.
;
; The following keywords are only valid if one of the string
; formats is selected.
;
; TRUNCATE = If set, then the time will be truncated to 1 second
; accuracy. Note that this is not the same thing as
; rounding off to the nearest second, but is a
; rounding down.
;
; DATE_ONLY = If set, then only the date part of the string is
; returned.
;
; TIME_ONLY = If set, then only the time part of the string is
; returned.
;
; UPPERCASE = If set, then the month field in either the VMS or
; STIME format is returned as uppercase.
;
; NOZ = When set, the "Z" delimiter (which denotes UTC
; time) is left off the end of the CCSDS/ISO-8601
; string format. It was decided by the FITS
; committee to not append the "Z" in standard FITS
; keywords.
;
; The following keyword is always valid.
;
; 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_UTC, UTC, ERRMSG=ERRMSG
; IF ERRMSG NE '' THEN ...
;
;
; Calls : INT2UTC
;
; Common : Uses the internal common block LOCAL_DIFF to store information
; between calls. This common block is shared with the routine
; LOCAL_DIFF.
;
; Restrictions: This routine depends on the behavior of IDL's SYSTIME function.
; Currently, it is believed that this routine will return the
; time in UTC on all properly configured Unix systems. However,
; the result may be different in other operating systems; e.g. on
; VMS and MacIntosh computers it gives the local time instead.
; It is believed to work correctly in IDL for Windows.
;
; In order to get around this difficulty, the file
; "local_diff.dat" can be placed in the directory given by the
; environment variable TIME_CONV. If this file exists, then this
; program will read the value (local-UTC in hours) from this file
; and use it as a correction factor. For example, for U.S.
; Eastern Standard Time, this file would contain the value -5.
; (See local_diff.pro for more information.) This means then,
; that this file must contain the correct value, and must be
; updated to reflect changes between standard and daylight
; savings time.
;
; On the other hand, if the second line in the "local_diff.dat"
; file reads "GMT", then it is assumed that the computer is
; running on GMT instead of local time, and no correction is
; made.
;
; The file local_diff.dat is only read once. The contents are
; stored in a common block between calls. Once a day, the file
; is reread.
;
; The accuracy of the time returned by this routine depends on
; that of the computer's system clock.
;
; Side effects: None.
;
; Category : Utilities, time.
;
; Prev. Hist. : None. However, the concept of "internal" and "external" time
; is based in part on the Yohkoh software by M. Morrison and G.
; Linford, LPARL.
;
; Written : William Thompson, GSFC, 21 September 1993.
;
; Modified : Version 1, William Thompson, GSFC, 21 September 1993.
; Version 2, William Thompson, GSFC, 3 November 1994
; Added test for "local_diff.dat" file.
; Version 3, William Thompson, GSFC, 14 November 1994
; Added test for "GMT" line in "local_diff.dat" file
; Changed .DAY to .MJD
; Version 4, William Thompson, GSFC, 17 November 1994
; Fixed bug introduced in version 3
; Version 5, William Thompson, GSFC, 20 December 1994
; Added keywords TRUNCATE, DATE_ONLY, TIME_ONLY
; Version 6, Donald G. Luttermoser, GSFC/ARC, 20 December 1994
; Added the keyword ERRMSG.
; Version 7, William Thompson, GSFC, 25 January 1995
; Changed to call intrinsic ROUND instead of NINT. The
; version of NINT in the Astronomy User's Library doesn't
; automatically select between short and long integers as
; the CDS version does.
; Version 8, Donald G. Luttermoser, GSFC/ARC, 30 January 1995
; Added ERRMSG keyword to internally called procedures.
; Made the error handling procedures more robust.
; Version 9, William Thompson, GSFC, 14 March 1995
; Added keywords VMS, STIME, UPPERCASE
; Version 10, William Thompson, GSFC, 15 March 1995
; Changed CDS_TIME to TIME_CONV
; Version 11, William Thompson, GSFC, 2 June 1997
; Store information between calls in common block.
; Version 12, William Thompson, GSFC, 17 September 1997
; Added keyword NOZ.
;
; Version : Version 12, 17-Sep-1997
;-

head2stc.pro

;+
; Project : SOHO-CDS
;
; Name : HEAD2STC
;
; Purpose : convert FITs header to structure
;
; Category : imaging
;
; Explanation :
;
; Syntax : stc=head2stc(head)
;
; Examples :
;
; Inputs : HEAD = FITS header
;
; Opt. Inputs : None
;
; Outputs : STC = structure with header keys as tags
;
; Opt. Outputs: None
;
; Keywords : None
;
; Common : None
;
; Restrictions: None
;
; Side effects: None
;
; History : Written - 22 November 1996, D. Zarro, ARC/GSFC
; Modified - 22 May 1999, Zarro (SM&A/GSC), added check
; for extra fields without comments
;
; Contact : dzarro@solar.stanford.edu
;-

headfits.pro

;+
; NAME:
; HEADFITS
; PURPOSE:
; Read a FITS (primary or extension) header into a string array.
; EXPLANATION:
; Under Unix, HEADFITS() can also read gzip (.gz) or Unix compressed
; (.Z) FITS files
;
; CALLING SEQUENCE:
; Result = HEADFITS( filename ,[ EXTEN = ])
;
; INPUTS:
; FILENAME = String containing the name of the FITS file to be read.
;
; OPTIONAL INPUT KEYWORD:
; EXTEN = integer scalar, specifying which FITS extension to read.
; For example, to read the header of the first extension set
; EXTEN = 1. Default is to read the primary FITS header
; (EXTEN = 0).
;
; OUTPUTS:
; Result of function = FITS header, string array
;
; EXAMPLE:
; Print the main FITS header of a file 'test.fits' into a string
; variable, h
;
; IDL> print, headfits( 'test.fits')
;
; Print the second extension header of a gzip compressed FITS file
; 'test.fits.gz' (Unix only). Use HPRINT for pretty format
;
; IDL> hprint, headfits( 'test.fits.gz', 2)
;
; PROCEDURES CALLED
; FXPOSIT(), MRD_HREAD
; MODIFICATION HISTORY:
; adapted by Frank Varosi from READFITS by Jim Wofford, January, 24 1989
; Keyword EXTEN added, K.Venkatakrishna, May 1992
; Make sure first 8 characters are 'SIMPLE' W. Landsman October 1993
; Check PCOUNT and GCOUNT W. Landsman December 1994
; Major rewrite, work for Unix gzip files, W. Landsman April 1996
; Converted to IDL V5.0 W. Landsman September 1997
;-

host_to_ieee.pro

;+
; NAME:
; HOST_TO_IEEE
; PURPOSE:
; Translate an IDL variable from host to IEEE representation
; EXPLANATION:
; The variable is converted from the format used by the host architecture
; into IEEE-754 representation (as used, for example, in FITS data ).
;
; CALLING SEQUENCE:
; HOST_TO_IEEE, data, [ IDLTYPE = , ]
;
; INPUT-OUTPUT PARAMETERS:
; data - any IDL variable, scalar or vector. It will be modified by
; HOST_TO_IEEE to convert from host to IEEE representation. Byte
; and string variables are returned by HOST_TO_IEEE unchanged
;
; OPTIONAL KEYWORD INPUTS:
; IDLTYPE - scalar integer (1-9) specifying the IDL datatype according
; to the code given by the SIZE function. This keyword
; will usually be used when suppying a byte array that needs
; to be interpreted as another data type (e.g. FLOAT).
;
; EXAMPLE:
; Suppose FITARR is a 2880 element byte array to be converted to a FITS
; record and interpreted a FLOAT data.
;
; IDL> host_to_ieee, FITARR, IDLTYPE = 4
;
; METHOD:
; The BYTEORDER procedure is called with the appropriate keywords
;
; MODIFICATION HISTORY:
; Adapted from CONV_UNIX_VAX, W. Landsman Hughes/STX January, 1992
; Version for IDL V5.0 August 1997
; Converted to IDL V5.0 W. Landsman September 1997
;-

idl_release.pro

;+
; Project : SOHO - CDS
;
; Name : IDL_RELEASE
;
; Purpose : check if IDL release version within specified range
;
; Category : system
;
; Explanation :
;
; Syntax : IDL> a=idl_release(lower=lower,upper=upper)
;
; Examples :
;
; Inputs : None
;
; Opt. Inputs :
;
; Outputs : 1/0 if IDL version is within specified range
;
; Opt. Outputs: None
;
; Keywords : LOWER = lower version to check
; UPPER = upper version to check
; INCLUSIVE = make check inclusive
; VERS = IDL version
;
; Common : None
;
; Restrictions: None
;
; Side effects: None.
;
; History : Version 1, 27-Feb-1997, D M Zarro. Written
;
; Contact : DZARRO@SOLAR.STANFORD.EDU
;-

id_esc.pro

;+
; NAME:
; id_esc
; PURPOSE:
; To bijectively map character strings to identifiers, allowing
; (for example) FITS header strings to be used as structure
; tag names.
; METHOD:
; Illegal characters are turned into escape sequences. An
; escape sequence consists of a pair of identifier-legal characters
; FOLLOWED by the (identifier-legal) character '$'. The unusual
; escape structure (with the marker following the sequence)
; is to allow the first character of the tag to always be an
; alphabetical character. There is a special escape ('zz$'),
; the 0th entry in the data arrays in the id_escape common block,
; whose only purpose is to be an alphabetical character at the start
; of an identifier if necessary.
; EXAMPLE:
; print,id_esc(['3-days_left',"date_obs","time-obs"])
; zz$3_d$days_left date_obs time_d$obs
; AUTHOR:
; Craig DeForest
; HISTORY:
; Written 16-Jan-98
; USAGE:
; tagname = fitstagesc(fitsname)
; INPUTS:
; The string to be escaped, or an array of 'em
; RETURNS:
; The escaped string, or an array of 'em
;-

id_esc_init.pro

;+
; NAME:
; id_esc_init
; PURPOSE:
; Initialize the common blocks used by id_esc and id_unesc
; HISTORY:
; Written 16-Jan-98, Craig DeForest
; Added uppercase escape sequences, 20-Jan-98, CED
; 14-Feb-1998 - S.L.Freeland - nlm->n_elements
; 26-Jan-1999 - C.E.DeForest - changed escape codes to UPPERCASE
; because IDL (may its creators plumb the depths of the inferno)
; always returns UPPERCASE for structure tags. This fixes
; a bug in fits_interp.
; METHOD:
; Identifiers may have A-Z, 0-9, $, and _ in them. We use the '$'
; as a marker for two-digit escape sequences that indicate the
; unusable characters. Most of the printable ones have sort-of-mnemonic
; escape sequences defined in a nice array below. The unprintable
; and high-end ones, we handle with two-digit hexadecimal codes.
; All this stuff just generates a string array ('targets') that
; contains one of each kind of character that needs escaping, and
; another string array('escapes') that contains the two-letter code
; for each of the unusable characters.
; SEE ALSO: id_esc, id_unesc
;-

id_unesc.pro

;+
; NAME:
; id_unesc
; PURPOSE:
; Convert identifiers escaped with id_esc back into strings.
; USAGE:
; string = id_unesc(identifier)
; INPUT:
; The escaped string (identifier) to convert back to a regular string.
; OUTPUT:
; The original string
; HISTORY:
; Written 16-Jan-98
; 14-Feb-1998 - S.L.Freeland - nlm->n_elements
; AUTHOR:
; Craig DeForest
; METHOD:
; We have to work around IDL's awful, sick, and twisted string
; handling. We break the string into an array of characters
; to find the '$' characters (escape sequences are two alphanumeric
; (or '_') characters followed by '$'), and then convert the
; complete three-character sequence back into its original target
; character using the information in the id_escape common block.
; At the end, we patch the modified array back into a string.
;-

ieee_to_host.pro

;+
; NAME:
; IEEE_TO_HOST
; PURPOSE:
; Translate an IDL variable from IEEE-754 to host representation
; EXPLANATION:
; The variable is translated from IEEE-754 (as used, for
; example, in FITS data ), into the host machine architecture.
;
; CALLING SEQUENCE:
; IEEE_TO_HOST, data, [ IDLTYPE = , ]
;
; INPUT-OUTPUT PARAMETERS:
; data - any IDL variable, scalar or vector. It will be modified by
; IEEE_TO_HOST to convert from IEEE to host representation. Byte
; and string variables are returned by IEEE_TO_HOST unchanged
;
; OPTIONAL KEYWORD INPUTS:
; IDLTYPE - scalar integer (1-9) specifying the IDL datatype according
; to the code given by the SIZE function. This keyword
; is usually when DATA is a byte array to be interpreted as
; another datatype (e.g. FLOAT).
;
; EXAMPLE:
; A 2880 byte array (named FITARR) from a FITS record is to be
; interpreted as floating and converted to the host representaton:
;
; IDL> IEEE_TO_HOST, fitarr, IDLTYPE = 4
;
; METHOD:
; The BYTEORDER procedure is called with the appropriate keyword
;
; PROCEDURE CALLS:
; WHERE_NEGZERO() - Called under VMS prior to V5.1 to check for
; IEEE -0.0 values
;
; MODIFICATION HISTORY:
; Written, W. Landsman Hughes/STX May, 1992
; Converted to IDL V5.0 W. Landsman September 1997
; Under VMS check for IEEE -0.0 values January 1998
; VMS now handle -0.0 values under IDL V5.1 July 1998
;-

image_stats.pro

;+
; PROJECT:
; SXI-M Ground Data System
;
; NAME:
; IMAGE_STATS
;
; PURPOSE:
; Compute statistcs of a floating point image
;
; EXPLANATION:
; TBS
;
; CALLING SEQUENCE:
; IMAGE_STATISTICS,image
;
; INPUTS:
; image = input image array
; index = associated header index structure
;
; OUTPUTS:
; index = associated header index structure
; with updated parameter values
;
; OPTIONAL INPUT KEYWORDS:
; N/A
;
; EXTERNAL CALLS:
; N/A
;
; CALLED BY:
; SXIM_PREP
;
; METHOD:
; TBS
;
; HISTORY:
; Version 1.x
; Written by Steven Hill at NOAA/SEC 30 Jan 2001
; 001.001 Modified by Steven Hill 14 Mar 2001 to include directly write the header index
; 001.002 Modified by SM Hill 28 Mar 2001 to use IDL 5.4 Image statistics routine.
; Renamed to IMAGE_STATS
;
;-;

img_scl.pro



int2utc.pro

;+
; Project : SOHO - CDS
;
; Name : INT2UTC()
;
; Purpose : Converts CDS internal time to calendar format.
;
; Explanation : This procedure takes the UTC calendar time in "internal" format
; (Modified Julian Day number, and time of day in milliseconds),
; and converts it to a calendar format, either as a structure or
; as a string. For notes on other time formats, see file
; aaareadme.txt.
;
; Use : Result = INT2UTC( INT )
; Result = INT2UTC( INT, /CCSDS )
; Result = INT2UTC( INT, /ECS )
;
; 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 result of the function will be a structure containing the
; tag elements YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, and
; MILLISECOND.
;
; Alternatively, if the CCSDS switch is set, then the result will
; be the calendar date in the format recommended by the
; Consultative Committee for Space Data Systems (ISO 8601), e.g.
;
; "1988-01-18T17:20:43.123Z"
;
; Or if the ECS switch is set, then the result will be a calendar
; date in the format used by the EOF Core System, e.g.
;
; "1988/01/18 17:20:43.123"
;
; Note that this isn't exactly the ECS string format, because the
; ECS does not use fractional seconds. However, if /ECS is
; combined with /TRUNCATE, then the following output will result
;
; "1988/01/18 17:20:43"
;
; which matches what the ECS expects to see.
;
; Using the keyword /VMS writes out the time in a format similar
; to that used by the VMS operating system, e.g.
;
; "18-Jan-1988 17:20:43.123"
;
; A variation of this is obtained with the /STIME keyword, which
; emulates the value of !STIME in IDL. It is the same as using
; /VMS except that the time is only output to 0.01 second
; accuracy, e.g.
;
; "18-Jan-1988 17:20:43.12"
;
; The keywords /DATE_ONLY and TIME_ONLY can be used to extract
; either the date or time part of the string.
;
; Opt. Outputs: None.
;
; Keywords : CCSDS = If set, then the output is in CCSDS format, as
; explained above.
;
; ECS = If set, then the output is in ECS format, as
; explained above.
;
; VMS = If set, then the output will be in VMS format, as
; described above.
;
; STIME = If set, then the output will be in STIME format, as
; described above.
;
; Only one of the above keywords can be set. If none of them are
; set, the the time is output in external format. The following
; keywords are only valid if one of the above keywords is set.
;
; TRUNCATE = If set, then the time will be truncated to 1 second
; accuracy. Note that this is not the same thing as
; rounding off to the nearest second, but is a
; rounding down.
;
; DATE_ONLY = If set, then only the date part of the string is
; returned.
;
; TIME_ONLY = If set, then only the time part of the string is
; returned.
;
; UPPERCASE = If set, then the month field in either the VMS or
; STIME format is returned as uppercase.
;
; NOZ = When set, the "Z" delimiter (which denotes UTC
; time) is left off the end of the CCSDS/ISO-8601
; string format. It was decided by the FITS
; committee to not append the "Z" in standard FITS
; keywords.
;
; The following keyword is always valid.
;
; 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 = INT2UTC ( INT, ERRMSG=ERRMSG )
; IF ERRMSG NE '' THEN ...
;
; Calls : DATATYPE, UTC2STR, MJD2DATE
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: The result of an array with a single element may be a scalar.
; If an error occurs and the ERRMSG keyword has been set, the
; result returned from INT2UTC is an integer scalar of value -1.
;
; Category : Utilities, Time.
;
; Prev. Hist. : None. However, the concept of "internal" and "external" time
; is based in part on the Yohkoh software by M. Morrison and G.
; Linford, LPARL.
;
; Written : William Thompson, GSFC, 20 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, William Thompson, GSFC, 20 December 1994
; Added keywords TRUNCATE, DATE_ONLY, TIME_ONLY
; Version 4, Donald G. Luttermoser, GSFC/ARC, 28 December 1994
; Added the keyword ERRMSG. Added check to the structure
; tag names in INT.
; Version 5, William Thompson, GSFC, 25 January 1995
; Changed to call intrinsic ROUND instead of NINT. The
; version of NINT in the Astronomy User's Library doesn't
; automatically select between short and long integers as
; the CDS version does.
; Version 6, Donald G. Luttermoser, GSFC/ARC, 30 January 1995
; Added ERRMSG keyword to internally called procedures.
; Made the error handling procedure more robust. Note
; that this routine accepts both scalar and vector
; input.
; Version 7, William Thompson, GSFC, 14 March 1995
; Added keywords VMS, STIME, UPPERCASE
; Version 8, William Thompson, GSFC, 17 September 1997
; Added keyword NOZ.
;
; Version : Version 8, 17-Sep-1997
;-

isvalid.pro

;+
; NAME:
; ISVALID
; PURPOSE:
; Returns validity flag for its argument
; CALLING SEQUENCE:
; result = isvalid(variable)
; INPUTS:
; variable: the variable to be tested
; OPTIONAL INPUT PARAMETERS:
; (none)
; KEYWORD PARAMETERS:
; (none)
; RESTRICTIONS:
; None I know of....
; MODIFICATION HISTORY:
; Created by Craig DeForest, 4/13/1995
;-

is_dir.pro

;+
; Project : HESSI
;
; Name : IS_DIR
;
; Purpose : platform/OS independent check if input name is a
; valid directory.
;
; Category : system utility
;
; Explanation : uses 'cd' and 'catch'
;
; Syntax : IDL> a=is_dir(name)
;
; Inputs : NAME = directory name to check
;
; Outputs : 1/0 if success/failure
;
; Keywords : OUT = full name of directory
;
; Restrictions: Needs IDL version .ge. 4. Probably works in Windows
;
; Side effects: None
;
; History : Written, 6-June-1999, Zarro (SM&A/GSFC)
; Modified, 2-Dec-1999, Zarro - add check for NFS /tmp_mnt
;
; Contact : dzarro@solar.stanford.edu
;-

;-- utility for removing /tmp from NFS mount point names

pro rem_tmp,name,tname

if (exist(name)) then tname=name

if datatype(name) ne 'STR' then return

if (strlowcase(os_family()) ne 'unix') then return

item='/tmp_mnt/'
tmp=strpos(name,item)
if tmp eq 0 then begin
tname=strmid(name,strlen(item)-1,strlen(name))
endif

return & end

;-----------------------------------------------------------------------------

function is_dir,name,out=out

if exist(name) then out=name

if datatype(name) ne 'STR' then begin
out=''
return,0b
endif

np=n_elements(name)

;-- use recursion for vector inputs

if np gt 1 then begin
bool=bytarr(np)
out=strarr(np)
for i=0,np-1 do begin
bool(i)=is_dir(name(i),out=tout)
out(i)=tout
endfor
if np eq 1 then bool=bool(0)
return,bool
endif

cname=chklog(name,/pre)
if strtrim(cname,2) eq '' then begin
out=''
return,0b
endif

;-- use the old system dependent "chk_dir" for pre-version 4

if not idl_release(lower=4,/inc) then begin
status=chk_dir(cname,out)
if not status then out=''
return,status
endif

;-- save current directory

cd,curr=curr

error=0
catch,error
if error ne 0 then begin
catch,/cancel
cd,curr
out=''
return,0b
endif


;-- patch for UNIX NFS mounts with /tmp_mnt

rem_tmp,cname,tname

;-- try to 'cd' to 'name' and catch error

cd,tname
cd,curr,curr=tout
rem_tmp,tout,out


;-- 'cd' succeeded so 'name' is a valid directory

is_fits.pro

;+NAME/ONE LINE DESCRIPTION OF ROUTINE:
; IS_FITS determines whether a file is in fits format
;
;DESCRIPTION:
; IS_FITS reads the primary header unit from a file and searches
; for the keyword 'SIMPLE'. If SIMPLE = T then the file is
; determined to be a fits file and result = 1. The keyword
; 'EXTENSIONS' is then searched for; if it is found then then
; next header unit is read in and the value of the 'XTENSION'
; keyword is returned in the optional parameter 'extension'. If
; 'EXTENSIONS' is not found then 'extension' is left blank.
;
;
;CALLING SEQUENCE:
; RESULT = IS_FITS ( filename, [extension] )
;
;ARGUMENTS (I = input, O = output, [] = optional):
; RESULT O integer Contains 1 for each file that is in
; fits format, SIMPLE = 'T'
; FILENAME I string File name to be checked
; EXTENSION [O] string Contains the extension type if
; the fits file contains 'XTENSION'
; keyword
;
;WARNINGS:
;
;EXAMPLE:
; To check if file 'filename' is fits format use the following:
;
; status = is_fits('filename')
;
; The return status = 1 if it is a fits file and 0 if not. No
; information on extensions is returned.
;
; To determine if a file is a valid fits extension file and what
; type if extension it is, then include the optional 'extension'
; keyword:
;
; status = is_fits('filename', extension)
;
; In this case status = 1 if the file is a valid fits file. The
; keyword extension = 'BINTABLE' if the file is fits Binary
; Table Extension. If no extensions were found then extension
; is left blank. !ERROR will be returned as 0 for no errors and
; as 1 if the file was not found.
;#
;COMMON BLOCKS:
; None
;
;PROCEDURE (AND OTHER PROGRAMMING NOTES):
;
;PERTINENT ALGORITHMS, LIBRARY CALLS, ETC.:
; Uses a call to SXPAR to find keyword values.
;
;MODIFICATION HISTORY:
; Written by Dave Bazell, General Sciences Corp. 4 Feb 1993 spr 10477
; Modified by Dalroy Ward, General Sciences Corp. 24 Mar 1993 spr
; modified routine to handle headers longer than one record
; 13-Aug-2000, Zarro (EIT/GSFC) - added more stringent test for
; non-zero dimensions
;
;.TITLE
; Routine IS_FITS
;-

is_ieee_big.pro

;+
; NAME:
; IS_IEEE_BIG
; PURPOSE:
; Determine if the current machine is use IEEE, big-endian numbers.
; EXPLANATION:
; (Big endian implies that byteorder XDR conversions are no-ops).
; CALLING SEQUENCE:
; flag = is_ieee_big()
; INPUT PARAMETERS:
; None
; RETURNS:
; 1 if the machine appears to be IEEE-compliant, 0 if not.
; COMMON BLOCKS:
; None.
; SIDE EFFECTS:
; None
; RESTRICTIONS:
; PROCEDURE:
; A sample int, long, float and double are converted using
; byteorder and compared with the original. If there is no
; change, the machine is assumed to be IEEE compliant and
; big-endian.
; MODIFICATION HISTORY:
; Written 15-April-1996 by T. McGlynn for use in MRDFITS.
; 13-jul-1997 jkf/acc - added calls to check_math to avoid
; underflow messages in V5.0 on Win32 (NT).
; Converted to IDL V5.0 W. Landsman September 1997
;-

is_member.pro

;+
; Name: is_member
;
; Purpose: check set membership (element(s) IN set?), return boolean
;
; Input Parameters:
; elements - item(s) to check
; set - array (set) to check (use keyword if not specified)
;
; Keyword_Parameters:
; swap_os - return true if current OS requires byte swapping
; wc - if set, just check for pattern match
;
; Calling Sequence:
; truth=is_member(element, set) ; user specified values
; truth=is_member(/swap_os) ; built in tests via keywords
;
; Calling Examples:
; IF is_member(/swap_os) THEN ; check current OS
; IF is_member(name,['n1','n2','n3']) THEN ; is name in namelist?
; IF is_member(pattern,'n1,n2,n3']) THEN ; same as above
; IF is_member(name,namelist,/ignore_case) THEN ; case insensitive
; IF is_member(pattern,list,/wc) THEN ; pattern match?
;
; History:
; 11-Apr-1994 (SLF) [reduce duplicate code, self-documenting code]
; 25-oct-1994 (SLF) add WC keyword and function
; 3-oct-1995 (SLF) add linux to sawap_os
; 1-nov-1996 (SLF) allow SET to be scaler string (comma delimited)
;-

is_number.pro

;+
;NAME:
; is_number
;PURPOSE:
; Test string (or array of strings) to see if it is a number
;SAMPLE CALLING SEQUENCE:
; out = is_number(inarray)
; print, is_number(v)
; print, is_number('xx')
; out = is_number('66.6e')
;INPUT:
; inarray - The string(s) to test
;OUTPUT:
; out - Boolean array (0 means not a string, 1 means it is)
;METHOD:
; Use READS and trap on any errors with ON_IOERROR
;HISTORY:
; Written 29-Oct-97 by M.Morrison
; Modified 29-Jun-99, Zarro (SM&A/GSFC) - added check for undefined input
; Modified 29-Sep-00, Zarro (EIT/GSFC) - added check for invalid inputs
;-

line_noise.pro



long_time_str.pro



make_browse.pro

;+
; PROJECT:
; SXI-M Ground Data System
;
; NAME:
; MAKE_BROWSE
;
; PURPOSE:
; Generate byte images for browsing and real-time display.
;
; EXPLANATION:
; TBS
;
; CALLING SEQUENCE:
; MAKE_BROWSE,image,index,image_type,level,browse,stamp
;
; INPUTS:
; image = input image (512x512)
; index = input header (from FITS) as index structure
; image_type = image type, e.g., flare, etc.
; level = image level code, e.g., A=level-0, B=level-1
;
; OUTPUTS:
; browse = browse image array with annotation (512x512 byte array)
; stamp = stamp image array with no annotation (128x128 byte array)
;
; OPTIONAL INPUT KEYWORDS:
; N/A
;
; EXTERNAL CALLS:
; N/A
;
; 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/6/2001
; Removed full path for level-1 circular mask file
; Added color bar on left side of full sized images
; 001.003 Modified by SMH 7/10/2001
; Added correct ph/pix/sec scaling for level-1 PNGs
; 001.004 Modified by SMH 7/26/2001
; Accommodated message for missing TSYNC packet
; impact on MCP gain computation
;
;-

make_str.pro

;+
; NAME:
; MAKE_STR
;
; PURPOSE:
; Control dynamic structure building - avoids collision of
; names which might result if different modules used the same
; structure names and had different numbber/types of tag fields
;
; CALLING SEQUENCE:
; user_value= MAKE_STR(ustr_string [,str_name=str_name, /NOEXEC]
;
; INPUTS:
; USTR_STRING - string of form '{dummy,T1:intarr(10), T2:oL...}'
;
; OUTPUTS:
; return value = structure defined by USTR_STRING
;
; OPTIONAL KEYWORD PARAMETERS:
; STR_NAME - (Output) Structure name created
; NOEXEC - If set, a unique name is allocated but no structure
; is created - in this case, the return value is the
; allocated name (string variable), not the structure
;
; COMMON BLOCKS;
; MAKE_STR_PRIVATE - used to generate unique names (via counter)
; MAKE_STR_BLK - track previously created structures
; MAKE_STR_BLK1 - flag to enable/disable structure exist checks
;
; FILE I/O:
; NONE
;
; METHOD
; uses a common block to store counter which is incremented on
; each call and incorporated into the structrure name. Uses the
; IDL EXECUTE statement to dynamically create the structure
;
; MODIFICATION HISTORY:
; Version 1 - SLF, 3/5/91 Samuel Freeland
; Version 1.1 - SLF, 10/23/91 - added call to strstat to check for
; structure existance
; Version 2.0 - slf, 15-jan-93 - added 2nd common block to track
; defined structures
; slf, 18-jan-93 - add string compress
; slf, 1-feb-93 - kludge for strings large than 512
; slf, 3-feb-93 add make_str_blk for
; slf, 7-feb-93 improved feb 1 upgrades
; slf, 26-mar-93 use systime + counter for str names
; slf, 15-jan-97 Version 5 (derivation of HOME)
; richard.schwartz@gsfc.nasa.gov, 9-feb-1999.
; Fix path to work on Windows and Mac, too.
; Zarro (SM&A/GSFC) 25-May-99, added check for
; undefined HOME and/or write access
; Csillaghy (SSL/UCB) 8-Dec-1999, /QUIET keyword
; to str_checks.
;
;
;-

match_struct.pro

;+
; Project : SDAC
;
; Name : MATCH_STRUCT
;
; Purpose : check if two structures are identical
;
; Explanation : cross-checks type and value of each field
;
; Use : STATUS=MATCH_STRUCT(STRUCT1,STRUCT2)
;
; Inputs : S1, S2 = input structures
;
; Opt. Inputs : None.
;
; Outputs : STATUS = 1/0 is input structure are/are not identical
;
; Opt. Outputs: None.
;
; Keywords : TAG_ONLY = set to check if only tags are the same
; FLOATING = do checks in floating point
; BLANK = treat string blanks as valid characters
; TYPE_ONLY = set to check if datatype of each tag
; is the same (values are not checked)
; EXCLUDE = tags to exclude (e.g [1,3,4] or [tag1,tag2..])
; INCLUDE = tags to include
; SENSITIVE = make string matches case sensitive
; DTAG = tag name where first difference is found
;
; Calls : DATATYPE
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: None.
;
; Category : Structure handling
;
; Prev. Hist. : None.
;
; Written : Dominic Zarro (ARC/GSFC)
;
; Modified : To handle arrays of strings. CDP, 27-Feb-95
; Removed redundant string check. DMZ, 1-March-95
;
; Version : Version 3, 1-March-95
;
;-

function match_struct,s1,s2,tags_only=tags_only,floating=floating,blank=blank,$
dtag=dtag,sensitive=sensitive,type_only=type_only,include=include,exclude=exclude

on_error,1

status=0b
dtag=''

if (datatype(s1) ne 'STC') or (datatype(s2) ne 'STC') then begin
message,'syntax --> STATUS=MATCH_STRUCT(STRUCT1,STRUCT2)',/contin
return,status
endif

;-- check that input structures have same number of tags

t1=tag_names(s1) & t2=tag_names(s2)
if n_elements(t1) ne n_elements(t2) then return,status
ntags=n_elements(t1)

match,t1,t2,a,b
if ((a(0) eq -1) or (b(0) eq -1)) or (n_elements(a) ne ntags) then return,status


if keyword_set(tags_only) then return,1b

;-- check if datatype match

if keyword_set(type_only) then begin
return,match_struct(clear_struct(s1(0)),clear_struct(s2(0)),dtag=dtag)
endif

;-- flag tags to include/exclude

if exist(exclude) then begin
if datatype(exclude) eq 'STR' then begin
to_exclude=where_vector(trim(strupcase(exclude)),trim(t1),count)
endif else to_exclude=exclude
endif else to_exclude=-1

if exist(include) then begin
if datatype(include) eq 'STR' then begin
to_include=where_vector(trim(strupcase(include)),trim(t1),count)
endif else to_include=include
endif else to_include=indgen(ntags)

;-- check that everything matches

for i=0,n_elements(t1)-1 do begin

check=where(i eq to_include,count)
if count gt 0 then begin
check=where(i eq to_exclude,count)
if count eq 0 then begin

dtag=t1(i)
if t1(i) ne t2(i) then return,0b

f1=s1.(i) & f2=s2.(i)

if datatype(f1) ne datatype(f2) then begin
return,0b
endif

;-- have to do the following in case there are small differences
; due to round-off

dtype=datatype(f1)
if (dtype ne 'STR') and (dtype ne 'STC') and keyword_set(floating) then begin
f1=float(f1) & f2=float(f2)
endif

if (dtype eq 'STR') then begin
if not keyword_set(blank) then begin
f1=strtrim(f1,2) & f2=strtrim(f2,2)
endif
if not keyword_set(sensitive) then begin
f1=strlowcase(f1) & f2=strlowcase(f2)
endif
endif

case 1 of

;-- structure case

datatype(f1) eq 'STC' : begin
status=match_struct(f1,f2,tags_only=tags_only,floating=floating,$
dtag=dtag,blank=blank)
end

else: begin
clook=where( (f2 eq f1) eq 1,cnt)
status=(cnt eq n_elements(f1))
end

endcase
if total(status) ne n_elements(status) then return,0b
endif
endif
endfor

;-- made it this far, so must be ok

merge_struct.pro

;+
; Project : SOHO - CDS
;
; Name : MERGE_STRUCT
;
; Purpose : merge/concatanate two structures
;
; Explanation : concatanates two structures by using CREATE_STRUCT to
; ensure that input structures have the same name and, thus,
; avoid the problem of concatanating two differently named
; structures. Why didn't anyone think of this before.
;
; Use : NEW_STRUCT=MERGE_STRUCT(STRUCT1,STRUCT2)
;
; Inputs : STRUCT1,2 = input structures
;
; Opt. Inputs : None.
;
; Outputs : NEW_STRUCT = concatanated structure
;
; Opt. Outputs: None.
;
; Keywords : ERR = err string
; NOTAG_CHECK = don't check if tag names match.
; NOCHECK = skip input checking
;
; Category : Structure handling
;
; Prev. Hist. : None.
;
; Written : Dominic Zarro (SAC/GSFC)
;
; Version : Version 1.0, 19 January 1998
;-

mod_img.pro



mrd_hread.pro

;+
; NAME:
; MRD_HREAD
;
; PURPOSE:
; Reads a FITS header from an opened disk file or Unix pipe
; EXPLANATION:
; Like FXHREAD but also works with compressed Unix files
;
; CALLING SEQUENCE:
; MRD_HREAD, UNIT, HEADER [, STATUS ]
; INPUTS:
; UNIT = Logical unit number of an open FITS file
; OUTPUTS:
; HEADER = String array containing the FITS header.
; OPT. OUTPUTS:
; STATUS = Condition code giving the status of the read. Normally, this
; is zero, but is set to !ERR if an error occurs, or if the
; first byte of the header is zero (ASCII null).
; RESTRICTIONS:
; The file must already be positioned at the start of the header. It
; must be a proper FITS file.
; SIDE EFFECTS:
; The file ends by being positioned at the end of the FITS header, unless
; an error occurs.
; REVISION HISTORY:
; Written, Thomas McGlynn August 1995
; Modified, Thomas McGlynn January 1996
; Changed MRD_HREAD to handle Headers which have null characters
; A warning message is printed out but the program continues.
; Previously MRD_HREAD would fail if the null characters were
; not in the last 2880 byte block of the header. Note that
; such characters are illegal in the header but frequently
; are produced by poor FITS writers.
; Converted to IDL V5.0 W. Landsman September 1997
;-

nint.pro

;+
; Project : SOHO - CDS
;
; Name : NINT()
;
; Purpose : Returns the nearest integers to the input values.
;
; Explanation : Returns the nearest integer (2 or 4 byte) to the input scalar
; or array. Note this function should be used instead of
; relying on the IDL FIX or LONG functions to convert a real
; number. Eg fix(1.0/0.001) = 999 but nint(1.0/0.001) = 1000
;
; Use : IDL> n = nint(x)
;
; Inputs : x array for which nearest integers are to be found.
;
; Opt. Inputs : None
;
; Outputs : Function value - the nearest integers.
;
; Opt. Outputs: None
;
; Keywords : LONG = If this keyword is set and non-zero, then the result
; of NINT is of type LONG. Otherwise, the result is
; either of type INTEGER or LONG depending on the
; extent of the data.
;
; Calls : None
;
; Restrictions: The nearest integer of 2.5 is 3
; the nearest integer of -2.5 is -3
;
; Side effects: None
;
; Category : Util, Numerical
;
; Prev. Hist. : Unknown
;
; Written : Unknown
;
; Modified : To CDS format, C D Pike, RaL, 18-May-1993
; Version 2, William Thompson, GSFC, 27 July 1993.
; Added LONG keyword, taken from routine of same name
; written by Wayne Landsman.
; Version 3, William Thompson, GSFC, 17 February 1998
; Use ROUND function
; Version 4, William Thompson, GSFC, 19 February 1998
; Allow string inputs
;
; Version : Version 4, 19 February 1998
;-

os_family.pro

;+
; Project : SOHO - CDS
;
; Name : OS_FAMILY()
;
; Purpose : Return current operating system as in !VERSION.OS_FAMILY
;
; Category : Utilities, Operating_system
;
; Explanation : Return the current operating system as in !VERSION.OS_FAMILY
;
; OS_FAMILY is assumed to be 'unix' if !VERSION.OS is not 'windows',
; 'MacOS' or 'vms'
;
; To make procedures from IDL V4.0 and later compatibile with earlier
; versions of IDL, replace calls to !VERSION.OS_FAMILY with OS_FAMILY().
;
; Can also be used to replace calls to !VERSION.OS if care is taken with
; the change of case between 'Windows', which is what this routine
; returns, and 'windows' which is what !VERSION.OS returned in versions
; of IDL prior to 4.0.
;
; Syntax : Result = OS_FAMILY()
;
; Examples : IF OS_FAMILY() EQ 'vms' THEN ...
;
; Inputs : None.
;
; Opt. Inputs : None.
;
; Outputs : The result of the function is a scalar string containing one of
; the four values 'Windows','MacOS','vms' or 'unix'
;
; Opt. Outputs: None.
;
; Keywords : LOWER - set to return lowercase strings
;
; Calls : TAG_EXISTS
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: None.
;
; Prev. Hist. : Written, W. Landsman
;
; History : Version 1, 29-Aug-1995, William Thompson, GSFC
; Incorporated into CDS library
; Version 2, 15 May 2000, Zarro (SM&A/GSFC) - added /LOWER
;
; Contact : WTHOMPSON
;-

path_delimiter.pro

;+
; Name: path_delimiter
;
; Purpose: return system dependent !path delimiter
;
; Input Parameters:
; NONE
;
; Keyword Parameters:
; OS - used for getting other OS delimiters
;
; Calling Sequence:
; pdelim=path_delimiter() ; one for this OS
; pdelim=path_delimiter(os=xxx) ; test other OS
;
; History:
; 2-April-1998 - replace corrupted version in SSW
;
; Calls:
; os_family
;-

prstr.pro

;+
; Name: prstr
;
; Pupose: print input string array as using format='(a)' to force one
; entry per line (other types use idl standard print defaults)
;
; Input Parameters:
; strarr - array to print (will be converted to string)
; lun - (optional - in/out) open unit for file
;
; Keyword Parameters:
; file - file name for output (default is via scratch.pro)
; (if not defined, it is output from scratch)
; print - if set, print out the text
; hc - if set, print out the text (hc=hardcopy=synonym for print)
; file - string file name for write (default is via scratch.pro)
; compress - if set, compress and remove nulls (useful for FITS header)
; nomore - if set, inhibit 'more-like' behavior (print everything)
; landscape - keyword passed to sprint (via scratch)
; quiet - if set, dont print error messages (file not openable...)
;
; Calling Sequence:
; prstr,strarry [,/nomore] ; print string array to terminal
; prstr,strarry,/print ; scratch file->lpr, delete scratch
; prstr,strarry,lun ; print strarray to scratch file
; ; (open file if lun is undefined)
; prstr,strarry,lun,file=fname ; user supplies file
; prstr,strarry,lun,/print ; same, close, print, delete
; prstr,strarry,lun,/landscape ; same, in landscape
; prstr,strarry,lun,/print,/nodel ; dont delete scrat
;
; History:
; slf, circa June 1992
; slf, 18-jan-1993 - added file and hc keywords
; slf, 5-mar-1993 - use scratch.pro for temp files
; slf, 2-jun-1993 - add close keyword
; mdm, 3-Jun-1993 - Closed the file when LUN is not used in the call
; slf, 29-jul-1993 - added compress keyword and function
; slf, 12-aug-1993 - added 'more' logic to terminal print, input chk
; added nomore keyord
; slf, 18-apr-1994 - call more.pro for tty output
; slf, 20-feb-1996 - update for SSW use (ssw_nomore for batch jobs)
; slf, 7-oct-1997 - add LANDSCAPE switch
;-

psf_gaussian.pro

;+
; NAME:
; PSF_GAUSSIAN
;
; PURPOSE:
; Create a 1-d, 2-d, or 3-d Gaussian with specified FWHM, center
; EXPLANATION:
; Return a point spread function having Gaussian profiles,
; as either a 1D vector, a 2D image, or 3D volumetric-data.
;
; CALLING SEQUENCE:
; psf = psf_Gaussian( NPIXEL=, FWHM= , [/NORMALIZE, /ST_DEV, )
; or:
; psf = psf_Gaussian( parameters, NPIXEL = )
;
; REQUIRED INPUT KEYWORD:
; NPIXEL = number pixels for each dimension, specify as an array,
; or just one number to make all sizes equal.
;
; OPTIONAL KEYWORDS:
;
; NDIMEN = dimension of result: 1 (vector), 2 (image), or 3 (volume),
; default = 2 (an image result).
;
; FWHM = the desired Full-Width Half-Max (pixels) in each dimension,
; specify as an array, or single number to make all the same.
;
; CENTROID = pixels numbers of PSF maximum ( 0.5 is center of a pixel ),
; default is exact center of requested vector/image/volume.
;
; STDEV = optional way to specify width by standard deviation param.
;
; XY_CORREL = scalar between 0 and 1 specifying correlation coefficient
; Use this keyword, for example, to specify an elliptical
; gaussian oriented at an angle to the X,Y axis
;
; /NORMALIZE causes resulting PSF to be normalized so Total( psf ) = 1.
;
; INPUTS (optional):
;
; parameters = an NDIMEN by 3 array giving for each dimension:
; [ maxval, center, stdev ], overrides other keywords.
;
; EXAMPLE:
; Create a 31 x 31 array containing a normalized centered gaussian
; with an X FWHM = 4.3 and a Y FWHM = 3.6
;
; IDL> array = PSF_GAUSSIAN( Npixel=31, FWHM=[4.3,3.6], /NORMAL
;
; EXTERNAL CALLS:
; function Gaussian
;
; HISTORY:
; Written, Frank Varosi NASA/GSFC 1991.
; Converted to IDL V5.0 W. Landsman September 1997
;-

psf_moffit.pro



readfits.pro

;+
; NAME:
; READFITS
; PURPOSE:
; Read a FITS file into IDL data and header variables.
; EXPLANATION:
; Under Unix, READFITS() can also read gzip or Unix compressed FITS files.
; See http://idlastro.gsfc.nasa.gov/fitsio.html for other ways of
; reading FITS files with IDL.
;
; CALLING SEQUENCE:
; Result = READFITS( Filename,[ Header, heap, /NOSCALE, EXTEN_NO=,
; NSLICE=, /SILENT , NaNVALUE =, STARTROW =, NUMROW = ,
; /No_Unsigned ] )
;
; INPUTS:
; FILENAME = Scalar string containing the name of the FITS file
; (including extension) to be read. If the filename has
; a *.gz extension, it will be treated as a gzip compressed
; file. If it has a .Z extension, it will be treated as a
; Unix compressed file.
;
; OUTPUTS:
; Result = FITS data array constructed from designated record.
; If the specified file was not found, then Result = -1
;
; OPTIONAL OUTPUT:
; Header = String array containing the header from the FITS file.
; heap = For extensions, the optional heap area following the main
; data array (e.g. for variable length binary extensions).
;
; OPTIONAL INPUT KEYWORDS:
;
; EXTEN_NO - scalar integer specify the FITS extension to read. For
; example, specify EXTEN = 1 or /EXTEN to read the first
; FITS extension. Extensions are read using recursive
; calls to READFITS.
;
; NaNVALUE - This scalar is only needed on architectures (such as VMS
; prior to IDL V5.1) that do not recognize the IEEE "not a number"
; (NaN) convention. It specifies the value to translate any IEEE
; NAN values in the FITS data array.
;
; /NOSCALE - If present and non-zero, then the ouput data will not be
; scaled using the optional BSCALE and BZERO keywords in the
; FITS header. Default is to scale.
;
; /NO_UNSIGNED - By default, if theIDL Version is 5.2 or greater, and the
; header indicates an unsigned integer (BITPIX = 16, BZERO=2^15,
; BSCALE=1) then FITS_READ will output an IDL unsigned integer
; data type (UINT). But if /NO_UNSIGNED is set, or the IDL
; version is before 5.2, then the data is converted to type LONG.
;
; NSLICE - An integer scalar specifying which N-1 dimensional slice of a
; N-dimensional array to read. For example, if the primary
; image of a file 'wfpc.fits' contains a 800 x 800 x 4 array,
; then
;
; IDL> im = readfits('wfpc.fits',h, nslice=2)
; is equivalent to
; IDL> im = readfits('wfpc.fits',h)
; IDL> im = im(*,*,2)
; but the use of the NSLICE keyword is much more efficient.
;
; NUMROW - Scalar non-negative integer specifying the number of rows
; of the image or table to read. Useful when one does not
; want to read the entire image or table.
;
; POINT_LUN - Position (in bytes) in the FITS file at which to start
; reading. Useful if READFITS is called by another procedure
; which needs to directly read a FITS extension. Should
; always be a multiple of 2880, and not be used with EXTEN_NO
; keyword.
;
; /SILENT - Normally, READFITS will display the size the array at the
; terminal. The SILENT keyword will suppress this
;
; STARTROW - Non-negative integer scalar specifying the row
; of the image or extension table at which to begin reading.
; Useful when one does not want to read the entire table.
;
; EXAMPLE:
; Read a FITS file TEST.FITS into an IDL image array, IM and FITS
; header array, H. Do not scale the data with BSCALE and BZERO.
;
; IDL> im = READFITS( 'TEST.FITS', h, /NOSCALE)
;
; If the file contain a FITS extension, it could be read with
;
; IDL> tab = READFITS( 'TEST.FITS', htab, /EXTEN )
;
; The function TBGET() can be used for further processing of a binary
; table, and FTGET() for an ASCII table.
; To read only rows 100-149 of the FITS extension,
;
; IDL> tab = READFITS( 'TEST.FITS', htab, /EXTEN,
; STARTR=100, NUMR = 50 )
;
; To read in a file that has been compressed:
;
; IDL> tab = READFITS('test.fits.gz',h)
;
; ERROR HANDLING:
; If an error is encountered reading the FITS file, then
; (1) the system variable !ERROR is set (via the MESSAGE facility)
; (2) the error message is displayed (unless /SILENT is set),
; and the message is also stored in !ERR_STRING
; (3) READFITS returns with a value of -1
; RESTRICTIONS:
; (1) Cannot handle random group FITS
;
; NOTES:
; (1) If data is stored as integer (BITPIX = 16 or 32), and BSCALE
; and/or BZERO keywords are present, then the output array is scaled to
; floating point (unless /NOSCALE is present) using the values of BSCALE
; and BZERO. In the header, the values of BSCALE and BZERO are then
; reset to 1. and 0., while the original values are written into the
; new keywords O_BSCALE and O_BZERO. If the BLANK keyword was
; present, then any input integer values equal to BLANK in the input
; integer image are unchanged by BSCALE or BZERO
;
; (2) The use of the NSLICE keyword is incompatible with the NUMROW
; or STARTROW keywords.
;
; (3) READFITS() underwent a substantial rewrite in October 1998 to
; eliminate recursive calls, and improve efficiency when reading
; extensions.
; 1. The NUMROW and STARTROW keywords can now be used when reading
; a primary image (extension = 0).
; 2. There is no error check for moving past the end of file when
; reading the data array.
;
; (4) On some Unix shells, one may get a "Broken pipe" message if reading
; a compressed file, and not reading to the end of the file (i.e. the
; decompression has not gone to completion). This is an informative
; message only, and should not affect the output of READFITS.
; PROCEDURES USED:
; Functions: SXPAR(), WHERENAN()
; Procedures: IEEE_TO_HOST, SXADDPAR, SXDELPAR
;
; MODIFICATION HISTORY:
; Original Version written in 1988, W.B. Landsman Raytheon STX
; Revision History prior to June 1997 removed
; Recognize BSCALE, BZERO in IMAGE extensions WBL Jun-97
; Added NSLICE keyword WBL Jul-97
; Added ability to read heap area after extensions WBL Aug-97
; Suppress *all* nonfatal messages with /SILENT WBL Dec-97
; Converted to IDL V5.0 WBL Dec-1997
; Fix NaN assignment for int data C. Gehman/JPL Mar-98
; Fix bug with NaNvalue = 0.0 C. Gehman/JPL Mar-98
; Major rewrite to eliminate recursive calls when reading extensions
; W.B. Landsman Raytheon STX October 1998
; Add /binary modifier needed for Windows W. Landsman April 1999
; Read unsigned datatypes, added /no_unsigned W. Landsman December 1999
; Output BZERO = 0 for unsigned data types W. Landsman January 2000
; Open with /swap_if_little_endian if since V5.1 W. Landsman February 2000
; Fixed logic error when using NSLICE keyword W. Landsman March 2000
;-

rem_elem.pro

;+
; Name: rem_elem
;
; Purpose: return subscripts of input array remaining after elements in
; a second array are removed
;
; Input Parameters:
; inarray - array to search/remove from
; remarray - array of elements to search/remove from inarray
;
; Output Parameters:
; count - number of elements (subscripts) returned
;
; Calling Sequence:
; ss = rem_elem(inarray,remarray) ; subscripts remaining or -1
;
; History:
; slf, 20-jan-1993
; slf, 7-feb-1993 - documentation carification and variable name change
;-

reverse.pro

;+
; NAME:
; REVERSE
;
; PURPOSE:
; Reverse the order of rows or columns in an array or vector.
;
; CATEGORY:
; Array manipulation.
;
; CALLING SEQUENCE:
; Result = REVERSE(Array [, Subscript_Index])
;
; INPUTS:
; Array: The array or vector containing the original data.
;
; OPTIONAL INPUT PARAMETERS:
; Subscript_Index: If this parameter is omitted or 1, the first subscript is
; reversed (i.e., rows are reversed). Set this parameter to
; 2 to reverse columns.
;
; KEYWORD PARAMETERS:
; None.
;
; OUTPUTS:
; REVERSE returns a copy of the original array that is reversed about
; one of its dimensions.
;
; COMMON BLOCKS:
; None.
;
; SIDE EFFECTS:
; None.
;
; RESTRICTIONS:
; Only works for 1-, 2-, or 3-dimensional arrays.
;
; PROCEDURE:
; Uses the ROTATE function.
;
; MODIFICATION HISTORY:
; Old.
; Apr, 1991, DMS, Added 3D reversing.
; Sept, 1992 Mark L. Rivers, added simple return for scaler argument
;-

since_version.pro

;+
; Project : SOHO - CDS
;
; Name :
; SINCE_VERSION
;
; Purpose :
; Determine if current release is later than specified.
;
; Explanation :
; Determine if the current release of IDL (as given in the
; !VERSION.RELEASE system variable) comes after the user specified
; release.
;
; Use :
; test = SINCE_VERSION( release )
;
; Use the /FTOXDR keyword to the BYTEORDER procedure if the current
; release of IDL is 2.2.2 or later
;
; IDL> if since_version('2.2.2') then byteorder, a, /FTOXDR
;
; Inputs :
; release - scalar string, must be formatted exactly like the
; !VERSION.RELEASE system variable (e.g. '3.0.0')
;
; Opt. Inputs :
; None.
;
; Outputs :
; test - 1 if current release is identical or later than the specified
; 'release' else 0
;
; Opt. Outputs: None.
;
; Keywords : None.
;
; Calls : None.
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: None.
;
; Category : Utilities, Miscellaneous
;
; Prev. Hist. :
; Written Wayne Landsman Hughes/STX January, 1992
; Corrected algorithm W. Landsman April, 1992
;
; Written : Wayne Landsman, Hughes/STX, January 1992
;
; Modified : Version 1, William Thompson, GSFC, 14 December 1994
; Incorporated into CDS library
;
; Version : Version 1, 14 December 1994
;-

sswfits_struct.pro

;+
; Name: sswfits_struct
;
; Purpose: return "STANDARD" ssw structure (FITs->IDL mapping)
;
; Input Parameters:
; number (optional) - number structures returned - default is one
;
; Keyword Parameters:
; addfits - switch , if set, include FITS required minimal tags
;
; Calling Sequence:
; str=sswfits_struct( [number] [/addfits] )
;
; History:
; 15-jan-1997 - S.L. Freeland (from 'eit_struct.pro')
; 25-feb-1997 - SSW generic
; 10-apr-1998 - add CROTA (CED)
; 8-sep-1998 - add EXPTIME and WAVELNTH (CED)
; 15-oct-1998 - S.L.Freeland add SOLAR_L0, SOLAR_P, CROTA2,
; XCEN, YCEN
; /ADDFITS keyword and function - made version=2
; 4-Apr-2000 - Add CROTACN1 and CROTACN2 (floating)
;-

str2arr.pro

;+
;
; PROJECT: SSW
;
; NAME:
; STR2ARR
;
; PURPOSE:
; Convert delimited string into string array
;
; INPUT PARAMETERS:
; instring - delimited string to be split into components
; delim - delimiter to use (default=comma)
;
; OUTPUT:
; function output is string array, n_elements=number delimiters+1
;
; KEYWORD PARAMETERS:
; delimit - delimiter - equiv to positional DELIM; for backward compat.
; numult - switch, if set, dont return nulls for consecutive delimiters
; list - if set, display array to terminal (via more)
; array (output) - string array, number elements=number of delimeters+1
; (same as function output)
;
; CALLING SEQUENCE:
; array=STR2ARR(string [, delimiter, delimit=delimit, /nomult, /list]
;
; CALLING EXAMPLES:
; IDL> more,str2arr('this,is,a,test') ; default delim
; this ; (ie: comma)
; is
; a
; test
;
; IDL> more,str2arr('this$$$is$$$another$$$test','$$$') ; delim='$$$'
; this
; is
; a
; test
;
;
; COMMON BLOCKS;
; NONE
;
; MODIFICATION HISTORY:
; Version 0 - Sam Freeland (Yohkoh)
; slf - feature correction (occur is array, then prob.)
; slf - 25-feb-92 - added positional delim parameter
; slf - 2-feb-93 - changed recursion to loop for memory problems
; slf - 19-mar-93 - optimize case where delimiter is 1 character (comma)
; slf - 20-mar-93 - fixed a minor bug with major implications
; slf - 16-Jan-97 - merge Dave Pike (RAL) changes for SSW GEN
; (LIST and NOMULT keyword and function)
; slf - 8-may-97 - added to header
; Zarro (SM&A/GSFC), 14-Sep-99, threw in couple of temporary's for memory
;-

str2utc.pro

;+
; Project : SOHO - CDS
;
; Name : STR2UTC()
;
; Purpose : Parses UTC time strings.
;
; Explanation : This procedure parses UTC time strings to extract the date and
; time.
;
; Use : Result = STR2UTC( UTC )
; Result = STR2UTC( UTC, /EXTERNAL )
;
; Inputs : UTC = A character string containing the date and time. The
; target format is the CCSDS ASCII Calendar Segmented
; Time Code format (ISO 8601), e.g.
;
; "1988-01-18T17:20:43.123Z"
;
; The "Z" is optional. The month and day can be
; replaced with the day-of-year, e.g.
;
; "1988-018T17:20:43.123Z"
;
; Other variations include
;
; "1988-01-18T17:20:43.12345"
; "1988-01-18T17:20:43"
; "1988-01-18"
; "17:20:43.123"
;
; Also, the "T" can be replaced by a blank, and the
; dashes "-" can be replaced by a slash "/". This is
; the format used by the SOHO ECS. (Another optional
; format, as used at Wilcox observatory, is to replace
; the "T" with an underscore "_", and the dashes with
; periods.)
;
; In addition this routine can parse dates where only
; two digits of the year is given--the year is assumed
; to be between 1950 and 2049.
;
; Character string months, e.g. "JAN" or "January", can
; be used instead of the number. In that case, it
; assumes that the date is either in day-month-year or
; month-day-year format, e.g. "18-JAN-1988" or
; "Jan-18-1988". However, if the first parameter is
; four digits, then year-month-day is assumed, e.g.
; "1988-Jan-18".
;
; Dates in a different order than year-month-day are
; supported, but unless the month is given as a
; character string, then these are only supported
; through the /MDY and /DMY keywords.
;
; Opt. Inputs : None.
;
; Outputs : The result of the function is a structure containing the (long
; integer) tags:
;
; MJD: The Modified Julian Day number.
; TIME: The time of day, in milliseconds since the
; beginning of the day.
;
; Alternatively, if the EXTERNAL keyword is set, then the result
; is a structure with the elements YEAR, MONTH, DAY, HOUR,
; MINUTE, SECOND, and MILLISECOND.
;
; Any elements not found in the input character string will be
; set to zero.
;
; Opt. Outputs: None.
;
; Keywords : EXTERNAL = If set, then the output is in CDS external format,
; as described above.
;
; DMY = Normally the date is in the order year-month-day.
; However, if DMY is set then the order is
; day-month-year. Note that if the month is given as
; a character string, then the default is
; day-month-year.
;
; MDY = If set, then the date is in the order
; month-day-year.
;
; YMD = If set, then the date is in the order
; year-month-day.
;
; TEMPLATE = If set, then the first string in the input array UTC
; is used as a template for all the strings to follow.
; This speeds up processing of large string arrays.
; However, it requires that all the strings have
; *EXACTLY* the same format. In other words, all the
; date fields must be in exactly the same places, with
; exactly the same widths.
;
; If /TEMPLATE is not passed, then all the strings
; will be processed sequentially, which is slower but
; much safer.
;
; 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 = ''
; RESULT = STR2UTC( UTC, ERRMSG=ERRMSG )
; IF ERRMSG NE '' THEN ...
;
; Calls : DATATYPE, DATE2MJD, UTC2INT, MJD2DATE, VALID_NUM, BOOST_ARRAY
;
; Common : None.
;
; Restrictions: The components of the time should be separated by the colon ":"
; character, except between the seconds and fractional seconds
; parts, where the separator is the period "." character. As of
; version 21, the colon separator can be omitted, but this is not
; recommended.
;
; The components of the date must be separated by either the dash
; "-" or slash "/" character.
;
; The only spaces allowed are at the beginning or end of the
; string, or between the date and the time.
;
; This routine does not check to see if the dates entered are
; valid. For example, it would not object to the date
; "1993-February-31", even though there is no such date.
; In this case, the date would be converted to "1993-March-3".
;
; Side effects: If an error is encountered and the ERRMSG keyword is set,
; STR2UTC returns an integer scalar equal to -1.
;
; Category : Utilities, Time.
;
; Prev. Hist. : Part of the logic of this routine is taken from TIMSTR2EX by M.
; Morrison, LPARL. However, the behavior of this routine is
; different from the Yohkoh routine. Also, the concept of
; "internal" and "external" time is based in part on the Yohkoh
; software by M. Morrison and G. Linford, LPARL.
;
; Written : William Thompson, GSFC, 13 September 1993.
;
; Modified : Version 1, William Thompson, GSFC, 21 September 1993.
; Version 2, William Thompson, GSFC, 28 September 1993.
; Expanded the capabilities of this routine based on
; TIMSTR2EX.
; Version 3, William Thompson, GSFC, 20 October 1993.
; Corrected small bug when the time string contains
; fractional milliseconds, as suggested by Mark Hadfield,
; NIWA Oceanographic.
; Version 4, William Thompson, GSFC, 18 April 1994.
; Corrected bugs involved with passing arrays as
; input--routine was not calling itself reiteratively
; correctly.
; Version 5, Donald G. Luttermoser, GSFC/ARC, 28 December 1994
; Added the keyword ERRMSG.
; Version 6, William Thompson, GSFC, 25 January 1995
; Changed to call intrinsic ROUND instead of NINT. The
; version of NINT in the Astronomy User's Library doesn't
; automatically select between short and long integers as
; the CDS version does.
; Version 7, William Thompson, GSFC, 26 January 1995
; Modified to support VMS-style format.
; Made error-handling more robust.
; Version 8, Donald G. Luttermoser, GSFC/ARC, 30 January 1995
; Added ERRMSG keyword to internally called procedures.
; Note that this routine can handle both scalars and
; vectors as input.
; Version 9, William Thompson, GSFC, 2 February 1995
; Fixed bug with years input with two-digits.
; Version 10, William Thompson, GSFC, 22 March 1995
; Fixed bug when date string contains OCT in capital
; letters.
; Version 11, William Thompson, GSFC, 15 June 1995
; Modified so that the default behavior is different when
; the month is given as a character string. In that
; case, it now assumes that the year is the *last*
; parameter in the string unless given with all four
; digits.
; Version 12, William Thompson, GSFC, 19 June 1995
; Made logic used in version 11 more robust. Added
; keyword YMD.
; Version 13, William Thompson, GSFC, 6 October 1995
; Added ability to recognize strings that end in either
; AM or PM.
; Version 14, William Thompson, GSFC, 15 January 1996
; Extended bug fix of version 10 to "SEPT" and "AUGUST".
; Version 15, Dominic Zarro, GSFC, 15 January 1997
; Included input UTC string in output error message
; Version 16, William Thompson, GSFC, 27 January 1997
; Include support for Wilcox/MDI time format, e.g.
; "1988.01.18_17:20"
; Version 17, William Thompson, GSFC, 28 January 1997
; Allow for long input arrays.
; Version 18, William Thompson, GSFC, 7 February 1997
; Further refined support for Wilcox/MDI time format,
; allowing the string to end in _TAI or _UT.
; Version 19, William Thompson, GSFC, 30 September 1997
; Fixed bug involving times before dates, and month
; strings containing the letter T.
; Version 20, William Thompson, GSFC, 8 June 1999
; Avoid conflict with date.pro
; Version 21, 07-Apr-2000, William Thompson, GSFC
; Allow ":" to be omitted in time string.
; Call CHECK_EXT_TIME
; Version 22, 10-Apr-2000, William Thompson, GSFC
; Added keyword TEMPLATE
; Version 23, 28-Apr-2000, William Thompson, GSFC
; Fixed bug with /TEMPLATE and only dates, no times.
; Version 24, 30-Apr-2000, S.L.Freeland, LMSAL
; Made backwardly compatible with Version < 5
; Scalarize 1 element DAY/MONTH/YEAR
; Version 25, 1-May-2000, William Thompson, GSFC
; Corrected scalarization of YEAR/MONTH/DAY
; Version 26, 30-Jun-2000, William Thompson, GSFC
; Fixed bug with only hours, no minutes or seconds.
; Version 27, 05-Jul-2000, William Thompson, GSFC
; If no date passed, then use today.
;
; Version : Version 27, 05-Jul-2000
;-

strarrcompress.pro

;+
; Name: strarrcompress
;
; Purpose: remove null elements from string arrays (1D 2D)
;
; Input Paramters:
; strarray - string array
;
; Keyword Parameters:
; rows - switch (2D only) - if set, eliminate null rows
; columns - switch (2D only) - if set, eliminate null columns
; trim - if set, trim non-null elements (leading/trailing blanks)
;
; Calling Sequence:
; comparr=strarrcompress(strarr)
;
; History:
; 14-May-1996 - S.L.Freeland
;-

strep.pro

;+
; Project : SOHO - CDS
;
; Name : STREP
;
; Purpose : Replaces first occurrence of given string within a string.
;
; Explanation : Within the given string the routine will replace the first
; occurrence of the supplied substring with the requested
; replacement.
;
; eg. IDL> x = 'abcdefgcd'
; print, strep(x,'cd','qq') --> 'abqqefgcd'
;
; see also REPSTR() for replacement of all occurrences.
;
; Use : Result = output=strep(input,old,new,/all)
;
; Inputs :
; input=any string
; old=old characters
; new=new characters
;
; Opt. Inputs : None.
;
; Outputs : Result = new string.
;
; Opt. Outputs: None.
;
; Keywords : all = replace all characters
;
; Calls : uses STRMID
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: None.
;
; Category : String processing
;
; Prev. Hist. : None.
;
; Written : DMZ (ARC) August 1993
;
; Modified : Documentation header update. CDP, 26-Sep-94
;
; Version : Version 2, 26-Sep-94
; Version 3, 8-Jun-98, Zarro (SAC/GSFC) - added /compress
;-
;
FUNCTION strep,input,old,new,all=all,compress=compress
len=STRLEN(input) & p=STRPOS(input,old)

tnew=STRTRIM(new,2)
IF p EQ -1 THEN RETURN,input
leno=STRLEN(old)
lenn=STRLEN(tnew)

;-- buffer so that new string tailors with old string

strjustify.pro

;+
; Name: strjustify
;
; Purpose: left/right justify or center string array
;
; Input Parameters:
; inarry - string array input
;
; Output:
; return value is justified or centered version of inarry (padded)
;
; Keyword Parameters:
; left - switch, if set, left justify
; right - switch, if set, right justify
; center - switch, if set, center
; width - strlen of returned array (default is max(strlen(inarrary))
; pad - pad character (default is blank)
; boxtext = boxtext
;
; Calling Sequence:
; justtext=strjustify(text [,/left, /right, /center, /box, width=width]
; History:
; 16-May-1994 (SLF) Written
; 1-oct-1994 (SLF) add BOXTEXT keyword and fuction
; 14-apr-1995 (SLF) protect against scaler input
; 10-apr-1997 (SLF) protect against all null string input
;
;-

strlastchar.pro

;+
; Name: strlastchar
;
; Purpose: return last non-blank character(s) in a string or string array
;
; Input Parameters:
; array - string or string array
;
; Calling Sequence:
; lastchar=strlastchar(strarr)
;
; History:
; 29-jul-1995 (SLF)
;-

strnumber.pro

;+
; NAME:
; STRNUMBER
; PURPOSE:
; Function to determine if a string is a valid numeric value.
;
; CALLING SEQUENCE:
; result = strnumber( st, [val, /HEX] )
;
; INPUTS:
; st - any IDL scalar string
;
; OUTPUTS:
; 1 is returned as the function value if the string st has a
; valid numeric value, otherwise, 0 is returned.
;
; OPTIONAL OUTPUT:
; val - (optional) value of the string. real*8
;
; KEYWORDS:
; Hex - If present and nonzero, the string is treated as a hexadecimal
; longword integer.
;
; EXAMPLES:
; IDL> res = strnumber(' ',val)
; returns res=0 (not a number) and val is undefined
;
; IDL> res = strnumber('0.2d', val)
; returns res=1 (a valid number), and val = 0.2000d
;
; NOTES:
; (1) STRNUMBER was modified in February 1993 to include a special test for
; empty or null strings, which now returns a 0 (not a number). Without
; this special test, it was found that a empty string (' ') could corrupt
; the stack.
;
; (2) STRNUMBER will return a string such as '23.45uyrg' as a valid
; number (=23.45) since this is how IDL performs the type conversion. If
; you want a stricter definition of valid number then use the VALID_NUM
; function.
; HISTORY:
; version 1 By D. Lindler Aug. 1987
; test for empty string, W. Landsman February, 1993
; Converted to IDL V5.0 W. Landsman September 1997
; Hex keyword added. MRG, RITSS, 15 March 2000.
;-

strspecial.pro

;+
; Name: strspecial
;
; Purpose: return true if input is a 'special' character (or as defined by keyword)
;
; Input Parameters:
; strarray - scaler string or string array
;
; Output
; function returns truth value (VECTOR) , depending upon keyords set
;
; Keyword Parameters:
; lastchar (input) switch, look at LAST character (default is FIRST)
; firstchar (input) switch, look at FIRST character (default for arrays)
; digit - (input) switch, return TRUE where character in {0-9}
; alpha - (input) switch, return TRUE where character in {a-z, A-Z}
; lchar - (output) return LAST character array (last char in strarray)
; chkall - (input) strarray must be scaler - boolean for entire string
;
; Calling Sequence:
; truth=strspecial(arr) ; =1 where leading chars are special
; truth=strspecial(arr,/digit) ; =1 where leading chars in {0-9}
; truth=strspecial(arr,/alpha,/last); =1 where trailing chars in {a-z,A-Z}
;
; Sample Calls:
; A: Scaler input, no positional keywords (FIRSTCHAR & LASTCHAR)
; IDL> print,strspecial('*-TITLE-*') ; boolean for each character
; 1 1 0 0 0 0 0
; B: Scaler input w/ positional keyword
; IDL> print,strspecial('abcd1',/last,/digit) ; only first or last
; 1
; C: Array input (default looks at FIRSTCHAR of each element)
; IDL> print,strspecial(['abc','123','!@#'],/lastchar)
; 0 0 1
; History:
; 15-jul-1995
; 28-jul-1995 - add DIGIT, ALPHA, LASCHAR keywords
; 2-aug-1995 - added recursive segment for all characters of scaler
;
; Restrictions:
; just looks at FIRST or LAST characters if input is an ARRAY
; trailing blanks are not "special"
;
; Method: recursive for scaler strings
;-

strstat.pro

;+
; Name: strstat
;
; Purpose: check to see if the input structure name exists
;
; Input Parameters:
; strname = string containing structure name to check
;
; Optional Keyword Parameters:
; quiet - if keyword set then quietinformational messages are
; inhibited
;
; Output:
; function returns 1 if structure exists
; returns 0 if structure does not exist
;
; Side Effects:
; prints informational message if info is set
;
; History: SLF, 10/23/91 to allow make_str to avoid previously
; allocated names as occured when idl restore was used
;
;-

str_checks.pro

;+
; Name: str_checks
;
; Purpose: turn structure checks on or off (for make_str.pro)
;
; Keyword Parameters:
; on - if set, turns checking on (more diagnostic messages but avoids
; conflicts with idl save files)
; off - if set, turns checking off (quieter but may conflict with
; idl save files)
;
; History:
; slf, 3-feb-1993
; slf, 4-feb-1993 ; add diagnostics and quiet keyword
; slf,26-mar-1993 ; document inquire keyword
;
; Calling Sequence:
; str_checks ; enable checks (and noisy messages)
; str_checks,/on ; equivilent to above
; str_checks,/off ; disable checks
; str_checks,/inquire ; check flag state but dont change it
;
; Common Blocks:
; make_str_blk1
;
; Restrictions: uses common block - should be handled by system variable
; when system variable definitions are full integrated
;
;
;-

str_replace.pro

;+
; Name: str_replace
;
; Purpose: replace all occurences of a substring with a replacement
; if no replacement string is specified, a blank is inserted
;
; Input Parameters:
; source - source string
; insub - target string for replace
; outsub - replacement string
;
; History: slf, 11/19/91
; slf, 19-mar-93 ; optimize case where insub and outsub
; ; are each 1 character in length
; mdm, 21-Jul-97 ; patch to handle big arrays
; fz, 12-May-98 ; change loop variable to long
;-

sun_fake.pro



sxaddpar.pro

;+
; NAME:
; SXADDPAR
; PURPOSE:
; Add or modify a parameter in a FITS header array.
;
; CALLING SEQUENCE:
; sxaddpar, Header, Name, Value, [ Comment, Location,
; BEFORE =, AFTER = , FORMAT= , /PDU]
;
; INPUTS:
; Header = String array containing FITS or STSDAS header. The
; length of each element must be 80 characters. If not
; defined, then SXADDPAR 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 = '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.
;
; OPTIONAL INPUT PARAMETERS:
; Comment = String field. The '/' is added by this routine. Added
; starting in position 31. If not supplied, or set equal to
; '', then the previous comment field is retained (when found)
;
; Location = Keyword string name. The parameter will be placed before the
; location of this keyword. This parameter is identical to
; the BEFORE keyword and is kept only for consistency with
; earlier versions of SXADDPAR.
;
; OPTIONAL INPUT KEYWORD PARAMETERS:
; 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.
; /PDU = specifies keyword is to be added to the primary data unit
; header. If it already exists, it's current value is updated in
; the current position and it is not moved.
; OUTPUTS:
; Header = updated FITS header array.
;
; RESTRICTIONS:
; Warning -- Parameters and names are not checked
; against valid FITS parameter names, values and types.
;
; MODIFICATION HISTORY:
; DMS, RSI, July, 1983.
; D. Lindler Oct. 86 Added longer string value capability
; Converted to NEWIDL D. Lindler April 90
; Added Format keyword, J. Isensee, July, 1990
; Added keywords BEFORE and AFTER. K. Venkatakrishna, May '92
; Pad string values to at least 8 characters W. Landsman April 94
; Aug 95: added /PDU option and changed routine to update last occurence
; of an existing keyword (the one SXPAR reads) instead of the
; first occurence.
; Comment for string data can start after column 32 W. Landsman June 97
; Make sure closing quote supplied with string value W. Landsman June 98
; Converted to IDL V5.0 W. Landsman June 98
; Increase precision of default formatting of double precision floating
; point values. C. Gehman, JPL September 1998
;
;-

sxdelpar.pro



sxim_despike.pro

;+
; PROJECT:
; SXI-M Ground Data System
;
; NAME:
; SXIM_DESPIKE (function)
;
; PURPOSE:
; Remove spikes and particle tracks from SXI raw images.
;
; EXPLANATION:
; TBS
;
; CALLING SEQUENCE:
; result=sxim_despike,image,threshold
;
; INPUTS:
; image = 2-D image array (float or integer) to be cleaned
;
; OUTPUTS:
; result = Cleaned 2-D image array (float)
;
; OPTIONAL INPUT KEYWORDS:
; THRESHOLD = Median filter threshold for good pixel map
;
; EXTERNAL CALLS:
; TBS
;
; CALLED BY:
; SXIM_PREP
;
; METHOD:
; TBS
;
; HISTORY:
; Written by Steven Hill at NOAA/SEC, 5 May 2000
;
;-

sxim_lincal.pro

;+
; PROJECT:
; SXI-M Ground Data System
;
; NAME:
; SXIM_LINCAL
;
; PURPOSE:
; Remove line noise from SXI-M background images.
;
; EXPLANATION:
; TBS
;
; CALLING_SEQUENCE:
; TBS
;
; INPUTS:
; image = 512x512 integer image to be processed
;
; OUTPUTS:
; result = 512x512 floating point image with line noise removed.
;
; OPTIONAL INPUT KEYWORDS:
; N/A
;
; EXTERNAL CALLS:
; N/A
;
; CALLED BY:
; SXIM_PREP
;
; METHOD:
; TBS
; Note that this function should not be applied to solar images, only
; to background images.
;
; HISTORY:
; Written by Steven Hill at NOAA/SEC, 5 May 2000
;
;-

sxim_prep.pro

;+
; PROJECT:
; SXI-M Ground Data System
;
; NAME:
; SXIM_PREP
;
; PURPOSE:
; Apply corrections and calibrations to raw images.
;
; EXPLANATION:
; TBS
;
; CALLING SEQUENCE:
; sxim_prep,input_path,input_filename,output_path,output_filename,image_type, $
; short_dark_filename,long_dark_filename
;
; INPUTS:
; input_filename = name of level-0 FITS file to read (string)
; input_path = name of input directory (string)
;
; OUTPUTS:
; output_filename = name of level-1 FITS file to write
; output_path = name of output directory (string)
;
; OPTIONAL INPUT KEYWORDS:
; N/A
;
; EXTERNAL CALLS:
; FAKE_IMAGES,filename,fake,replace_file
; HEAD2STC,header (function)
; IMAGE_STATISTICS,image1 (function)
; MAKE_GIFS,image,index,image_type,image_level,gif,stamp
; READFITS,input_filename,header,exten_no=exten_no (function)
; SXI_021_HDR,input_header,master_header,statistics,image_type
; SXIM_FILL,image,counter1,counter2 (function)
; SXIM_DESPIKE,image0 (function)
; WRITEFITS,output_filename,image,header
;
; CALLED BY:
; SXIM_BATCH or operational Python code
;
; METHOD:
; TBS
;
; HISTORY:
; 001.001 Written by Steven Hill at NOAA/SEC 30 Jan 2001
; 001.002 Modified by Steven Hill at NOAA/SEC 28 Mar 2001
; Now use IDL 5.4 IMAGE_STATISTICS routine
; 001.003 Modified by SMH 4/4/2001
; Fake_images returns an image rather than rewriting
; level-0 FITS files for testing
; 001.004 Modified by SMH 4/6/2001
; Removed full path directories for flat file
; Added color to browse images
; 001.005 Modified by SMH 4/10/2001
; Removed file size checking as this is done above
; SXIM_PREP.PRO
; 001.006 Modified by SMH 5/03/2001
; Updated file name handling including milliseconds
; 001.007 Modified by SMH 7/10/2001
; Added image registration for L1 PNGs
; Added logic for missing dark frames
; 001.008 Modified by SMH 7/13/2001
; Added logic to verify background (dark) files
; 001.009 Modified by SMH 7/26/2001
; Use programmed MCP volts if TSYNC packet missing
; in Level-0 FITS input file.
; Also added configuration file for fake images and dark
; frame path.
; 003.000 Modified by SMH 8/6/2001
; Added IDL error reset if backgrounds aren't found by
; IDL code. This special handling simplifies python driver code.
;
;-

sxim_strsplit.pro

;+
; Name: strsplit
;
; Purpose: split string array at first (or last) occurence of pattern
;
; Input Paramters:
; inarry - initial string array to split
; pattern - search string (default is blank)
;
; Output:
; function return value is string array
;
; Calling Sequence:
; strarr=sxim_strsplit(inarray, pattern , tail=tail)
; strarr=sxim_strsplit(inarray, pattern , /tail, head=head)
;
; Calling Examples:
; head=sxim_strsplit(inarray, pattern)
; tail=sxim_strsplit(inarray, pattern, /tail)
;
; History:
; 13-Jan-1993 (SLF)
; 11-Mar-1993 (SLF) 'released'
; 10-jun-1994 (SLF) bug fix
;
;-

sxim_uniq.pro

;+
; NAME:
; UNIQ
;
; PURPOSE:
; Return the subscripts of the unique elements in an array.
;
; Note that repeated elements must be adjacent in order to be
; found. This routine is intended to be used with the SORT
; function. See the discussion of the IDX argument below.
;
; This command is inspired by the Unix uniq(1) command.
;
; CATEGORY:
; Array manipulation.
;
; CALLING SEQUENCE:
; UNIQ(Array [, Idx] [/first] )
;
; INPUTS:
; Array: The array to be scanned. The type and number of dimensions
; of the array are not important. The array must be sorted
; into monotonic order unless the optional parameter Idx is
; supplied.
;
; OPTIONAL INPUT PARAMETERS:
; IDX: This optional parameter is an array of indices into Array
; that order the elements into monotonic order.
; That is, the expression:
;
; Array(Idx)
;
; yields an array in which the elements of Array are
; rearranged into monotonic order. If the array is not
; already in monotonic order, use the command:
;
; UNIQ(Array, SORT(Array))
;
; The expression below finds the unique elements of an unsorted
; array:
;
; Array(UNIQ(Array, SORT(Array)))
;
; OUTPUTS:
; An array of indicies into ARRAY is returned. The expression:
;
; ARRAY(UNIQ(ARRAY))
;
; will be a copy of the sorted Array with duplicate adjacent
; elements removed.
;
; Optional Keyword Parameter:
; first - if set, return index of FIRST occurence for duplicates
; (default is LAST occurence)
;
; COMMON BLOCKS:
; None.
;
; MODIFICATION HISTORY:
; 29 July 1992, ACY - Corrected for case of all elements the same.
; 30 Aug 1994, SLF - added /first keyword
; 1 Sep 1994, MDM - Modified to return a vector for the case of
; a single element being returned (so it matches
; the pre IDL Ver 3.0 version of UNIQ)
; - Modified to return [0] for a scalar
; 10 Sep 1996, Zarro
; - modified to return 0 for a scalar and a scalar
; for single element being returned.
; 10 Oct 1996, Zarro
; - added OLDWAY keyword to return,[value] for scalar
; value
;-

sxi_021_hdr.pro

;+
; PROJECT:
; SXI-M Ground Data System
;
; NAME:
; SXI_021_HDR
;
; PURPOSE:
; Convert a Level-0 FITS header to a Level-1 FITS header.
; (Should be upgraded to use index structures rather than string arrays.)
;
; EXPLANATION:
; TBS
;
; CALLING SEQUENCE:
; SXI_021_HDR,hdr0,hdr1
;
; INPUTS:
; hdr0 = input header (level-0) as string array
; template = master header for level-1 as string array
;
; OUTPUTS:
; result=hdr1 = new level-1 header as string array
;
; OPTIONAL INPUT KEYWORDS:
; N/A
;
; EXTERNAL CALLS:
; SXI_SXMODPAR (special array input version of SXMODPAR)
;
; CALLED BY:
; SXIM_PREP
;
; METHOD:
; TBS
;
; HISTORY:
; Version 1.x
; Written by Steven Hill at NOAA/SEC 30 Jan 2001
; Modified by Steven Hill 14 Mar 2001 to really be only a header
; template loader.
;
;-;

sxi_interp.pro

;+
; Name : sxi_interp()
;
; Purpose: : do linear interpolation on each column of data in the
; 512x512 data array d1 (a Level-0 SXI FITS image array)
;
; Inputs : crit = Max number of -1 data points acceptable for
; interpolation to be done on a column
; d1 = Level-0 SXI FITS image array (512x512)
;
; Output : d2 = Resulting 512x512 array, containing interpolated
; data if interpolation was done, or median-smoothed
; d1 if not
; d3 = Number of pixels missing in d1
;
; Return value : Number of -1 data points that were replaced by
; interpolated values
;
; Contact : sgreer@sec.noaa.gov
; Modified : Steve Hill 14 Mar 2001 to include initial missing pixel count (d3)
;-

sxi_make_name.pro

;+
;
; Written by Steven M. Hill, NOAA/SEC, 5/3/2001
;-

sxi_parse_name.pro

;+
;-

sxi_sxmodpar.pro

;+
; NAME:
; SXI_SXMODPAR
; PURPOSE:
; Add or modify a parameter in a FITS header array.
;
; CALLING SEQUENCE:
; sxi_sxmodpar, Header, Name, Value, Comment, [ Location,
; BEFORE =, AFTER = , FORMAT= ]
;
; INPUTS:
; Header = String array containing FITS header. Max string length must be
; equal to 80. If not defined, then SXADDPAR 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 = '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.
;
; OPTIONAL INPUT PARAMETERS:
; Comment = String field. The '/' is added by this routine. Added
; starting in position 31. If not supplied, or set equal to
; '', then the previous comment field is retained (when found)
;
; Location = Keyword string name. The parameter will be placed before the
; location of this keyword. This parameter is identical to
; the BEFORE keyword and is kept only for consistency with
; earlier versions of SXADDPAR.
;
; OPTIONAL INPUT KEYWORD PARAMETERS:
; 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.
;
; OUTPUTS:
; Header = updated FITS header array.
;
; RESTRICTIONS:
; Warning -- Parameters and names are not checked
; against valid FITS parameter names, values and types.
;
; MODIFICATION HISTORY:
; DMS, RSI, July, 1983.
; D. Lindler Oct. 86 Added longer string value capability
; Converted to NEWIDL D. Lindler April 90
; Added Format keyword, J. Isensee, July, 1990
; Added keywords BEFORE and AFTER. K. Venkatakrishna, May '92
; Fix comment copy for VALUE extending beyond col 32, V J Pizzo, Mar '00
;-

sxpar.pro

;+
; NAME:
; SXPAR
; PURPOSE:
; Obtain the value of a parameter in a FITS header
;
; CALLING SEQUENCE:
; result = SXPAR( Hdr, Name, [ Abort, COUNT=, COMMENT =, /NoCONTINUE ])
;
; INPUTS:
; Hdr = FITS header array, (e.g. as returned by READFITS)
; string array, 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 INPUTS:
; ABORT - string specifying that SXPAR 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, SXPAR will return quietly with COUNT = 0
; (and !ERR = -1) if a keyword is not found.
;
; OPTIONAL INPUT KEYWORDS:
; /NOCONTINUE = If set, then continuation lines will not be read, even
; if present in the header
;
; OPTIONAL OUTPUT KEYWORDS:
; COUNT - Optional keyword to return a value equal to the number of
; parameters found by SXPAR, integer scalar
;
; COMMENT - Array of comments associated with the returned values
;
; OUTPUTS:
; Function value = value of parameter in header.
; If parameter is double precision, floating, long or string,
; the result is of that type. Apostrophes are stripped
; from strings. If the parameter is logical, 1b is
; returned for T, and 0b is returned for F.
; If Name was of form 'keyword*' then a vector of values
; are returned.
;
; SIDE EFFECTS:
; !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. The use of !ERR is deprecated, and
; instead the COUNT keyword is preferred
;
; If a keyword occurs more than once in a header, a warning is given,
; and the first occurence is used.
;
; EXAMPLES:
; Given a FITS header, h, return the values of all the NAXISi values
; into a vector. Then place the history records into a string vector.
;
; IDL> naxisi = sxpar( h ,'NAXIS*') ; Extract NAXISi value
; IDL> history = sxpar( h, 'HISTORY' ) ; Extract HISTORY records
;
; PROCEDURE:
; The first 8 chacters of each element of Hdr are searched for a
; match to Name. The value from the last 20 characters is returned.
; An error occurs if there is no parameter with the given name.
;
; If a numeric value has no decimal point it is returned as type
; LONG. If it contains more than 8 numerals, or contains the
; characters 'D' or 'E', then it is returned as type DOUBLE. Otherwise
; it is returned as type FLOAT. Very large integer values, outside
; the range of valid LONG, are returned as DOUBLE.
;
; 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.
;
; 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.
;
; PROCEDURES CALLED:
; GETTOK(), STRNUMBER(), VALID_NUM()
; MODIFICATION HISTORY:
; DMS, May, 1983, STPAR Written.
; D. Lindler Jan 90 added ABORT input parameter
; J. Isensee Jul,90 added COUNT keyword
; W. Thompson, Feb. 1992, added support for FITS complex values.
; W. Thompson, May 1992, corrected problem with HISTORY/COMMENT/blank
; keywords, and complex value error correction.
; W. Landsman, November 1994, fix case where NAME is an empty string
; W. Landsman, March 1995, Added COMMENT keyword, ability to read
; values longer than 20 character
; W. Landsman, July 1995, Removed /NOZERO from MAKE_ARRAY call
; T. Beck May 1998, Return logical as type BYTE
; W. Landsman May 1998, Make sure integer values are within range of LONG
; Converted to IDL V5.0, May 1998
; W. Landsman Feb 1998, Recognize CONTINUE convention
; W. Landsman Oct 1999, Recognize numbers such as 1E-10 as floating point
; W. Landsman Jan 2000, Only accept integer N values when name = keywordN
;-

tag_exist.pro

;+
; Project : SOHO - CDS
;
; Name : TAG_EXIST()
;
; Purpose : To test whether a tag name exists in a structure.
;
; Explanation : Routine obtains a list of tagnames and tests whether the
; requested one exists or not. The search is recursive so
; if any tag names in the structure are themselves structures
; the search drops down to that level. (However, see the keyword
; TOP_LEVEL).
;
; Use : IDL> status = tag_exist(str, tag)
;
; Inputs : str - structure variable to search
; tag - tag name to search for
;
; Opt. Inputs : None
;
; Outputs : Function returns 1 if tag name exists or 0 if it does not.
;
; Opt. Outputs: None
;
; Keywords : INDEX = Index of matching tag
;
; TOP_LEVEL = If set, then only the top level of the structure is
; searched.
;
; Category : Util, structure
;
; Written : C D Pike, RAL, 18-May-94
;
; Modified : Version 1.1, D Zarro, ARC/GSFC, 27-Jan-95
; Passed out index of matching tag
; Version 2, William Thompson, GSFC, 6 March 1996
; Added keyword TOP_LEVEL
; Version 2.1, Zarro, GSFC, 1 August 1996
; Added call to help
; Version 3, Zarro, EIT/GSFC, 3 June 2000
; added check for input array structure
; Version 4, Zarro, EIT/GSFC, 23 Aug 2000
; removed calls to DATATYPE
; Version 5, Zarro, EIT/GSFC, 29 Sept 2000
; added /quiet
;-

tag_index.pro

;+
; Name: tag_index
;
; Purpsose: return tag position (index) of 'tag' within 'str'
;
; Input Parameters:
; str - structure
; tag - tag name (string scaler or vector )
;
; Output:
; function returns indices of tag within str (-1 if not found)
; longword scaler returned if tag is scaler, else longword vector
;
; History: slf
; modified, 21-feb-92 for to allow tag vector
;-

tai2utc.pro

;+
; Project : SOHO - CDS
;
; Name : TAI2UTC()
;
; Purpose : Converts TAI time in seconds to UTC calendar time.
;
; Explanation : This procedure takes the Atomic International Time (TAI)
; calculated from the 6 byte (local) on-board time from the
; spacecraft and converts it into UTC calendar time in one of the
; CDS standard formats -- for acceptable formats see file
; aaareadme.txt.
;
; Use : Result = TAI2UTC( TAI )
; Result = TAI2UTC( TAI, /EXTERNAL )
; Result = TAI2UTC( TAI, /CCSDS )
; Result = TAI2UTC( TAI, /ECS )
;
; Inputs : TAI = The time in seconds from midnight, 1 January 1958.
; This should be a double precision array. Any
; necessary calibrations should be applied before
; calling this routine.
;
; Opt. Inputs : None.
;
; Outputs : The result of the function will be the UTC calendar time in one
; of several formats, depending on the keywords passed.
;
; Internal: A structure containing the tags:
;
; MJD: The Modified Julian Day number.
; TIME: The time of day, in milliseconds since
; the beginning of the day.
;
; Both are long integers. This is the default
; format.
;
; External: A structure containing the integer tags
; YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, and
; MILLISECOND.
;
; CCSDS: An ASCII string containing the UTC time to
; millisecond accuracy in the format
; recommended by the Consultative Committee
; for Space Data Systems (ISO 8601), e.g.
;
; "1988-01-18T17:20:43.123Z"
;
; ECS: Similar to CCSDS, except that the date has
; the format:
;
; "1988/01/18 17:20:43.123"
;
; VMS: The date and time has the format
;
; "18-JAN-1988 17:20:43.123"
;
; STIME: The date and time has the format
;
; "18-JAN-1988 17:20:43.12"
;
; See UTC2STR for more information.
;
; Opt. Outputs: None.
;
; Keywords : EXTERNAL = If set, then the output is in external format, as
; explained above.
;
; CCSDS = If set, then the output is in CCSDS format, as
; explained above.
;
; ECS = If set, then the output is in ECS format, as
; explained above.
;
; VMS = If set, then the output will be in VMS format, as
; described above.
;
; STIME = If set, then the output will be in STIME format, as
; described above.
;
; The following keywords are only valid if one of the string
; formats is selected.
;
; TRUNCATE = If set, then the time will be truncated to 1 second
; accuracy. Note that this is not the same thing as
; rounding off to the nearest second, but is a
; rounding down.
;
; DATE_ONLY = If set, then only the date part of the string is
; returned.
;
; TIME_ONLY = If set, then only the time part of the string is
; returned.
;
; UPPERCASE = If set, then the month field in either the VMS or
; STIME format is returned as uppercase.
;
; NOZ = When set, the "Z" delimiter (which denotes UTC
; time) is left off the end of the CCSDS/ISO-8601
; string format. It was decided by the FITS
; committee to not append the "Z" in standard FITS
; keywords.
;
; The following keyword is always valid.
;
; 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 = ''
; RESULT = TAI2UTC( TAI, ERRMSG=ERRMSG )
; IF ERRMSG NE '' THEN ...
;
; Calls : DATATYPE, GET_LEAP_SEC, INT2UTC
;
; 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: The result of an array with a single element may be a scalar.
; If an error has been encountered and the ERRMSG keyword has
; been set, TAI2UTC returns an integer value of -1.
;
; Category : Utilities, Time.
;
; Prev. Hist. : None. However, the concept of "internal" and "external" time
; is based in part on the Yohkoh software by M. Morrison and G.
; Linford, LPARL.
;
; Written : William Thompson, GSFC, 12 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, William Thompson, GSFC, 20 December 1994
; Added keywords TRUNCATE, DATE_ONLY, TIME_ONLY
; Version 4, Donald G. Luttermoser, GSFC/ARC, 28 December 1994
; Added the keyword ERRMSG.
; Version 5, William Thompson, GSFC, 25 January 1995
; Changed to call intrinsic ROUND instead of NINT. The
; version of NINT in the Astronomy User's Library doesn't
; automatically select between short and long integers as
; the CDS version does.
; Version 6, Donald G. Luttermoser, GSFC/ARC, 30 January 1995
; Added ERRMSG keyword to internally called procedures.
; Made error handling procedure more robust. Note
; that this routine can handle both scalars and vectors
; as input.
; Version 7, William Thompson, GSFC, 14 March 1995
; Added keywords VMS, STIME, UPPERCASE
; Version 8, William Thompson, GSFC, 28 January 1997
; Allow for long input arrays.
;
; Version : Version 8, 28 January 1997
;-

test_dir.pro

;+
; Project : SOHO-CDS
;
; Name : TEST_DIR
;
; Purpose : Test that a directory exists and is writable
;
; Category : Utility
;
; Explanation :
;
; Syntax : status=test_dir(dir_name)
;
; Examples :
;
; Inputs : DIR_NAME = directory name to check
;
; Opt. Inputs : None
;
; Outputs : status = 1/0 if success/fail
;
; Keywords : ERR = output messages
; QUIET = turn off printing output messages
; COUNT = # of valid directories
;
; History : Written 14 May 1998 D. Zarro, SAC/GSFC
; Modified 14 March 2000, Zarro (SM&A/GSFC) - vectorized
;
; Contact : dzarro@solar.stanford.edu
;-

function test_dir,dir_name,out=out,quiet=quiet,err=err,count=count

;-- use recursion for vector inputs

test_open.pro

;+
; Project : SOHO - CDS
;
; Name : TEST_OPEN
;
; Purpose : Test open a file to determine existence and/or write access
;
; Explanation :
; Uses OPENR or OPENW (if /WRITE is set) to return status of
; input file. If input file is not given, then TEST_OPEN will
; test if the current directory is writeable.
; Use :
; OK=TEST_OPEN(FILE) ;test for existence
; OK=TEST_OPEN(FILE,/WRITE) ;test for write access
; Inputs :
; FILE = file to test
; Opt. Inputs :
; None.
; Outputs :
; OK = logical 1 for existence and readable
; or 0 for nonexistent and/or not writeable (if /WRITE)
; Opt. Outputs:
; None.
; Keywords :
; WRITE = If set, then test for write access.
; QUIET = set to keep quiet
; NODIR = do not test if input is a directory (for speed)
; ERR = error string
; Category :
; Utilities, Operating_system.
; Written :
; Dominic Zarro, GSFC, 1993.
; Version :
; Version 1, 1 August 1993.
; Version 2, 15 March 1995, modified, Zarro
; -- added check for directory input
; Version 3, 3 September 1996, Zarro
; -- added VMS check for non-existent file input
; Version 4, 2-Feb-1999, Zarro (SM&A) - check for scalar input
; Version 5, 7-Oct-1999, Zarro (SM&A) - vectorized
; Version 6, 17-Nov-1999, Zarro (SM&A) - added CATCH, and
; randomized temporary files.
; Version 7, 18-Dec-2000, Zarro (EIT/GSFC) - allowed checking
; current directory write access when input is undefined.
;-

function test_open,file,write=write,quiet=quiet,nodir=nodir,err=err


err=''
ok=0b
np=n_elements(file)

if np gt 1 then begin
ok=bytarr(np)
for i=0,np-1 do begin
ok(i)=test_open(file(i),write=write,quiet=quiet,nodir=nodir,err=terr)
err=trim(err+' '+terr)
endfor
return,ok
endif

if (n_params() eq 0) and (1-keyword_set(write)) then begin
err='Undefined input'
message,err,/cont
return,0b
endif

if datatype(file) ne 'STR' then is_direc=1 else begin
if not keyword_set(nodir) then is_direc=is_dir(file,out=out) else is_direc=0
endelse

if is_direc then begin
del=1b & app=0b & temp=''
if keyword_set(write) then temp='test_open.'+get_rid()
if datatype(out) eq 'STR' then temp=concat_dir(out,temp)
endif else begin
del=0b & app=1b & temp=file
if keyword_set(write) then begin
if not test_open(temp) then del=1b
endif
endelse

;-- set some traps. First check for I/O errors, then anything else.

error=0
on_ioerror,trap

if error ne 0 then begin
trap:
on_ioerror,null
ok=0b
goto,cleanup
endif

;-- use Catch for IDL versions >= 4

tracks.pro



trim.pro

;+
; NAME:
; TRIM()
; PURPOSE:
; Converts numbers to strings, without trailing zeros.
; EXPLANATION:
; Converts numbers into a string representation, and trims off leading
; and/or trailing blanks. Differs from STRTRIM in that trailing zeros
; after the period are also trimmed off, unless NUMBER is already a
; string, or an explicit format is passed.
; CALLING SEQUENCE:
; Result = TRIM( NUMBER [, FORMAT ] [, FLAG ] )
; INPUTS:
; NUMBER = Scalar variable or constant. May be of any ordinary type,
; including string. However, structures are not allowed.
; OPTIONAL INPUTS :
; FORMAT - Format specification for STRING function. Must be a string
; variable, start with the "(" character, end with the ")"
; character, and be a valid FORTRAN format specification. If
; NUMBER is complex, then FORMAT will be applied separately to
; the real and imaginary parts.
;
; FLAG - Flag passed to STRTRIM to control the type of trimming:
;
; FLAG = 0 Trim trailing blanks.
; FLAG = 1 Trim leading blanks.
; FLAG = 2 Trim both leading and trailing blanks.
;
; The default value is 2. If NUMBER is complex, then FORMAT
; will be applied separately to the real and imaginary parts.
;
; OUTPUTS:
; Function returns as a string variable representing the value NUMBER.
; RESTRICTIONS:
; NUMBER must not be an array. NUMBER must not be a structure.
; FORMAT must be a valid format specification, and must not be passed
; if NUMBER is of type string.
; FLAG must not be of string type, or an array.
; PROCEDURES USED:
; None
; REVISION HISTORY:
; Version 1, William Thompson, GSFC, 9 April 1993,
; Transferred from Solar Library, W. Landsman September 1997
; Updated parentheses to V5.0, W. Landsman September 1997
; Added check for undefined input D. Zarro December 1998
;-

utc2int.pro

;+
; Project : SOHO - CDS
;
; Name : UTC2INT()
;
; Purpose : Converts CCSDS calendar time to internal format.
;
; Explanation : This procedure converts Coordinated Universal Time (UTC)
; calendar time, as either a seven element structure variable, or
; in the CCSDS/ISO 8601 ASCII calendar format, into CDS internal
; format. For notes on various time formats, see file
; aaareadme.txt.
;
; Use : Result = UTC2INT( UTC )
;
; Inputs : UTC = This can either be a structure with the tags YEAR,
; MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, or a
; character string in CCSDS/ISO 8601 format, e.g.
;
; "1988-01-18T17:20:43.123Z"
;
; or one of it's variants--see STR2UTC for more
; details.
;
; Opt. Inputs : None.
;
; Outputs : The result of the function is a structure with the tags:
;
; MJD = The Modified Julian Day number
; TIME = The time of day, in milliseconds since the
; start of 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 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 = ''
; RESULT = UTC2INT( UTC, ERRMSG=ERRMSG )
; IF ERRMSG NE '' THEN ...
;
; Calls : DATATYPE, DATE2MJD, STR2UTC
;
; Common : None.
;
; Restrictions: None.
;
; Side effects: If an error is encountered and the ERRMSG keyword is set,
; UTC2INT returns an integer scalar equal to -1.
;
; Category : None.
;
; Prev. Hist. : None. However, the concept of "internal" and "external" time
; is based in part on the Yohkoh software by M. Morrison and G.
; Linford, LPARL.
;
; Written : William Thompson, GSFC, 13 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, 3 January 1995
; Added the keyword ERRMSG. Check to see if the input
; structure (if sent) has 2 or 7 tags. If 2 tags (MJD &
; TIME), this procedure returns the input variable with
; no changes (i.e., already in CDS internal format).
; Version 4, Donald G. Luttermoser, GSFC/ARC, 30 January 1995
; Added ERRMSG keyword to internally called procedures.
; Made error handling routine more robust. Note that
; this procedure allows both scalars and vectors as
; input.
; Version 5, William Thompson, GSFC/SAC, 17 September 1997
; Fix bug where the time 23:60:00 or 24:00:00 would be
; misinterpreted as 23:59:60 on days containing leap
; seconds. Include call to CHECK_INT_TIME.
;
; Version : Version 5, 17-Sep-1997
;-

utc2sec.pro

;+
; Project : SOHO - CDS
;
; Name : UTC2SEC()
;
; Purpose : Converts CDS UTC time format to seconds since MJD=0.
;
; Explanation : Used in the UTPLOT programs, this function converts CDS
; internal UTC format to seconds since MJD=0.
; It takes no account of leap seconds.
; For notes on various time formats, see file aaareadme.txt.
;
; Use : IDL> sec = utc2sec(str)
;
; Inputs : str - structure variable containing UTC time format
;
; Opt. Inputs : None
;
; Outputs : Function returns seconds elapsed since MJD=0.
;
; 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 = ''
; RESULT = UTC2SEC( STR, ERRMSG=ERRMSG )
; IF ERRMSG NE '' THEN ...
;
; Calls : None
;
; Common : None
;
; Restrictions: No account is taken of leap seconds.
;
; Side effects: If an error is encountered and the ERRMSG keyword is set,
; UTC2SEC returns an integer scalar equal to -1.
;
; Category : Util, time
;
; Prev. Hist. : None
;
; Written : C D Pike, RAL, 20-Apr-94
;
; Modified : Version 1, C D Pike, RAL, 20-Apr-94
; Version 2, William Thompson, GSFC, 14 November 1994
; Changed .DAY to .MJD
; Version 3, Donald G. Luttermoser, GSFC/ARC, 3 January 1995
; Added the keyword ERRMSG. Added ON_ERROR,2 flag.
; Allow for input of EXTERNAL format of UTC.
; Version 4, 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 routine can handle both scalars and vectors
; as input.
;
; Version : Version 4, 30 January 1995
;-

utc2tai.pro

;+
; Project : SOHO - CDS
;
; Name : UTC2TAI()
;
; Purpose : Converts UTC calendar time to TAI.
;
; Explanation : This procedure converts Coordinated Universal Time (UTC)
; calendar time, in one of the CDS formats into Atomic
; International Time (TAI). For notes on various time formats,
; see file aaareadme.txt.
;
; Use : Result = UTC2TAI( UTC )
;
; Inputs : UTC = Coordinated Universal Time, in one of the following
; formats:
;
; Internal: A structure containing the tags:
;
; MJD: The Modified Julian Day number.
; TIME: The time of day, in milliseconds since
; the beginning of the day.
;
; Both are long integers.
;
; External: A structure containing the integer tags
; YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, and
; MILLISECOND.
;
; CCSDS: An ASCII string containing the UTC time to
; millisecond accuracy in the format
; recommended by the Consultative Committee
; for Space Data Systems (ISO 8601), e.g.
;
; "1988-01-18T17:20:43.123Z"
;
; or one of its variants--see STR2UTC for
; more details.
;
; Opt. Inputs : None.
;
; Outputs : The result of the function is the Atomic International Time
; calculated from the date and time, in seconds from midnight on
; 1 January 1958.
;
; Opt. Outputs: None.
;
; Keywords : NOCORRECT = If set, then the time will be assumed to be already
; a TAI value, even though apparently in UTC format,
; and no adjustment will be made for leap seconds.
;
; 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 = ''
; RESULT = UTC2TAI( UTC, ERRMSG=ERRMSG )
; IF ERRMSG NE '' THEN ...
;
; Calls : DATATYPE, GET_LEAP_SEC, STR2UTC, UTC2INT
;
; 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: If an error is encountered and the ERRMSG keyword is set,
; UTC2TAI returns an integer scalar equal to -1.
;
; Category : None.
;
; Prev. Hist. : None. However, the concept of "internal" and "external" time
; is based in part on the Yohkoh software by M. Morrison and G.
; Linford, LPARL.
;
; Written : William Thompson, GSFC, 13 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, 3 January 1995
; 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 routine more robust. Note
; that this procedure can handle both scalars and
; vectors as input.
; Version 5, William Thompson, GSFC, 28 January 1997
; Allow for long input arrays.
; Version 6, William Thompson, GSFC, 7 February 1997
; Added keyword NOCORRECT
;
; Version : Version 6, 7 February 1997
;-

valid_num.pro

;+
; Project : SOHO - CDS
;
; Name : VALID_NUM()
;
; Purpose : Check if a string is a valid number representation.
;
; Explanation : The input string is parsed for characters that may possibly
; form a valid number. It is more robust than simply checking
; for an IDL conversion error because that allows strings such
; as '22.3qwert' to be returned as the valid number 22.3
; See also the original NUM_CHK which returns the status in
; the opposite sense.
;
; Use : IDL> status = valid_num(string [,value] [,/integer])
;
; Inputs : string - the string to be tested
;
; Opt. Inputs : None
;
; Outputs : The function returns 1 for valid, 0 for invalid number
;
; Opt. Outputs: value - The value the string decodes to. This will be
; returned as a double precision number unless /INTEGER
; is present, in which case a long integer is returned.
;
; Keywords : Integer - if present code checks specfically for an integer.
;
; Calls : None
;
; Restrictions: None
;
; Side effects: None
;
; Category : Utilities, Numerical
;
; Prev. Hist. : Small changes from NUM_CHK by Andrew Bowen,
; Tessella Support Services, 8/3/93
;
; Written : CDS version by C D Pike, RAL, 24-May-93
;
; Modified : Version 1, C D Pike, RAL, 24-May-93
; Version 2, William Thompson, GSFC, 14 October 1994
; Added optional output parameter VALUE to allow
; VALID_NUM to replace STRNUMBER in FITS routines.
;
; Version : Version 1 24-May-93
; Converted to IDL V5.0 W. Landsman September 1997
;-

vertical_check.pro

;+
; Name : vertical_check()
;
; Purpose: : determine good (non -1) endpoint locations in a data
; vector of 512 elements (-1 indicates missing data)
;
; Inputs : crit = Max number of -1 data points acceptable for
; return value to be 1
; d = data vector
;
; Outputs : y1 = first non -1 data value location in d
; : y2 = last non -1 data value location in d
;
; Return value :
; 1 = Usable y1 and y2 values are returned.
; 2 = The number of -1 data values exceeded crit.
; 3 = The data vector had no -1 data values.
;
; Contact : sgreer@sec.noaa.gov
;-

wc_where.pro

;+
; Name: wc_where
;
; Purpose: return subscripts of input array where a pattern match is
; found - allows use of multiple wild card characters (*)
;
; Input Paramters:
; inarray - string array to search
; inpattern - string (scaler) to match - may include wild cards (*)
;
; Output:
; function returns subscripts of inarray where match found (-1 if none)
; mcount - number of matches found
;
; Calling Examples:
; ss=wc_where(files_arr,'*9201*',mcount)
; ss=wc_where(files_arr,'sfr*1230*')
; ss=wc_where(routine_arr,'*time*.pro',mcount)
;
; History:
; slf, 8-Jan-1993
; slf,13-Jan-1993 - patched last segment logic
; slf,15-Jan-1993 - added case_ignore keyword
; slf,12-apr-1993 - dont clobber pattern via case_ignore
; slf,17-feb-1994 - fix bug in last segment logic
; slf,30-jun-1994 - call wc_whereq if pattern has embedded "?" character
;
;-

where_negzero.pro

;+
; NAME:
; WHERE_NEGZERO()
;
; PURPOSE:
; Find positions of IEEE -0.0 values.
;
; EXPLANATION :
; Finds the positions of all values within an array that correspond to the
; IEEE value -0.0, as determined from the bit pattern. Prior to IDL V5.1,
; the VMS operating system had trouble coping with these values. If using
; any other operating system, then no action is performed.
;
; CALLING SEQUENCE:
; Result = WHERE_NEGZERO( ARRAY [, COUNT, /QUIET ] )
;
; INPUTS:
; ARRAY = Array to test against the IEEE -0.0 value. Must be
; either floating point or double-precision.
;
; OUTPUTS:
; The result of the function is the indices of all values of
; ARRAY corresponding to the IEEE -0.0 value, similar to the IDL
; WHERE function.
;
; OPTIONAL OUTPUT:
; COUNT = Number of values found corresponding to IEEE -0.0.
;
; OPTIONAL INPUT KEYWORD:
; /QUIET = If set, then warning messages are not printed out.
;
; RESTRICTIONS:
; ARRAY must be of type float or double-precision.
;
; SIDE EFFECTS:
; If no -0.0 values are found, or if ARRAY is not of type float,
; or double precision, or if the operating system is something
; other than VMS, then -1 is returned, and COUNT is set to 0.
;
; REVISION HISTORY:
; Written, 31-Jan-1997, William Thompson, GSFC
; Converted to IDL V5.0 W. Landsman September 1997
;-

writefits.pro

;+
; NAME:
; WRITEFITS
; PURPOSE:
; Write IDL array and header variables to a disk FITS file.
;
; EXPLANATION:
; A minimal FITS header is created if not supplied.
; WRITEFITS works for all types of FITS files except random groups
;
; CALLING SEQUENCE:
; WRITEFITS, filename, data [, header, NaNvalue = , /APPEND]
;
; INPUTS:
; FILENAME = String containing the name of the file to be written.
;
; DATA = Image array to be written to FITS file. If DATA is
; undefined or a scalar, then only the FITS header (which
; must have NAXIS = 0) will be written to disk
;
; OPTIONAL INPUT:
; HEADER = String array containing the header for the FITS file.
; If variable HEADER is not given, the program will generate
; a minimal FITS header.
;
; OPTIONAL INPUT KEYWORD:
; NaNvalue - Value in the data array to be set to the IEEE NaN
; condition. This is the FITS representation of undefined
; values
; APPEND - If this keyword is set then the supplied header and data
; array are assumed to be an extension and are appended onto
; the end of an existing FITS file. Note that the primary
; header in the existing file must already have an EXTEND
; keyword to indicate the presence of an FITS extension.
;
; OUTPUTS:
; None
;
; RESTRICTIONS:
; (1) It recommended that BSCALE and BZERO not be used (or set equal
; to 1. and 0) with REAL*4 or REAL*8 data.
; (2) WRITEFITS will remove any group parameters from the FITS header
;
; EXAMPLE:
; Write a randomn 50 x 50 array as a FITS file creating a minimal header.
;
; IDL> im = randomn(seed, 50, 50) ;Create array
; IDL> writefits, 'test', im ;Write to a FITS file "test"
;
; PROCEDURES USED:
; CHECK_FITS, HEADFITS(), HOST_TO_IEEE, IS_IEEE_BIG(), MKHDR, SXDELPAR,
; SXADDPAR, SXPAR()
;
; MODIFICATION HISTORY:
; WRITTEN, Jim Wofford, January, 29 1989
; MODIFIED, Wayne Landsman, added BITPIX = -32,-64 support for UNIX
; Use new BYTEODER keywords 22-Feb-92
; Modify OPENW for V3.0.0 W. Landsman Dec 92
; Work for "windows" R. Isaacman Jan 93
; More checks for null data Mar 94
; Work for Linux W. Landsman Sep 95
; Added call to IS_IEEE_BIG() W. Landsman Apr 96
; Make sure SIMPLE is written in first line of header W. Landsman Jun 97
; Use SYSTIME() instead of !STIME W. Landsman July 97
; Create a default image extension header if needed W. Landsman June 98
; Converted to IDL V5.0 W. Landsman June 98
; Write unsigned data types W. Landsman December 1999
;-

write_dir.pro

;+
; Project : HESSI
;
; Name : WRITE_DIR
;
; Purpose : platform/OS independent check if directory as write permission
;
; Category : system utility
;
; Explanation : uses 'openw'
;
; Syntax : IDL> a=write_dir(name)
;
; Examples :
;
; Inputs : NAME = directory name to check
;
; Opt. Inputs : None
;
; Outputs : 1/0 if success/failure
;
; Opt. Outputs: None
;
; Keywords : None
;
; Restrictions: Probably works in Windows
;
;
; History : Written, 6-June-1999, Zarro (SM&A/GSFC)
; Modified, 29-Nov-1999, Zarro - added call to TEST_OPEN
; Modfiied, 13-Mar-2000, Zarro - vectorized
;
; Contact : dzarro@solar.stanford.edu
;-