# File: u_phot.x include include include include include include "u_incl.h" include "u_data.h" ################################################################################# # # # U_PHOTMODE -- Construct value for PHOTMODE keyword from the following # # header keywords: # # , DETECTOR, ATODGAIN, FILTNAM1, FILTNAM2, # # # # The PHOTMODE keyword is constructed by concatenating the # # string values of the keywords, except that the integer value # # of DETECTOR is first converted to its character representation. # # # # Last Modified: # # 20 Aug 92 by RAShaw Initial implementation # # 10 Sep 93 by CYZhang Match the new GRAPHTAB and COMPTAB keywords # # 19 Oct 93 by CYZhang Attach LRFWAVE to Linear Ramp Filters # # 15 Feb 94 by CYZhang Remove DN from PHOTMODE string # procedure u_photmode (cam, kw) # Calling arguments: pointer cam # pointer to CAMera data structure pointer kw # pointer to KeyWord data structure # Local variables: #char bunit[SZ_PHOT] # Brightness unit: DN or PH (photons) char gain[SZ_PHOT] # A-to-D Gain setting #char mode[SZ_PHOT] # mode (on-chip binning used?) char text[SZ_PHOT] # Workspace for constructing PHOTMODE char lrf_text[SZ_FNAME] # Constructing LRFWAVE string char tx_end[1] # EOS # Functions used: bool streq() # Test for string equality int strlen() # Return the length of a character string bool fp_equalr() # Test equality for two real numbers errchk strcpy, strlen, u_kwerr, u_error begin call strcpy (EOS, text, SZ_PHOT) # Determine the chip binning mode, then save the first character of that # keyword. # There is no need for photometric keywords for "FULL" or "AREA" and # for "OPEN" filter specification anymore in the # latest hstgraph_930903a.tab and hstcomp_930903a.tab # Chris Burrows recommended to leave these things out -- CYZ 9/9/93 # if ( IS_FULL(cam) ) # call strcpy ("FULL", mode, SZ_PHOT) # else # call strcpy ("AREA", mode, SZ_PHOT) # Set the brightness unit to Data Numbers. Note that this is currently # hardwired to "DN", but that another potentially valid value would be "PH" # for photons. # If ATODGAIN is set up right (not empty), DN must be used. --CYZ 10/9/93 # When DN is used without ATODGAIN set up, ATODGAIN=A2D7 # Bill Sparks said DN caused lots of confusion, it should be removed # from the PHOTMODE string, even though it is still a legitimate # keyword in the cdbs database --CYZ 15/2/94 # call strcpy ("DN", bunit, SZ_PHOT) # Set "gain" string according to the ATODGAIN value # The latest version has A2D15 and A2D7 rather than A2DHI and A2DLO -- CYZ # 9/9/93 # if ( abs (A2DGAIN(cam) - LO_A2D) > EPSILONR ) # call strcpy ("A2DHI", gain, SZ_PHOT) # else # call strcpy ("A2DLO", gain, SZ_PHOT) if ( fp_equalr(A2DGAIN(cam), HI_A2D) ) call strcpy ("A2D15", gain, SZ_PHOT) else if ( fp_equalr(A2DGAIN(cam), LO_A2D) ) call strcpy ("A2D7", gain, SZ_PHOT) else if ( !fp_equalr(A2DGAIN(cam), HI_A2D) && !fp_equalr(A2DGAIN(cam), LO_A2D) ) call strcpy ("A2D7", gain, SZ_PHOT) # The name strings for each filter are presently in the global keywords # FILTER1 and FILTER2; set them = "OPEN" if they are empty (i.e. = EOS) # if (streq (FILTER1(cam), text)) # call strcpy ("OPEN", FILTER1(cam), SZ_PHOT) # if (streq (FILTER2(cam), text)) # call strcpy ("OPEN", FILTER2(cam), SZ_PHOT) # Instead set them = "" if they are empty (see the latest tables) -- CYZ # 9/9/93 if (streq (FILTER1(cam), text)) call strcpy ("", FILTER1(cam), SZ_PHOT) if (streq (FILTER2(cam), text)) call strcpy ("", FILTER2(cam), SZ_PHOT) # Linear Ramp Filters need specification of wavelength -- CYZ 19/10/93 if (streq (FILTER1(cam), "LRF")) { call sprintf (lrf_text, SZ_FNAME, "#%-7.2f") call pargr (LRFWAVE(cam)) call strcat (lrf_text, FILTER1(cam), SZ_FNAME) } if (streq (FILTER2(cam), "LRF")) { call sprintf (lrf_text, SZ_FNAME, "#%-7.2f") call pargr (LRFWAVE(cam)) call strcat (lrf_text, FILTER2(cam), SZ_FNAME) } # Add the EOS to the end of the PHOTMODE string tx_end[1] = EOS # Concatenate strings, separated by commas. # call sprintf (text, SZ_LINE, "WFPC2,%1d,%4s,%5s,%2s,%s,%s") # call sprintf (text, SZ_LINE, "WF,%1d,%4s,%2s,%s,%s" # call sprintf (text, SZ_LINE, "WFPC2,%1d,%s,%2s,%s,%s") # call sprintf (text, SZ_LINE, "WFPC2,%1d,%s,%2s,%s,%s,%s%s") call sprintf (text, SZ_LINE, "WFPC2,%1d,%s,%s,%s,%s%s") call pargi (DETECTOR(cam)) call pargstr (gain) # Remove "bunit" (DN) from the PHOTMODE string -- CYZ 15/2/94 # call pargstr (bunit) call pargstr (FILTER1(cam)) call pargstr (FILTER2(cam)) call pargstr ("CAL") call pargstr (tx_end) # Copy the result to PHOTMODE(cam) and quit. Note that PHOTMODE must be no # longer than SZ_PHOT characters because it is the value of a GROUP parameter. if (strlen (text) > SZ_PHOT) call u_error ("PHOTMODE string longer than 48 chars") call strcpy (text, PHOTMODE(kw), SZ_PHOT) end ################################################################################# # # # U_PHOTMATCH -- Search GRAPHTAB and COMPTAB files for a match with # # the keyword PHOTMODE. If found, compute the grand # # throughput table and the values for the group parameter # # keywords: PHOTFLAM, PHOTZPT, PHOTPLAM, PHOTBW. # # # # The grpnum parameter is included in missing calibration # # error messages since it is possible to have phot # # calibration on only a subset of the groups. # # # # Revision History: # # 23 Jul 1992 by RAShaw Initial implementation # # 10 Sep 1993 by CYZhang Not used any more # procedure u_photmatch (tp, kw, grpnum) # Calling arguments: pointer tp # pointer to table descriptor pointer kw # pointer to KeyWord structure int grpnum # current group number # Local variables: pointer cp_photmode # photmode column pointer pointer cp_flam # photflam: inverse sensitivity pointer cp_zpt # photzpt: magnitude zero point pointer cp_plam # photplam: pivot wavelength pointer cp_bw # photbw: bandwidth of filter bool pflag # match found flag char pmode[SZ_PHOT] # PHOTMODE(cam) from PHOTTAB int row # loop index for search char text[SZ_LINE] # buffer for warning message string int trows # number of rows in phot table # Functions used: bool streq() # string equality test int tbpsta() # Return number of rows in tables errchk u_kwerr, u_error, tbcfnd, tbpsta, tbegtt, tbegtr, imgstr, streq, imputr, u_strpwht, u_warn, sprintf, pargi begin # Map PHOTMODE column in table call tbcfnd (tp, "PHOTMODE", cp_photmode, 1) if (cp_photmode == NULL) call u_error ("PHOTMODE column not found in PHOTTAB") # Find number of rows in table iferr ( trows = tbpsta (tp, TBL_NROWS) ) call u_error ("Could not determine size of PHOTTAB") # Search PHOTMODE column for match pflag = false do row = 1, trows { iferr ( call tbegtt (tp, cp_photmode, row, pmode, SZ_PHOT) ) call u_error ("Row read from PHOTTAB failed") # Strip trailing whitespace from table entry call u_strpwht (pmode) if ( streq (PHOTMODE(kw), pmode) ) { # Match found case: map columns iferr ( call tbcfnd (tp, "PHOTFLAM", cp_flam, 1) ) call u_error ("PHOTFLAM column not found in PHOTTAB") if (cp_flam == NULL) call u_error ("PHOTFLAM column pointer map failed" ) iferr ( call tbcfnd (tp, "PHOTZPT", cp_zpt, 1) ) call u_error ("PHOTZPT column not found in PHOTTAB") if (cp_zpt == NULL) call u_error ("PHOTZPT column pointer map failed" ) iferr ( call tbcfnd (tp, "PHOTPLAM", cp_plam, 1) ) call u_error ("PHOTPLAM column not found in PHOTTAB") if (cp_plam == NULL) call u_error ("PHOTPLAM column pointer map failed") iferr ( call tbcfnd (tp, "PHOTBW", cp_bw, 1) ) call u_error ("PHOTBW column not found in PHOTTAB") if (cp_bw == NULL) call u_error ("PHOTBW column pointer map failed") # Fetch photometry keyword values iferr (call tbegtr (tp, cp_flam, row, PHOTFLAM(kw))) call u_error ("PHOTFLAM value not found in PHOTTAB") iferr (call tbegtr (tp, cp_zpt, row, PHOTZPT(kw))) call u_error ("PHOTZPT value not found in PHOTTAB") iferr (call tbegtr (tp, cp_plam, row, PHOTPLAM(kw))) call u_error ("PHOTPLAM value not found in PHOTTAB") iferr (call tbegtr (tp, cp_bw, row, PHOTBW(kw))) call u_error ("PHOTBW value not found in PHOTTAB") # Indicate match found & stop search pflag = true break } } # Print warning message if no calibration found and is_c0h file if (!pflag) { call sprintf (text, SZ_LINE, "Photometric calibration not available for group %d") call pargi (grpnum) call u_warn (text) } end # u_photcalc -- calculate synthetic photmetry for WFPC2 # # This subroutine first creates an array of wavelengths. Then it # computes the instrument passband and error on the input wavelength # set. Finally it computes four scalar photometric parameters from the # instrument passband: the inverse sensitivity, PHOT(1), the zero # point parameter, PHOT(2), the pivot wavelength, PHOT(3), and the # rms bandwith, PHOT(4) # # History: # -------- # Version Date Author Description # 1 04-08-93 J.C. Hsu adapt from gtphot.f # 2 08-09-93 B. Simon Adapted to updated synphot lib # 3 01-25-94 C.Y. Zhang Get phot_path to HISTORY #------------------------------------------------------------------------------ procedure u_photcalc (kw, grpnum, thr_tp, grftbl, cmptbl, phot_path, maxpath) pointer kw # io: keyword structure int grpnum # i: group number pointer thr_tp # i: throughput table pointer char grftbl[ARB] # i: graph table name char cmptbl[ARB] # i: component table name char phot_path[ARB] # o: history info for phot int maxpath # i: max size of phot_path #-- bool logspace char colname[SZ_COLNAME], keyword[SZ_KEYWORD] int nwave pointer sp, wave, filt, filterr, colptr real phot[4] errchk getbandx, phopar begin # Write diagnostic message call printf ("photmode = %s\n") call pargstr (PHOTMODE(kw)) call flush (STDOUT) # Define wavelength set length and type nwave = 1000 logspace = true # Compute throughput and photmetric quantities call smark (sp) call salloc (wave, nwave, TY_REAL) call salloc (filt, nwave, TY_REAL) call salloc (filterr, nwave, TY_REAL) call getbandx (PHOTMODE(kw), grftbl, cmptbl, logspace, nwave, Memr[wave], Memr[filt], Memr[filterr]) call phopar (nwave, Memr[wave], Memr[filt], phot) # Write photmetric quantites to structure PHOTFLAM(kw) = phot[1] PHOTZPT(kw) = phot[2] PHOTPLAM(kw) = phot[3] PHOTBW(kw) = phot[4] # Write throughput to table if (grpnum == 1) { call tbcdef (thr_tp, colptr, "WAVELENGTH", " ", " ", TY_REAL, 1, 1) call tbcptr (thr_tp, colptr, Memr[wave], 1, nwave) } call sprintf (colname, SZ_COLNAME, "THROUGHPUT_%d") call pargi (grpnum) call tbcdef (thr_tp, colptr, colname, " ", " ", TY_REAL, 1, 1) call tbcptr (thr_tp, colptr, Memr[filt], 1, nwave) call sprintf (keyword, SZ_KEYWORD, "PHMODE_%d") call pargi (grpnum) call tbhadt (thr_tp, keyword, PHOTMODE(kw)) # Get history info for phot call listpath (PHOTMODE(kw), grftbl, cmptbl, phot_path, maxpath) call sfree (sp) end