smei_base $SSW_SMEI_UCSD/camera/for/base/smei_base.f
[Next]
 NAME:
	smei_base
 PURPOSE:
	Determines pedestal & dark current, finds measles
 CALLING SEQUENCE:
	program smei_base
 INPUTS:
	SMEI data frames read from specified source (usually the
	SMEI frame data base)

	smei_base -start_time=<start_time> -stop_time=<stop_time>
		-camera=<1,2,3> [NOT YET: -mode=<0,1,2>]
		-source=<source> -destination=<destination>

	<start_time> and <stop_time> bracket the time period to be processed.
	The times are specified either as orbit numbers or as a UT time in the
	format YYYY_DOY_hhmmss (i.e. the standard SMEI time format).
	<start_time> MUST be specified. If <stop_time> is not specified than a
	single orbit starting at <start_time> is processed.

	The camera number (1,2 or 3) MUST be specified.

	<source> is the source directory where SMEI frames are picked up.

	<destination> is the destination directory for the updated SMEI frames
 OUTPUTS:
	Updated SMEI frames as Fits files in <destination>
 INCLUDE:
	include		'openfile.h'
	include		'smei_frm_layout.h'
	include		'smei_frm_basepar.h'
	include		'smei_frm_hdr.h'
	include		'math.h'
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'filparts.h'
 CALLS: ***
	ArrR4AddConstant, ArrR4Copy, ArrR4Mask, ArrR4Mean, BadI4, BadR4, BadR4Test
	ForeignArgSet, ForeignI4Arg, ForeignR4Arg, Int2Str, Say, Str2Str, Time2Str, bOpenFile
	cDbl2Str, cHideLogical, iFilePath, iFreeLun, iGetFileSpec, iOSDeleteFile [1]
	iOSDeleteFile [2], iOSDeleteFile [3], iOSDeleteFile [4], iScratchLun
	iSetFileSpec, itrim, smei_Time2Split, smei_cal_get, smei_cal_init, smei_foreign
	smei_frm_base, smei_frm_c3fudge, smei_frm_c3mask_active, smei_frm_clean
	smei_frm_fts, smei_frm_getlist, smei_frm_measle, smei_frm_pickup, smei_frm_read
	smei_frm_saturated, smei_frm_stats, smei_frm_write, smei_hdr_str
	smei_orb_mkname
 PROCEDURE:
	smei_base is run on every individual SMEI frame to fill in three groups
	of header entries in the Fits header:

	1) base-related entries (pedestal, dark current, pattern names, etc.)
	2) optical axis entries (RA, Dec, and PA)
	   These depend on the Coriolis sky-to-spacecraft quaternions and
	   on the fixed camera-to-spacecraft quaternions
	3) unit vectors for Sun, Moon, Venus in the UCSD camera frame, and
	   eclipse information. These depend on the Coriolis orbital
	   elements and the quaternions.

	If smei_base is first run on a .nic.gz file (which does not contain
	any of the above information) all header entries are calculated
	and a new .fts.gz file is created (i.e. both header and data frame
	are written). This will happen in the conversion of the SMEI
	data base from .nic.gz to .fts.gz files.

	As of Mar-2005 we do not produce .nic.gz files from the
	real-time SMEI data, but create .fts.gz files instead with the
	flag SMEI__HDR_BASE_DONE set to zero. These Fits files
	do not yet have the base headers filled (group 1 above), while
	the unit vectors of Sun, Moon and Venus are probably based
	on orbital elements that could be weeks old, and hence may
	not be very accurate. If smei_base is first run on these files
	then the zero value in SMEI__HDR_BASE_DONE will trigger the
	calculation of all three groups of headers. If the source is the
	same as the destination, then the existing Fits file is updated
	with the header information, i.e. the header is only partially
	updated, and the data array remains untouched. If the
	destination is different from the origin then a new Fits
	file is written. In both cases the flag SMEI__HDR_BASE_DONE
	is set to one.

	If smei_base is run on a Fits file which already has the
	SMEI__HDR_BASE_DONE flag set, then by default no action is taken
	(not even when destination and source are different) unless the
	version number of smei_base has been increased.
	Overide this behavior by setting the -force keyword. This will
	trigger a recalculation of all three groups of header entries.

	The -savefrm option will do the base calculation and save three
	fts files into the destination directory:
	- *_0.fts.gz: frame with constant pedestal+dark_current subtracted
	- *_1.fts.gz: frame with pedestal and pattern subtracted
	- *_2.fts.gz: frame with pedestal and pattern subtracted and measles removed
	The original Fits file is never modified when -savefrm is set.
 MODIFICATION HISTORY:
	FEB-2005, Paul Hick (UCSD/CASS)
	    Complete overhaul of Andys version to allow direct processing
	    from the SMEI data base.
	JUN-2005, Paul Hick (UCSD/CASS), V1.02.
	    nped_min for cam 1 and 2 in mode 2: from 115 to 105
	    ped_median_excess for cam 1 and 2 in mode 2: from 2 to 4
	    Added bSaveFrm option
	JUL-2005, Paul Hick (UCSD/CASS), V1.03
	    Changed ped_right_offset_cam(3,1:2) from bad to zero
	    Fixed bug in cal_name determination. Left-right pedestal offset
	    in ped_aux(SMEI__PED_RIGHT_OFFSET) cleared for each frame instead
	    of only when calibration pattern changes.
	JUL-2005, Paul Hick (UCSD/CASS), V1.04
	    Modification in smei_frm_ped. ped_aux(SMEI__PED_RIGHT_OFFSET)
	    is now updated only by frames that pass the pedestal test on
	    ped_aux(SMEI__PED_MEAN_REF)+ped_aux(SMEI__PED_MEAN_EXCESS).
	    There also is a warning printed if ped_mean_diff (difference
	    between left and right mean pedestal) rises above
	    ped_aux(SMEI__PED_MEAN_EXCESS). If this happens
	    ped_aux(SMEI__PED_RIGHT_OFFSET) is not updated, and the pedestal
	    calculation might get stuck in a bad state.
	AUG-2005, Paul Hick (UCSD/CASS), V1.05
	    smei_frm_read contained a bug that affected the cam3/mode1 frames
	    only. The frame time was not picked up correctly, and as a result
	    the onboard factor 2 gain change in Feb 2005 was not compensated
	    for correctly.
	AUG-2005, Paul Hick (UCSD/CASS), V1.06
	    Changed ndark_min_cam(3,1) from 100 to 450.
	    Added dark_max_ratio to list of command line arguments.
	AUG-2005, Paul Hick (UCSD/CASS), V1.07
	    In smei_frm_saturated the saturation value for frames where
	    the onboard flatfield is not enabled (primarily camera 3 mode 1
	    data) was changed from 65535 to 65533.
	SEP-2005, Paul Hick (UCSD/CASS), V2.00
	    Residual values for squares and center group are now a mean
	    (instead of a median).
	NOV-2005, Paul Hick (UCSD/CASS), V2.01
	    dark_scale_ratio_cam is now initialized to BadInitFlag for
	    camera 3. This triggers calculation of the ratio using
	    the function smei_frm_ratio (called in smei_frm_base).
	NOV-2005, Paul Hick (UCSD/CASS), V2.02
	    dark_scale_ratio_cam is set to BadInitFlag only for mode 1
	    (mode 0 and 2 are set to one).
	    dark_scale_fudge_cam is also set to BadInitFlag for mode 1.
	    This triggers calculation of fudge ratio with smei_frm_c3fudge.
	NOV-2005, Paul Hick (UCSD/CASS), V2.03
	    The fudge scale and offset are now applied whenever a dark
	    current value is available (even a rejected value), and not
	    only to dark currents of accepted frames. Note that this affects
	    camera 3 only (cam 1 and 2 do not have fudge factors).
	MAR-2007, Paul Hick (UCSD/CASS), V3.10
	    Set ped_aux(SMEI__PED_LEFT_SIDE_ONLY) to BadR4 to compensate
	    for changes to smei_frm_ped.
	    For camera 3 only after 2005, Doy 159 00 UT, the pedestal is
	    now derived from the left side (underscan) pedestal columns
	    only. Note that this also means that the left-side offset for
	    the pedestal is no longer tracked.
	MAR-2007, Paul Hick (UCSD/CASS), V4.00
	    For camera 3 only a check is made whether the "bad pixel"
	    mask is in effect. If it is then the calibration pattern with
	    the mask taken into account is used instead of the regular
	    mask.
	    For camera 3 the header entry for the orbital (on-the-fly)
	    pattern always used to be set to a name based on the orbit
	    start time for each frame. Now this entry is cleared (if
	    present) if the mode is not 1, or if the mode is 1 but the
	    the corresponding orbital pattern file does not exist.
	    (smei_orb is now responsible for setting this entry).
	JUN-2007,  Paul Hick (UCSD/CASS), V4.10
	    Bug fixes to smei_frm_read introduced in V4.00.
	    For time periods with a "bad pixel" mask onboard
	    (smei_frm_c3mask_active(0,ctime,-1,cmask)=1)
	    two errors were made:
	    - For camera 3, mode 1, the gain change of a factor two was
	      not applied to frames with the flat_enabled flag off (zero),
	      i.e. the pedestal was 2x the correct value (and all frames
	      were rejected as bad).
	    - For cameras 1 and 2 the headroom 0.75 was not corrected for,
	      when flat_enabled=1, i.e. the pedestal and dark current
	      were 0.75 times the correct value.
	    V4.00 was run for all cameras from 2006_001 to 2007_160.
	JUL-2007, Paul Hick (UCSD/CASS)
	    Modified use of c3mask cmd line argument (used for camera 3
	    in mode 1 only).

	    If -c3mask=0 is specified then the regular calibration pattern
	    (with no "bad-pixel" mask taken into account) is used for all
	    frames.
	    If -c3mask=1 is specified then the calibration pattern with
	    the "bad-pixel" mask taken into account is used. This is only
	    useful for periods were a "bad-pixel" mask was in effect
	    (only for these periods does a "bad-pixel" calibration
	    pattern exist).
	    If -c3mask=-1 then the program decides which pattern to use
	    on a frame-by-frame basis (see smei_frm_c3mask_active)

	    If no explicit pattern is specified (i.e. the pattern from the
	    frame headers is used then -c3mask=-1 is the default.

	    If an explicit pattern file is specified on the cmd line, then
	    only -c3mask=0 or -c3mask=1 are valid. The default is -c3mask=0.
	JUL-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V4.11
	    For camera 2 the pedestal is now calculated only from the
	    underscan (left-side) columns for frames after 2006_125.
	JUN-2008, Paul Hick (UCSD/CASS)
	    Added -test cmd line argument (no frames written)
	    Addde -nofudge keyword (suppress fudge factors for dark current)
	JUL-2008, Paul Hick (UCSD/CASS), V4.12
	    Added Fits keyword DARK_AVE for mean of dark current.
	    (Keyword DARK_CUR contains the fudged median)
	JUL-2008, Paul Hick (UCSD/CASS), V4.13
	    Fudge factors for camera 3 with "bad-pixel" mask active
	    are now calculated differently (single fudge factor
	    for each mask).
	OCT-2008, Paul Hick (UCSD/CASS), V4.14
	    Significant changes to smei_frm_c3mask_active to fix some
	    problems with transitions between masks. Added new mask.
	    Added cmd line args -ped_median_deficit and -ped_median_excess
	NOV-2008, Paul Hick (UCSD/CASS), V4.15
	    Added cmd line args -ped_mean_ref and -ped_mean_excess.
	    Especially the default ped_mean_ref is not adequate anymore for
	    camera 3. The default ped_mean_excess is probably still OK.
	NOV-2008, Paul Hick (UCSD/CASS), V5.00
	    Removed cmd line arg -ped_mean_ref again.
	    Whenever some estimate for the pedestal is needed this
	    is now obtained by a call to function smei_frm_ped_mean.
	    This replaces hardcoded values in ped_mean_ref_cam (copied
	    to ped_aux(SMEI__PED_MEAN_REF)) and ped_init_cam (copied
	    to base_aux(SMEI__BAS_PED_INIT+[0,1,2]).
	JUN-2011, Paul Hick (UCSD/CASS), V5.01
	    Added -later_pattern cmd line option to select later pattern.
	NOV-2012, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V5.02
	    Added -twopass option to make two passes on the pedestal
	    calculation: -twopass=1: make two passes if first pass fails;
	    -twopass=2: always make two passes.


smei_cal $SSW_SMEI_UCSD/camera/for/cal/smei_cal.f
[Previous] [Next]
 NAME:
	smei_cal
 PURPOSE:
	Determines dark current pattern from weekly closed shutter calibrations.
 CALLING SEQUENCE:
	program smei_cal
	smei_cal [-force -crx -stats -nic]
		<pattern> destination=<destination> camera=<camera> mode=<mode>
 INPUTS:
	SMEI frames from SMEI data base.
 OUTPUTS:
	The primary output file is a Fits file with name c#cal_YYYY_DOY_hhmmss
	in the destination directory, where the date is taken from the middle
	frame in the group used to calculate the pattern.

	The Fits file contains the mode 0, mode 1 and mode 2 pattern. The mode
	0 array is the primary array, with mode 1 and 2 as Fits extensions.

	If -stats is set then one line for each frame is written to file
	c#cal_YYYY_DOY_hhmmss_stats.dat.

	If -force is set then existing pattern files are overwritten. By default
	no new patterns are created if the Fits pattern file already exists.
	(the pattern is still calculated and is used to process the other keywords).
 INCLUDE:
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'openfile.h'
	include		'filparts.h'
	include		'smei_frm_hdr.h'
	include		'smei_frm_layout.h'
	include		'smei_frm_basepar.h'
	include		'math.h'
	include		'smei_cal_version.h'
 CALLS: ***
	ArrR4Constant, ArrR4Mask, ArrR4SetMinMax, BadI4, BadR4, ForeignArgSet, Int2Str
	SMEI_FRM_PED_MEAN, Say, Str2Str, Time2Str, WhatIsR4, WriteI4GRD, bOpenFile, bWriteFrm
	cDbl2Str, iFilePath, iFreeLun, iGetFileSpec, iGetLogical [1], iGetLogical [2]
	iGetLogical [3], iHideLogical, iOSDeleteFile [1], iOSDeleteFile [2]
	iOSDeleteFile [3], iOSDeleteFile [4], iSearch [1], iSearch [2], iSearch [3]
	iSearch [4], iSetFileSpec, itrim, smei_Time2Split, smei_cal_build, smei_cal_c3mask
	smei_cal_group, smei_foreign, smei_frm_base, smei_frm_clean, smei_frm_get
	smei_frm_measle, smei_frm_mode, smei_frm_path, smei_frm_pickup, smei_frm_read
	smei_frm_saturated, smei_frm_stats
 RESTRICTIONS:
	The program has only been tested on Linux. To get it to work on
	Windows probably some modifications are needed to the Windows
	version of iSearch.
 EXAMPLES:
	Make pattern files for all patterns defined in $SMEIDB/cal/txt
	and make Fits files.

	smei_cal $SMEIDB/cal/txt/*.txt

	To put Fits pattern files only in directory $SMEIDB/cal

	smei_cal $SMEIDB/cal/txt/*.txt -destination=$SMEIDB/cal
 PROCEDURE:
	The patterns produced are identical to the patterns produced by Andys
	original program with two differences:
	1. For cameras 1 and 2 Andy did not fill the pattern in the pedestal columns
	   (13-16, 1269-1272); this version does.
	    Since for cameras 1 and 2 the pedestal pattern is never used the first
	    difference does not matter. Only for camera 3 is the pedestal pattern used.
	2. Andys program did not use the dark current pixels in the top row on the
	   right side (row 256, cols 1265-1268) to calculate the dark current, but
	   did fill in the pattern for three of these pixels (1265-1267). Only in
	   pixel (1268,256) was the pattern not calculated. This program throws
	   out all four pixels all the time, so there is no pattern for these pixels.
	   For use with mode 1 and 2 data the engineering (mode 0) pattern is
	   binned down by 2x2 and 4x4, respectively. In mode 1 the pattern
	   in dark current pixels ([629,128] and [630,128] ) will be different; 
	   in mode 2 dark current pixel [317,64] will be different.

	After 2005 June 8 (Doy 159) 00:00:00 UT only the left side of the frame
	(the underscan region) is used in the pedestal calculation for camera 3.
	(At the end of this day Coriolis came on-line again after a month long
	mishap with Windsat). This was done to reduce the effect of an increasing
	left-right assymetry due to dark-current bleeding in the direction of the
	readout and artificially increasing the overscan pedestal values.
 MODIFICATION HISTORY:
	APR-2004, Andrew Buffington (UCSD/CASS; abuffington@ucsd.edu)
	    Note that "headroom" and small-scale FF are turned OFF when
	    camera 3 in 1x1 mode as here...
	    Another consequence of this is that columns 21 and 1264 are
	    NOT stamped out as would be the case if the SSFF were imposed.
	    Thus these have a full amount of pedestal and dark current,
	    but only an unknown and variable-with-row fraction of sky
	    between 0.5 and unity. Yuck!
	JUN-2004, Paul Hick (UCSD/CASS)
	    Substantial rewrite to allow direct processing from the SMEI data base.
	FEB-2007, Paul Hick (UCSD/CASS)
	    Modified to take presence of "bad pixel" mask into account for camera 3.
	    For patterns during times when a "bad pixel" mask is into effect
	    the pattern Fits file now contains an additional three extensions
	    with the mask-adjusted pattern for mode 0,1 and 2
	    (see smei_cal_c3mask).
	MAR-2007, Paul Hick (UCSD/CASS)
	    For camera 3 after 2005_159 the pedestal is now calculated from the
	    left side (underscan) pedestal columns only.
	JUN-2007, Paul Hick (UCSD/CASS)
	    Recompiled after bugfix in smei_frm_read. The bug did not affect
	    the calibration patterns, so the recompile does not change anything.
	JUN-2007, Paul Hick (UCSD/CASS)
	    For camera 2 after 2006_125 the pedestal is now calculated from the
	    left side (underscan) pedestal columns only.
	DEC-2007, Paul Hick (UCSD/CASS)
	    Added some code to prefix directory names to SMEI frames processed
	    to make the patterns (uses input through keyword -source).
	JUN-2008, Paul Hick (UCSD/CASS)
	    Added cmd line option -test (test mode: no files written)
	JUL-2008, Paul Hick (UCSD/CASS)
	    Both mean-based and median-based dark current are now put
	    in the Fits header for the calibration pattern
	    (previously only the median was put in the Fits file)
	OCT-2008, Paul Hick (UCSD/CASS)
	    Added new mask to smei_frm_c3mask_active. Fixed some bugs in
	    defining transitions between masks.
	NOV-2008, Paul Hick (UCSD/CASS), V2.0
	    Whenever some estimate for the pedestal is needed this
	    is now obtained by a call to function smei_frm_ped_mean.
	    This replaces hardcoded values in ped_mean_ref_cam (copied
	    to ped_aux(SMEI__PED_MEAN_REF)) and ped_init_cam (copied
	    to base_aux(SMEI__BAS_PED_INIT+[0,1,2]).
	APR-2009, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V2.1
	    Added keyword PED_VAL with the mean pedestal of the frames
	    used to build the pattern.
       OCT-2010, John Clover (UCSD/CASS), V2.11
           The left side pedestal columns are now correctly used
           for calibration patterns. (Change was made JUN-2007 and
           subsequently disappeared.
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V2.2
	    Added keyword C3MASK, containing the name of a C3
	    "bad-pixel" mask, to FTS hdr for cal pattern with
	    cam3 on-board flatfield mask applied.


smei_cal_add $SSW_SMEI_UCSD/camera/for/cal/smei_cal_add.f
[Previous] [Next]
 NAME:
	smei_cal_add
 PURPOSE:
	Accumulutes information for engineering mode pattern calculation
 CATEGORY:
	ucsd/camera/for/lib
 CALLING SEQUENCE:
	subroutine smei_cal_add(cut, nx, ny, frame, pattern, count, count_cr)
 INPUTS:
	cut		real		threshold for cosmic ray determination
	nx		integer		horizontal frame size
	ny		integer		vertical frame size
	frame(nx,ny)	real		frame data with pedestal already subtracted
	pattern(nx,ny)	real		accumulates pattern data
	count  (nx,ny)  real		counts number of frames contributing to each pixel
					in the pattern.
					!! Count is initialized by caller (smei_cal_build).
	count_cr	integer		counts # pixels excluded because they are suspected
					to be cosmic rays.
					!! count_cr must be initialized to a negative value
					!! to make sure that smei_add_pat is initialized properly.
					!! count_cr is set to zero as part of the initialization.
 OUTPUTS:
	pattern(nx,ny)	real		updated pattern
	count  (nx,ny)  real		updated count data
	count_cr	integer		updated cosmic ray count
 CALLS: ***
	BadR4, Flt2Str, Int2Str, Say, Str2Str
 CALLED BY:
	smei_cal_build
 INCLUDE:
	include		'smei_frm_layout.h'
 REMARK:
	In Andys original program the 'cut' value used was twice as big as here, but was
	multiplied by 0.5 when the cut was applied. The factor 0.5 has been absorbed here
	in the value for 'cut'.
 PROCEDURE:
	The pattern is calculated in pedestal, dark current and covered pixels.
	Only pixels that are consistently flagged as bad (probably by smei_frm_clean)
	will not receive a pattern value.
	Currently (Jun-2004) these are the four leading columns in the eng mode frames
	and 8 pixels at the top right of the CCD, for a total of 4*256+8=1032 pixels
	with no pattern.
 MODIFICATION HISTORY:
	JUN-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_cal_bin $SSW_SMEI_UCSD/camera/for/cal/smei_cal_bin.f
[Previous] [Next]
 NAME:
	smei_cal_bin
 PURPOSE:
	Rebin engineering mode frame (mode 0) to
	pseudo science=mode frame (mode 1 and 2)
 CATEGORY:
	camera/for/cal
 CALLING SEQUENCE:
	subroutine smei_cal_bin(mode,hdr,frame,hdr_,frame_)
 INPUTS:
 OUTPUTS:
 CALLS: ***
	ArrR4TimesConstant, ArrR8Copy, Say, Time2Str, smei_frm_c3mask_active, smei_hdr_str
	smei_hdr_time
 CALLED BY:
	smei_cal_build
 INCLUDE:
	include		'smei_frm_hdr.h'
	include		'smei_frm_layout.h'
 PROCEDURE:
 MODIFICATION HISTORY:
	JUN-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_cal_build $SSW_SMEI_UCSD/camera/for/cal/smei_cal_build.f
[Previous] [Next]
 NAME:
	smei_cal_build
 PURPOSE:
	Calculates engineering mode pattern from selection of 'closed shutter' data.
 CATEGORY:
	ucsd/camera/for/lib
 CALLING SEQUENCE:
	subroutine smei_cal_build(bMask,rmask,nfrm,cfrm,cdest,pattern_cut,
     &		pattern_ped,pattern,pattern_dark,dark_pixs,ncr_count,ped_aux)
 INPUTS:
	bMask		logical		.FALSE.: do not try to apply a "bad pixel" mask
					.TRUE. : try to apply a "bad pixel" mask
	rmask(*)	real		onboard mask (used only if bMask=.TRUE.)
	cdest(*)	character	destination for rebinned frames
					(see PROCEDURE)
	nfrm		integer		# frames
	cfrm(nfrm)	character*(*)	fully-qualified file names of SMEI data frame
	pattern_cut	real
	ped_aux(*)	real
 OUTPUTS:
	pattern_ped	real		pattern pedestal
					mean of all nfrm pedestals
	pattern_dark(2)	real		pattern dark current
					median and mean of all nfrm dark currents
	pattern(*)	real		eng mode frame pattern
	dark_pixs(SMEI__DRK_NPIX,nfrm)
			real		all the individual dark current pixels
 CALLS: ***
	ArrR4AddConstant, ArrR4DivideByArrR4, ArrR4TimesArrR4, ArrR4Zero, BadR4, Flt2Str
	Int2Str, Say, Str2Str, iArrR4ValuePresent, iCheckDirectory, iFilePath, iGetFileSpec
	iSetFileSpec, itrim, smei_cal_add, smei_cal_bin, smei_frm_clean, smei_frm_dark
	smei_frm_fts, smei_frm_mode, smei_frm_ped, smei_frm_read
 CALLED BY:
	smei_cal
 INCLUDE:
	include		'openfile.h'
	include		'filparts.h'
	include		'smei_frm_layout.h'
	include		'smei_frm_basepar.h'
	include		'smei_frm_hdr.h'
 PROCEDURE:
	The pattern is calculated in pedestal, dark current and covered pixels.
	Only pixels that are consistently flagged as bad (probably by smei_frm_clean)
	will not receive a pattern value.
	Currently (Jun-2004) these are the four leading columns in the eng mode frames
	and 8 pixels at the top right of the CCD, for a total of 4*256+8=1032 pixels
	with no pattern.

	A check is made to ensure that all dark current and uncovered pixels are
	actually filled with something (i.e. are not returned as zero). Excluded from
	this check are four dark current pixels in the top row at the right of the CCD
	which are flagged as bad in smei_frm_clean, and will be zero in the pattern
	calculated here.

	In all dark current output the pedestals have been subtracted already.

	If bMask is .TRUE. on input then the "bad pixel" mask (rmask) is applied
	to each of the frames in cfrm. The "bad pixel" mask is only active during
	certain time periods (see smei_frm_mask) for camera 3 only.

	If cDest is not a blank string, it should contain an existing directory
	(usually the same directory the calibration patterns are written to).
	cDest should contain subdirectories 'mask_out' and 'mask_in'.
	If bMask=.FALSE. and 'mask_out' exists the mode 0 frames are rebinned
	for all three modes (mode 0: 1x1, mode 1: 2x2 and mode 2: 4x4), and
	these 'pseudo frames' are written to subdirectories 'c1','c2','c3'
	in 'mask_out', depending on camera). If bMask=.TRUE. and 'mask_in' the frames
	go to 'mask_in' instead. The 'mask_out' directory contains frames 'as is'
	'mask_in' contains frames with the appropriate "bad-pixel" mask
	folded in (i.e. with "bad pixels" that are removed from the real science
	mode data blanked out prior to binning). Note that only camera 3 has a
	"bad-pixel" mask.

	So the directory structure is:
			                |- c1 (cam 1, mode 0,1,2 pseudo frames
			  |-- mask_out -|- c2 (cam 2, mode 0,1,2 pseudo frames
			  |             |- c3 (cam 3, mode 0,1,2 pseudo frames
		<cDest> --|
			  |-- mask_in ---- c3 (cam 3, mode 0,1,2 pseudo frames

	In these frames header entries related to pedestal and dark current
	are set to 0, and can be filled in by running smei_base.
 MODIFICATION HISTORY:
	JUN-2004, Paul Hick (UCSD/CASS)
	FEB-2007, Paul Hick (UCSD/CASS)
	    Added bMask argument to allow creation of patterns with
	    the "bad pixel" mask for camera 3 applied.
	JUN-2008, Paul Hick (UCSD/CASS)
	    Added code to write out rebinned "science mode" frames for each
	    of the frames used to create the calibration pattern.
	JUL-2008, Paul Hick (UCSD/CASS)
	    Changed from function to subroutine. Extra keyword pattern_dark
	    returns median and mean pattern dark current.
	NOV-2008, Paul Hick (UCSD/CASS)
	    Modified to accomodate new arg to smei_frm_ped
	APR-2009, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V2.1
	    Added keyword PED_VAL with the mean pedestal of the frames
	    used to build the pattern.


smei_cal_c3mask $SSW_SMEI_UCSD/camera/for/cal/smei_cal_c3mask.f
[Previous] [Next]
 NAME:
	smei_cal_c3mask
 PURPOSE:
	Reads bad pixel mask for camera 3
 CATEGORY:
	gen/for/lib/frm
 CALLING SEQUENCE:
	logical function smei_cal_c3mask(ipatt,tframe,flat_enabled,mask,tmask)
 INPUTS:
	ipatt		integer		0/1, passed to smei_frm_c3mask_active
	tframe		character	SMEI frame time in format YYYY_DOY_hhmmss
	flat_enabled	integer		nint(hdr(SMEI__HDR_FLAT_ENABLED)) or -1
					"flatfield-enabled" flag from SMEI frame header
 OUTPUTS:
	smei_cal_c3mask	logical		.TRUE. : bad pixel mask in use for specified time
						and flatfield flag (if not -1)
					.FALSE.: no bad pixel mask in use for specified time
						and flatfield flag (if not -1)
	mask(*)		real		bad pixel mask
					Mask has full resolution of 1272x256 and
					contains values 0 and 1.
					If no bad pixel mask is in effect than all values
					in the mask are set to 1.
	tmask		character*(SMEI__UT_FORMAT_LEN)
					smei_cal_c3mask=.TRUE. : name of C3 "bad-pixel" mask
					smei_cal_c3mask=.FALSE.: blank string
 CALLS: ***
	ArrR4Constant, Int2Str, Say, Str2Str, bOpenFile, cInt2Str, iFilePath, iFreeLun
	smei_frm_c3mask_active
 CALLED BY:
	smei_cal
 INCLUDE:
	include		'filparts.h'
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'openfile.h'
	include		'smei_frm_layout.h'
 PROCEDURE:
	The test for whether or not a "bad pixel" needs to be read is
	done by smei_frm_c3mask_active.

	A mask is applied only for camera 3 in mode 1 (2x2 binned). The mask is
	multiplied with the readout onboard, EXCEPT THAT the mask is NOT APPLIED
	when a whole 2x2 group of mask elements is zero. In this case the
	the usual 2x2 average is returned.

	Therefore, if a 2x2 group of elements in the mask read from file is set
	to zero (flagged as "bad") then the 4 pixels in this group are set back
	to one (set to "good").
 MODIFICATION HISTORY:
	FEB-2007, Paul Hick (UCSD/CASS)
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Added new argument, tmask, to return name of C3 "bad-pixel" mask.


smei_cal_group $SSW_SMEI_UCSD/camera/for/cal/smei_cal_group.f
[Previous] [Next]
 NAME:
	smei_cal_group
 PURPOSE:
	Processes the content of the list file with information about
	all groups of closed shutter frames.
 CALLING SEQUENCE:
	integer function smei_cal_group(cList, icam, TBeg, TEnd, cframes, cframeref, bTfloat)
 INPUTS:
	cList*(*)	character	name of ASCII file with frame names
 OUTPUTS:
	icam		integer		camera number (1,2,3)
	TBeg(2)		integer		start time of 'closed shutter' data
	TEnd(2)		integer		end time of 'closed shutter' data
	cframes(smei_cal_group)
			character	list of frame names to be used to
					calculate the shutter.
	cframeref*(*)	character	base name for all pattern-related output files.
					cframeref contains only a file (no directory, no type)
	bTfloat		logical		set to .TRUE. if the patterns were selected near
					the minimum (camera 1,2) or maximum (3) of the CCD
					temperature curve.
					(!!!! this is only correct for camera 3 and for 
					cameras 1 and 2 for the patterns after approximately
					doy 100 in 2004.)
	smei_cal_group	integer		# frames in array cframes
 CALLED BY:
	smei_cal
 INCLUDE:
	include		'filparts.h'
	include		'openfile.h'
 CALLS: ***
	LocFirst, LocFirstLen, Say, bOpenFile, iFreeLun, iGetFileSpec, iSetFileSpec, itrim
	smei_Time2Split
 PROCEDURE:
	Each closed shutter calibration is characterized in a small ascii file
	containing a group 2+N frame names (currently N=10).
	Frames 1 and 2 bracket the 'closed shutter' data;
	the following group on N frames is used to determine the pattern.
 MODIFICATION HISTORY:
	JUN-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_cal_version $SSW_SMEI_UCSD/camera/for/cal/smei_cal_version.h
[Previous] [Next]
 NAME:
	smei_cal_version
 PURPOSE:
	Stores version number for program smei_cal
	(which makes the "shutter-closed" calibration patterns.
 INCLUDED BY:
	smei_cal, smei_cal_write
 MODIFICATION HISTORY:
	OCT-2008, Paul Hick (UCSD/CASS) V1.04
	    New mask added to smei_frm_c3mask_active
	APR-2009, Paul Hick (UCSD/CASS), v. 2.1
	    Added keyword PED_VAL with the mean pedestal of the frames
	    used to build the pattern.
	OCT-2010, John Clover (UCSD/CASS), V2.11
	    Changed version slightly to reflect the left column
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V2.2
	    Added keyword C3MASK to Fts hdr for cal pattern with
	    cam3 on-board mask applied.


smei_cal_write $SSW_SMEI_UCSD/camera/for/cal/smei_cal_write.f
[Previous] [Next]
 NAME:
	smei_cal_write
 PURPOSE:
	Write closed shutter calibration pattern file
 CATEGORY:
	ucsd/camera/for/lib
 CALLING SEQUENCE:
	subroutine smei_cal_write(bTestMode,bAppend,cFile,bTfloat,pattern_ped,pattern_dark,pattern,nfrm,cfrm,TBeg,TEnd,ncr_count,cmask)
 INPUTS:
	bTestMode	logical		.TRUE.: no Fits file created/modified
					.FALSE.: Fits file created/modified
	bAppend		logical		.FALSE.: create new Fits file
					.TRUE. : append to existing Fits file
	cFile*(*)	character	fully qualified name with type missing
	bTfloat		logical		.TRUE. if pattern was based on frames near temperature
					minimum (cam 1,2) or maximum (cam 3).
	pattern_ped	real		pedestal in pattern
	pattern_dark(2)	real		dark current in pattern (median and mean)
	pattern(*)	real		engineering mode (1272x256) pattern array
	nfrm		integer		# frames used to calculate the pattern
	cfrm(nfrm)	character	names of frames used to calculate the pattern
	TBeg(2)		integer		Begin time of closed shutter calibration data
	TEnd(2)		integer		End time of closed shutter calibration data
					All engineering mode frames between TBeg and TEnd
					are used for the performance test.
	ncr_count	integer		cosmic ray count (from smei_cal_add)
	cmask		character*(SMEI__UT_FORMAT_LEN
					name of C3 "bad-pixel" mask or blank string.
					If not a blank string it is added to the FTS
					header as keyword C3MASK.
 OUTPUTS:
 CALLS:
	ArrR4Copy, ArrR4Mask, ArrR4Zero, BadR4, FTCLOS, FTCRHD, FTINIT, FTPHPR, FTPKNS, FTPKYE
	FTPKYJ, FTPKYL, FTPKYS, FTPPRE, Flt2Str, Int2Str, Say, Time2Str, WriteR4GRD, bOpenFile
	iFilePath, iFreeLun, iGetFileSpec, iGetLun, iOSSpawnCmd [1], iOSSpawnCmd [2]
	iOSSpawnCmd [3], iOSSpawnCmd [4], iSetFileSpec, itrim, say_fts
 INCLUDE:
	include		'smei_frm_layout.h'
	include		'ftspar.h'
	include		'filparts.h'
	include		'openfile.h'
	include		'smei_cal_version.h'
 PROCEDURE:
	How many bad values do we expect????
 MODIFICATION HISTORY:
	JUN-2004, Paul Hick (UCSD/CASS)
	FEB-2007, Paul Hick (UCSD/CASS)
	    Added bAppend argument to be able to append patterns with
	    "bad pixel" mask applied.
	DEC-2007, Paul Hick (UCSD/CASS)
	    Added DATE keyword with creation date for file
	JAN-2008, Paul Hick (UCSD/CASS), v. 1.01
	    Added keyword SMEI_CAL with software version number
	JUN-2008, Paul Hick (UCSD/CASS), v. 1.02
	    Added argument bTestMode
	    Added keyword TIME (same time as in pattern name)
	    Fixed bug: keyword NAME was not filled correctly.
	JUL-2008, Paul Hick (UCSD/CASS), v. 1.03
	    Added keyword DARK_AVE with the mean dark current
	    (DARK_VAL contains the median)
	APR-2009, Paul Hick (UCSD/CASS; pphick@ucsd.edu), v. 2.1
	    Added keyword PED_VAL with the mean pedestal of the frames
	    used to build the pattern.
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu), v. 2.2
	    Added input argument cmask, containing the name of the
	    C3 "bad-pixel" mask used (or blank string if it isn't
	    used). It is added to the header for the cal pattern
	    with mask applied as keyword C3MASK.


smei_frm_write $SSW_SMEI_UCSD/camera/for/base/smei_frm_write.f
[Previous] [Next]
 NAME:
	smei_frm_write
 PURPOSE:
	Write or update SMEI frame as Fits file.
 CATEGORY:
	gen/for/lib
 CALLING SEQUENCE:
	subroutine smei_frm_write(cFrm, hdr, cDest, bdig, bnodups)
 INPUTS:
	cFrm
	hdr
	cDest
	bdig
	bnodups
 CALLED BY:
	smei_base
 INCLUDE:
	include		'filparts.h'
	include		'openfile.h'
	include		'smei_frm_hdr.h'
	include		'smei_frm_layout.h'
	include		'ftspar.h'
 CALLS: ***
	FTCLOS, FTGISZ, FTGPVE, FTNOPN, Say, Str2Str, iCheckDirectory, iFreeLun, iGetFileSpec
	iGetLun, iOSDeleteFile [1], iOSDeleteFile [2], iOSDeleteFile [3]
	iOSDeleteFile [4], iOSSpawnCmd [1], iOSSpawnCmd [2], iOSSpawnCmd [3]
	iOSSpawnCmd [4], iSetFileSpec, itrim, say_fts, smei_frm_fts, smei_frm_fts_axis
	smei_frm_fts_base, smei_frm_fts_eph, smei_frm_path
 PROCEDURE:
 MODIFICATION HISTORY:
	FEB-2005, Paul Hick (UCSD/CASS)
	JUL-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Introduced smei_frm_fts call to write new Fits file


smei_get_glare $SSW_SMEI_UCSD/camera/for/sky/smei_get_glare.f
[Previous] [Next]
 NAME:
	smei_get_glare
 PURPOSE:
	Get glare map
 CALLING SEQUENCE:
	subroutine smei_get_glare(icam, mode, glare_map, glare_factor, cx, cy, dx, dy)
 INPUTS:
 OUTPUTS:
	icam		integer		camera (1,2,3)
	mode		integer		mode (0,1,2)
	glare_map	real		318x64 (mode 2) frame representing the glare
	glare_factor	real		90x180 array of multipliers for the glare map
	cx		real
	cy		real
	dx		real
	dy		real
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 INCLUDE:
	include		'filparts.h'
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'smei_frm_layout.h'
	include		'ftspar.h'
 CALLS: ***
	FTCLOS, FTGISZ, FTGKYE, FTGPVE, FTNOPN, Int2Str, Say, Str2Str, iFilePath, iFreeLun, iGetLun
	say_fts
 RESTRICTIONS:
	glare_map    MUST be a 318 x  64 array
	glare_factor MUST be a  90 x 180 array
 PROCEDURE:
	The glare map represents the shape of the glare as present in
	the SMEI frames as a mode 2 (318x64) array.
	This glare map, multiplied by a constant, is subtracted from
	each SMEI frame. The multiplier is a function of the location
	of the Sun relative to the optical axis.
	The glare_factor array represents this multiplier as a function
	of two angles thetax and thetay.
 MODIFICATION HISTORY:
	DEC-2004, Paul Hick (UCSD/CASS)
	DEC-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Now using WCS-compliant keywords.


smei_get_starmask $SSW_SMEI_UCSD/camera/for/sky/smei_get_starmask.f
[Previous] [Next]
 NAME:
	smei_get_starmask
 PURPOSE:
	Read in star masks for indexing.
 CALLING SEQUENCE
	subroutine smei_get_starmask(bNoStarMask,n_eq, n_pl, mask)
 INPUTS:
	bNoStarMask	logical		.FALSE.: use star mask (read from
						file $SMEIDB/starmask.fts.gz)
					.TRUE  : set mask to zero everywhere
	n_eq		integer		number of bins in hires equatorial map
	n_pl		integer		number of bins in hires polar maps
 OUTPUTS:
	mask(n_eq+2*n_pl)
			integer		mask values:
					0: indicates skybin away from bright star
					1: indicates skybin close to bright star.
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 INCLUDE:
	include		'filparts.h'
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'ftspar.h'
 CALLS: ***
	ArrI4Zero, FTCLOS, FTGISZ, FTGPVJ, FTMAHD, FTNOPN, Say, iFilePath, iFreeLun, iGetLun
	say_fts


smei_orb $SSW_SMEI_UCSD/camera/for/orb/smei_orb.f
[Previous] [Next]
 NAME:
	smei_orb
 PURPOSE:
	Determines minimum pattern for a reference orbit.
	Then uses the miminimum pattern to create difference patterns for
	all orbits in a specified period.
 CALLING SEQUENCE:
	program smei_orb
 INPUTS:
	(SMEI frames from SMEI data base)

	Input from command line (see smei_foreign):

	min_orbit	integer		extracted from
					    minimum=<min_orbit> or minimum=<YYYY_DOY_hhmmss>
					orbit to be used for calculating the mimimum pattern
					in smei_orb.
	beg_orbit	integer		extracted from
					    start=<start_orbit> or start=<YYYY_DOY_hhmmss>
					The start time of the first orbit for which a
                                       difference orbital pattern is calculated.
	end_orbit	integer		extracted from
					    stop=<end_orbit> or stop=<YYYY_DOY_hhmmss>
					The iend time of the last orbit for which a minimum
                                       orbital pattern is calculated.
                                       (so if an orbit number n is specified, then orbit
                                       n-1 is the last orbit processed)
	norbit		integer		extracted from
					    orbits=<orbits>
					Alternative to end_orbit: # orbits processed starting
					at start_orbit.
	fraction(2)	real		extracted from lowfraction=lowfraction and
					    highfraction=highfraction respectively
					two fractions of one defining the part of the orbit
					used for the orbital minimum and difference patterns.
					if fraction(1) < fraction(2) then only the part of the
					orbit with fraction(1) <= orbitfraction <= fraction(2)
					is used.
					if fraction(1) > fraction(2) then only the beginning part
					of the orbit with orbitfraction < fraction(2) and the trailing
					part with orbitfraction >= fraction(2) is used.
 OUTPUTS:
	One mimimum pattern, many difference patterns.
 INCLUDE:
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'filparts.h'
	include		'openfile.h'
	include		'ftspar.h'
	include		'smei_frm_layout.h'
	include		'smei_frm_hdr.h'
	include		'smei_frm_hdrok.h'
 CALLS: ***
	ArrI4Copy, ArrR4Bad, ArrR4Constant, ArrR4Copy, BadI4, Dbl2Str, FTCLOS, FTNOPN, FTUKYS
	ForeignArgSet, ForeignI4Arg, Int2Str, SMEI_FRM_READ_SET_SDARK, SMEI_ORB_DIFF, Say
	Str2Str, Time2Str, cDbl2Str, cHideLogical, cInt2Str, iFreeLun, iGetFileSpec, iGetLun
	iOSSpawnCmd [1], iOSSpawnCmd [2], iOSSpawnCmd [3], iOSSpawnCmd [4], iSetFileSpec
	itrim, say_fts, smei_Time2Split, smei_cal_get, smei_cal_init, smei_foreign
	smei_frm_c3mask_active, smei_frm_clean, smei_frm_get, smei_frm_mode, smei_frm_ok
	smei_frm_read, smei_hdr_str, smei_orb_min, smei_orb_write, smei_orbit2
	smei_orbit_time2
 RESTRICTIONS:
	The first frame in the minimum orbits determines which cal pattern
	is used for the rest of the run, and what the setting of the C3
	mask flag is.
 PROCEDURE:
	Fractions for May 2003: 0.5682, 0.1857
	Fractions for Oct 2003: 0.8694, 0.6398 (1325.0/1524, 975.0/1524)
 EXAMPLE:
	smei_orb -min=2035 -start=2035 -stop=2221 -destination=$TUB
		-lowfraction=0.5682 -highfraction=0.1857
 MODIFICATION HISTORY:
	MAR-2004, Andrew Buffington (UCSD/CASS; abuffington@ucsd.edu)
	    Note that "headroom" and small-scale FF are turned OFF when
	    camera 3 in 2x2 mode as here. Another consequence of this is
	    that columns 11 and 631 are NOT half stamped out as would be
	    the case if the SSFF were imposed. Thus these have a full
	    amount of pedestal and dark current, but only an unknown and
	    variable-with-row fraction of sky between 0.5 and unity. Yuck!
	AUG-2004, Paul Hick (UCSD/CASS)
	    Rewrite based on Andys pattern_get_cam3.for
	AUG-2005, Paul Hick (UCSD/CASS); V1.01
	    Added code to update Fits header of individual frames with
	    name of difference pattern (the program version number is
	    coded into the comment string.
	    Added extra map to each orbital file containing for each pixel
	    the orbital fraction of the frame used to fill it.
	JUL-2006, Paul Hick (UCSD/CASS); V3.01
	    Added Fits keywords SMEI_ORB and CREATED to output files.
	MAR-2007, Paul Hick (UCSD/CASS); V4.00
	    Modified to cope with "bad pixel" masks.
	    The first frame of an orbit now sets both the name of the
	    "closed shutter" pattern and the flag that decides whether
	    or not a "bad pixel" mask is in effect.
	JUN-2007, Paul Hick (UCSD/CASS); V4.10
	    Fixed bug in smei_frm_read, introduced in V4.00
	    The orbital pattern would have been wrong for orbits with
	    flat_enabled=0 during periods when a "bad-pixel" mask was
	    onboard. The first time this happens is after 2007_133.
	    Since these orbits have not been run yet, no harm done.
	SEP-2008, Paul Hick (UCSD/CASS); V4.12
	    Added command line argument sdark, and added call to
	    smei_frm_read_set_sdark.
	OCT-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu); V4.13
	    Modications to smei_frm_c3mask_active in handling
	    transitions between mask. Added new mask


smei_orb_get $SSW_SMEI_UCSD/camera/for/sky/smei_orb_get.f
[Previous] [Next]
 NAME:
	smei_orb_get
 PURPOSE:
	Select orbital minimum or difference pattern
 CATEGORY:
	ucsd/camera/for/lib
 CALLING SEQUENCE:
	subroutine smei_orb_get(orb_file,icam,mode,cal_file,orb_pattern,bNew,version)
 INPUTS:
	orb_file	character*(*)	name of orbital difference file
					Only file name; no directory, no extension, i.e.
					as extracted from Fits header of SMEI frame.
					If orb_file is a blank string then orb_pattern is
					set to zero.
	icam		integer		must be always 3
	mode		integer		must be always 1
	cal_file	character*(*)	File name of closed shutter calibration pattern.
 OUTPUTS:
	orb_pattern	real		
	bNew		logical		.TRUE. if a new orbital difference pattern is read
					(and orb_pattern was modified)
					.FALSE. if no new pattern is read (and orb_pattern
					is not modified)
	version		double precision Version number of smei_orb that wrote the
					 the orbital pattarn. Return 0.0d0 if no orbital
					 pattern was read.
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 INCLUDE:
	include		'filparts.h'
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'smei_frm_layout.h'
 CALLS: ***
	ArrR4Zero, Say, iFilePath, iGetFileSpec, iSearch [1], iSearch [2], iSearch [3]
	iSearch [4], iSetFileSpec, smei_frm_read_get_sdark, smei_orb_cal_name
	smei_orb_read, smei_orb_version
 PROCEDURE:
	The name of the last difference pattern is saved internally.
	A new difference pattern is read only if the input orb_file is different from
	the internally saved name. If a new file is read then orb_pattern is updated,
	and bNew is set true. If no new file is read then orb_pattern is not modified.
	and bNew is set false.

	If the input cal_file is not the blank string then it is compared against the
	the name of the calibration patterns associated with the current difference
	pattern. If the names do not match program execution terminates.
 MODIFICATION HISTORY:
	SEP-2005, Paul Hick (UCSD/CASS)
	JAN-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Added version argument.


smei_orb_min $SSW_SMEI_UCSD/camera/for/orb/smei_orb_min.f
[Previous] [Next]
 NAME:
	smei_orb_min
 PURPOSE:
	Accumulate minimum orbital pattern
 CATEGORY:
	ucsd/camera/for/lib
 CALLING SEQUENCE:
	subroutine smei_orb_min(nsec,nx,ny,frame,ip_min,ip_frac,orb_pattern,ped_val,dark_scale,cal_pattern)
 INPUTS:
	nsec		integer		number of seconds into orbit
	nx		integer		horizontal frame size
	ny		integer		vertical frame size
	frame(*)	real		frame data (after massaging by smei_frm_clean)
	orb_pattern(*)	real		pattern to be updated.
					Should be initialized to BadR4 by caller.
	ped_val		real		pedestal value (from smei_frm_ped)
	dark_scale	real		scaling factor for calibration patttern
	cal_pattern(*)	real		closed shutter calibration pattern
 OUTPUTS:
	orb_pattern(*)	real		updated orbital minimum pattern
 CALLED BY:
	smei_orb
 INCLUDE:
	include		'smei_frm_layout.h'
 RESTRICTIONS:
 CALLS: ***
	BadR4, smei_frm_mode
 SEE ALSO:
 PROCEDURE:
 MODIFICATION HISTORY:
	JUN-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_orb_write $SSW_SMEI_UCSD/camera/for/orb/smei_orb_write.f
[Previous] [Next]
 NAME:
	smei_orb_write
 PURPOSE:
	Write orbital pattern file
 CATEGORY:
	ucsd/camera/for/lib
 CALLING SEQUENCE:
	subroutine smei_orb_write(version,bForce,bDiff,cDest,cPatCal,min_orbit,this_orbit,
     &		tfirst,tlast,tlow,thigh,nframe,nx,ny,ip_orb,ip_frac,orb_pattern,cthis_orbit)
 INPUTS:
	version		double precision smei_orb version number
	bForce  	logical		.FALSE.: do not overwrite existing pattern (if a pattern
						exists, execution is aborted).
					.TRUE. : overwrite pattern (the existing pattern file
						is deleted, and a new one is written)
	bDiff		logical		.FALSE.: write minimum pattern
					.TRUE. : write difference pattern
	cDest*(*)	character	destination directory for orbit pattern files
	cPatCal*(*)	character	name of closed shutter calibration pattern on which
					the orbital pattern is based
	min_orbit	integer		minimum orbit
	this_orbit	integer		curent orbit (either minimum orbit or a difference orbit)
	tfirst(2)	integer		time of first frame in orbit
	tlast(2)	integer		time of last frame in orbit
	tlow(2)		integer		start time of fraction of orbit used
	thigh(2)	integer		end time of fraction of orbit used
	nframe(2)	integer		nframe(1): # frames in orbit this_orbit
					nframe(2): # frames used
	nx		integer		horizontal dimension of orbital pattern
	ny		integer		vertical dimension of orbital pattern
	ip_orb		integer
	ip_frac		integer
	orb_pattern(*)	real
 OUTPUTS:
	cthis_orbit*(*)	character	name of output file
 CALLED BY:
	smei_orb
 INCLUDE:
	include		'filparts.h'
	include		'smei_frm_layout.h'
 CALLS: ***
	ArrR4Copy, ArrR4Mask, BadR4, FTCLOS, FTCRHD, FTINIT, FTPHPR, FTPKYE, FTPKYG, FTPKYJ, FTPKYS
	FTPPRE, Say, Time2Str, Time2System, iFilePath, iFreeLun, iGetLun, iOSDeleteFile [1]
	iOSDeleteFile [2], iOSDeleteFile [3], iOSDeleteFile [4], itrim, say_fts
	smei_orb_mkname
 PROCEDURE:
	How many bad values do we expect????
 MODIFICATION HISTORY:
	JUN-2004, Paul Hick (UCSD/CASS)
	JUL-2006, Paul Hick (UCSD/CASS)
	    Added Fits keyword SMEI_ORB (version number) and CREATED
	    (time file is created).
	APR-2007, Paul Hick (UCSD/CASS)
	    Added keyword IFRAME (number of frames used).
	    Pattern name determined from tfirst by calling smei_orb_mkname.
	DEC-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Changed keyword CREATED to DATE (consistent with IDL)


smei_skyd $SSW_SMEI_UCSD/camera/for/sky/smei_skyd.f
[Previous] [Next]
 NAME:
	smei_skyd
 PURPOSE:
	Creates skymaps from individual SMEI data frames
 CATEGORY:
	camera/for/sky
 CALLING SEQUENCE:
	program smei_skyd
 INPUTS:
	Input is controlled by command line arguments (see PROCEDURE).

	<Pattern-file>	file with pattern
			default: $DAT/smei/testcase/DATA_SMEI/c2pat_2004_140.grd
			use SMEIDB? to get pattern from SMEI data base
 OPTIONAL INPUTS:
	-source=<source>directory where the SMEI frames are located
			default: SMEIDB? (the SMEI data base)
	-destination=<destination>
			directory where the output files are written.
			default: $TUB
	-help		print some instructions and exit.

	-firstorbit=<value>	default: 7223
	-lastorbit=<value>	default: 7224
			Orbits firstorbit through lastorbit are processed
	-lowfraction=<value>	default: 0.0
	-highfraction=<value>	default: 1.0
			Only frames inside orbitfraction range
			[lowfraction,highfraction] are used
			(highfraction MUST be larger than lowfraction).

	-camera=<value>	camera to be processed
			default: 2
	-mode=<value>	frame mode to be processed
			default: 2 for cameras 1 and 2; 1 for camera 3
	-level=<value>	frame mode to be processed
			default: 2
	-grd		output .grd files in addition to Fits file.
	-keepglare	do not remove glare
	-overwrite	create a new skymap if the Fits file already exists
	-checkversion	create a new skymap if the Fits file already exists,
			but only if it has a lower version number.
			(if -overwrite is set then -checkversion is ignored)
	-version
	-dumpversion
	-avoidmoon
	-avoidmoon=tx1,tx2,ty1,ty2
	-avoidvenus=tx1,tx2,ty1,ty2
	-avoidsun=tx1,tx2,ty1,ty2
 OUTPUTS:
 INCLUDE:
	include		'dirspec [1].h'
	include		'dirspec [2].h'
	include		'dirspec [3].h'
	include		'dirspec [4].h'
	include		'openfile.h'
	include		'filparts.h'
	include		'smei_frm_layout.h'
	include		'smei_frm_hdr.h'
	include		'smei_frm_hdrok.h'
	include		'smei_skyd_dim.h'
 CALLS: ***
	ArrI4Copy, ArrR8Bad, BadI4, BadR4, Dbl2Str, ForeignArgSet, ForeignI4Arg, Int2Str
	SMEI_FRM_READ_SET_SDARK, Say, Str2Str, Time2Str, bOpenFile, cDbl2Str, cInt2Str
	iFreeLun, iGetFileSpec, iHideLogical, iOSDeleteFile [1], iOSDeleteFile [2]
	iOSDeleteFile [3], iOSDeleteFile [4], iScratchLun, iSetFileSpec, smei_cal_init
	smei_foreign, smei_frm_getlist, smei_frm_ok, smei_frm_read, smei_hdr_str
	smei_orbit2, smei_orbit_time2, smei_skyd_fts, smei_skyd_init, smei_skyd_make
	smei_skyd_sky
 EXAMPLE:
	To run the testcase:

	smei_skyd $DAT/smei/testcase/DATA_SMEI
 PROCEDURE:
 >	A call to smei_skyd has the structure:

	smei_skyd <List-file> <Pattern-file> <Frame-dir> <Output-dir>
		-keyword1=<value1> -keyword2=<value2> ....

 >	Large-scale flatfields are read from $SMEIDB/flatfield (one of
	c1_clsff.fts.gz, c2_clsff.fts.gz or c3_clsff.fts.gz.

	Old HTM grid versus new equatorial/polar grid
	---------------------------------------------

	The linear dimension of pixels on the sky is ~0.05*2^mode (so 0.05,
	0.1 and 0.2 degrees for mode 0,1,2, respectively). Or in terms of area
	on the sky 9*4^mode, or 9,36 and 144 arcmin^2 for mode 0,1,2.

	The HTM grid was used at level 11 for mode 1,2 and at level 12 for mode 0.
	The area of nodes in the HTM grid is 3 to 7.3 arcmin^2 at level 11, and
	0.86 to 1.8 arcmin^2 at level 12.

	The final skymaps have a basic resolution of 0.1 degrees on the sky or
	36 arcmin^2 per skybin. This is level 1 in the new setup. Higher levels
	are subdivisions of this grid, i.e. level n has bins with linear
	dimension of 0.1/n degrees, or area 36/n^2 arcmin^2. So n=3 in the new
	setup provides about the same resolution as HTM level 11, and level 5
	is about the same as HTM level 12.
 MODIFICATION HISTORY:
	NOV-2004, Paul Hick (UCSD/CASS)
	MAY-2005, Paul Hick (UCSD/CASS)
	    Added processing of command line keywords nped_min and ndark_min
	    to override the default test for accepting frames (based on setting
	    of flag by smei_base).
	SEP-2005, Paul Hick (UCSD/CASS)
	    Camera 3 glare removal is now also done using the glare model
	    for the multiplier, instead of using a few constants.
	NOV-2005, Paul Hick (UCSD/CASS), V2.0
	    Modified to use different glare maps for cameras 2 and 3.
	NOV-2005, Paul Hick (UCSD/CASS), V2.1
	    Added another low resolution map to output file (fraction
	    of orbit in seconds since start of orbit).
	    The lowres maps for the 'glare angles' are now always calculated.
	    They used to be set zero if glare subtraction was suppressed.
	    All lowres maps for camera 2 are run through GridSphere2D to
	    fill holes near the equatorial poles.
	DEC-2005, Paul Hick (UCSD/CASS), V2.11
	    Changed format of several entries in Fits header
	    Modified to deal with presence of -overwrite on cmd line
	DEC-2005, Paul Hick (UCSD/CASS), V2.12
	    Added keyword MODE to Fits header
	    Added processing of keyword to force overwrite of
	    skymaps with a lower version number.
	    Added keyword IMG_TYPE to Fits header
	JAN-2006, Paul Hick (UCSD/CASS), V3.00
	    Introduced new definition of orbit start times based on
	    spacecraft ephemeris data (see smei_sgp4_orbits.pro).
	JAN-2006, Paul Hick (UCSD/CASS), V3.01
	    Added keyword nshutter_open_skip to enable skipping of
	    frames after the shutter opens (see smei_frm_ok).
	JAN-2006,  Paul Hick (UCSD/CASS), V4.0
	    Fixed bug in smei_skyd_sky (the slope of the background
	    near stars was incorrect due to a wrong array index).
	    Reduced memory footprint by only processing HTM nodes
	    on the sky near the frame being processed.
	FEB-2006, Paul Hick (UCSD/CASS), V5.0
	    Removed JHU HTM grid.
	JUN-2006, Paul Hick (UCSD/CASS), V5.1
	    Added smei_skyd_size subroutine to control size of votes arrays.
	    Added direction cosine angle in long dimension to skymap file.
	    Note that this changes the layout of the Fits skymap file.
	JUN-2006, Paul Hick (UCSD/CASS), V5.2
	    Added hdrok array to store selection criteria for frames.
	    These are now added to the primary Fits header of the skymap.
	JUL-2006, Paul Hick (UCSD/CASS)
	    Fixed error in some of the comments for the map description
	    keyword for the polar maps.
	    Added Fits keyword STIME and ETIME to extension containing the time
	    STIME in seconds since the first frame used (these were only specified
	    in the main header). STIME is the time origin for the array.
	JUL-2006, Paul Hick (UCSD/CASS), V5.3
	    Added check for bad quaternions in smei_frm_ok (this is used to skip past
	    B-dot episodes during S/C anomalies, for instance).
	    Filled the 'bad pixel' map in smei_skyd_combine (this has been empty
	    since version 4.0).
	OCT-2006, John Clover, Paul Hick (UCSD/CASS), V6.0
	    Fixed problem near seam of map where start and end of orbit meet.
	    The orientation of camera 2 at the start of the orbit
	    is now used to draw a reference great circle on the sky. Near this
	    boundary pixels are tested individually to decide whether they are
	    part of the current orbit and should be dropped in the skymap.
	    Introduced torigin to keep track of the time origin for the
	    lowres time map. This is added to the Fits header of the time
	    map as keyword TORIGIN (used to be STIME).
	    Times tfirstfrm and tlastfrm are assigned the time of the first
	    and last frame, respectively, for which at least one pixel was
	    dropped in the skymap. These are written into the main header
	    of the skymap as keywords STIME and ETIME.
	    Added extra extension to lowres maps containg nr of pixels
	    contributing to each lowres bin.
	NOV-2006, Paul Hick (UCSD/CASS), V6.01
	    Bugfix in smei_frm_ok (exclusion zones for Sun, Moon and Venus
	    were not processed)
	MAR-2007, Paul Hick (UCSD/CASS)
	    Added check for "bad pixel" mask presence for camera 3.
	    The "closed shutter" calibration pattern for camera 3 is different
	    depending on whether a "bad pixel" mask is in effect.
	APR-2007, Paul Hick (UCSD/CASS), V6.1
	    Added keyword CLNEDGE, set to .FALSE.. Should be set .TRUE.
	    when straylight from sky just outside the fov is removed.
	MAY-2007, Paul Hick (UCSD/CASS), V6.2
	    Added GridSphere calls to smooth low resolution maps
	    where only a few CCD pixels (< 3) contribute to a skybin.
	MAY-2007, Paul Hick (UCSD/CASS), V6.21
	    Bug fix in smei_frm_read (was not picking up name of orbital
	    pattern).
	MAY-2007, Paul Hick (UCSD/CASS), V6.22
	    Bug fix in smei_skyd_size (abort was skipped when memory pool
	    for votes was full).
	JUN-2007, Paul Hick (UCSD/CASS), V6.23
	    Recompiled after bugfix in smei_frm_read.
	JUL-2007, Paul Hick (UCSD/CASS), V6.24
	    Renamed Fits key SMEI_HTM to SMEI_SKY (software version number)
	    Added cmd line argument -c3mask (used for camera 3 in mode 1
	    only) to control selection of calibration pattern (without or
	    with "bad-pixel" mask taken into account.
	DEC-2007, Paul Hick (UCSD/CASS)
	    For single orbit runs the exit code for a successful run is now
	    1 [new skymap (over)written] or 3 [no new skymap written, either
	    because there are zero frames in the orbit, or because a
	    a skymap existed already and was not overwritten].
	    For multiple orbits the exit code a successful run is always 1
	    (this also was the case for single orbit runs).
	DEC-2007, Paul Hick (UCSD/CASS), V7.01
	    Replaced keywords CX*,CY*,D_* keywords by WCS keywords
	    CRPIX*, CDELT*. Added other WCS keywords to make the
	    headers WCS compliant: CRVAL*, CTYPE*, CUNIT*, RADESYS,
	    EQUINOX, MJD-OBS and (polar maps only) LONPOLE.
	    Added keyword BAD_DATA to headers for lowres maps.
	    Added keyword GAIN with camera gain based on time
	    set in MJD-OBS and TIME.
	    Changed keyword CREATED to DATE (consistent with IDL)
	JAN-2008, Paul Hick (UCSD/CASS), V7.02
	    Added keywords SMEI_CAL and SMEI_ORB with version numbers
	APR-2008, Paul Hick (UCSD/CASS), V7.03
	    Removed comma from comment string for Fits keyword MAP.
	JUL-2008, Paul Hick (UCSD/CASS)
	    Decreased setting of iSilent passed to smei_frm_ok
	SEP-2008, Paul Hick (UCSD/CASS), V7.04
	    Added cmd line argument sdark.
	OCT-2008, Paul Hick (UCSD/CASS), V7.05
	    Modifications to handling of transitions of c3
	    "bad-pixel" masks (in smei_frm_c3mask_active).
	NOV-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V7.06
	    Added default box for rejection of frames with Sun
	    too close to the optical axis (in smei_frm_ok).
	JUN-2011, John Clover (UCSD/CASS), V7.07
	    No code change; the file $SMEIDB/starmask.fts.gz has been modified.
	    The previous version used the coordinate system used by Andy for
	    the grd files from which starmask.fts.gz derives. The SMEI sky
	    maps use a different reference frame. The conversion between the
	    two frames was supposed to be made in smei_mkstarmask.pro, but this
	    was done. The new version of starmask.fts.gz fixes this.
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V7.08
	    Changed the print statements in smei_skyd_combine. For a -quiet
	    setting less/equal 1 now all votes (both accepted and rejected)
	    are shown, alongside the final value for each skybin.
	    Also added cmd line keyword -nostarmask to disable use of
	    starmask.fts.gz, effectively disabling the correction for
	    'star-nibbling'.


smei_skyd_addvalue $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_addvalue.f
[Previous] [Next]
 NAME:
	smei_skyd_addvalue
 PURPOSE:
	Make sure that the values added together
	are all about the same size
	(i.e. do not add 0.5 and 359.5 but 0.5 and -0.5 for angles).
 CALLING SEQUENCE:
	subroutine smei_skyd_addvalue(val,dval,hit,sum)
 INPUTS:
	val		real
	dval		real
	hit		real		number of hits in bin so far
	sum		real		accumulated value
 OUTPUTS:
	sum		real		update accumulated value
 MODIFICATION HISTORY:
	NOV-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_checkpix $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_checkpix.f
[Previous] [Next]
 NAME:
	smei_skyd_checkpix
 PURPOSE:
	Check location of pixel against reference camera frame
	defining a great circle on the sky defining at the seam
	between start and end of orbit
 CATEGORY:
	camera/for/sky
 CALLING SEQUENCE:
	logical function smei_skyd_checkpix(pfov,runit,qq_cam2cam_edge)
 INPUTS:
	pfov		integer	linear array index into CCD frame
	runit(*)	double precision
				unit vector in current camera frame
	qq_cam2cam_edge(*)
			double precision
				quaternion that rotates vectors from
				current camera frame to reference frame
 OUTPUTS:
	smei_skyd_checkpix
			logical see Procedure
 CALLS: ***
	quaternion_rotate_xyz
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 PROCEDURE:
	The camera frame has z-axis along the optical axis, x-axis
	along the long dimension of the fov, and y-axis along the
	narrow dimension such that y increases with decreasing radius
	on the CCD. Stars travel in the direction of decreasing y;
	frames sweep the sky in the direction of increasing y.

	The reference camera frame is defined by the nominal viewing
	direction of camera 2 at the start of an orbit. The long
	dimension of camera 2 defines a reference circle that is used
	separate start and end of orbit.

	If a pixel in any frame near start or end of the orbit has
	a negative y than it is traveling towards the reference
	circle; if it has positive y it is traveling away from it.

	For frames near the start of an orbit negative y
	(smei_skyd_checkpix=.FALSE.) means the pixel is part of the
	previous orbit; positive y (smei_skyd_checkpix=.TRUE.)
	means the pixel is part of the current orbit.

	For frames near the end of an orbit negative y
	(smei_skyd_checkpix=.FALSE.) means the pixel is still in the
	current orbit; positive y (smei_skyd_checkpix=.TRUE.)
	means the pixel is part of the next orbit.
 MODIFICATION HISTORY:
	OCT-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_combine $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_combine.f
[Previous] [Next]
 NAME:
	smei_skyd_combine
 PURPOSE:
	Combines in into a single value.
 CATEGORY:
	smei/camera/for/sky
 CALLING SEQUENCE:
	integer function smei_skyd_combine(iType,bKeepGlitch,iSilent,level,node_id,count,val,flag,pos,rgood,rbad,badpix)
	!integer function smei_skyd_combine(iType,bKeepGlitch,iSilent,count,val,flag,rgood,rbad,badpix)
 INPUTS:
	iType			integer		defines type of final response
						0: Mean
						1: Median
						2: Mean/median (ratio)
						3: Mean-median (difference)
						4: Standard deviation
						5: Median/std (ratio)
	bKeepGlitch		logical 	suppress glitch removal
	iSilent			integer		higher values suppress more informational messages
	count			integer		number of votes
	level			integer
	node_id			integer
	val(*)			real		response for all votes
	flag(*)			integer*1	bitwise flags (e.g. the 'near star' flag)
	pos(*)			integer		linear array index for the originating SMEI frame
						for each vote
	badpix(*)		integer		'bad pixel' map		
 OUTPUTS:
	smei_skyd_combine	integer		number of good votes from which final response
						is calculated
	rgood			real		final response for selected node,
						calculated from all good votes
	rbad			real		fraction of total adus in rejected votes: 1:nlow-1 where
						too low; nhigh+1,count were too high
	badpix(*)		integer		updated 'bad pixel' map
 CALLED BY:
	smei_skyd_fill, smei_skyd_flush, smei_skyd_sort
 INCLUDE:
	include		'filparts.h'
	include		'smei_skyd_dim.h'
 CALLS: ***
	ArrR4Mean, ArrR4Median, ArrR4Stdev, ArrR4Total, BadR4, Flt2Str, IndexR4, Int2Str, Say
	Str2Str, cInt2Str, smei_skyd_node2skyloc
 PROCEDURE:
 MODIFICATION HISTORY:
	JAN-2006, Paul Hick (UCSD/CASS)
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Added arguments level and node_id (used in constructing diagnostic messages)
	    Made diagnostic messages more intelligible. All votes are now
	    printed if iSilent <=1.


smei_skyd_dim $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_dim.h
[Previous] [Next]
 NAME:
	smei_skyd_dim
 PURPOSE:
	Parameter definitions for sizes of skymaps
 CALLING SEQUENCE:
	include 'smei_skyd_dim.h'
 INCLUDED BY:
	smei_skyd, smei_skyd_combine, smei_skyd_fill, smei_skyd_node2sky
	smei_skyd_node2skyloc, smei_skyd_pixel, smei_skyd_scan, smei_skyd_size
	smei_skyd_sky
 PROCEDURE:
	Equatorial map covers [0,360] in RA and [-60,60] in declination
	at 0.1 degree resolution.
	The north and polar maps are polar maps out to 40 degrees from
	the pole in two perpendicular directions with 0.1 degree resolution.
 MODIFICATION HISTORY:
	JAN-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_fill $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_pool.f
[Previous] [Next]
 NAME:
	smei_skyd_fill
 PURPOSE:
	Each pixel contributes to several nodes. These 'votes' are added
	here to the pool of votes for all nodes.
 CATEGORY:
	smei/camera/for/sky
 CALLING SEQUENCE:
	subroutine smei_skyd_fill(iSilent,level,icam,mode,ra_pix,dec_pix,ipos,response,nflag)
 INPUTS:
	iSilent		integer			higher value suppresses more messages
	level		integer			determines resolution of pool of nodes
						(1 <= level <= SKYD__LEVEL=3
	icam		integer			camera 1,2, or 3
	mode		integer			mode 0,1 or 2
	ra_pix (*)	double precision	RA  for center and four corners of a pixel
	dec_pix(*)	double precision	dec for center and four corners of a pixel
						(passed to smei_skyd_pixel)
	ipos		integer			linear array position of pixel in frame
	response	real			CCD response for pixel
	nflag		integer			bitwise flags
 CALLS: ***
	ArrI4Copy, ArrI4GetMinMax, BadR4, BadR8, Flt2Str, IndexI4, Int2Str, Say, Str2Str, cInt2Str
	datan2d, dcosd, dsind, quaternion_rotate_xyz, smei_axis_cam, smei_skyd_combine
	smei_skyd_node2sky, smei_skyd_pixel, smei_skyd_size
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 INCLUDE:
	include		'filparts.h'
	include		'smei_skyd_dim.h'
 PROCEDURE:
	The pool of nodes is maintaind in the node_* arrays.

	All nodes in the first couple of frames are all put in pool 2
	(with one vote for each node). These are the nodes that may be encountered
	again in frames at the end of the orbit.

	For subsequent frames, if the node is present already in pool 1 or 2 then
	a vote is added to that node. New nodes are put in pool 1. 

	Nodes from pool 1 are removed if they move far enough outside the FOV.
	After the last frame has been processed (and the skymap is complete),
	both pools are cleared.

	The node_sort array contains the indices needed to sort the node_* arrays
	containing nodes up to and including contributions from the previous frame,
	i.e. NOT YET the contribution from the frame currently being processed.
	At the start node_sort(*) = n_nodes(SKYD__NODE_NTOP).
	As pixels from the new frame are added the node_* arrays and
	n_nodes(SKYD__NODE_NTOP) are updated; node_sort will be synchronized with
	n_nodes(SKYD__NODE_NTOP) by skyd_sort prior to starting the next frame.

	The implicit assumption is made that within a frame all triangles will have
	different node names, i.e. NO NODE IS DUPLICATED WITHIN A FRAME.
 MODIFICATION HISTORY:
	JAN-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_fixvalue $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_fixvalue.f
[Previous] [Next]
 NAME:
	smei_skyd_fixvalue
 PURPOSE:
	Make sure value is in range [val_lo, val_hi]
 CALLING SEQUENCE:
	subroutine smei_skyd_fixvalue(val,val_lo,val_hi)
 INPUTS:
	val		real
	val_lo		real
	val_hi		real
 OUTPUTS:
	val		real
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 MODIFICATION HISTORY:
	OCT-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_flush $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_pool.f
[Previous] [Next]
 NAME:
	smei_skyd_flush
 PURPOSE:
	Removes node that have moved outside the field of view from the
	pool of nodes after depositing in on the equatorial and/or polar skymaps
 CALLING SEQUENCE:
	entry smei_skyd_flush(iType,bKeepGlitch,iSilent,level,icam,mode,qq,drfov_max,img,xmg,badpix,lowres)
 INPUTS:
	iType		integer		Passed to smei_skyd_combine to determine the statistical quantity.
					possible values n=0,1,2,3,4,5. Set on cmd line using
					-mean, -median or -type=n options. 
	bKeepGlitch	logical		Passed to smei_skyd_combine
					Suppress glitch removal. Set with cmd line -keepglitch option
	level		integer		
	mode		integer		mode (0,1,2)
	icam		integer		camera (1,2,3)
	qq(*)		double precision quaternion
	drfov_max	real
 OUTPUTS:
	xmg(*)		real		accumulated totals for equatorial map
	img(*)		real		total counts for equatorial map
					Passed to smei_skyd_node2sky which updates
					them when nodes are complete
	badpix(*)	integer		'bad pixel' map for SMEI frame
					Passed to smei_skyd_combine
	lowres(SKYD__NXLO,SKYD__NYLO,SKYD__LO_NMAP)
 CALLS: ***
	ArrI4Copy, ArrI4GetMinMax, BadR4, BadR8, Flt2Str, IndexI4, Int2Str, Say, Str2Str, cInt2Str
	datan2d, dcosd, dsind, quaternion_rotate_xyz, smei_axis_cam, smei_skyd_combine
	smei_skyd_node2sky, smei_skyd_pixel, smei_skyd_size
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 PROCEDURE:
	n_nodes		integer		n_nodes(SKYD__NODE_NTOP)
					  highest occupied index in pool arrays
					  updated to a lower value when empty slots
					  at the end of the pool are removed.
					n_nodes(SKYD__NODE_NSLOT)
					  total number of nodes in pool
					  updated when nodes are removed
					n_nodes(SKYD__NODE_NVOTE)
					  total number of votes in pool
					  update when nodes are removed
	smei_skyd_flush is called in smei_skyd_sky prior to adding in the pixels
	of the a new frame into the pool, i.e. the quaternion from the new
	header is used to decided whether a node is inside/outside the fov.
 MODIFICATION HISTORY:
	FEB-2006, Paul Hick (UCSD/CASS)
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Added args level and node_id to call to smei_skyd_combine


smei_skyd_fnc $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_fnc.h
[Previous] [Next]
 NAME:
	smei_skyd_fnc
 PURPOSE:
	Function declarations for smei_sky
 CATEGORY:
	camera/for/sky
 CALLING SEQUENCE:
	include		'smei_skyd_fnc.h'
 PROCEDURE:
 MODIFICATION HISTORY:
	JUN-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_fts $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_sky.f
[Previous] [Next]
 NAME:
	smei_skyd_fts
 PURPOSE:
	Writes orbital sky maps to FTS file
 CATEGORY:
	ucsd/camera/for/sky
 CALLING SEQUENCE:
	entry smei_skyd_fts(sky_version,forbit_ext,forbit_ltd,hdrok,nframe,iframe,ibreak)
 CALLS: ***
	ArrI4Copy, ArrI4Zero, ArrR4DivideByArrR4, ArrR4Mask, ArrR4PlusArrR4, ArrR4Zero
	ArrR8Copy, BadR4, Dbl2Str, FTCLOS, FTCRHD, FTINIT, FTPHPR, FTPKYG, FTPKYJ, FTPKYL, FTPKYS
	FTPPRB, FTPPRE, FTPPRJ, Flt2Str, ForeignArgSet, ForeignI4Arg, ForeignR8Arg
	GridSphere2D, GridSphereRange, GridSphereWeight, Int2Str, SMEI_SKYD_PRINT
	SMEI_SKYD_PRINT_NODES, SMEI_SKYD_SAVE, Say, Str2Str, Time2Day8, Time2Delta
	Time2Differ, Time2HMS, Time2MJD, Time2Str, Time2System, Time2smei_quaternion
	cInt2Str, dasind, datan2d, dcosd, dsind, iFilePath, iFreeLun, iGetFileSpec, iGetLun
	iOSDeleteFile [1], iOSDeleteFile [2], iOSDeleteFile [3], iOSDeleteFile [4]
	iSearch [1], iSearch [2], iSearch [3], iSearch [4], iSetFileSpec, itrim
	quaternion_inverse, quaternion_multiply, quaternion_rotate_xyz, say_fts
	smei_FitPlane, smei_axis_cam, smei_axis_ccd, smei_cal_get
	smei_frm_c3mask_active, smei_get_glare, smei_get_lsff, smei_get_starmask
	smei_hdr_quaternion, smei_hdr_time, smei_inside_fov, smei_orb_get, smei_orbit2
	smei_orbit_period2, smei_orbit_time2, smei_skyd_checkpix, smei_skyd_fill
	smei_skyd_fixvalue, smei_skyd_flush, smei_skyd_go, smei_skyd_scan
	smei_skyd_sort
 CALLED BY:
	smei_skyd
 PROCEDURE:
 >	Entry point in smei_skyd_sky.

 >	The equatorial maps use a linear scale to from array index i,j to ra,dec
		i=1,nxeq, ra=[0,360), j=1,nyeq, dec=[-60,60)
		i = cxeq+ra *d_eq	ra  = (i-cxeq)/d_eq
		j = cyeq+dec*d_eq	dec = (j-cyeq)/d_eq
 >	The polar maps use a polar transformation
		i=1,nxeq, j=1,nyeq
		i = cxpl+d_pl*(90-abs(dec))*cos(ra)
		j = cypl+d_pl*(90-abs(dec))*sin(ra)
		ra  = atan( (j-cypl)/(i-cxpl) )
		90-abs(dec) = sqrt( (i-cxpl)^2+(j-cypl)^2 )
 >	The equatorial map is written as primary data, the north and
	south polar maps as first and second extension, respectively.
 >	Added entries to FTS header:

	Ext 0 (equatorial map):
		SMEI_SKY	character	smei_skyd software version number
		DATE		character	File creation time
		NAME		character	File name (no directory, no type)
		CAMERA		integer		Camera  
		ORBIT		double precision Orbit number
		MAP		character	String describing map
		CX		double precision Array index for RA=0 
		CY		double precision Array index for DEC=0
		BD		double precision Number of bins per degree

	Ext 1 (north pole map)
		MAP		character	String describing map
		CX		double precision Array index for north pole
		CY		double precision Array index for north pole
		BD		double precision Number of bins per degree

	Ext 2 (south pole map)
		MAP		character	String describing map
		CX		double precision Array index for south pole
		CY		double precision Array index for south pole
		BD		double precision Number of bins per degree

	Note that the values for both poles are the same.

 >	After the high-resolution skymaps follow a group of (currently) six
	low resolution maps:

	Ext 3-8 ('dirty' sky brightness, time, psf orientation w.r.t. equatorial
	north and w.r.t. vernal equinox, fraction of discarded response, and
	fraction of bad nodes)
		MAP		character	String describing map
		CX		double precision Array index for RA=0 
		CY		double precision Array index for DEC=0
		BD		double precision Number of bins per degree
 MODIFICATION HISTORY:
	NOV-2004, Paul Hick (UCSD/CASS)
	APR-2005, Paul Hick (UCSD/CASS)
	    New set of camera quaternions for cam 1 and 2.
	    Ad hoc corrections to tx and ty in smei_ccd2cam.
	    Added 'onesky' keyword.
	    Extra keyword ONEORBIT to identify orbital maps.
	NOV-2005, Paul Hick (UCSD/CASS)
	    Modified to accepts different glare maps for cameras 2 and 3.
	DEC-2005, Paul Hick (UCSD/CASS)
	    Modified to deal with presence of -overwrite on cmd line.
	    Added Fits keyword MODE.
	    Added processing of SMEI_HTM keyword for existing sky maps
	    to force overwrite of maps with lower version number.
	APR-2007, Paul Hick (UCSD/CASS)
	    Added keyword CLNEDGE, set to .FALSE.. Should be set .TRUE.
	    when straylight from sky just outside the fov is removed.
	JUL-2007, Paul Hick (UCSD/CASS)
	    Renamed key SMEI_HTM to key SMEI_SKY (for version number)
	DEC-2007, Paul Hick (UCSD/CASS)
	    Replaced keywords CX*,CY*,D_* keywords by WCS keywords
	    CRPIX*, CDELT*. Added other WCS keywords to make the
	    header WCS compliant: CRVAL*, CTYPE*, CUNIT*, RADESYS,
	    EQUINOX, MJD-OBS and (polar maps only) LONPOLE.
	    Added keyword BAD_DATA to headers for lowres maps.
	    Added keyword GAIN with camera gain based on time
	    set in MJD-OBS and TIME.
	APR-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Removed comma from comment string for keyword MAP


smei_skyd_go $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_go.f
[Previous] [Next]
 NAME:
	smei_skyd_go
 PURPOSE:
	Decide on whether to continue processing frames for given orbit
 CALLING SEQUENCE:
	logical function smei_skyd_go(bOverwrite,bCheckVersion,cFile,version,bExists)
 INPUTS:
	bOverwrite		logical
	bCheckVersion		logical
	cFile			character*(*)
	version			double precision
 OUTPUTS:
	bExists			logical
	smei_skyd_go	logical
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 INCLUDE:
	include		'filparts.h'
	include		'ftspar.h'
 CALLS: ***
	FTCLOS, FTGKYD, FTNOPN, Say, iFreeLun, iGetLun, iSearch [1], iSearch [2], iSearch [3]
	iSearch [4], say_fts
 PROCEDURE:
	Called when the first good frame for an orbits has been found to decide
	whether the orbit needs to be processed and a skymap is to be created.
 >	If the skymap does not exist then a skymap is created (bExists=.FALSE.;
	smei_skyd_go=.TRUE.)
 >	If the skymap already exists then bOverwrite, bCheckVersion and version
	determine what happens:
	1. If bOverwrite is .TRUE. then the skymap is overwritten (bExists=.TRUE.,
	smei_skyd_go=.TRUE.)
	2. If bCheckversion is .TRUE. and version is larger than the version of
	the skymap then the skymap is overwritten (bExists=.TRUE.;
	smei_skyd_go=.TRUE.)
	3. If bOverwrite=bCheckVersion=.FALSE. then the skymap is not overwritten
	(bExists=.TRUE.; bGo=.FALSE.)
 MODIFICATION HISTORY:
	DEC-2005, Paul Hick (UCSD/CASS)
	JUL-2007, Paul Hick (UCSD/CASS)
	    Added test for key SMEI_SKY in addition to check for now
	    obsolete key SMEI_HTM to determine version number.
	NOV-2007, Paul Hick (UCSD/CASS)
	    Bug fix. istat was not reinitialized to zero after looking for
	    keyword SMEI_SKY. Bug reported by John Clover.
	DEC-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Removed check for SMEI_HTM. Keyword is no longer present
	    in any of the skymaps on $SMEISKY0/sky.


smei_skyd_init $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_sky.f
[Previous] [Next]
 NAME:
	smei_skyd_init
 PURPOSE:
	Initialize variables for smei_skyd_sky.
 CALLING SEQUENCE:
	entry smei_skyd_init(sky_version,icurrent_orbit,TLow,THigh,hdr,cVar,cArg,bGo)
 INPUTS:
	sky_version	double precision	smei_skyd version number
	icurrent_orbit	integer			orbit number of the current orbit
						being processed (the 'hdr' for the
						the current frame might still belong
						to the previous of next orbit).
	hdr(*)		double precision	frame header array
	cVar(*)		character*(*)		cVar(2): pattern file or SMEIDB?
						cVar(4): output directory
	cArg		character*(*)		command line keywords
 OUTPUTS:
	bGo		logical			bGo is returned .FALSE. only
						if the first frame for a new skymap
						is processed, and the Fits file for
						the skymap already exists.
 CALLS: ***
	ArrI4Copy, ArrI4Zero, ArrR4DivideByArrR4, ArrR4Mask, ArrR4PlusArrR4, ArrR4Zero
	ArrR8Copy, BadR4, Dbl2Str, FTCLOS, FTCRHD, FTINIT, FTPHPR, FTPKYG, FTPKYJ, FTPKYL, FTPKYS
	FTPPRB, FTPPRE, FTPPRJ, Flt2Str, ForeignArgSet, ForeignI4Arg, ForeignR8Arg
	GridSphere2D, GridSphereRange, GridSphereWeight, Int2Str, SMEI_SKYD_PRINT
	SMEI_SKYD_PRINT_NODES, SMEI_SKYD_SAVE, Say, Str2Str, Time2Day8, Time2Delta
	Time2Differ, Time2HMS, Time2MJD, Time2Str, Time2System, Time2smei_quaternion
	cInt2Str, dasind, datan2d, dcosd, dsind, iFilePath, iFreeLun, iGetFileSpec, iGetLun
	iOSDeleteFile [1], iOSDeleteFile [2], iOSDeleteFile [3], iOSDeleteFile [4]
	iSearch [1], iSearch [2], iSearch [3], iSearch [4], iSetFileSpec, itrim
	quaternion_inverse, quaternion_multiply, quaternion_rotate_xyz, say_fts
	smei_FitPlane, smei_axis_cam, smei_axis_ccd, smei_cal_get
	smei_frm_c3mask_active, smei_get_glare, smei_get_lsff, smei_get_starmask
	smei_hdr_quaternion, smei_hdr_time, smei_inside_fov, smei_orb_get, smei_orbit2
	smei_orbit_period2, smei_orbit_time2, smei_skyd_checkpix, smei_skyd_fill
	smei_skyd_fixvalue, smei_skyd_flush, smei_skyd_go, smei_skyd_scan
	smei_skyd_sort
 CALLED BY:
	smei_skyd
 PROCEDURE:
	Entry point in smei_skyd_sky.
 MODIFICATION HISTORY:
	NOV-2004, Paul Hick (UCSD/CASS)
	DEC-2005, Paul Hick (UCSD/CASS)
	    Modified to deal with presence of -overwrite on cmd line
	JUL-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Added check for cmd line argument -c3mask=0/1
	    Added argument ipick to smei_cal_get calls


smei_skyd_make $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_sky.f
[Previous] [Next]
 NAME:
	smei_skyd_make
 PURPOSE:
	Takes the three node arrays (node, nodeid, and hits),
	averages them and puts them into a two-dimensional skymap
 CATEGORY:
	camera/for/sky
 CALLING SEQUENCE:
	entry smei_skyd_make()
 OUTPUTS:
	Output goes to three equatorial .grd files, two polar .grd files
	and a FTS file containing both equatorial and polar maps.
 CALLS: ***
	ArrI4Copy, ArrI4Zero, ArrR4DivideByArrR4, ArrR4Mask, ArrR4PlusArrR4, ArrR4Zero
	ArrR8Copy, BadR4, Dbl2Str, FTCLOS, FTCRHD, FTINIT, FTPHPR, FTPKYG, FTPKYJ, FTPKYL, FTPKYS
	FTPPRB, FTPPRE, FTPPRJ, Flt2Str, ForeignArgSet, ForeignI4Arg, ForeignR8Arg
	GridSphere2D, GridSphereRange, GridSphereWeight, Int2Str, SMEI_SKYD_PRINT
	SMEI_SKYD_PRINT_NODES, SMEI_SKYD_SAVE, Say, Str2Str, Time2Day8, Time2Delta
	Time2Differ, Time2HMS, Time2MJD, Time2Str, Time2System, Time2smei_quaternion
	cInt2Str, dasind, datan2d, dcosd, dsind, iFilePath, iFreeLun, iGetFileSpec, iGetLun
	iOSDeleteFile [1], iOSDeleteFile [2], iOSDeleteFile [3], iOSDeleteFile [4]
	iSearch [1], iSearch [2], iSearch [3], iSearch [4], iSetFileSpec, itrim
	quaternion_inverse, quaternion_multiply, quaternion_rotate_xyz, say_fts
	smei_FitPlane, smei_axis_cam, smei_axis_ccd, smei_cal_get
	smei_frm_c3mask_active, smei_get_glare, smei_get_lsff, smei_get_starmask
	smei_hdr_quaternion, smei_hdr_time, smei_inside_fov, smei_orb_get, smei_orbit2
	smei_orbit_period2, smei_orbit_time2, smei_skyd_checkpix, smei_skyd_fill
	smei_skyd_fixvalue, smei_skyd_flush, smei_skyd_go, smei_skyd_scan
	smei_skyd_sort
 CALLED BY:
	smei_skyd
 PROCEDURE:
 >	Entry point in smei_skyd_sky. See that procedure for more information.
 MODIFICATION HISTORY:
	April 2003, Aaron Smith (UCSD/CASS)
	    Updated to include capability for all sky imaging in 3 equatorial
	    plots, and two polar plots


smei_skyd_node2sky $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_node2sky.f
[Previous] [Next]
 NAME:
	smei_skyd_node2sky
 PURPOSE:
	Drop node on skymap (equatorial or polar maps)
 CALLING SEQUENCE:
	subroutine smei_skyd_node2sky(level,node_id,nvote,ngood,xgood,img,xmg)
 INPUTS:
	node_i		integer
	level		integer
	node_id		integer
	nvote		integer			(not used)
	ngood		integer			(not used)
	xgood		real			response of node (return value of
						smei_skyd_combinevotes.
	xmg(*)		real			accumulated totals for equatorial map
	img(*)		real			total counts for equatorial map
 OUTPUTS:
	xmg(*)		real			updated sky map arrays
	img(*)		real
 CALLED BY:
	smei_skyd_fill, smei_skyd_flush, smei_skyd_sort
 INCLUDE:
	include		'smei_skyd_dim.h'
 SEE ALSO:
	smei_skyd_combine
 PROCEDURE:
 MODIFICATION HISTORY:
	JAN-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_node2skyloc $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_node2skyloc.f
[Previous] [Next]
 NAME:
	smei_skyd_node2skyloc
 PURPOSE:
	Drop node on skymap (equatorial or polar maps)
 CALLING SEQUENCE:
	subroutine smei_skyd_node2skyloc(level,node_id,kp,ix,jy)
 INPUTS:
	node_i		integer
	level		integer
	node_id		integer
 OUTPUTS:
	kp		integer		kp=0: equatorial map
					kp=1: north pole map
					kp=2: south pole map
	ix		integer		array index in 1st dim
	jy		integer		array index in 2nd dim
					(ix,jy) is the array index into
					a hires skymap array
 CALLED BY:
	smei_skyd_combine
 INCLUDE:
	include		'smei_skyd_dim.h'
 SEE ALSO:
	smei_skyd_combine
 PROCEDURE:
 MODIFICATION HISTORY:
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
		Extracted from smei_skyd_node2sky


smei_skyd_pixel $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_pixel.f
[Previous] [Next]
 NAME:
	smei_skyd_pixel
 PURPOSE:
	Construct list of nodes (skybins) to which a given pixel contributes 
 CATEGORY:
	smei/camera/for/sky
 CALLING SEQUENCE:
	integer function smei_skyd_pixel(level,ra_pix,dec_pix,max_count,node_list)
 INPUTS:
	level		integer			determines resolution of pool of nodes
						(1 <= level <= SKYD__LEVEL=3
	ra_pix (0:4)	double precision	RA  for center and four corners of a pixel
	dec_pix(0:4)	double precision	dec for center and four corners of a pixel

	max_count	integer			Max allowed number of nodes
 OUTPUTS:
	smei_skyd_pixel	integer			number of nodes on node_list
	node_list(*)	integer			node id
 CALLS: ***
	Say, cInt2Str, dcosd, dsind, inside_area
 CALLED BY:
	smei_skyd_fill, smei_skyd_flush, smei_skyd_sort
 INCLUDE:
	include		'smei_skyd_dim.h'
 PROCEDURE:
	The name of a node is related to the linear array index into one
	of the skymaps (equatorial, south and north pole).
	The equatorial map has NEQ = (level*SKYD__NXEQ)*(level*SKYD__NYEQ) bins.
	The two polar maps have NPL = (level*SKYD__NXPL)*(level*SKYD__NYPL) bins.

	Each node corresponds to a skybin in these maps.
	An equatorial node has node id 1 ... NEQ
	An north polar node has node id NEQ+1 ... NEQ+NPL
	A south polar node has node id NEQ+NPL+1 ... NEQ+2*NPL

	Program execution is aborted if there are more than max_count nodes
 MODIFICATION HISTORY:
	FEB-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_scan $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_scan.f
[Previous] [Next]
 NAME:
	smei_skyd_scan
 PURPOSE:
	Extracts part of skymap inside box bounded in right ascension
	and declination
 CATEGORY:
	camera/for/sky
 CALLING SEQUENCE:
	subroutine smei_skyd_scan(ra_min,ra_max,dec_min,dec_max,
     &		d_eq_,n_eq_,nxeq_,nyeq_,cxeq_,cyeq_,
     &		d_pl_,n_pl_,nxpl_,nypl_,cxpl_,cypl_,	img,xmg)
 INPUTS:
	ra_min		double precision	minimum right ascension (deg) in [0,360]
	ra_max		double precision	maximum right ascension (deg) in [0,360]
						If ra_min > ra_max then RA=[ra_min,360]
						and RA[0,ra_max] are extracted
	dec_min		double precision	minimum declination
	dec_max		double precision	maximum declination
	xmg(*)		real			sky map
	img(*)		real			sky map counts
 OUTPUTS:
	For the eqautorial map:

	d_eq_		double precision	bin size (skybins per degree)
	n_eq_		integer			nr of sky bins (=nxeq_*nyeq_)
	nxeq_		integer			nr of sky bins in RA direction
	nyeq_		integer			nr of sky bins in dec direction
	cxeq_		double precision	array index for RA=0
	cyeq_		double precision	array index for dec=0

	For the polar maps:

	d_pl_		double precision	radial bin size (skybins per degree)
	n_pl_(2)	integer			nr of sky bins in polar maps (=nxpl_*nypl_)
	nxpl_(2)	integer			nr of sky bins in x-direction of polar map
	nypl_(2)	integer			nr of sky bins in y-direction of polar map
	cxpl_(2)	double precision	horizontal array index of pole
	cypl_(2)	double precision	vertical array index of pole

	xmg(*)		real			updated sky maps
	img(*)		real			updated sky map counts
 CALLS: ***
	ArrR4Copy, Int2Str, Say, Str2Str, dcosd, dsind
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 INCLUDE:
	include		'filparts.h'
	include		'smei_skyd_dim.h'
 PROCEDURE:
 MODIFICATION HISTORY:
	MAR-2006, Paul Hick (UCSD/CASS)
	JUN-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
	    Added print statements for pixel coordinates in full-sky map for the
	    the lower-left corner of the selected patch of sky.


smei_skyd_size $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_size.f
[Previous] [Next]
 NAME:
	smei_skyd_size
 CATEGORY:
	smei/camera/for/sky
 CALLING SEQUENCE:
	subroutine smei_skyd_size(iSilent,id,n_nodes,node_cnt,node_value,node_flag)
 INPUTS:
	iSilent			integer		higher value suppresses more messages
	id			integer		0: increase max number of votes allowed
						1: increase max number of nodes allowed
	n_nodes(SKYD__NODE_N)
				integer		pool statistics
	node_cnt  (SKYD__NODES)	integer
	node_value(SKYD__NODES)	real
	node_flag (SKYD__NODES)	integer*1
					pool arrays
 CALLED BY:
	smei_skyd_fill, smei_skyd_flush, smei_skyd_sort
 INCLUDE:
	include		'filparts.h'
	include		'smei_skyd_dim.h'
 CALLS: ***
	ArrI4GetMinMax, Flt2Str, Int2Str, Say, Str2Str
 MODIFICATION HISTORY:
	MAR-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)


smei_skyd_sky $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_sky.f
[Previous] [Next]
 NAME:
	smei_skyd_sky
 PURPOSE:
	Indexes a frame of SMEI data.
 CATEGORY:
	camera/for/sky
 CALLING SEQUENCE:
	subroutine smei_skyd_sky(hdr,iframe,frame)
 INPUTS:
	hdr(*)		double precision frame header
	frame(*)	real		2-D SMEI frame
 OUTPUTS:
 CALLED BY:
	smei_skyd
 IMPLICIT:
	implicit none
 INCLUDE:
	include		'filparts.h'
	include		'smei_frm_layout.h'
	include		'smei_frm_hdr.h'
	include		'smei_frm_hdrok.h'
	include		'smei_skyd_dim.h'
 CALLS: ***
	ArrI4Copy, ArrI4Zero, ArrR4DivideByArrR4, ArrR4Mask, ArrR4PlusArrR4, ArrR4Zero
	ArrR8Copy, BadR4, Dbl2Str, FTCLOS, FTCRHD, FTINIT, FTPHPR, FTPKYG, FTPKYJ, FTPKYL, FTPKYS
	FTPPRB, FTPPRE, FTPPRJ, Flt2Str, ForeignArgSet, ForeignI4Arg, ForeignR8Arg
	GridSphere2D, GridSphereRange, GridSphereWeight, Int2Str, SMEI_SKYD_PRINT
	SMEI_SKYD_PRINT_NODES, SMEI_SKYD_SAVE, Say, Str2Str, Time2Day8, Time2Delta
	Time2Differ, Time2HMS, Time2MJD, Time2Str, Time2System, Time2smei_quaternion
	cInt2Str, dasind, datan2d, dcosd, dsind, iFilePath, iFreeLun, iGetFileSpec, iGetLun
	iOSDeleteFile [1], iOSDeleteFile [2], iOSDeleteFile [3], iOSDeleteFile [4]
	iSearch [1], iSearch [2], iSearch [3], iSearch [4], iSetFileSpec, itrim
	quaternion_inverse, quaternion_multiply, quaternion_rotate_xyz, say_fts
	smei_FitPlane, smei_axis_cam, smei_axis_ccd, smei_cal_get
	smei_frm_c3mask_active, smei_get_glare, smei_get_lsff, smei_get_starmask
	smei_hdr_quaternion, smei_hdr_time, smei_inside_fov, smei_orb_get, smei_orbit2
	smei_orbit_period2, smei_orbit_time2, smei_skyd_checkpix, smei_skyd_fill
	smei_skyd_fixvalue, smei_skyd_flush, smei_skyd_go, smei_skyd_scan
	smei_skyd_sort
 SEE ALSO:
	smei_skyd_init, smei_skyd_make
 PROCEDURE:
	The photometric measurements from a single SMEI camera are combined
	and then averaged to produce a surface-brightness sky map.
	The "level" parameter governs the
	granularity of the triangular coordinate frame. The coordinates of
	the four corners of a pixel (or bin) are transformed down into this
	frame, and the photometric surface brightness as measured by that
	pixel is added to all nodes whose centers lie within the rectangle.
	This surface brightness is corrected by 1/cosine of the pixels angle
	to the camera axis, and by r/rad0 the pixels fractional distance to
	the FOVs rotational center. When the data sequence is finished, all
	triangle response sums are averaged and the resulting sky map binned
	into an output surface brightness map.
 MODIFICATION HISTORY:
	2002,2003 Aaron Smith (UCSD/CASS)
	2002->Original
	2003->removed most C++ functions and re-wrote in fortran as subroutines
	    ->add quaternion capabilities
	DEC-2002, Paul Hick (UCSD/CASS)
	    Defined LEVEL and NMAX as parameters. NMAX is determined from LEVEL.
	    NMAX is then used to dimension arrays node, nodeid and hits
	JAN-2003, Andrew Buffington (UCSD/CASS)
	    Integrated standard pedestal and dark current routines.
	    Rendered names compliant with those of B.V. Jackson
	    Incorporated 1/cosine surface-brightness correction for aperture
	    perspective (currently in smei_skyd_sky routine)
	    Incorporated large and small scale flatfield corrections
	    Incorporated FORTRAN read subroutine
	Jan-May, 2003 Aaron Smith (UCSD)
	    note: not compliant with TMO data anymore
	FEB-2005, Paul Hick (UCSD/CASS)
	    Reduced resolution of polar maps from 1600x1600 to 800x800.
	    Added theta-x and theta-y maps for glare removal as
	    low-resolution maps to Fits skymap.
	NOV-2005, Paul Hick (UCSD/CASS)
	    Added another low resolution map to output file (fraction
	    of orbit in seconds since start of orbit).
	    The lowres maps for the 'glare angles' are now always calculated.
	    They used to be set zero if glare subtraction was suppressed.
	    All lowres maps for camera 2 are run through GridSphere2D to
	    fill holes near the equatorial poles.
	DEC-2005, Paul Hick (UCSD/CASS)
	    Modified to deal with presence of -overwrite on cmd line
       JUN-2006, Paul Hick (UCSD/CASS), V5.1
           Added smei_skyd_size subroutine to control size of
           votes arrays.
           Added direction cosine angle in long dimension to
           skymap file. Note that this changes the layout of the
           Fits skymap file.
	JUL-2006, Paul Hick (UCSD/CASS), V5.3
	    Fixed error in some of the comments for the map description
	    keyword for the polar maps.
	    Added Fits keyword STIME and ETIME to extension containing the time
	    STIME in seconds since the first frame used (these were only specified
	    in the main header). STIME is the time origin for the array.
	MAR-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V6.1
	    Added check for "bad pixel" mask presence for camera 3.
	    The "closed shutter" calibration pattern for camera 3 is different
	    depending on whether a "bad pixel" mask is in effect.
	MAY-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu), V6.2
	    Added GridSphereWeight calls to smooth low resolution maps
	    where only a few CCD pixels (< 3) contribut a skybin.


smei_skyd_sort $SSW_SMEI_UCSD/camera/for/sky/smei_skyd_pool.f
[Previous]
 NAME:
	smei_skyd_sort
 PURPOSE:
	Sorts the node ID of all nodes
 CALLING SEQUENCE:
	entry smei_skyd_sort(iSilent)
 INPUTS:
	iSilent		controls informational messages
 OUTPUTS:
 CALLS: ***
	ArrI4Copy, ArrI4GetMinMax, BadR4, BadR8, Flt2Str, IndexI4, Int2Str, Say, Str2Str, cInt2Str
	datan2d, dcosd, dsind, quaternion_rotate_xyz, smei_axis_cam, smei_skyd_combine
	smei_skyd_node2sky, smei_skyd_pixel, smei_skyd_size
 CALLED BY:
	smei_skyd_fts, smei_skyd_init, smei_skyd_make, smei_skyd_sky
 PROCEDURE:
	The sorted array are described by a couple of arrays
	that are saved internally

	node_sort		index array to sort nodes
	n_nodes(SKYD__NODE_NEMPTY)
				number of empty slots in pool
				(these are located at the bottom of the node_sort array)
	n_nodes(SKYD__NODE_IEMPTY)
				counter used when filling up empty slots in smei_skyd_fill
				(initialized to zero here)

	n_nodes(*) is set zero at the start of a new orbit, forcing the
	initialization of n_nodes(SKYD__NODE_NSORT), n_nodes(SKYD__NODE_NEMPTY) and
	n_nodes(SKYD__NODE_IEMPTY) to zero.
 MODIFICATION HISTORY:
	FEB-2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu)