Index: /trunk/icd-demo/Makefile
===================================================================
--- /trunk/icd-demo/Makefile	(revision 8426)
+++ /trunk/icd-demo/Makefile	(revision 8426)
@@ -0,0 +1,63 @@
+default: icd-demo sample
+help:
+	@echo "USAGE: make pstest"
+
+CC      =       gcc
+SRC     =       src
+BIN     =       bin
+
+DESTBIN =       $(HOME)/src/bin/$(ARCH)
+
+LPSLIB  :=      $(shell pslib-config --libs)
+IPSLIB  :=      $(shell pslib-config --cflags)
+
+INCS	= 	$(IPSLIB)
+LIBS	= 	$(LPSLIB)
+CFLAGS	=	$(INCS) -std=c99 -Wall -Werror -g
+LFLAGS	=	$(LIBS) 
+
+ICDDEMO = $(BIN)/icd-demo.$(ARCH)
+
+icd-demo: $(ICDDEMO)
+
+sample:
+	cd def; ../bin/icd-demo.$(ARCH) P2.file.txt ../fits/P2.file.fits
+	cd def; ../bin/icd-demo.$(ARCH) P4S.file.txt ../fits/P4S.file.fits
+	cd def; ../bin/icd-demo.$(ARCH) P4D.file.txt ../fits/P4D.file.fits
+
+# dependancy rules for binary code #########################
+.PRECIOUS: %.$(ARCH).o
+.PRECIOUS: $(BIN)/%.$(ARCH)
+
+%.$(ARCH).o : %.c
+	$(CC) $(CFLAGS) -c $< -o $@
+
+$(BIN)/%.$(ARCH) : $(SRC)/%.$(ARCH).o
+	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
+	$(CC) $^ -o $@ $(LFLAGS)
+	@echo "done with $@"
+
+$(DESTBIN)/%: $(BIN)/%.$(ARCH)
+	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
+	rm -f $(DESTBIN)/$*
+	cp $(BIN)/$*.$(ARCH) $(DESTBIN)/$*
+
+$(INSTALL): % : $(BIN)/%.$(ARCH)
+
+%.clean :
+	rm -f $(BIN)/$*.$(ARCH)
+	rm -f $(SRC)/*.$(ARCH).o
+
+%.install:
+	make $(DESTBIN)/$*
+
+# utilities #################################################
+
+install:
+	for i in $(INSTALL); do make $$i.install; done
+
+clean:	
+	rm -f $(BIN)/*.$(ARCH)
+	rm -f `find . -name "*.o"`
+	rm -f `find . -name "*~"`
+	rm -f `find . -name "#*"`
Index: /trunk/icd-demo/def/P2.chip0.alt.txt
===================================================================
--- /trunk/icd-demo/def/P2.chip0.alt.txt	(revision 8426)
+++ /trunk/icd-demo/def/P2.chip0.alt.txt	(revision 8426)
@@ -0,0 +1,32 @@
+ 
+# extra data which belongs to table header
+HEADER METADATA
+  EXTNAME STR ALT_FIT_PARAMS
+  COMMENT STR
+  COMMENT STR  This HDU applies to all detections that have been analyzed
+  COMMENT STR  with the IPP alternative PSF fitting procedure. 
+  COMMENT STR  Note that the IPP_IDET must be unique within a file so as
+  COMMENT STR  to allow matching up sources between the PSF matching and
+  COMMENT STR  either the alternative PSF fits for P2, P4S, and P4D
+  COMMENT STR  detections or the extended source fits to the
+  COMMENT STR  Image Stack/Cumulative Sky detections.
+  COMMENT STR   
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  RA_ALT            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"                                
+  DEC_ALT           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"                               
+  RA_ALT_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"                            
+  DEC_ALT_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"                           
+  ALT_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"                    
+  CAL_ALT_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"                           
+  CAL_ALT_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"                  
+  ALT_PARM_1        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 1"                  
+  ALT_PARM_2        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 2"                  
+  ALT_PARM_3        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 3"                  
+  ALT_PARM_4        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 4"                  
+  ALT_PARM_5        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 5"                  
+END
Index: /trunk/icd-demo/def/P2.chip0.psf.txt
===================================================================
--- /trunk/icd-demo/def/P2.chip0.psf.txt	(revision 8426)
+++ /trunk/icd-demo/def/P2.chip0.psf.txt	(revision 8426)
@@ -0,0 +1,141 @@
+ 
+# description of the chip metadata
+BLANK METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR
+  COMMENT  STR  Combination (P4S, P4D, Image Stack/ Cumulative Sky) Image
+  COMMENT  STR  Metadata HDU
+  COMMENT  STR  
+  OBS_ID   STR  UnknownFormat       # Observation Identifier
+  CLASSID  S32                    0 # Class ID = focal plane location
+  DETECTID S32                    0 # Numerical ID of detector
+  NX       S32                 4800 # Number of columns on the detector
+  NY       S32                 4800 # Number of rows on the detector   DATE    STR 2006/02/05
+  COMMENT  STR
+  COMMENT  STR  Astrometric Solution (up to linear terms)
+  COMMENT  STR
+  NASTRO   S32                  100 # Number of astrometry stars
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  CTYPE1   STR  RA---TAN            # WCS Coordinate type
+  CTYPE2   STR  DEC--TAN            # WCS Coordinate type
+  CRVAL1   F32      321.30941666667 # WCS Ref value (RA in decimal degrees)
+  CRVAL2   F32     -5.1685277777778 # WCS Ref value (DEC in decimal degrees)
+  CRPIX1   F32    -1051.17692913657 # WCS Coordinate reference pixel
+  CRPIX2   F32     2033.40939404705 # WCS Coordinate reference pixel
+  CD1_1    F32  1.13378419402790E-4 # WCS Coordinate scale matrix
+  CD1_2    F32  8.93919113249280E-8 # WCS Coordinate scale matrix
+  CD2_1    F32  -5.4105516940550E-7 # WCS Coordinate scale matrix
+  CD2_2    F32  -1.1365323690945E-4 # WCS Coordinate scale matrix
+  COMMENT  STR
+  COMMENT  STR  Higher order terms in astrometric solution
+  COMMENT  STR
+  POLYORD  S32                    3 # Polynomial Order
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 1, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 1, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 1, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 1, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 1, coefficient of Y^2
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 2, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 2, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 2, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 2, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 2, coefficient of Y^2
+  COMMENT  STR
+  COMMENT  STR  PSF Description Parameters
+  COMMENT  STR
+  PSFMOD   S32                    1 # PSF Model number
+  PSFFWHM  F32                  1.0 # PSF Full width at Half Maximum (pixels)
+  PSFWIDX  F32                  1.0 # PSF Width in X coordinate (pixels)
+  PSFWIDY  F32                  1.0 # PSF Width in Y coordinate (pixels)
+  PSFTHETA F32                  0.0 # PSF Orientation angle (degrees)
+  PSF_EX1  F32                  0.0 # PSF Extra parameter #1
+  PSF_EX2  F32                  0.0 # PSF Extra parameter #2
+  COMMENT  STR
+  COMMENT  STR  Photometry Calibration information
+  COMMENT  STR
+  COMMENT  STR   Formula for Photometry, based on keywords given in this header:
+  COMMENT  STR   m = -2.5*log(DN) + 2.5*log(EXPTIME)
+  COMMENT  STR   M = m + PHOT_C + PHOT_K*(AIRMASS - 1) + PHOT_X*(PHOT_C1 - PHOT_C2)
+  COMMENT  STR
+  PHOTCODE STR  GPC.00.r            # Photometry reduction code identifier
+  PHOTOCID S32                      # Numerical code for reduction code
+  PHOT_C   F32              25.7150 # Elixir zero point - measured for camera run
+  PHOT_CS  F32               0.0048 # Elixir zero point - scatter
+  PHOT_NS  S32                   19 # Elixir zero point - N stars
+  PHOT_NM  S32                    5 # Elixir zero point - N images
+  PHOT_C0  F32              25.7430 # Elixir zero point - nominal
+  PHOT_X   F32               0.0830 # Elixir zero point - color term
+  PHOT_K   F32              -0.0400 # Elixir zero point - airmass term
+  PHOT_C1  STR  i_SDSS              # Elixir zero point - color 1
+  PHOT_C2  STR  r_SDSS              # Elixir zero point - color 2
+  COMMENT  STR
+  COMMENT  STR  Some statistics on this image
+  COMMENT  STR
+  NDETECT  S32                 1000 # Number of detections
+  MAGSAT   F32                15.0  # Magnitude at which sources saturate
+  MAGCOMP  F32                22.0  # Magnitude for which frame is 95% complete
+  SKYVAL   F32              1000.0  # Median sky value on detector
+  SKYVAR   F32                 1.0  # Variance of sky values
+  BIASVAL  F32               200.0  # Mean bias level of frame
+  BIASVAR  F32                 1.0  # Variance of bias values
+  COMMENT  STR
+  COMMENT  STR  Images used to process this exposure
+  COMMENT  STR 
+  DETREND1 STR  bias.00.fits        # 
+  DETREND2 STR  dark.00.fits        # 
+  DETREND3 STR  flat.00.fits        # 
+  DETREND4 STR  fringe.01.fits      # 
+  DETREND5 STR  none                # 
+  DETREND6 STR  none                # 
+  DETREND7 STR  none                # 
+  DETREND8 STR  none                # 
+  COMMENT  STR
+  COMMENT  STR  Quality Assurance Flags from IPP
+  COMMENT  STR
+  QAFLAGS  STR  UnknownValue        # IP QA flags
+END
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P2.chip1.alt.txt
===================================================================
--- /trunk/icd-demo/def/P2.chip1.alt.txt	(revision 8426)
+++ /trunk/icd-demo/def/P2.chip1.alt.txt	(revision 8426)
@@ -0,0 +1,32 @@
+ 
+# extra data which belongs to table header
+HEADER METADATA
+  EXTNAME STR ALT_FIT_PARAMS
+  COMMENT STR
+  COMMENT STR  This HDU applies to all detections that have been analyzed
+  COMMENT STR  with the IPP alternative PSF fitting procedure. 
+  COMMENT STR  Note that the IPP_IDET must be unique within a file so as
+  COMMENT STR  to allow matching up sources between the PSF matching and
+  COMMENT STR  either the alternative PSF fits for P2, P4S, and P4D
+  COMMENT STR  detections or the extended source fits to the
+  COMMENT STR  Image Stack/Cumulative Sky detections.
+  COMMENT STR   
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  RA_ALT            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"                                
+  DEC_ALT           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"                               
+  RA_ALT_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"                            
+  DEC_ALT_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"                           
+  ALT_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"                    
+  CAL_ALT_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"                           
+  CAL_ALT_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"                  
+  ALT_PARM_1        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 1"                  
+  ALT_PARM_2        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 2"                  
+  ALT_PARM_3        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 3"                  
+  ALT_PARM_4        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 4"                  
+  ALT_PARM_5        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 5"                  
+END
Index: /trunk/icd-demo/def/P2.chip1.psf.txt
===================================================================
--- /trunk/icd-demo/def/P2.chip1.psf.txt	(revision 8426)
+++ /trunk/icd-demo/def/P2.chip1.psf.txt	(revision 8426)
@@ -0,0 +1,139 @@
+ 
+# description of the chip metadata
+BLANK METADATA
+  COMMENT  STR
+  COMMENT  STR  Combination (P4S, P4D, Image Stack/ Cumulative Sky) Image
+  COMMENT  STR  Metadata HDU
+  COMMENT  STR  
+  OBS_ID   STR  UnknownFormat       # Observation Identifier
+  CLASSID  S32                    0 # Class ID = focal plane location
+  DETECTID S32                    0 # Numerical ID of detector
+  NX       S32                 4800 # Number of columns on the detector
+  NY       S32                 4800 # Number of rows on the detector   DATE    STR 2006/02/05
+  COMMENT  STR
+  COMMENT  STR  Astrometric Solution (up to linear terms)
+  COMMENT  STR
+  NASTRO   S32                  100 # Number of astrometry stars
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  CTYPE1   STR  RA---TAN            # WCS Coordinate type
+  CTYPE2   STR  DEC--TAN            # WCS Coordinate type
+  CRVAL1   F32      321.30941666667 # WCS Ref value (RA in decimal degrees)
+  CRVAL2   F32     -5.1685277777778 # WCS Ref value (DEC in decimal degrees)
+  CRPIX1   F32    -1051.17692913657 # WCS Coordinate reference pixel
+  CRPIX2   F32     2033.40939404705 # WCS Coordinate reference pixel
+  CD1_1    F32  1.13378419402790E-4 # WCS Coordinate scale matrix
+  CD1_2    F32  8.93919113249280E-8 # WCS Coordinate scale matrix
+  CD2_1    F32  -5.4105516940550E-7 # WCS Coordinate scale matrix
+  CD2_2    F32  -1.1365323690945E-4 # WCS Coordinate scale matrix
+  COMMENT  STR
+  COMMENT  STR  Higher order terms in astrometric solution
+  COMMENT  STR
+  POLYORD  S32                    3 # Polynomial Order
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 1, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 1, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 1, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 1, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 1, coefficient of Y^2
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 2, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 2, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 2, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 2, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 2, coefficient of Y^2
+  COMMENT  STR
+  COMMENT  STR  PSF Description Parameters
+  COMMENT  STR
+  PSFMOD   S32                    1 # PSF Model number
+  PSFFWHM  F32                  1.0 # PSF Full width at Half Maximum (pixels)
+  PSFWIDX  F32                  1.0 # PSF Width in X coordinate (pixels)
+  PSFWIDY  F32                  1.0 # PSF Width in Y coordinate (pixels)
+  PSFTHETA F32                  0.0 # PSF Orientation angle (degrees)
+  PSF_EX1  F32                  0.0 # PSF Extra parameter #1
+  PSF_EX2  F32                  0.0 # PSF Extra parameter #2
+  COMMENT  STR
+  COMMENT  STR  Photometry Calibration information
+  COMMENT  STR
+  COMMENT  STR   Formula for Photometry, based on keywords given in this header:
+  COMMENT  STR   m = -2.5*log(DN) + 2.5*log(EXPTIME)
+  COMMENT  STR   M = m + PHOT_C + PHOT_K*(AIRMASS - 1) + PHOT_X*(PHOT_C1 - PHOT_C2)
+  COMMENT  STR
+  PHOTCODE STR  GPC.00.r            # Photometry reduction code identifier
+  PHOTOCID S32                      # Numerical code for reduction code
+  PHOT_C   F32              25.7150 # Elixir zero point - measured for camera run
+  PHOT_CS  F32               0.0048 # Elixir zero point - scatter
+  PHOT_NS  S32                   19 # Elixir zero point - N stars
+  PHOT_NM  S32                    5 # Elixir zero point - N images
+  PHOT_C0  F32              25.7430 # Elixir zero point - nominal
+  PHOT_X   F32               0.0830 # Elixir zero point - color term
+  PHOT_K   F32              -0.0400 # Elixir zero point - airmass term
+  PHOT_C1  STR  i_SDSS              # Elixir zero point - color 1
+  PHOT_C2  STR  r_SDSS              # Elixir zero point - color 2
+  COMMENT  STR
+  COMMENT  STR  Some statistics on this image
+  COMMENT  STR
+  NDETECT  S32                 1000 # Number of detections
+  MAGSAT   F32                15.0  # Magnitude at which sources saturate
+  MAGCOMP  F32                22.0  # Magnitude for which frame is 95% complete
+  SKYVAL   F32              1000.0  # Median sky value on detector
+  SKYVAR   F32                 1.0  # Variance of sky values
+  BIASVAL  F32               200.0  # Mean bias level of frame
+  BIASVAR  F32                 1.0  # Variance of bias values
+  COMMENT  STR
+  COMMENT  STR  Images used to process this exposure
+  COMMENT  STR 
+  DETREND1 STR  bias.00.fits        # 
+  DETREND2 STR  dark.00.fits        # 
+  DETREND3 STR  flat.00.fits        # 
+  DETREND4 STR  fringe.01.fits      # 
+  DETREND5 STR  none                # 
+  DETREND6 STR  none                # 
+  DETREND7 STR  none                # 
+  DETREND8 STR  none                # 
+  COMMENT  STR
+  COMMENT  STR  Quality Assurance Flags from IPP
+  COMMENT  STR
+  QAFLAGS  STR  UnknownValue        # IP QA flags
+END
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P2.file.txt
===================================================================
--- /trunk/icd-demo/def/P2.file.txt	(revision 8426)
+++ /trunk/icd-demo/def/P2.file.txt	(revision 8426)
@@ -0,0 +1,30 @@
+
+# Keywords for P2 Frame Descriptor HDU
+HEADER METADATA
+  TELESCOP STR  PS1                 # Telescope name
+  TELNUM   S32                    1 # Telescope number
+  CAMERA   STR  GPC1                # Camera name
+  CAMERAID S32                    1 # Camera number
+  OBS_ID   STR  UnknownFormat       # Observation identifier
+  ANALVER  S32                    0 # Analysis version number
+  P1RECIP  STR              Basic.0 # Phase 1 recipe
+  P2RECIP  STR               GPC.01 # Phase 2 recipe
+  P3RECIP  STR               GPC.00 # Phase 3 recipe
+  NFILES   F32                    1 # Number of associated files ???
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  PHOT_CS  F32                0.007 # Scater in photometric solution (mag)
+  MJDATE   F64        10000.0011223 # MJD at start of exposure
+  EXPTIME  F32                30.01 # Exposure time (seconds)
+  FILTER   STR  r.12345             # Filter identification string
+  FILTERID F32                    2 # Filter holder position
+  AIRMASS  F32                1.012 # Airmass at start of exposure
+  RA       F32            10.000000 # Telescope boresight in RA (degrees)
+  DEC      F32            -10.00000 # Telescope boresight in DEC (degrees)
+END
+
+# the file contains table data for each chip:
+TABLE MULTI
+TABLE STR P2.chip0.psf.txt
+TABLE STR P2.chip0.alt.txt
+TABLE STR P2.chip1.psf.txt
+TABLE STR P2.chip1.alt.txt
Index: /trunk/icd-demo/def/P4D.chip0.alt.txt
===================================================================
--- /trunk/icd-demo/def/P4D.chip0.alt.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4D.chip0.alt.txt	(revision 8426)
@@ -0,0 +1,32 @@
+ 
+# extra data which belongs to table header
+HEADER METADATA
+  EXTNAME STR ALT_FIT_PARAMS
+  COMMENT STR
+  COMMENT STR  This HDU applies to all detections that have been analyzed
+  COMMENT STR  with the IPP alternative PSF fitting procedure. 
+  COMMENT STR  Note that the IPP_IDET must be unique within a file so as
+  COMMENT STR  to allow matching up sources between the PSF matching and
+  COMMENT STR  either the alternative PSF fits for P2, P4S, and P4D
+  COMMENT STR  detections or the extended source fits to the
+  COMMENT STR  Image Stack/Cumulative Sky detections.
+  COMMENT STR   
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  RA_ALT            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"                                
+  DEC_ALT           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"                               
+  RA_ALT_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"                            
+  DEC_ALT_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"                           
+  ALT_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"                    
+  CAL_ALT_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"                           
+  CAL_ALT_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"                  
+  ALT_PARM_1        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 1"                  
+  ALT_PARM_2        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 2"                  
+  ALT_PARM_3        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 3"                  
+  ALT_PARM_4        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 4"                  
+  ALT_PARM_5        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 5"                  
+END
Index: /trunk/icd-demo/def/P4D.chip0.low.txt
===================================================================
--- /trunk/icd-demo/def/P4D.chip0.low.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4D.chip0.low.txt	(revision 8426)
@@ -0,0 +1,41 @@
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P4D.chip0.psf.txt
===================================================================
--- /trunk/icd-demo/def/P4D.chip0.psf.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4D.chip0.psf.txt	(revision 8426)
@@ -0,0 +1,143 @@
+
+# description of the chip metadata
+BLANK METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR
+  COMMENT  STR  Basic Info about this frame
+  COMMENT  STR
+  SKYCELL  S32                       # Sky Cell ID number
+  CELLVER  S32                       # Sky Cell version number
+  FILTER   S32                       # Filter 
+  STACKID  S32                       # ID for this image stack
+  NP2IMGS  S32                       # Number of P2 images contributing
+  ANALVER  S32                       # Software Analysis Version
+  COMMENT  STR
+  COMMENT  STR  Combination (P4S, P4D, Image Stack/ Cumulative Sky) Image
+  COMMENT  STR  Metadata HDU
+  COMMENT  STR  
+  OBS_ID   STR  UnknownFormat       # Observation Identifier
+  CLASSID  S32                    0 # Class ID = focal plane location
+  DETECTID S32                    0 # Numerical ID of detector
+  NX       S32                 4800 # Number of columns on the detector
+  NY       S32                 4800 # Number of rows on the detector   DATE    STR 2006/02/05
+  COMMENT  STR
+  COMMENT  STR  Astrometric Solution (up to linear terms)
+  COMMENT  STR
+  NASTRO   S32                  100 # Number of astrometry stars
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  CTYPE1   STR  RA---TAN            # WCS Coordinate type
+  CTYPE2   STR  DEC--TAN            # WCS Coordinate type
+  CRVAL1   F32      321.30941666667 # WCS Ref value (RA in decimal degrees)
+  CRVAL2   F32     -5.1685277777778 # WCS Ref value (DEC in decimal degrees)
+  CRPIX1   F32    -1051.17692913657 # WCS Coordinate reference pixel
+  CRPIX2   F32     2033.40939404705 # WCS Coordinate reference pixel
+  CD1_1    F32  1.13378419402790E-4 # WCS Coordinate scale matrix
+  CD1_2    F32  8.93919113249280E-8 # WCS Coordinate scale matrix
+  CD2_1    F32  -5.4105516940550E-7 # WCS Coordinate scale matrix
+  CD2_2    F32  -1.1365323690945E-4 # WCS Coordinate scale matrix
+  COMMENT  STR
+  COMMENT  STR  Higher order terms in astrometric solution
+  COMMENT  STR
+  POLYORD  S32                    3 # Polynomial Order
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 1, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 1, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 1, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 1, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 1, coefficient of Y^2
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 2, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 2, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 2, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 2, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 2, coefficient of Y^2
+  COMMENT  STR
+  COMMENT  STR  PSF Description Parameters
+  COMMENT  STR
+  PSFMOD   S32                    1 # PSF Model number
+  PSFFWHM  F32                  1.0 # PSF Full width at Half Maximum (pixels)
+  PSFWIDX  F32                  1.0 # PSF Width in X coordinate (pixels)
+  PSFWIDY  F32                  1.0 # PSF Width in Y coordinate (pixels)
+  PSFTHETA F32                  0.0 # PSF Orientation angle (degrees)
+  PSF_EX1  F32                  0.0 # PSF Extra parameter #1
+  PSF_EX2  F32                  0.0 # PSF Extra parameter #2
+  COMMENT  STR
+  COMMENT  STR  Photometry Calibration information
+  COMMENT  STR
+  COMMENT  STR   Formula for Photometry, based on keywords given in this header:
+  COMMENT  STR   m = -2.5*log(DN) + 2.5*log(EXPTIME)
+  COMMENT  STR   M = m + PHOT_C + PHOT_K*(AIRMASS - 1) + PHOT_X*(PHOT_C1 - PHOT_C2)
+  COMMENT  STR
+  PHOTCODE STR  GPC.00.r            # Photometry reduction code identifier
+  PHOTOCID S32                      # Numerical code for reduction code
+  PHOT_C   F32              25.7150 # Elixir zero point - measured for camera run
+  PHOT_CS  F32               0.0048 # Elixir zero point - scatter
+  PHOT_NS  S32                   19 # Elixir zero point - N stars
+  PHOT_NM  S32                    5 # Elixir zero point - N images
+  PHOT_C0  F32              25.7430 # Elixir zero point - nominal
+  PHOT_X   F32               0.0830 # Elixir zero point - color term
+  PHOT_K   F32              -0.0400 # Elixir zero point - airmass term
+  PHOT_C1  STR  i_SDSS              # Elixir zero point - color 1
+  PHOT_C2  STR  r_SDSS              # Elixir zero point - color 2
+  COMMENT  STR
+  COMMENT  STR  Some statistics on this image
+  COMMENT  STR
+  NDETECT  S32                 1000 # Number of detections
+  MAGSAT   F32                15.0  # Magnitude at which sources saturate
+  MAGCOMP  F32                22.0  # Magnitude for which frame is 95% complete
+  SKYVAL   F32              1000.0  # Median sky value on detector
+  SKYVAR   F32                 1.0  # Variance of sky values
+  BIASVAL  F32               200.0  # Mean bias level of frame
+  BIASVAR  F32                 1.0  # Variance of bias values
+  COMMENT  STR
+  COMMENT  STR  P2 images used to generate this image stack
+  COMMENT  STR 
+  COMMENT  STR
+  COMMENT  STR  Quality Assurance Flags from IPP
+  COMMENT  STR
+  QAFLAGS  STR  UnknownValue        # IP QA flags
+END
+
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P4D.chip1.alt.txt
===================================================================
--- /trunk/icd-demo/def/P4D.chip1.alt.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4D.chip1.alt.txt	(revision 8426)
@@ -0,0 +1,32 @@
+ 
+# extra data which belongs to table header
+HEADER METADATA
+  EXTNAME STR ALT_FIT_PARAMS
+  COMMENT STR
+  COMMENT STR  This HDU applies to all detections that have been analyzed
+  COMMENT STR  with the IPP alternative PSF fitting procedure. 
+  COMMENT STR  Note that the IPP_IDET must be unique within a file so as
+  COMMENT STR  to allow matching up sources between the PSF matching and
+  COMMENT STR  either the alternative PSF fits for P2, P4S, and P4D
+  COMMENT STR  detections or the extended source fits to the
+  COMMENT STR  Image Stack/Cumulative Sky detections.
+  COMMENT STR   
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  RA_ALT            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"                                
+  DEC_ALT           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"                               
+  RA_ALT_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"                            
+  DEC_ALT_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"                           
+  ALT_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"                    
+  CAL_ALT_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"                           
+  CAL_ALT_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"                  
+  ALT_PARM_1        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 1"                  
+  ALT_PARM_2        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 2"                  
+  ALT_PARM_3        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 3"                  
+  ALT_PARM_4        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 4"                  
+  ALT_PARM_5        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 5"                  
+END
Index: /trunk/icd-demo/def/P4D.chip1.low.txt
===================================================================
--- /trunk/icd-demo/def/P4D.chip1.low.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4D.chip1.low.txt	(revision 8426)
@@ -0,0 +1,41 @@
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P4D.chip1.psf.txt
===================================================================
--- /trunk/icd-demo/def/P4D.chip1.psf.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4D.chip1.psf.txt	(revision 8426)
@@ -0,0 +1,143 @@
+
+# description of the chip metadata
+BLANK METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR
+  COMMENT  STR  Basic Info about this frame
+  COMMENT  STR
+  SKYCELL  S32                       # Sky Cell ID number
+  CELLVER  S32                       # Sky Cell version number
+  FILTER   S32                       # Filter 
+  STACKID  S32                       # ID for this image stack
+  NP2IMGS  S32                       # Number of P2 images contributing
+  ANALVER  S32                       # Software Analysis Version
+  COMMENT  STR
+  COMMENT  STR  Combination (P4S, P4D, Image Stack/ Cumulative Sky) Image
+  COMMENT  STR  Metadata HDU
+  COMMENT  STR  
+  OBS_ID   STR  UnknownFormat       # Observation Identifier
+  CLASSID  S32                    0 # Class ID = focal plane location
+  DETECTID S32                    0 # Numerical ID of detector
+  NX       S32                 4800 # Number of columns on the detector
+  NY       S32                 4800 # Number of rows on the detector   DATE    STR 2006/02/05
+  COMMENT  STR
+  COMMENT  STR  Astrometric Solution (up to linear terms)
+  COMMENT  STR
+  NASTRO   S32                  100 # Number of astrometry stars
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  CTYPE1   STR  RA---TAN            # WCS Coordinate type
+  CTYPE2   STR  DEC--TAN            # WCS Coordinate type
+  CRVAL1   F32      321.30941666667 # WCS Ref value (RA in decimal degrees)
+  CRVAL2   F32     -5.1685277777778 # WCS Ref value (DEC in decimal degrees)
+  CRPIX1   F32    -1051.17692913657 # WCS Coordinate reference pixel
+  CRPIX2   F32     2033.40939404705 # WCS Coordinate reference pixel
+  CD1_1    F32  1.13378419402790E-4 # WCS Coordinate scale matrix
+  CD1_2    F32  8.93919113249280E-8 # WCS Coordinate scale matrix
+  CD2_1    F32  -5.4105516940550E-7 # WCS Coordinate scale matrix
+  CD2_2    F32  -1.1365323690945E-4 # WCS Coordinate scale matrix
+  COMMENT  STR
+  COMMENT  STR  Higher order terms in astrometric solution
+  COMMENT  STR
+  POLYORD  S32                    3 # Polynomial Order
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 1, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 1, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 1, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 1, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 1, coefficient of Y^2
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 2, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 2, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 2, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 2, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 2, coefficient of Y^2
+  COMMENT  STR
+  COMMENT  STR  PSF Description Parameters
+  COMMENT  STR
+  PSFMOD   S32                    1 # PSF Model number
+  PSFFWHM  F32                  1.0 # PSF Full width at Half Maximum (pixels)
+  PSFWIDX  F32                  1.0 # PSF Width in X coordinate (pixels)
+  PSFWIDY  F32                  1.0 # PSF Width in Y coordinate (pixels)
+  PSFTHETA F32                  0.0 # PSF Orientation angle (degrees)
+  PSF_EX1  F32                  0.0 # PSF Extra parameter #1
+  PSF_EX2  F32                  0.0 # PSF Extra parameter #2
+  COMMENT  STR
+  COMMENT  STR  Photometry Calibration information
+  COMMENT  STR
+  COMMENT  STR   Formula for Photometry, based on keywords given in this header:
+  COMMENT  STR   m = -2.5*log(DN) + 2.5*log(EXPTIME)
+  COMMENT  STR   M = m + PHOT_C + PHOT_K*(AIRMASS - 1) + PHOT_X*(PHOT_C1 - PHOT_C2)
+  COMMENT  STR
+  PHOTCODE STR  GPC.00.r            # Photometry reduction code identifier
+  PHOTOCID S32                      # Numerical code for reduction code
+  PHOT_C   F32              25.7150 # Elixir zero point - measured for camera run
+  PHOT_CS  F32               0.0048 # Elixir zero point - scatter
+  PHOT_NS  S32                   19 # Elixir zero point - N stars
+  PHOT_NM  S32                    5 # Elixir zero point - N images
+  PHOT_C0  F32              25.7430 # Elixir zero point - nominal
+  PHOT_X   F32               0.0830 # Elixir zero point - color term
+  PHOT_K   F32              -0.0400 # Elixir zero point - airmass term
+  PHOT_C1  STR  i_SDSS              # Elixir zero point - color 1
+  PHOT_C2  STR  r_SDSS              # Elixir zero point - color 2
+  COMMENT  STR
+  COMMENT  STR  Some statistics on this image
+  COMMENT  STR
+  NDETECT  S32                 1000 # Number of detections
+  MAGSAT   F32                15.0  # Magnitude at which sources saturate
+  MAGCOMP  F32                22.0  # Magnitude for which frame is 95% complete
+  SKYVAL   F32              1000.0  # Median sky value on detector
+  SKYVAR   F32                 1.0  # Variance of sky values
+  BIASVAL  F32               200.0  # Mean bias level of frame
+  BIASVAR  F32                 1.0  # Variance of bias values
+  COMMENT  STR
+  COMMENT  STR  P2 images used to generate this image stack
+  COMMENT  STR 
+  COMMENT  STR
+  COMMENT  STR  Quality Assurance Flags from IPP
+  COMMENT  STR
+  QAFLAGS  STR  UnknownValue        # IP QA flags
+END
+
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P4D.file.txt
===================================================================
--- /trunk/icd-demo/def/P4D.file.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4D.file.txt	(revision 8426)
@@ -0,0 +1,32 @@
+
+# Keywords for P4D Frame Descriptor HDU
+HEADER METADATA
+  TELESCOP STR  PS1                 # Telescope name
+  TELNUM   S32                    1 # Telescope number
+  CAMERA   STR  GPC1                # Camera name
+  CAMERAID S32                    1 # Camera number
+  OBS_ID   STR  UnknownFormat       # Observation identifier
+  ANALVER  S32                    0 # Analysis version number
+  P1RECIP  STR              Basic.0 # Phase 1 recipe
+  P2RECIP  STR               GPC.01 # Phase 2 recipe
+  P3RECIP  STR               GPC.00 # Phase 3 recipe
+  NFILES   F32                    1 # Number of associated files ???
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  PHOT_CS  F32                0.007 # Scater in photometric solution (mag)
+  MJDATE   F64        10000.0011223 # MJD at start of exposure
+  EXPTIME  F32                30.01 # Exposure time (seconds)
+  FILTER   STR  r.12345             # Filter identification string
+  FILTERID F32                    2 # Filter holder position
+  AIRMASS  F32                1.012 # Airmass at start of exposure
+  RA       F32            10.000000 # Telescope boresight in RA (degrees)
+  DEC      F32            -10.00000 # Telescope boresight in DEC (degrees)
+END
+
+# the file contains table data for each chip:
+TABLE MULTI
+TABLE STR P4D.chip0.psf.txt
+TABLE STR P4D.chip0.alt.txt
+TABLE STR P4D.chip0.low.txt
+TABLE STR P4D.chip1.psf.txt
+TABLE STR P4D.chip1.alt.txt
+TABLE STR P4D.chip1.low.txt
Index: /trunk/icd-demo/def/P4S.chip0.alt.txt
===================================================================
--- /trunk/icd-demo/def/P4S.chip0.alt.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4S.chip0.alt.txt	(revision 8426)
@@ -0,0 +1,32 @@
+ 
+# extra data which belongs to table header
+HEADER METADATA
+  EXTNAME STR ALT_FIT_PARAMS
+  COMMENT STR
+  COMMENT STR  This HDU applies to all detections that have been analyzed
+  COMMENT STR  with the IPP alternative PSF fitting procedure. 
+  COMMENT STR  Note that the IPP_IDET must be unique within a file so as
+  COMMENT STR  to allow matching up sources between the PSF matching and
+  COMMENT STR  either the alternative PSF fits for P2, P4S, and P4D
+  COMMENT STR  detections or the extended source fits to the
+  COMMENT STR  Image Stack/Cumulative Sky detections.
+  COMMENT STR   
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  RA_ALT            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"                                
+  DEC_ALT           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"                               
+  RA_ALT_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"                            
+  DEC_ALT_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"                           
+  ALT_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"                    
+  CAL_ALT_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"                           
+  CAL_ALT_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"                  
+  ALT_PARM_1        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 1"                  
+  ALT_PARM_2        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 2"                  
+  ALT_PARM_3        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 3"                  
+  ALT_PARM_4        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 4"                  
+  ALT_PARM_5        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 5"                  
+END
Index: /trunk/icd-demo/def/P4S.chip0.psf.txt
===================================================================
--- /trunk/icd-demo/def/P4S.chip0.psf.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4S.chip0.psf.txt	(revision 8426)
@@ -0,0 +1,143 @@
+
+# description of the chip metadata
+BLANK METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR
+  COMMENT  STR  Basic Info about this frame
+  COMMENT  STR
+  SKYCELL  S32                       # Sky Cell ID number
+  CELLVER  S32                       # Sky Cell version number
+  FILTER   S32                       # Filter 
+  STACKID  S32                       # ID for this image stack
+  NP2IMGS  S32                       # Number of P2 images contributing
+  ANALVER  S32                       # Software Analysis Version
+  COMMENT  STR
+  COMMENT  STR  Combination (P4S, P4D, Image Stack/ Cumulative Sky) Image
+  COMMENT  STR  Metadata HDU
+  COMMENT  STR  
+  OBS_ID   STR  UnknownFormat       # Observation Identifier
+  CLASSID  S32                    0 # Class ID = focal plane location
+  DETECTID S32                    0 # Numerical ID of detector
+  NX       S32                 4800 # Number of columns on the detector
+  NY       S32                 4800 # Number of rows on the detector   DATE    STR 2006/02/05
+  COMMENT  STR
+  COMMENT  STR  Astrometric Solution (up to linear terms)
+  COMMENT  STR
+  NASTRO   S32                  100 # Number of astrometry stars
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  CTYPE1   STR  RA---TAN            # WCS Coordinate type
+  CTYPE2   STR  DEC--TAN            # WCS Coordinate type
+  CRVAL1   F32      321.30941666667 # WCS Ref value (RA in decimal degrees)
+  CRVAL2   F32     -5.1685277777778 # WCS Ref value (DEC in decimal degrees)
+  CRPIX1   F32    -1051.17692913657 # WCS Coordinate reference pixel
+  CRPIX2   F32     2033.40939404705 # WCS Coordinate reference pixel
+  CD1_1    F32  1.13378419402790E-4 # WCS Coordinate scale matrix
+  CD1_2    F32  8.93919113249280E-8 # WCS Coordinate scale matrix
+  CD2_1    F32  -5.4105516940550E-7 # WCS Coordinate scale matrix
+  CD2_2    F32  -1.1365323690945E-4 # WCS Coordinate scale matrix
+  COMMENT  STR
+  COMMENT  STR  Higher order terms in astrometric solution
+  COMMENT  STR
+  POLYORD  S32                    3 # Polynomial Order
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 1, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 1, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 1, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 1, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 1, coefficient of Y^2
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 2, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 2, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 2, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 2, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 2, coefficient of Y^2
+  COMMENT  STR
+  COMMENT  STR  PSF Description Parameters
+  COMMENT  STR
+  PSFMOD   S32                    1 # PSF Model number
+  PSFFWHM  F32                  1.0 # PSF Full width at Half Maximum (pixels)
+  PSFWIDX  F32                  1.0 # PSF Width in X coordinate (pixels)
+  PSFWIDY  F32                  1.0 # PSF Width in Y coordinate (pixels)
+  PSFTHETA F32                  0.0 # PSF Orientation angle (degrees)
+  PSF_EX1  F32                  0.0 # PSF Extra parameter #1
+  PSF_EX2  F32                  0.0 # PSF Extra parameter #2
+  COMMENT  STR
+  COMMENT  STR  Photometry Calibration information
+  COMMENT  STR
+  COMMENT  STR   Formula for Photometry, based on keywords given in this header:
+  COMMENT  STR   m = -2.5*log(DN) + 2.5*log(EXPTIME)
+  COMMENT  STR   M = m + PHOT_C + PHOT_K*(AIRMASS - 1) + PHOT_X*(PHOT_C1 - PHOT_C2)
+  COMMENT  STR
+  PHOTCODE STR  GPC.00.r            # Photometry reduction code identifier
+  PHOTOCID S32                      # Numerical code for reduction code
+  PHOT_C   F32              25.7150 # Elixir zero point - measured for camera run
+  PHOT_CS  F32               0.0048 # Elixir zero point - scatter
+  PHOT_NS  S32                   19 # Elixir zero point - N stars
+  PHOT_NM  S32                    5 # Elixir zero point - N images
+  PHOT_C0  F32              25.7430 # Elixir zero point - nominal
+  PHOT_X   F32               0.0830 # Elixir zero point - color term
+  PHOT_K   F32              -0.0400 # Elixir zero point - airmass term
+  PHOT_C1  STR  i_SDSS              # Elixir zero point - color 1
+  PHOT_C2  STR  r_SDSS              # Elixir zero point - color 2
+  COMMENT  STR
+  COMMENT  STR  Some statistics on this image
+  COMMENT  STR
+  NDETECT  S32                 1000 # Number of detections
+  MAGSAT   F32                15.0  # Magnitude at which sources saturate
+  MAGCOMP  F32                22.0  # Magnitude for which frame is 95% complete
+  SKYVAL   F32              1000.0  # Median sky value on detector
+  SKYVAR   F32                 1.0  # Variance of sky values
+  BIASVAL  F32               200.0  # Mean bias level of frame
+  BIASVAR  F32                 1.0  # Variance of bias values
+  COMMENT  STR
+  COMMENT  STR  P2 images used to generate this image stack
+  COMMENT  STR 
+  COMMENT  STR
+  COMMENT  STR  Quality Assurance Flags from IPP
+  COMMENT  STR
+  QAFLAGS  STR  UnknownValue        # IP QA flags
+END
+
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P4S.chip1.alt.txt
===================================================================
--- /trunk/icd-demo/def/P4S.chip1.alt.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4S.chip1.alt.txt	(revision 8426)
@@ -0,0 +1,32 @@
+ 
+# extra data which belongs to table header
+HEADER METADATA
+  EXTNAME STR ALT_FIT_PARAMS
+  COMMENT STR
+  COMMENT STR  This HDU applies to all detections that have been analyzed
+  COMMENT STR  with the IPP alternative PSF fitting procedure. 
+  COMMENT STR  Note that the IPP_IDET must be unique within a file so as
+  COMMENT STR  to allow matching up sources between the PSF matching and
+  COMMENT STR  either the alternative PSF fits for P2, P4S, and P4D
+  COMMENT STR  detections or the extended source fits to the
+  COMMENT STR  Image Stack/Cumulative Sky detections.
+  COMMENT STR   
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  RA_ALT            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"                                
+  DEC_ALT           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"                               
+  RA_ALT_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"                            
+  DEC_ALT_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"                           
+  ALT_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"                    
+  CAL_ALT_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"                           
+  CAL_ALT_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"                  
+  ALT_PARM_1        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 1"                  
+  ALT_PARM_2        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 2"                  
+  ALT_PARM_3        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 3"                  
+  ALT_PARM_4        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 4"                  
+  ALT_PARM_5        TTYPE  E     NONE             NONE   NONE   "ALT model parameter 5"                  
+END
Index: /trunk/icd-demo/def/P4S.chip1.psf.txt
===================================================================
--- /trunk/icd-demo/def/P4S.chip1.psf.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4S.chip1.psf.txt	(revision 8426)
@@ -0,0 +1,143 @@
+
+# description of the chip metadata
+BLANK METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR
+  COMMENT  STR  Basic Info about this frame
+  COMMENT  STR
+  SKYCELL  S32                       # Sky Cell ID number
+  CELLVER  S32                       # Sky Cell version number
+  FILTER   S32                       # Filter 
+  STACKID  S32                       # ID for this image stack
+  NP2IMGS  S32                       # Number of P2 images contributing
+  ANALVER  S32                       # Software Analysis Version
+  COMMENT  STR
+  COMMENT  STR  Combination (P4S, P4D, Image Stack/ Cumulative Sky) Image
+  COMMENT  STR  Metadata HDU
+  COMMENT  STR  
+  OBS_ID   STR  UnknownFormat       # Observation Identifier
+  CLASSID  S32                    0 # Class ID = focal plane location
+  DETECTID S32                    0 # Numerical ID of detector
+  NX       S32                 4800 # Number of columns on the detector
+  NY       S32                 4800 # Number of rows on the detector   DATE    STR 2006/02/05
+  COMMENT  STR
+  COMMENT  STR  Astrometric Solution (up to linear terms)
+  COMMENT  STR
+  NASTRO   S32                  100 # Number of astrometry stars
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  CTYPE1   STR  RA---TAN            # WCS Coordinate type
+  CTYPE2   STR  DEC--TAN            # WCS Coordinate type
+  CRVAL1   F32      321.30941666667 # WCS Ref value (RA in decimal degrees)
+  CRVAL2   F32     -5.1685277777778 # WCS Ref value (DEC in decimal degrees)
+  CRPIX1   F32    -1051.17692913657 # WCS Coordinate reference pixel
+  CRPIX2   F32     2033.40939404705 # WCS Coordinate reference pixel
+  CD1_1    F32  1.13378419402790E-4 # WCS Coordinate scale matrix
+  CD1_2    F32  8.93919113249280E-8 # WCS Coordinate scale matrix
+  CD2_1    F32  -5.4105516940550E-7 # WCS Coordinate scale matrix
+  CD2_2    F32  -1.1365323690945E-4 # WCS Coordinate scale matrix
+  COMMENT  STR
+  COMMENT  STR  Higher order terms in astrometric solution
+  COMMENT  STR
+  POLYORD  S32                    3 # Polynomial Order
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 1, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 1, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 1, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 1, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 1, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 1, coefficient of Y^2
+  PCA1X3Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^3
+  PCA1X2Y1 F32                  0.0 # WCS, Axis 2, coefficient of X^2 * Y
+  PCA1X1Y2 F32                  0.0 # WCS, Axis 2, coefficient of X * Y^2
+  PCA1X0Y3 F32                  0.0 # WCS, Axis 2, coefficient of Y^3
+  PCA1X2Y0 F32                  0.0 # WCS, Axis 2, coefficient of X^2
+  PCA1X1Y1 F32                  0.0 # WCS, Axis 2, coefficient of X * Y
+  PCA1X0Y2 F32                  0.0 # WCS, Axis 2, coefficient of Y^2
+  COMMENT  STR
+  COMMENT  STR  PSF Description Parameters
+  COMMENT  STR
+  PSFMOD   S32                    1 # PSF Model number
+  PSFFWHM  F32                  1.0 # PSF Full width at Half Maximum (pixels)
+  PSFWIDX  F32                  1.0 # PSF Width in X coordinate (pixels)
+  PSFWIDY  F32                  1.0 # PSF Width in Y coordinate (pixels)
+  PSFTHETA F32                  0.0 # PSF Orientation angle (degrees)
+  PSF_EX1  F32                  0.0 # PSF Extra parameter #1
+  PSF_EX2  F32                  0.0 # PSF Extra parameter #2
+  COMMENT  STR
+  COMMENT  STR  Photometry Calibration information
+  COMMENT  STR
+  COMMENT  STR   Formula for Photometry, based on keywords given in this header:
+  COMMENT  STR   m = -2.5*log(DN) + 2.5*log(EXPTIME)
+  COMMENT  STR   M = m + PHOT_C + PHOT_K*(AIRMASS - 1) + PHOT_X*(PHOT_C1 - PHOT_C2)
+  COMMENT  STR
+  PHOTCODE STR  GPC.00.r            # Photometry reduction code identifier
+  PHOTOCID S32                      # Numerical code for reduction code
+  PHOT_C   F32              25.7150 # Elixir zero point - measured for camera run
+  PHOT_CS  F32               0.0048 # Elixir zero point - scatter
+  PHOT_NS  S32                   19 # Elixir zero point - N stars
+  PHOT_NM  S32                    5 # Elixir zero point - N images
+  PHOT_C0  F32              25.7430 # Elixir zero point - nominal
+  PHOT_X   F32               0.0830 # Elixir zero point - color term
+  PHOT_K   F32              -0.0400 # Elixir zero point - airmass term
+  PHOT_C1  STR  i_SDSS              # Elixir zero point - color 1
+  PHOT_C2  STR  r_SDSS              # Elixir zero point - color 2
+  COMMENT  STR
+  COMMENT  STR  Some statistics on this image
+  COMMENT  STR
+  NDETECT  S32                 1000 # Number of detections
+  MAGSAT   F32                15.0  # Magnitude at which sources saturate
+  MAGCOMP  F32                22.0  # Magnitude for which frame is 95% complete
+  SKYVAL   F32              1000.0  # Median sky value on detector
+  SKYVAR   F32                 1.0  # Variance of sky values
+  BIASVAL  F32               200.0  # Mean bias level of frame
+  BIASVAR  F32                 1.0  # Variance of bias values
+  COMMENT  STR
+  COMMENT  STR  P2 images used to generate this image stack
+  COMMENT  STR 
+  COMMENT  STR
+  COMMENT  STR  Quality Assurance Flags from IPP
+  COMMENT  STR
+  QAFLAGS  STR  UnknownValue        # IP QA flags
+END
+
+
+# extra data which belongs to table header
+HEADER METADATA
+  COMMENT  STR  MULTI
+  COMMENT  STR   
+  COMMENT  STR   This HDU applies to all detections that have been analyzed
+  COMMENT  STR   with the IPP PSF fitting procedure. Note that the IPP_IDET
+  COMMENT  STR   must be unique within a file so as to allow matching up
+  COMMENT  STR   sources between the PSF matching and either the alternative
+  COMMENT  STR   PSF fits for P2, P4S, and P4D detections or the extended
+  COMMENT  STR   source fits to the Image Stack/Cumulative Sky detections.
+  COMMENT  STR
+  EXTNAME  STR PSF_FIT_PARAMS
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE              TTYPE  TFORM TUNIT            TMIN   TMAX   COMMENT
+  IPP_IDET          TTYPE  J     NONE             NONE   NONE   "IPP detection identifer index"                 
+  X_PSF             TTYPE  E     PIXELS              0   5000   "PSF x coordinate"                              
+  Y_PSF             TTYPE  E     PIXELS              0   5000   "PSF y coordinate"                              
+  X_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF x coordinate"                     
+  Y_PSF_SIG         TTYPE  E     PIXELS              0     10   "Sigma in PSF y coordinate"                     
+  RA_PSF            TTYPE  D     DECIMAL DEGREES     0    360   "RA from PSF fit"
+  DEC_PSF           TTYPE  D     DECIMAL DEGREES   -90    +90   "DEC from PSF fit"
+  RA_PSF_SIG        TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit RA"
+  DEC_PSF_SIG       TTYPE  E     ARCSECONDS          0      1   "Sigma of PSF fit DEC"
+  PSF_INST_MAG      TTYPE  E     MAG               -20      0   "PSF fit instrumental magnitude"
+  PSF_INST_MAG_SIG  TTYPE  E     MAG                 0    0.5   "Sigma of PSF instrumental magnitude"
+  PEAK_FLUX_AS_MAG  TTYPE  E     MAG               -20      0   "Peak flux expressed as magnitude"
+  SKY               TTYPE  E     ADU                 0  60000   "Sky level"
+  SKY_SIGMA         TTYPE  E     ADU                 0  60000   "Sigma of sky level"
+  STAR_GALAXY_SEP   TTYPE  E     NONE                0      1   "Star-Galaxy separator"
+  PSF_WIDTH_X       TTYPE  E     ARCSECONDS          0     20   "PSF width in x coordinate"
+  PSF_WIDTH_Y       TTYPE  E     ARCSECONDS          0     20   "PSF width in y coordinate"
+  PSF_THETA         TTYPE  E     DEGREES          -180   +180   "PSF orientation angle"
+  PSF_QF            TTYPE  E     NONE                0      1   "PSF coverage/quality factor"
+  CAL_PSF_MAG       TTYPE  E     MAG               -10    +30   "Calibrated magnitude"
+  CAL_PSF_MAG_SIG   TTYPE  E     MAG                 0    0.5   "Sigma of calibrated magnitude"
+  N_FRAMES          TTYPE  I     NONE                0  10000   "Number of frames overlapping source center"
+END
Index: /trunk/icd-demo/def/P4S.file.txt
===================================================================
--- /trunk/icd-demo/def/P4S.file.txt	(revision 8426)
+++ /trunk/icd-demo/def/P4S.file.txt	(revision 8426)
@@ -0,0 +1,30 @@
+
+# Keywords for P4S Frame Descriptor HDU
+HEADER METADATA
+  TELESCOP STR  PS1                 # Telescope name
+  TELNUM   S32                    1 # Telescope number
+  CAMERA   STR  GPC1                # Camera name
+  CAMERAID S32                    1 # Camera number
+  OBS_ID   STR  UnknownFormat       # Observation identifier
+  ANALVER  S32                    0 # Analysis version number
+  P1RECIP  STR              Basic.0 # Phase 1 recipe
+  P2RECIP  STR               GPC.01 # Phase 2 recipe
+  P3RECIP  STR               GPC.00 # Phase 3 recipe
+  NFILES   F32                    1 # Number of associated files ???
+  CERROR   F32               10.000 # Scatter in astrometry solution (MAS)
+  PHOT_CS  F32                0.007 # Scater in photometric solution (mag)
+  MJDATE   F64        10000.0011223 # MJD at start of exposure
+  EXPTIME  F32                30.01 # Exposure time (seconds)
+  FILTER   STR  r.12345             # Filter identification string
+  FILTERID F32                    2 # Filter holder position
+  AIRMASS  F32                1.012 # Airmass at start of exposure
+  RA       F32            10.000000 # Telescope boresight in RA (degrees)
+  DEC      F32            -10.00000 # Telescope boresight in DEC (degrees)
+END
+
+# the file contains table data for each chip:
+TABLE MULTI
+TABLE STR P4S.chip0.psf.txt
+TABLE STR P4S.chip0.alt.txt
+TABLE STR P4S.chip1.psf.txt
+TABLE STR P4S.chip1.alt.txt
Index: /trunk/icd-demo/def/filedef.txt
===================================================================
--- /trunk/icd-demo/def/filedef.txt	(revision 8426)
+++ /trunk/icd-demo/def/filedef.txt	(revision 8426)
@@ -0,0 +1,12 @@
+
+# description of PHU keywords
+HEADER METADATA
+  NAME    STR PHU
+  NLINE   S32 100
+  WIDTH   F32 2.54
+  HEIGHT  F32 25.4
+END
+
+TABLE MULTI
+TABLE STR tabledef.txt
+TABLE STR tabledef.txt
Index: /trunk/icd-demo/def/tabledef.txt
===================================================================
--- /trunk/icd-demo/def/tabledef.txt	(revision 8426)
+++ /trunk/icd-demo/def/tabledef.txt	(revision 8426)
@@ -0,0 +1,29 @@
+ 
+# this file describes a FITS table to be simulated
+BLANK METADATA
+  EXTNAME STR FOOFOO
+  NAME    STR CHIP0
+  NLINE   S32 100
+  WIDTH   F32 2.54
+  HEIGHT  F32 25.4
+END
+
+HEADER METADATA
+  EXTNAME STR FOOBAR
+  DATE    STR 2006/02/05
+  NLINE   S32 100
+  WIDTH   F32 2.54
+  HEIGHT  F32 25.4
+END
+
+# description of the FITS table columns
+COLUMNS METADATA
+  TYPE    TTYPE TFORM TUNIT       TMIN   TMAX       COMMENT
+  IPP_ID  TTYPE J     NONE           0   100000     "this is a test"
+  RA      TTYPE D     DEGREES      0.0    360.0     "this is a test"
+  DEC     TTYPE D     DEGREES    -90.0    +90.0     "this is a test"
+  RA_SIG  TTYPE E     ARCSECONDS   0.0      15.0    "this is a test"
+  DEC_SIG TTYPE E     ARCSECONDS   0.0      15.0    "this is a comment"
+  NFRAMES TTYPE I     NONE           0     100      "this is a test"
+  NAME    TTYPE A     NONE        NONE     NONE
+END
Index: /trunk/icd-demo/src/icd-demo.c
===================================================================
--- /trunk/icd-demo/src/icd-demo.c	(revision 8426)
+++ /trunk/icd-demo/src/icd-demo.c	(revision 8426)
@@ -0,0 +1,203 @@
+# include <stdio.h>
+# include <strings.h>
+# include <math.h>
+# include "pslib.h"
+
+int parseFile (psFits *fits, char *file);
+
+int main (int argc, char **argv) {
+
+    int nFail;
+
+    if (argc != 3) {
+	fprintf (stderr, "USAGE: icd-demo (input) (output)\n");
+	exit (2);
+    }
+
+    // construct a sample FITS table based on the given descriptive metadata file
+    psMetadata *fd      = psMetadataConfigParse (NULL, &nFail, argv[1], false);
+
+    psFits *fits = psFitsOpen (argv[2], "w");
+
+    psMetadata *header  = psMetadataLookupPtr (NULL, fd, "HEADER");
+    psFitsWriteBlank (fits, header);
+
+    // get the list pointers for the PSF_MODEL entries
+    psList *list = NULL;
+    psMetadataItem *mdi = psMetadataLookup (fd, "TABLE");
+    if (mdi->type == PS_DATA_STRING) {
+        list = psListAlloc(NULL);
+        psListAdd (list, PS_LIST_HEAD, mdi);
+    } else {
+        list = psMemIncrRefCounter(mdi->data.list);
+    }
+
+    // try each model option listed in config
+    psMetadataItem *item = NULL;
+    psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE);
+    while ((item = psListGetAndIncrement (iter)) != NULL) {
+        char *file = item->data.V;
+	parseFile (fits, file);
+    }
+    psFitsClose (fits);
+}
+
+int parseFile (psFits *fits, char *file) {
+
+    int nFail;
+    char unitWord[64];
+    double min, max, rvalue, range;
+
+    psMetadataItem *col;
+    psRandom *rnd = psRandomAlloc (PS_RANDOM_TAUS, 0);
+
+    // construct a sample FITS table based on the given descriptive metadata file
+    psMetadata *fd      = psMetadataConfigParse (NULL, &nFail, file, false);
+
+    psMetadata *blank  = psMetadataLookupPtr (NULL, fd, "BLANK");
+    if (blank) {
+	psFitsWriteBlank (fits, blank);
+    }
+
+    psMetadata *header  = psMetadataLookupPtr (NULL, fd, "HEADER");
+    psMetadata *columns = psMetadataLookupPtr (NULL, fd, "COLUMNS");
+    psMetadataIterator *iter = psMetadataIteratorAlloc (columns, PS_LIST_HEAD, NULL);
+    char *extname       = psMetadataLookupStr (NULL, header, "EXTNAME");
+
+    psArray *table = psArrayAlloc (10);
+
+    // XXX insert unit values: we need a method to do this in psFitsWriteTable
+    int nCol = 1;
+    while ((col = psMetadataGetAndIncrement (iter)) != NULL) {
+	psMetadata *md = col->data.V;
+	char *unit = psMetadataLookupStr (NULL, md, "TUNIT");
+	if (strcasecmp (unit, "NONE")) {
+	    sprintf (unitWord, "TUNIT%d", nCol);
+	    psMetadataAddStr (header, PS_LIST_TAIL, unitWord, 0, "", unit);
+	}
+	nCol ++;
+    }
+    psMetadataIteratorSet (iter, PS_LIST_HEAD);
+
+    // make a total of NN fake data columns
+    for (int i = 0; i < 10; i++) {
+	
+	int nCol = 1;
+
+	psMetadata *row = psMetadataAlloc ();
+
+	while ((col = psMetadataGetAndIncrement (iter)) != NULL) {
+
+	    psMetadata *md = col->data.V;
+
+	    char *format = psMetadataLookupStr (NULL, md, "TFORM");
+	    char *comment = psMetadataLookupStr (NULL, md, "COMMENT");
+	    char *unit = psMetadataLookupStr (NULL, md, "TUNIT");
+	    if (strcasecmp (unit, "NONE")) {
+		sprintf (unitWord, "TUNIT%d", nCol);
+		psMetadataAddStr (header, PS_LIST_TAIL, unitWord, 0, "", unit);
+	    }
+
+	    if (!strcasecmp (format, "I")) {
+		int value;
+
+		char *minWord = psMetadataLookupStr (NULL, md, "TMIN");
+		char *maxWord = psMetadataLookupStr (NULL, md, "TMAX");
+
+		min = atoi (minWord);
+		if (!strcasecmp (minWord, "NONE")) min = 0;
+		max = atoi (maxWord);
+		if (!strcasecmp (maxWord, "NONE")) max = 100;
+		range = max - min;
+
+		rvalue = psRandomUniform (rnd);
+		value = range * rvalue + min;
+
+		psMetadataAdd (row, PS_LIST_TAIL, col->name, PS_DATA_S16, comment, value);
+	    }
+
+	    if (!strcasecmp (format, "J")) {
+		int value;
+
+		char *minWord = psMetadataLookupStr (NULL, md, "TMIN");
+		char *maxWord = psMetadataLookupStr (NULL, md, "TMAX");
+
+		min = atoi (minWord);
+		if (!strcasecmp (minWord, "NONE")) min = 0;
+		max = atoi (maxWord);
+		if (!strcasecmp (maxWord, "NONE")) max = 100;
+		range = max - min;
+
+		rvalue = psRandomUniform (rnd);
+		value = range * rvalue + min;
+
+		psMetadataAdd (row, PS_LIST_TAIL, col->name, PS_DATA_S32, comment, value);
+	    }
+
+	    if (!strcasecmp (format, "K")) {
+		long int value;
+
+		char *minWord = psMetadataLookupStr (NULL, md, "TMIN");
+		char *maxWord = psMetadataLookupStr (NULL, md, "TMAX");
+
+		min = atoi (minWord);
+		if (!strcasecmp (minWord, "NONE")) min = 0;
+		max = atoi (maxWord);
+		if (!strcasecmp (maxWord, "NONE")) max = 100;
+		range = max - min;
+
+		rvalue = psRandomUniform (rnd);
+		value = range * rvalue + min;
+
+		psMetadataAdd (row, PS_LIST_TAIL, col->name, PS_DATA_S64, comment, value);
+	    }
+
+	    if (!strcasecmp (format, "E")) {
+		float value;
+
+		char *minWord = psMetadataLookupStr (NULL, md, "TMIN");
+		char *maxWord = psMetadataLookupStr (NULL, md, "TMAX");
+
+		min = atoi (minWord);
+		if (!strcasecmp (minWord, "NONE")) min = 0;
+		max = atoi (maxWord);
+		if (!strcasecmp (maxWord, "NONE")) max = 100;
+		range = max - min;
+
+		rvalue = psRandomUniform (rnd);
+		value = range * rvalue + min;
+
+		psMetadataAdd (row, PS_LIST_TAIL, col->name, PS_DATA_F32, comment, value);
+	    }
+
+	    if (!strcasecmp (format, "D")) {
+		double value;
+
+		char *minWord = psMetadataLookupStr (NULL, md, "TMIN");
+		char *maxWord = psMetadataLookupStr (NULL, md, "TMAX");
+
+		min = atoi (minWord);
+		if (!strcasecmp (minWord, "NONE")) min = 0;
+		max = atoi (maxWord);
+		if (!strcasecmp (maxWord, "NONE")) max = 100;
+		range = max - min;
+
+		rvalue = psRandomUniform (rnd);
+		value = range * rvalue + min;
+
+		psMetadataAdd (row, PS_LIST_TAIL, col->name, PS_DATA_F64, comment, value);
+	    }
+
+	    if (!strcasecmp (format, "A")) {
+		char *value = NULL;
+		psStringAppend (&value, "word %03d", i);
+		psMetadataAdd (row, PS_LIST_TAIL, col->name, PS_DATA_STRING, "", value);
+	    }
+	}
+        psArrayAdd (table, 100, row);
+        psFree (row);
+	psMetadataIteratorSet (iter, PS_LIST_HEAD);
+    }
+    psFitsWriteTable (fits, header, table, extname);
+    return 1;
+}
