# Format file for CTIO Mosaic2 camera used by ESSENCE

# How to identify this type
RULE	METADATA
	TELESCOP	STR	CTIO 4.0 meter telescope
	DETECTOR	STR	Mosaic2
	EXTEND		BOOL	T
	NEXTEND		S32	16
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.OBS	STR	FILENAME # A PHU keyword for unique identifier within the hierarchy level
END

# What's in the FITS file?
CONTENTS	METADATA
	# Extension name, chip name:type
	im1		STR	ccd00:LeftAmp:left
	im2		STR	ccd00:RightAmp:right
	im3		STR	ccd01:LeftAmp:left  
	im4		STR	ccd01:RightAmp:right
	im5		STR	ccd02:LeftAmp:left  
	im6		STR	ccd02:RightAmp:right
	im7		STR	ccd03:LeftAmp:left  
	im8		STR	ccd03:RightAmp:right
	im9		STR	ccd04:LeftAmp:left  
	im10		STR	ccd04:RightAmp:right
	im11		STR	ccd05:LeftAmp:left  
	im12		STR	ccd05:RightAmp:right
	im13		STR	ccd06:LeftAmp:left  
	im14		STR	ccd06:RightAmp:right
	im15		STR	ccd07:LeftAmp:left  
	im16		STR	ccd07:RightAmp:right
END

# Specify the cell data
CELLS	METADATA
	left	METADATA
		CELL.BIASSEC.SOURCE	STR	HEADER
		CELL.TRIMSEC.SOURCE	STR	HEADER
		CELL.BIASSEC		STR	BIASSEC
		CELL.TRIMSEC		STR	TRIMSEC
		CELL.XPARITY		S32	1
		CELL.X0			S32	0
	END
	right	METADATA
		CELL.BIASSEC.SOURCE	STR	HEADER
		CELL.TRIMSEC.SOURCE	STR	HEADER
		CELL.BIASSEC		STR	BIASSEC
		CELL.TRIMSEC		STR	TRIMSEC
		CELL.XPARITY		S32	1
		CELL.X0			S32	1024
	END
END

# How to translate PS concepts into FITS headers
TRANSLATION	METADATA
	FPA.AIRMASS		STR	AIRMASS
	FPA.FILTERID		STR	FILTER
	FPA.FILTER		STR	FILTER
	FPA.RA			STR	RA
	FPA.DEC			STR	DEC
	FPA.RADECSYS		STR	RADECSYS
	FPA.OBSTYPE		STR	OBSTYPE
	FPA.OBJECT		STR	OBJECT
	FPA.TIME		STR	MJD-OBS
	CHIP.TEMP		STR	CCDTEM
	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	CCDSUM
	CELL.YBIN		STR	CCDSUM
END

# Default PS concepts that may be specified by value
DEFAULTS	METADATA
        FPA.TELESCOPE           STR     BLANCO
        FPA.INSTRUMENT          STR     MOSAIC2
        FPA.DETECTOR            STR     MOSAIC2
	FPA.POSANGLE		F32	0.0
	FPA.TIMESYS		STR	UTC		# Header says "UTC approximate"
	FPA.ALT			F32	0.0		# Not present in header
	FPA.AZ			F32	0.0		# Not present in header
	CELL.TIMESYS		STR	UTC		# Header says "UTC approximate"
	CELL.READDIR		S32	1		# Cell is read in x direction
	CELL.BAD		S32	0
	CELL.YPARITY		S32	1
	CELL.Y0			S32	0

	CHIP.X0.DEPEND		STR	CHIP.NAME
	CHIP.X0		METADATA
		ccd00	S32	0
		ccd01	S32	2048
		ccd02	S32	4096
		ccd03	S32	6144
		ccd04	S32	0
		ccd05	S32	2048
		ccd06	S32	4096
		ccd07	S32	6144
	END
	CHIP.Y0.DEPEND		STR	CHIP.NAME
	CHIP.Y0		METADATA
		ccd00	S32	0
		ccd01	S32	0
		ccd02	S32	0
		ccd03	S32	0
		ccd04	S32	4096
		ccd05	S32	4096
		ccd06	S32	4096
		ccd07	S32	4096
	END
	CHIP.XPARITY	S32	1
	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
	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
#	CHIP.X0		STR	FORTRAN
#	CHIP.Y0		STR	FORTRAN
#	CELL.X0		STR	FORTRAN
#	CELL.Y0		STR	FORTRAN
END
