# Refurbished GPC1
# Change effective from 22 January 2010 (TJD=5219): new CCD temperature keywords

# How to identify this type
RULE    METADATA
	ORIGIN		STR	PS1
        TELESCOP        STR     PS1
	INSTRUME	STR	gpc1
        CONTROLR        STR     STARGRASP
        NAMPS           S32     64
	MJD-OBS		F64	55219.0		# OP: >=
END

# How to read this data
FILE    METADATA
        PHU             STR     CHIP       # The FITS file represents a single chip
        EXTENSIONS      STR     CELL       # The extensions represent cells
        FPA.OBS         STR     CONTROLR   # A PHU keyword for unique identifier within the hierarchy level
        CONTENT         STR     DETECTOR   # How to determine content of FITS file
        CONTENT.RULE    STR     {CHIP.ID}  # How to derive the CONTENT when writing
END

# What's in the FITS file?
CONTENTS        METADATA
        # CONTENT      =    chip name : type
        CCID58-2-15a1  STR  XY01:GPCChip  # chip 00
        CCID58-2-18a1  STR  XY02:GPCChip  # chip 01
        CCID58-2-04a2  STR  XY03:GPCChip  # chip 02
        CCID58-1-01b1  STR  XY04:GPCChip  # chip 03
        CCID58-1-09b1  STR  XY05:GPCChip  # chip 04
        CCID58-2-09b1  STR  XY06:GPCChip  # chip 05
        CCID58-2-22a1  STR  XY10:GPCChip  # chip 06
        CCID58-2-01a1  STR  XY11:GPCChip  # chip 07
        CCID58-3-11a1  STR  XY12:GPCChip  # chip 08
        CCID58-3-06a1  STR  XY13:GPCChip  # chip 09
        CCID58-3-05b1  STR  XY14:GPCChip  # chip 10
        CCID58-3-08b1  STR  XY15:GPCChip  # chip 11
        CCID58-1-02b1  STR  XY16:GPCChip  # chip 12
        CCID58-2-07b2  STR  XY17:GPCChip  # chip 13
        CCID58-1-19a1  STR  XY20:GPCChip  # chip 14
        CCID58-1-04a1  STR  XY21:GPCChip  # chip 15
        CCID58-2-09a2  STR  XY22:GPCChip  # chip 16
        CCID58-1-02a1  STR  XY23:GPCChip  # chip 17
        CCID58-3-10b1  STR  XY24:GPCChip  # chip 18
        CCID58-3-05b2  STR  XY25:GPCChip  # chip 19
        CCID58-3-04b1  STR  XY26:GPCChip  # chip 20
        CCID58-1-18b1  STR  XY27:GPCChip  # chip 21
        CCID58-3-13a2  STR  XY30:GPCChip  # chip 22
        CCID58-3-05a1  STR  XY31:GPCChip  # chip 23
        CCID58-2-01a2  STR  XY32:GPCChip  # chip 24
        CCID58-1-02a2  STR  XY33:GPCChip  # chip 25
        CCID58-3-03b1  STR  XY34:GPCChip  # chip 26
        CCID58-1-01b2  STR  XY35:GPCChip  # chip 27
        CCID58-3-14b1  STR  XY36:GPCChip  # chip 28
        CCID58-2-23b2  STR  XY37:GPCChip  # chip 29
        CCID58-3-02b1  STR  XY40:GPCChip  # chip 30
        CCID58-1-03b2  STR  XY41:GPCChip  # chip 31
        CCID58-1-07b1  STR  XY42:GPCChip  # chip 32
        CCID58-2-11b2  STR  XY43:GPCChip  # chip 33
        CCID58-2-09a1  STR  XY44:GPCChip  # chip 34
        CCID58-3-04a2  STR  XY45:GPCChip  # chip 35
        CCID58-3-02a1  STR  XY46:GPCChip  # chip 36
        CCID58-3-14a1  STR  XY47:GPCChip  # chip 37
        CCID58-1-17b1  STR  XY50:GPCChip  # chip 38
        CCID58-2-09b2  STR  XY51:GPCChip  # chip 39
        CCID58-1-04b1  STR  XY52:GPCChip  # chip 40
        CCID58-1-05b2  STR  XY53:GPCChip  # chip 41
        CCID58-3-05a2  STR  XY54:GPCChip  # chip 42
        CCID58-3-03a2  STR  XY55:GPCChip  # chip 43
        CCID58-3-02a2  STR  XY56:GPCChip  # chip 44
        CCID58-3-11a2  STR  XY57:GPCChip  # chip 45
        CCID58-2-16b1  STR  XY60:GPCChip  # chip 46
        CCID58-1-03b1  STR  XY61:GPCChip  # chip 47
        CCID58-3-03b2  STR  XY62:GPCChip  # chip 48
        CCID58-1-02b2  STR  XY63:GPCChip  # chip 49
        CCID58-1-07a1  STR  XY64:GPCChip  # chip 50
        CCID58-2-04a1  STR  XY65:GPCChip  # chip 51
        CCID58-3-10a1  STR  XY66:GPCChip  # chip 52
        CCID58-1-09a1  STR  XY67:GPCChip  # chip 53
        CCID58-2-13b1  STR  XY71:GPCChip  # chip 54
        CCID58-1-14b1  STR  XY72:GPCChip  # chip 55
        CCID58-3-11b2  STR  XY73:GPCChip  # chip 56
        CCID58-1-05a2  STR  XY74:GPCChip  # chip 57
        CCID58-1-21a1  STR  XY75:GPCChip  # chip 58
        CCID58-2-05a1  STR  XY76:GPCChip  # chip 59
END

CHIPS   METADATA
        GPCChip         METADATA
                # Extension name, cellName:cellType
                xy00   STR  xy00:GPCCell
                xy10   STR  xy10:GPCCell
                xy20   STR  xy20:GPCCell
                xy30   STR  xy30:GPCCell
                xy40   STR  xy40:GPCCell
                xy50   STR  xy50:GPCCell
                xy60   STR  xy60:GPCCell
                xy70   STR  xy70:GPCCell
                xy01   STR  xy01:GPCCell
                xy11   STR  xy11:GPCCell
                xy21   STR  xy21:GPCCell
                xy31   STR  xy31:GPCCell
                xy41   STR  xy41:GPCCell
                xy51   STR  xy51:GPCCell
                xy61   STR  xy61:GPCCell
                xy71   STR  xy71:GPCCell
                xy02   STR  xy02:GPCCell
                xy12   STR  xy12:GPCCell
                xy22   STR  xy22:GPCCell
                xy32   STR  xy32:GPCCell
                xy42   STR  xy42:GPCCell
                xy52   STR  xy52:GPCCell
                xy62   STR  xy62:GPCCell
                xy72   STR  xy72:GPCCell
                xy03   STR  xy03:GPCCell
                xy13   STR  xy13:GPCCell
                xy23   STR  xy23:GPCCell
                xy33   STR  xy33:GPCCell
                xy43   STR  xy43:GPCCell
                xy53   STR  xy53:GPCCell
                xy63   STR  xy63:GPCCell
                xy73   STR  xy73:GPCCell
                xy04   STR  xy04:GPCCell
                xy14   STR  xy14:GPCCell
                xy24   STR  xy24:GPCCell
                xy34   STR  xy34:GPCCell
                xy44   STR  xy44:GPCCell
                xy54   STR  xy54:GPCCell
                xy64   STR  xy64:GPCCell
                xy74   STR  xy74:GPCCell
                xy05   STR  xy05:GPCCell
                xy15   STR  xy15:GPCCell
                xy25   STR  xy25:GPCCell
                xy35   STR  xy35:GPCCell
                xy45   STR  xy45:GPCCell
                xy55   STR  xy55:GPCCell
                xy65   STR  xy65:GPCCell
                xy75   STR  xy75:GPCCell
                xy06   STR  xy06:GPCCell
                xy16   STR  xy16:GPCCell
                xy26   STR  xy26:GPCCell
                xy36   STR  xy36:GPCCell
                xy46   STR  xy46:GPCCell
                xy56   STR  xy56:GPCCell
                xy66   STR  xy66:GPCCell
                xy76   STR  xy76:GPCCell
                xy07   STR  xy07:GPCCell
                xy17   STR  xy17:GPCCell
                xy27   STR  xy27:GPCCell
                xy37   STR  xy37:GPCCell
                xy47   STR  xy47:GPCCell
                xy57   STR  xy57:GPCCell
                xy67   STR  xy67:GPCCell
                xy77   STR  xy77:GPCCell
        END
END

# Specify the cell data
CELLS   METADATA
        GPCCell         METADATA
                CELL.TRIMSEC.SOURCE     STR     HEADER
                CELL.TRIMSEC            STR     DATASEC
                CELL.BIASSEC.SOURCE     STR     HEADER
                CELL.BIASSEC            STR     BIASSEC
        END
END


# How to translate PS concepts into FITS headers
TRANSLATION     METADATA
        FPA.FILTERID    STR     FILTERID
        FPA.FILTER      STR     FILTERID
        FPA.RA          STR     RA
        FPA.DEC         STR     DEC
        FPA.RADECSYS    STR     EQUINOX
        FPA.OBSTYPE     STR     OBSTYPE
        FPA.OBJECT      STR     OBJECT
        FPA.OBS.MODE    STR     OBS_MODE
        FPA.COMMENT     STR     CMMTOBS
        FPA.AIRMASS     STR     AIRMASS
        FPA.POSANGLE    STR     POSANGLE
	FPA.ROTANGLE	STR	ROT
        FPA.FOCUS       STR     M2Z
        FPA.TIME        STR     SHUTOUTC
        FPA.ALT         STR     ALT
        FPA.AZ          STR     AZ
        # FPA.TEMP        STR     DETTEM
        FPA.M1X         STR     M1X
        FPA.M1Y         STR     M1Y   
        FPA.M1Z         STR     M1Z   
        FPA.M1TIP       STR     M1TIP 
        FPA.M1TILT      STR     M1TILT
        FPA.M2X         STR     M2X
        FPA.M2Y         STR     M2Y   
        FPA.M2Z         STR     M2Z   
        FPA.M2TIP       STR     M2TIP 
        FPA.M2TILT      STR     M2TILT
        FPA.ENV.TEMP    STR     ENVTEM
        FPA.ENV.HUMID   STR     ENVHUM
        FPA.ENV.WIND    STR     ENVWIN
        FPA.ENV.DIR     STR     ENVDIR

        FPA.TELTEMP.M1     STR  TELTEMM1 # Primary mirror temps (C) 
        FPA.TELTEMP.M1CELL STR  TELTEMMS # Primary mirror support temps (C)   
        FPA.TELTEMP.M2     STR  TELTEMM2 # Secondary mirror temps (C
        FPA.TELTEMP.SPIDER STR  TELTEMSP # Spider temperatures (C)  
        FPA.TELTEMP.TRUSS  STR  TELTEMTR # Mid truss temperatures (C
        FPA.TELTEMP.EXTRA  STR  TELTEMEX # Miscellaneous temperatures (C)     

        FPA.BURNTOOL.APPLIED STR BTOOLAPP

        FPA.PON.TIME    STR     PONTIME

        CHIP.ID         STR     DETECTOR
        CELL.XBIN       STR     CCDSUM
        CELL.YBIN       STR     CCDSUM
        CELL.X0         STR     IMNPIX1
        CELL.Y0         STR     IMNPIX2
        CELL.XPARITY    STR     ATM1_1
        CELL.YPARITY    STR     ATM2_2
	CHIP.TEMP	STR	CDETTEM
        FPA.EXPOSURE    STR     EXPREQ          # Requested exposure time, presumably camera exposure time
        CELL.EXPOSURE   STR     EXPTIME         # Exposure time measured by shutter
        CELL.DARKTIME   STR     DARKTIME        # Exposure time for camera
        CELL.TIME       STR     SHUTOUTC	# Observation time
        CELL.GAIN       STR     GAIN		# Cell gain (e/ADU)
        CELL.READNOISE  STR     RDNOISE		# Cell read noise (ADU)
        CELL.SATURATION STR     MAXLIN		# Saturation point (ADU)
END

# Default PS concepts that may be specified by value
DEFAULTS        METADATA
        FPA.TELESCOPE   STR     PS1
        FPA.INSTRUMENT  STR     GPC1
        FPA.LONGITUDE   STR     10:25:01.417 # West Longitude in Hours 10.4170608521
        FPA.LATITUDE    STR     20:42:25.558 # North Latitude in Degrees 20.7070999146
        FPA.ELEVATION   F32     3048.0 # altitude in meters
        FPA.DETECTOR    STR     GPC1
        FPA.TIMESYS     STR     UTC
	CHIP.XSIZE	S32	4846
	CHIP.YSIZE	S32	4868
        CHIP.XPARITY    S32     1
        CHIP.YPARITY    S32     1
        CHIP.X0.DEPEND          STR     CHIP.NAME
        CHIP.X0         METADATA
          XY01  S32     4971
          XY02  S32     4971
          XY03  S32     4971
          XY04  S32     4971
          XY05  S32     4971
          XY06  S32     4971
          XY10  S32     9942
          XY11  S32     9942
          XY12  S32     9942
          XY13  S32     9942
          XY14  S32     9942
          XY15  S32     9942
          XY16  S32     9942
          XY17  S32     9942
          XY20  S32     14913
          XY21  S32     14913
          XY22  S32     14913
          XY23  S32     14913
          XY24  S32     14913
          XY25  S32     14913
          XY26  S32     14913
          XY27  S32     14913
          XY30  S32     19884
          XY31  S32     19884
          XY32  S32     19884
          XY33  S32     19884 # should be 19872
          XY34  S32     19884
          XY35  S32     19884
          XY36  S32     19884
          XY37  S32     19884
          XY40  S32     20041
          XY41  S32     20041
          XY42  S32     20041
          XY43  S32     20041 # should be 20029
          XY44  S32     20041
          XY45  S32     20041
          XY46  S32     20041
          XY47  S32     20041
          XY50  S32     25012
          XY51  S32     25012
          XY52  S32     25012
          XY53  S32     25012
          XY54  S32     25012
          XY55  S32     25012
          XY56  S32     25012
          XY57  S32     25012
          XY60  S32     29983
          XY61  S32     29983
          XY62  S32     29983
          XY63  S32     29983
          XY64  S32     29983
          XY65  S32     29983
          XY66  S32     29983
          XY67  S32     29983
          XY71  S32     34954
          XY72  S32     34954
          XY73  S32     34954
          XY74  S32     34954
          XY75  S32     34954
          XY76  S32     34954
        END
        CHIP.Y0.DEPEND          STR     CHIP.NAME
        CHIP.Y0         METADATA
          XY01  S32     10286
          XY02  S32     15429
          XY03  S32     20572
          XY04  S32     25715
          XY05  S32     30858
          XY06  S32     36001
          XY10  S32     5143
          XY11  S32     10286
          XY12  S32     15429
          XY13  S32     20572
          XY14  S32     25715
          XY15  S32     30858
          XY16  S32     36001
          XY17  S32     41144
          XY20  S32     5143
          XY21  S32     10286
          XY22  S32     15429
          XY23  S32     20572
          XY24  S32     25715
          XY25  S32     30858
          XY26  S32     36001
          XY27  S32     41144
          XY30  S32     5143
          XY31  S32     10286
          XY32  S32     15429
          XY33  S32     20572
          XY34  S32     25715 # should be 25755
          XY35  S32     30858
          XY36  S32     36001
          XY37  S32     41144
          XY40  S32     306
          XY41  S32     5449
          XY42  S32     10592
          XY43  S32     15735 # should be 15707
          XY44  S32     20878 # should be 20890
          XY45  S32     26021
          XY46  S32     31164
          XY47  S32     36307
          XY50  S32     306
          XY51  S32     5449
          XY52  S32     10592
          XY53  S32     15735
          XY54  S32     20878
          XY55  S32     26021
          XY56  S32     31164
          XY57  S32     36307
          XY60  S32     306
          XY61  S32     5449
          XY62  S32     10592
          XY63  S32     15735
          XY64  S32     20878
          XY65  S32     26021
          XY66  S32     31164
          XY67  S32     36307
          XY71  S32     5449
          XY72  S32     10592
          XY73  S32     15735
          XY74  S32     20878
          XY75  S32     26021
          XY76  S32     31164
        END
        CHIP.XPARITY.DEPEND     STR     CHIP.NAME
        CHIP.XPARITY    METADATA
          XY01  S32     -1
          XY02  S32     -1
          XY03  S32     -1
          XY04  S32     -1
          XY05  S32     -1
          XY06  S32     -1
          XY10  S32     -1
          XY11  S32     -1
          XY12  S32     -1
          XY13  S32     -1
          XY14  S32     -1
          XY15  S32     -1
          XY16  S32     -1
          XY17  S32     -1
          XY20  S32     -1
          XY21  S32     -1
          XY22  S32     -1
          XY23  S32     -1
          XY24  S32     -1
          XY25  S32     -1
          XY26  S32     -1
          XY27  S32     -1
          XY30  S32     -1
          XY31  S32     -1
          XY32  S32     -1
          XY33  S32     -1
          XY34  S32     -1
          XY35  S32     -1
          XY36  S32     -1
          XY37  S32     -1
          XY40  S32     1
          XY41  S32     1
          XY42  S32     1
          XY43  S32     1
          XY44  S32     1
          XY45  S32     1
          XY46  S32     1
          XY47  S32     1
          XY50  S32     1
          XY51  S32     1
          XY52  S32     1
          XY53  S32     1
          XY54  S32     1
          XY55  S32     1
          XY56  S32     1
          XY57  S32     1
          XY60  S32     1
          XY61  S32     1
          XY62  S32     1
          XY63  S32     1
          XY64  S32     1
          XY65  S32     1
          XY66  S32     1
          XY67  S32     1
          XY71  S32     1
          XY72  S32     1
          XY73  S32     1
          XY74  S32     1
          XY75  S32     1
          XY76  S32     1
        END
        CHIP.YPARITY.DEPEND     STR     CHIP.NAME
        CHIP.YPARITY    METADATA
          XY01  S32     -1
          XY02  S32     -1
          XY03  S32     -1
          XY04  S32     -1
          XY05  S32     -1
          XY06  S32     -1
          XY10  S32     -1
          XY11  S32     -1
          XY12  S32     -1
          XY13  S32     -1
          XY14  S32     -1
          XY15  S32     -1
          XY16  S32     -1
          XY17  S32     -1
          XY20  S32     -1
          XY21  S32     -1
          XY22  S32     -1
          XY23  S32     -1
          XY24  S32     -1
          XY25  S32     -1
          XY26  S32     -1
          XY27  S32     -1
          XY30  S32     -1
          XY31  S32     -1
          XY32  S32     -1
          XY33  S32     -1
          XY34  S32     -1
          XY35  S32     -1
          XY36  S32     -1
          XY37  S32     -1
          XY40  S32     1
          XY41  S32     1
          XY42  S32     1
          XY43  S32     1
          XY44  S32     1
          XY45  S32     1
          XY46  S32     1
          XY47  S32     1
          XY50  S32     1
          XY51  S32     1
          XY52  S32     1
          XY53  S32     1
          XY54  S32     1
          XY55  S32     1
          XY56  S32     1
          XY57  S32     1
          XY60  S32     1
          XY61  S32     1
          XY62  S32     1
          XY63  S32     1
          XY64  S32     1
          XY65  S32     1
          XY66  S32     1
          XY67  S32     1
          XY71  S32     1
          XY72  S32     1
          XY73  S32     1
          XY74  S32     1
          XY75  S32     1
          XY76  S32     1
        END
        CELL.READDIR    S32     1
        CELL.BAD        S32     0
	CELL.XSIZE	S32	590
	CELL.YSIZE	S32	598
        CELL.TIMESYS    STR     UTC
END

# How to translation PS concepts into database lookups
DATABASE        METADATA
	# this rule is fragile : does not match the camera
        FPA.TEMP        STR     SELECT ccd_temp FROM rawExp WHERE dateobs >= '{FPA.DATE}' and abs(timediff(dateobs, cast('{FPA.TIME}' as datetime))) < 2
END


# Where there might be some ambiguity, specify the format
FORMATS         METADATA
        FPA.RA          STR     DEGREES
        FPA.DEC         STR     DEGREES
	FPA.LONGITUDE	STR	HOURS
	FPA.LATITUDE	STR	DEGREES
        FPA.TIME        STR     YEAR.FIRST
        CELL.TIME       STR     YEAR.FIRST
        CELL.BINNING    STR     TOGETHER
        # CELL.X0         STR     FORTRAN
        # CELL.Y0         STR     FORTRAN
	CELL.READNOISE	STR	ADU
END
 
