aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/aplib
diff options
context:
space:
mode:
Diffstat (limited to 'noao/digiphot/apphot/aplib')
-rw-r--r--noao/digiphot/apphot/aplib/apairmass.x36
-rw-r--r--noao/digiphot/apphot/aplib/apapcolon.x353
-rw-r--r--noao/digiphot/apphot/aplib/aparrays.x52
-rw-r--r--noao/digiphot/apphot/aplib/apfilter.x41
-rw-r--r--noao/digiphot/apphot/aplib/apfree.x25
-rw-r--r--noao/digiphot/apphot/aplib/apgaperts.x214
-rw-r--r--noao/digiphot/apphot/aplib/apgqverify.x68
-rw-r--r--noao/digiphot/apphot/aplib/apgsvw.x162
-rw-r--r--noao/digiphot/apphot/aplib/apgtverify.x19
-rw-r--r--noao/digiphot/apphot/aplib/apimbuf.x17
-rw-r--r--noao/digiphot/apphot/aplib/apimkeys.x72
-rw-r--r--noao/digiphot/apphot/aplib/apinit.x106
-rw-r--r--noao/digiphot/apphot/aplib/apinpars1.x104
-rw-r--r--noao/digiphot/apphot/aplib/apinpars2.x207
-rw-r--r--noao/digiphot/apphot/aplib/apitime.x36
-rw-r--r--noao/digiphot/apphot/aplib/apmark1.x270
-rw-r--r--noao/digiphot/apphot/aplib/apmark2.x46
-rw-r--r--noao/digiphot/apphot/aplib/apnew.x46
-rw-r--r--noao/digiphot/apphot/aplib/apnscolon.x165
-rw-r--r--noao/digiphot/apphot/aplib/apnshow.x118
-rw-r--r--noao/digiphot/apphot/aplib/apotime.x52
-rw-r--r--noao/digiphot/apphot/aplib/apoutpars1.x99
-rw-r--r--noao/digiphot/apphot/aplib/apoutpars2.x146
-rw-r--r--noao/digiphot/apphot/aplib/appadu.x37
-rw-r--r--noao/digiphot/apphot/aplib/apqrad.x119
-rw-r--r--noao/digiphot/apphot/aplib/aprcursor1.x584
-rw-r--r--noao/digiphot/apphot/aplib/aprcursor2.x144
-rw-r--r--noao/digiphot/apphot/aplib/aprdnoise.x36
-rw-r--r--noao/digiphot/apphot/aplib/apset.x72
-rw-r--r--noao/digiphot/apphot/aplib/apset1.x330
-rw-r--r--noao/digiphot/apphot/aplib/apset2.x227
-rw-r--r--noao/digiphot/apphot/aplib/apshowplot.x83
-rw-r--r--noao/digiphot/apphot/aplib/apstat.x77
-rw-r--r--noao/digiphot/apphot/aplib/apstat1.x316
-rw-r--r--noao/digiphot/apphot/aplib/apstat2.x215
-rw-r--r--noao/digiphot/apphot/aplib/apverify1.x582
-rw-r--r--noao/digiphot/apphot/aplib/apverify2.x188
-rw-r--r--noao/digiphot/apphot/aplib/apwcs.x117
-rw-r--r--noao/digiphot/apphot/aplib/apwparam1.x415
-rw-r--r--noao/digiphot/apphot/aplib/apwparam2.x104
-rw-r--r--noao/digiphot/apphot/aplib/apwres1.x437
-rw-r--r--noao/digiphot/apphot/aplib/apwres2.x347
-rw-r--r--noao/digiphot/apphot/aplib/apwres3.x132
-rw-r--r--noao/digiphot/apphot/aplib/apwres4.x238
-rw-r--r--noao/digiphot/apphot/aplib/mkpkg102
45 files changed, 7356 insertions, 0 deletions
diff --git a/noao/digiphot/apphot/aplib/apairmass.x b/noao/digiphot/apphot/aplib/apairmass.x
new file mode 100644
index 00000000..3dcb9cdf
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apairmass.x
@@ -0,0 +1,36 @@
+include <imhdr.h>
+include "../lib/apphot.h"
+
+# AP_AIRMASS - Procedure to determine the image airmass.
+
+procedure ap_airmass (im, ap)
+
+pointer im # pointer to IRAF image
+pointer ap # pointer to apphot structure
+
+pointer sp, key
+real xair
+real imgetr(), apstatr()
+
+begin
+ call smark (sp)
+ call salloc (key, SZ_FNAME, TY_CHAR)
+ call apstats (ap, AIRMASS, Memc[key], SZ_FNAME)
+ if (Memc[key] == EOS)
+ xair = apstatr (ap, XAIRMASS)
+ else {
+ iferr {
+ xair = imgetr (im, Memc[key])
+ } then {
+ xair = apstatr (ap, XAIRMASS)
+ call eprintf ("Warning: Image %s Keyword: %s not found\n")
+ call pargstr (IM_HDRFILE(im))
+ call pargstr (Memc[key])
+ }
+ }
+ if (IS_INDEFR(xair) || xair <= 0.0)
+ call apsetr (ap, XAIRMASS, INDEFR)
+ else
+ call apsetr (ap, XAIRMASS, xair)
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apapcolon.x b/noao/digiphot/apphot/aplib/apapcolon.x
new file mode 100644
index 00000000..1a906345
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apapcolon.x
@@ -0,0 +1,353 @@
+include <error.h>
+include "../lib/apphot.h"
+
+# AP_APCOLON -- Process colon commands for setting the top level apphot package
+# parameters.
+
+procedure ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage,
+ newcenterbuf, newcenter, newskybuf, newsky, newbuf, newfit)
+
+pointer ap # pointer to the apphot structure
+pointer im # pointer to the iraf image
+int cl # coordinate file descriptor
+int out # output file descriptor
+int stid # output file sequence number
+int ltid # coordinate file sequence number
+char cmdstr[ARB] # command string
+int newimage # new image ?
+int newcenterbuf, newcenter # new centering parameters ?
+int newskybuf, newsky # new sky fitting parameters ?
+int newbuf, newfit # new photometry parameters ?
+
+bool bval
+int ncmd, ip
+pointer sp, cmd, str
+real rval
+
+bool streq(), itob()
+int strdic(), nscan(), btoi(), apstati(), ctowrd(), open()
+pointer immap()
+real apstatr()
+errchk immmap, open
+
+begin
+ # Allocate working space.
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Get the command.
+ ip = 1
+ 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, APCMDS)
+ switch (ncmd) {
+
+ case APCMD_FWHMPSF:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_FWHMPSF)
+ call pargr (apstatr (ap, FWHMPSF))
+ call pargstr (UN_ASCALEUNIT)
+ } else {
+ call apsetr (ap, FWHMPSF, rval)
+ if (stid > 1)
+ call ap_rparam (out, KY_FWHMPSF, rval, UN_ASCALEUNIT,
+ "full width half max of psf")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case APCMD_SCALE:
+ call gargr (rval)
+ if (nscan () == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_SCALE)
+ call pargr (1.0 / apstatr (ap, SCALE))
+ call pargstr (UN_AUNITS)
+ } else if (rval > 0.0) {
+ call apsetr (ap, SCALE, (1.0 / rval))
+ if (stid > 1)
+ call ap_rparam (out, KY_SCALE, (1.0 / rval), UN_AUNITS,
+ "scale in units / pixel")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case APCMD_EMISSION:
+ call gargb (bval)
+ if (nscan() == 1) {
+ call printf ("%s = %b\n")
+ call pargstr (KY_POSITIVE)
+ call pargb (itob (apstati (ap, POSITIVE)))
+ } else {
+ call apseti (ap, POSITIVE, btoi (bval))
+ if (stid > 1)
+ call ap_bparam (out, KY_POSITIVE, bval, UN_ASWITCH,
+ "emission feature")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case APCMD_FILTER:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, FILTER, Memc[str], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_FILTER)
+ call pargstr (Memc[str])
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, FILTER, Memc[str])
+ if (im != NULL)
+ call ap_filter (im, ap)
+ if (stid > 1)
+ call ap_sparam (out, KY_FILTER, Memc[str], UN_AKEYWORD,
+ "filter keyword")
+ }
+
+ case APCMD_FILTERID:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, FILTERID, Memc[str], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_FILTERID)
+ call pargstr (Memc[str])
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, FILTERID, Memc[str])
+ }
+
+ case APCMD_OBSTIME:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, OBSTIME, Memc[str], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_OBSTIME)
+ call pargstr (Memc[str])
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, OBSTIME, Memc[str])
+ if (im != NULL)
+ call ap_otime (im, ap)
+ if (stid > 1)
+ call ap_sparam (out, KY_OBSTIME, Memc[str], UN_AKEYWORD,
+ "obstime keyword")
+ }
+
+ case APCMD_OTIME:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, OTIME, Memc[str], SZ_LINE)
+ call printf ("%s = %s %s\n")
+ call pargstr (KY_OTIME)
+ call pargstr (Memc[str])
+ call pargstr (UN_ATIMEUNIT)
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, OTIME, Memc[str])
+ }
+
+ case APCMD_AIRMASS:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, AIRMASS, Memc[str], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_AIRMASS)
+ call pargstr (Memc[str])
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, AIRMASS, Memc[str])
+ if (im != NULL)
+ call ap_airmass (im, ap)
+ if (stid > 1)
+ call ap_sparam (out, KY_AIRMASS, Memc[str], UN_AKEYWORD,
+ "airmass keyword")
+ }
+
+ case APCMD_XAIRMASS:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_XAIRMASS)
+ call pargr (apstatr (ap, XAIRMASS))
+ call pargstr (UN_ANUMBER)
+ } else {
+ call apsetr (ap, XAIRMASS, rval)
+ #if (stid > 1)
+ #call ap_rparam (out, KY_XAIRMASS, rval, UN_ANUMBER,
+ #"airmass")
+ }
+
+ case APCMD_EXPOSURE:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, EXPOSURE, Memc[str], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_EXPOSURE)
+ call pargstr (Memc[str])
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, EXPOSURE, Memc[str])
+ if (im != NULL)
+ call ap_itime (im, ap)
+ if (stid > 1)
+ call ap_sparam (out, KY_EXPOSURE, Memc[str], UN_AKEYWORD,
+ "exposure time keyword")
+ newfit = YES
+ }
+
+ case APCMD_ITIME:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_ITIME)
+ call pargr (apstatr (ap, ITIME))
+ call pargstr (UN_ATIMEUNIT)
+ } else {
+ call apsetr (ap, ITIME, rval)
+ #if (stid > 1)
+ #call ap_rparam (out, KY_ITIME, rval, UN_ATIMEUNIT,
+ #"exposure time")
+ newfit = YES
+ }
+
+ case APCMD_DATAMIN:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_DATAMIN)
+ call pargr (apstatr (ap, DATAMIN))
+ call pargstr (UN_ACOUNTS)
+ } else {
+ call apsetr (ap, DATAMIN, rval)
+ if (stid > 1)
+ call ap_rparam (out, KY_DATAMIN, rval, UN_ACOUNTS,
+ "minimim good data value")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case APCMD_DATAMAX:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_DATAMAX)
+ call pargr (apstatr (ap, DATAMAX))
+ call pargstr (UN_ACOUNTS)
+ } else {
+ call apsetr (ap, DATAMAX, rval)
+ if (stid > 1)
+ call ap_rparam (out, KY_DATAMAX, rval, UN_ACOUNTS,
+ "maximum good data value")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case APCMD_IMAGE:
+ call gargwrd (Memc[cmd], SZ_LINE)
+ call apstats (ap, IMNAME, Memc[str], SZ_FNAME)
+ if (Memc[cmd] == EOS || streq (memc[cmd], Memc[str])) {
+ call printf ("%s: %s\n")
+ call pargstr (KY_IMNAME)
+ call pargstr (Memc[str])
+ } else {
+ if (im != NULL) {
+ call imunmap (im)
+ im = NULL
+ }
+ iferr {
+ im = immap (Memc[cmd], READ_ONLY, 0)
+ } then {
+ call erract (EA_WARN)
+ im = immap (Memc[str], READ_ONLY, 0)
+ } else {
+ call apimkeys (ap, im, Memc[cmd])
+ newimage = YES
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+ }
+
+ case APCMD_COORDS:
+ call gargwrd (Memc[cmd], SZ_LINE)
+ call apstats (ap, CLNAME, Memc[str], SZ_FNAME)
+ if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) {
+ call printf ("%s: %s\n")
+ call pargstr (KY_CLNAME)
+ call pargstr (Memc[str])
+ } else {
+ if (cl != NULL) {
+ call close( cl)
+ cl = NULL
+ }
+ iferr {
+ cl = open (Memc[cmd], READ_ONLY, TEXT_FILE)
+ } then {
+ cl = NULL
+ call erract (EA_WARN)
+ call apsets (ap, CLNAME, "")
+ call apsets (ap, CLROOT, "")
+ call printf ("Coordinate file is undefined.\n")
+ } else {
+ call apsets (ap, CLNAME, Memc[cmd])
+ call apfroot (Memc[cmd], Memc[str], SZ_FNAME)
+ call apsets (ap, CLROOT, Memc[str])
+ ltid = 0
+ }
+ }
+
+ case APCMD_OUTPUT:
+ call gargwrd (Memc[cmd], SZ_LINE)
+ call apstats (ap, OUTNAME, Memc[str], SZ_FNAME)
+ if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) {
+ call printf ("%s: %s\n")
+ call pargstr (KY_OUTNAME)
+ call pargstr (Memc[str])
+ } else {
+ if (out != NULL) {
+ call close (out)
+ out = NULL
+ if (stid <= 1)
+ call delete (Memc[str])
+ }
+ iferr {
+ out = open (Memc[cmd], NEW_FILE, TEXT_FILE)
+ } then {
+ call erract (EA_WARN)
+ call printf ("Reopening output file: %s\n")
+ call pargstr (Memc[str])
+ if (Memc[str] != EOS)
+ out = open (Memc[str], APPEND, TEXT_FILE)
+ else
+ out = NULL
+ } else {
+ call apsets (ap, OUTNAME, Memc[cmd])
+ stid = 1
+ }
+ }
+ default:
+ call printf ("Unknown or ambiguous colon command\7\n")
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/aparrays.x b/noao/digiphot/apphot/aplib/aparrays.x
new file mode 100644
index 00000000..563608fd
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/aparrays.x
@@ -0,0 +1,52 @@
+include "../lib/apphotdef.h"
+include "../lib/photdef.h"
+include "../lib/phot.h"
+
+# AP_ARRAYR -- Procedure to move apphot parameters stored as real arrays
+# into a user allocated array.
+
+procedure ap_arrayr (ap, param, array)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+real array[ARB] # array
+
+pointer phot
+
+begin
+ phot = AP_PPHOT(ap)
+ switch (param) {
+ case APERTS:
+ call amovr (Memr[AP_APERTS(phot)], array, AP_NAPERTS(phot))
+ case MAGS:
+ call amovr (Memr[AP_MAGS(phot)], array, AP_NAPERTS(phot))
+ case MAGERRS:
+ call amovr (Memr[AP_MAGERRS(phot)], array, AP_NAPERTS(phot))
+ default:
+ call error (0, "AP_ARRAYR: Unknown apphot real array")
+ }
+end
+
+
+# AP_ARRAYD -- Procedure to move apphot parameters stored as double arrays
+# into a user allocated array.
+
+procedure ap_arrayd (ap, param, array)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+double array[ARB] # array
+
+pointer phot
+
+begin
+ phot = AP_PPHOT(ap)
+ switch (param) {
+ case AREAS:
+ call amovd (Memd[AP_AREA(phot)], array, AP_NAPERTS(phot))
+ case SUMS:
+ call amovd (Memd[AP_SUMS(phot)], array, AP_NAPERTS(phot))
+ default:
+ call error (0, "AP_ARRAYD: Unknown apphot double array")
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apfilter.x b/noao/digiphot/apphot/aplib/apfilter.x
new file mode 100644
index 00000000..b9bfcc9d
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apfilter.x
@@ -0,0 +1,41 @@
+include <imhdr.h>
+include "../lib/apphot.h"
+
+# AP_FILTER -- Procedure to set the image airmass.
+
+procedure ap_filter (im, ap)
+
+pointer im # pointer to IRAF image
+pointer ap # pointer to apphot structure
+
+pointer sp, key, filt
+
+begin
+ call smark (sp)
+ call salloc (key, SZ_FNAME, TY_CHAR)
+ call salloc (filt, SZ_FNAME, TY_CHAR)
+
+ call apstats (ap, FILTER, Memc[key], SZ_FNAME)
+ Memc[filt] = EOS
+ if (Memc[key] == EOS)
+ call apstats (ap, FILTERID, Memc[filt], SZ_FNAME)
+ else {
+ iferr {
+ call imgstr (im, Memc[key], Memc[filt], SZ_FNAME)
+ } then {
+ call apstats (ap, FILTERID, Memc[filt], SZ_FNAME)
+ call eprintf ("Warning: Image %s Keyword: %s not found\n")
+ call pargstr (IM_HDRFILE(im))
+ call pargstr (Memc[key])
+ }
+ }
+
+ if (Memc[filt] == EOS) {
+ call apsets (ap, FILTERID, "INDEF")
+ } else {
+ call ap_rmwhite (Memc[filt], Memc[filt], SZ_FNAME)
+ call apsets (ap, FILTERID, Memc[filt])
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apfree.x b/noao/digiphot/apphot/aplib/apfree.x
new file mode 100644
index 00000000..30c6c396
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apfree.x
@@ -0,0 +1,25 @@
+include "../lib/apphotdef.h"
+
+# AP_NOISECLS -- Procedure to close up the noise structure and arrays.
+
+procedure ap_noisecls (ap)
+
+pointer ap # pointer to apphot structure
+
+begin
+ if (AP_NOISE(ap) == NULL)
+ return
+ call mfree (AP_NOISE(ap), TY_STRUCT)
+end
+
+
+# AP_DISPCLS -- Procedure to close up the dislay structure and arrays.
+
+procedure ap_dispcls (ap)
+
+pointer ap # pointer to the apphot structure
+
+begin
+ if (AP_PDISPLAY(ap) != NULL)
+ call mfree (AP_PDISPLAY(ap), TY_STRUCT)
+end
diff --git a/noao/digiphot/apphot/aplib/apgaperts.x b/noao/digiphot/apphot/aplib/apgaperts.x
new file mode 100644
index 00000000..05558cc1
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apgaperts.x
@@ -0,0 +1,214 @@
+include <lexnum.h>
+include <ctype.h>
+
+# AP_GETAPERTS -- Procedure to extract real aperture values from a string
+
+int procedure ap_getaperts (str, aperts, max_naperts)
+
+char str[ARB] # string
+real aperts[ARB] # number of apertures
+int max_naperts # maximum number of apertures
+
+int fd, naperts
+int open(), ap_rdaperts(), ap_decaperts()
+errchk open(), close()
+
+begin
+ naperts = 0
+
+ iferr {
+ fd = open (str, READ_ONLY, TEXT_FILE)
+ naperts = ap_rdaperts (fd, aperts, max_naperts)
+ call close (fd)
+ } then {
+ naperts = ap_decaperts (str, aperts, max_naperts)
+ }
+
+ return (naperts)
+end
+
+
+# AP_RDAPERTS -- Procedure to read out the apertures listed one per line
+# from a file.
+
+int procedure ap_rdaperts (fd, aperts, max_naperts)
+
+int fd # aperture list file descriptor
+real aperts[ARB] # list of apertures
+int max_naperts # maximum number of apertures
+
+int naperts
+pointer sp, line
+int getline(), ap_decaperts()
+
+begin
+ call smark (sp)
+ call salloc (line, SZ_LINE, TY_CHAR)
+
+ naperts = 0
+ while (getline (fd, Memc[line]) != EOF && naperts < max_naperts) {
+ naperts = naperts + ap_decaperts (Memc[line], aperts[1+naperts],
+ max_naperts - naperts)
+ }
+
+ call sfree (sp)
+
+ return (naperts)
+end
+
+
+# AP_DECAPERTS -- Procedure to decode the aperture string.
+
+int procedure ap_decaperts (str, aperts, max_naperts)
+
+char str[ARB] # aperture string
+real aperts[ARB] # aperture array
+int max_naperts # maximum number of apertures
+
+char outstr[SZ_LINE]
+int naperts, ip, op, ndecode, nap
+real apstart, apend, apstep
+bool fp_equalr()
+int gctor()
+
+begin
+ naperts = 0
+
+ for (ip = 1; str[ip] != EOS && naperts < max_naperts;) {
+
+ apstart = 0.0
+ apend = 0.0
+ apstep = 0.0
+ ndecode = 0
+
+ # Skip past white space and commas.
+ while (IS_WHITE(str[ip]))
+ ip = ip + 1
+ if (str[ip] == ',')
+ ip = ip + 1
+
+ # Get the number.
+ op = 1
+ while (IS_DIGIT(str[ip]) || str[ip] == '.') {
+ outstr[op] = str[ip]
+ ip = ip + 1
+ op = op + 1
+ }
+ outstr[op] = EOS
+
+ # Decode the starting aperture.
+ op = 1
+ if (gctor (outstr, op, apstart) > 0) {
+ apend = apstart
+ ndecode = 1
+ } else
+ apstart = 0.0
+
+ # Skip past white space and commas.
+ while (IS_WHITE(str[ip]))
+ ip = ip + 1
+ if (str[ip] == ',')
+ ip = ip + 1
+
+ # Get the ending aperture
+ if (str[ip] == ':') {
+ ip = ip + 1
+
+ # Get the ending aperture.
+ op = 1
+ while (IS_DIGIT(str[ip]) || str[ip] == '.') {
+ outstr[op] = str[ip]
+ ip = ip + 1
+ op = op + 1
+ }
+ outstr[op] = EOS
+
+ # Decode the ending aperture.
+ op = 1
+ if (gctor (outstr, op, apend) > 0) {
+ ndecode = 2
+ apstep = apend - apstart
+ }
+ }
+
+ # Skip past white space and commas.
+ while (IS_WHITE(str[ip]))
+ ip = ip + 1
+ if (str[ip] == ',')
+ ip = ip + 1
+
+ # Get the step size.
+ if (str[ip] == ':') {
+ ip = ip + 1
+
+ # Get the step size.
+ op = 1
+ while (IS_DIGIT(str[ip]) || str[ip] == '.') {
+ outstr[op] = str[ip]
+ ip = ip + 1
+ op = op + 1
+ }
+ outstr[op] = EOS
+
+ # Decode the step size.
+ op = 1
+ if (gctor (outstr, op, apstep) > 0) {
+ if (fp_equalr (apstep, 0.0))
+ apstep = apend - apstart
+ else
+ ndecode = (apend - apstart) / apstep + 1
+ if (ndecode < 0) {
+ ndecode = -ndecode
+ apstep = - apstep
+ }
+ }
+ }
+
+ # Negative apertures are not permitted.
+ if (apstart <= 0.0 || apend <= 0.0)
+ break
+
+ # Fill in the apertures.
+ if (ndecode == 0) {
+ ;
+ } else if (ndecode == 1) {
+ naperts = naperts + 1
+ aperts[naperts] = apstart
+ } else if (ndecode == 2) {
+ naperts = naperts + 1
+ aperts[naperts] = apstart
+ if (naperts >= max_naperts)
+ break
+ naperts = naperts + 1
+ aperts[naperts] = apend
+ } else {
+ for (nap = 1; nap <= ndecode && naperts < max_naperts;
+ nap = nap + 1) {
+ naperts = naperts + 1
+ aperts[naperts] = apstart + (nap - 1) * apstep
+ }
+ }
+ }
+
+ return (naperts)
+end
+
+
+# GCTOR -- Procedure to convert a character variable to a real number.
+# This routine is just an interface routine to the IRAF procedure gctod.
+
+int procedure gctor (str, ip, rval)
+
+char str[ARB] # string to be converted
+int ip # pointer to the string
+real rval # real value
+
+double dval
+int nchars
+int gctod()
+
+begin
+ nchars = gctod (str, ip, dval)
+ rval = dval
+ return (nchars)
+end
diff --git a/noao/digiphot/apphot/aplib/apgqverify.x b/noao/digiphot/apphot/aplib/apgqverify.x
new file mode 100644
index 00000000..b7114e37
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apgqverify.x
@@ -0,0 +1,68 @@
+include <ttyset.h>
+include <fset.h>
+
+define QUERY "[Hit return to continue, n next image, q quit, w quit and save parameters]"
+
+# APGQVERIFY -- Print a message in the status line asking the user if they
+# really want to quit, returning YES if they really want to quit, NO otherwise.
+
+int procedure apgqverify (task, ap, ch)
+
+char task[ARB] # name of the apphot task
+pointer ap # pointer to apphot structure
+int ch # character keystroke command
+
+pointer tty
+int getci(), strmatch()
+pointer ttyodes()
+
+begin
+ tty = ttyodes ("terminal")
+ call ttyclearln (STDOUT, tty)
+ call ttyso (STDOUT, tty, YES)
+
+ call printf (QUERY)
+ call flush (STDOUT)
+ call fseti (STDIN, F_RAW, YES)
+ if (getci (STDIN, ch) == EOF)
+ ;
+ call fseti (STDIN, F_RAW, NO)
+ call ttyso (STDOUT, tty, NO)
+ call ttyclearln (STDOUT, tty)
+ call printf ("\n")
+ call flush (STDOUT)
+
+ call ttycdes (tty)
+
+ if (ch == 'q') {
+ return (YES)
+ } else if (ch == 'w') {
+ if (strmatch ("^center", task) > 0) {
+ call ap_pcpars (ap)
+ } else if (strmatch ("^fitsky", task) > 0) {
+ call ap_pspars (ap)
+ } else if (strmatch ("^phot", task) > 0) {
+ call ap_ppars (ap)
+ } else if (strmatch ("^wphot", task) > 0) {
+ call ap_wpars (ap)
+ } else if (strmatch ("^qphot", task) > 0) {
+ call ap_qppars (ap)
+ } else if (strmatch ("^polyphot", task) > 0) {
+ call ap_pypars (ap)
+ } else if (strmatch ("^radprof", task) > 0) {
+ call ap_rpars (ap)
+ } else if (strmatch ("^fitpsf", task) > 0) {
+ call ap_ppfpars (ap)
+ } else if (strmatch ("^daofind", task) > 0) {
+ call ap_fdpars (ap)
+ } else if (strmatch ("^polymark", task) > 0) {
+ ;
+ }
+ return (YES)
+ } else if (ch == 'n') {
+ return (YES)
+ } else {
+ return (NO)
+ }
+
+end
diff --git a/noao/digiphot/apphot/aplib/apgsvw.x b/noao/digiphot/apphot/aplib/apgsvw.x
new file mode 100644
index 00000000..00f35e90
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apgsvw.x
@@ -0,0 +1,162 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <imio.h>
+include <imhdr.h>
+include <math.h>
+
+# AP_GSWV -- Set the data window and viewport for the image display.
+
+procedure ap_gswv (id, image, im, max_nframes)
+
+pointer id # pointer to the image display graphics stream
+char image # the input image name
+pointer im # pointer to the input image
+int max_nframes # the maximum number of display frames
+
+real vx1, vx2, vy1, vy2
+
+begin
+ if (id == NULL)
+ return
+ call ap_gsview (image, im, max_nframes, vx1, vx2, vy1, vy2)
+ call gsview (id, vx1, vx2, vy1, vy2)
+ call gswind (id, 1.0, real (IM_LEN(im,1)), 1.0, real (IM_LEN(im,2)))
+end
+
+
+# AP_GSVIEW -- Map the viewport and window of the image display.
+
+procedure ap_gsview (image, im, max_nframes, vx1, vx2, vy1, vy2)
+
+char image # the input image name
+pointer im # pointer to the input image
+int max_nframes # the maximum number of display frames
+real vx1, vx2, vy1, vy2 # the output viewport
+
+int i, frame, wcs_status, dim1, dim2, step1, step2
+pointer sp, rimname, frimage, frimname, frim, iw
+real x1, x2, y1, y2, fx1, fx2, fy1, fy2, junkx, junky
+bool streq()
+pointer imd_mapframe(), iw_open()
+
+begin
+ # Allocate some memory.
+ call smark (sp)
+ call salloc (rimname, SZ_FNAME, TY_CHAR)
+ call salloc (frimage, SZ_FNAME, TY_CHAR)
+ call salloc (frimname, SZ_FNAME, TY_CHAR)
+
+ # Get the root image name.
+ call imgimage (image, Memc[rimname], SZ_FNAME)
+
+ # Loop through the defined image frames searching for the one
+ # which has the image loaded.
+
+ frame = 0
+ do i = 1, max_nframes {
+ frim = imd_mapframe (i, READ_ONLY, NO)
+ iw = iw_open (frim, i, Memc[frimage], SZ_FNAME, wcs_status)
+ call imgimage (Memc[frimage], Memc[frimname], SZ_FNAME)
+ if (streq (Memc[rimname], Memc[frimname])) {
+ frame = i
+ break
+ } else {
+ call iw_close (iw)
+ call imunmap (frim)
+ }
+ }
+
+ # Default to current frame if the image has not been displayes?
+ if (frame == 0) {
+ call eprintf ("Warning: image %s is not loaded in the display\n")
+ call pargstr (Memc[rimname])
+ vx1 = 0.0
+ vx2 = 1.0
+ vy1 = 0.0
+ vy2 = 1.0
+ call sfree (sp)
+ return
+ }
+
+ # Find the beginning and end points of the requested image section.
+ # We already know at this point that the input logical image is
+ # 2-dimensional. However this 2-dimensional section may be part of
+ # n-dimensional image.
+
+ # X dimension.
+ dim1 = IM_VMAP(im,1)
+ step1 = IM_VSTEP(im,dim1)
+ if (step1 >= 0) {
+ x1 = IM_VOFF(im,dim1) + 1
+ x2 = x1 + IM_LEN(im,1) - 1
+ } else {
+ x1 = IM_VOFF(im,dim1) - 1
+ x2 = x1 - IM_LEN(im,1) + 1
+ }
+
+ # Y dimension.
+ dim2 = IM_VMAP(im,2)
+ step2 = IM_VSTEP(im,dim2)
+ if (step2 >= 0) {
+ y1 = IM_VOFF(im,dim2) + 1
+ y2 = y1 + IM_LEN(im,2) - 1
+ } else {
+ y1 = IM_VOFF(im,dim2) - 1
+ y2 = y1 - IM_LEN(im,2) + 1
+ }
+
+ # Get the frame buffer coordinates corresponding to the lower left
+ # and upper right corners of the image section.
+
+ call iw_im2fb (iw, x1, y1, fx1, fy1)
+ call iw_im2fb (iw, x2, y2, fx2, fy2)
+ if (fx1 > fx2) {
+ junkx = fx1
+ fx1 = fx2
+ fx2 = junkx
+ }
+ if (fy1 > fy2) {
+ junky = fy1
+ fy1 = fy2
+ fy2 = junky
+ }
+
+ # Check that some portion of the input image is in the display.
+ # If not select the default viewport and window coordinates.
+ if (fx1 > IM_LEN(frim,1) || fx2 < 1.0 || fy1 > IM_LEN(frim,2) ||
+ fy2 < 1.0) {
+ vx1 = 0.0
+ vx2 = 1.0
+ vy1 = 0.0
+ vy2 = 1.0
+ call iw_close (iw)
+ call imunmap (frim)
+ call sfree (sp)
+ return
+ }
+
+ # Compute a new viewport and window for X.
+ if (fx1 >= 1.0)
+ vx1 = max (0.0, min (1.0, (fx1 - 0.5) / IM_LEN(frim,1)))
+ else
+ vx1 = 0.0
+ if (fx2 <= IM_LEN(frim,1))
+ vx2 = max (0.0, min (1.0, (fx2 + 0.5) / IM_LEN(frim,1)))
+ else
+ vx2 = 1.0
+
+ # Compute a new viewport and window for Y.
+ if (fy1 >= 1.0)
+ vy1 = max (0.0, min (1.0, (fy1 - 0.5) / IM_LEN(frim,2)))
+ else
+ vy1 = 0.0
+ if (fy2 <= IM_LEN(frim,2))
+ vy2 = max (0.0, min (1.0, (fy2 + 0.5) / IM_LEN(frim,2)))
+ else
+ vy2 = 1.0
+
+ # Clean up.
+ call iw_close (iw)
+ call imunmap (frim)
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apgtverify.x b/noao/digiphot/apphot/aplib/apgtverify.x
new file mode 100644
index 00000000..a2d8bed8
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apgtverify.x
@@ -0,0 +1,19 @@
+# APGTVERIFY -- Print a message in the status line asking the user if they
+# really want to quit, returning YES if they really want to quit, NO otherwise.
+
+int procedure apgtverify (ch)
+
+int ch # character keystroke command
+
+begin
+ if (ch == 'q') {
+ return (YES)
+ } else if (ch == 'w') {
+ return (YES)
+ } else if (ch == 'n') {
+ return (NO)
+ } else {
+ return (NO)
+ }
+
+end
diff --git a/noao/digiphot/apphot/aplib/apimbuf.x b/noao/digiphot/apphot/aplib/apimbuf.x
new file mode 100644
index 00000000..d600a15d
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apimbuf.x
@@ -0,0 +1,17 @@
+include "../lib/apphotdef.h"
+
+# AP_IMBUF -- Set the parameters for the image buffer.
+
+procedure ap_imbuf (ap, hwidth, sequential)
+
+pointer ap # pointer to the apphot structure
+int hwidth # halfwidth of the line buffer
+int sequential # optimize for sequntial i/o
+
+begin
+ AP_SEQUENTIAL(ap) = sequential
+ AP_HWIDTH(ap) = hwidth
+ if (AP_IMBUF(ap) != NULL)
+ call mfree (AP_IMBUF(ap), TY_REAL)
+ AP_IMBUF(ap) = NULL
+end
diff --git a/noao/digiphot/apphot/aplib/apimkeys.x b/noao/digiphot/apphot/aplib/apimkeys.x
new file mode 100644
index 00000000..74105404
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apimkeys.x
@@ -0,0 +1,72 @@
+include "../lib/apphot.h"
+
+# APIMKEYS - Set the image name and keyword parameters after an image
+# is mapped.
+
+procedure apimkeys (ap, im, imname)
+
+pointer ap # pointer to the apphot structure
+pointer im # the image descriptor
+char imname[ARB] # the input image name
+
+pointer sp, imroot, mw, ct
+int apstati()
+pointer mw_openim(), mw_sctran()
+errchk mw_openim(), mw_sctran()
+
+begin
+ call smark (sp)
+ call salloc (imroot, SZ_FNAME, TY_CHAR)
+
+ # Set the image and root names.
+ call apsets (ap, IMNAME, imname)
+ call apimroot (imname, Memc[imroot], SZ_FNAME)
+ call apsets (ap, IMROOT, Memc[imroot])
+
+ # Set the wcs descriptors.
+ mw = apstati (ap, MW)
+ if (mw != NULL)
+ call mw_close (mw)
+ iferr {
+ mw = mw_openim (im)
+ } then {
+ call apseti (ap, MW, NULL)
+ call apseti (ap, CTIN, NULL)
+ call apseti (ap, CTOUT, NULL)
+ } else {
+ call apseti (ap, MW, mw)
+ switch (apstati (ap, WCSIN)) {
+ case WCS_WORLD:
+ iferr (ct = mw_sctran (mw, "world", "logical", 03B))
+ ct = NULL
+ case WCS_PHYSICAL:
+ iferr (ct = mw_sctran (mw, "physical", "logical", 03B))
+ ct = NULL
+ case WCS_TV, WCS_LOGICAL:
+ ct = NULL
+ default:
+ ct = NULL
+ }
+ call apseti (ap, CTIN, ct)
+ switch (apstati (ap, WCSOUT)) {
+ case WCS_PHYSICAL:
+ iferr (ct = mw_sctran (mw, "logical", "physical", 03B))
+ ct = NULL
+ case WCS_TV, WCS_LOGICAL:
+ ct = NULL
+ default:
+ ct = NULL
+ }
+ call apseti (ap, CTOUT, ct)
+ }
+
+ # Set the keywords.
+ call ap_rdnoise (im, ap)
+ call ap_padu (im, ap)
+ call ap_itime (im, ap)
+ call ap_airmass (im, ap)
+ call ap_filter (im, ap)
+ call ap_otime (im, ap)
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apinit.x b/noao/digiphot/apphot/aplib/apinit.x
new file mode 100644
index 00000000..19e87eee
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apinit.x
@@ -0,0 +1,106 @@
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/noisedef.h"
+include "../lib/noise.h"
+include "../lib/displaydef.h"
+
+# AP_DEFSETUP -- Initialize the global apphot package parameters to their
+# default values.
+
+procedure ap_defsetup (ap, fwhmpsf)
+
+pointer ap # pointer to the apphot package
+real fwhmpsf # the FWHM of the stellar images
+
+begin
+ # Initalize the file names.
+ AP_IMNAME(ap) = EOS
+ AP_IMROOT(ap) = EOS
+ AP_CLNAME(ap) = EOS
+ AP_CLROOT(ap) = EOS
+ AP_OUTNAME(ap) = EOS
+ AP_PLOTFILE(ap) = EOS
+ AP_OUTNAME(ap) = EOS
+
+ AP_WCSIN(ap) = WCS_LOGICAL
+ AP_WCSOUT(ap) = WCS_LOGICAL
+ AP_MW(ap) = NULL
+ AP_CTIN(ap) = NULL
+ AP_CTOUT(ap) = NULL
+
+ # Initialize the cursor positions.
+ AP_CWX(ap) = INDEFR
+ AP_CWY(ap) = INDEFR
+ AP_WX(ap) = INDEFR
+ AP_WY(ap) = INDEFR
+
+ # Set up the data characteristics.
+ AP_SCALE(ap) = DEF_SCALE
+ AP_FWHMPSF(ap) = fwhmpsf
+ AP_POSITIVE(ap) = DEF_POSITIVE
+ AP_DATAMIN(ap) = DEF_DATAMIN
+ AP_DATAMAX(ap) = DEF_DATAMAX
+
+ # Set up the image header keywords.
+ AP_EXPOSURE(ap) = EOS
+ AP_ITIME(ap) = DEF_ITIME
+ AP_FILTER(ap) = EOS
+ call strcpy (DEF_FILTERID, AP_FILTERID(ap), SZ_FNAME)
+ AP_AIRMASS(ap) = EOS
+ AP_XAIRMASS(ap) = DEF_XAIRMASS
+ AP_OBSTIME(ap) = EOS
+ call strcpy (DEF_OTIME, AP_OTIME(ap), SZ_FNAME)
+
+ # Set buffer parameters.
+ AP_SEQUENTIAL(ap) = NULL
+ AP_IMBUF(ap) = NULL
+ AP_HWIDTH(ap) = 0
+end
+
+
+# AP_NOISESETUP -- Procedure to intialize noise model parameters.
+
+procedure ap_noisesetup (ap, noise)
+
+pointer ap # pointer to apphot structure
+int noise # noise model
+
+pointer nse
+
+begin
+ call malloc (AP_NOISE(ap), LEN_APNOISE, TY_STRUCT)
+ nse = AP_NOISE(ap)
+ AP_NOISEFUNCTION(nse) = noise
+ switch (noise) {
+ case AP_NCONSTANT:
+ call strcpy ("constant", AP_NSTRING(nse), SZ_FNAME)
+ case AP_NPOISSON:
+ call strcpy ("poisson", AP_NSTRING(nse), SZ_FNAME)
+ default:
+ call strcpy ("poisson", AP_NSTRING(nse), SZ_FNAME)
+ }
+ AP_READNOISE(nse) = DEF_READNOISE
+ AP_SKYSIGMA(nse) = DEF_SKYSIGMA
+ AP_EPADU(nse) = DEF_EPADU
+ AP_GAIN(nse) = EOS
+ AP_CCDREAD(nse) = EOS
+end
+
+
+# AP_DISPSETUP -- Procedure to setup the display parameters.
+
+procedure ap_dispsetup (ap)
+
+pointer ap # pointer to apphot structure
+
+pointer dsp
+
+begin
+ call malloc (AP_PDISPLAY(ap), LEN_DISPLAYSTRUCT, TY_STRUCT)
+ dsp = AP_PDISPLAY(ap)
+ AP_MKSKY(dsp) = DEF_MKSKY
+ AP_MKCENTER(dsp) = DEF_MKCENTER
+ AP_MKAPERT(dsp) = DEF_MKAPERT
+ AP_RADPLOTS(dsp) = DEF_RADPLOTS
+ AP_MKDETECTIONS(dsp) = DEF_MKDETECTIONS
+end
diff --git a/noao/digiphot/apphot/aplib/apinpars1.x b/noao/digiphot/apphot/aplib/apinpars1.x
new file mode 100644
index 00000000..cc332004
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apinpars1.x
@@ -0,0 +1,104 @@
+include "../lib/apphot.h"
+include "../lib/display.h"
+include "../lib/noise.h"
+include "../lib/find.h"
+
+# AP_GDAPARS-- Read in the data dependent parameters from the datapars file.
+
+procedure ap_gdapars (ap)
+
+pointer ap # pointer to the apphot structure
+
+int noise
+pointer sp, str, np
+bool clgpsetb()
+int strdic(), btoi()
+pointer clopset()
+real clgpsetr()
+
+begin
+ # Allocate workin space.
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Open the pset parameter file.
+ np = clopset ("datapars")
+
+ # Get the data dependent parameters.
+ call apsetr (ap, FWHMPSF, clgpsetr (np, "fwhmpsf"))
+ call apsetr (ap, SCALE, 1.0 / clgpsetr (np, "scale"))
+ call apseti (ap, POSITIVE, btoi (clgpsetb (np, "emission")))
+ call apsetr (ap, DATAMIN, clgpsetr (np, "datamin"))
+ call apsetr (ap, DATAMAX, clgpsetr (np, "datamax"))
+ call apsetr (ap, SKYSIGMA, clgpsetr (np, "sigma"))
+
+ # Get the noise function parameters.
+ call clgpset (np, "noise", Memc[str], SZ_LINE)
+ noise = strdic (Memc[str], Memc[str], SZ_LINE, NFUNCS)
+ call apsets (ap, NSTRING, Memc[str])
+ call apseti (ap, NOISEFUNCTION, noise)
+ call clgpset (np, "gain", Memc[str], SZ_LINE)
+ call apsets (ap, GAIN, Memc[str])
+ call apsetr (ap, EPADU, clgpsetr (np, "epadu"))
+ call clgpset (np, "ccdread", Memc[str], SZ_LINE)
+ call apsets (ap, CCDREAD, Memc[str])
+ call apsetr (ap, READNOISE, clgpsetr (np, "readnoise"))
+
+ # Get the image header parameters.
+ call clgpset (np, "exposure", Memc[str], SZ_LINE)
+ call apsets (ap, EXPOSURE, Memc[str])
+ call apsetr (ap, ITIME, clgpsetr (np, "itime"))
+ call clgpset (np, "airmass", Memc[str], SZ_LINE)
+ call apsets (ap, AIRMASS, Memc[str])
+ call apsetr (ap, XAIRMASS, clgpsetr (np, "xairmass"))
+ call clgpset (np, "filter", Memc[str], SZ_LINE)
+ call apsets (ap, FILTER, Memc[str])
+ call clgpset (np, "ifilter", Memc[str], SZ_LINE)
+ call apsets (ap, FILTERID, Memc[str])
+ call clgpset (np, "obstime", Memc[str], SZ_LINE)
+ call apsets (ap, OBSTIME, Memc[str])
+ call clgpset (np, "otime", Memc[str], SZ_LINE)
+ call apsets (ap, OTIME, Memc[str])
+
+ # Close the parameter set files.
+ call clcpset (np)
+
+ call sfree (sp)
+end
+
+
+# AP_GFIPARS -- Read in the object finding parametes from the findpars
+# parameter file.
+
+procedure ap_gfipars (ap)
+
+pointer ap # pointer to the apphot structure
+
+pointer pp
+bool clgpsetb()
+int btoi()
+pointer clopset()
+real clgpsetr()
+
+begin
+ # Open the pset parameter file.
+ pp = clopset ("findpars")
+
+ # Get the kernel statistics.
+ call apsetr (ap, NSIGMA, clgpsetr (pp, "nsigma"))
+ call apsetr (ap, RATIO, clgpsetr (pp, "ratio"))
+ call apsetr (ap, THETA, clgpsetr (pp, "theta"))
+
+ # Get the image detection characteristics.
+ call apsetr (ap, THRESHOLD, clgpsetr (pp, "threshold"))
+ call apsetr (ap, SHARPLO, clgpsetr (pp, "sharplo"))
+ call apsetr (ap, SHARPHI, clgpsetr (pp, "sharphi"))
+ call apsetr (ap, ROUNDLO, clgpsetr (pp, "roundlo"))
+ call apsetr (ap, ROUNDHI, clgpsetr (pp, "roundhi"))
+
+ # Set the marking parameter.
+ call apseti (ap, MKDETECTIONS, btoi (clgpsetb (pp, "mkdetections")))
+
+ # Close the parameter set file.
+ call clcpset (pp)
+end
diff --git a/noao/digiphot/apphot/aplib/apinpars2.x b/noao/digiphot/apphot/aplib/apinpars2.x
new file mode 100644
index 00000000..ff9cf3eb
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apinpars2.x
@@ -0,0 +1,207 @@
+include "../lib/display.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+include "../lib/polyphot.h"
+
+# AP_GCEPARS -- Read in the centering algorithm parameters from the
+# centerpars parameter file.
+
+procedure ap_gcepars (ap)
+
+pointer ap # pointer to the apphot structure
+
+int function
+pointer sp, str, pp
+bool clgpsetb()
+int strdic(), btoi(), clgpseti()
+pointer clopset()
+real clgpsetr()
+
+begin
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Open the pset parameter file.
+ pp = clopset ("centerpars")
+
+ # Get the centering parameters.
+ call clgpset (pp, "calgorithm", Memc[str], SZ_LINE)
+ function = strdic (Memc[str], Memc[str], SZ_LINE, CFUNCS)
+ call apsets (ap, CSTRING, Memc[str])
+ call apseti (ap, CENTERFUNCTION, function)
+ call apsetr (ap, CAPERT, clgpsetr (pp, "cbox") / 2.0)
+ call apsetr (ap, CTHRESHOLD, clgpsetr (pp, "cthreshold"))
+ call apsetr (ap, MINSNRATIO, clgpsetr (pp, "minsnratio"))
+ call apseti (ap, CMAXITER, clgpseti (pp, "cmaxiter"))
+ call apsetr (ap, MAXSHIFT, clgpsetr (pp, "maxshift"))
+ call apseti (ap, CLEAN, btoi (clgpsetb (pp, "clean")))
+ call apsetr (ap, RCLEAN, clgpsetr (pp, "rclean"))
+ call apsetr (ap, RCLIP, clgpsetr (pp, "rclip"))
+ call apsetr (ap, SIGMACLEAN, clgpsetr (pp, "kclean"))
+
+ call apseti (ap, MKCENTER, btoi (clgpsetb (pp, "mkcenter")))
+
+
+ # Close the parameter set file.
+ call clcpset (pp)
+
+ call sfree (sp)
+end
+
+
+# AP_GSAPARS -- Read in the sky fitting parameters from the fitskypars
+# parameter file.
+
+procedure ap_gsapars (ap)
+
+pointer ap # pointer to the apphot strucuture
+
+int function
+pointer sp, str, pp
+bool clgpsetb()
+int strdic(), clgpseti(), btoi()
+pointer clopset()
+real clgpsetr()
+
+begin
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Open the pset parameter file.
+ pp = clopset ("fitskypars")
+
+ # Get the sky fitting algorithm parameters.
+ call clgpset (pp, "salgorithm", Memc[str], SZ_LINE)
+ function = strdic (Memc[str], Memc[str], SZ_LINE, SFUNCS)
+ call apsets (ap, SSTRING, Memc[str])
+ call apseti (ap, SKYFUNCTION, function)
+ call apsetr (ap, SKY_BACKGROUND, clgpsetr (pp, "skyvalue"))
+ call apsetr (ap, ANNULUS, clgpsetr (pp, "annulus"))
+ call apsetr (ap, DANNULUS, clgpsetr (pp, "dannulus"))
+ call apsetr (ap, K1, clgpsetr (pp, "khist"))
+ call apsetr (ap, BINSIZE, clgpsetr (pp, "binsize"))
+ call apseti (ap, SMOOTH, btoi (clgpsetb (pp, "smooth")))
+ call apseti (ap, SMAXITER, clgpseti (pp, "smaxiter"))
+ call apsetr (ap, SLOCLIP, clgpsetr (pp, "sloclip"))
+ call apsetr (ap, SHICLIP, clgpsetr (pp, "shiclip"))
+ call apseti (ap, SNREJECT, clgpseti (pp, "snreject"))
+ call apsetr (ap, SLOREJECT, clgpsetr (pp, "sloreject"))
+ call apsetr (ap, SHIREJECT, clgpsetr (pp, "shireject"))
+ call apsetr (ap, RGROW, clgpsetr (pp, "rgrow"))
+
+ # Get the marking parameter.
+ call apseti (ap, MKSKY, btoi (clgpsetb (pp, "mksky")))
+
+ # Close the parameter set file.
+ call clcpset (pp)
+
+ call sfree (sp)
+end
+
+
+# AP_GPHPARS -- Get the photometry algorithm parameters from the photometry
+# file.
+
+procedure ap_gphars (ap)
+
+pointer ap # pointer to the apphot strucuture
+
+pointer sp, str, pp
+bool clgpsetb()
+int btoi()
+pointer clopset()
+real clgpsetr()
+
+begin
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Open the pset parameter file.
+ pp = clopset ("photpars")
+
+ # Get the photometry parameters.
+ call clgpset (pp, "apertures", Memc[str], SZ_LINE)
+ call apsets (ap, APERTS, Memc[str])
+ call apsetr (ap, ZMAG, clgpsetr (pp, "zmag"))
+ call apseti (ap, MKAPERT, btoi (clgpsetb (pp, "mkapert")))
+ call apsets (ap, PWSTRING, "constant")
+ call apseti (ap, PWEIGHTS, AP_PWCONSTANT)
+
+ # Close the parameter set file.
+ call clcpset (pp)
+
+ call sfree (sp)
+end
+
+
+# AP_GPOPARS -- Get the polygonal aperture photometry parameters.
+
+procedure ap_gpopars (ap)
+
+pointer ap # pointer to the apphot strucuture
+
+pointer sp, str, pp
+bool clgpsetb()
+int btoi()
+pointer clopset()
+real clgpsetr()
+
+begin
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Open the pset parameter file.
+ pp = clopset ("polypars")
+
+ # Get the parameters.
+ call apsetr (ap, PYZMAG, clgpsetr (pp, "zmag"))
+ call apseti (ap, MKPOLYGON, btoi (clgpsetb (pp, "mkpolygon")))
+
+ # Close the parameter set file.
+ call clcpset (pp)
+
+ call sfree (sp)
+end
+
+
+# AP_GWHPARS -- Get the photometry algorithm parameters from the photometry
+# file.
+
+procedure ap_gwhars (ap)
+
+pointer ap # pointer to the apphot strucuture
+
+int weight
+pointer sp, str, pp
+bool clgpsetb()
+int btoi(), strdic()
+pointer clopset()
+real clgpsetr()
+
+begin
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Open the pset parameter file.
+ pp = clopset ("photpars")
+
+ # Get the photometry parameters.
+ call clgpset (pp, "apertures", Memc[str], SZ_LINE)
+ call apsets (ap, APERTS, Memc[str])
+ call apsetr (ap, ZMAG, clgpsetr (pp, "zmag"))
+ call apseti (ap, MKAPERT, btoi (clgpsetb (pp, "mkapert")))
+ call apsets (ap, PWSTRING, "constant")
+ call apseti (ap, PWEIGHTS, AP_PWCONSTANT)
+
+ # Get the major parameters.
+ call clgpset (pp, "weighting", Memc[str], SZ_LINE)
+ weight = strdic (Memc[str], Memc[str], SZ_LINE, PWFUNCS)
+ call apsets (ap, PWSTRING, Memc[str])
+ call apseti (ap, PWEIGHTS, weight)
+
+ # Close the parameter set file.
+ call clcpset (pp)
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apitime.x b/noao/digiphot/apphot/aplib/apitime.x
new file mode 100644
index 00000000..c01dfc9e
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apitime.x
@@ -0,0 +1,36 @@
+include <imhdr.h>
+include "../lib/apphot.h"
+
+# AP_ITIME - Procedure to set the image exposure time .
+
+procedure ap_itime (im, ap)
+
+pointer im # pointer to IRAF image
+pointer ap # pointer to apphot structure
+
+pointer sp, key
+real itime
+real imgetr(), apstatr()
+
+begin
+ call smark (sp)
+ call salloc (key, SZ_FNAME, TY_CHAR)
+ call apstats (ap, EXPOSURE, Memc[key], SZ_FNAME)
+ if (Memc[key] == EOS)
+ itime = apstatr (ap, ITIME)
+ else {
+ iferr {
+ itime = imgetr (im, Memc[key])
+ } then {
+ itime = apstatr (ap, ITIME)
+ call eprintf ("Warning: Image %s Keyword: %s not found\n")
+ call pargstr (IM_HDRFILE(im))
+ call pargstr (Memc[key])
+ }
+ }
+ if (IS_INDEFR(itime) || itime <= 0.0)
+ call apsetr (ap, ITIME, 1.0)
+ else
+ call apsetr (ap, ITIME, itime)
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apmark1.x b/noao/digiphot/apphot/aplib/apmark1.x
new file mode 100644
index 00000000..1982a679
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apmark1.x
@@ -0,0 +1,270 @@
+include <gset.h>
+include "../lib/apphot.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+include "../lib/polyphot.h"
+include "../lib/radprof.h"
+
+# APMARK -- Procedure to mark center, fitsky and phot parameters on the display.
+
+procedure apmark (ap, id, mkcenter, mksky, mkapert)
+
+pointer ap # apphot pointer
+pointer id # pointer to image display stream
+int mkcenter # mark the computed center
+int mksky # mark the sky annulus
+int mkapert # mark the aperture(s)
+
+int i, marktype
+pointer sp, temp
+real inner_sky, outer_sky, apert
+int apstati(), gstati()
+real apstatr()
+errchk greactivate, gdeactivate, gamove, gadraw, gmark
+
+begin
+ if (id == NULL)
+ return
+ if (mkcenter == NO && mksky == NO && mkapert == NO)
+ return
+ iferr {
+ call greactivate (id, 0)
+ } then {
+ return
+ }
+
+ marktype = gstati (id, G_PMLTYPE)
+
+ # Mark the center and shift on the display.
+ if (mkcenter == YES) {
+ iferr {
+ call gseti (id, G_PMLTYPE, GL_SOLID)
+ call gamove (id, (apstatr (ap, XCENTER) - apstatr (ap, XSHIFT)),
+ (apstatr (ap, YCENTER) - apstatr (ap, YSHIFT)))
+ call gadraw (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER))
+ call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER),
+ GM_PLUS, -2.0, -2.0)
+ } then
+ ;
+ }
+
+ # Draw the sky annuli on the display.
+ if (mksky == YES) {
+ iferr {
+ call gseti (id, G_PMLTYPE, GL_DASHED)
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_PLUS, -2.0, -2.0)
+ inner_sky = 2.0 * apstatr (ap, SCALE) * apstatr (ap, ANNULUS)
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_CIRCLE, -inner_sky, -inner_sky)
+ outer_sky = 2.0 * apstatr (ap, SCALE) * (apstatr (ap,
+ ANNULUS) + apstatr (ap, DANNULUS))
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_CIRCLE, -outer_sky, -outer_sky)
+ } then
+ ;
+ }
+
+ # Draw the apertures on the display.
+ if (mkapert == YES) {
+ iferr {
+ call smark (sp)
+ call salloc (temp, apstati (ap, NAPERTS), TY_REAL)
+ call ap_arrayr (ap, APERTS, Memr[temp])
+ call gseti (id, G_PMLTYPE, GL_DASHED)
+ call gmark (id, apstatr (ap, PXCUR), apstatr (ap, PYCUR),
+ GM_PLUS, -2.0, -2.0)
+ do i = 1, apstati (ap, NAPERTS) {
+ apert = 2.0 * apstatr (ap, SCALE) * Memr[temp+i-1]
+ call gmark (id, apstatr (ap, PXCUR), apstatr (ap, PYCUR),
+ GM_CIRCLE, -apert, -apert)
+ }
+ call sfree (sp)
+ } then
+ call sfree (sp)
+ }
+
+ # Restore the mark type.
+ call gseti (id, G_PMLTYPE, marktype)
+
+ iferr {
+ call gdeactivate (id, 0)
+ } then
+ return
+end
+
+# APPYMARK -- Procedure to mark center, fitsky and polyphot parameters on the
+# display.
+
+procedure appymark (ap, id, x, y, nver, mkcenter, mksky, mkpolygon)
+
+pointer ap # apphot pointer
+pointer id # pointer to image display stream
+real x[ARB] # coordinates of x vertices
+real y[ARB] # coordinates of y vertices
+int nver # number of vertices
+int mkcenter # mark the computed center
+int mksky # mark the sky annulus
+int mkpolygon # mark the aperture(s)
+
+int marktype, linetype
+real inner_sky, outer_sky
+int gstati()
+real apstatr()
+errchk greactivate, gdeactivate, gamove, gadraw, gmark, gline
+
+begin
+ if (id == NULL)
+ return
+ if (mkcenter == NO && mksky == NO && mkpolygon == NO)
+ return
+ iferr {
+ call greactivate (id, 0)
+ } then
+ return
+
+ marktype = gstati (id, G_PMLTYPE)
+ linetype = gstati (id, G_PLTYPE)
+
+ if (mkcenter == YES) {
+ iferr {
+ call gseti (id, G_PMLTYPE, GL_SOLID)
+ call gamove (id, (apstatr (ap, XCENTER) - apstatr (ap, XSHIFT)),
+ (apstatr (ap, YCENTER) - apstatr (ap, YSHIFT)))
+ call gadraw (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER))
+ call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER),
+ GM_PLUS, -2.0, -2.0)
+ } then
+ ;
+ }
+
+ if (mksky == YES) {
+ iferr {
+ call gseti (id, G_PMLTYPE, GL_DASHED)
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_PLUS, -2.0, -2.0)
+ inner_sky = 2.0 * apstatr (ap, SCALE) * apstatr (ap, ANNULUS)
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_CIRCLE, -inner_sky, -inner_sky)
+ outer_sky = 2.0 * apstatr (ap, SCALE) * (apstatr (ap,
+ ANNULUS) + apstatr (ap, DANNULUS))
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_CIRCLE, -outer_sky, -outer_sky)
+ } then
+ ;
+ }
+
+ if (mkpolygon == YES) {
+ iferr {
+ call gseti (id, G_PLTYPE, GL_DASHED)
+ call gmark (id, apstatr (ap, PYCX), apstatr (ap, PYCY),
+ GM_PLUS, -2.0, -2.0)
+ call gpline (id, x, y, nver)
+ } then
+ ;
+ }
+
+ call gseti (id, G_PMLTYPE, marktype)
+ call gseti (id, G_PLTYPE, linetype)
+
+ iferr (call gdeactivate (id, 0))
+ return
+end
+
+
+# APRMARK -- Procedure to mark center, fitsky and radprof parameters on the
+# display.
+
+procedure aprmark (ap, id, mkcenter, mksky, mkapert)
+
+pointer ap # apphot pointer
+pointer id # pointer to image display stream
+int mkcenter # mark the computed center
+int mksky # mark the sky annulus
+int mkapert # mark the aperture(s)
+
+int i, marktype
+pointer sp, temp
+real inner_sky, outer_sky, apert, radius, xc, yc
+int apstati(), gstati()
+real apstatr()
+errchk greactivate, gdeactivate, gamove, gadraw, gmark
+
+begin
+ if (id == NULL)
+ return
+ if (mkcenter == NO && mksky == NO && mkapert == NO)
+ return
+
+ iferr {
+ call greactivate (id, 0)
+ } then
+ return
+
+ marktype = gstati (id, G_PMLTYPE)
+
+ # Mark the center and shift on the display.
+ if (mkcenter == YES) {
+ iferr {
+ call gseti (id, G_PMLTYPE, GL_SOLID)
+ call gamove (id, (apstatr (ap, XCENTER) - apstatr (ap, XSHIFT)),
+ (apstatr (ap, YCENTER) - apstatr (ap, YSHIFT)))
+ call gadraw (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER))
+ call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER),
+ GM_PLUS, -2.0, -2.0)
+ call gflush (id)
+ } then
+ ;
+ }
+
+ # Draw the sky annuli on the display.
+ if (mksky == YES) {
+ iferr {
+ call gseti (id, G_PMLTYPE, GL_DASHED)
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_PLUS, -2.0, -2.0)
+ inner_sky = 2.0 * apstatr (ap, SCALE) * apstatr (ap, ANNULUS)
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_CIRCLE, -inner_sky, -inner_sky)
+ outer_sky = 2.0 * apstatr (ap, SCALE) * (apstatr (ap,
+ ANNULUS) + apstatr (ap, DANNULUS))
+ call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR),
+ GM_CIRCLE, -outer_sky, -outer_sky)
+ call gflush (id)
+ } then
+ ;
+ }
+
+ # Draw the apertures on the display.
+ if (mkapert == YES) {
+ iferr {
+ call smark (sp)
+ call salloc (temp, apstati (ap, NAPERTS), TY_REAL)
+ call gseti (id, G_PMLTYPE, GL_DASHED)
+ call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER),
+ GM_PLUS, -2.0, -2.0)
+ call ap_arrayr (ap, APERTS, Memr[temp])
+ do i = 1, apstati (ap, NAPERTS) {
+ apert = 2.0 * apstatr (ap, SCALE) * Memr[temp+i-1]
+ call gmark (id, apstatr (ap, XCENTER), apstatr (ap,
+ YCENTER), GM_CIRCLE, -apert, -apert)
+ }
+ xc = apstatr (ap, XCENTER)
+ yc = apstatr (ap, YCENTER)
+ radius = apstatr (ap, SCALE) * apstatr (ap, RPRADIUS)
+ call gamove (id, xc - radius, yc - radius)
+ call gadraw (id, xc + radius, yc - radius)
+ call gadraw (id, xc + radius, yc + radius)
+ call gadraw (id, xc - radius, yc + radius)
+ call gadraw (id, xc - radius, yc - radius)
+ call sfree (sp)
+ } then
+ call sfree (sp)
+ }
+
+ call gseti (id, G_PMLTYPE, marktype)
+
+ iferr (call gdeactivate (id, 0))
+ return
+end
diff --git a/noao/digiphot/apphot/aplib/apmark2.x b/noao/digiphot/apphot/aplib/apmark2.x
new file mode 100644
index 00000000..96896e56
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apmark2.x
@@ -0,0 +1,46 @@
+include <gset.h>
+include "../lib/apphot.h"
+include "../lib/fitpsf.h"
+
+
+# AP_PFMARK -- Procedure to mark the psf fitting box on the display.
+
+procedure appfmark (ap, id, mkbox)
+
+pointer ap # pointer to the apphot procedure
+pointer id # pointer to the display stream
+int mkbox # mark the psf fitting box
+
+int marktype
+real radius, xc, yc
+int gstati()
+real apstatr()
+errchk greactivate, gdeactivate, gamove, gadraw
+
+begin
+ if (id == NULL)
+ return
+ if (mkbox == NO)
+ return
+
+ iferr (call greactivate (id, 0))
+ return
+
+ marktype = gstati (id,G_PMLTYPE)
+ iferr {
+ call gseti (id, G_PMLTYPE, GL_DASHED)
+ xc = apstatr (ap, PFXCUR)
+ yc = apstatr (ap, PFYCUR)
+ radius = apstatr (ap, SCALE) * apstatr (ap, PSFAPERT)
+ call gamove (id, xc - radius, yc - radius)
+ call gadraw (id, xc + radius, yc - radius)
+ call gadraw (id, xc + radius, yc + radius)
+ call gadraw (id, xc - radius, yc + radius)
+ call gadraw (id, xc - radius, yc - radius)
+ } then
+ ;
+ call gseti (id, G_PMLTYPE, marktype)
+
+ iferr (call gdeactivate (id, 0))
+ return
+end
diff --git a/noao/digiphot/apphot/aplib/apnew.x b/noao/digiphot/apphot/aplib/apnew.x
new file mode 100644
index 00000000..b5da6fc1
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apnew.x
@@ -0,0 +1,46 @@
+include "../lib/apphot.h"
+
+# APNEW -- Procedure to determine whether the current star is the same as
+# the previous star and/or whether the current star belongs to the coordinate
+# list or not.
+
+int procedure apnew (ap, wx, wy, xlist, ylist, newlist)
+
+pointer ap # pointer to the apphot structure
+real wx # x cursor coordinate
+real wy # y cursor coordinate
+real xlist # x list coordinate
+real ylist # y list coordinate
+int newlist # integer new list
+
+bool fp_equalr()
+int newobject
+real deltaxy
+real apstatr()
+
+begin
+ deltaxy = apstatr (ap, FWHMPSF) * apstatr (ap, SCALE)
+
+ if (newlist == NO) {
+ if (! fp_equalr (wx, apstatr (ap, WX)) || ! fp_equalr (wy,
+ apstatr (ap, WY)))
+ newobject = YES
+ else
+ newobject = NO
+ } else if ((abs (xlist - wx) <= deltaxy) &&
+ (abs (ylist - wy) <= deltaxy)) {
+ wx = xlist
+ wy = ylist
+ newobject = NO
+ } else if (fp_equalr (wx, apstatr (ap, WX)) && fp_equalr (wy,
+ apstatr (ap, WY))) {
+ wx = xlist
+ wy = ylist
+ newobject = NO
+ } else {
+ newlist = NO
+ newobject = YES
+ }
+
+ return (newobject)
+end
diff --git a/noao/digiphot/apphot/aplib/apnscolon.x b/noao/digiphot/apphot/aplib/apnscolon.x
new file mode 100644
index 00000000..34bc43fc
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apnscolon.x
@@ -0,0 +1,165 @@
+include <error.h>
+include "../lib/noise.h"
+
+# AP_NSCOLON -- Procedure to process colon commands for setting
+# noise fitting parameters.
+
+procedure ap_nscolon (ap, im, out, stid, cmdstr, newcenterbuf,
+ newcenter, newskybuf, newsky, newbuf, newfit)
+
+pointer ap # pointer to the apphot structure
+pointer im # pointer to the iraf image
+int out # output file descriptor
+int stid # output file sequence number
+char cmdstr[ARB] # command string
+int newcenterbuf, newcenter # new centering parameters ?
+int newskybuf, newsky # new sky fitting parameters ?
+int newbuf, newfit # new photometry parameters ?
+
+int ncmd, stat, ip
+pointer sp, cmd, str
+real rval
+int strdic(), nscan(), ctowrd()
+real apstatr()
+errchk immmap
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Get the command.
+ ip = 1
+ 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, NCMDS)
+ switch (ncmd) {
+
+ case NCMD_NOISE:
+ call gargwrd (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, NSTRING, Memc[str], SZ_FNAME)
+ call printf ("%s = %s %s\n")
+ call pargstr (KY_NSTRING)
+ call pargstr (Memc[str])
+ call pargstr (UN_NMODEL)
+ } else {
+ stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, NFUNCS)
+ if (stat > 0) {
+ call apseti (ap, NOISEFUNCTION, stat)
+ call apsets (ap, NSTRING, Memc[cmd])
+ if (stid > 1)
+ call ap_sparam (out, KY_NSTRING, Memc[cmd], UN_NMODEL,
+ "noise model")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+ }
+
+ case NCMD_SIGMA:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_SKYSIGMA)
+ call pargr (apstatr (ap, SKYSIGMA))
+ call pargstr (UN_NCOUNTS)
+ } else {
+ call apsetr (ap, SKYSIGMA, rval)
+ if (stid > 1)
+ call ap_rparam (out, KY_SKYSIGMA, rval, UN_NCOUNTS,
+ "standard deviation of 1 pixel")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case NCMD_EPADU:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_EPADU)
+ call pargr (apstatr (ap, EPADU))
+ call pargstr (UN_NEPADU)
+ } else {
+ call apsetr (ap, EPADU, rval)
+ if (stid > 1)
+ call ap_rparam (out, KY_EPADU, rval, UN_NEPADU,
+ "photons per adu")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case NCMD_GAIN:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, GAIN, Memc[str], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_GAIN)
+ call pargstr (Memc[str])
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, GAIN, Memc[str])
+ if (im != NULL)
+ call ap_padu (im, ap)
+ if (stid > 1)
+ call ap_sparam (out, KY_GAIN, Memc[str], UN_NKEYWORD,
+ "gain keyword")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case NCMD_CCDREAD:
+ call gargstr (Memc[cmd], SZ_LINE)
+ if (Memc[cmd] == EOS) {
+ call apstats (ap, CCDREAD, Memc[str], SZ_LINE)
+ call printf ("%s = %s\n")
+ call pargstr (KY_CCDREAD)
+ call pargstr (Memc[str])
+ } else {
+ if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0)
+ Memc[str] = EOS
+ call apsets (ap, CCDREAD, Memc[str])
+ if (im != NULL)
+ call ap_rdnoise (im, ap)
+ if (stid > 1)
+ call ap_sparam (out, KY_CCDREAD, Memc[str], UN_NKEYWORD,
+ "read noise keyword")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+ case NCMD_READNOISE:
+ call gargr (rval)
+ if (nscan() == 1) {
+ call printf ("%s = %g %s\n")
+ call pargstr (KY_READNOISE)
+ call pargr (apstatr (ap, READNOISE))
+ call pargstr (UN_NELECTRONS)
+ } else {
+ call apsetr (ap, READNOISE, rval)
+ if (stid > 1)
+ call ap_rparam (out, KY_READNOISE, rval, UN_NELECTRONS,
+ "readout noise")
+ newcenterbuf = YES; newcenter = YES
+ newskybuf = YES; newsky = YES
+ newbuf = YES; newfit = YES
+ }
+
+
+ default:
+ call printf ("Unknown or ambiguous colon command\7\n")
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apnshow.x b/noao/digiphot/apphot/aplib/apnshow.x
new file mode 100644
index 00000000..a0a173a0
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apnshow.x
@@ -0,0 +1,118 @@
+include "../lib/apphot.h"
+include "../lib/noise.h"
+
+# AP_NSHOW -- Procedure to display the current data parameters.
+
+procedure ap_nshow (ap)
+
+pointer ap # pointer to the apphot structure
+
+pointer sp, str1, str2
+bool itob()
+int apstati()
+real apstatr()
+
+begin
+ call smark (sp)
+ call salloc (str1, SZ_LINE, TY_CHAR)
+ call salloc (str2, SZ_LINE, TY_CHAR)
+
+ # Set the object charactersitics.
+ call printf ("\nData Characteristics\n")
+ call apstats (ap, IMNAME, Memc[str1], SZ_FNAME)
+ call printf (" %s: %s (%.2f, %.2f) %s: %g\n")
+ call pargstr (KY_IMNAME)
+ call pargstr (Memc[str1])
+ call pargr (apstatr (ap, CWX))
+ call pargr (apstatr (ap, CWY))
+ call pargstr (KY_SCALE)
+ call pargr (1.0 / apstatr (ap, SCALE))
+
+ call apstats (ap, OUTNAME, Memc[str1], SZ_FNAME)
+ call printf (" %s: %s")
+ call pargstr (KY_OUTNAME)
+ call pargstr (Memc[str1])
+
+ call apstats (ap, CLNAME, Memc[str1], SZ_FNAME)
+ call printf (" %s: %s\n")
+ call pargstr (KY_CLNAME)
+ call pargstr (Memc[str1])
+
+ call printf (" %s = %g %s %s = %b\n")
+ call pargstr (KY_FWHMPSF)
+ call pargr (apstatr (ap, FWHMPSF))
+ call pargstr (UN_ASCALEUNIT)
+ call pargstr (KY_POSITIVE)
+ call pargb (itob (apstati (ap, POSITIVE)))
+
+ call printf (" %s = %g %s %s = %g %s\n")
+ call pargstr (KY_DATAMIN)
+ call pargr (apstatr (ap, DATAMIN))
+ call pargstr (UN_ACOUNTS)
+ call pargstr (KY_DATAMAX)
+ call pargr (apstatr (ap, DATAMAX))
+ call pargstr (UN_ACOUNTS)
+
+ call apstats (ap, EXPOSURE, Memc[str1], SZ_FNAME)
+ call printf (" %s = %s %s = %g %s\n")
+ call pargstr (KY_EXPOSURE)
+ call pargstr (Memc[str1])
+ call pargstr (KY_ITIME)
+ call pargr (apstatr (ap, ITIME))
+ call pargstr (UN_ATIMEUNIT)
+
+ # Set the filter ID.
+ call apstats (ap, FILTER, Memc[str1], SZ_FNAME)
+ call apstats (ap, FILTERID, Memc[str2], SZ_FNAME)
+ call printf (" %s = %s %s = %s\n")
+ call pargstr (KY_FILTER)
+ call pargstr (Memc[str1])
+ call pargstr (KY_FILTERID)
+ call pargstr (Memc[str2])
+
+ # Set the airmass.
+ call apstats (ap, AIRMASS, Memc[str1], SZ_FNAME)
+ call printf (" %s = %s %s = %g\n")
+ call pargstr (KY_AIRMASS)
+ call pargstr (Memc[str1])
+ call pargstr (KY_XAIRMASS)
+ call pargr (apstatr (ap, XAIRMASS))
+
+ # Set the time of observation.
+ call apstats (ap, OBSTIME, Memc[str1], SZ_FNAME)
+ call apstats (ap, OTIME, Memc[str2], SZ_FNAME)
+ call printf (" %s = %s %s = %s\n")
+ call pargstr (KY_OBSTIME)
+ call pargstr (Memc[str1])
+ call pargstr (KY_OTIME)
+ call pargstr (Memc[str2])
+
+ # Set the noise model.
+ call printf ("\nNoise Model\n")
+ call apstats (ap, NSTRING, Memc[str1], SZ_FNAME)
+ call printf (" %s = %s %s %s = %g %s\n")
+ call pargstr (KY_NSTRING)
+ call pargstr (Memc[str1])
+ call pargstr (UN_NMODEL)
+ call pargstr (KY_SKYSIGMA)
+ call pargr (apstatr (ap, SKYSIGMA))
+ call pargstr (UN_NCOUNTS)
+
+ call apstats (ap, GAIN, Memc[str1], SZ_LINE)
+ call printf (" %s = %s %s = %g %s\n")
+ call pargstr (KY_GAIN)
+ call pargstr (Memc[str1])
+ call pargstr (KY_EPADU)
+ call pargr (apstatr (ap, EPADU))
+ call pargstr (UN_NEPADU)
+
+ call apstats (ap, CCDREAD, Memc[str1], SZ_LINE)
+ call printf (" %s = %s %s = %g %s\n")
+ call pargstr (KY_CCDREAD)
+ call pargstr (Memc[str1])
+ call pargstr (KY_READNOISE)
+ call pargr (apstatr (ap, READNOISE))
+ call pargstr (UN_NELECTRONS)
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apotime.x b/noao/digiphot/apphot/aplib/apotime.x
new file mode 100644
index 00000000..2da01e3e
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apotime.x
@@ -0,0 +1,52 @@
+include <imhdr.h>
+include "../lib/apphot.h"
+
+# AP_OTIME -- Fetch the time or epoch of the observation from the image
+# header.
+
+procedure ap_otime (im, ap)
+
+pointer im # pointer to IRAF image
+pointer ap # pointer to apphot structure
+
+char timechar
+int index
+pointer sp, key, otime
+bool streq()
+int strldx()
+
+begin
+ call smark (sp)
+ call salloc (key, SZ_FNAME, TY_CHAR)
+ call salloc (otime, SZ_FNAME, TY_CHAR)
+
+ call apstats (ap, OBSTIME, Memc[key], SZ_FNAME)
+ Memc[otime] = EOS
+ if (Memc[key] == EOS)
+ call apstats (ap, OTIME, Memc[otime], SZ_FNAME)
+ else {
+ iferr {
+ call imgstr (im, Memc[key], Memc[otime], SZ_FNAME)
+ } then {
+ call apstats (ap, OTIME, Memc[otime], SZ_FNAME)
+ call eprintf ("Warning: Image %s Keyword: %s not found\n")
+ call pargstr (IM_HDRFILE(im))
+ call pargstr (Memc[key])
+ }
+ }
+ if (Memc[otime] == EOS) {
+ call apsets (ap, OTIME, "INDEF")
+ } else if (streq ("DATE-OBS", Memc[key]) || streq ("date-obs",
+ Memc[key])) {
+ timechar = 'T'
+ index = strldx (timechar, Memc[otime])
+ if (index > 0)
+ call apsets (ap, OTIME, Memc[otime+index])
+ else
+ call apsets (ap, OTIME, "INDEF")
+ } else {
+ call apsets (ap, OTIME, Memc[otime])
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apoutpars1.x b/noao/digiphot/apphot/aplib/apoutpars1.x
new file mode 100644
index 00000000..c4894bbb
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apoutpars1.x
@@ -0,0 +1,99 @@
+include "../lib/apphot.h"
+include "../lib/noise.h"
+include "../lib/display.h"
+include "../lib/find.h"
+
+
+# AP_DAPARS -- Procedure to write out the current DATAPARS parameters
+# to the current DATAPARS parameter file.
+
+procedure ap_dapars (ap)
+
+pointer ap # pointer to apphot structure
+
+pointer sp, str, np
+bool itob()
+int apstati()
+pointer clopset()
+real apstatr()
+
+begin
+ # Open the parameter sets.
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ np = clopset ("datapars")
+
+ # Set the noise model.
+ call apstats (ap, NSTRING, Memc[str], SZ_FNAME)
+ call clppset (np, "noise", Memc[str])
+
+ # Get the rest of the data dependent parameters.
+ call clppsetr (np, "fwhmpsf", apstatr (ap, FWHMPSF))
+ call clppsetr (np, "scale", 1.0 / apstatr (ap, SCALE))
+ call clppsetb (np, "emission", itob (apstati (ap, POSITIVE)))
+ call clppsetr (np, "datamin", apstatr (ap, DATAMIN))
+ call clppsetr (np, "datamax", apstatr (ap, DATAMAX))
+
+ call clppsetr (np, "sigma", apstatr (ap, SKYSIGMA))
+ call apstats (ap, GAIN, Memc[str], SZ_LINE)
+ call clppset (np, "gain", Memc[str])
+ call clppsetr (np, "epadu", apstatr (ap, EPADU))
+ call apstats (ap, CCDREAD, Memc[str], SZ_LINE)
+ call clppset (np, "ccdread", Memc[str])
+ call clppsetr (np, "readnoise", apstatr (ap, READNOISE))
+
+ call apstats (ap, EXPOSURE, Memc[str], SZ_LINE)
+ call clppset (np, "exposure", Memc[str])
+ call clppsetr (np, "itime", apstatr (ap, ITIME))
+
+ call apstats (ap, AIRMASS, Memc[str], SZ_LINE)
+ call clppset (np, "airmass", Memc[str])
+ call clppsetr (np, "xairmass", apstatr (ap, XAIRMASS))
+
+ call apstats (ap, FILTER, Memc[str], SZ_LINE)
+ call clppset (np, "filter", Memc[str])
+ call apstats (ap, FILTERID, Memc[str], SZ_LINE)
+ call clppset (np, "ifilter", Memc[str])
+
+ call apstats (ap, OBSTIME, Memc[str], SZ_LINE)
+ call clppset (np, "obstime", Memc[str])
+ call apstats (ap, OTIME, Memc[str], SZ_LINE)
+ call clppset (np, "otime", Memc[str])
+
+ # Close the pset files.
+ call clcpset (np)
+ call sfree (sp)
+end
+
+
+# AP_FIPARS -- Procedure to write out the current FINDPARS parameters
+# to the current FINDPARS parameter file.
+
+procedure ap_fipars (ap)
+
+pointer ap # pointer to apphot structure
+
+pointer pp
+bool itob()
+int apstati()
+pointer clopset()
+real apstatr()
+
+begin
+ pp = clopset ("findpars")
+
+ call clppsetr (pp, "nsigma", apstatr (ap, NSIGMA) )
+ call clppsetr (pp, "ratio", apstatr (ap, RATIO))
+ call clppsetr (pp, "theta", apstatr (ap, THETA))
+
+ call clppsetr (pp, "threshold", apstatr (ap, THRESHOLD))
+ call clppsetr (pp, "sharplo", apstatr (ap, SHARPLO))
+ call clppsetr (pp, "sharphi", apstatr (ap, SHARPHI))
+ call clppsetr (pp, "roundlo", apstatr (ap, ROUNDLO))
+ call clppsetr (pp, "roundhi", apstatr (ap, ROUNDHI))
+
+ call clppsetb (pp, "mkdetections", itob (apstati (ap, MKDETECTIONS)))
+
+ call clcpset (pp)
+end
diff --git a/noao/digiphot/apphot/aplib/apoutpars2.x b/noao/digiphot/apphot/aplib/apoutpars2.x
new file mode 100644
index 00000000..79b929c4
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apoutpars2.x
@@ -0,0 +1,146 @@
+include "../lib/display.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+include "../lib/polyphot.h"
+
+
+# AP_CEPARS -- Procedure to write out the current CENTERPARS parameters
+# to the current CENTERPARS parameter file.
+
+procedure ap_cepars (ap)
+
+pointer ap # pointer to apphot structure
+
+pointer sp, str, cp
+bool itob()
+int apstati()
+pointer clopset()
+real apstatr()
+
+begin
+ # Open the parameter set.
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+ cp = clopset ("centerpars")
+
+ # Write the centering parameters.
+ call apstats (ap, CSTRING, Memc[str], SZ_FNAME)
+ call clppset (cp, "calgorithm", Memc[str])
+ call clppsetr (cp, "cbox", 2.0 * apstatr (ap, CAPERT))
+ call clppsetr (cp, "cthreshold", apstatr (ap, CTHRESHOLD))
+ call clppsetr (cp, "minsnratio", apstatr (ap, MINSNRATIO))
+ call clppseti (cp, "cmaxiter", apstati (ap, CMAXITER))
+ call clppsetr (cp, "maxshift", apstatr (ap, MAXSHIFT))
+ call clppsetb (cp, "clean", itob (apstati (ap, CLEAN)))
+ call clppsetr (cp, "rclean", apstatr (ap, RCLEAN))
+ call clppsetr (cp, "rclip", apstatr (ap, RCLIP))
+ call clppsetr (cp, "kclean", apstatr (ap, SIGMACLEAN))
+ call clppsetb (cp, "mkcenter", itob (apstati (ap, MKCENTER)))
+
+ # Close the pset file.
+ call clcpset (cp)
+ call sfree (sp)
+end
+
+
+# AP_SAPARS -- Procedure to write out the current FITSKYPARS parameters
+# to the FITSKYPARS file.
+
+procedure ap_sapars (ap)
+
+pointer ap # pointer to apphot structure
+
+pointer mp, str, sp
+bool itob()
+int apstati()
+pointer clopset()
+real apstatr()
+
+begin
+ # Open the parameter sets.
+ call smark (mp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+ sp = clopset ("fitskypars")
+
+ # Set the sky fitting parameters.
+ call apstats (ap, SSTRING, Memc[str], SZ_FNAME)
+ call clppset (sp, "salgorithm", Memc[str])
+ call clppsetr (sp, "annulus", apstatr (ap, ANNULUS))
+ call clppsetr (sp, "dannulus", apstatr (ap, DANNULUS))
+ call clppsetr (sp, "skyvalue", apstatr (ap, SKY_BACKGROUND))
+ call clppsetr (sp, "khist", apstatr (ap, K1))
+ call clppsetr (sp, "binsize", apstatr (ap, BINSIZE))
+ call clppsetb (sp, "smooth", itob (apstati (ap, SMOOTH)))
+ call clppsetr (sp, "sloclip", apstatr (ap, SLOCLIP))
+ call clppsetr (sp, "shiclip", apstatr (ap, SHICLIP))
+ call clppseti (sp, "smaxiter", apstati (ap, SMAXITER))
+ call clppseti (sp, "snreject", apstati (ap, SNREJECT))
+ call clppsetr (sp, "sloreject", apstatr (ap, SLOREJECT))
+ call clppsetr (sp, "shireject", apstatr (ap, SHIREJECT))
+ call clppsetr (sp, "rgrow", apstatr (ap, RGROW))
+ call clppsetb (sp, "mksky", itob (apstati (ap, MKSKY)))
+
+ # Close up the pset files.
+ call clcpset (sp)
+ call sfree (mp)
+end
+
+
+# AP_PHPARS -- Procedure to write out the PHOTPARS parameters to the
+# PHOTPARS task.
+
+procedure ap_phpars (ap)
+
+pointer ap # pointer to apphot structure
+
+pointer mp, str, pp
+bool itob()
+int apstati()
+pointer clopset()
+real apstatr()
+
+begin
+ # Open the parameter set.
+ call smark (mp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+ pp = clopset ("photpars")
+
+ # Set the photometry parameters.
+ call apstats (ap, APERTS, Memc[str], SZ_LINE)
+ call clppset (pp, "apertures", Memc[str])
+ call clppsetr (pp, "zmag", apstatr (ap, ZMAG))
+ call apstats (ap, PWSTRING, Memc[str], SZ_FNAME)
+ call clppset (pp, "weighting", Memc[str])
+ call clppsetb (pp, "mkapert", itob (apstati (ap, MKAPERT)))
+
+ # Close the pset file.
+ call clcpset (pp)
+ call sfree (mp)
+end
+
+
+# AP_POPARS -- Procedure to write the current POLYPARS parameters to the
+# current POLYPARS parameter file.
+
+procedure ap_popars (ap)
+
+pointer ap # pointer to apphot structure
+
+pointer pp
+bool itob()
+int apstati()
+pointer clopset()
+real apstatr()
+
+begin
+ # Open the psets.
+ pp = clopset ("polypars")
+
+ # Set the photometry parameters.
+ call clppsetr (pp, "zmag", apstatr (ap, PYZMAG))
+ call clppsetb (pp, "mkpolygon", itob (apstati (ap, MKPOLYGON)))
+
+ # Close the pset files.
+ call clcpset (pp)
+end
diff --git a/noao/digiphot/apphot/aplib/appadu.x b/noao/digiphot/apphot/aplib/appadu.x
new file mode 100644
index 00000000..121decaf
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/appadu.x
@@ -0,0 +1,37 @@
+include <imhdr.h>
+include "../lib/noise.h"
+
+# AP_PADU -- Procedure to set the gain parameter for the noise model
+# computation.
+
+procedure ap_padu (im, ap)
+
+pointer im # pointer to IRAF image
+pointer ap # pointer to apphot structure
+
+pointer sp, key
+real padu
+real imgetr(), apstatr()
+
+begin
+ call smark (sp)
+ call salloc (key, SZ_FNAME, TY_CHAR)
+ call apstats (ap, GAIN, Memc[key], SZ_FNAME)
+ if (Memc[key] == EOS)
+ padu = apstatr (ap, EPADU)
+ else {
+ iferr {
+ padu = imgetr (im, Memc[key])
+ } then {
+ padu = apstatr (ap, EPADU)
+ call eprintf ("Warning: Image %s Keyword %s not found.\n")
+ call pargstr (IM_HDRFILE(im))
+ call pargstr (Memc[key])
+ }
+ }
+ if (IS_INDEFR(padu) || padu <= 0.0)
+ call apsetr (ap, EPADU, 1.0)
+ else
+ call apsetr (ap, EPADU, padu)
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apqrad.x b/noao/digiphot/apphot/aplib/apqrad.x
new file mode 100644
index 00000000..6c035d7f
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apqrad.x
@@ -0,0 +1,119 @@
+include <mach.h>
+include "../lib/apphot.h"
+include "../lib/center.h"
+
+define RADIUS 15.0
+define CRADIUS 5
+
+# AP_QRAD -- Simple radial profile plotter.
+
+procedure ap_qrad (ap, im, wx, wy, gd)
+
+pointer ap # pointer to apphot structure
+pointer im # pointero to the IRAF image
+real wx, wy # cursor coordinates
+pointer gd # pointer to graphics stream
+
+real gwx, gwy, xcenter, ycenter, xc, yc, radius, rmin, rmax, imin, imax
+real u1, u2, v1, v2, x1, x2, y1, y2, xold, yold
+pointer gt, sp, pix, coords, index, r, cmd
+int maxpix, npix, nx, ny, wcs, key, niter
+
+real apstatr()
+pointer ap_gtinit()
+int ap_skypix(), clgcur(), apstati()
+int nscan(), scan()
+
+begin
+ # Check for open graphics stream.
+ if (gd == NULL)
+ return
+ call greactivate (gd, 0)
+ call gclear (gd)
+ call gflush (gd)
+
+ # Get the radius of the extraction region.
+ call printf ("Half width of extraction box (%4.1f) pixels:")
+ call pargr (RADIUS)
+ call flush (STDOUT)
+ if (scan () == EOF)
+ radius = RADIUS
+ else {
+ call gargr (radius)
+ if (nscan () < 1)
+ radius = RADIUS
+ }
+ maxpix = (2 * int (radius) + 1) ** 2
+
+ # Allocate temporary space.
+ call smark (sp)
+ call salloc (coords, maxpix, TY_INT)
+ call salloc (index, maxpix, TY_INT)
+ call salloc (pix, maxpix, TY_REAL)
+ call salloc (r, maxpix, TY_REAL)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+
+ # Fit the center using 3 iterations.
+ xold = wx
+ yold = wy
+ niter = 0
+ repeat {
+ call ap_ictr (im, xold, yold, CRADIUS, apstati (ap,
+ POSITIVE), xcenter, ycenter)
+ niter = niter + 1
+ if (abs (xcenter - xold) <= 1.0 && abs (ycenter - yold) <= 1.0)
+ break
+ xold = xcenter
+ yold = ycenter
+ } until (niter >= 3)
+
+ # Fetch the pixels for the radial profile.
+ npix = ap_skypix (im, xcenter, ycenter, 0.0, radius, Memr[pix],
+ Memi[coords], xc, yc, nx, ny)
+ if (npix <= 0) {
+ call gdeactivate (gd, 0)
+ call sfree (sp)
+ return
+ }
+ call ap_index (Memi[index], npix)
+
+
+ # Store old viewport and window coordinates.
+ call ggview (gd, u1, u2, v1, v2)
+ call ggwind (gd, x1, x2, y1, y2)
+
+ # Initialize the plot and store the viewport and window limits.
+ #call apstats (ap, IMNAME, Memc[cmd], SZ_FNAME)
+ call apstats (ap, IMROOT, Memc[cmd], SZ_FNAME)
+ call ap_ltov (im, xcenter, ycenter, xcenter, ycenter, 1)
+ gt = ap_gtinit (Memc[cmd], xcenter, ycenter)
+
+ # Compute the radius values.
+ call ap_xytor (Memi[coords], Memi[index], Memr[r], npix, xc, yc, nx)
+ call alimr (Memr[r], npix, rmin, rmax)
+ call alimr (Memr[pix], npix, imin, imax)
+
+ # Plot radial profiles.
+ call gclear (gd)
+ call ap_rset (gd, gt, 0.0, rmax, imin, imax, apstatr (ap, SCALE))
+ call ap_plotrad (gd, gt, Memr[r], Memr[pix], npix, "plus")
+
+ # Go into cursor mode.
+ call printf ("Waiting for cursor mode command: [:.help=help,q=quit]")
+ while (clgcur ("gcommands", gwx, gwy, wcs, key, Memc[cmd], SZ_LINE) !=
+ EOF) {
+ if (key == 'q')
+ break
+ call printf (
+ "Waiting for cursor mode command: [:.help=help,q=quit]")
+ }
+
+ # Restore old window and viewport coordinates.
+ call gsview (gd, u1, u2, v1, v2)
+ call gswind (gd, x1, x2, y1, y2)
+
+ # Free plots and working space.
+ call ap_gtfree (gt)
+ call sfree (sp)
+ call gdeactivate (gd, 0)
+end
diff --git a/noao/digiphot/apphot/aplib/aprcursor1.x b/noao/digiphot/apphot/aplib/aprcursor1.x
new file mode 100644
index 00000000..594cbbeb
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/aprcursor1.x
@@ -0,0 +1,584 @@
+include "../lib/apphot.h"
+include "../lib/noise.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+
+
+# AP_CFWHMPSF -- Read the fwhmpsf from the radial profile plot.
+
+real procedure ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # sequence number in output file
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, fwhmpsf, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vfwhmpsf()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the FWHM of the PSF on the plot.
+ call printf ("Mark half-width half-maximum of the psf (%g) pixels:")
+ call pargr (apstatr (ap, FWHMPSF) * scale / 2.0)
+ call gscur (gd, apstatr (ap, FWHMPSF) * scale / 2.0, (imin + imax) /
+ 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk <= 0.0 || xjunk > rmax)
+ fwhmpsf = apstatr (ap, FWHMPSF)
+ else
+ fwhmpsf = 2.0 * xjunk / scale
+
+ # Verify the results.
+ call apsetr (ap, FWHMPSF, fwhmpsf)
+ fwhmpsf = ap_vfwhmpsf (ap)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT,
+ "full width half maximum of the psf")
+
+ call sfree (sp)
+
+ return (fwhmpsf)
+end
+
+
+# AP_CDATAMIN -- Read the good data minimum off the radial profile plot.
+
+real procedure ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # sequence number in output file
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real datamin, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vdatamin()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+
+ # Mark the datamin on the plot.
+ call printf ("Mark the good data minimum (%g) counts:")
+ call pargr (apstatr (ap, DATAMIN))
+ if (IS_INDEFR (apstatr (ap, DATAMIN)))
+ call gscur (gd, (rmin + rmax) / 2.0, imin - 1.0)
+ else
+ call gscur (gd, (rmin + rmax) / 2.0, apstatr (ap, DATAMIN))
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || yjunk < imin || yjunk > imax)
+ datamin = apstatr (ap, DATAMIN)
+ else
+ datamin = yjunk
+
+ # Verify the results.
+ call apsetr (ap, DATAMIN, datamin)
+ datamin = ap_vdatamin (ap)
+
+ # Store the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS,
+ "minimum good data value")
+ call sfree (sp)
+
+ return (datamin)
+end
+
+
+# AP_CDATAMAX -- Read the good data maximum off the radial profile plot.
+
+real procedure ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # sequence number in output file
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real datamax, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vdatamax()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+
+ # Mark the datamax on the plot.
+ call printf ("Mark the good data maximum (%g) counts:")
+ call pargr (apstatr (ap, DATAMAX))
+ if (IS_INDEFR (apstatr (ap, DATAMAX)))
+ call gscur (gd, (rmin + rmax) / 2.0, imax + 1.0)
+ else
+ call gscur (gd, (rmin + rmax) / 2.0, apstatr (ap, DATAMAX))
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || yjunk < imin || yjunk > imax)
+ datamax = apstatr (ap, DATAMAX)
+ else
+ datamax = yjunk
+
+ # Verify the result.
+ call apsetr (ap, DATAMAX, datamax)
+ datamax = ap_vdatamax (ap)
+
+ # Store the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS,
+ "maximum good data value")
+ call sfree (sp)
+
+ return (datamax)
+end
+
+
+# AP_CCAPERT -- Read the centering aperture of the radial profile plot.
+
+real procedure ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # output file sequence number
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, capert, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vcapert()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the centering aperture on the plot.
+ call printf ("Mark centering box half width (%g) pixels:")
+ call pargr (apstatr (ap, CAPERT) * scale)
+ call gscur (gd, apstatr (ap, CAPERT) * scale, (imin + imax) / 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk <= 0.0 || xjunk > rmax)
+ capert = apstatr (ap, CAPERT)
+ else
+ capert = xjunk / scale
+
+ # Verify the results.
+ call apsetr (ap, CAPERT, capert)
+ capert = ap_vcapert (ap)
+
+ # Store the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_CAPERT, 2.0 * capert, UN_CSCALEUNIT,
+ "centering box width")
+ call sfree (sp)
+
+ return (capert)
+end
+
+
+# AP_CRCLEAN -- Read the cleaning radius off the radial profile plot.
+
+real procedure ap_crclean (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # sequence number in output file
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, rclean, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vrclean()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the cleaning radius on the plot.
+ call printf (
+ "Mark the centering algorithm cleaning radius (%g) pixels:")
+ call pargr (apstatr (ap, RCLEAN) * scale)
+ call gscur (gd, apstatr (ap, RCLEAN) * scale, (imin + imax) /
+ 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk <= 0.0 || xjunk > rmax)
+ rclean = apstatr (ap, RCLEAN)
+ else
+ rclean = xjunk / scale
+
+ # Verify the results.
+ call apsetr (ap, RCLEAN, rclean)
+ rclean = ap_vrclean (ap)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_RCLEAN, rclean, UN_CSCALEUNIT,
+ "cleaning radius")
+ call sfree (sp)
+
+ return (rclean)
+end
+
+
+# AP_CRCLIP -- Read the clipping radius off the radial profile plot.
+
+real procedure ap_crclip (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # sequence number in output file
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, rclip, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vrclip()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark clipping radius on the plot.
+ call printf (
+ "Mark the centering algorithm clipping radius (%g) pixels:")
+ call pargr (apstatr (ap, RCLIP) * scale)
+ call gscur (gd, apstatr (ap, RCLIP) * scale, (imin + imax) /
+ 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk <= 0.0 || xjunk > rmax)
+ rclip = apstatr (ap, RCLIP)
+ else
+ rclip = xjunk / scale
+
+ # Verify the results.
+ call apsetr (ap, RCLIP, rclip)
+ rclip = ap_vrclip (ap)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_RCLIP, rclip, UN_CSCALEUNIT,
+ "clipping radius")
+ call sfree (sp)
+
+ return (rclip)
+end
+
+
+# AP_CANNULUS -- Read the sky annulus of the radial profile plot.
+
+real procedure ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # output file sequence number
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, annulus, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vannulus()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the inner sky radius.
+ call printf ("Mark inner sky radius (%g) pixels:")
+ call pargr (apstatr (ap, ANNULUS) * apstatr (ap, SCALE))
+ call gscur (gd, apstatr (ap, ANNULUS) * apstatr (ap, SCALE),
+ (imin + imax) / 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk < 0.0 || xjunk > rmax)
+ annulus = apstatr (ap, ANNULUS)
+ else
+ annulus = xjunk / scale
+
+ # Verify the result.
+ call apsetr (ap, ANNULUS, annulus)
+ annulus = ap_vannulus (ap)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT,
+ "radius of the inner sky annulus")
+ call sfree (sp)
+
+ return (annulus)
+end
+
+
+# AP_CRGROW -- Read the region growing radius off the radial profile plot.
+
+real procedure ap_crgrow (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # the output file descriptor
+int stid # output file sequence number
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, rgrow, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vrgrow()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the inner sky radius.
+ call printf ("Mark region growing radius (%g) pixels:")
+ call pargr (apstatr (ap, RGROW) * apstatr (ap, SCALE))
+ call gscur (gd, apstatr (ap, RGROW) * apstatr (ap, SCALE),
+ (imin + imax) / 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk < 0.0 || xjunk > rmax)
+ rgrow = apstatr (ap, RGROW)
+ else
+ rgrow = xjunk / scale
+
+ # Verify the region growing radius.
+ call apsetr (ap, RGROW, rgrow)
+ rgrow = ap_vrgrow (ap)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_RGROW, rgrow, UN_SSCALEUNIT,
+ "region growing radius")
+ call sfree (sp)
+
+ return (rgrow)
+end
+
+
+# AP_CDANNULUS -- Read the sky annulus width off the radial profile plot.
+
+real procedure ap_cdannulus (ap, gd, out, stid, annulus, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # output file sequence number
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, annulus, dannulus, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vdannulus()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the outer sky radius.
+ call printf ("Mark outer sky radius (%g) pixels:")
+ call pargr (apstatr (ap, SCALE) * (apstatr (ap, ANNULUS) +
+ apstatr (ap, DANNULUS)))
+ call gscur (gd, apstatr (ap, SCALE) * (apstatr (ap, ANNULUS) +
+ apstatr (ap, DANNULUS)), (imin + imax) / 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || (xjunk / scale < annulus) || xjunk > rmax)
+ dannulus = apstatr (ap, DANNULUS)
+ else
+ dannulus = (xjunk / scale - annulus)
+
+ # Verify the width of the annulus.
+ call apsetr (ap, DANNULUS, dannulus)
+ dannulus = ap_vdannulus (ap)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT,
+ "width of the sky annulus")
+ call sfree (sp)
+
+ return (dannulus)
+end
+
+
+# AP_CSIGMA -- Read the sky sigma from the radial profile plot.
+
+real procedure ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # sequence number in output file
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real mean, sigma3, xjunk, yjunk
+int clgcur()
+int apstati()
+real apstatr(), ap_vsigma()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+
+ # Estimate the mean sky.
+ if (apstati (ap, POSITIVE) == YES)
+ mean = imin
+ else
+ mean = imax
+ call printf ("Estimate sky sigma. Mark mean sky level (%g):")
+ call pargr (mean)
+ call gscur (gd, (rmin + rmax) / 2.0, mean)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || yjunk < imin || yjunk > imax)
+ mean = mean
+ else
+ mean = yjunk
+
+ # Estimate the sky sigma.
+ if (IS_INDEFR (apstatr (ap, SKYSIGMA)))
+ sigma3 = INDEFR
+ else
+ sigma3 = 3.0 * apstatr (ap, SKYSIGMA)
+ call printf ("Next mark 3 sigma sky level (%g):")
+ call pargr (sigma3)
+ if (IS_INDEFR(sigma3))
+ call gscur (gd, (rmin + rmax) / 2.0, imin - 1.0)
+ else
+ call gscur (gd, (rmin + rmax) / 2.0, mean + sigma3)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || yjunk < imin || yjunk > imax) {
+ sigma3 = apstatr (ap, SKYSIGMA)
+ if (! IS_INDEFR (sigma3))
+ sigma3 = 3.0 * sigma3
+ } else
+ sigma3 = abs (yjunk - mean)
+
+ # Verify the results.
+ if (IS_INDEFR(sigma3))
+ call apsetr (ap, SKYSIGMA, INDEFR)
+ else
+ call apsetr (ap, SKYSIGMA, sigma3 / 3.0)
+ sigma3 = ap_vsigma (ap)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_SKYSIGMA, sigma3, UN_NCOUNTS,
+ "standard deviation of 1 sky pixel")
+
+ call sfree (sp)
+
+ if (IS_INDEFR(sigma3))
+ return (sigma3)
+ else
+ return (sigma3 / 3.0)
+end
+
+
+# AP_CAPER -- Read the apertures off the radial profile plot.
+
+procedure ap_caper (ap, gd, out, stid, outstr, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # output file number sequence
+char outstr[ARB] # output apertures
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int i, wcs, key, naperts
+pointer sp, cmd, tstr, aperts
+real scale, xjunk, yjunk
+int clgcur()
+int apstati(), strlen()
+real apstatr()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ call salloc (tstr, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Get the apertures.
+ naperts = apstati (ap, NAPERTS)
+ call salloc (aperts, naperts, TY_REAL)
+ call ap_arrayr (ap, APERTS, Memr[aperts])
+
+ # Encode the old aperture string.
+ outstr[1] = EOS
+ do i = 1, naperts - 1 {
+ call sprintf (outstr[1+strlen(outstr)], SZ_FNAME,"%.2f,")
+ call pargr (Memr[aperts+i-1] * scale)
+ }
+ call sprintf (outstr[1+strlen(outstr)], SZ_FNAME,"%.2f")
+ call pargr (Memr[aperts+naperts-1] * scale)
+
+ # Type prompt string.
+ call printf ("Mark apertures (%s) pixels [q=quit]:")
+ call pargstr (outstr)
+ call gscur (gd, Memr[aperts] * scale, (imin + imax) / 2.0)
+
+ # Mark the apertures.
+ outstr[1] = EOS
+ Memc[tstr] = EOS
+ while (clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd],
+ SZ_LINE) != EOF) {
+ if (key == 'q')
+ break
+ if (xjunk <= 0.0 || xjunk > rmax)
+ next
+ call sprintf (outstr[1+strlen(outstr)], SZ_FNAME,"%.2f,")
+ call pargr (xjunk / scale)
+ call sprintf (Memc[tstr+strlen(Memc[tstr])], SZ_FNAME,"%.2f,")
+ call pargr (xjunk)
+ call printf ("Mark apertures (%s) pixels [q=quit]:")
+ call pargstr (Memc[tstr])
+ }
+ outstr[strlen(outstr)] = EOS
+
+ # Verify the results.
+ call apsets (ap, APERTS, outstr)
+ call ap_vaperts (ap, outstr, SZ_LINE)
+
+ # Save the results.
+ if (out != NULL && stid > 1)
+ call ap_sparam (out, KY_APERTS, outstr, UN_PSCALEUNIT,
+ "list of aperture radii")
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/aprcursor2.x b/noao/digiphot/apphot/aplib/aprcursor2.x
new file mode 100644
index 00000000..e24049b5
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/aprcursor2.x
@@ -0,0 +1,144 @@
+include "../lib/apphot.h"
+include "../lib/radprof.h"
+include "../lib/fitpsf.h"
+
+# AP_CRPROF -- Read the radial profile size off the radial profile plot.
+
+real procedure ap_crprof (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # output file sequence number
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, radius, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vrpradius()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Estimate the minimum (maximum) data level.
+ # Mark maximum radius of the radial profile.
+ call printf ("Mark maximum radius for profile (%g) pixels:")
+ call pargr (apstatr (ap, RPRADIUS) * scale)
+ call gscur (gd, apstatr (ap, RPRADIUS) * scale, (imin + imax) / 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk < 0.0 || xjunk > rmax)
+ radius = apstatr (ap, RPRADIUS)
+ else
+ radius = xjunk / scale
+
+ # Verify the results.
+ call apsetr (ap, RPRADIUS, radius)
+ radius = ap_vrpradius (ap)
+
+ # Store the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_RPRADIUS, radius, UN_RSCALEUNIT,
+ "fitting radius")
+
+ call sfree (sp)
+
+ return (radius)
+end
+
+
+# AP_CRPSTEP -- Read the radial profile size off the radial profile plot.
+
+real procedure ap_crpstep (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # output file sequence number
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, step, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vstep()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the radial profile step size.
+ call printf ("Mark step size (%g) pixels:")
+ call pargr (apstatr (ap, RPSTEP) * scale)
+ call gscur (gd, apstatr (ap, RPSTEP) * scale, (imin + imax) / 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk < 0.0 || xjunk > rmax)
+ step = apstatr (ap, RPSTEP)
+ else
+ step = xjunk / scale
+
+ # Verify the results.
+ call apsetr (ap, RPSTEP, step)
+ step = ap_vstep (ap)
+
+ # Store the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_RPSTEP, step, UN_RSCALEUNIT,
+ "step size in pixels")
+
+ call sfree (sp)
+
+ return (step)
+end
+
+
+# AP_CPAPERT -- Read the fitting radius on the radial profile plot.
+
+real procedure ap_cpapert (ap, gd, out, stid, rmin, rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer gd # pointer to the grapics stream
+int out # output file descriptor
+int stid # output file sequence number
+real rmin, rmax # x axis limits
+real imin, imax # y axis limits
+
+int wcs, key, stat
+pointer sp, cmd
+real scale, psfapert, xjunk, yjunk
+int clgcur()
+real apstatr(), ap_vpsfapert()
+
+begin
+ call smark (sp)
+ call salloc (cmd, SZ_LINE, TY_CHAR)
+ scale = apstatr (ap, SCALE)
+
+ # Mark the fitting radius on the plot.
+ call printf ("Mark fitting box half width (%g) pixels:")
+ call pargr (apstatr (ap, PSFAPERT) * scale)
+ call gscur (gd, apstatr (ap, PSFAPERT) * scale, (imin + imax) / 2.0)
+ stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE)
+ if (stat == EOF || xjunk <= 0.0 || xjunk > rmax)
+ psfapert = apstatr (ap, PSFAPERT)
+ else
+ psfapert = xjunk / scale
+
+ # Verify the results.
+ call apsetr (ap, PSFAPERT, psfapert)
+ psfapert = ap_vpsfapert (ap)
+
+ # Store the results.
+ if (out != NULL && stid > 1)
+ call ap_rparam (out, KY_PSFAPERT, 2.0 * psfapert, UN_PSFSCALEUNIT,
+ "width of the fitting box")
+
+ call sfree (sp)
+
+ return (psfapert)
+end
diff --git a/noao/digiphot/apphot/aplib/aprdnoise.x b/noao/digiphot/apphot/aplib/aprdnoise.x
new file mode 100644
index 00000000..e4fbda2c
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/aprdnoise.x
@@ -0,0 +1,36 @@
+include <imhdr.h>
+include "../lib/noise.h"
+
+# AP_RDNOISE - Procedure to set the image read noise parameter.
+
+procedure ap_rdnoise (im, ap)
+
+pointer im # pointer to IRAF image
+pointer ap # pointer to apphot structure
+
+pointer sp, key
+real rdnoise
+real imgetr(), apstatr()
+
+begin
+ call smark (sp)
+ call salloc (key, SZ_FNAME, TY_CHAR)
+ call apstats (ap, CCDREAD, Memc[key], SZ_FNAME)
+ if (Memc[key] == EOS)
+ rdnoise = apstatr (ap, READNOISE)
+ else {
+ iferr {
+ rdnoise = imgetr (im, Memc[key])
+ } then {
+ rdnoise = apstatr (ap, READNOISE)
+ call eprintf ("Warning: Image %s Keyword %s not found.\n")
+ call pargstr (IM_HDRFILE(im))
+ call pargstr (Memc[key])
+ }
+ }
+ if (IS_INDEFR(rdnoise) || rdnoise <= 0.0)
+ call apsetr (ap, READNOISE, 0.0)
+ else
+ call apsetr (ap, READNOISE, rdnoise)
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apset.x b/noao/digiphot/apphot/aplib/apset.x
new file mode 100644
index 00000000..2248f561
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apset.x
@@ -0,0 +1,72 @@
+define MAXERR1 500
+define MAXERR2 1000
+
+
+# APSETS -- Procedure to set an apphot string parameter.
+
+procedure apsets (ap, param, str)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+char str[ARB] # string parameter
+
+begin
+ if (param <= MAXERR1)
+ call ap1sets (ap, param, str)
+ else if (param <= MAXERR2)
+ call ap2sets (ap, param, str)
+end
+
+
+# APSETI -- Procedure to set an integer apphot parameter.
+
+procedure apseti (ap, param, ival)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+int ival # integer value
+
+begin
+ if (param <= MAXERR1)
+ call ap1seti (ap, param, ival)
+ else if (param <= MAXERR2)
+ call ap2seti (ap, param, ival)
+ else
+ call error (0, "Unknown APPHOT integer parameter")
+end
+
+
+# APSETR -- Procedure to set a real apphot parameter.
+
+procedure apsetr (ap, param, rval)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+real rval # real value
+
+begin
+ if (param <= MAXERR1)
+ call ap1setr (ap, param, rval)
+ else if (param <= MAXERR2)
+ call ap2setr (ap, param, rval)
+ else
+ call error (0, "Unknown APPHOT real parameter")
+end
+
+
+# APSETD -- Procedure to set a double apphot parameter.
+
+procedure apsetd (ap, param, dval)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+double dval # double value
+
+begin
+ if (param <= MAXERR1)
+ call ap1setd (ap, param, dval)
+ else if (param <= MAXERR2)
+ call ap2setd (ap, param, dval)
+ else
+ call error (0, "Unknown APPHOT double parameter")
+end
diff --git a/noao/digiphot/apphot/aplib/apset1.x b/noao/digiphot/apphot/aplib/apset1.x
new file mode 100644
index 00000000..6c4d6f1b
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apset1.x
@@ -0,0 +1,330 @@
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/centerdef.h"
+include "../lib/center.h"
+include "../lib/fitskydef.h"
+include "../lib/fitsky.h"
+include "../lib/photdef.h"
+include "../lib/phot.h"
+include "../lib/fitpsfdef.h"
+include "../lib/fitpsf.h"
+
+# AP1SETS -- Procedure to set an apphot string parameter.
+
+procedure ap1sets (ap, param, str)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+char str[ARB] # string parameter
+
+int naperts
+pointer ctr, sky, phot, psf
+real aperts[MAX_NAPERTS]
+int ap_getaperts()
+
+begin
+ ctr = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+ case IMNAME:
+ call strcpy (str, AP_IMNAME(ap), SZ_FNAME)
+ case IMROOT:
+ call strcpy (str, AP_IMROOT(ap), SZ_FNAME)
+ case CLNAME:
+ call strcpy (str, AP_CLNAME(ap), SZ_FNAME)
+ case CLROOT:
+ call strcpy (str, AP_CLROOT(ap), SZ_FNAME)
+ case PLOTFILE:
+ call strcpy (str, AP_PLOTFILE(ap), SZ_FNAME)
+ case OUTNAME:
+ call strcpy (str, AP_OUTNAME(ap), SZ_FNAME)
+ case EXPOSURE:
+ call strcpy (str, AP_EXPOSURE(ap), SZ_FNAME)
+ case AIRMASS:
+ call strcpy (str, AP_AIRMASS(ap), SZ_FNAME)
+ case FILTER:
+ call strcpy (str, AP_FILTER(ap), SZ_FNAME)
+ case FILTERID:
+ call strcpy (str, AP_FILTERID(ap), SZ_FNAME)
+ case OBSTIME:
+ call strcpy (str, AP_OBSTIME(ap), SZ_FNAME)
+ case OTIME:
+ call strcpy (str, AP_OTIME(ap), SZ_FNAME)
+
+ case CSTRING:
+ call strcpy (str, AP_CSTRING(ctr), SZ_FNAME)
+
+ case SSTRING:
+ call strcpy (str, AP_SSTRING(sky), SZ_FNAME)
+
+ case APSTRING:
+ call strcpy (str, AP_APSTRING(phot), SZ_FNAME)
+ case APERTS:
+ naperts = ap_getaperts (str, aperts, MAX_NAPERTS)
+ if (naperts > 0) {
+ call strcpy (str, AP_APSTRING(phot), SZ_LINE)
+ AP_NAPERTS(phot) = naperts
+ call realloc (AP_APERTS(phot), AP_NAPERTS(phot), TY_REAL)
+ call realloc (AP_AREA(phot), AP_NAPERTS(phot), TY_DOUBLE)
+ call realloc (AP_SUMS(phot), AP_NAPERTS(phot), TY_DOUBLE)
+ call realloc (AP_MAGS(phot), AP_NAPERTS(phot), TY_REAL)
+ call realloc (AP_MAGERRS(phot), AP_NAPERTS(phot), TY_REAL)
+ call amovr (aperts, Memr[AP_APERTS(phot)], AP_NAPERTS(phot))
+ call asrtr (Memr[AP_APERTS(phot)], Memr[AP_APERTS(phot)],
+ AP_NAPERTS(phot))
+ }
+ case PWSTRING:
+ call strcpy (str, AP_PWSTRING(phot), SZ_FNAME)
+
+ case PSFSTRING:
+ call strcpy (str, AP_PSFSTRING(psf), SZ_FNAME)
+
+ default:
+ call error (0, "APSETS: Unknown apphot string parameter")
+ }
+end
+
+
+# AP1SETI -- Procedure to set an integer apphot parameter.
+
+procedure ap1seti (ap, param, ival)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+int ival # integer value
+
+pointer cen, sky, phot, psf
+
+begin
+ cen = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+ case POSITIVE:
+ AP_POSITIVE(ap) = ival
+ case WCSIN:
+ AP_WCSIN(ap) = ival
+ case WCSOUT:
+ AP_WCSOUT(ap) = ival
+ case MW:
+ AP_MW(ap) = ival
+ case CTIN:
+ AP_CTIN(ap) = ival
+ case CTOUT:
+ AP_CTOUT(ap) = ival
+
+ case CENTERFUNCTION:
+ AP_CENTERFUNCTION(cen) = ival
+ case CLEAN:
+ AP_CLEAN(cen) = ival
+ case CMAXITER:
+ AP_CMAXITER(cen) = ival
+
+ case SKYFUNCTION:
+ AP_SKYFUNCTION(sky) = ival
+ case SMAXITER:
+ AP_SMAXITER(sky) = ival
+ case SNREJECT:
+ AP_SNREJECT(sky) = ival
+ case SMOOTH:
+ AP_SMOOTH(sky) = ival
+ case NSKY:
+ AP_NSKY(sky) = ival
+ case NSKY_REJECT:
+ AP_NSKY_REJECT(sky) = ival
+
+ case PWEIGHTS:
+ AP_PWEIGHTS(phot) = ival
+
+ case PSFUNCTION:
+ AP_PSFUNCTION(psf) = ival
+ case NPARS:
+ AP_PSFNPARS(psf) = ival
+ case MAXNPARS:
+ AP_MAXNPARS(psf) = ival
+ case PMAXITER:
+ AP_PMAXITER(psf) = ival
+ case PNREJECT:
+ AP_PNREJECT(psf) = ival
+
+ default:
+ call error (0, "APSETI: Unknown apphot integer parameter")
+ }
+end
+
+
+# AP1SETR -- Procedure to set a real apphot parameter.
+
+procedure ap1setr (ap, param, rval)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+real rval # real value
+
+pointer cen, sky, phot, psf
+
+begin
+ cen = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+
+ case FWHMPSF:
+ AP_FWHMPSF(ap) = rval
+ case SCALE:
+ AP_SCALE(ap) = rval
+ case WX:
+ AP_WX(ap) = rval
+ case WY:
+ AP_WY(ap) = rval
+ case ITIME:
+ AP_ITIME(ap) = rval
+ case CWX:
+ AP_CWX(ap) = rval
+ case CWY:
+ AP_CWY(ap) = rval
+ case DATAMIN:
+ AP_DATAMIN(ap) = rval
+ case DATAMAX:
+ AP_DATAMAX(ap) = rval
+ case XAIRMASS:
+ AP_XAIRMASS(ap) = rval
+
+ case CDATALIMIT:
+ AP_CDATALIMIT(cen) = rval
+ case XSHIFT:
+ AP_XSHIFT(cen) = rval
+ case YSHIFT:
+ AP_YSHIFT(cen) = rval
+ case OXSHIFT:
+ AP_OXSHIFT(cen) = rval
+ case OYSHIFT:
+ AP_OYSHIFT(cen) = rval
+ case CXCUR:
+ AP_CXCUR(cen) = rval
+ case CYCUR:
+ AP_CYCUR(cen) = rval
+ case CAPERT:
+ AP_CAPERT(cen) = rval
+ case CTHRESHOLD:
+ AP_CTHRESHOLD(cen) = rval
+ case MAXSHIFT:
+ AP_MAXSHIFT(cen) = rval
+ case MINSNRATIO:
+ AP_MINSNRATIO(cen) = rval
+ case RCLEAN:
+ AP_RCLEAN(cen) = rval
+ case RCLIP:
+ AP_RCLIP(cen) = rval
+ case SIGMACLEAN:
+ AP_SIGMACLEAN(cen) = rval
+ case OXINIT:
+ AP_OXINIT(cen) = rval
+ case OYINIT:
+ AP_OYINIT(cen) = rval
+ case XCENTER:
+ AP_XCENTER(cen) = rval
+ case YCENTER:
+ AP_YCENTER(cen) = rval
+ case OXCENTER:
+ AP_OXCENTER(cen) = rval
+ case OYCENTER:
+ AP_OYCENTER(cen) = rval
+ case XERR:
+ AP_XERR(cen) = rval
+ case YERR:
+ AP_YERR(cen) = rval
+
+ case ANNULUS:
+ AP_ANNULUS(sky) = rval
+ case DANNULUS:
+ AP_DANNULUS(sky) = rval
+ case SXCUR:
+ AP_SXCUR(sky) = rval
+ case SYCUR:
+ AP_SYCUR(sky) = rval
+ case OSXCUR:
+ AP_OSXCUR(sky) = rval
+ case OSYCUR:
+ AP_OSYCUR(sky) = rval
+ case K1:
+ AP_K1(sky) = rval
+ case SLOREJECT:
+ AP_SLOREJECT(sky) = rval
+ case SHIREJECT:
+ AP_SHIREJECT(sky) = rval
+ case SLOCLIP:
+ AP_SLOCLIP(sky) = rval
+ case SHICLIP:
+ AP_SHICLIP(sky) = rval
+ case BINSIZE:
+ AP_BINSIZE(sky) = rval
+ case RGROW:
+ AP_RGROW(sky) = rval
+ case SKY_BACKGROUND:
+ AP_SKYBACKGROUND(sky) = rval
+ case SKY_MODE:
+ AP_SKY_MODE(sky) = rval
+ case SKY_SIGMA:
+ AP_SKY_SIG(sky) = rval
+ case SKY_SKEW:
+ AP_SKY_SKEW(sky) = rval
+
+ case PXCUR:
+ AP_PXCUR(phot) = rval
+ case PYCUR:
+ AP_PYCUR(phot) = rval
+ case OPXCUR:
+ AP_OPXCUR(phot) = rval
+ case OPYCUR:
+ AP_OPYCUR(phot) = rval
+ case ZMAG:
+ AP_ZMAG(phot) = rval
+
+ case PK2:
+ AP_PK2(psf) = rval
+ case PSFAPERT:
+ AP_PSFAPERT(psf) = rval
+ case PFXCUR:
+ AP_PFXCUR(psf) = rval
+ case PFYCUR:
+ AP_PFYCUR(psf) = rval
+ case OPFXCUR:
+ AP_OPFXCUR(psf) = rval
+ case OPFYCUR:
+ AP_OPFYCUR(psf) = rval
+
+ default:
+ call error (0, "APSETR: Unknown apphot real parameter")
+ }
+end
+
+
+# AP1SETD -- Procedure to set a double apphot parameter.
+
+procedure ap1setd (ap, param, dval)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+double dval # double value
+
+pointer cen, sky, phot, psf
+
+begin
+ cen = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+ default:
+ call error (0, "APSETD: Unknown apphot double parameter")
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apset2.x b/noao/digiphot/apphot/aplib/apset2.x
new file mode 100644
index 00000000..85200daf
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apset2.x
@@ -0,0 +1,227 @@
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/displaydef.h"
+include "../lib/display.h"
+include "../lib/noisedef.h"
+include "../lib/noise.h"
+include "../lib/polyphotdef.h"
+include "../lib/polyphot.h"
+include "../lib/radprofdef.h"
+include "../lib/radprof.h"
+include "../lib/finddef.h"
+include "../lib/find.h"
+
+# AP2SETS -- Procedure to set an apphot string parameter.
+
+procedure ap2sets (ap, param, str)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+char str[ARB] # string parameter
+
+pointer nse, ply
+
+begin
+ nse = AP_NOISE(ap)
+ ply = AP_POLY(ap)
+
+ switch (param) {
+ case PYNAME:
+ call strcpy (str, AP_PYNAME(ply), SZ_FNAME)
+ case PYROOT:
+ call strcpy (str, AP_PYROOT(ply), SZ_FNAME)
+ case GAIN:
+ call strcpy (str, AP_GAIN(nse), SZ_FNAME)
+ case NSTRING:
+ call strcpy (str, AP_NSTRING(nse), SZ_FNAME)
+ case CCDREAD:
+ call strcpy (str, AP_CCDREAD(nse), SZ_FNAME)
+ default:
+ call error (0, "APSETS: Unknown apphot string parameter")
+ }
+end
+
+
+# AP2SETI -- Procedure to set an integer apphot parameter.
+
+procedure ap2seti (ap, param, ival)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+int ival # integer value
+
+pointer dsp, nse, ply, rprof
+
+begin
+ nse = AP_NOISE(ap)
+ dsp = AP_PDISPLAY(ap)
+ ply = AP_POLY(ap)
+ rprof = AP_RPROF(ap)
+
+ switch (param) {
+ case RPORDER:
+ AP_RPORDER(rprof) = ival
+ case RPNREJECT:
+ AP_RPNREJECT(rprof) = ival
+ case PYNVER:
+ AP_PYNVER(ply) = ival
+ case PYBADPIX:
+ AP_PYBADPIX(ply) = ival
+ case MKSKY:
+ AP_MKSKY(dsp) = ival
+ case MKCENTER:
+ AP_MKCENTER(dsp) = ival
+ case MKAPERT:
+ AP_MKAPERT(dsp) = ival
+ case MKPOLYGON:
+ AP_MKPOLYGON(dsp) = ival
+ case MKDETECTIONS:
+ AP_MKDETECTIONS(dsp) = ival
+ case NOISEFUNCTION:
+ AP_NOISEFUNCTION(nse) = ival
+ case MKPSFBOX:
+ AP_MKPSFBOX(dsp) = ival
+ case RADPLOTS:
+ AP_RADPLOTS(dsp) = ival
+ case RPNPTS:
+ AP_RPNPTS(rprof) = ival
+ case RPNDATA:
+ AP_RPNDATA(rprof) = ival
+ case RPNDATAREJ:
+ AP_RPNDATAREJ(rprof) = ival
+ default:
+ call error (0, "APSETI: Unknown apphot integer parameter")
+ }
+end
+
+
+# AP2SETR -- Procedure to set a real apphot parameter.
+
+procedure ap2setr (ap, param, rval)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+real rval # real value
+
+pointer nse, ply, rprof, fnd
+
+begin
+ nse = AP_NOISE(ap)
+ ply = AP_POLY(ap)
+ rprof = AP_RPROF(ap)
+ fnd = AP_PFIND(ap)
+
+ switch (param) {
+ case RPFWHM:
+ AP_RPFWHM(rprof) = rval
+ case INORM:
+ AP_INORM(rprof) = rval
+ case TNORM:
+ AP_TINORM(rprof) = rval
+ case DNORM:
+ AP_DNORM(rprof) = rval
+ case RPXCUR:
+ AP_RPXCUR(rprof) = rval
+ case RPYCUR:
+ AP_RPYCUR(rprof) = rval
+ case ORPXCUR:
+ AP_ORPXCUR(rprof) = rval
+ case ORPYCUR:
+ AP_ORPYCUR(rprof) = rval
+ case RPRADIUS:
+ AP_RPRADIUS(rprof) = rval
+ AP_RPNPTS(rprof) = int (AP_RPRADIUS(rprof) / AP_RPSTEP(rprof)) + 1
+ call realloc (AP_RPDIST(rprof), AP_RPNPTS(rprof), TY_REAL)
+ call realloc (AP_INTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL)
+ call realloc (AP_DINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL)
+ call realloc (AP_TINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL)
+ case RPSTEP:
+ AP_RPSTEP(rprof) = rval
+ AP_RPNPTS(rprof) = int (AP_RPRADIUS(rprof) / AP_RPSTEP(rprof)) + 1
+ call realloc (AP_RPDIST(rprof), AP_RPNPTS(rprof), TY_REAL)
+ call realloc (AP_INTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL)
+ call realloc (AP_DINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL)
+ call realloc (AP_TINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL)
+ case RPKSIGMA:
+ AP_RPKSIGMA(rprof) = rval
+ case PYZMAG:
+ AP_PYZMAG(ply) = rval
+ case PYMAG:
+ AP_PYMAG(ply) = rval
+ case PYMAGERR:
+ AP_PYMAGERR(ply) = rval
+ case PYX:
+ AP_PYX(ply) = rval
+ case PYY:
+ AP_PYY(ply) = rval
+ case PYMINRAD:
+ AP_PYMINRAD(ply) = rval
+ case PYCX:
+ AP_PYCX(ply) = rval
+ case PYCY:
+ AP_PYCY(ply) = rval
+ case OPYCX:
+ AP_OPYCX(ply) = rval
+ case OPYCY:
+ AP_OPYCY(ply) = rval
+ case PYXMEAN:
+ AP_PYXMEAN(ply) = rval
+ case PYYMEAN:
+ AP_PYYMEAN(ply) = rval
+ case OPYXMEAN:
+ AP_OPYXMEAN(ply) = rval
+ case OPYYMEAN:
+ AP_OPYYMEAN(ply) = rval
+ case SKYSIGMA:
+ AP_SKYSIGMA(nse) = rval
+ case EPADU:
+ AP_EPADU(nse) = rval
+ case READNOISE:
+ AP_READNOISE(nse) = rval
+ case THRESHOLD:
+ AP_THRESHOLD(fnd) = rval
+ case RATIO:
+ AP_RATIO(fnd) = rval
+ case THETA:
+ AP_THETA(fnd) = rval
+ case NSIGMA:
+ AP_NSIGMA(fnd) = rval
+ case SHARPLO:
+ AP_SHARPLO(fnd) = rval
+ case SHARPHI:
+ AP_SHARPHI(fnd) = rval
+ case ROUNDLO:
+ AP_ROUNDLO(fnd) = rval
+ case ROUNDHI:
+ AP_ROUNDHI(fnd) = rval
+ default:
+ call error (0, "APSETR: Unknown apphot real parameter")
+ }
+end
+
+
+# AP2SETD -- Procedure to set a double apphot parameter.
+
+procedure ap2setd (ap, param, dval)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+double dval # double value
+
+pointer nse, ply, rprof, fnd
+
+begin
+ nse = AP_NOISE(ap)
+ ply = AP_POLY(ap)
+ rprof = AP_RPROF(ap)
+ fnd = AP_PFIND(ap)
+
+ switch (param) {
+ case PYNPIX:
+ AP_PYNPIX(ply) = dval
+ case PYFLUX:
+ AP_PYFLUX(ply) = dval
+ default:
+ call error (0, "APSETD: Unknown apphot double parameter")
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apshowplot.x b/noao/digiphot/apphot/aplib/apshowplot.x
new file mode 100644
index 00000000..ed188d52
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apshowplot.x
@@ -0,0 +1,83 @@
+include "../lib/apphot.h"
+
+define RADIUS 15.0
+define CRADIUS 5
+
+# AP_SHOWPLOT -- Plot a radial profile of a star.
+
+int procedure ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin,
+ rmax, imin, imax)
+
+pointer ap # pointer to the apphot structure
+pointer im # pointer to the image
+real wx, wy # the cursor coordinates
+pointer gd # pointer to the graphics stream
+real xcenter, ycenter # the centered coordinates
+real rmin, rmax # minimum and maximum radius
+real imin, imax # minimum and maximum intensity
+
+real radius, xc, yc, xold, yold
+pointer sp, r, skypix, coords, index, str, gt
+int niter, lenbuf, nx, ny, nsky
+
+real apstatr()
+pointer ap_gtinit()
+int ap_gvrad(), apstati(), ap_skypix()
+
+begin
+ call gclear (gd)
+ call gflush (gd)
+
+ # Set the pixel extraction parameters.
+ lenbuf = ap_gvrad (RADIUS, radius)
+
+ # Initialize.
+ call smark (sp)
+ call salloc (r, lenbuf, TY_REAL)
+ call salloc (skypix, lenbuf, TY_REAL)
+ call salloc (coords, lenbuf, TY_INT)
+ call salloc (index, lenbuf, TY_INT)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Center the star.
+ niter = 0
+ xold = wx
+ yold = wy
+ repeat {
+ call ap_ictr (im, xold, yold, CRADIUS, apstati (ap, POSITIVE),
+ xcenter, ycenter)
+ niter = niter + 1
+ if (abs (xcenter - xold) <= 1.0 && abs (ycenter - yold) <= 1.0)
+ break
+ xold = xcenter
+ yold = ycenter
+ } until (niter >= 3)
+
+ # Fetch the pixels.
+ nsky = ap_skypix (im, xcenter, ycenter, 0.0, radius, Memr[skypix],
+ Memi[coords], xc, yc, nx, ny)
+ if (nsky <= 0) {
+ call sfree (sp)
+ return (ERR)
+ }
+ call ap_index (Memi[index], nsky)
+
+ # Compute the radius and intensity values.
+ call ap_xytor (Memi[coords], Memi[index], Memr[r], nsky, xc, yc, nx)
+ call alimr (Memr[r], nsky, rmin, rmax)
+ call alimr (Memr[skypix], nsky, imin, imax)
+
+ # Plot the radial profiles.
+ #call apstats (ap, IMNAME, Memc[str], SZ_FNAME)
+ call apstats (ap, IMROOT, Memc[str], SZ_FNAME)
+ call ap_ltov (im, xcenter, ycenter, xc, yc, 1)
+ gt = ap_gtinit (Memc[str], xc, yc)
+ call ap_rset (gd, gt, 0.0, rmax, imin, imax, apstatr (ap, SCALE))
+ call ap_plotrad (gd, gt, Memr[r], Memr[skypix], nsky, "plus")
+
+ # Cleanup.
+ call ap_gtfree (gt)
+ call sfree (sp)
+
+ return (OK)
+end
diff --git a/noao/digiphot/apphot/aplib/apstat.x b/noao/digiphot/apphot/aplib/apstat.x
new file mode 100644
index 00000000..9ddc98ca
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apstat.x
@@ -0,0 +1,77 @@
+define MAXERR1 500
+define MAXERR2 1000
+
+# APSTATS -- Procedure to fetch an apphot string parameter.
+
+procedure apstats (ap, param, str, maxch)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+char str[ARB] # string
+int maxch # maximum number of characters
+
+begin
+ if (param <= MAXERR1)
+ call ap1stats (ap, param, str, maxch)
+ else if (param <= MAXERR2)
+ call ap2stats (ap, param, str, maxch)
+ else
+ call error (0, "APSTATS: Unknown apphot string parameter")
+end
+
+
+# APSTATI -- Procedure to set an integer apphot parameter.
+
+int procedure apstati (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+int ap1stati(), ap2stati()
+
+begin
+ if (param <= MAXERR1)
+ return (ap1stati (ap, param))
+ else if (param <= MAXERR2)
+ return (ap2stati (ap, param))
+ else
+ call error (0, "APSTATI: Unknown apphot integer parameter")
+end
+
+
+# APSTATR -- Procedure to set a real apphot parameter.
+
+real procedure apstatr (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+real ap1statr(), ap2statr()
+
+begin
+ if (param <= MAXERR1)
+ return (ap1statr (ap, param))
+ else if (param <= MAXERR2)
+ return (ap2statr (ap, param))
+ else
+ call error (0, "APSTATR: Unknown apphot real parameter")
+end
+
+
+# APSTATD -- Procedure to set a double apphot parameter.
+
+double procedure apstatd (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+double ap1statd(), ap2statd()
+
+begin
+ if (param <= MAXERR1)
+ return (ap1statd (ap, param))
+ else if (param <= MAXERR2)
+ return (ap2statd (ap, param))
+ else
+ call error (0, "APSTATD: Unknown apphot double parameter")
+end
diff --git a/noao/digiphot/apphot/aplib/apstat1.x b/noao/digiphot/apphot/aplib/apstat1.x
new file mode 100644
index 00000000..0df220ae
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apstat1.x
@@ -0,0 +1,316 @@
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/centerdef.h"
+include "../lib/center.h"
+include "../lib/fitskydef.h"
+include "../lib/fitsky.h"
+include "../lib/photdef.h"
+include "../lib/phot.h"
+include "../lib/fitpsfdef.h"
+include "../lib/fitpsf.h"
+
+# AP1STATS -- Procedure to fetch an apphot string parameter.
+
+procedure ap1stats (ap, param, str, maxch)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+char str[ARB] # string
+int maxch # maximum number of characters
+
+pointer cen, sky, phot, psf
+
+begin
+ cen = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+ case IMNAME:
+ call strcpy (AP_IMNAME(ap), str, maxch)
+ case IMROOT:
+ call strcpy (AP_IMROOT(ap), str, maxch)
+ case CLNAME:
+ call strcpy (AP_CLNAME(ap), str, maxch)
+ case CLROOT:
+ call strcpy (AP_CLROOT(ap), str, maxch)
+ case PLOTFILE:
+ call strcpy (AP_PLOTFILE(ap), str, maxch)
+ case OUTNAME:
+ call strcpy (AP_OUTNAME(ap), str, maxch)
+ case EXPOSURE:
+ call strcpy (AP_EXPOSURE(ap), str, maxch)
+ case AIRMASS:
+ call strcpy (AP_AIRMASS(ap), str, maxch)
+ case FILTER:
+ call strcpy (AP_FILTER(ap), str, maxch)
+ case FILTERID:
+ call strcpy (AP_FILTERID(ap), str, maxch)
+ case OBSTIME:
+ call strcpy (AP_OBSTIME(ap), str, maxch)
+ case OTIME:
+ call strcpy (AP_OTIME(ap), str, maxch)
+
+ case CSTRING:
+ call strcpy (AP_CSTRING(cen), str, maxch)
+
+ case SSTRING:
+ call strcpy (AP_SSTRING(sky), str, maxch)
+
+ case APSTRING:
+ call strcpy (AP_APSTRING(phot), str, maxch)
+ case APERTS:
+ call strcpy (AP_APSTRING(phot), str, maxch)
+ case PWSTRING:
+ call strcpy (AP_PWSTRING(phot), str, maxch)
+
+ case PSFSTRING:
+ call strcpy (AP_PSFSTRING(psf), str, maxch)
+
+ default:
+ call error (0, "APSTATS: Unknown apphot string parameter")
+ }
+end
+
+
+# AP1STATI -- Procedure to set an integer apphot parameter.
+
+int procedure ap1stati (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+pointer cen, sky, phot, psf
+
+begin
+ cen = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+ case POSITIVE:
+ return (AP_POSITIVE(ap))
+ case WCSIN:
+ return (AP_WCSIN(ap))
+ case WCSOUT:
+ return (AP_WCSOUT(ap))
+ case MW:
+ return (AP_MW(ap))
+ case CTIN:
+ return (AP_CTIN(ap))
+ case CTOUT:
+ return (AP_CTOUT(ap))
+
+ case CENTERFUNCTION:
+ return (AP_CENTERFUNCTION(cen))
+ case CLEAN:
+ return (AP_CLEAN(cen))
+ case CMAXITER:
+ return (AP_CMAXITER(cen))
+
+ case SKYFUNCTION:
+ return (AP_SKYFUNCTION(sky))
+ case SMAXITER:
+ return (AP_SMAXITER(sky))
+ case SNREJECT:
+ return (AP_SNREJECT(sky))
+ case SMOOTH:
+ return (AP_SMOOTH(sky))
+ case NSKY:
+ return (AP_NSKY(sky))
+ case NSKY_REJECT:
+ return (AP_NSKY_REJECT(sky))
+
+ case NAPERTS:
+ return (AP_NAPERTS(phot))
+ case PWEIGHTS:
+ return (AP_PWEIGHTS(phot))
+
+ case MAXNPARS:
+ return (AP_MAXNPARS(psf))
+ case NPARS:
+ return (AP_PSFNPARS(psf))
+ case PMAXITER:
+ return (AP_PMAXITER(psf))
+ case PSFUNCTION:
+ return (AP_PSFUNCTION(psf))
+ case PNREJECT:
+ return (AP_PNREJECT(psf))
+
+ default:
+ call error (0, "APSTATI: Unknown apphot integer parameter")
+ }
+end
+
+
+# AP1STATR -- Procedure to set a real apphot parameter.
+
+real procedure ap1statr (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+pointer cen, sky, phot, psf
+
+begin
+ cen = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+
+ case FWHMPSF:
+ return (AP_FWHMPSF(ap))
+ case SCALE:
+ return (AP_SCALE(ap))
+ case WX:
+ return (AP_WX(ap))
+ case WY:
+ return (AP_WY(ap))
+ case ITIME:
+ return (AP_ITIME(ap))
+ case CWX:
+ return (AP_CWX(ap))
+ case CWY:
+ return (AP_CWY(ap))
+ case DATAMIN:
+ return (AP_DATAMIN(ap))
+ case DATAMAX:
+ return (AP_DATAMAX(ap))
+ case XAIRMASS:
+ return (AP_XAIRMASS(ap))
+
+ case CDATALIMIT:
+ return (AP_CDATALIMIT(cen))
+ case XSHIFT:
+ return (AP_XSHIFT(cen))
+ case YSHIFT:
+ return (AP_YSHIFT(cen))
+ case OXSHIFT:
+ return (AP_OXSHIFT(cen))
+ case OYSHIFT:
+ return (AP_OYSHIFT(cen))
+ case CXCUR:
+ return (AP_CXCUR(cen))
+ case CYCUR:
+ return (AP_CYCUR(cen))
+ case CAPERT:
+ return (AP_CAPERT(cen))
+ case CTHRESHOLD:
+ return (AP_CTHRESHOLD(cen))
+ case MAXSHIFT:
+ return (AP_MAXSHIFT(cen))
+ case MINSNRATIO:
+ return (AP_MINSNRATIO(cen))
+ case RCLEAN:
+ return (AP_RCLEAN(cen))
+ case RCLIP:
+ return (AP_RCLIP(cen))
+ case SIGMACLEAN:
+ return (AP_SIGMACLEAN(cen))
+
+ case OXINIT:
+ return (AP_OXINIT(cen))
+ case OYINIT:
+ return (AP_OYINIT(cen))
+ case XCENTER:
+ return (AP_XCENTER(cen))
+ case YCENTER:
+ return (AP_YCENTER(cen))
+ case OXCENTER:
+ return (AP_OXCENTER(cen))
+ case OYCENTER:
+ return (AP_OYCENTER(cen))
+ case XERR:
+ return (AP_XERR(cen))
+ case YERR:
+ return (AP_YERR(cen))
+
+ case SXCUR:
+ return (AP_SXCUR(sky))
+ case SYCUR:
+ return (AP_SYCUR(sky))
+ case OSXCUR:
+ return (AP_OSXCUR(sky))
+ case OSYCUR:
+ return (AP_OSYCUR(sky))
+ case ANNULUS:
+ return (AP_ANNULUS(sky))
+ case DANNULUS:
+ return (AP_DANNULUS(sky))
+ case K1:
+ return (AP_K1(sky))
+ case SLOREJECT:
+ return (AP_SLOREJECT(sky))
+ case SHIREJECT:
+ return (AP_SHIREJECT(sky))
+ case SLOCLIP:
+ return (AP_SLOCLIP(sky))
+ case SHICLIP:
+ return (AP_SHICLIP(sky))
+ case BINSIZE:
+ return (AP_BINSIZE(sky))
+ case RGROW:
+ return (AP_RGROW(sky))
+ case SKY_BACKGROUND:
+ return (AP_SKYBACKGROUND(sky))
+ case SKY_MODE:
+ return (AP_SKY_MODE(sky))
+ case SKY_SIGMA:
+ return (AP_SKY_SIG(sky))
+ case SKY_SKEW:
+ return (AP_SKY_SKEW(sky))
+
+ case PXCUR:
+ return (AP_PXCUR(phot))
+ case PYCUR:
+ return (AP_PYCUR(phot))
+ case OPXCUR:
+ return (AP_OPXCUR(phot))
+ case OPYCUR:
+ return (AP_OPYCUR(phot))
+ case ZMAG:
+ return (AP_ZMAG(phot))
+
+ case PSFAPERT:
+ return (AP_PSFAPERT(psf))
+ case PK2:
+ return (AP_PK2(psf))
+ case PFXCUR:
+ return (AP_PFXCUR(psf))
+ case PFYCUR:
+ return (AP_PFYCUR(psf))
+ case OPFXCUR:
+ return (AP_OPFXCUR(psf))
+ case OPFYCUR:
+ return (AP_OPFYCUR(psf))
+
+ default:
+ call error (0, "APSTATR: Unknown apphot real parameter")
+ }
+end
+
+
+# AP1STATD -- Procedure to set a double apphot parameter.
+
+double procedure ap1statd (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+pointer cen, sky, phot, psf
+
+begin
+ cen = AP_PCENTER(ap)
+ sky = AP_PSKY(ap)
+ phot = AP_PPHOT(ap)
+ psf = AP_PPSF(ap)
+
+ switch (param) {
+ default:
+ call error (0, "APSTATD: Unknown apphot double parameter")
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apstat2.x b/noao/digiphot/apphot/aplib/apstat2.x
new file mode 100644
index 00000000..032b19e5
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apstat2.x
@@ -0,0 +1,215 @@
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/displaydef.h"
+include "../lib/display.h"
+include "../lib/noisedef.h"
+include "../lib/noise.h"
+include "../lib/polyphotdef.h"
+include "../lib/polyphot.h"
+include "../lib/radprofdef.h"
+include "../lib/radprof.h"
+include "../lib/finddef.h"
+include "../lib/find.h"
+
+# AP2STATS -- Procedure to fetch an apphot string parameter.
+
+procedure ap2stats (ap, param, str, maxch)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+char str[ARB] # string
+int maxch # maximum number of characters
+
+pointer nse, ply
+
+begin
+ nse = AP_NOISE(ap)
+ ply = AP_POLY(ap)
+
+ switch (param) {
+ case PYNAME:
+ call strcpy (AP_PYNAME(ply), str, maxch)
+ case PYROOT:
+ call strcpy (AP_PYROOT(ply), str, maxch)
+ case GAIN:
+ call strcpy (AP_GAIN(nse), str, maxch)
+ case NSTRING:
+ call strcpy (AP_NSTRING(nse), str, maxch)
+ case CCDREAD:
+ call strcpy (AP_CCDREAD(nse), str, maxch)
+ default:
+ call error (0, "APSTATS: Unknown apphot string parameter")
+ }
+end
+
+
+# AP2STATI -- Procedure to set an integer apphot parameter.
+
+int procedure ap2stati (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+pointer dsp, nse, ply, rprof
+
+begin
+ dsp = AP_PDISPLAY(ap)
+ nse = AP_NOISE(ap)
+ ply = AP_POLY(ap)
+ rprof = AP_RPROF(ap)
+
+ switch (param) {
+ case RPORDER:
+ return (AP_RPORDER(rprof))
+ case RPNREJECT:
+ return (AP_RPNREJECT(rprof))
+ case PYNVER:
+ return (AP_PYNVER(ply))
+ case PYBADPIX:
+ return (AP_PYBADPIX(ply))
+ case MKSKY:
+ return (AP_MKSKY(dsp))
+ case MKCENTER:
+ return (AP_MKCENTER(dsp))
+ case MKAPERT:
+ return (AP_MKAPERT(dsp))
+ case MKPOLYGON:
+ return (AP_MKPOLYGON(dsp))
+ case MKDETECTIONS:
+ return (AP_MKDETECTIONS(dsp))
+ case NOISEFUNCTION:
+ return (AP_NOISEFUNCTION(nse))
+ case MKPSFBOX:
+ return (AP_MKPSFBOX(dsp))
+ case RADPLOTS:
+ return (AP_RADPLOTS(dsp))
+ case RPNPTS:
+ return (AP_RPNPTS(rprof))
+ case RPNDATA:
+ return (AP_RPNDATA(rprof))
+ case RPNDATAREJ:
+ return (AP_RPNDATAREJ(rprof))
+ default:
+ call error (0, "APSTATI: Unknown apphot integer parameter")
+ }
+end
+
+
+# AP2STATR -- Procedure to set a real apphot parameter.
+
+real procedure ap2statr (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+pointer nse, ply, rprof, fnd
+
+begin
+ nse = AP_NOISE(ap)
+ ply = AP_POLY(ap)
+ rprof = AP_RPROF(ap)
+ fnd = AP_PFIND(ap)
+
+ switch (param) {
+ case RPFWHM:
+ return (AP_RPFWHM(rprof))
+ case INORM:
+ return (AP_INORM(rprof))
+ case TNORM:
+ return (AP_TINORM(rprof))
+ case DNORM:
+ return (AP_DNORM(rprof))
+ case RPXCUR:
+ return (AP_RPXCUR(rprof))
+ case RPYCUR:
+ return (AP_RPYCUR(rprof))
+ case ORPXCUR:
+ return (AP_ORPXCUR(rprof))
+ case ORPYCUR:
+ return (AP_ORPYCUR(rprof))
+ case RPRADIUS:
+ return (AP_RPRADIUS(rprof))
+ case RPSTEP:
+ return (AP_RPSTEP(rprof))
+ case RPKSIGMA:
+ return (AP_RPKSIGMA(rprof))
+ case PYZMAG:
+ return (AP_PYZMAG(ply))
+ case PYMAG:
+ return (AP_PYMAG(ply))
+ case PYMAGERR:
+ return (AP_PYMAGERR(ply))
+ case PYX:
+ return (AP_PYX(ply))
+ case PYY:
+ return (AP_PYY(ply))
+ case PYMINRAD:
+ return (AP_PYMINRAD(ply))
+ case PYXMEAN:
+ return (AP_PYXMEAN(ply))
+ case PYYMEAN:
+ return (AP_PYYMEAN(ply))
+ case OPYXMEAN:
+ return (AP_OPYXMEAN(ply))
+ case OPYYMEAN:
+ return (AP_OPYYMEAN(ply))
+ case PYCX:
+ return (AP_PYCX(ply))
+ case PYCY:
+ return (AP_PYCY(ply))
+ case OPYCX:
+ return (AP_OPYCX(ply))
+ case OPYCY:
+ return (AP_OPYCY(ply))
+ case SKYSIGMA:
+ return (AP_SKYSIGMA(nse))
+ case EPADU:
+ return (AP_EPADU(nse))
+ case READNOISE:
+ return (AP_READNOISE(nse))
+ case THRESHOLD:
+ return (AP_THRESHOLD(fnd))
+ case RATIO:
+ return (AP_RATIO(fnd))
+ case THETA:
+ return (AP_THETA(fnd))
+ case NSIGMA:
+ return (AP_NSIGMA(fnd))
+ case SHARPLO:
+ return (AP_SHARPLO(fnd))
+ case SHARPHI:
+ return (AP_SHARPHI(fnd))
+ case ROUNDLO:
+ return (AP_ROUNDLO(fnd))
+ case ROUNDHI:
+ return (AP_ROUNDHI(fnd))
+ default:
+ call error (0, "APSTATR: Unknown apphot real parameter")
+ }
+end
+
+
+# AP2STATD -- Procedure to set a double apphot parameter.
+
+double procedure ap2statd (ap, param)
+
+pointer ap # pointer to apphot structure
+int param # parameter
+
+pointer nse, ply, rprof, fnd
+
+begin
+ nse = AP_NOISE(ap)
+ ply = AP_POLY(ap)
+ rprof = AP_RPROF(ap)
+ fnd = AP_PFIND(ap)
+
+ switch (param) {
+ case PYNPIX:
+ return (AP_PYNPIX(ply))
+ case PYFLUX:
+ return (AP_PYFLUX(ply))
+ default:
+ call error (0, "APSTATD: Unknown apphot double parameter")
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apverify1.x b/noao/digiphot/apphot/aplib/apverify1.x
new file mode 100644
index 00000000..1ecd04b6
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apverify1.x
@@ -0,0 +1,582 @@
+include <math.h>
+include "../lib/apphot.h"
+include "../lib/noise.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+
+# AP_GVRAD -- Verify or get the radius of the extraction box.
+
+int procedure ap_gvrad (defradius, radius)
+
+real defradius # the default radius
+real radius # the output radius
+
+int lenbuf
+int scan(), nscan()
+
+begin
+ call printf (
+ "Radius of extraction box in pixels (%4.1f) (CR or value): ")
+ call pargr (defradius)
+ call flush (STDOUT)
+
+ if (scan () == EOF)
+ radius = defradius
+ else {
+ call gargr (radius)
+ if (nscan () < 1)
+ radius = defradius
+ }
+ lenbuf = PI * radius * (radius + 1.0)
+
+ return (lenbuf)
+end
+
+
+# AP_VFWHMPSF -- Verify the full width maximum of the psf.
+
+real procedure ap_vfwhmpsf (ap)
+
+pointer ap # pointer to the apphot structure
+
+real scale, fwhmpsf
+int scan(), nscan()
+real apstatr()
+
+begin
+ scale = apstatr (ap, SCALE)
+ call printf ("FWHM of features in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, FWHMPSF))
+ call flush (STDOUT)
+
+ # Confirm the fwhmpsf.
+ if (scan() == EOF)
+ fwhmpsf = apstatr (ap, FWHMPSF)
+ else {
+ call gargr (fwhmpsf)
+ if (nscan () != 1)
+ fwhmpsf = apstatr (ap, FWHMPSF)
+ }
+
+ call printf ("\tNew FWHM of features: %g scale units %g pixels\n")
+ call pargr (fwhmpsf)
+ call pargr (scale * fwhmpsf)
+ call apsetr (ap, FWHMPSF, fwhmpsf)
+
+ return (fwhmpsf)
+end
+
+
+# AP_VDATAMIN-- Verify the minimum good data value.
+
+real procedure ap_vdatamin (ap)
+
+pointer ap # pointer to the apphot structure
+
+real datamin
+int scan(), nscan()
+real apstatr()
+
+begin
+ # Confirm the threshold parameter.
+ call printf ("Minimum good data value (%g) (CR or value): ")
+ call pargr (apstatr (ap, DATAMIN))
+ call flush (STDOUT)
+ if (scan() == EOF)
+ datamin = apstatr (ap, DATAMIN)
+ else {
+ call gargr (datamin)
+ if (nscan () != 1)
+ datamin = apstatr (ap, DATAMIN)
+ }
+
+ call printf ("\tNew minimum good data value: %g counts\n")
+ call pargr (datamin)
+ call apsetr (ap, DATAMIN, datamin)
+
+ return (datamin)
+end
+
+
+# AP_VDATAMAX-- Verify the maximum good data value.
+
+real procedure ap_vdatamax (ap)
+
+pointer ap # pointer to the apphot structure
+
+real datamax
+int scan(), nscan()
+real apstatr()
+
+begin
+ # Confirm the threshold parameter.
+ call printf ("Maximum good data value (%g) (CR or value): ")
+ call pargr (apstatr (ap, DATAMAX))
+ call flush (STDOUT)
+ if (scan() == EOF)
+ datamax = apstatr (ap, DATAMAX)
+ else {
+ call gargr (datamax)
+ if (nscan () != 1)
+ datamax = apstatr (ap, DATAMAX)
+ }
+
+ call printf ("\tNew maximum good data value: %g counts\n")
+ call pargr (datamax)
+ call apsetr (ap, DATAMAX, datamax)
+
+ return (datamax)
+end
+
+
+# AP_VSIGMA -- Verify the standard deviation of the sky
+
+real procedure ap_vsigma (ap)
+
+pointer ap # pointer to the apphot structure
+
+real skysigma
+int scan(), nscan()
+real apstatr()
+
+begin
+ # Confirm the sky sigma parameter.
+ call printf (
+ "Standard deviation of background in counts (%g) (CR or value): ")
+ call pargr (apstatr (ap, SKYSIGMA))
+ call flush (STDOUT)
+ if (scan() == EOF)
+ skysigma = apstatr (ap, SKYSIGMA)
+ else {
+ call gargr (skysigma)
+ if (nscan () != 1)
+ skysigma = apstatr (ap, SKYSIGMA)
+ }
+
+ call printf ("\tNew standard deviation of background: %g counts\n")
+ call pargr (skysigma)
+ call apsetr (ap, SKYSIGMA, skysigma)
+
+ return (skysigma)
+end
+
+
+# AP_VCSTRING -- Verify the centering string.
+
+procedure ap_vcstring (ap, str, maxch)
+
+pointer ap # pointer to the apphot strucuture
+char str[ARB] # output string
+int maxch # maximum number of characters
+
+int cfunc
+int scan(), strdic(), nscan()
+
+begin
+ # Print the old centering algorithm.
+ call apstats (ap, CSTRING, str, maxch)
+ call printf ("Centering algorithm (%s) (CR or value): ")
+ call pargstr (str)
+ call flush (STDOUT)
+
+ # Confirm the centering algorithm.
+ if (scan() != EOF) {
+ call gargwrd (str, maxch)
+ cfunc = strdic (str, str, maxch, CFUNCS)
+ if (nscan () == 1 && cfunc > 0) {
+ call apseti (ap, CENTERFUNCTION, cfunc)
+ call apsets (ap, CSTRING, str)
+ }
+ }
+
+ # Print the new result.
+ call apstats (ap, CSTRING, str, maxch)
+ call printf ("\tNew centering algorithm: %s\n")
+ call pargstr (str)
+end
+
+
+# AP_VCAPERT -- Verify the centering aperture.
+
+real procedure ap_vcapert (ap)
+
+pointer ap # pointert to the apphot strucuture
+
+real scale, capert
+int scan(), nscan()
+real apstatr()
+
+begin
+ # Get the apphot scale factor.
+ scale = apstatr (ap, SCALE)
+
+ # Print the old centering value.
+ call printf ("Centering box width in scale units (%g) (CR or value): ")
+ call pargr (2.0 * apstatr (ap, CAPERT))
+ call flush (STDOUT)
+
+ # Get the new centering value.
+ if (scan() == EOF)
+ capert = 2.0 * apstatr (ap, CAPERT)
+ else {
+ call gargr (capert)
+ if (nscan () != 1)
+ capert = 2.0 * apstatr (ap, CAPERT)
+ }
+
+ # Type the new value.
+ call apsetr (ap, CAPERT, capert / 2.0)
+ call printf ("\tNew centering box width: %g scale units %g pixels\n")
+ call pargr (capert)
+ call pargr (scale * capert)
+
+ return (capert / 2.0)
+end
+
+
+# AP_VCTHRESHOLD -- Verify the centering threshold parameter.
+
+real procedure ap_vcthreshold (ap)
+
+pointer ap # pointer to the apphot structure
+
+real skysigma, cthreshold
+int scan(), nscan()
+real apstatr()
+
+begin
+ # Get the sky sigma.
+ skysigma = apstatr (ap, SKYSIGMA)
+
+ # Print the old centering threshold.
+ call printf (
+ "Centering threshold in sigma above data minimum (%g) (CR or value): ")
+ call pargr (apstatr (ap, CTHRESHOLD))
+ call flush (STDOUT)
+
+ # Confirm the centering threshold parameter.
+ if (scan() == EOF)
+ cthreshold = apstatr (ap, CTHRESHOLD)
+ else {
+ call gargr (cthreshold)
+ if (nscan () != 1)
+ cthreshold = apstatr (ap, CTHRESHOLD)
+ }
+
+ # Print the new centering threshold.
+ call apsetr (ap, CTHRESHOLD, cthreshold)
+ call printf ("\tNew centering threshold: %g skysigma %g counts\n")
+ call pargr (cthreshold)
+ if (IS_INDEFR(skysigma))
+ call pargr (INDEFR)
+ else
+ call pargr (cthreshold * skysigma)
+
+ return (cthreshold)
+end
+
+
+# AP_VRCLEAN -- Verify the cleaning radius
+
+real procedure ap_vrclean (ap)
+
+pointer ap # pointer to the apphot structure
+
+real scale, rclean
+int scan(), nscan()
+real apstatr()
+
+begin
+ # Confirm the cleaning radius.
+ scale = apstatr (ap, SCALE)
+ call printf ("Cleaning radius in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, RCLEAN))
+ call flush (STDOUT)
+ if (scan() == EOF)
+ rclean = apstatr (ap, RCLEAN)
+ else {
+ call gargr (rclean)
+ if (nscan () != 1)
+ rclean = apstatr (ap, RCLEAN)
+ }
+
+ call apsetr (ap, RCLEAN, rclean)
+ call printf ("\tNew cleaning radius: %g scale units %g pixels\n")
+ call pargr (rclean)
+ call pargr (scale * rclean)
+
+ return (rclean)
+end
+
+
+# AP_VRCLIP -- Verify the clipping radius.
+
+real procedure ap_vrclip (ap)
+
+pointer ap # pointer to the apphot structure
+
+real scale, rclip
+int scan(), nscan()
+real apstatr()
+
+begin
+ # Confirm the clipping radius.
+ scale = apstatr (ap, SCALE)
+ call printf ("Clipping radius in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, RCLIP))
+ call flush (STDOUT)
+ if (scan() == EOF)
+ rclip = apstatr (ap, RCLIP)
+ else {
+ call gargr (rclip)
+ if (nscan () != 1)
+ rclip = apstatr (ap, RCLIP)
+ }
+
+ call apsetr (ap, RCLIP, rclip)
+ call printf ("\tNew FWHM clipping radius: %g scale units %g pixels\n")
+ call pargr (rclip)
+ call pargr (scale * rclip)
+
+ return (rclip)
+end
+
+
+# AP_VSSTRING -- Verify the sky fitting algorithm string.
+
+procedure ap_vsstring (ap, str, maxch)
+
+pointer ap # pointer to the apphot structure
+char str[ARB] # output string
+int maxch # maximum number of characteristics
+
+int sfunc
+int scan(), nscan(), strdic()
+
+begin
+ # Print the old salgorithm string.
+ call apstats (ap, SSTRING, str, maxch)
+ call printf ("Sky fitting algorithm (%s) (CR or value): ")
+ call pargstr (str)
+ call flush (STDOUT)
+
+ # Confirm the sky fitting algorithm.
+ if (scan() != EOF) {
+ call gargwrd (str, maxch)
+ sfunc = strdic (str, str, maxch, SFUNCS)
+ if (nscan () == 1 && sfunc > 0) {
+ call apseti (ap, SKYFUNCTION, sfunc)
+ call apsets (ap, SSTRING, str)
+ }
+ }
+
+ # Print the new salgorithm string.
+ call apstats (ap, SSTRING, str, maxch)
+ call printf ("\tSky fitting algorithm: %s\n")
+ call pargstr (str)
+end
+
+
+# AP_VANNULUS -- Verify the inner radius of sky annulus.
+
+real procedure ap_vannulus (ap)
+
+pointer ap # pointer to the apphot structure
+
+real scale, annulus
+int scan(), nscan()
+real apstatr()
+
+begin
+ scale = apstatr (ap, SCALE)
+
+ # Print the old inner sky radius value.
+ call printf (
+ "Inner radius of sky annulus in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, ANNULUS))
+ call flush (STDOUT)
+
+ # Verify the new value.
+ if (scan () == EOF)
+ annulus = apstatr (ap, ANNULUS)
+ else {
+ call gargr (annulus)
+ if (nscan () != 1)
+ annulus = apstatr (ap, ANNULUS)
+ }
+
+ # Print the old inner sky radius value.
+ call apsetr (ap, ANNULUS, annulus)
+ call printf (
+ "\tNew inner radius of sky annulus: %g scale units %g pixels\n")
+ call pargr (annulus)
+ call pargr (scale * annulus)
+
+ return (annulus)
+end
+
+
+# AP_VDANNULUS -- Verify the width of the sky annulus.
+
+real procedure ap_vdannulus (ap)
+
+pointer ap # pointer to the apphot structure
+
+real scale, dannulus
+int scan(), nscan()
+real apstatr()
+
+begin
+ scale = apstatr (ap, SCALE)
+
+ # Print the old sky annulus width.
+ call printf (
+ "Width of the sky annulus in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, DANNULUS))
+ call flush (STDOUT)
+
+ # Confirm the width of the sky annulus.
+ if (scan() == EOF)
+ dannulus = apstatr (ap, DANNULUS)
+ else {
+ call gargr (dannulus)
+ if (nscan () != 1)
+ dannulus = apstatr (ap, DANNULUS)
+ }
+
+ # Print the new sky annulus width.
+ call apsetr (ap, DANNULUS, dannulus)
+ call printf (
+ "\tNew width of the sky annulus: %g scale units %g pixels\n")
+ call pargr (dannulus)
+ call pargr (scale * dannulus)
+
+ return (dannulus)
+end
+
+
+# AP_VRGROW -- Verify the region growing radius
+
+real procedure ap_vrgrow (ap)
+
+pointer ap # pointer to the apphot structure
+
+real scale, rgrow
+int scan(), nscan()
+real apstatr()
+
+begin
+ scale = apstatr (ap, SCALE)
+
+ # Print the old region growing radius.
+ call printf (
+ "Region growing radius in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, RGROW))
+ call flush (STDOUT)
+
+ # Confirm the region growing radius.
+ if (scan() == EOF)
+ rgrow = apstatr (ap, RGROW)
+ else {
+ call gargr (rgrow)
+ if (nscan () != 1)
+ rgrow = apstatr (ap, RGROW)
+ }
+
+ # Print the region growing radius.
+ call apsetr (ap, RGROW, rgrow)
+ call printf (
+ "\tNew region growing radius: %g scale units %g pixels\n")
+ call pargr (rgrow)
+ call pargr (scale * rgrow)
+
+ return (rgrow)
+end
+
+
+# AP_VAPERTS -- Verify the photometric apertures.
+
+procedure ap_vaperts (ap, str, maxch)
+
+pointer ap # pointer to the apphot structure
+char str[ARB] # output string
+int maxch # maximum number of characters
+
+int i, naperts
+pointer sp, aperts
+real scale
+int scan(), nscan(), ap_getaperts()
+real apstatr()
+
+begin
+ call smark (sp)
+ call salloc (aperts, MAX_NAPERTS, TY_REAL)
+
+ scale = apstatr (ap, SCALE)
+
+ # Print the old aperture string.
+ call apstats (ap, APERTS, str, maxch)
+ call printf (
+ "File/list of aperture radii in scale units (%s) (CR or value): ")
+ call pargstr (str)
+ call flush (STDOUT)
+
+ # Get the new apertures.
+ if (scan() == EOF)
+ call apstats (ap, APERTS, str, maxch)
+ else {
+ call gargwrd (str, maxch)
+ if (nscan () != 1)
+ call apstats (ap, APERTS, str, maxch)
+ }
+
+ # Print the new apertures.
+ naperts = ap_getaperts (str, Memr[aperts], MAX_NAPERTS)
+ do i = 1, naperts {
+ call printf ("\tAperture radius %d: %g scale units %g pixels\n")
+ call pargi (i)
+ call pargr (Memr[aperts+i-1])
+ call pargr (scale * Memr[aperts+i-1])
+ }
+
+ call apsets (ap, APERTS, str)
+ call sfree (sp)
+end
+
+
+# AP_VPWSTRING -- Verify the weighting string.
+
+procedure ap_vpwstring (ap, str, maxch)
+
+pointer ap # pointer to the apphot structure
+char str[ARB] # output string
+int maxch # maximum number of characters
+
+int wfunc
+int scan(), nscan(), strdic()
+
+begin
+ # Print the old string.
+ call apstats (ap, PWSTRING, str, maxch)
+ call printf ("Weighting algorithm (%s) (CR or value): ")
+ call pargstr (str)
+ call flush (STDOUT)
+
+ # Get the new value.
+ if (scan() != EOF) {
+ call gargwrd (str, maxch)
+ wfunc = strdic (str, str, maxch, PWFUNCS)
+ if (nscan () == 1 && wfunc > 0) {
+ call apseti (ap, PWEIGHTS, wfunc)
+ call apsets (ap, PWSTRING, str)
+ }
+ }
+
+ # Print the new value.
+ call apstats (ap, PWSTRING, str, maxch)
+ call printf ("\tNew weighting algorithm: %s\n")
+ call pargstr (str)
+
+ call apsets (ap, PWSTRING, str)
+end
diff --git a/noao/digiphot/apphot/aplib/apverify2.x b/noao/digiphot/apphot/aplib/apverify2.x
new file mode 100644
index 00000000..b5f02f46
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apverify2.x
@@ -0,0 +1,188 @@
+include "../lib/apphot.h"
+include "../lib/noise.h"
+include "../lib/find.h"
+include "../lib/fitpsf.h"
+include "../lib/radprof.h"
+
+
+# AP_VTHRESHOLD -- Verify the full detection threshold.
+
+real procedure ap_vthreshold (ap)
+
+pointer ap # pointer to the apphot structure
+
+real skysigma, threshold
+int scan(), nscan()
+real apstatr()
+
+begin
+ skysigma = apstatr (ap, SKYSIGMA)
+
+ # Confirm the threshold parameter.
+ call printf (
+ "Detection threshold in sigma (%g) (CR or value): ")
+ call pargr (apstatr (ap, THRESHOLD))
+ call flush (STDOUT)
+ if (scan() == EOF)
+ threshold = apstatr (ap, THRESHOLD)
+ else {
+ call gargr (threshold)
+ if (nscan () != 1)
+ threshold = apstatr (ap, THRESHOLD)
+ }
+
+ call printf ("\tNew detection threshold: %g sigma %g counts\n")
+ call pargr (threshold)
+ call apsetr (ap, THRESHOLD, threshold)
+ if (IS_INDEFR(skysigma))
+ call pargr (INDEFR)
+ else
+ call pargr (threshold * skysigma)
+
+ return (threshold)
+end
+
+# AP_VPFSTRING -- Verify the psf fitting function.
+
+procedure ap_vpfstring (ap, str, maxch)
+
+pointer ap # pointer to the apphot structure
+char str[ARB] # output string
+int maxch # maximum number of characters
+
+int pfunc
+int scan(), nscan(), strdic()
+
+begin
+ # Print the old string value.
+ call apstats (ap, PSFSTRING, str, maxch)
+ call printf ("Fitting function (%s) (CR or value): ")
+ call pargstr (str)
+ call flush (STDOUT)
+
+ # Get the new value.
+ if (scan() != EOF) {
+ call gargwrd (str, maxch)
+ pfunc = strdic (str, str, maxch, PSFFUNCS)
+ if (nscan () == 1 && pfunc > 0) {
+ call apseti (ap, PSFUNCTION, pfunc)
+ call apsets (ap, PSFSTRING, str)
+ }
+ }
+
+ # Print the new value.
+ call apstats (ap, PSFSTRING, str, SZ_LINE)
+ call printf ("\tNew fitting function: %s\n")
+ call pargstr (str)
+end
+
+
+# AP_VPSFAPERT -- Verify the point spread function fitting aperture.
+
+real procedure ap_vpsfapert (ap)
+
+pointer ap # pointer to the apphot strucuture
+
+real scale, psfapert
+int scan(), nscan()
+real apstatr()
+
+begin
+ scale = apstatr (ap, SCALE)
+
+ # Print the old value.
+ call printf ("Fitting box width in scale units (%g) (CR or value): ")
+ call pargr (2.0 * apstatr (ap, PSFAPERT))
+ call flush (STDOUT)
+
+ # Get the new value.
+ if (scan() == EOF)
+ psfapert = 2.0 * apstatr (ap, PSFAPERT)
+ else {
+ call gargr (psfapert)
+ if (nscan () != 1)
+ psfapert = 2.0 * apstatr (ap, PSFAPERT)
+ }
+
+ # Print the new value.
+ call printf ("\tNew fitting box width: %g scale units %g pixels\n")
+ call pargr (psfapert)
+ call pargr (scale * psfapert)
+ call apsetr (ap, PSFAPERT, psfapert / 2.0)
+
+ return (psfapert / 2.0)
+end
+
+
+# AP_VRPRADIUS -- Verify the radial profile fitting radius.
+
+real procedure ap_vrpradius (ap)
+
+pointer ap # pointer to the apphot strucuture
+
+real scale, radius
+int scan(), nscan()
+real apstatr()
+
+begin
+ scale = apstatr (ap, SCALE)
+
+ # Print the old value.
+ call printf ("Fitting radius in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, RPRADIUS))
+ call flush (STDOUT)
+
+ # Get the new value.
+ if (scan() == EOF)
+ radius = apstatr (ap, RPRADIUS)
+ else {
+ call gargr (radius)
+ if (nscan () != 1)
+ radius = apstatr (ap, RPRADIUS)
+ }
+
+ # Print the new value.
+ call printf ("\tNew fitting radius: %g scale units %g pixels\n")
+ call pargr (radius)
+ call pargr (scale * radius)
+ call apsetr (ap, RPRADIUS, radius)
+
+ return (radius)
+end
+
+
+# AP_VSTEP -- Verify the profile step size.
+
+real procedure ap_vstep (ap)
+
+pointer ap # pointer to the apphot strucuture
+
+real scale, step
+int scan(), nscan()
+real apstatr()
+
+begin
+ scale = apstatr (ap, SCALE)
+
+ # Print the old value.
+ call printf ("Step size in scale units (%g) (CR or value): ")
+ call pargr (apstatr (ap, RPSTEP))
+ call flush (STDOUT)
+
+ # Get the new value.
+ if (scan() == EOF)
+ step = apstatr (ap, RPSTEP)
+ else {
+ call gargr (step)
+ if (nscan () != 1)
+ step = apstatr (ap, RPSTEP)
+ }
+
+ # Print the new value.
+ call printf ("\tNew step size: %g scale units %g pixels\n")
+ call pargr (step)
+ call pargr (scale * step)
+ call apsetr (ap, RPSTEP, step)
+
+ return (step)
+end
diff --git a/noao/digiphot/apphot/aplib/apwcs.x b/noao/digiphot/apphot/aplib/apwcs.x
new file mode 100644
index 00000000..21ff7831
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apwcs.x
@@ -0,0 +1,117 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <imio.h>
+include "../lib/apphot.h"
+
+# AP_ITOL -- Convert coordinates from the input coordinate system to the
+# logical coordinate system.
+
+procedure ap_itol (ap, xin, yin, xout, yout, npts)
+
+pointer ap # the apphot package descriptor
+real xin[ARB] # the input x coordinate
+real yin[ARB] # the input y coordinate
+real xout[ARB] # the output x coordinate
+real yout[ARB] # the output y coordinate
+int npts # the number of coordinates to convert
+
+double xt, yt
+pointer ct
+int i
+int apstati()
+
+begin
+ ct = apstati (ap, CTIN)
+ if (ct == NULL) {
+ call amovr (xin, xout, npts)
+ call amovr (yin, yout, npts)
+ return
+ }
+
+ do i = 1, npts {
+ call mw_c2trand (ct, double (xin[i]), double (yin[i]), xt, yt)
+ xout[i] = xt
+ yout[i] = yt
+ }
+end
+
+
+# AP_LTOO -- Convert coordinates from the logical coordinate system to the
+# output coordinate system.
+
+procedure ap_ltoo (ap, xin, yin, xout, yout, npts)
+
+pointer ap # the apphot package descriptor
+real xin[ARB] # the input x coordinate
+real yin[ARB] # the input y coordinate
+real xout[ARB] # the output x coordinate
+real yout[ARB] # the output y coordinate
+int npts # the number of coordinates to convert
+
+double xt, yt
+pointer ct
+int i
+int apstati()
+
+begin
+ ct = apstati (ap, CTOUT)
+ if (ct == NULL) {
+ call amovr (xin, xout, npts)
+ call amovr (yin, yout, npts)
+ return
+ }
+
+ do i = 1, npts {
+ call mw_c2trand (ct, double (xin[i]), double (yin[i]), xt, yt)
+ xout[i] = xt
+ yout[i] = yt
+ }
+end
+
+
+# AP_LTOV -- Convert coordinate from the logical coordinate system to the
+# output coordinate system.
+
+procedure ap_ltov (im, xin, yin, xout, yout, npts)
+
+pointer im # the input image descriptor
+real xin[ARB] # the input x coordinate
+real yin[ARB] # the input y coordinate
+real xout[ARB] # the output x coordinate
+real yout[ARB] # the output y coordinate
+int npts # the number of coordinates to convert
+
+int i, index1, index2
+
+begin
+ index1 = IM_VMAP(im,1)
+ index2 = IM_VMAP(im,2)
+ do i = 1, npts {
+ xout[i] = xin[i] * IM_VSTEP(im,index1) + IM_VOFF(im,index1)
+ yout[i] = yin[i] * IM_VSTEP(im,index2) + IM_VOFF(im,index2)
+ }
+end
+
+
+# AP_VTOL -- Convert coordinate from the tv coordinate system to the
+# logical coordinate system.
+
+procedure ap_vtol (im, xin, yin, xout, yout, npts)
+
+pointer im # the input image descriptor
+real xin[ARB] # the input x coordinate
+real yin[ARB] # the input y coordinate
+real xout[ARB] # the output x coordinate
+real yout[ARB] # the output y coordinate
+int npts # the number of coordinates to convert
+
+int i, index1, index2
+
+begin
+ index1 = IM_VMAP(im,1)
+ index2 = IM_VMAP(im,2)
+ do i = 1, npts {
+ xout[i] = (xin[i] - IM_VOFF(im,index1)) / IM_VSTEP(im,index1)
+ yout[i] = (yin[i] - IM_VOFF(im,index2)) / IM_VSTEP(im,index2)
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apwparam1.x b/noao/digiphot/apphot/aplib/apwparam1.x
new file mode 100644
index 00000000..54086aeb
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apwparam1.x
@@ -0,0 +1,415 @@
+include <time.h>
+include "../lib/apphotdef.h"
+include "../lib/apphot.h"
+include "../lib/noise.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+
+# AP_PARAM -- Procedure to write the apphot parameters to a text file.
+
+procedure ap_param (ap, out, task)
+
+pointer ap # pointer to the apphot structure
+int out # output file descriptor
+char task[ARB] # task name
+
+int nchars
+pointer sp, outstr, date, time
+bool itob()
+int strmatch(), envfind(), gstrcpy(), apstati()
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+
+ # Allocate working space.
+ call smark (sp)
+ call salloc (outstr, SZ_LINE, TY_CHAR)
+ call salloc (date, SZ_DATE, TY_CHAR)
+ call salloc (time, SZ_DATE, TY_CHAR)
+
+ # Write the id.
+
+ nchars = envfind ("version", Memc[outstr], SZ_LINE)
+ if (nchars <= 0)
+ nchars = gstrcpy ("NOAO/IRAF", Memc[outstr], SZ_LINE)
+ call ap_rmwhite (Memc[outstr], Memc[outstr], SZ_LINE)
+ call ap_sparam (out, "IRAF", Memc[outstr], "version",
+ "current version of IRAF")
+
+ nchars = envfind ("userid", Memc[outstr], SZ_LINE)
+ call ap_sparam (out, "USER", Memc[outstr], "name", "user id")
+
+ call gethost (Memc[outstr], SZ_LINE)
+ call ap_sparam (out, "HOST", Memc[outstr], "computer",
+ "IRAF host machine")
+
+ call apdate (Memc[date], Memc[time], SZ_DATE)
+ call ap_sparam (out, "DATE", Memc[date], "yyyy-mm-dd", "date")
+ call ap_sparam (out, "TIME", Memc[time], "hh:mm:ss", "time")
+
+ call ap_sparam (out, "PACKAGE", "apphot", "name",
+ "name of IRAF package")
+ call ap_sparam (out, "TASK", task, "name", "name of apphot task")
+ call fprintf (out, "#\n")
+
+ # Write out the apphot parameters.
+ call ap_rparam (out, KY_SCALE, 1.0 / apstatr (ap, SCALE), UN_AUNITS,
+ "scale in units per pixel")
+ call ap_rparam (out, KY_FWHMPSF, apstatr (ap, FWHMPSF), UN_ASCALEUNIT,
+ "full width half maximum of the psf")
+ call ap_bparam (out, KY_POSITIVE, itob (apstati (ap, POSITIVE)),
+ UN_ASWITCH, "positive feature")
+ call ap_rparam (out, KY_DATAMIN, apstatr (ap, DATAMIN), UN_ACOUNTS,
+ "minimum good data value")
+ call ap_rparam (out, KY_DATAMAX, apstatr (ap, DATAMAX), UN_ACOUNTS,
+ "maximum good data value")
+
+ # Write out the image header keyword parameters.
+ call apstats (ap, EXPOSURE, Memc[outstr], SZ_FNAME)
+ if (Memc[outstr] == EOS)
+ call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
+ call ap_sparam (out, KY_EXPOSURE, Memc[outstr], UN_AKEYWORD,
+ "exposure time keyword")
+ call apstats (ap, AIRMASS, Memc[outstr], SZ_FNAME)
+ if (Memc[outstr] == EOS)
+ call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
+ call ap_sparam (out, KY_AIRMASS, Memc[outstr], UN_AKEYWORD,
+ "airmass keyword")
+ call apstats (ap, FILTER, Memc[outstr], SZ_FNAME)
+ if (Memc[outstr] == EOS)
+ call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
+ call ap_sparam (out, KY_FILTER, Memc[outstr], UN_AKEYWORD,
+ "filter keyword")
+ call apstats (ap, OBSTIME, Memc[outstr], SZ_FNAME)
+ if (Memc[outstr] == EOS)
+ call strcpy ("\"\"", Memc[outstr], SZ_FNAME)
+ call ap_sparam (out, KY_OBSTIME, Memc[outstr], UN_AKEYWORD,
+ "obstime keyword")
+ call fprintf (out, "#\n")
+
+ # Write the noise model parameters.
+ call ap_wnse (ap, out)
+
+ # Write the centering parameters.
+ call ap_wctrs (ap, out)
+
+ # Write sky fitting parameters.
+ call ap_wskys (ap, out)
+
+ # Write the phot parameters.
+ call ap_wwphot (ap, out)
+
+ # Write the polyphot parameters.
+ call ap_wpoly (ap, out)
+
+ # Write the radial profile parameters.
+ call ap_wprofs (ap, out)
+
+ # Write the psf fitting parameters.
+ call ap_wpsf (ap, out)
+
+ # Write the header banner
+ if (strmatch ("^center", task) > 0)
+ call ap_cphdr (ap, out)
+ else if (strmatch ("^fitsky", task) > 0)
+ call ap_sphdr (ap, out)
+ else if (strmatch ("^phot", task) > 0)
+ call ap_maghdr (ap, out)
+ else if (strmatch ("^qphot", task) > 0)
+ call ap_maghdr (ap, out)
+ else if (strmatch ("^wphot", task) > 0)
+ call ap_maghdr (ap, out)
+ else if (strmatch ("^polyphot", task) > 0)
+ call ap_yhdr (ap, out)
+ else if (strmatch ("^fitpsf", task) > 0)
+ call ap_pfhdr (ap, out)
+ else if (strmatch ("^radprof", task) > 0)
+ call ap_rphdr (ap, out)
+ #else if (strmatch ("^daofind", task) > 0)
+ #call ap_fdhdr (ap, out)
+
+ call sfree (sp)
+end
+
+
+# AP_WCTRS -- Procedure to write out the centering parameters.
+
+procedure ap_wctrs (ap, out)
+
+pointer ap # apphot pointer
+int out # output file descriptor
+
+pointer sp, str
+bool itob()
+int apstati()
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ if (AP_PCENTER(ap) != NULL) {
+ call apstats (ap, CSTRING, Memc[str], SZ_FNAME)
+ call ap_sparam (out, KY_CSTRING, Memc[str], UN_CALGORITHM,
+ "centering algorithm")
+ call ap_rparam (out, KY_CAPERT, 2.0* apstatr (ap, CAPERT),
+ UN_CSCALEUNIT, "centering box width")
+ call ap_rparam (out, KY_CTHRESHOLD, apstatr (ap, CTHRESHOLD),
+ UN_CSIGMA, "threshold for centering")
+ call ap_rparam (out, KY_MINSNRATIO, apstatr (ap, MINSNRATIO),
+ UN_CNUMBER, "minimum signal to noise ratio")
+ call ap_iparam (out, KY_CMAXITER, apstati (ap, CMAXITER),
+ UN_CNUMBER, "maximum number of iterations")
+ call ap_rparam (out, KY_MAXSHIFT, apstatr (ap, MAXSHIFT),
+ UN_CSCALEUNIT, "maximum shift")
+ call ap_bparam (out, KY_CLEAN, itob (apstati (ap, CLEAN)),
+ UN_CSWITCH, "apply clean algorithm before centering")
+ call ap_rparam (out, KY_RCLEAN, apstatr (ap, RCLEAN),
+ UN_CSCALEUNIT, "cleaning radius")
+ call ap_rparam (out, KY_RCLIP, apstatr (ap, RCLIP), UN_CSCALEUNIT,
+ "clipping radius")
+ call ap_rparam (out, KY_SIGMACLEAN, apstatr (ap, SIGMACLEAN),
+ UN_CSIGMA, "k-sigma clean rejection criterion")
+ call fprintf (out, "#\n")
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_WSKYS -- Procedure to write out the sky fitting parameters.
+
+procedure ap_wskys (ap, out)
+
+pointer ap # apphot structure
+int out # output pointer
+
+pointer sp, str
+bool itob()
+int apstati()
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ if (AP_PSKY(ap) != NULL) {
+ call apstats (ap, SSTRING, Memc[str], SZ_FNAME)
+ call ap_sparam (out, KY_SSTRING, Memc[str], UN_SALGORITHM,
+ " sky fitting algorithm")
+ call ap_rparam (out, KY_ANNULUS, apstatr (ap, ANNULUS),
+ UN_SSCALEUNIT, "inner radius of sky annulus")
+ call ap_rparam (out, KY_DANNULUS, apstatr (ap, DANNULUS),
+ UN_SSCALEUNIT, "width of the sky annulus")
+ call ap_rparam (out, KY_SKY_BACKGROUND, apstatr (ap,
+ SKY_BACKGROUND), UN_SCOUNTS, "user supplied sky value")
+ call ap_rparam (out, KY_K1, apstatr (ap, K1), UN_SSIGMA,
+ "half width of sky histogram")
+ call ap_rparam (out, KY_BINSIZE, apstatr (ap, BINSIZE),
+ UN_SSIGMA, "width of sky histogram bin")
+ call ap_bparam (out, KY_SMOOTH, itob (apstati (ap, SMOOTH)),
+ UN_SSWITCH, "Lucy smooth the histogram")
+ call ap_iparam (out, KY_SMAXITER, apstati (ap, SMAXITER),
+ UN_SNUMBER, "maximum number of iterations")
+ call ap_rparam (out, KY_SLOCLIP, apstatr (ap, SLOCLIP),
+ UN_SPERCENT, "lower clipping limit")
+ call ap_rparam (out, KY_SHICLIP, apstatr (ap, SHICLIP),
+ UN_SPERCENT, "upper clipping limit")
+ call ap_iparam (out, KY_SNREJECT, apstati (ap, SNREJECT),
+ UN_SNUMBER, "maximum number of rejection cycles")
+ call ap_rparam (out, KY_SLOREJECT, apstatr (ap, SLOREJECT),
+ UN_SSIGMA, "lower k-sigma rejection criterion")
+ call ap_rparam (out, KY_SHIREJECT, apstatr (ap, SHIREJECT),
+ UN_SSIGMA, "upper k-sigma rejection criterion")
+ call ap_rparam (out, KY_RGROW, apstatr (ap, RGROW), UN_SSCALEUNIT,
+ "region growing radius")
+ call fprintf (out, "#\n")
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_WNSE -- Porcedure to compute the noise model parameters.
+
+procedure ap_wnse (ap, out)
+
+pointer ap # apphot pointer
+int out # output file descriptor
+
+pointer sp, str
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ if (AP_NOISE(ap) != NULL) {
+ call apstats (ap, NSTRING, Memc[str], SZ_FNAME)
+ call ap_sparam (out, KY_NSTRING, Memc[str], UN_NMODEL,
+ "noise model")
+ call ap_rparam (out, KY_SKYSIGMA, apstatr (ap, SKYSIGMA),
+ UN_NCOUNTS, "standard deviation of 1 sky pixel")
+ call apstats (ap, GAIN, Memc[str], SZ_FNAME)
+ if (Memc[str] == EOS)
+ call strcpy ("\"\"", Memc[str], SZ_FNAME)
+ call ap_sparam (out, KY_GAIN, Memc[str], UN_NKEYWORD,
+ "gain keyword")
+ call ap_rparam (out, KY_EPADU, apstatr (ap, EPADU), UN_NEPADU,
+ "electrons per adu")
+ call apstats (ap, CCDREAD, Memc[str], SZ_FNAME)
+ if (Memc[str] == EOS)
+ call strcpy ("\"\"", Memc[str], SZ_FNAME)
+ call ap_sparam (out, KY_CCDREAD, Memc[str], UN_NKEYWORD,
+ "read noise keyword")
+ call ap_rparam (out, KY_READNOISE, apstatr (ap, READNOISE),
+ UN_NELECTRONS, "electrons")
+ call fprintf (out, "#\n")
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_WWPHOT -- Procedure to write out the photometry parameters.
+
+procedure ap_wwphot (ap, out)
+
+pointer ap # apphot structure pointer
+int out # output file descriptor
+
+pointer sp, str
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ if (AP_PPHOT(ap) != NULL) {
+ call apstats (ap, PWSTRING, Memc[str], SZ_LINE)
+ call ap_sparam (out, KY_PWSTRING, Memc[str], UN_PMODEL,
+ "photometric weighting scheme")
+ call apstats (ap, APERTS, Memc[str], SZ_LINE)
+ call ap_sparam (out, KY_APERTS, Memc[str], UN_PSCALEUNIT,
+ "list of apertures")
+ call ap_rparam (out, KY_ZMAG, apstatr (ap, ZMAG), UN_PZMAG,
+ "zero point of magnitdue scale")
+ call fprintf (out, "#\n")
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_RPARAM -- Procedure to encode a real apphot parameter.
+
+procedure ap_rparam (out, keyword, value, units, comments)
+
+int out # output file descriptor
+char keyword[ARB] # keyword string
+real value # parameter value
+char units[ARB] # units string
+char comments[ARB] # comment string
+
+begin
+ if (out == NULL)
+ return
+
+ call strupr (keyword)
+ call fprintf (out,
+ "#K%4t%-10.10s%14t = %17t%-23.7g%41t%-10.10s%52t%-10s\n")
+ call pargstr (keyword)
+ call pargr (value)
+ call pargstr (units)
+ call pargstr ("%-23.7g")
+ call pargstr (comments)
+end
+
+
+# AP_IPARAM -- Procedure to encode an apphot integer parameter.
+
+procedure ap_iparam (out, keyword, value, units, comments)
+
+int out # output file descriptor
+char keyword[ARB] # keyword string
+int value # parameter value
+char units[ARB] # units string
+char comments[ARB] # comment string
+
+begin
+ if (out == NULL)
+ return
+
+ call strupr (keyword)
+ call fprintf (out,
+ "#K%4t%-10.10s%14t = %17t%-23d%41t%-10.10s%52t%-10s\n")
+ call pargstr (keyword)
+ call pargi (value)
+ call pargstr (units)
+ call pargstr ("%-23d")
+ call pargstr (comments)
+end
+
+
+# AP_BPARAM -- Procedure to encode an apphot boolean parameter.
+
+procedure ap_bparam (out, keyword, value, units, comments)
+
+int out # output file descriptor
+char keyword[ARB] # keyword string
+bool value # parameter value
+char units[ARB] # units string
+char comments[ARB] # comment string
+
+begin
+ if (out == NULL)
+ return
+
+ call strupr (keyword)
+ call fprintf (out,
+ "#K%4t%-10.10s%14t = %17t%-23b%41t%-10.10s%52t%-10s\n")
+ call pargstr (keyword)
+ call pargb (value)
+ call pargstr (units)
+ call pargstr ("%-23b")
+ call pargstr (comments)
+end
+
+
+# AP_SPARAM -- Procedure to encode an apphot string parameter.
+
+procedure ap_sparam (out, keyword, value, units, comments)
+
+int out # output file descriptor
+char keyword[ARB] # keyword string
+char value[ARB] # parameter value
+char units[ARB] # units string
+char comments[ARB] # comment string
+
+begin
+ if (out == NULL)
+ return
+
+ call strupr (keyword)
+ call fprintf (out,
+ "#K%4t%-10.10s%14t = %17t%-23.23s%41t%-10.10s%52t%-10s\n")
+ call pargstr (keyword)
+ call pargstr (value)
+ call pargstr (units)
+ call pargstr ("%-23s")
+ call pargstr (comments)
+end
diff --git a/noao/digiphot/apphot/aplib/apwparam2.x b/noao/digiphot/apphot/aplib/apwparam2.x
new file mode 100644
index 00000000..1c15f26c
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apwparam2.x
@@ -0,0 +1,104 @@
+include "../lib/apphotdef.h"
+include "../lib/polyphot.h"
+include "../lib/fitpsf.h"
+include "../lib/radprof.h"
+
+
+# AP_WPROFS -- Procedure to print out the profile fitting parameters.
+
+procedure ap_wprofs (ap, out)
+
+pointer ap # apphot structure pointer
+int out # output file descriptor
+
+pointer sp, str
+int apstati()
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ if (AP_RPROF(ap) != NULL) {
+ call ap_rparam (out, KY_RPRADIUS, apstatr (ap, RPRADIUS),
+ UN_RSCALEUNIT, "fitting radius")
+ call ap_rparam (out, KY_RPSTEP, apstatr (ap, RPSTEP),
+ UN_RSCALEUNIT, "step size in radius")
+ call ap_iparam (out, KY_RPORDER, apstati (ap, RPORDER), UN_RNUMBER,
+ "number of splines pieces")
+ call ap_rparam (out, KY_RPKSIGMA, apstatr (ap, RPKSIGMA),
+ UN_RSIGMA, "k-sigma rejection criterion")
+ call ap_iparam (out, KY_RPNREJECT, apstati (ap, RPNREJECT),
+ UN_RNUMBER, "maximum number of rejection cycles")
+ call fprintf (out, "#\n")
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_WPOLY -- Procedure to write out the polyphot parameters.
+
+procedure ap_wpoly (ap, out)
+
+pointer ap # apphot structure pointer
+int out # output file descriptor
+
+pointer sp, str
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ if (AP_POLY(ap) != NULL) {
+ call ap_sparam (out, "WEIGHTING", "constant", "model", "")
+ call ap_rparam (out, KY_PYZMAG, apstatr (ap, PYZMAG), UN_PYZMAG,
+ "zero point of magnitdue scale")
+ call fprintf (out, "#\n")
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_WPSF -- Procedure to write the psf fitting parameters .
+
+procedure ap_wpsf (ap, out)
+
+pointer ap # apphot strucuture pointer
+int out # output file descriptor
+
+pointer sp, str
+int apstati()
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ if (AP_PPSF(ap) != NULL) {
+ call apstats (ap, PSFSTRING, Memc[str], SZ_FNAME)
+ call ap_sparam (out, KY_PSFUNCTION, Memc[str], UN_PSFMODEL,
+ "fitting function")
+ call ap_rparam (out, KY_PSFAPERT, 2.0 * apstatr (ap, PSFAPERT),
+ UN_PSFSCALEUNIT, "width of the fitting box")
+ call ap_iparam (out, KY_PMAXITER, apstati (ap, PMAXITER),
+ UN_PSFSCALEUNIT, "maximum number of iterations")
+ call ap_rparam (out, KY_PK2, apstatr (ap, PK2), UN_PSFSIGMA,
+ "k-sigma rejection limit for the fit")
+ call ap_iparam (out, KY_PNREJECT, apstati (ap, PNREJECT),
+ UN_PSFNUMBER, "maximum number of rejection cycles")
+ call fprintf (out, "#\n")
+ }
+
+ call sfree (sp)
+end
diff --git a/noao/digiphot/apphot/aplib/apwres1.x b/noao/digiphot/apphot/aplib/apwres1.x
new file mode 100644
index 00000000..3d7b490a
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apwres1.x
@@ -0,0 +1,437 @@
+include "../lib/apphot.h"
+include "../lib/find.h"
+include "../lib/center.h"
+include "../lib/fitsky.h"
+
+# define the #N, #U, and #F daofind strings
+
+define FD_NSTR "#N%4tXCENTER%14tYCENTER%24tMAG%33tSHARPNESS%45t\
+SROUND%57tGROUND%69tID%80t\\\n"
+define FD_USTR "#U%4tpixels%14tpixels%24t#%33t#%45t#%57t#%69t#%80t\\\n"
+define FD_FSTR "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-12.3f%45t\
+%%-12.3f%57t%%-12.3f%69t%%-6d%80t\\\n"
+define FD_WSTR "%4t%-10.3f%-10.3f%-9.3f%-12.3f%-12.3f%-12.3f%-6d\n"
+
+# AP_WFDPARAM -- Write the daofind parameters to the output file.
+
+procedure ap_wfdparam (out, ap)
+
+int out # the output file descriptor
+pointer ap # pointer to the apphot structure
+
+pointer sp, str
+real apstatr()
+
+begin
+ if (out == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ # Write out the parameters.
+ call ap_param (ap, out, "daofind")
+ #call apstats (ap, IMNAME, Memc[str], SZ_FNAME)
+ call apstats (ap, IMROOT, Memc[str], SZ_FNAME)
+ call ap_sparam (out, KY_IMNAME, Memc[str], "imagename", "image name")
+ call ap_rparam (out, KY_FWHMPSF, apstatr (ap, FWHMPSF), UN_ASCALEUNIT,
+ "fwhm of the psf")
+ call ap_rparam (out, KY_THRESHOLD, apstatr (ap, THRESHOLD),
+ UN_FSIGMA, "detection threshold in sigma")
+ call ap_rparam (out, KY_NSIGMA, apstatr (ap, NSIGMA), UN_FSIGMA,
+ "size of the kernel in fwhmpsf")
+ call ap_rparam (out, KY_RATIO, apstatr (ap, RATIO), UN_FNUMBER,
+ "ratio of ysigma to xsigma")
+ call ap_rparam (out, KY_THETA, apstatr (ap, THETA), UN_FDEGREES,
+ "position angle in degrees")
+ call fprintf (out, "#\n")
+ call ap_rparam (out, KY_SHARPLO, apstatr (ap, SHARPLO), UN_FNUMBER,
+ "lower sharpness bound")
+ call ap_rparam (out, KY_SHARPHI, apstatr (ap, SHARPHI), UN_FNUMBER,
+ "higher sharpness bound")
+ call ap_rparam (out, KY_ROUNDLO, apstatr (ap, ROUNDLO), UN_FNUMBER,
+ "lower roundness bound")
+ call ap_rparam (out, KY_ROUNDHI, apstatr (ap, ROUNDHI), UN_FNUMBER,
+ "higher roundness bound")
+ call fprintf (out, "#\n")
+
+ # Write out the header banner.
+ call ap_fdhdr (ap, out)
+
+ call sfree (sp)
+end
+
+
+# AP_FDHDR -- Write the daofind column banner to the output file.
+
+procedure ap_fdhdr (ap, out)
+
+pointer ap # pointer to the apphot structure (unused)
+int out # output file descriptor
+
+begin
+ if (out == NULL)
+ return
+
+ call fprintf (out, FD_NSTR)
+ call fprintf (out, FD_USTR)
+ call fprintf (out, FD_FSTR)
+ call fprintf (out, "#\n")
+end
+
+
+# APSTDOUT -- Print the daofind results on the standard output.
+
+procedure apstdout (density, ptrs, ncols, nbox, cols, x, y, sharp, round1,
+ round2, nstars, ntotal, threshold)
+
+real density[ncols,nbox] # array of densities
+int ptrs[ARB] # array of line pointers
+int ncols, nbox # dimensions of the data
+int cols[ARB] # array of column numbers
+real x[ARB] # x coordinates
+real y[ARB] # y coordinates
+real sharp[ARB] # sharpness
+real round1[ARB] # first roundness parameter
+real round2[ARB] # second roundness parameter
+int nstars # number of detected stars in the line
+int ntotal # total number of detected objects
+real threshold # threshold for detection
+
+int i, middle
+real den
+
+begin
+ middle = 1 + nbox / 2
+ do i = 1, nstars {
+ call printf (" %7.2f %7.2f %7.3f %6.3f %6.3f %6.3f %4d\n")
+ call pargr (x[i])
+ call pargr (y[i])
+ if (threshold <= 0.0)
+ den = INDEFR
+ else
+ den = -2.5 * log10 (density[cols[i],ptrs[middle]] /
+ threshold)
+ call pargr (den)
+ call pargr (sharp[i])
+ call pargr (round1[i])
+ call pargr (round2[i])
+ call pargi (ntotal + i)
+ }
+end
+
+
+# APDTFOUT -- Write the daofind results to the output file.
+
+procedure apdtfout (fd, density, ptrs, ncols, nbox, cols, x, y, sharp, round1,
+ round2, nstars, ntotal, threshold, stid)
+
+int fd # the output file descriptor
+real density[ncols, nbox] # densities
+int ptrs[ARB] # array of line pointers
+int ncols, nbox # dimensions of the data
+int cols[ARB] # column numbers
+real x[ARB] # xcoords
+real y[ARB] # y coords
+real sharp[ARB] # sharpnesses
+real round1[ARB] # first roundness
+real round2[ARB] # second roundness
+int nstars # number of detected stars in the line
+int ntotal # total number of detected objects
+real threshold # threshold for detection
+int stid # output file sequence number
+
+int i, middle
+real den
+
+begin
+ if (fd == NULL)
+ return
+
+ middle = 1 + nbox / 2
+ do i = 1, nstars {
+ call fprintf (fd, FD_WSTR)
+ call pargr (x[i])
+ call pargr (y[i])
+ if (threshold <= 0.0)
+ den = INDEFR
+ else
+ den = -2.5 * log10 (density[cols[i],ptrs[middle]] /
+ threshold)
+ call pargr (den)
+ call pargr (sharp[i])
+ call pargr (round1[i])
+ call pargr (round2[i])
+ call pargi (stid + ntotal + i - 1)
+ }
+end
+
+
+# define the #N, #U and #K id strings
+
+define ID_NSTR "#N%4tIMAGE%24tXINIT%34tYINIT%44tID%50tCOORDS%73tLID%80t\\\n"
+define ID_USTR "#U%4timagename%24tpixels%34tpixels%44t##%50tfilename%73t\
+##%80t\\\n"
+define ID_FSTR "#F%4t%%-23s%24t%%-10.3f%34t%%-10.3f%44t%%-6d%50t%%-23s%73t\
+%%-6d%80t \n"
+define ID_WSTR "%-23.23s%24t%-10.3f%34t%-10.3f%44t%-6d%50t%-23.23s%73t\
+%-6d%80t%c\n"
+
+# AP_IDHDR -- Print the id column header strings.
+
+procedure ap_idhdr (ap, fd)
+
+pointer ap # apphot descriptor (unused)
+int fd # output file descriptor
+
+begin
+ if (fd == NULL)
+ return
+ call fprintf (fd, ID_NSTR)
+ call fprintf (fd, ID_USTR)
+ call fprintf (fd, ID_FSTR)
+ call fprintf (fd, "#\n")
+end
+
+
+# AP_WID -- Write the id record to a file.
+
+procedure ap_wid (ap, fd, xpos, ypos, id, lid, lastchar)
+
+pointer ap # pointer to apphot structure
+int fd # output file descriptor
+real xpos # x position
+real ypos # y position
+int id # id of the star
+int lid # list number
+int lastchar # last character in record
+
+pointer sp, imname, clname
+
+begin
+ if (fd == NULL)
+ return
+
+ call smark (sp)
+ call salloc (imname, SZ_FNAME, TY_CHAR)
+ call salloc (clname, SZ_FNAME, TY_CHAR)
+
+ # Print description of object.
+ call apstats (ap, IMROOT, Memc[imname], SZ_FNAME)
+ call apstats (ap, CLROOT, Memc[clname], SZ_FNAME)
+ if (Memc[clname] == EOS)
+ call strcpy ("nullfile", Memc[clname], SZ_FNAME)
+ call fprintf (fd, ID_WSTR)
+ call pargstr (Memc[imname])
+ call pargr (xpos)
+ call pargr (ypos)
+ call pargi (id)
+ call pargstr (Memc[clname])
+ call pargi (lid)
+ call pargi (lastchar)
+
+ call sfree (sp)
+end
+
+
+# define the #N, #U and #K center strings
+
+define CTR_NSTR "#N%4tXCENTER%15tYCENTER%26tXSHIFT%34tYSHIFT%42tXERR%50t\
+YERR%66tCIER%71tCERROR%80t\\\n"
+define CTR_USTR "#U%4tpixels%15tpixels%26tpixels%34tpixels%42tpixels%50t\
+pixels%66t##%71tcerrors%80t\\\n"
+define CTR_FSTR "#F%4t%%-14.3f%15t%%-11.3f%26t%%-8.3f%34t%%-8.3f%42t\
+%%-8.3f%50t%%-15.3f%66t%%-5d%71t%%-9s%80t \n"
+define CTR_WSTR "%4t%-11.3f%-11.3f%-8.3f%-8.3f%-8.3f%-15.3f%-5d%-9.9s\
+%80t%c\n"
+
+
+# AP_CHDR -- Print the center algorithm column header strings.
+
+procedure ap_chdr (ap, fd)
+
+pointer ap # apphot descriptor (unused)
+int fd # output file descriptor
+
+begin
+ if (fd == NULL)
+ return
+ call fprintf (fd, CTR_NSTR)
+ call fprintf (fd, CTR_USTR)
+ call fprintf (fd, CTR_FSTR)
+ call fprintf (fd, "#\n")
+end
+
+
+# AP_WCRES -- Write out the centering algorithm results to a file.
+
+procedure ap_wcres (ap, fd, ier, lastchar)
+
+pointer ap # pointer to apphot structure
+int fd # output file descriptor
+int ier # error code
+int lastchar # last character written out
+
+pointer sp, str
+real apstatr()
+
+begin
+ if (fd == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+ call ap_cserrors (ier, Memc[str], SZ_LINE)
+
+ # Print the computed centers.
+ call fprintf (fd, CTR_WSTR)
+ call pargr (apstatr (ap, OXCENTER))
+ call pargr (apstatr (ap, OYCENTER))
+ call pargr (apstatr (ap, OXSHIFT))
+ call pargr (apstatr (ap, OYSHIFT))
+ call pargr (apstatr (ap, XERR))
+ call pargr (apstatr (ap, YERR))
+ call pargi (ier)
+ call pargstr (Memc[str])
+ call pargi (lastchar)
+
+ call sfree (sp)
+end
+
+
+# AP_CSERRORS -- Encode the centering task error messages into a string.
+
+procedure ap_cserrors (ier, str, maxch)
+
+int ier # error code
+char str[ARB] # output str
+int maxch # maximum number of characters
+
+begin
+ switch (ier) {
+ case AP_CTR_NOAREA:
+ call strcpy ("OffImage", str, maxch)
+ case AP_CTR_OUTOFBOUNDS:
+ call strcpy ("EdgeImage", str, maxch)
+ case AP_CTR_NTOO_SMALL:
+ call strcpy ("TooFewPts", str, maxch)
+ case AP_CTR_SINGULAR:
+ call strcpy ("Singular", str, maxch)
+ case AP_CTR_NOCONVERGE:
+ call strcpy ("BadFit", str, maxch)
+ case AP_CTR_BADSHIFT:
+ call strcpy ("BigShift", str, maxch)
+ case AP_CTR_LOWSNRATIO:
+ call strcpy ("LowSnr", str, maxch)
+ case AP_CTR_BADDATA:
+ call strcpy ("BadPixels", str, maxch)
+ default:
+ call strcpy ("NoError", str, maxch)
+ }
+end
+
+
+# define the #N, #U and #K fitsky strings
+
+define SKY_NSTR "#N%4tMSKY%19tSTDEV%34tSSKEW%49tNSKY%56tNSREJ%66tSIER\
+%71tSERROR%80t\\\n"
+define SKY_USTR "#U%4tcounts%19tcounts%34tcounts%49tnpix%56tnpix%66t##\
+%71tserrors%80t\\\n"
+define SKY_FSTR "#F%4t%%-18.7g%19t%%-15.7g%34t%%-15.7g%49t%%-7d%56t\
+%%-9d%66t%%-5d%71t%%-9s%80t \n"
+define SKY_WSTR "%4t%-15.7g%-15.7g%-15.7g%-7d%-9d%-5d%-9.9s%80t%c\n"
+
+# AP_SHDR -- Print the sky fitting column header strings.
+
+procedure ap_shdr (ap, fd)
+
+pointer ap # apphot descriptor (unused)
+int fd # output file descriptor
+
+begin
+ if (fd == NULL)
+ return
+
+ call fprintf (fd, SKY_NSTR)
+ call fprintf (fd, SKY_USTR)
+ call fprintf (fd, SKY_FSTR)
+ call fprintf (fd, "#\n")
+end
+
+
+# AP_WSRES -- Write the results of the sky fitting algorithms to the output
+# file.
+
+procedure ap_wsres (ap, fd, ier, lastchar)
+
+pointer ap # pointer to apphot structure
+int fd # output file descriptor
+int ier # error code
+int lastchar # last character
+
+int apstati()
+real apstatr()
+
+pointer sp, str
+
+begin
+ if (fd == NULL)
+ return
+
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+ call ap_sserrors (ier, Memc[str], SZ_LINE)
+
+ # Print the computed sky value and statistics.
+ call fprintf (fd, SKY_WSTR)
+ call pargr (apstatr (ap, SKY_MODE))
+ call pargr (apstatr (ap, SKY_SIGMA))
+ call pargr (apstatr (ap, SKY_SKEW))
+ call pargi (apstati (ap, NSKY))
+ call pargi (apstati (ap, NSKY_REJECT))
+ call pargi (ier)
+ call pargstr (Memc[str])
+ call pargi (lastchar)
+
+ call sfree (sp)
+end
+
+
+# AP_SSERRORS -- Encode the sky fitting error messages in a string.
+
+procedure ap_sserrors (ier, str, maxch)
+
+int ier # integer error code
+char str[ARB] # the output string
+int maxch # maximum number of characters
+
+begin
+ switch (ier) {
+ case AP_NOSKYAREA:
+ call strcpy ("OffImage", str, maxch)
+ case AP_SKY_OUTOFBOUNDS:
+ call strcpy ("EdgeImage", str, maxch)
+ case AP_NOHISTOGRAM:
+ call strcpy ("NoHist", str, maxch)
+ case AP_FLAT_HIST:
+ call strcpy ("FlatHist", str, maxch)
+ case AP_NSKY_TOO_SMALL:
+ call strcpy ("TooFewPts", str, maxch)
+ case AP_SKY_SINGULAR:
+ call strcpy ("Singular", str, maxch)
+ case AP_SKY_NOCONVERGE:
+ call strcpy ("BadFit", str, maxch)
+ case AP_NOGRAPHICS:
+ call strcpy ("NoGraph", str, maxch)
+ case AP_NOSKYFILE:
+ call strcpy ("NoFile", str, maxch)
+ case AP_EOFSKYFILE:
+ call strcpy ("ShortFile", str, maxch)
+ case AP_BADSKYSCAN:
+ call strcpy ("BadRecord", str, maxch)
+ case AP_BADPARAMS:
+ call strcpy ("BadParams", str, maxch)
+ default:
+ call strcpy ("NoError", str, maxch)
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apwres2.x b/noao/digiphot/apphot/aplib/apwres2.x
new file mode 100644
index 00000000..1c5d38a5
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apwres2.x
@@ -0,0 +1,347 @@
+include "../lib/apphotdef.h"
+include "../lib/photdef.h"
+
+include "../lib/apphot.h"
+include "../lib/fitsky.h"
+include "../lib/phot.h"
+include "../lib/polyphot.h"
+
+# define the #N, #U and #K phot/wphot strings
+
+define MAG1_NSTR "#N%4tITIME%19tXAIRMASS%34tIFILTER%57tOTIME%80t\\\n"
+define MAG1_USTR "#U%4ttimeunit%19tnumber%34tname%57ttimeunit%80t\\\n"
+define MAG1_FSTR "#F%4t%%-18.7g%19t%%-15.7g%34t%%-23s%57t%%-23s%80t \n"
+define MAG1_WSTR "%4t%-15.7g%-15.7g%-23.23s%-23.23s%80t\\\n"
+
+define MAG2_NSTR "#N%4tRAPERT%13tSUM%27tAREA%38tFLUX%52tMAG%59tMERR%66t\
+PIER%71tPERROR%80t\\\n"
+define MAG2_USTR "#U%4tscale%13tcounts%27tpixels%38tcounts%52tmag%59t\
+mag%66t##%71tperrors%80t\\\n"
+define MAG2_FSTR "#F%4t%%-12.2f%13t%%-14.7g%27t%%-11.7g%38t%%-14.7g%52t\
+%%-7.3f%59t%%-6.3f%66t%%-5d%71t%%-9s%80t \n"
+define MAG2_WSTR "%4t%-9.2f%-14.7g%-11.7g%-14.7g%-7.3f%-6.3f%-5d%-9.9s\
+%79t%2s\n"
+
+
+# AP_MHDR -- Print the phot/wphot/qphot column header strings.
+
+procedure ap_mhdr (ap, fd)
+
+pointer ap # apphot descriptor (unused)
+int fd # output file descriptor
+
+begin
+ if (fd == NULL)
+ return
+
+ call fprintf (fd, MAG1_NSTR)
+ call fprintf (fd, MAG1_USTR)
+ call fprintf (fd, MAG1_FSTR)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, MAG2_NSTR)
+ call fprintf (fd, MAG2_USTR)
+ call fprintf (fd, MAG2_FSTR)
+ call fprintf (fd, "#\n")
+end
+
+
+# AP_WMRES -- Write the results of the phot/qphot/wphot tasks to the output
+# file.
+
+procedure ap_wmres (ap, fd, i, pier, endstr)
+
+pointer ap # pointer to apphot structure
+int fd # output text file
+int i # index of variable length field
+int pier # photometric error
+char endstr[ARB] # termination string
+
+int ier
+pointer sp, str, phot
+real sky_val
+real apstatr()
+
+begin
+ # Initialize.
+ if (fd == NULL)
+ return
+
+ phot = AP_PPHOT(ap)
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Write out the exposure time, airmass and filter information.
+ if (i <= 1) {
+ call fprintf (fd, MAG1_WSTR)
+ call pargr (apstatr (ap, ITIME))
+ call pargr (apstatr (ap, XAIRMASS))
+ call apstats (ap, FILTERID, Memc[str], SZ_FNAME)
+ call pargstr (Memc[str])
+ call apstats (ap, OTIME, Memc[str], SZ_FNAME)
+ call pargstr (Memc[str])
+ }
+
+ # Write out the error code.
+ if (IS_INDEFR(Memr[AP_MAGS(phot)+i-1])) {
+ if (pier != AP_APERT_OUTOFBOUNDS)
+ ier = pier
+ else if (i > AP_NMAXAP(phot))
+ ier = AP_APERT_OUTOFBOUNDS
+ else
+ ier = AP_OK
+ } else if (i >= AP_NMINAP(phot)) {
+ ier = AP_APERT_BADDATA
+ } else {
+ ier = AP_OK
+ }
+ call ap_pserrors (ier, Memc[str], SZ_LINE)
+
+ # Write out the photometry results.
+ call fprintf (fd, MAG2_WSTR)
+ if (i == 0) {
+ call pargr (0.0)
+ call pargr (0.0)
+ call pargr (0.0)
+ call pargr (INDEFR)
+ call pargr (INDEFR)
+ call pargi (ier)
+ call pargstr (Memc[str])
+ call pargstr (endstr)
+ } else {
+ call pargr (Memr[AP_APERTS(phot)+i-1])
+ call pargd (Memd[AP_SUMS(phot)+i-1])
+ call pargd (Memd[AP_AREA(phot)+i-1])
+ sky_val = apstatr (ap, SKY_MODE)
+ if (IS_INDEFR(sky_val))
+ call pargr (0.0)
+ else
+ call pargr (real (Memd[AP_SUMS(phot)+i-1] - sky_val *
+ Memd[AP_AREA(phot)+i-1]))
+ call pargr (Memr[AP_MAGS(phot)+i-1])
+ if (Memr[AP_MAGERRS(phot)+i-1] > 99.999)
+ call pargr (INDEFR)
+ else
+ call pargr (Memr[AP_MAGERRS(phot)+i-1])
+ call pargi (ier)
+ call pargstr (Memc[str])
+ call pargstr (endstr)
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_PSERRORS -- Encode the photometric errors string.
+
+procedure ap_pserrors (ier, str, maxch)
+
+int ier # photometry error code
+char str[ARB] # output string
+int maxch # maximum length of string
+
+begin
+ switch (ier) {
+ case AP_APERT_NOAPERT:
+ call strcpy ("OffImage", str, maxch)
+ case AP_APERT_OUTOFBOUNDS:
+ call strcpy ("EdgeImage", str, maxch)
+ case AP_APERT_NOSKYMODE:
+ call strcpy ("NoSky", str, maxch)
+ case AP_APERT_NEGMAG:
+ call strcpy ("NoFlux", str, maxch)
+ case AP_APERT_BADDATA:
+ call strcpy ("BadPixels", str, maxch)
+ default:
+ call strcpy ("NoError", str, maxch)
+ }
+end
+
+
+# define the #N, #U and #K polyphot strings
+
+define PY_NSTR1 "#N%4tITIME%19tXAIRMASS%34tIFILTER%57tOTIME%80t\\\n"
+define PY_USTR1 "#U%4ttimeunit%19tnumber%34tname%57ttimeunit%80t\\\n"
+define PY_FSTR1 "#F%4t%%-18.7g%19t%%-15.7g%34t%%-23s%57t%%-23s%80t \n"
+define PY_WSTR1 "%4t%-15.7g%-15.7g%-23.23s%-23.23s%80t\\\n"
+
+define PY_NSTR2 "#N%4tSUM%19tAREA%34tFLUX%49tMAG%58tMERR%66tPIER%71t\
+PERROR%80t\\\n"
+define PY_USTR2 "#U%4tcounts%19tpixels%34tcounts%49tmag%58tmag%66t##%71t\
+perrors%80t\\\n"
+define PY_FSTR2 "#F%4t%%-18.7g%19t%%-15.7g%34t%%-15.7g%49t%%-9.3f%58t\
+%%-7.3f%66t%%-5d%71t%%-9s%80t \n"
+define PY_WSTR2 "%4t%-15.7g%-15.7g%-15.7g%-9.3f%-7.3f%-5d%-9.9s%80t\\\n"
+
+define PY_NSTR3 "#N%4tPOLYGONS%24tPID%29tOLDXMEAN%38tOLDYMEAN%47t\
+XMEAN%56tYMEAN%65tMINRAD%74tNVER%80t\\\n"
+define PY_USTR3 "#U%4tfilename%24t##%29tpixels%38tpixels%47t\
+pixels%56tpixels%65tpixels%74t##%80t\\\n"
+define PY_FSTR3 "#F%4t%%-23s%24t%%-5d%29t%%-9.2f%38t%%-9.2f%47t\
+%%-9.2f%56t%%-9.2f%65t%%-9.2f%74t%%-5d%80t \n"
+define PY_WSTR3 "%4t%-20.20s%-5d%-9.2f%-9.2f%-9.2f%-9.2f%-9.2f%-5d%80t\\\n"
+
+define PY_NSTR4 "#N%4tXVERTEX%13tYVERTEX%80t\\\n"
+define PY_USTR4 "#U%4tpixels%13tpixels%80t\\\n"
+define PY_FSTR4 "#F%4t%%-12.2f%13t%%-9.2f%80t \n"
+define PY_WSTR4 "%4t%-9.2f%-9.2f%79t%2s\n"
+
+
+# AP_PLHDR -- Print the polyphot column header strings.
+
+procedure ap_plhdr (ap, fd)
+
+pointer ap # apphot descriptor (unused)
+int fd # output file descriptor
+
+begin
+ if (fd == NULL)
+ return
+
+ call fprintf (fd, PY_NSTR1)
+ call fprintf (fd, PY_USTR1)
+ call fprintf (fd, PY_FSTR1)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PY_NSTR2)
+ call fprintf (fd, PY_USTR2)
+ call fprintf (fd, PY_FSTR2)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PY_NSTR3)
+ call fprintf (fd, PY_USTR3)
+ call fprintf (fd, PY_FSTR3)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PY_NSTR4)
+ call fprintf (fd, PY_USTR4)
+ call fprintf (fd, PY_FSTR4)
+ call fprintf (fd, "#\n")
+end
+
+
+# AP_WLRES -- Write the results of the polyphot task to the output file.
+
+procedure ap_wlres (py, fd, xver, yver, nver, pid, pier)
+
+pointer py # pointer to apphot structure
+int fd # output file descriptor
+real xver[ARB] # coords of x vertices
+real yver[ARB] # coords of y vertices
+int nver # number of vertices
+int pid # polygon number
+int pier # photometric error
+
+int i
+pointer sp, str, pyname
+real sky_val
+int apstati()
+double apstatd()
+real apstatr()
+
+begin
+ if (fd == NULL)
+ return
+
+ # Allocate space.
+ call smark (sp)
+ call salloc (pyname, SZ_FNAME, TY_CHAR)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Write out the exposure time, airmass and filter id.
+ call fprintf (fd, PY_WSTR1)
+ call pargr (apstatr (py, ITIME))
+ call pargr (apstatr (py, XAIRMASS))
+ call apstats (py, FILTERID, Memc[str], SZ_FNAME)
+ call pargstr (Memc[str])
+ call apstats (py, OTIME, Memc[str], SZ_FNAME)
+ call pargstr (Memc[str])
+
+ # Write the photometry results.
+ call ap_spyerrors (pier, Memc[str], SZ_LINE)
+ sky_val = apstatr (py, SKY_MODE)
+ call fprintf (fd, PY_WSTR2)
+ call pargd (apstatd (py, PYFLUX))
+ call pargd (apstatd (py, PYNPIX))
+ if (IS_INDEFR(sky_val))
+ call pargr (0.0)
+ else
+ call pargr (real (apstatd (py, PYFLUX) - sky_val *
+ apstatd (py, PYNPIX)))
+ call pargr (apstatr (py, PYMAG))
+ if (apstatr (py, PYMAGERR) > 99.999)
+ call pargr (INDEFR)
+ else
+ call pargr (apstatr (py, PYMAGERR))
+ call pargi (pier)
+ call pargstr (Memc[str])
+
+ # Write the polygon characteristics
+ #call apstats (py, PYNAME, Memc[pyname], SZ_FNAME)
+ call apstats (py, PYROOT, Memc[pyname], SZ_FNAME)
+ call fprintf (fd, PY_WSTR3)
+ if (Memc[pyname] == EOS)
+ call pargstr ("nullfile")
+ else
+ call pargstr (Memc[pyname])
+ call pargi (pid)
+ call pargr (apstatr (py, OPYXMEAN))
+ call pargr (apstatr (py, OPYYMEAN))
+ call pargr (apstatr (py, OPYCX))
+ call pargr (apstatr (py, OPYCY))
+ call pargr (apstatr (py, PYMINRAD))
+ call pargi (apstati (py, PYNVER))
+
+ # Write out the vertices of the polygon.
+ if (nver == 0) {
+ call fprintf (fd, PY_WSTR4)
+ call pargr (INDEFR)
+ call pargr (INDEFR)
+ call pargstr (" ")
+ } else {
+ do i = 1, nver {
+ call fprintf (fd, PY_WSTR4)
+ if (nver == 1) {
+ call pargr (xver[i])
+ call pargr (yver[i])
+ call pargstr (" ")
+ } else if (i == nver) {
+ call pargr (xver[i])
+ call pargr (yver[i])
+ call pargstr ("* ")
+ } else {
+ call pargr (xver[i])
+ call pargr (yver[i])
+ call pargstr ( "*\\")
+ }
+ }
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_SPYERRORS -- Encode the polygon fitting error in a string.
+
+procedure ap_spyerrors (ier, str, maxch)
+
+int ier # error code
+char str[ARB] # output string
+int maxch # maximum number of characters
+
+begin
+ switch (ier) {
+ case PY_NOPOLYGON:
+ call strcpy ("NoPolygon", str, maxch)
+ case PY_OUTOFBOUNDS:
+ call strcpy ("EdgeImage", str, maxch)
+ case PY_NOPIX:
+ call strcpy ("NoPixels", str, maxch)
+ case PY_NOSKYMODE:
+ call strcpy ("NoSky", str, maxch)
+ case PY_BADDATA:
+ call strcpy ("BadPixels", str, maxch)
+ default:
+ call strcpy ("NoError", str, maxch)
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apwres3.x b/noao/digiphot/apphot/aplib/apwres3.x
new file mode 100644
index 00000000..757361dc
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apwres3.x
@@ -0,0 +1,132 @@
+include "../lib/apphotdef.h"
+include "../lib/radprofdef.h"
+include "../lib/apphot.h"
+include "../lib/radprof.h"
+
+# define the #N, #U and #K radprof strings
+
+define RP_NSTR1 "#N%4tPFWHM%14tINORM%29tTINORM%66tRIER%71tRERROR%80t\\\n"
+define RP_USTR1 "#U%4tScale%14tcounts%29tcounts%66t##%71trerrors%80t\\\n"
+define RP_FSTR1 "#F%4t%%-13.3f%14t%%-15.7f%29t%%-36.7f%66t%%-5d%71t\
+%%-9s%80t \n"
+define RP_WSTR1 "%4t%-10.3f%-15.7g%-36.7g%-5d%-9.9s%80t\\\n"
+
+define RP_NSTR2 "#N%4tPRADIUS%14tINTENSITY%29tTINTENSITY%80t\\\n"
+define RP_USTR2 "#U%4tscale%14tcounts%29tcounts%80t\\\n"
+define RP_FSTR2 "#F%4t%%-13.3f%14t%%-15.7f%29t%%-15.7f%80t \n"
+define RP_WSTR2 "%4t%-10.3f%-15.7g%-15.7g%79t%2s\n"
+
+
+# AP_RHDR -- Print the radprof column header strings.
+
+procedure ap_rhdr (ap, fd)
+
+pointer ap # apphot descriptor (unused)
+int fd # output file descriptor
+
+begin
+ if (fd == NULL)
+ return
+ call fprintf (fd, RP_NSTR1)
+ call fprintf (fd, RP_USTR1)
+ call fprintf (fd, RP_FSTR1)
+ call fprintf (fd, "#\n")
+ call fprintf (fd, RP_NSTR2)
+ call fprintf (fd, RP_USTR2)
+ call fprintf (fd, RP_FSTR2)
+ call fprintf (fd, "#\n")
+end
+
+
+# AP_WRRES -- Write the results of the radprof task to the output file.
+
+procedure ap_wrres (ap, fd, ier)
+
+pointer ap # pointer to apphot structure
+int fd # output text file descriptor
+int ier # radial profile error
+
+int i, nrpts
+pointer sp, str, rprof
+real apstatr()
+
+begin
+ # Initialize.
+ if (fd == NULL)
+ return
+ rprof = AP_RPROF(ap)
+ call smark (sp)
+ call salloc (str, SZ_LINE, TY_CHAR)
+
+ # Print the radprof parameters.
+ call ap_srerrors (ier, Memc[str], SZ_LINE)
+ call fprintf (fd, RP_WSTR1)
+ call pargr (apstatr (ap, RPFWHM) / apstatr (ap, SCALE))
+ call pargr (apstatr (ap, INORM))
+ call pargr (apstatr (ap, TNORM))
+ call pargi (ier)
+ call pargstr (Memc[str])
+
+ # Print the radial profile.
+ nrpts = apstatr (ap, RPRADIUS) / apstatr (ap, RPSTEP) + 1
+ if (nrpts == 0) {
+ call fprintf (fd, RP_WSTR2)
+ call pargr (INDEFR)
+ call pargr (INDEFR)
+ call pargr (INDEFR)
+ call pargstr (" ")
+ } else {
+ do i = 1, nrpts {
+ if (nrpts == 1) {
+ call fprintf (fd, RP_WSTR2)
+ call pargr (Memr[AP_RPDIST(rprof)+i-1] / AP_SCALE(ap))
+ call pargr (Memr[AP_INTENSITY(rprof)+i-1])
+ call pargr (Memr[AP_TINTENSITY(rprof)+i-1])
+ call pargstr (" ")
+ } if (i == nrpts) {
+ call fprintf (fd, RP_WSTR2)
+ call pargr (Memr[AP_RPDIST(rprof)+i-1] / AP_SCALE(ap))
+ call pargr (Memr[AP_INTENSITY(rprof)+i-1])
+ call pargr (Memr[AP_TINTENSITY(rprof)+i-1])
+ call pargstr ("* ")
+ } else {
+ call fprintf (fd, RP_WSTR2)
+ call pargr (Memr[AP_RPDIST(rprof)+i-1] / AP_SCALE(ap))
+ call pargr (Memr[AP_INTENSITY(rprof)+i-1])
+ call pargr (Memr[AP_TINTENSITY(rprof)+i-1])
+ call pargstr ("*\\")
+ }
+ }
+ }
+
+ call sfree (sp)
+end
+
+
+# AP_SRERRORS -- Encode the radial profile error message in a string.
+
+procedure ap_srerrors (ier, str, maxch)
+
+int ier # error code
+char str[ARB] # encoded error string
+int maxch # maximum number of characters
+
+begin
+ switch (ier) {
+ case AP_RP_NOPROFILE:
+ call sprintf (str, maxch, "%s")
+ call pargstr ("OffImage")
+ case AP_RP_OUTOFBOUNDS:
+ call sprintf (str, maxch, "%s")
+ call pargstr ("EdgeImage")
+ case AP_RP_NPTS_TOO_SMALL:
+ call sprintf (str, maxch, "%s")
+ call pargstr ("TooFewPts")
+ case AP_RP_SINGULAR:
+ call sprintf (str, maxch, "%s")
+ call pargstr ("Singular")
+ default:
+ call sprintf (str, maxch, "%s")
+ call pargstr ("NoError")
+ }
+end
diff --git a/noao/digiphot/apphot/aplib/apwres4.x b/noao/digiphot/apphot/aplib/apwres4.x
new file mode 100644
index 00000000..67276ea1
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/apwres4.x
@@ -0,0 +1,238 @@
+include "../lib/apphotdef.h"
+include "../lib/fitpsfdef.h"
+include "../lib/apphot.h"
+include "../lib/fitpsf.h"
+
+# define the #N, #U and #K fitpsf strings
+
+define PSF_RNSTR1 "#N%4tXCENTER%14tYCENTER%24tRSIGMA%33tAMPLITUDE%48t\
+SKY%80t\\\n"
+define PSF_RUSTR1 "#U%4tpixels%14tpixels%24tpixels%33tcounts%48t\
+counts%80t\\\n"
+define PSF_RFSTR1 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.2f%33t%%-15.7g%48t\
+%%-15.7g%80t \n"
+define PSF_RWSTR1 "%4t%-10.3f%14t%-10.3f%24t%-9.2f%33t%-15.7g%48t\
+%-15.7g%80t\\\n"
+
+define PSF_RNSTR2 "#N%4tEXCENTER%14tEYCENTER%24tERSIGMA%33tEAMPLITUDE%48t\
+ESKY%63tIER%68tERROR%80t\\\n"
+define PSF_RUSTR2 "#U%4tpixels%14tpixels%24tpixels%33tcounts%48t\
+counts%63t##%68terrors%80t\\\n"
+define PSF_RFSTR2 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-15.7g%48t\
+%%-15.7g%63t%%-5d%68t%%-13s%80t \n"
+define PSF_RWSTR2 "%4t%-10.3f%14t%-10.3f%24t%-9.3f%33t%-15.7g%48t\
+%-15.7g%63t%-5d%68t%-13.13s\n"
+
+define PSF_ENSTR1 "#N%4tXCENTER%14tYCENTER%24tXSIGMA%33tYSIGMA%42t\
+ROT%49tAMPLITUDE%64tSKY%80t\\\n"
+define PSF_EUSTR1 "#U%4tpixels%14tpixels%24tpixels%33tpixels%42t\
+deg%49tcounts%64tcounts%80t\\\n"
+define PSF_EFSTR1 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.2f%33t%%-9.2f%42t\
+%%-7.2f%49t%%-15.7g%64t%%-15.7g%80t \n"
+define PSF_EWSTR1 "%4t%-10.3f%-10.3f%-9.2f%-9.2f%-7.2f%-15.7g%-15.7g%80t\\\n"
+
+define PSF_ENSTR2 "#N%4tEXCENTER%14tEYCENTER%24tEXSIGMA%33tEYSIGMA%42t\
+EROT%49tEAMPLITDE%64tESKY%80t\\\n"
+define PSF_EUSTR2 "#U%4tpixels%14tpixels%24tpixels%33tpixels%42t\
+deg%49tcounts%64tcounts%80t\\\n"
+define PSF_EFSTR2 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-9.3f%42t\
+%%-7.2f%49t%%-15.7g%64t%%-15.7g%80t \n"
+define PSF_EWSTR2 "%4t%-10.3f%-10.3f%-9.3f%-9.3f%-7.2f%-15.7g%-15.7g%80t\\\n"
+
+define PSF_ENSTR3 "#N%4tIER%9tERROR%80t\\\n"
+define PSF_EUSTR3 "#U%4t##%9terrors%80t\\\n"
+define PSF_EFSTR3 "#F%4t%%-8d%9t%%-13s%80t \n"
+define PSF_EWSTR3 "%4t%-5d%-13.13s%80t \n"
+
+
+define PSF_MNSTR1 "#N%4tXCENTER%14tYCENTER%24tRGYRAT%33tELLIP%42t\
+ROT%49tAMPLITUDE%64tSKY%80t\\\n"
+define PSF_MUSTR1 "#U%4tpixels%14tpixels%24tpixels%33tratio%42tdeg%49t\
+counts%64tcounts%80t\\\n"
+define PSF_MFSTR1 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.2f%33t%%-9.2f%42t\
+%%-7.2f%49t%%-15.7g%64t%%-15.7f%80t \n"
+define PSF_MWSTR1 "%4t%-10.3f%-10.3f%-9.2f%-9.2f%-7.2f%-15.7g%-15.7g%80t\\\n"
+
+define PSF_MNSTR2 "#N%4tEXCENTER%14tEYCENTER%24tERGYRAT%33tEELLIP%42t\
+EROT%49tEAMPLITUDE%64tESKY%80t\\\n"
+define PSF_MUSTR2 "#U%4tpixels%14tpixels%24tpixels%33tratio%42tdeg%49t\
+counts%64tcounts%80t\\\n"
+define PSF_MFSTR2 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-9.3f%42t\
+%%-7.2f%49t%%-15.7g%64t%%-15.7g%80t \n"
+define PSF_MWSTR2 "%4t%-10.3f%-10.3f%-9.3f%-9.3f%-7.2f%-15.7g%-15.7g%80t\\\n"
+
+define PSF_MNSTR3 "#N%4tIER%9tERROR%80t\\\n"
+define PSF_MUSTR3 "#U%4t##%9terrors%80t\\\n"
+define PSF_MFSTR3 "#F%4t%%-8d%9t%%-13s%80t \n"
+define PSF_MWSTR3 "%4t%-5d%-13.13s%80t \n"
+
+
+# AP_WFRES -- Write the results of the fitpsf task to the output file.
+
+procedure ap_wfres (ap, fd, ier)
+
+pointer ap # pointer to apphot structure
+int fd # output file descriptor
+int ier # comment string
+
+pointer psf
+
+begin
+ # Initialize.
+ if (fd == NULL)
+ return
+ psf = AP_PPSF(ap)
+
+ # Print the parameters.
+ switch (AP_PSFUNCTION(psf)) {
+ case AP_RADGAUSS:
+ call fprintf (fd, PSF_RWSTR1)
+ call pargr (Memr[AP_PPARS(psf)+1])
+ call pargr (Memr[AP_PPARS(psf)+2])
+ call pargr (Memr[AP_PPARS(psf)+3])
+ call pargr (Memr[AP_PPARS(psf)])
+ call pargr (Memr[AP_PPARS(psf)+4])
+ call fprintf (fd, PSF_RWSTR2)
+ call pargr (Memr[AP_PPERRS(psf)+1])
+ call pargr (Memr[AP_PPERRS(psf)+2])
+ call pargr (Memr[AP_PPERRS(psf)+3])
+ call pargr (Memr[AP_PPERRS(psf)])
+ call pargr (Memr[AP_PPERRS(psf)+4])
+ call pargi (ier)
+ case AP_ELLGAUSS:
+ call fprintf (fd, PSF_EWSTR1)
+ call pargr (Memr[AP_PPARS(psf)+1])
+ call pargr (Memr[AP_PPARS(psf)+2])
+ call pargr (Memr[AP_PPARS(psf)+3])
+ call pargr (Memr[AP_PPARS(psf)+4])
+ call pargr (Memr[AP_PPARS(psf)+5])
+ call pargr (Memr[AP_PPARS(psf)])
+ call pargr (Memr[AP_PPARS(psf)+6])
+ call fprintf (fd, PSF_EWSTR2)
+ call pargr (Memr[AP_PPERRS(psf)+1])
+ call pargr (Memr[AP_PPERRS(psf)+2])
+ call pargr (Memr[AP_PPERRS(psf)+3])
+ call pargr (Memr[AP_PPERRS(psf)+4])
+ call pargr (Memr[AP_PPERRS(psf)+5])
+ call pargr (Memr[AP_PPERRS(psf)])
+ call pargr (Memr[AP_PPERRS(psf)+6])
+ call fprintf (fd, PSF_EWSTR3)
+ call pargi (ier)
+ case AP_MOMENTS:
+ call fprintf (fd, PSF_MWSTR1)
+ call pargr (Memr[AP_PPARS(psf)+1])
+ call pargr (Memr[AP_PPARS(psf)+2])
+ call pargr (Memr[AP_PPARS(psf)+3])
+ call pargr (Memr[AP_PPARS(psf)+4])
+ call pargr (Memr[AP_PPARS(psf)+5])
+ call pargr (Memr[AP_PPARS(psf)])
+ call pargr (Memr[AP_PPARS(psf)+6])
+ call fprintf (fd, PSF_MWSTR2)
+ call pargr (Memr[AP_PPERRS(psf)+1])
+ call pargr (Memr[AP_PPERRS(psf)+2])
+ call pargr (Memr[AP_PPERRS(psf)+3])
+ call pargr (Memr[AP_PPERRS(psf)+4])
+ call pargr (Memr[AP_PPERRS(psf)+5])
+ call pargr (Memr[AP_PPERRS(psf)])
+ call pargr (Memr[AP_PPERRS(psf)+6])
+ call fprintf (fd, PSF_MWSTR3)
+ call pargi (ier)
+ default:
+ ;
+ }
+
+ # Print the error message.
+ switch (ier) {
+ case AP_NOPSFAREA:
+ call pargstr ("OffImage")
+ case AP_PSF_OUTOFBOUNDS:
+ call pargstr ("EdgeImage")
+ case AP_NPSF_TOO_SMALL:
+ call pargstr ("TooFewPts")
+ case AP_PSF_SINGULAR:
+ call pargstr ("Singular")
+ case AP_PSF_NOCONVERGE:
+ call pargstr ("BadFit")
+ default:
+ call pargstr ("NoError")
+ }
+end
+
+
+# RADHDR -- Write the column headers for the radial gaussian function.
+
+procedure radhdr (ap, fd)
+
+pointer ap # pointer to apphot structure
+int fd # output file descriptor
+
+begin
+ # Print the keyword names.
+ call ap_idhdr (ap, fd)
+
+ call fprintf (fd, PSF_RNSTR1)
+ call fprintf (fd, PSF_RUSTR1)
+ call fprintf (fd, PSF_RFSTR1)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PSF_RNSTR2)
+ call fprintf (fd, PSF_RUSTR2)
+ call fprintf (fd, PSF_RFSTR2)
+ call fprintf (fd, "#\n")
+end
+
+
+# ELHDR -- Write the column headers for the elliptical gaussian function.
+
+procedure elhdr (ap, fd)
+
+pointer ap # pointer to apphot structure
+int fd # output file descriptor
+
+begin
+ # Print the keywords.
+ call ap_idhdr (ap, fd)
+
+ call fprintf (fd, PSF_ENSTR1)
+ call fprintf (fd, PSF_EUSTR1)
+ call fprintf (fd, PSF_EFSTR1)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PSF_ENSTR2)
+ call fprintf (fd, PSF_EUSTR2)
+ call fprintf (fd, PSF_EFSTR2)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PSF_ENSTR3)
+ call fprintf (fd, PSF_EUSTR3)
+ call fprintf (fd, PSF_EFSTR3)
+ call fprintf (fd, "#\n")
+end
+
+
+# MOMHDR -- Write the column headers for the moments function.
+
+procedure momhdr (ap, fd)
+
+pointer ap # pointer to apphot structure
+int fd # output file descriptor
+
+begin
+ # Print the keywords.
+ call ap_idhdr (ap, fd)
+
+ call fprintf (fd, PSF_MNSTR1)
+ call fprintf (fd, PSF_MUSTR1)
+ call fprintf (fd, PSF_MFSTR1)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PSF_MNSTR2)
+ call fprintf (fd, PSF_MUSTR2)
+ call fprintf (fd, PSF_MFSTR2)
+ call fprintf (fd, "#\n")
+
+ call fprintf (fd, PSF_MNSTR3)
+ call fprintf (fd, PSF_MUSTR3)
+ call fprintf (fd, PSF_MFSTR3)
+ call fprintf (fd, "#\n")
+end
diff --git a/noao/digiphot/apphot/aplib/mkpkg b/noao/digiphot/apphot/aplib/mkpkg
new file mode 100644
index 00000000..a426075f
--- /dev/null
+++ b/noao/digiphot/apphot/aplib/mkpkg
@@ -0,0 +1,102 @@
+# APPHOT Library Tools
+
+$checkout libpkg.a ".."
+$update libpkg.a
+$checkin libpkg.a ".."
+$exit
+
+libpkg.a:
+ apairmass.x <imhdr.h> ../lib/apphot.h
+ apapcolon.x <error.h> ../lib/apphot.h
+ aparrays.x ../lib/phot.h ../lib/photdef.h \
+ ../lib/apphotdef.h
+ apfree.x ../lib/apphotdef.h
+ apgaperts.x <lexnum.h> <ctype.h>
+ apgqverify.x <ttyset.h> <fset.h>
+ apgsvw.x <imio.h> <imhdr.h> \
+ <math.h>
+ apgtverify.x
+ apinit.x ../lib/apphotdef.h ../lib/apphot.h \
+ ../lib/noisedef.h ../lib/noise.h \
+ ../lib/displaydef.h
+ apinpars1.x ../lib/apphot.h ../lib/noise.h \
+ ../lib/find.h ../lib/display.h
+ apinpars2.x ../lib/display.h ../lib/center.h \
+ ../lib/fitsky.h ../lib/phot.h \
+ ../lib/polyphot.h
+ apitime.x ../lib/apphot.h <imhdr.h>
+ apfilter.x <imhdr.h> ../lib/apphot.h
+ apimbuf.x ../lib/apphotdef.h
+ apmark1.x <gset.h> ../lib/center.h \
+ ../lib/fitsky.h ../lib/apphot.h \
+ ../lib/phot.h ../lib/polyphot.h \
+ ../lib/radprof.h
+ apmark2.x <gset.h> ../lib/apphot.h \
+ ../lib/fitpsf.h
+ apnew.x ../lib/apphot.h
+ apnscolon.x <error.h> ../lib/noise.h
+ apnshow.x ../lib/apphot.h ../lib/noise.h
+ apotime.x ../lib/apphot.h <imhdr.h>
+ apoutpars1.x ../lib/apphot.h ../lib/noise.h \
+ ../lib/display.h ../lib/find.h
+ apoutpars2.x ../lib/display.h ../lib/center.h \
+ ../lib/fitsky.h ../lib/phot.h \
+ ../lib/polyphot.h
+ apqrad.x ../lib/apphot.h ../lib/center.h \
+ <mach.h>
+ appadu.x ../lib/noise.h <imhdr.h>
+ aprcursor1.x ../lib/apphot.h ../lib/noise.h \
+ ../lib/center.h ../lib/fitsky.h \
+ ../lib/phot.h
+ aprcursor2.x ../lib/apphot.h ../lib/fitpsf.h \
+ ../lib/radprof.h
+ aprdnoise.x ../lib/noise.h <imhdr.h>
+ apset.x
+ apset1.x ../lib/center.h ../lib/centerdef.h \
+ ../lib/fitsky.h ../lib/apphot.h \
+ ../lib/apphotdef.h ../lib/fitskydef.h \
+ ../lib/phot.h ../lib/photdef.h \
+ ../lib/fitpsfdef.h ../lib/fitpsf.h
+ apset2.x ../lib/apphot.h ../lib/apphotdef.h \
+ ../lib/display.h ../lib/polyphot.h \
+ ../lib/radprofdef.h ../lib/radprof.h \
+ ../lib/polyphotdef.h ../lib/noisedef.h \
+ ../lib/noise.h ../lib/finddef.h \
+ ../lib/find.h ../lib/displaydef.h
+ apstat.x
+ apstat1.x ../lib/center.h ../lib/centerdef.h \
+ ../lib/fitsky.h ../lib/apphot.h \
+ ../lib/apphotdef.h ../lib/fitskydef.h \
+ ../lib/phot.h ../lib/photdef.h \
+ ../lib/fitpsfdef.h ../lib/fitpsf.h
+ apstat2.x ../lib/apphot.h ../lib/apphotdef.h \
+ ../lib/display.h ../lib/polyphot.h \
+ ../lib/radprofdef.h ../lib/radprof.h \
+ ../lib/polyphotdef.h ../lib/noisedef.h \
+ ../lib/noise.h ../lib/finddef.h \
+ ../lib/find.h ../lib/displaydef.h
+ apshowplot.x ../lib/apphot.h
+ apverify1.x <math.h> ../lib/apphot.h \
+ ../lib/center.h ../lib/fitsky.h \
+ ../lib/phot.h ../lib/noise.h
+ apverify2.x ../lib/apphot.h ../lib/fitpsf.h \
+ ../lib/noise.h ../lib/find.h \
+ ../lib/radprof.h
+ apwres1.x ../lib/apphot.h ../lib/find.h \
+ ../lib/center.h ../lib/fitsky.h
+ apwres2.x ../lib/apphotdef.h ../lib/photdef.h \
+ ../lib/apphot.h ../lib/fitsky.h \
+ ../lib/phot.h ../lib/polyphot.h
+ apwres3.x ../lib/apphotdef.h ../lib/radprofdef.h \
+ ../lib/apphot.h ../lib/radprof.h
+ apwres4.x ../lib/apphotdef.h ../lib/fitpsfdef.h \
+ ../lib/fitpsf.h ../lib/apphot.h
+ apwparam1.x <time.h> ../lib/apphot.h \
+ ../lib/noise.h ../lib/center.h \
+ ../lib/fitsky.h ../lib/phot.h \
+ ../lib/apphotdef.h
+ apwparam2.x ../lib/apphotdef.h ../lib/polyphot.h \
+ ../lib/radprof.h ../lib/fitpsf.h
+ apimkeys.x ../lib/apphot.h
+ apwcs.x ../lib/apphot.h <imio.h>
+ ;