aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/wphot
diff options
context:
space:
mode:
Diffstat (limited to 'noao/digiphot/apphot/wphot')
-rw-r--r--noao/digiphot/apphot/wphot/apbwphot.x108
-rw-r--r--noao/digiphot/apphot/wphot/apgmeasure.x190
-rw-r--r--noao/digiphot/apphot/wphot/apgwppars.x35
-rw-r--r--noao/digiphot/apphot/wphot/aptmeasure.x192
-rw-r--r--noao/digiphot/apphot/wphot/apwconfirm.x110
-rw-r--r--noao/digiphot/apphot/wphot/apwmag.x157
-rw-r--r--noao/digiphot/apphot/wphot/apwpars.x27
-rw-r--r--noao/digiphot/apphot/wphot/apwpcolon.x157
-rw-r--r--noao/digiphot/apphot/wphot/apwphot.x509
-rw-r--r--noao/digiphot/apphot/wphot/apwremag.x76
-rw-r--r--noao/digiphot/apphot/wphot/mkpkg38
-rw-r--r--noao/digiphot/apphot/wphot/t_wphot.x339
-rw-r--r--noao/digiphot/apphot/wphot/wphot.key109
13 files changed, 2047 insertions, 0 deletions
diff --git a/noao/digiphot/apphot/wphot/apbwphot.x b/noao/digiphot/apphot/wphot/apbwphot.x
new file mode 100644
index 00000000..b684abb7
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apbwphot.x
@@ -0,0 +1,108 @@
+include <fset.h>
+include "../lib/apphot.h"
+include "../lib/display.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+
+# AP_BWPHOT -- Procedure to compute the magnitudes for a list of objects
+# interactively.
+
+procedure ap_bwphot (ap, im, cl, sd, out, id, ld, gd, mgd, gid, interactive)
+
+pointer ap # pointer to apphot structure
+pointer im # pointer to IRAF image
+int cl # starlist file descriptor
+int sd # sky file descriptor
+int out # output file descriptor
+int id, ld # sequence and list numbers
+pointer gd # pointer to stdgraph stream
+pointer mgd # pointer to the plot metacode stream
+pointer gid # pointer to image display stream
+int interactive # interactive pr batch mode
+
+int stdin, ild, cier, sier, pier
+pointer sp, str
+real wx, wy
+int fscan(), nscan(), apfitsky(), apfitcenter(), ap_wmag(), strncmp()
+int apstati()
+real apstatr()
+
+begin
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+ call fstats (cl, F_FILENAME, Memc[str], SZ_FNAME)
+
+ # Initialize
+ ild = ld
+
+ # Print query.
+ if (strncmp ("STDIN", Memc[str], 5) == 0)
+ stdin = YES
+ else
+ stdin = NO
+ if (stdin == YES) {
+ call printf ("Type object x and y coordinates (^D or ^Z to end): ")
+ call flush (STDOUT)
+ }
+
+ # Loop over the coordinate file.
+ while (fscan (cl) != EOF) {
+
+ # Get and store the coordinates.
+ call gargr (wx)
+ call gargr (wy)
+ if (nscan () != 2) {
+ if (stdin == YES) {
+ call printf (
+ "Type object x and y coordinates (^D or ^Z to end): ")
+ call flush (STDOUT)
+ }
+ next
+ }
+
+ # Transform the input coordinates.
+ switch (apstati(ap,WCSIN)) {
+ case WCS_WORLD, WCS_PHYSICAL:
+ call ap_itol (ap, wx, wy, wx, wy, 1)
+ case WCS_TV:
+ call ap_vtol (im, wx, wy, wx, wy, 1)
+ default:
+ ;
+ }
+ call apsetr (ap, CWX, wx)
+ call apsetr (ap, CWY, wy)
+
+ # Center the coordinatess, fit the sky and compute magnitudes.
+ cier = apfitcenter (ap, im, wx, wy)
+ sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap,
+ YCENTER), sd, gd)
+ pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr(ap, YCENTER),
+ apstati (ap, POSITIVE), apstatr (ap, SKY_MODE),
+ apstatr (ap, SKY_SIGMA), apstati (ap, NSKY))
+
+ # Write the results.
+ if (interactive == YES) {
+ call ap_qpmag (ap, cier, sier, pier)
+ if (gid != NULL)
+ call apmark (ap, gid, apstati (ap, MKCENTER), apstati (ap,
+ MKSKY), apstati (ap, MKAPERT))
+ }
+ if (id == 1)
+ call ap_param (ap, out, "wphot")
+ call ap_pmag (ap, out, id, ild, cier, sier, pier)
+ call ap_pplot (ap, im, id, mgd, YES)
+
+ # Prepare for the next object.
+ id = id + 1
+ ild = ild + 1
+ call apsetr (ap, WX, wx)
+ call apsetr (ap, WY, wy)
+ if (stdin == YES) {
+ call printf (
+ "Type object x and y coordinates (^Z or ^D to end): ")
+ call flush (STDOUT)
+ }
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/wphot/apgmeasure.x b/noao/digiphot/apphot/wphot/apgmeasure.x
new file mode 100644
index 00000000..738630f2
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apgmeasure.x
@@ -0,0 +1,190 @@
+# AP_GMEASURE -- Procedure to measure the fluxes and effective areas of a set of
+# apertures assuming a Gaussian weighting function.
+
+procedure ap_gmeasure (im, wx, wy, c1, c2, l1, l2, aperts, sums, areas,
+ naperts, sigsq, gain, varsky)
+
+pointer im # pointer to image
+real wx, wy # center of subraster
+int c1, c2 # column limits
+int l1, l2 # line limits
+real aperts[ARB] # array of apertures
+double sums[ARB] # array of sums
+double areas[ARB] # aperture areas
+int naperts # number of apertures
+real sigsq # the profile widht squared
+real gain # the sky value
+real varsky # the sky variance
+
+int i, j, k, nx, yindex
+double fctn, weight, norm
+pointer sp, buf, sump, sumpw
+real xc, yc, apmaxsq, dy2, r2, r, prof, var
+pointer imgs2r()
+
+begin
+ # Initialize.
+ call smark (sp)
+ call salloc (sump, naperts, TY_DOUBLE)
+ call salloc (sumpw, naperts, TY_DOUBLE)
+ call aclrd (Memd[sump], naperts)
+ call aclrd (Memd[sumpw], naperts)
+
+ # Get array boundary parameters.
+ nx = c2 - c1 + 1
+ xc = wx - c1 + 1
+ yc = wy - l1 + 1
+ apmaxsq = (aperts[naperts] + 0.5) ** 2
+
+ # Clear out the accumulaters
+ call aclrd (sums, naperts)
+ call aclrd (areas, naperts)
+
+ # Loop over the pixels.
+ do j = l1, l2 {
+ buf = imgs2r (im, c1, c2, j, j)
+ if (buf == EOF) {
+ call sfree (sp)
+ return
+ }
+ yindex = j - l1 + 1
+ dy2 = (yindex - yc) ** 2
+ do i = 1, nx {
+ r2 = (i - xc) ** 2 + dy2
+ if (r2 > apmaxsq)
+ next
+ prof = max (exp (-r2 / sigsq), 0.0)
+ if (prof <= 0.0)
+ next
+ var = max (0.0, Memr[buf+i-1])
+ var = var / gain + varsky
+ if (var <= 0.0)
+ next
+ weight = prof / var
+ r = sqrt (r2) - 0.5
+ do k = 1, naperts {
+ if (r > aperts[k])
+ next
+ fctn = max (0.0, min (1.0, aperts[k] - r))
+ sums[k] = sums[k] + weight * fctn * Memr[buf+i-1]
+ areas[k] = areas[k] + weight * fctn
+ Memd[sump+k-1] = Memd[sump+k-1] + prof
+ Memd[sumpw+k-1] = Memd[sumpw+k-1] + weight * prof
+ }
+ }
+ }
+
+ # Normalize.
+ do k = 1, naperts {
+ if (Memd[sumpw+k-1] <= 0.0d0)
+ norm = 0.0d0
+ else
+ norm = Memd[sump+k-1] / Memd[sumpw+k-1]
+ sums[k] = sums[k] * norm
+ areas[k] = areas[k] * norm
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_BGMEASURE -- Procedure to measure the fluxes and effective areas of a set
+# of apertures assuming a Gaussian weighting function.
+
+procedure ap_bgmeasure (im, wx, wy, c1, c2, l1, l2, datamin, datamax,
+ aperts, sums, areas, naperts, minapert, sigsq, gain, varsky)
+
+pointer im # pointer to image
+real wx, wy # center of subraster
+int c1, c2 # column limits
+int l1, l2 # line limits
+real datamin # minimum good data
+real datamax # maximum good data
+real aperts[ARB] # array of apertures
+double sums[ARB] # array of sums
+double areas[ARB] # aperture areas
+int naperts # number of apertures
+int minapert # minimum aperture fo bad pixels
+real sigsq # the profile widht squared
+real gain # the image gain value
+real varsky # the sky variance
+
+int i, j, k, nx, yindex, kindex
+double fctn, weight, norm
+pointer sp, buf, sump, sumpw
+real xc, yc, apmaxsq, dy2, r2, r
+real pixval, prof, var
+pointer imgs2r()
+
+begin
+ # Initialize.
+ call smark (sp)
+ call salloc (sump, naperts, TY_DOUBLE)
+ call salloc (sumpw, naperts, TY_DOUBLE)
+ call aclrd (Memd[sump], naperts)
+ call aclrd (Memd[sumpw], naperts)
+ minapert = naperts + 1
+
+ # Get array boundary parameters.
+ nx = c2 - c1 + 1
+ xc = wx - c1 + 1
+ yc = wy - l1 + 1
+ apmaxsq = (aperts[naperts] + 0.5) ** 2
+
+ # Clear out the accumulaters
+ call aclrd (sums, naperts)
+ call aclrd (areas, naperts)
+
+ # Loop over the pixels.
+ do j = l1, l2 {
+ buf = imgs2r (im, c1, c2, j, j)
+ if (buf == EOF) {
+ call sfree (sp)
+ return
+ }
+ yindex = j - l1 + 1
+ dy2 = (yindex - yc) ** 2
+ do i = 1, nx {
+ r2 = (i - xc) ** 2 + dy2
+ if (r2 > apmaxsq)
+ next
+ prof = max (exp (-r2 / sigsq), 0.0)
+ if (prof <= 0.0)
+ next
+ pixval = Memr[buf+i-1]
+ var = max (0.0, pixval)
+ var = pixval / gain + varsky
+ if (var <= 0.0)
+ next
+ weight = prof / var
+ r = sqrt (r2) - 0.5
+ kindex = naperts + 1
+ do k = 1, naperts {
+ if (r > aperts[k])
+ next
+ kindex = min (k, kindex)
+ fctn = max (0.0, min (1.0, aperts[k] - r))
+ sums[k] = sums[k] + weight * fctn * pixval
+ areas[k] = areas[k] + weight * fctn
+ Memd[sump+k-1] = Memd[sump+k-1] + prof
+ Memd[sumpw+k-1] = Memd[sumpw+k-1] + weight * prof
+ }
+ if (kindex < minapert) {
+ if (pixval < datamin || pixval > datamax)
+ minapert = kindex
+ }
+ }
+ }
+
+ # Normalize.
+ do k = 1, naperts {
+ if (Memd[sumpw+k-1] <= 0.0d0)
+ norm = 0.0d0
+ else
+ norm = Memd[sump+k-1] / Memd[sumpw+k-1]
+ sums[k] = sums[k] * norm
+ areas[k] = areas[k] * norm
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/wphot/apgwppars.x b/noao/digiphot/apphot/wphot/apgwppars.x
new file mode 100644
index 00000000..91383169
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apgwppars.x
@@ -0,0 +1,35 @@
+include "../lib/display.h"
+include "../lib/noise.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+
+# AP_GWPPARS -- Procedure to fetch the phot task parameters.
+
+procedure ap_gwppars (ap)
+
+pointer ap # pointer to apphot structure
+
+bool clgetb()
+int btoi()
+
+begin
+ # Initialize the photometry structure.
+ call appinit (ap, AP_CENTROID1D, 2.5, AP_MODE, 10.0, 10.0, 3.0, 1,
+ AP_PWCONSTANT, 2.0, AP_NPOISSON)
+
+ # Get the data dependent parameters.
+ call ap_gdapars (ap)
+
+ # Get the centering parameters.
+ call ap_gcepars (ap)
+
+ # Get the sky fitting parameters.
+ call ap_gsapars (ap)
+
+ # Get the photometry parameters.
+ call ap_gwhpars (ap)
+
+ # Set the radplot parameters.
+ call apseti (ap, RADPLOTS, btoi (clgetb ("radplots")))
+end
diff --git a/noao/digiphot/apphot/wphot/aptmeasure.x b/noao/digiphot/apphot/wphot/aptmeasure.x
new file mode 100644
index 00000000..8ba7b650
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/aptmeasure.x
@@ -0,0 +1,192 @@
+# AP_TMEASURE -- Procedure to measure the fluxes and effective areas of a set of
+# apertures assuming a conical weighting function.
+
+procedure ap_tmeasure (im, wx, wy, c1, c2, l1, l2, aperts, sums, areas,
+ naperts, fwhmpsf, gain, varsky)
+
+pointer im # pointer to image
+real wx, wy # center of subraster
+int c1, c2 # column limits
+int l1, l2 # line limits
+real aperts[ARB] # array of apertures
+double sums[ARB] # array of sums
+double areas[ARB] # aperture areas
+int naperts # number of apertures
+real fwhmpsf # width of the profile
+real gain # the image gain
+real varsky # the sky variance
+
+int i, j, k, yindex, nx
+double fctn, weight, norm
+pointer buf, sp, sump, sumpw
+real xc, yc, apmaxsq, dy2, r2, r, pixval, prof, var
+pointer imgs2r()
+
+begin
+ # Initialize.
+ call smark (sp)
+ call salloc (sump, naperts, TY_DOUBLE)
+ call salloc (sumpw, naperts, TY_DOUBLE)
+ call aclrd (Memd[sump], naperts)
+ call aclrd (Memd[sumpw], naperts)
+
+ # Set up some array boundary parameters.
+ nx = c2 - c1 + 1
+ xc = wx - c1 + 1
+ yc = wy - l1 + 1
+ apmaxsq = (aperts[naperts] + 0.5) ** 2
+
+ # Clear out the accumulaters
+ call aclrd (sums, naperts)
+ call aclrd (areas, naperts)
+
+ # Loop over the pixels.
+ do j = l1, l2 {
+ buf = imgs2r (im, c1, c2, j, j)
+ if (buf == NULL) {
+ call sfree (sp)
+ return
+ }
+ yindex = j - l1 + 1
+ dy2 = (yindex - yc) ** 2
+ do i = 1, nx {
+ r2 = (i - xc) ** 2 + dy2
+ if (r2 > apmaxsq)
+ next
+ r = sqrt (r2)
+ prof = max (1.0 - r / fwhmpsf, 0.0)
+ if (prof <= 0.0)
+ next
+ pixval = Memr[buf+i-1]
+ var = max (0.0, pixval)
+ var = var / gain + varsky
+ if (var <= 0.0)
+ next
+ weight = prof / var
+ r = r - 0.5
+ do k = 1, naperts {
+ if (r > aperts[k])
+ next
+ fctn = max (0.0, min (1.0, aperts[k] - r))
+ Memd[sump+k-1] = Memd[sump+k-1] + prof
+ Memd[sumpw+k-1] = Memd[sumpw+k-1] + prof * weight
+ sums[k] = sums[k] + weight * fctn * pixval
+ areas[k] = areas[k] + weight * fctn
+ }
+ }
+ }
+
+ # Normalize.
+ do k = 1, naperts {
+ if (Memd[sumpw+k-1] <= 0.0d0)
+ norm = 0.0d0
+ else
+ norm = Memd[sump+k-1] / Memd[sumpw+k-1]
+ sums[k] = sums[k] * norm
+ areas[k] = areas[k] * norm
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_BTMEASURE -- Procedure to measure the fluxes and effective areas of a
+# set of apertures assuming a conical weighting function.
+
+procedure ap_btmeasure (im, wx, wy, c1, c2, l1, l2, datamin, datamax,
+ aperts, sums, areas, naperts, minapert, fwhmpsf, gain, varsky)
+
+pointer im # pointer to image
+real wx, wy # center of subraster
+int c1, c2 # column limits
+int l1, l2 # line limits
+real datamin # minimum good data value
+real datamax # maximum good data value
+real aperts[ARB] # array of apertures
+double sums[ARB] # array of sums
+double areas[ARB] # aperture areas
+int naperts # number of apertures
+int minapert # minimum aperture
+real fwhmpsf # width of the profile
+real gain # the image gain
+real varsky # the sky variance
+
+int i, j, k, yindex, kindex, nx
+double fctn, weight, norm
+pointer buf, sp, sump, sumpw
+real xc, yc, apmaxsq, dy2, r2, r, pixval, prof, var
+pointer imgs2r()
+
+begin
+ # Initialize.
+ call smark (sp)
+ call salloc (sump, naperts, TY_DOUBLE)
+ call salloc (sumpw, naperts, TY_DOUBLE)
+ call aclrd (Memd[sump], naperts)
+ call aclrd (Memd[sumpw], naperts)
+ minapert = naperts + 1
+
+ # Set up some array boundary parameters.
+ nx = c2 - c1 + 1
+ xc = wx - c1 + 1
+ yc = wy - l1 + 1
+ apmaxsq = (aperts[naperts] + 0.5) ** 2
+
+ # Clear out the accumulaters
+ call aclrd (sums, naperts)
+ call aclrd (areas, naperts)
+
+ # Loop over the pixels.
+ do j = l1, l2 {
+ buf = imgs2r (im, c1, c2, j, j)
+ if (buf == NULL) {
+ call sfree (sp)
+ return
+ }
+ yindex = j - l1 + 1
+ dy2 = (yindex - yc) ** 2
+ do i = 1, nx {
+ r2 = (i - xc) ** 2 + dy2
+ if (r2 > apmaxsq)
+ next
+ r = sqrt (r2)
+ prof = max (1.0 - r / fwhmpsf, 0.0)
+ if (prof <= 0.0)
+ next
+ pixval = Memr[buf+i-1]
+ var = max (0.0, pixval)
+ var = var / gain + varsky
+ if (var <= 0.0)
+ next
+ weight = prof / var
+ r = r - 0.5
+ kindex = naperts + 1
+ do k = 1, naperts {
+ if (r > aperts[k])
+ next
+ kindex = min (k, kindex)
+ fctn = max (0.0, min (1.0, aperts[k] - r))
+ Memd[sump+k-1] = Memd[sump+k-1] + prof
+ Memd[sumpw+k-1] = Memd[sumpw+k-1] + prof * weight
+ sums[k] = sums[k] + weight * fctn * pixval
+ areas[k] = areas[k] + weight * fctn
+ }
+ if (kindex < minapert) {
+ if (pixval < datamin || pixval > datamax)
+ minapert = kindex
+ }
+ }
+ }
+
+ # Normalize.
+ do k = 1, naperts {
+ if (Memd[sumpw+k-1] <= 0.0d0)
+ norm = 0.0d0
+ else
+ norm = Memd[sump+k-1] / Memd[sumpw+k-1]
+ sums[k] = sums[k] * norm
+ areas[k] = areas[k] * norm
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/wphot/apwconfirm.x b/noao/digiphot/apphot/wphot/apwconfirm.x
new file mode 100644
index 00000000..53222388
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apwconfirm.x
@@ -0,0 +1,110 @@
+include "../lib/apphot.h"
+include "../lib/noise.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+
+# AP_WCONFIRM -- Procedure to confirm the critical phot parameters.
+
+procedure ap_wconfirm (ap, out, stid)
+
+pointer ap # pointer to the apphot structure
+int out # pointer to the output file descriptor
+int stid # output file sequence number
+
+pointer sp, cstr, sstr, pwstr, aperts
+real fwhmpsf, capert, annulus, dannulus, skysigma
+real datamin, datamax
+int apstati()
+real apstatr(), ap_vfwhmpsf(), ap_vcapert(), ap_vsigma()
+real ap_vannulus(), ap_vdannulus(), ap_vdatamin(), ap_vdatamax()
+
+begin
+ call smark (sp)
+ call salloc (cstr, SZ_FNAME, TY_CHAR)
+ call salloc (sstr, SZ_FNAME, TY_CHAR)
+ call salloc (pwstr, SZ_FNAME, TY_CHAR)
+ call salloc (aperts, SZ_LINE, TY_CHAR)
+
+ call printf ("\n")
+
+ # Confirm the centering algorithm.
+ call ap_vcstring (ap, Memc[cstr], SZ_FNAME)
+
+ if (apstati (ap, CENTERFUNCTION) != AP_NONE) {
+
+ # Confirm the fwhmpsf.
+ if (apstati (ap, CENTERFUNCTION) != AP_CENTROID1D)
+ fwhmpsf = ap_vfwhmpsf (ap)
+ else
+ fwhmpsf = apstatr (ap, FWHMPSF)
+
+ # Confirm the centering box.
+ capert = 2.0 * ap_vcapert (ap)
+
+ } else {
+
+ fwhmpsf = apstatr (ap, FWHMPSF)
+ capert = 2.0 * apstatr (ap, CAPERT)
+ }
+
+ # Confirm the sky fitting algorithm.
+ call ap_vsstring (ap, Memc[sstr], SZ_FNAME)
+
+ if (apstati (ap, SKYFUNCTION) != AP_CONSTANT &&
+ apstati (ap, SKYFUNCTION) != AP_SKYFILE) {
+
+ # Confirm the sky annulus parameter.
+ annulus = ap_vannulus (ap)
+
+ # Confirm the width of the sky annulus.
+ dannulus = ap_vdannulus (ap)
+
+ } else {
+ annulus = apstatr (ap, ANNULUS)
+ dannulus = apstatr (ap, DANNULUS)
+ }
+
+ # Confirm the sky sigma parameter.
+ skysigma = ap_vsigma (ap)
+
+ # Confirm the weighting scheme algorithm.
+ call ap_vpwstring (ap, Memc[pwstr], SZ_FNAME)
+
+ # Confirm the aperture radii parameter.
+ call ap_vaperts (ap, Memc[aperts], SZ_LINE)
+
+ # Verify the datamin and datamax parameters.
+ datamin = ap_vdatamin (ap)
+ datamax = ap_vdatamax (ap)
+
+ call printf ("\n")
+
+ # Update the database file.
+ if (out != NULL && stid > 1) {
+ call ap_sparam (out, KY_CSTRING, Memc[cstr], UN_CALGORITHM,
+ "centering algorithm")
+ call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT,
+ "full width half maximum of the psf")
+ call ap_rparam (out, KY_CAPERT, capert, UN_CSCALEUNIT,
+ "centering box width")
+ call ap_sparam (out, KY_SSTRING, Memc[sstr], UN_SALGORITHM,
+ "sky fitting algorithm")
+ call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT,
+ "inner radius of the sky annulus")
+ call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT,
+ "width of the sky annulus")
+ call ap_rparam (out, KY_SKYSIGMA, skysigma, UN_NCOUNTS,
+ "standard deviation of 1 sky pixel")
+ call ap_sparam (out, KY_PWSTRING, Memc[pwstr], UN_PMODEL,
+ "photometric weighting function")
+ call ap_sparam (out, KY_APERTS, Memc[aperts], UN_PSCALEUNIT,
+ "list of apertures")
+ call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS,
+ "minimum good data value")
+ call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS,
+ "maximum good data value")
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/wphot/apwmag.x b/noao/digiphot/apphot/wphot/apwmag.x
new file mode 100644
index 00000000..0818bf3f
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apwmag.x
@@ -0,0 +1,157 @@
+include <mach.h>
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/noisedef.h"
+include "../lib/photdef.h"
+include "../lib/phot.h"
+
+define CONVERSION 2.772588
+
+# AP_WMAG -- Procedure to compute the magnitudes inside a set of apertures for
+# a single of object.
+
+int procedure ap_wmag (ap, im, wx, wy, positive, skyval, skysig, nsky)
+
+pointer ap # pointer to the apphot structure
+pointer im # pointer to the IRAF image
+real wx, wy # object coordinates
+int positive # emission or absorption features
+real skyval # sky value
+real skysig # sky sigma
+int nsky # number of sky pixels
+
+int c1, c2, l1, l2, ier, nap
+pointer sp, nse, phot, temp
+real datamin, datamax, zmag, wsigsq, wvarsky
+int apmagbuf()
+
+begin
+ # Initalize.
+ phot = AP_PPHOT(ap)
+ nse = AP_NOISE(ap)
+ AP_PXCUR(phot) = wx
+ AP_PYCUR(phot) = wy
+ if (IS_INDEFR(wx) || IS_INDEFR(wy)) {
+ AP_OPXCUR(phot) = INDEFR
+ AP_OPYCUR(phot) = INDEFR
+ } else {
+ switch (AP_WCSOUT(ap)) {
+ case WCS_WORLD, WCS_PHYSICAL:
+ call ap_ltoo (ap, wx, wy, AP_OPXCUR(phot), AP_OPYCUR(phot), 1)
+ case WCS_TV:
+ call ap_ltov (im, wx, wy, AP_OPXCUR(phot), AP_OPYCUR(phot), 1)
+ default:
+ AP_OPXCUR(phot) = wx
+ AP_OPYCUR(phot) = wy
+ }
+ }
+ call amovkd (0.0d0, Memd[AP_SUMS(phot)], AP_NAPERTS(phot))
+ call amovkd (0.0d0, Memd[AP_AREA(phot)], AP_NAPERTS(phot))
+ call amovkr (INDEFR, Memr[AP_MAGS(phot)], AP_NAPERTS(phot))
+ call amovkr (INDEFR, Memr[AP_MAGERRS(phot)], AP_NAPERTS(phot))
+
+ # Make sure the center is defined.
+ if (IS_INDEFR(wx) || IS_INDEFR(wy))
+ return (AP_APERT_NOAPERT)
+
+ # Fetch the aperture pixels.
+ ier = apmagbuf (ap, im, wx, wy, c1, c2, l1, l2)
+ if (ier == AP_APERT_NOAPERT)
+ return (AP_APERT_NOAPERT)
+
+ call smark (sp)
+ call salloc (temp, AP_NAPERTS(phot), TY_REAL)
+
+ # Compute the min and max.
+ if (IS_INDEFR(AP_DATAMIN(ap)))
+ datamin = -MAX_REAL
+ else
+ datamin = AP_DATAMIN(ap)
+ if (IS_INDEFR(AP_DATAMAX(ap)))
+ datamax = MAX_REAL
+ else
+ datamax = AP_DATAMAX(ap)
+
+ # Do photometry for all the apertures.
+ AP_NMINAP(phot) = AP_NMAXAP(phot) + 1
+ call amulkr (Memr[AP_APERTS(phot)], AP_SCALE(ap), Memr[temp],
+ AP_NAPERTS(phot))
+
+ switch (AP_PWEIGHTS(phot)) {
+ case AP_PWCONSTANT:
+ if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap)))
+ call apmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp],
+ Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot))
+ else
+ call apbmeasure (im, wx, wy, c1, c2, l1, l2, datamin,
+ datamax, Memr[temp], Memd[AP_SUMS(phot)],
+ Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot))
+ case AP_PWCONE:
+ wsigsq = AP_FWHMPSF(ap) * AP_SCALE(ap)
+ wvarsky = (AP_READNOISE(nse) / AP_EPADU(nse)) ** 2
+ if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap)))
+ call ap_tmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp],
+ Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot),
+ wsigsq, AP_EPADU(nse), wvarsky)
+ else
+ call ap_btmeasure (im, wx, wy, c1, c2, l1, l2, datamin,
+ datamax, Memr[temp], Memd[AP_SUMS(phot)],
+ Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot),
+ wsigsq, AP_EPADU(nse), wvarsky)
+ case AP_PWGAUSS:
+ wsigsq = (AP_FWHMPSF(ap) * AP_SCALE(ap)) ** 2 / CONVERSION
+ wvarsky = (AP_READNOISE(nse) / AP_EPADU(nse)) ** 2
+ if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap)))
+ call ap_gmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp],
+ Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot),
+ wsigsq, AP_EPADU(nse), wvarsky)
+ else
+ call ap_bgmeasure (im, wx, wy, c1, c2, l1, l2,
+ datamin, datamax, Memr[temp], Memd[AP_SUMS(phot)],
+ Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot),
+ wsigsq, AP_EPADU(nse), wvarsky)
+ default:
+ if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap)))
+ call apmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp],
+ Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot))
+ else
+ call apbmeasure (im, wx, wy, c1, c2, l1, l2, datamin,
+ datamax, Memr[temp], Memd[AP_SUMS(phot)],
+ Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot))
+ }
+
+ # Make sure that the sky value has been defined.
+ if (IS_INDEFR(skyval))
+ ier = AP_APERT_NOSKYMODE
+
+ else {
+
+ # Check for bad pixels.
+ if ((ier == AP_OK) && (AP_NMINAP(phot) <= AP_NMAXAP(phot)))
+ ier = AP_APERT_BADDATA
+
+ nap = min (AP_NMINAP(phot) - 1, AP_NMAXAP(phot))
+
+ # Compute the magnitudes and errors.
+ if (positive == YES)
+ call apcopmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)],
+ Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, skyval,
+ skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse),
+ AP_EPADU(nse))
+ else
+ call apconmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)],
+ Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, skyval,
+ skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse),
+ AP_EPADU(nse), AP_READNOISE(nse))
+
+ # Compute correction for itime.
+ zmag = 2.5 * log10 (AP_ITIME(ap))
+ call aaddkr (Memr[AP_MAGS(phot)], zmag, Memr[AP_MAGS(phot)], nap)
+ }
+
+ call sfree (sp)
+ if (ier != AP_OK)
+ return (ier)
+ else
+ return (AP_OK)
+end
diff --git a/noao/digiphot/apphot/wphot/apwpars.x b/noao/digiphot/apphot/wphot/apwpars.x
new file mode 100644
index 00000000..88406a8f
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apwpars.x
@@ -0,0 +1,27 @@
+include "../lib/display.h"
+
+# AP_WPARS -- Procedure to write out the wphot task parameters.
+
+procedure ap_wpars (ap)
+
+pointer ap # pointer to apphot structure
+
+bool itob()
+int apstati()
+
+begin
+ # Write out the data dependent parameters.
+ call ap_dapars (ap)
+
+ # Write the centering parameters.
+ call ap_cepars (ap)
+
+ # Write out the sky fitting parameters.
+ call ap_sapars (ap)
+
+ # Write out the photometry parameters.
+ call ap_phpars (ap)
+
+ # Set the radplots parameter.
+ call clputb ("radplots", itob (apstati (ap, RADPLOTS)))
+end
diff --git a/noao/digiphot/apphot/wphot/apwpcolon.x b/noao/digiphot/apphot/wphot/apwpcolon.x
new file mode 100644
index 00000000..6f6e1f5c
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apwpcolon.x
@@ -0,0 +1,157 @@
+include <gset.h>
+include "../lib/apphot.h"
+include "../lib/fitsky.h"
+include "../lib/center.h"
+include "../lib/phot.h"
+include "../lib/display.h"
+include "../lib/noise.h"
+
+# AP_WPCOLON -- Process wphot colon commands.
+
+procedure ap_wpcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage,
+ newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag)
+
+pointer ap # pointer to the apphot structure
+pointer im # pointer to the iraf image
+int cl # coord file descriptor
+int out # output file descriptor
+int stid # output file sequence number
+int ltid # coord file sequence number
+char cmdstr[ARB] # command string
+int newimage # new image ?
+int newcenterbuf, newcenter # new center buffer ? new center fit ?
+int newskybuf, newsky # new sky buffer ? new sky fit ?
+int newmagbuf, newmag # new aperture buffer ? new fit ?
+
+pointer sp, incmd, outcmd
+int strdic()
+
+begin
+ # Get the command.
+ call smark (sp)
+ call salloc (incmd, SZ_LINE, TY_CHAR)
+ call salloc (outcmd, SZ_LINE, TY_CHAR)
+
+ call sscan (cmdstr)
+ call gargwrd (Memc[incmd], SZ_LINE)
+ if (Memc[incmd] == EOS) {
+ call sfree (sp)
+ return
+ }
+
+ # Process the command.
+ if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, CCMDS) != 0)
+ call apccolon (ap, out, stid, cmdstr, newcenterbuf, newcenter)
+ else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, SCMDS) != 0)
+ call apscolon (ap, out, stid, cmdstr, newskybuf, newsky)
+ else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, PCMDS) != 0)
+ call ap_wmagcolon (ap, out, stid, cmdstr, newmagbuf, newmag)
+ else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0)
+ call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage,
+ newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag)
+ else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0)
+ call ap_nscolon (ap, im, out, stid, cmdstr, newcenterbuf,
+ newcenter, newskybuf, newsky, newmagbuf, newmag)
+ else
+ call ap_himcolon (ap, cmdstr)
+
+ call sfree (sp)
+end
+
+
+# AP_WMAGCOLON -- Procedure to display and edit the photometry parameters.
+
+procedure ap_wmagcolon (ap, out, stid, cmdstr, newmagbuf, newmag)
+
+pointer ap # pointer to apphot structure
+int out # output file descriptor
+int stid # output number
+char cmdstr[ARB] # command string
+int newmagbuf # new aperture buffers
+int newmag # compute new magnitudes
+
+bool bval
+int ncmd, stat
+pointer sp, cmd
+real rval
+bool itob()
+int btoi(), strdic(), nscan(), apstati()
+real apstatr()
+
+begin
+ # Get the command.
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ call sscan (cmdstr)
+ call gargwrd (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call sfree (sp)
+ return
+ }
+
+ # Process the command
+ ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PCMDS)
+ switch (ncmd) {
+ case PCMD_APERTURES:
+ call gargwrd (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, APERTS, Memc[cmd], SZ_LINE)
+ call printf ("%s = %s %s\n")
+ call pargstr (KY_APERTS)
+ call pargstr (Memc[cmd])
+ call pargstr (UN_PSCALEUNIT)
+ } else {
+ call apsets (ap, APERTS, Memc[cmd])
+ if (stid > 1)
+ call ap_sparam (out, KY_APERTS, Memc[cmd], UN_PSCALEUNIT,
+ "list of aperture radii")
+ newmag = YES
+ newmagbuf = YES
+ }
+ case PCMD_ZMAG:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g\n")
+ call pargstr (KY_ZMAG)
+ call pargr (apstatr (ap, ZMAG))
+ } else {
+ call apsetr (ap, ZMAG, rval)
+ if (stid > 1)
+ call ap_rparam (out, KY_ZMAG, rval, UN_PZMAG,
+ "zero point of magnitude scale")
+ newmag = YES
+ }
+ case PCMD_MKAPERT:
+ call gargb (bval)
+ if (nscan () == 1) {
+ call printf ("%s = %b\n")
+ call pargstr (KY_MKAPERT)
+ call pargb (itob (apstati (ap, MKAPERT)))
+ } else {
+ call apseti (ap, MKAPERT, btoi (bval))
+ }
+ case PCMD_WEIGHTING:
+ call gargwrd (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, PWSTRING, Memc[cmd], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_PWSTRING)
+ call pargstr (Memc[cmd])
+ } else {
+ stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PWFUNCS)
+ if (stat > 0) {
+ call apseti (ap, PWEIGHTS, stat)
+ call apsets (ap, PWSTRING, Memc[cmd])
+ if (stid > 1)
+ call ap_sparam (out, KY_PWSTRING, Memc[cmd],
+ UN_PMODEL, "photometric weighting model")
+ newmagbuf = YES
+ newmag = YES
+ }
+ }
+ default:
+ call printf ("Unknown or ambiguous colon command\7\n")
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/wphot/apwphot.x b/noao/digiphot/apphot/wphot/apwphot.x
new file mode 100644
index 00000000..07849c0e
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apwphot.x
@@ -0,0 +1,509 @@
+include <ctype.h>
+include <gset.h>
+include <imhdr.h>
+include "../lib/phot.h"
+include "../lib/apphot.h"
+include "../lib/display.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+
+define HELPFILE "apphot$wphot/wphot.key"
+
+# APWPHOT -- Procedure to compute magnitudes for a list of objects
+
+int procedure ap_wphot (ap, im, cl, sd, gd, mgd, id, out, stid, interactive,
+ cache)
+
+pointer ap # pointer to apphot structure
+pointer im # pointer to IRAF image
+int cl # starlist file descriptor
+int sd # the sky file descriptor
+pointer gd # pointer to graphcis descriptor
+pointer mgd # pointer to graphics metacode file
+pointer id # pointer to image display stream
+int out # output file descriptor
+int stid # output file sequence number
+int interactive # interactive mode
+int cache # cache the input image pixels
+
+real wx, wy, xlist, ylist
+pointer sp, cmd
+int wcs, key, ltid, newlist, req_size, old_size, buf_size, memstat
+int newimage, newskybuf, newsky, newcenterbuf, newcenter, newmagbuf, newmag
+int colonkey, prev_num, req_num, ip, oid
+int cier, sier, pier
+
+real apstatr()
+int clgcur(), apfitsky(), aprefitsky(), apfitcenter(), aprefitcenter()
+int ap_wmag(), ap_wremag(), apgscur(), ctoi(), apstati(), apgqverify()
+int apgtverify(), apnew(), ap_avsky(), ap_memstat(), sizeof()
+bool fp_equalr()
+
+define endswitch_ 99
+
+begin
+ # Initialize.
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+
+ # Initialize the cursor command.
+ key = ' '
+ Memc[cmd] = EOS
+
+ # Initialize the fitting parameters.
+ newimage = NO
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newmagbuf = YES; newmag = YES
+ cier = AP_OK; sier = AP_OK; pier = AP_OK
+
+ # Initialize the sequence numbering.
+ newlist = NO
+ ltid = 0
+
+ # Loop over the coordinate file.
+ while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) !=
+ EOF) {
+
+ # Store the current cursor coordinates.
+ call ap_vtol (im, wx, wy, wx, wy, 1)
+ call apsetr (ap, CWX, wx)
+ call apsetr (ap, CWY, wy)
+
+ # Test to see if the cursor moved.
+ if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) {
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newmagbuf = YES; newmag = YES
+ }
+
+ # Store previous cursor coordinates.
+ call apsetr (ap, WX, apstatr (ap, CWX))
+ call apsetr (ap, WY, apstatr (ap, CWY))
+
+ # Loop over the colon keystroke commands.
+ switch (key) {
+
+ # Quit.
+ case 'q':
+ if (interactive == YES) {
+ if (apgqverify ("wphot", ap, key) == YES) {
+ call sfree (sp)
+ return (apgtverify (key))
+ }
+ } else {
+ call sfree (sp)
+ return (NO)
+ }
+
+ # Print out error messages.
+ case 'e':
+ if (interactive == YES)
+ call ap_perrors (ap, cier, sier, pier)
+
+ # Print out the help page(s).
+ case '?':
+ if ((id != NULL) && (id == gd))
+ call gpagefile (id, HELPFILE, "")
+ else if (interactive == YES)
+ call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]")
+
+ # Rewind the list.
+ case 'r':
+ if (cl != NULL) {
+ call seek (cl, BOFL)
+ ltid = 0
+ } else if (interactive == YES)
+ call printf ("No coordinate list\n")
+
+ # Get, measure next object from the list.
+ case 'm', 'n':
+
+ # No coordinate file.
+ if (cl == NULL) {
+ if (interactive == YES)
+ call printf ("No coordinate list\n")
+ goto endswitch_
+
+ }
+
+ # Need to rewind coordinate list.
+ prev_num = ltid
+ req_num = ltid + 1
+ if (apgscur (cl, id, xlist, ylist, prev_num, req_num,
+ ltid) == EOF) {
+ if (interactive == YES)
+ call printf (
+ "End of coordinate list, use r key to rewind\n")
+ goto endswitch_
+ }
+
+ # Convert coordinates if necessary.
+ switch (apstati (ap, WCSIN)) {
+ case WCS_PHYSICAL, WCS_WORLD:
+ call ap_itol (ap, xlist, ylist, xlist, ylist, 1)
+ case WCS_TV:
+ call ap_vtol (im, xlist, ylist, xlist, ylist, 1)
+ default:
+ ;
+ }
+
+ # Move to next object.
+ newlist = YES
+ if (key == 'm') {
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newmagbuf = YES; newmag = YES
+ goto endswitch_
+ }
+
+ # Measure the object.
+ cier = apfitcenter (ap, im, xlist, ylist)
+ sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap,
+ YCENTER), sd, gd)
+ pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr (ap,
+ YCENTER), apstati (ap, POSITIVE), apstatr (ap, SKY_MODE),
+ apstatr (ap, SKY_SIGMA), apstati (ap, NSKY))
+ if (id != NULL) {
+ call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap,
+ MKSKY), apstati (ap, MKAPERT))
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS))
+ if (interactive == YES)
+ call ap_qpmag (ap, cier, sier, pier)
+ if (stid == 1)
+ call ap_param (ap, out, "wphot")
+ call ap_pmag (ap, out, stid, ltid, cier, sier, pier)
+ call ap_pplot (ap, im, stid, mgd, YES)
+ stid = stid + 1
+ newcenterbuf = NO; newcenter = NO
+ newskybuf = NO; newsky = NO
+ newmagbuf = NO; newmag = NO
+
+ # Process the remainder of the list.
+ case 'l':
+ if (cl != NULL) {
+ oid = stid
+ ltid = ltid + 1
+ call ap_bwphot (ap, im, cl, sd, out, stid, ltid, gd, mgd,
+ id, YES)
+ ltid = ltid + stid - oid + 1
+ if (id != NULL) {
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ } else if (interactive == YES)
+ call printf ("No coordinate list\n")
+
+ # Process apphot colon commands.
+ case ':':
+ for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1)
+ ;
+ colonkey = Memc[cmd+ip-1]
+ switch (colonkey) {
+ case 'm', 'n':
+
+ # Show/set a wphot parameter.
+ if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') {
+ call ap_wpcolon (ap, im, cl, out, stid, ltid, Memc[cmd],
+ newimage, newcenterbuf, newcenter, newskybuf,
+ newsky, newmagbuf, newmag)
+ goto endswitch_
+ }
+
+ # No coordinate list.
+ if (cl == NULL) {
+ if (interactive == YES)
+ call printf ("No coordinate list\n")
+ goto endswitch_
+
+ }
+
+ # Get next object from list.
+ ip = ip + 1
+ prev_num = ltid
+ if (ctoi (Memc[cmd], ip, req_num) <= 0)
+ req_num = ltid + 1
+
+ # Fetch the next object from the list.
+ if (apgscur (cl, id, xlist, ylist, prev_num, req_num,
+ ltid) == EOF) {
+ if (interactive == YES)
+ call printf (
+ "End of coordinate list, use r key to rewind\n")
+ goto endswitch_
+
+ }
+
+ # Convert the coordinates.
+ switch (apstati (ap, WCSIN)) {
+ case WCS_PHYSICAL, WCS_WORLD:
+ call ap_itol (ap, xlist, ylist, xlist, ylist, 1)
+ case WCS_TV:
+ call ap_vtol (im, xlist, ylist, xlist, ylist, 1)
+ default:
+ ;
+ }
+
+ # Move to the next object.
+ newlist = YES
+ if (colonkey == 'm') {
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newmagbuf = YES; newmag = YES
+ goto endswitch_
+ }
+
+ # Measure the next object.
+ cier = apfitcenter (ap, im, xlist, ylist)
+ sier = apfitsky (ap, im, apstatr (ap, XCENTER),
+ apstatr (ap, YCENTER), sd, gd)
+ pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr (ap,
+ YCENTER), apstati (ap, POSITIVE), apstatr (ap,
+ SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY))
+ if (id != NULL) {
+ call apmark (ap, id, apstati (ap, MKCENTER),
+ apstati (ap, MKSKY), apstati (ap, MKAPERT))
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS))
+ if (interactive == YES)
+ call ap_qpmag (ap, cier, sier, pier)
+ if (stid == 1)
+ call ap_param (ap, out, "wphot")
+ call ap_pmag (ap, out, stid, ltid, cier, sier, pier)
+ call ap_pplot (ap, im, stid, mgd, YES)
+ stid = stid + 1
+ newcenterbuf = NO; newcenter = NO
+ newskybuf = NO; newsky = NO
+ newmagbuf = NO; newmag = NO
+
+ # Show/set a phot parameter.
+ default:
+ call ap_wpcolon (ap, im, cl, out, stid, ltid, Memc[cmd],
+ newimage, newcenterbuf, newcenter, newskybuf, newsky,
+ newmagbuf, newmag)
+ }
+
+ # Reestablish the image viewport and window.
+ if (newimage == YES) {
+ if ((id != NULL) && (id != gd))
+ call ap_gswv (id, Memc[cmd], im, 4)
+ req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) *
+ sizeof (IM_PIXTYPE(im))
+ memstat = ap_memstat (cache, req_size, old_size)
+ if (memstat == YES)
+ call ap_pcache (im, INDEFI, buf_size)
+ }
+
+ newimage = NO
+
+ # Save the current parameters in the pset files.
+ case 'w':
+ call ap_wpars (ap)
+
+ # Plot centered radial profile.
+ case 'd':
+ if (interactive == YES) {
+ call ap_qrad (ap, im, wx, wy, gd)
+ newmagbuf = YES; newmag = YES
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ }
+
+ # Setup phot parameters interactively.
+ case 'i':
+ if (interactive == YES) {
+ call ap_radsetup (ap, im, wx, wy, gd, out, stid)
+ newmagbuf = YES; newmag = YES
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ }
+
+ # Verify critical parameters.
+ case 'v':
+ call ap_wconfirm (ap, out, stid)
+ newmagbuf = YES; newmag = YES
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+
+ # Fit the center around the cursor position.
+ case 'c':
+ if (newcenterbuf == YES)
+ cier = apfitcenter (ap, im, wx, wy)
+ else if (newcenter == YES)
+ cier = aprefitcenter (ap, im, cier)
+ if (id != NULL) {
+ call apmark (ap, id, apstati (ap, MKCENTER), NO, NO)
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS))
+ if (interactive == YES)
+ call ap_qcenter (ap, cier)
+ newcenterbuf = NO; newcenter = NO
+
+ # Fit the sky around the cursor position.
+ case 't':
+ if (newskybuf == YES || ! fp_equalr (wx,
+ apstatr (ap, SXCUR)) || ! fp_equalr (wy, apstatr (ap,
+ SYCUR)))
+ sier = apfitsky (ap, im, wx, wy, sd, gd)
+ else if (newsky == YES)
+ sier = aprefitsky (ap, im, gd)
+ if (id != NULL) {
+ call apmark (ap, id, NO, apstati (ap, MKSKY), NO)
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS))
+ if (interactive == YES)
+ call ap_qspsky (ap, sier)
+ newskybuf = NO; newsky = NO
+
+ # Compute the average of several sky measurements around
+ # different cursor postions.
+ case 'a':
+ sier = ap_avsky (ap, im, stid, sd, id, gd, interactive)
+ if (interactive == YES)
+ call ap_qaspsky (ap, sier)
+ newskybuf = NO; newsky = NO
+
+ # Fit the sky around the current center position.
+ case 's':
+ if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER),
+ apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, SYCUR),
+ apstatr (ap, YCENTER)))
+ sier = apfitsky (ap, im, apstatr (ap, XCENTER),
+ apstatr (ap, YCENTER), sd, gd)
+ else if (newsky == YES)
+ sier = aprefitsky (ap, im, gd)
+ if (id != NULL) {
+ call apmark (ap, id, NO, apstati (ap, MKSKY), NO)
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS))
+ if (interactive == YES)
+ call ap_qspsky (ap, sier)
+ newskybuf = NO; newsky = NO
+
+ # Compute magnitudes around the cursor position using the current
+ # sky.
+ case 'p':
+ if (newcenterbuf == YES)
+ cier = apfitcenter (ap, im, wx, wy)
+ else if (newcenter == YES)
+ cier = aprefitcenter (ap, im, cier)
+ if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER),
+ apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap,
+ PYCUR), apstatr (ap, YCENTER)))
+ pier = ap_wmag (ap, im, apstatr (ap, XCENTER),
+ apstatr (ap, YCENTER), apstati (ap, POSITIVE),
+ apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA),
+ apstati (ap, NSKY))
+ else
+ pier = ap_wremag (ap, im, apstati (ap, POSITIVE),
+ apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA),
+ apstati (ap, NSKY))
+ if (id != NULL) {
+ call apmark (ap, id, NO, NO, apstati (ap, MKAPERT))
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ if (interactive == YES)
+ call ap_qpmag (ap, cier, sier, pier)
+ newcenterbuf = NO; newcenter = NO
+ newmagbuf = NO; newmag = NO
+ if (key == 'o') {
+ if (stid == 1)
+ call ap_param (ap, out, "wphot")
+ if (newlist == YES)
+ call ap_pmag (ap, out, stid, ltid, cier, sier, pier)
+ else
+ call ap_pmag (ap, out, stid, 0, cier, sier, pier)
+ call ap_pplot (ap, im, stid, mgd, YES)
+ stid = stid + 1
+ }
+
+ # Compute the center, sky, and magnitudes and save the results.
+ case 'f', ' ':
+ if (newcenterbuf == YES)
+ cier = apfitcenter (ap, im, wx, wy)
+ else if (newcenter == YES)
+ cier = aprefitcenter (ap, im, cier)
+ if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER),
+ apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, YCENTER),
+ apstatr (ap, SYCUR)))
+ sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap,
+ YCENTER), sd, gd)
+ else if (newsky == YES)
+ sier = aprefitsky (ap, im, gd)
+ if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER),
+ apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap, YCENTER),
+ apstatr (ap, PYCUR)))
+ pier = ap_wmag (ap, im, apstatr (ap, XCENTER),
+ apstatr (ap, YCENTER), apstati (ap, POSITIVE),
+ apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA),
+ apstati (ap, NSKY))
+ else
+ pier = ap_wremag (ap, im, apstati (ap, POSITIVE),
+ apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA),
+ apstati (ap, NSKY))
+
+ if (id != NULL) {
+ call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap,
+ MKSKY), apstati (ap, MKAPERT))
+ if (id == gd)
+ call gflush (id)
+ else
+ call gframe (id)
+ }
+ call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS))
+ if (interactive == YES)
+ call ap_qpmag (ap, cier, sier, pier)
+
+ newcenterbuf = NO; newcenter = NO
+ newskybuf = NO; newsky = NO
+ newmagbuf = NO; newmag = NO
+
+ if (key == ' ') {
+ if (stid == 1)
+ call ap_param (ap, out, "wphot")
+ if (newlist == YES)
+ call ap_pmag (ap, out, stid, ltid, cier, sier, pier)
+ else
+ call ap_pmag (ap, out, stid, 0, cier, sier, pier)
+ call ap_pplot (ap, im, stid, mgd, YES)
+ stid = stid + 1
+ }
+
+ default:
+ call printf ("Unknown or ambiguous keystroke command\n")
+ }
+
+endswitch_
+ # Setup for the next object.
+ key = ' '
+ Memc[cmd] = EOS
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/wphot/apwremag.x b/noao/digiphot/apphot/wphot/apwremag.x
new file mode 100644
index 00000000..5f611ec8
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/apwremag.x
@@ -0,0 +1,76 @@
+include <mach.h>
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/noisedef.h"
+include "../lib/photdef.h"
+include "../lib/phot.h"
+
+# AP_WREMAG -- Procedure to recompute the magnitudes inside a set of apertures
+# given that the sums and effective areas have already been computed.
+
+int procedure ap_wremag (ap, im, positive, skyval, skysig, nsky)
+
+pointer ap # pointer to the apphot structure
+pointer im # the input image descriptor
+int positive # emission or absorption features
+real skyval # sky value
+real skysig # sigma of sky
+int nsky # number of sky pixels
+
+int nap
+pointer nse, phot
+real zmag
+
+begin
+ # Initalize.
+ phot = AP_PPHOT(ap)
+ nse = AP_NOISE(ap)
+ call amovkr (INDEFR, Memr[AP_MAGS(phot)], AP_NAPERTS(phot))
+ call amovkr (INDEFR, Memr[AP_MAGERRS(phot)], AP_NAPERTS(phot))
+ if (IS_INDEFR(AP_PXCUR(phot)) || IS_INDEFR(AP_PYCUR(phot))) {
+ AP_OPXCUR(phot) = AP_PXCUR(phot)
+ AP_OPYCUR(phot) = AP_PYCUR(phot)
+ } else {
+ switch (AP_WCSOUT(ap)) {
+ case WCS_WORLD, WCS_PHYSICAL:
+ call ap_ltoo (ap, AP_PXCUR(phot), AP_PYCUR(phot),
+ AP_OPXCUR(phot), AP_OPYCUR(phot), 1)
+ case WCS_TV:
+ call ap_ltov (im, AP_PXCUR(phot), AP_PYCUR(phot),
+ AP_OPXCUR(phot), AP_OPYCUR(phot), 1)
+ default:
+ AP_OPXCUR(phot) = AP_PXCUR(phot)
+ AP_OPYCUR(phot) = AP_PYCUR(phot)
+ }
+ }
+
+ if (IS_INDEFR(AP_PXCUR(phot)) || IS_INDEFR(AP_PYCUR(phot)))
+ return (AP_APERT_NOAPERT)
+ if (IS_INDEFR(skyval))
+ return (AP_APERT_NOSKYMODE)
+
+ nap = min (AP_NMINAP(phot) - 1, AP_NMAXAP(phot))
+
+ # Compute the magnitudes and errors.
+ if (positive == YES)
+ call apcopmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)],
+ Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap,
+ skyval, skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse),
+ AP_EPADU(nse))
+ else
+ call apconmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)],
+ Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap,
+ skyval, skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse),
+ AP_EPADU(nse), AP_READNOISE(nse))
+
+ # Correct for itime.
+ zmag = 2.5 * log10 (AP_ITIME(ap))
+ call aaddkr (Memr[AP_MAGS(phot)], zmag, Memr[AP_MAGS(phot)], nap)
+
+ if (AP_NMINAP(phot) <= AP_NMAXAP(phot))
+ return (AP_APERT_BADDATA)
+ else if (AP_NMAXAP(phot) < AP_NAPERTS(phot))
+ return (AP_APERT_OUTOFBOUNDS)
+ else
+ return (AP_OK)
+end
diff --git a/noao/digiphot/apphot/wphot/mkpkg b/noao/digiphot/apphot/wphot/mkpkg
new file mode 100644
index 00000000..ac69a00d
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/mkpkg
@@ -0,0 +1,38 @@
+# WPHOT task
+
+$checkout libpkg.a ".."
+$update libpkg.a
+$checkin libpkg.a ".."
+$exit
+
+libpkg.a:
+ apbwphot.x <fset.h> ../lib/apphot.h \
+ ../lib/center.h ../lib/display.h \
+ ../lib/fitsky.h
+ apgwppars.x ../lib/center.h ../lib/fitsky.h \
+ ../lib/phot.h ../lib/display.h \
+ ../lib/noise.h
+ apwconfirm.x ../lib/apphot.h ../lib/noise.h \
+ ../lib/center.h ../lib/fitsky.h \
+ ../lib/phot.h
+ apwmag.x <mach.h> ../lib/apphotdef.h \
+ ../lib/noisedef.h ../lib/photdef.h \
+ ../lib/apphot.h ../lib/phot.h
+ apgmeasure.x
+ aptmeasure.x
+ apwpars.x ../lib/display.h
+ apwphot.x <ctype.h> <gset.h> \
+ ../lib/apphot.h ../lib/display.h \
+ ../lib/center.h ../lib/fitsky.h \
+ ../lib/phot.h <imhdr.h>
+ apwpcolon.x ../lib/noise.h ../lib/apphot.h \
+ ../lib/display.h ../lib/fitsky.h \
+ ../lib/center.h ../lib/phot.h \
+ <gset.h>
+ apwremag.x <mach.h> ../lib/apphotdef.h \
+ ../lib/noisedef.h ../lib/photdef.h \
+ ../lib/apphot.h ../lib/phot.h
+ t_wphot.x <fset.h> <gset.h> \
+ <lexnum.h> ../lib/apphot.h \
+ ../lib/fitsky.h <imhdr.h>
+ ;
diff --git a/noao/digiphot/apphot/wphot/t_wphot.x b/noao/digiphot/apphot/wphot/t_wphot.x
new file mode 100644
index 00000000..14a82a3e
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/t_wphot.x
@@ -0,0 +1,339 @@
+include <fset.h>
+include <gset.h>
+include <lexnum.h>
+include <imhdr.h>
+include "../lib/apphot.h"
+include "../lib/fitsky.h"
+
+# T_WPHOT -- Procedure to measure magnitudes inside a set of apertures for a
+# list of stars in a list of images.
+
+procedure t_wphot ()
+
+pointer image # pointer to name of the image
+pointer output # pointer to output file name
+pointer coords # pointer to name of coords file
+pointer skyfile # pointer to name of file with sky values
+pointer plotfile # pointer to name of plot metacode file
+pointer graphics # pointer to graphics display device
+pointer display # pointer to display device
+int interactive # mode of use
+int cache # cache the input image pixels
+int verify # verify critical parameters
+int update # update the critical parameters
+int verbose # print messages in verbose mode
+
+pointer sp, outfname, cname, ap, im, gd, mgd, id, str
+int limlist, lclist, lolist, lslist, sid, lid, sd, out, cl, root, stat, pfd
+int imlist, clist, olist, slist, wcs, memstat, req_size, old_size, buf_size
+
+pointer immap(), gopen()
+int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), apstati(), clgwrd()
+int strncmp(), strlen(), fnldir(), ap_wphot(), imtopenp(), clpopnu(), open()
+int ap_memstat(), sizeof()
+bool clgetb(), streq()
+errchk gopen
+
+begin
+ # Allocate temporary space.
+ call smark (sp)
+ call salloc (image, SZ_FNAME, TY_CHAR)
+ call salloc (output, SZ_FNAME, TY_CHAR)
+ call salloc (coords, SZ_FNAME, TY_CHAR)
+ call salloc (skyfile, SZ_FNAME, TY_CHAR)
+ call salloc (plotfile, SZ_FNAME, TY_CHAR)
+ call salloc (graphics, SZ_FNAME, TY_CHAR)
+ call salloc (display, SZ_FNAME, TY_CHAR)
+ call salloc (outfname, SZ_FNAME, TY_CHAR)
+ call salloc (cname, SZ_FNAME, TY_CHAR)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Set the standard output to flush on newline.
+ call fseti (STDOUT, F_FLUSHNL, YES)
+
+ # Get the task parameters.
+ imlist = imtopenp ("image")
+ limlist = imtlen (imlist)
+ clist = clpopnu ("coords")
+ lclist = clplen (clist)
+ olist = clpopnu ("output")
+ lolist = clplen (olist)
+
+ # Check that image and coordinate list lengths match.
+ if (limlist < 1 || (lclist > 1 && lclist != limlist)) {
+ call imtclose (imlist)
+ call clpcls (clist)
+ call clpcls (olist)
+ call error (0, "Imcompatible image and coordinate list lengths")
+ }
+
+ # Check that image and output list lengths match.
+ if (lolist > 1 && lolist != limlist) {
+ call imtclose (imlist)
+ call clpcls (clist)
+ call clpcls (olist)
+ call error (0, "Imcompatible image and output list lengths")
+ }
+
+ call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME)
+ if (Memc[cname] != EOS)
+ interactive = NO
+ #else if (lclist == 0)
+ #interactive = YES
+ else
+ interactive = btoi (clgetb ("interactive"))
+ cache = btoi (clgetb ("cache"))
+ verify = btoi (clgetb ("verify"))
+ update = btoi (clgetb ("update"))
+ verbose = btoi (clgetb ("verbose"))
+
+ # Intialize the phot structure.
+ call ap_gwppars (ap)
+
+ # Confirm the algorithm parameters.
+ if (verify == YES && interactive == NO) {
+ call ap_wconfirm (ap, NULL, 1)
+ if (update == YES)
+ call ap_wpars (ap)
+ }
+
+ # Get the wcs information.
+ wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR)
+ if (wcs <= 0) {
+ call eprintf (
+ "Warning: Setting the input coordinate system to logical\n")
+ wcs = WCS_LOGICAL
+ }
+ call apseti (ap, WCSIN, wcs)
+ wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR)
+ if (wcs <= 0) {
+ call eprintf (
+ "Warning: Setting the output coordinate system to logical\n")
+ wcs = WCS_LOGICAL
+ }
+ call apseti (ap, WCSOUT, wcs)
+
+ # Get the graphics and display devices.
+ call clgstr ("graphics", Memc[graphics], SZ_FNAME)
+ call clgstr ("display", Memc[display], SZ_FNAME)
+
+ # Open the plot files.
+ if (interactive == YES) {
+ if (Memc[graphics] == EOS)
+ gd = NULL
+ else {
+ iferr {
+ gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH)
+ } then {
+ call eprintf (
+ "Warning: Error opening graphics device.\n")
+ gd = NULL
+ }
+ }
+ if (Memc[display] == EOS)
+ id = NULL
+ else if (streq (Memc[graphics], Memc[display]))
+ id = gd
+ else {
+ iferr {
+ id = gopen (Memc[display], APPEND, STDIMAGE)
+ } then {
+ call eprintf (
+ "Warning: Graphics overlay not available for display device.\n")
+ id = NULL
+ }
+ }
+ } else {
+ gd = NULL
+ id = NULL
+ }
+
+ # Open the plot metacode file.
+ call clgstr ("plotfile", Memc[plotfile], SZ_FNAME)
+ if (Memc[plotfile] == EOS)
+ pfd = NULL
+ else
+ pfd = open (Memc[plotfile], APPEND, BINARY_FILE)
+ if (pfd != NULL)
+ mgd = gopen (Memc[graphics], NEW_FILE, pfd)
+ else
+ mgd = NULL
+
+ # Get the file name for the sky values.
+ if (apstati (ap, SKYFUNCTION) == AP_SKYFILE) {
+ slist = clpopnu ("skyfile")
+ lslist = clplen (slist)
+ if (limlist < 1 || (lslist > 1 && lslist != limlist)) {
+ call imtclose (imlist)
+ call clpcls (clist)
+ call clpcls (olist)
+ call clpcls (slist)
+ call error (0, "Imcompatible image and sky file list lengths")
+ }
+ } else
+ sd = NULL
+
+ # Begin looping over the image list.
+ sid = 1
+ while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) {
+
+ # Open the image and store image parameters.
+ im = immap (Memc[image], READ_ONLY, 0)
+ call apimkeys (ap, im, Memc[image])
+
+ # Set the image display viewport.
+ if ((id != NULL) && (id != gd))
+ call ap_gswv (id, Memc[image], im, 4)
+
+ # Cache the input image pixels.
+ req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) *
+ sizeof (IM_PIXTYPE(im))
+ memstat = ap_memstat (cache, req_size, old_size)
+ if (memstat == YES)
+ call ap_pcache (im, INDEFI, buf_size)
+
+ # Open the coordinate file, where coords is assumed to be a simple
+ # text file in which the x and y positions are in columns 1 and 2
+ # respectively and all remaining fields are ignored.
+
+ if (lclist <= 0) {
+ cl = NULL
+ call strcpy ("", Memc[outfname], SZ_FNAME)
+ } else {
+ stat = clgfil (clist, Memc[coords], SZ_FNAME)
+ root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME)
+ if (strncmp ("default", Memc[coords+root], 7) == 0 || root ==
+ strlen (Memc[coords])) {
+ call ap_inname (Memc[image], Memc[outfname], "coo",
+ Memc[outfname], SZ_FNAME)
+ lclist = limlist
+ cl = open (Memc[outfname], READ_ONLY, TEXT_FILE)
+ } else if (stat != EOF) {
+ call strcpy (Memc[coords], Memc[outfname], SZ_FNAME)
+ cl = open (Memc[outfname], READ_ONLY, TEXT_FILE)
+ } else {
+ call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME)
+ call seek (cl, BOF)
+ }
+ }
+ call apsets (ap, CLNAME, Memc[outfname])
+ call apfroot (Memc[outfname], Memc[str], SZ_LINE)
+ call apsets (ap, CLROOT, Memc[str])
+
+ # Open the skys file.
+ if (lslist <= 0) {
+ sd = NULL
+ call strcpy ("", Memc[skyfile], SZ_FNAME)
+ } else if (clgfil (slist, Memc[skyfile], SZ_FNAME) != EOF)
+ sd = open (Memc[skyfile], READ_ONLY, TEXT_FILE)
+ else
+ call seek (sd, BOF)
+ #call apsets (ap, SKYNAME, Memc[skyfile])
+
+ # Open the output text file, if output is "default", dir$default
+ # or a directory specification then the extension "mag" is added
+ # to the image name and a suitable version number is appended to
+ # the output name. If the output name is null then no output
+ # file is created.
+
+ if (lolist == 0) {
+ out = NULL
+ call strcpy ("", Memc[outfname], SZ_FNAME)
+ } else {
+ stat = clgfil (olist, Memc[output], SZ_FNAME)
+ root = fnldir (Memc[output], Memc[outfname], SZ_FNAME)
+ if (strncmp ("default", Memc[output+root], 7) == 0 || root ==
+ strlen (Memc[output])) {
+ call apoutname (Memc[image], Memc[outfname], "omag",
+ Memc[outfname], SZ_FNAME)
+ out = open (Memc[outfname], NEW_FILE, TEXT_FILE)
+ lolist = limlist
+ } else if (stat != EOF) {
+ call strcpy (Memc[output], Memc[outfname], SZ_FNAME)
+ out = open (Memc[outfname], NEW_FILE, TEXT_FILE)
+ } else
+ call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME)
+ }
+ call apsets (ap, OUTNAME, Memc[outfname])
+
+ # Do aperture photometry.
+ if (interactive == NO) {
+ if (Memc[cname] != EOS)
+ stat = ap_wphot (ap, im, cl, sd, NULL, mgd, NULL, out,
+ sid, NO, cache)
+ else if (cl != NULL) {
+ lid = 1
+ call ap_bwphot (ap, im, cl, sd, out, sid, lid, gd, mgd, id,
+ verbose)
+ stat = NO
+ } else
+ stat = NO
+ } else
+ stat = ap_wphot (ap, im, cl, sd, gd, mgd, id, out, sid, YES,
+ cache)
+
+ # Cleanup.
+ call imunmap (im)
+ if (cl != NULL) {
+ if (lclist > 1)
+ call close (cl)
+ }
+ if (sd != NULL) {
+ if (lslist > 1)
+ call close (sd)
+ }
+ if (out != NULL && lolist != 1) {
+ call close (out)
+ if (sid <= 1) {
+ call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME)
+ call delete (Memc[outfname])
+ }
+ sid = 1
+ }
+
+ # Uncache memory.
+ call fixmem (old_size)
+
+ if (stat == YES)
+ break
+ }
+
+
+ # Close the coordinate, sky and output files.
+ if (cl != NULL && lclist == 1)
+ call close (cl)
+ if (sd != NULL && lslist == 1)
+ call close (sd)
+ if (out != NULL && lolist == 1) {
+ call close (out)
+ if (sid <= 1) {
+ call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME)
+ call delete (Memc[outfname])
+ }
+ }
+
+ # Close up plot files
+ if (id == gd && id != NULL)
+ call gclose (id)
+ else {
+ if (gd != NULL)
+ call gclose (gd)
+ if (id != NULL)
+ call gclose (id)
+ }
+ if (mgd != NULL)
+ call gclose (mgd)
+ if (pfd != NULL)
+ call close (pfd)
+
+ # Free the photometry structures.
+ call appfree (ap)
+
+ # Close the coord, sky and image lists.
+ call imtclose (imlist)
+ call clpcls (clist)
+ if (sd != NULL)
+ call clpcls (slist)
+ call clpcls (olist)
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/wphot/wphot.key b/noao/digiphot/apphot/wphot/wphot.key
new file mode 100644
index 00000000..808bf923
--- /dev/null
+++ b/noao/digiphot/apphot/wphot/wphot.key
@@ -0,0 +1,109 @@
+ Interactive Photometry Commands
+
+? Print help
+: Colon commands
+v Verify the critical parameters
+w Store the current parameters
+d Plot radial profile of current star
+i Interactively set parameters using current star
+c Fit center of current star
+t Fit sky around cursor
+a Average sky values fit around several cursor positions
+s Fit sky around the current star
+p Do photometry for current star, using current sky
+o Do photometry for current star, using current sky, output results
+f Do photometry for current star
+spbar Do photometry for current star, output results
+m Move to next star in coordinate list
+n Do photometry for next star in coordinate list, output results
+l Do photometry for remaining stars in coordinate list, output results
+r Rewind the coordinate list
+e Print error messages
+q Exit task
+
+
+ Colon Commands
+
+:show [data/center/sky/fit] Show parameters
+:m [n] Move to next [nth] star in the coordinate list
+:n [n] Do photometry for next [nth] star in coordinate list, output results
+
+
+ Colon Parameter Editing Commands
+
+# Image and file parameters
+
+:image [string] Image name
+:coords [string] Coordinate file name
+:output [string] Output file name
+
+# Data dependent parameters
+
+:scale [value] Image scale (units per pixel)
+:fwhmpsf [value] Full-width half-maximum of PSF (scale units)
+:emission [y/n] Emission features (y), absorption (n)
+:sigma [value] Standard deviation of sky (counts)
+:datamin [value] Minimum good pixel value (counts)
+:datamax [value] Maximum good pixel value (counts)
+
+# Noise parameters
+
+:noise [string] Noise model (constant|poisson)
+:gain [string] Gain image header keyword
+:ccdread [string] Readout noise image header keyword
+:epadu [value] Gain (electrons per adu)
+:readnoise [value] Readout noise (electrons)
+
+# Observations parameters
+
+:exposure [string] Exposure time image header keyword
+:airmass [string] Airmass image header keyword
+:filter [string] Filter image header keyword
+:obstime [string] Time of observation image header keyword
+:itime [value] Integration time (time units)
+:xairmass [value] Airmass value (number)
+:ifilter [string] Filter id string
+:otime [string] Time of observations (time units)
+
+# Centering algorithm parameters
+
+:calgorithm [string] Centering algorithm
+:cbox [value] Width of the centering box (scale units)
+:cthreshold [value] Centering intensity threshold (sigma)
+:cmaxiter [value] Maximum number of iterations
+:maxshift [value] Maximum center shift (scale units)
+:minsnratio [value] Minimum S/N ratio for centering
+:clean [y/n] Clean subraster before centering
+:rclean [value] Cleaning radius (scale units)
+:rclip [value] Clipping radius (scale units)
+:kclean [value] Clean K-sigma rejection limit (sigma)
+
+# Sky fitting algorithm parameters
+
+:salgorithm [string] Sky fitting algorithm
+:skyvalue [value] User supplied sky value (counts)
+:annulus [value] Inner radius of sky annulus (scale units)
+:dannulus [value] Width of sky annulus (scale units)
+:khist [value] Sky histogram extent (+/- sigma)
+:binsize [value] Resolution of sky histogram (sigma)
+:smooth [y/n] Lucy smooth the sky histogram
+:sloclip [value] Low-side clipping factor in percent
+:shiclip [value] High-side clipping factor in percent
+:smaxiter [value] Maximum number of iterations
+:snreject [value] Maximum number of rejection cycles
+:sloreject [value] Low-side pixel rejection limits (sky sigma)
+:shireject [value] High-side pixel rejection limits (sky sigma)
+:rgrow [value] Region growing radius (scale units)
+
+# Photometry parameters
+
+:weighting [string] Weighting function (constant|cone|gauss)
+:apertures [string] List of aperture radii (scale units)
+:zmag [value] Zero point of magnitude scale
+
+# Plotting and marking parameters
+
+:mkcenter [y/n] Mark computed centers on display
+:mksky [y/n] Mark the sky annuli on the display
+:mkapert [y/n] Mark apertures on the display
+:radplot [y/n] Plot radial profile of object