# The raw GPC data comes off the telescope with each of the chips stored in separate files

# How to identify this type
RULE    METADATA
#	ORIGIN		STR	PS1
#        TELESCOP        STR     PS1
###	SOMETHING	STR	GPC1
        CONTROLR        STR     STARGRASP
        NAMPS           S32     64
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-1-13a1  STR  XY03:GPCChip  # chip 02
        CCID58-1-09a1  STR  XY04:GPCChip  # chip 03
        CCID58-2-16b1  STR  XY05:GPCChip  # chip 04
        CCID58-2-09b1  STR  XY06:GPCChip  # chip 05
        CCID58-2-22a1  STR  XY10:GPCChip  # chip 06
        CCID58-2-13a2  STR  XY11:GPCChip  # chip 07
        CCID58-1-17a2  STR  XY12:GPCChip  # chip 08
        CCID58-1-14a2  STR  XY13:GPCChip  # chip 09
        CCID58-1-09a2  STR  XY14:GPCChip  # chip 10
        CCID58-2-13b1  STR  XY15:GPCChip  # chip 11
        CCID58-1-09b1  STR  XY16:GPCChip  # chip 12
        CCID58-2-10b2  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-1-04a2  STR  XY24:GPCChip  # chip 18
        CCID58-1-01b1  STR  XY25:GPCChip  # chip 19
        CCID58-2-07b2  STR  XY26:GPCChip  # chip 20
        CCID58-1-18b1  STR  XY27:GPCChip  # chip 21
        CCID58-1-12a1  STR  XY30:GPCChip  # chip 22
        CCID58-2-01a1  STR  XY31:GPCChip  # chip 23
        CCID58-2-01a2  STR  XY32:GPCChip  # chip 24
        CCID58-1-02a2  STR  XY33:GPCChip  # chip 25
        CCID58-2-04a1  STR  XY34:GPCChip  # chip 26
        CCID58-1-01b2  STR  XY35:GPCChip  # chip 27
        CCID58-1-02b1  STR  XY36:GPCChip  # chip 28
        CCID58-2-16b2  STR  XY37:GPCChip  # chip 29
        CCID58-2-18b2  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-1-05a2  STR  XY44:GPCChip  # chip 34
        CCID58-1-21a2  STR  XY45:GPCChip  # chip 35
        CCID58-2-07a2  STR  XY46:GPCChip  # chip 36
        CCID58-1-21a1  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-2-09a1  STR  XY54:GPCChip  # chip 42
        CCID58-2-12a2  STR  XY55:GPCChip  # chip 43
        CCID58-1-10a2  STR  XY56:GPCChip  # chip 44
        CCID58-2-12a1  STR  XY57:GPCChip  # chip 45
        CCID58-2-22b2  STR  XY60:GPCChip  # chip 46
        CCID58-1-03b1  STR  XY61:GPCChip  # chip 47
        CCID58-2-23b2  STR  XY62:GPCChip  # chip 48
        CCID58-1-02b2  STR  XY63:GPCChip  # chip 49
        CCID58-1-07a1  STR  XY64:GPCChip  # chip 50
        CCID58-2-17a2  STR  XY65:GPCChip  # chip 51
        CCID58-2-14a1  STR  XY66:GPCChip  # chip 52
        CCID58-2-16a2  STR  XY67:GPCChip  # chip 53
        CCID58-2-04b2  STR  XY71:GPCChip  # chip 54
        CCID58-1-14b1  STR  XY72:GPCChip  # chip 55
        CCID58-1-25b1  STR  XY73:GPCChip  # chip 56
        CCID58-1-18a1  STR  XY74:GPCChip  # chip 57
        CCID58-2-16a1  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.RA          STR     COMRA
        # FPA.DEC         STR     COMDEC
        FPA.RADECSYS    STR     RADECSYS
        FPA.OBSTYPE     STR     OBSTYPE
        FPA.OBJECT      STR     OBJECT
        FPA.COMMENT     STR     CMMTOBS
        FPA.AIRMASS     STR     AIRMASS
        FPA.POSANGLE    STR     POSANGLE
        FPA.FOCUS       STR     M2Z
        FPA.TIME        STR     MJD-OBS
        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.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
#       CELL.SATURATION STR     SATURATE

#        CHIP.TEMP       STR     DETTEM	# XY24 is bad, so get it from the database; all others from header
	CHIP.TEMP.DEPEND	STR	CHIP.NAME
	CHIP.TEMP	METADATA
		XY01	STR	DETTEM
		XY02	STR	DETTEM
		XY03	STR	DETTEM
		XY04	STR	DETTEM
		XY05	STR	DETTEM
		XY06	STR	DETTEM
		XY10	STR	DETTEM
		XY11	STR	DETTEM
		XY12	STR	DETTEM
		XY13	STR	DETTEM
		XY14	STR	DETTEM
		XY15	STR	DETTEM
		XY16	STR	DETTEM
		XY17	STR	DETTEM
		XY20	STR	DETTEM
		XY21	STR	DETTEM
		XY22	STR	DETTEM
		XY23	STR	DETTEM
#		XY24	STR	DETTEM	# This is currently bad --- get it from the database
		XY25	STR	DETTEM
		XY26	STR	DETTEM
		XY27	STR	DETTEM
		XY30	STR	DETTEM
		XY31	STR	DETTEM
		XY32	STR	DETTEM
		XY33	STR	DETTEM
		XY34	STR	DETTEM
		XY35	STR	DETTEM
		XY36	STR	DETTEM
		XY37	STR	DETTEM
		XY40	STR	DETTEM
		XY41	STR	DETTEM
		XY42	STR	DETTEM
		XY43	STR	DETTEM
		XY44	STR	DETTEM
		XY45	STR	DETTEM
		XY46	STR	DETTEM
		XY47	STR	DETTEM
		XY50	STR	DETTEM
		XY51	STR	DETTEM
		XY52	STR	DETTEM
		XY53	STR	DETTEM
		XY54	STR	DETTEM
		XY55	STR	DETTEM
		XY56	STR	DETTEM
		XY57	STR	DETTEM
		XY60	STR	DETTEM
		XY61	STR	DETTEM
		XY62	STR	DETTEM
		XY63	STR	DETTEM
		XY64	STR	DETTEM
		XY65	STR	DETTEM
		XY66	STR	DETTEM
		XY67	STR	DETTEM
		XY71	STR	DETTEM
		XY72	STR	DETTEM
		XY73	STR	DETTEM
		XY74	STR	DETTEM
		XY75	STR	DETTEM
		XY76	STR	DETTEM
	END

        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
END

# Default PS concepts that may be specified by value
DEFAULTS        METADATA
        FPA.TELESCOPE   STR     PS1
        FPA.INSTRUMENT  STR     GPC1
        FPA.DETECTOR    STR     GPC1
        FPA.TIMESYS     STR     UTC
        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
          XY34  S32     19884
          XY35  S32     19884
          XY36  S32     19884
          XY37  S32     19884
          XY40  S32     20041
          XY41  S32     20041
          XY42  S32     20041
          XY43  S32     20041
          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
          XY35  S32     30858
          XY36  S32     36001
          XY37  S32     41144
          XY40  S32     306
          XY41  S32     5449
          XY42  S32     10592
          XY43  S32     15735
          XY44  S32     20878
          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.GAIN       F32     1.0
        CELL.READNOISE  F32     15.0
        CELL.READDIR    S32     1
        CELL.BAD        S32     -100
#       CELL.TIME       STR     MJD-OBS
#       CELL.TIMESYS    STR     TIMESYS
        CELL.SATURATION F32     40000.0
END

# How to translation PS concepts into database lookups
DATABASE        METADATA
	CHIP.TEMP.DEPEND	STR	CHIP.NAME
	CHIP.TEMP		METADATA
		XY24	STR	SELECT AVG(ccd_temp) FROM rawImfile WHERE dateobs = '{FPA.TIME}' AND class_id != 'XY24'
	END
END


# Where there might be some ambiguity, specify the format
FORMATS         METADATA
        FPA.RA          STR     DEGREES
        FPA.DEC         STR     DEGREES
        FPA.TIME        STR     MJD
        CELL.TIME       STR     MJD
        CELL.BINNING    STR     TOGETHER
        CELL.X0         STR     FORTRAN
        CELL.Y0         STR     FORTRAN
END
 
# Recipe options
RECIPES         METADATA
END
 
# How to get the supplementary stuff: mask and weight
SUPPLEMENTARY   METADATA
        MASK.SOURCE     STR     FILE            # Source type for mask: EXT | FILE
        MASK.NAME       STR     %a_mask.fits    # Name for mask extension or filename
        WEIGHT.SOURCE   STR     FILE            # Source type for weight: EXT | FILE
        WEIGHT.NAME     STR     %a_weight.fits  # Name for weight extension or filename
END
