# "mcshort" is a MegaCam camera with only the central six chips --- it's faster than the entire FPA.
# The raw MegaCam data comes off the telescope with each of the chips stored in extensions of a MEF file.

# How to identify this type
RULE	METADATA
	TELESCOP	STR	CFHT 3.6m
	DETECTOR	STR	MegaCam
	EXTEND		BOOL	T
	NEXTEND		S32	72
END

# How to read this data
FILE	METADATA
	PHU		STR	FPA	# The FITS file represents an entire FPA
	EXTENSIONS	STR	CELL	# The extensions represent cells
	FPA.NAME	STR	EXPNUM	# A PHU keyword for unique identifier within the hierarchy level
END

# What's in the FITS file?
CONTENTS	METADATA
	# Extension name, chip name:type
	amp00		STR	ccd00:LeftAmp:left
	amp01		STR	ccd00:RightAmp:right
	amp02		STR	ccd01:LeftAmp:left
	amp03		STR	ccd01:RightAmp:right
	amp04		STR	ccd02:LeftAmp:left
	amp05		STR	ccd02:RightAmp:right
	amp06		STR	ccd03:LeftAmp:left
	amp07		STR	ccd03:RightAmp:right
	amp08		STR	ccd04:LeftAmp:left
	amp09		STR	ccd04:RightAmp:right
	amp10		STR	ccd05:LeftAmp:left
	amp11		STR	ccd05:RightAmp:right
	amp12		STR	ccd06:LeftAmp:left
	amp13		STR	ccd06:RightAmp:right
	amp14		STR	ccd07:LeftAmp:left
	amp15		STR	ccd07:RightAmp:right
	amp16		STR	ccd08:LeftAmp:left
	amp17		STR	ccd08:RightAmp:right
	amp18		STR	ccd09:LeftAmp:left
	amp19		STR	ccd09:RightAmp:right
	amp20		STR	ccd10:LeftAmp:left
	amp21		STR	ccd10:RightAmp:right
	amp22		STR	ccd11:LeftAmp:left
	amp23		STR	ccd11:RightAmp:right
	amp24		STR	ccd12:LeftAmp:left
	amp25		STR	ccd12:RightAmp:right
	amp26		STR	ccd13:LeftAmp:left
	amp27		STR	ccd13:RightAmp:right
	amp28		STR	ccd14:LeftAmp:left
	amp29		STR	ccd14:RightAmp:right
	amp30		STR	ccd15:LeftAmp:left
	amp31		STR	ccd15:RightAmp:right
	amp32		STR	ccd16:LeftAmp:left
	amp33		STR	ccd16:RightAmp:right
	amp34		STR	ccd17:LeftAmp:left
	amp35		STR	ccd17:RightAmp:right
	amp36		STR	ccd18:LeftAmp:left
	amp37		STR	ccd18:RightAmp:right
	amp38		STR	ccd19:LeftAmp:left
	amp39		STR	ccd19:RightAmp:right
	amp40		STR	ccd20:LeftAmp:left
	amp41		STR	ccd20:RightAmp:right
	amp42		STR	ccd21:LeftAmp:left
	amp43		STR	ccd21:RightAmp:right
	amp44		STR	ccd22:LeftAmp:left
	amp45		STR	ccd22:RightAmp:right
	amp46		STR	ccd23:LeftAmp:left
	amp47		STR	ccd23:RightAmp:right
	amp48		STR	ccd24:LeftAmp:left
	amp49		STR	ccd24:RightAmp:right
	amp50		STR	ccd25:LeftAmp:left
	amp51		STR	ccd25:RightAmp:right
	amp52		STR	ccd26:LeftAmp:left
	amp53		STR	ccd26:RightAmp:right
	amp54		STR	ccd27:LeftAmp:left
	amp55		STR	ccd27:RightAmp:right
	amp56		STR	ccd28:LeftAmp:left
	amp57		STR	ccd28:RightAmp:right
	amp58		STR	ccd29:LeftAmp:left
	amp59		STR	ccd29:RightAmp:right
	amp60		STR	ccd30:LeftAmp:left
	amp61		STR	ccd30:RightAmp:right
	amp62		STR	ccd31:LeftAmp:left
	amp63		STR	ccd31:RightAmp:right
	amp64		STR	ccd32:LeftAmp:left
	amp65		STR	ccd32:RightAmp:right
	amp66		STR	ccd33:LeftAmp:left
	amp67		STR	ccd33:RightAmp:right
	amp68		STR	ccd34:LeftAmp:left
	amp69		STR	ccd34:RightAmp:right
	amp70		STR	ccd35:LeftAmp:left
	amp71		STR	ccd35:RightAmp:right
END

# Specify the cell data
CELLS	METADATA
	left	METADATA	# Left amplifier
		CELL.BIASSEC.SOURCE	STR	HEADER
		CELL.TRIMSEC.SOURCE	STR	HEADER
		CELL.BIASSEC		STR	BIASSEC
		CELL.TRIMSEC		STR	DATASEC
		CELL.XPARITY		S32	1 # We could have specified this as a DEFAULT, but this works
		CELL.X0			S32	1
		CELL.Y0			S32	1
	END
	right	METADATA	# Right amplifier
		CELL.BIASSEC.SOURCE	STR	HEADER
		CELL.TRIMSEC.SOURCE	STR	HEADER
		CELL.BIASSEC		STR	BIASSEC
		CELL.TRIMSEC		STR	DATASEC
		CELL.XPARITY		S32	-1 # This cell is read out in the opposite direction
		CELL.X0			S32	2048
		CELL.Y0			S32	1
	END
END

# How to translate PS concepts into FITS headers
TRANSLATION	METADATA
	FPA.NAME		STR	EXPNUM
	FPA.AIRMASS		STR	AIRMASS
	FPA.FILTERID		STR	FILTER
	FPA.FILTER		STR	FILTER
	FPA.POSANGLE		STR	ROTANGLE
	FPA.RA			STR	RA
	FPA.DEC			STR	DEC
	FPA.RADECSYS		STR	RADECSYS
	FPA.FOCUS		STR	TELFOCUS
	FPA.OBSTYPE		STR	OBSTYPE
	FPA.OBJECT		STR	OBJECT
	FPA.TIME		STR	MJD-OBS
	FPA.TIMESYS		STR	TIMESYS
	FPA.ALT			STR	TELALT
	FPA.AZ			STR	TELAZ
	FPA.TEMP		STR	DETTEM
	FPA.EXPOSURE		STR	EXPTIME
	CHIP.TEMP		STR	DETTEM
	CELL.EXPOSURE		STR	EXPTIME
	CELL.DARKTIME		STR	DARKTIME
	CELL.GAIN		STR	GAIN
	CELL.READNOISE		STR	RDNOISE
	CELL.TIME		STR	MJD-OBS
	CELL.TIMESYS		STR	TIMESYS
	CELL.XBIN		STR	CCDBIN1
	CELL.YBIN		STR	CCDBIN2
END

# Default PS concepts that may be specified by value
DEFAULTS	METADATA
	FPA.TELESCOPE		STR	CFHT
	FPA.INSTRUMENT		STR	MEGACAM
	FPA.DETECTOR		STR	MEGACAM
	CHIP.XSIZE		S32	2048
	CHIP.YSIZE		S32	4612
	CELL.XSIZE		S32	1024
	CELL.YSIZE		S32	4612
	CELL.XWINDOW		S32	0
	CELL.YWINDOW		S32	0
	CELL.READDIR		S32	1		# Cell is read in x direction
        CELL.SATURATION		F32	50000.0
	CELL.BAD		F32	0
	CELL.YPARITY		S32	1

	CHIP.X0.DEPEND		STR	CHIP.NAME
	CHIP.X0		METADATA
		ccd00	S32	0
		ccd01	S32	2048
		ccd02	S32	4096
		ccd03	S32	6144
		ccd04	S32	8192
		ccd05	S32	10240
		ccd06	S32	12288
		ccd07	S32	14336
		ccd08	S32	16384
		ccd09	S32	0
		ccd10	S32	2048
		ccd11	S32	4096
		ccd12	S32	6144
		ccd13	S32	8192
		ccd14	S32	10240
		ccd15	S32	12288
		ccd16	S32	14336
		ccd17	S32	16384
		ccd18	S32    -2048
		ccd19	S32	0    
		ccd20	S32	2048 
		ccd21	S32	4096 
		ccd22	S32	6144 
		ccd23	S32	8192 
		ccd24	S32	10240
		ccd25	S32	12288
		ccd26	S32	14336
		ccd27	S32    -2048
		ccd28	S32	0    
		ccd29	S32	2048 
		ccd30	S32	4096 
		ccd31	S32	6144 
		ccd32	S32	8192 
		ccd33	S32	10240
		ccd34	S32	12288
		ccd35	S32	14336
	END
	CHIP.Y0.DEPEND		STR	CHIP.NAME
	CHIP.Y0		METADATA
		ccd00	S32	18447
		ccd01	S32	18447
		ccd02	S32	18447
		ccd03	S32	18447
		ccd04	S32	18447
		ccd05	S32	18447
		ccd06	S32	18447
		ccd07	S32	18447
		ccd08	S32	18447
		ccd09	S32	13835
		ccd10	S32	13835
		ccd11	S32	13835
		ccd12	S32	13835
		ccd13	S32	13835
		ccd14	S32	13835
		ccd15	S32	13835
		ccd16	S32	13835
		ccd17	S32	13835
		ccd18	S32	4612
		ccd19	S32	4612
		ccd20	S32	4612
		ccd21	S32	4612
		ccd22	S32	4612
		ccd23	S32	4612
		ccd24	S32	4612
		ccd25	S32	4612
		ccd26	S32	4612
		ccd27	S32	0
		ccd28	S32	0
		ccd29	S32	0
		ccd30	S32	0
		ccd31	S32	0
		ccd32	S32	0
		ccd33	S32	0
		ccd34	S32	0
		ccd35	S32	0
	END
	CHIP.XPARITY.DEPEND	STR	CHIP.NAME
	CHIP.XPARITY	METADATA
		ccd00	S32	-1
		ccd01	S32	-1
		ccd02	S32	-1
		ccd03	S32	-1
		ccd04	S32	-1
		ccd05	S32	-1
		ccd06	S32	-1
		ccd07	S32	-1
		ccd08	S32	-1
		ccd09	S32	-1
		ccd10	S32	-1
		ccd11	S32	-1
		ccd12	S32	-1
		ccd13	S32	-1
		ccd14	S32	-1
		ccd15	S32	-1
		ccd16	S32	-1
		ccd17	S32	-1
		ccd18	S32	1
		ccd19	S32	1
		ccd20	S32	1
		ccd21	S32	1
		ccd22	S32	1
		ccd23	S32	1
		ccd24	S32	1
		ccd25	S32	1
		ccd26	S32	1
		ccd27	S32	1
		ccd28	S32	1
		ccd29	S32	1
		ccd30	S32	1
		ccd31	S32	1
		ccd32	S32	1
		ccd33	S32	1
		ccd34	S32	1
		ccd35	S32	1
	END
	CHIP.YPARITY.DEPEND	STR	CHIP.NAME
	CHIP.YPARITY	METADATA
		ccd00	S32	-1
		ccd01	S32	-1
		ccd02	S32	-1
		ccd03	S32	-1
		ccd04	S32	-1
		ccd05	S32	-1
		ccd06	S32	-1
		ccd07	S32	-1
		ccd08	S32	-1
		ccd09	S32	-1
		ccd10	S32	-1
		ccd11	S32	-1
		ccd12	S32	-1
		ccd13	S32	-1
		ccd14	S32	-1
		ccd15	S32	-1
		ccd16	S32	-1
		ccd17	S32	-1
		ccd18	S32	1
		ccd19	S32	1
		ccd20	S32	1
		ccd21	S32	1
		ccd22	S32	1
		ccd23	S32	1
		ccd24	S32	1
		ccd25	S32	1
		ccd26	S32	1
		ccd27	S32	1
		ccd28	S32	1
		ccd29	S32	1
		ccd30	S32	1
		ccd31	S32	1
		ccd32	S32	1
		ccd33	S32	1
		ccd34	S32	1
		ccd35	S32	1
	END
END

# How to translation PS concepts into database lookups
DATABASE	METADATA
	TYPE		dbEntry		TABLE		COLUMN		GIVENDBCOL	GIVENPS
#	FPA.BIAS	METADATA
#		TABLE	STR	Camera
#		COLUMN	STR	gain
#		chipId	STR	{CHIP.NAME}
#		cellId	STR	{CELL.NAME}
#		time	STR	{CELL.TIME}
#	END
#	CELL.GAIN	dbEntry		Camera		gain		chipId,cellId	CHIP.NAME,CELL.NAME
#	CELL.READNOISE	dbEntry		Camera		readNoise	chipId,cellId	CHIP.NAME,CELL.NAME

# A database entry refers to a particular column (COLUMN) in a
# particular table (TABLE), given certain PS concepts (GIVENPS) that
# match certain database columns (GIVENDBCOL).
END


# Where there might be some ambiguity, specify the format
FORMATS		METADATA
	FPA.RA		STR	HOURS
	FPA.DEC		STR	DEGREES
	FPA.TIME	STR	MJD
	CELL.TIME	STR	MJD
	CELL.X0		STR	FORTRAN
	CELL.Y0		STR	FORTRAN
END
