STScI Logo

analoglin



procedure analoglin (intable, outtable, ref_flux)

file intable = ""	{prompt = "input table name"}
file outtable = ""	{prompt = "output table name"}
file ref_flux = ""	{prompt = "reference flux density table"}

pset cal_tables = ""	{prompt = "Which set of calibration tables are used"}
bool save = no {prompt = "save the scratch table? (yes or no)"}
string temp_key = "DET_TEMP"	{prompt = "column name of the temperature"}

string mode = "al"

begin
	file	intbl, outtbl, reftbl, tmptable, tmp2, tmp3
	int 	ncols
	int 	rowused

	intbl = intable
	outtbl = outtable
	reftbl = ref_flux

	if (intbl == "") {
	    print ("Error: Input table is empty.")
	    bye ()
	}

	# set up a scratch table
	tmptable = mktemp("analoglin") + ".tab"
	tmp2 = mktemp("alin") + ".tab"
	tmp3 = mktemp("alin") + ".tab"

	#load table tools
	if (!defpac("ttools")) {
	    print ("The stsdas-ttools package must be loaded.")
	    bye ()
	}

	# expand column size
	tinfo (table = intbl, ttout = no)
	ncols = tinfo.ncols + 14
	rowused = tinfo.rowused + 14
	tchsize (intable = intbl, outtable = tmptable, maxpar = -1, 
		maxcols = ncols, rowlen = rowused, allrows = -1, verbose = no)

	# evaluate calibration corrections
	vevalp (tmptable, cal_tables = cal_tables)

	tcalc (table = tmptable, outcol = "AOBJ_C", equals = \
	       "((AOBJ-CVCOFFST)/GAINFACT-PREAMP_A-DARK_A)/(HVFACT_A*SENSITIV)",
 	       datatype = "real", mode = "h")
	tcalc (table = tmptable, outcol = "ASKY_C", equals = \
	       "((ASKY-CVCOFFST)/GAINFACT-PREAMP_A-DARK_A)/(HVFACT_A*SENSITIV)",
 	       datatype = "real", mode = "h")
	tcalc (table = tmptable, outcol = "AOBJ_C_ERR", 
 		equals = "AOBJ_ERR/(GAINFACT*HVFACT_A*SENSITIV)",
 		datatype = "real", mode = "h")
	
	vasen (intable = tmptable, outtable = tmp2, count_key = "AOBJ_C", 
		counterr_key = "AOBJ_C_ERR", sky_key = "ASKY_C", 
		temp_key = temp_key, ref_flux = reftbl)

	# fit a straight line to the data
	vpolyfit (intable = tmp2, outtable = tmp3, order = 1, weight = 0,
		type = "DIGITAL", yname = "COUNT", yerrname = "COUNT_ERR", 
		xname = "REF_FLUX", xrefname = "BASE_FLUX", xref = 0, 
		xminname = "FLUXMIN", xmaxname = "FLUXMAX", nattrib = 0)

	tproject (intable=tmp3, outtable=outtbl, 
		columns="~ORDER,TYPE,BASE_FLUX")
	delete (tmp3)

	# delete the scratch table
	if (save) {
	    print ("scratch table ", tmptable, " created locally")
	    print ("scratch table ", tmp2, " created locally")
	    putlog ("scratch table ", tmptable, " created locally")
	    putlog ("scratch table ", tmp2, " created locally")
	} else {
	    delete (tmptable)
	    delete (tmp2)
	}
end

Source Code · Search Form · STSDAS