# 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
PHU		STR	FPA	# The FITS file represents an entire FPA
EXTENSIONS	STR	CELL	# The extensions represent cells

# What's in the FITS file?
CONTENTS	METADATA
	# Extension name, chip name:type
	amp00	STR	ccd00:left
	amp01	STR	ccd00:right
	amp02	STR	ccd01:left
	amp03	STR	ccd01:right
	amp04	STR	ccd02:left
	amp05	STR	ccd02:right
	amp06	STR	ccd03:left
	amp07	STR	ccd03:right
	amp08	STR	ccd04:left
	amp09	STR	ccd04:right
	amp10	STR	ccd05:left
	amp11	STR	ccd05:right
	amp12	STR	ccd06:left
	amp13	STR	ccd06:right
	amp14	STR	ccd07:left
	amp15	STR	ccd07:right
	amp16	STR	ccd08:left
	amp17	STR	ccd08:right
	amp18	STR	ccd09:left
	amp19	STR	ccd09:right
	amp20	STR	ccd10:left
	amp21	STR	ccd10:right
	amp22	STR	ccd11:left
	amp23	STR	ccd11:right
	amp24	STR	ccd12:left
	amp25	STR	ccd12:right
	amp26	STR	ccd13:left
	amp27	STR	ccd13:right
	amp28	STR	ccd14:left
	amp29	STR	ccd14:right
	amp30	STR	ccd15:left
	amp31	STR	ccd15:right
	amp32	STR	ccd16:left
	amp33	STR	ccd16:right
	amp34	STR	ccd17:left
	amp35	STR	ccd17:right
	amp36	STR	ccd18:left
	amp37	STR	ccd18:right
	amp38	STR	ccd19:left
	amp39	STR	ccd19:right
	amp40	STR	ccd20:left
	amp41	STR	ccd20:right
	amp42	STR	ccd21:left
	amp43	STR	ccd21:right
	amp44	STR	ccd22:left
	amp45	STR	ccd22:right
	amp46	STR	ccd23:left
	amp47	STR	ccd23:right
	amp48	STR	ccd24:left
	amp49	STR	ccd24:right
	amp50	STR	ccd25:left
	amp51	STR	ccd25:right
	amp52	STR	ccd26:left
	amp53	STR	ccd26:right
	amp54	STR	ccd27:left
	amp55	STR	ccd27:right
	amp56	STR	ccd28:left
	amp57	STR	ccd28:right
	amp58	STR	ccd29:left
	amp59	STR	ccd29:right
	amp60	STR	ccd30:left
	amp61	STR	ccd30:right
	amp62	STR	ccd31:left
	amp63	STR	ccd31:right
	amp64	STR	ccd32:left
	amp65	STR	ccd32:right
	amp66	STR	ccd33:left
	amp67	STR	ccd33:right
	amp68	STR	ccd34:left
	amp69	STR	ccd34:right
	amp70	STR	ccd35:left
	amp71	STR	ccd35: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.FILTER		STR	FILTER
	FPA.POSANGLE		STR	ROTANGLE
	FPA.RA			STR	RA
	FPA.DEC			STR	DEC
	FPA.RADECSYS		STR	RADECSYS
	CELL.EXPOSURE		STR	EXPTIME
	CELL.DARKTIME		STR	DARKTIME
	CELL.GAIN		STR	GAIN
	CELL.READNOISE		STR	RDNOISE
	CELL.SATURATION		STR	SATURATE
	CELL.TIME		STR	MJD-OBS
	CELL.XBIN		STR	CCDBIN1
	CELL.YBIN		STR	CCDBIN2
END

# Default PS concepts that may be specified by value
DEFAULTS	METADATA
	CELL.READDIR		S32	1		# Cell is read in x direction
	CELL.BAD		S32	0
	CELL.TIMESYS		STR	UTC
	CELL.YPARITY		S32	1
END

# How to translation PS concepts into database lookups
DATABASE	METADATA
	TYPE		dbEntry		TABLE		COLUMN		GIVENDBCOL	GIVENPS
#	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
	CELL.TIME	STR	MJD
#	CELL.BINNING	STR	SEPARATE
	CELL.X0		STR	FORTRAN
	CELL.Y0		STR	FORTRAN
END

# Recipe options
RECIPES		METADATA
	PHASE2		STR	phase2.config		# Phase 2 recipe details
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
