aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/daophot/addstar
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /noao/digiphot/daophot/addstar
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'noao/digiphot/daophot/addstar')
-rw-r--r--noao/digiphot/daophot/addstar/dpadconfirm.x14
-rw-r--r--noao/digiphot/daophot/addstar/dpaddrd.x89
-rw-r--r--noao/digiphot/daophot/addstar/dpartstar.x303
-rw-r--r--noao/digiphot/daophot/addstar/dpnaddstar.x265
-rw-r--r--noao/digiphot/daophot/addstar/mkpkg17
-rw-r--r--noao/digiphot/daophot/addstar/t_addstar.x331
6 files changed, 1019 insertions, 0 deletions
diff --git a/noao/digiphot/daophot/addstar/dpadconfirm.x b/noao/digiphot/daophot/addstar/dpadconfirm.x
new file mode 100644
index 00000000..bff2ca93
--- /dev/null
+++ b/noao/digiphot/daophot/addstar/dpadconfirm.x
@@ -0,0 +1,14 @@
+# DP_ADCONFIRM -- Confirm the critical ADDSTAR parameters.
+
+procedure dp_adconfirm (dao)
+
+pointer dao # pointer to the daophot structure
+
+begin
+ call printf ("\n")
+
+ # Confirm the psf radius.
+ call dp_vpsfrad (dao)
+
+ call printf ("\n")
+end
diff --git a/noao/digiphot/daophot/addstar/dpaddrd.x b/noao/digiphot/daophot/addstar/dpaddrd.x
new file mode 100644
index 00000000..108448ee
--- /dev/null
+++ b/noao/digiphot/daophot/addstar/dpaddrd.x
@@ -0,0 +1,89 @@
+include "../lib/apseldef.h"
+
+# DP_TADINIT -- Initializie the column descriptors for the input ST photometry
+# table.
+
+procedure dp_tadinit (tp, column)
+
+pointer tp # table descriptor
+int column[ARB] # column pointer array
+
+begin
+ # Find the column pointers
+ call tbcfnd (tp, ID, column[1], 1)
+ if (column[1] == NULL)
+ call tbcfnd (tp, "ID", column[1], 1)
+ if (column[1] == NULL)
+ call printf ("Error reading ID.\n")
+
+ call tbcfnd (tp, XCENTER, column[2], 1)
+ if (column[2] == NULL)
+ call tbcfnd (tp, "XCENTER", column[2], 1)
+ if (column[2] == NULL)
+ call printf ("Error reading XCENTER.\n")
+
+ call tbcfnd (tp, YCENTER, column[3], 1)
+ if (column[3] == NULL)
+ call tbcfnd (tp, "YCENTER", column[3], 1)
+ if (column[3] == NULL)
+ call printf ("Error reading YCENTER.\n")
+
+ call tbcfnd (tp, MAG, column[4], 1)
+ if (column[4] == NULL)
+ call tbcfnd (tp, APMAG, column[4], 1)
+ if (column[4] == NULL)
+ call printf ("Error reading MAG.\n")
+end
+
+
+# DP_TADREAD -- Read a record from the input ST photometry table.
+
+procedure dp_tadread (tp, column, id, x, y, mag, row)
+
+pointer tp # table descriptor
+int column[ARB] # column pointer array
+int id # output id
+real x # output x value
+real y # output y value
+real mag # output magnitude
+int row # integer row
+
+bool nullflag
+
+begin
+ call tbrgti (tp, column[1], id, nullflag, 1, row)
+ if (nullflag)
+ id = 0
+ call tbrgtr (tp, column[2], x, nullflag, 1, row)
+ call tbrgtr (tp, column[3], y, nullflag, 1, row)
+ call tbrgtr (tp, column[4], mag, nullflag, 1, row)
+end
+
+
+# DP_GCOORDS -- Read the coordinates and magnitudes from a simple text file.
+
+int procedure dp_gcoords (cl, x, y, mag, id)
+
+int cl # file descriptor
+real x # x coordinate centers
+real y # y coordinate centers
+real mag # magnitudes
+int id # id of the star
+
+int fscan(), nscan()
+
+begin
+ while (fscan (cl) != EOF) {
+ call gargr (x)
+ call gargr (y)
+ call gargr (mag)
+ if (nscan () < 3)
+ next
+ call gargi (id)
+ if (nscan() < 4)
+ id = 0
+ return (1)
+ }
+
+ return (EOF)
+end
diff --git a/noao/digiphot/daophot/addstar/dpartstar.x b/noao/digiphot/daophot/addstar/dpartstar.x
new file mode 100644
index 00000000..9f464812
--- /dev/null
+++ b/noao/digiphot/daophot/addstar/dpartstar.x
@@ -0,0 +1,303 @@
+include <imhdr.h>
+include <tbset.h>
+include "../lib/daophotdef.h"
+include "../lib/apseldef.h"
+
+define ADD_NINCOLUMN 4
+
+# DP_ARTSTAR -- Add artificial stars to the data frames.
+
+procedure dp_artstar (dao, iim, oim, cl, ofd, nstar, minmag, maxmag, iseed,
+ coo_text, simple, offset, cache)
+
+pointer dao # pointer to DAOPHOT structure
+pointer iim # the input image descriptor
+pointer oim # image to add stars to
+int cl # fd of input photometry file
+int ofd # fd of output photometry file
+int nstar # number of stars to be added
+real minmag, maxmag # min. and max. magnitudes to add
+int iseed[ARB] # the random number generator array
+bool coo_text # coordinate text file ?
+int simple # simple text file ?
+int offset # id offset for output photometry file
+int cache # cache the output pixels
+
+real xmin, ymin, xwide, ywide, mwide, x, y, dxfrom_psf, dyfrom_psf, mag
+real radius, psfradsq, rel_bright, sky, tx, ty
+pointer sp, colpoint, psffit, subim, subim_new, indices, fields, key
+int i, iid, id, lowx, lowy, nxpix, nypix, nrow
+
+pointer dp_gsubrast(), imps2r(), tbpsta()
+int dp_gcoords(), dp_apsel()
+
+begin
+ # Get some memory.
+ call smark (sp)
+ call salloc (fields, SZ_LINE, TY_CHAR)
+ call salloc (indices, ADD_NINCOLUMN, TY_INT)
+ call salloc (colpoint, ADD_NINCOLUMN, TY_INT)
+
+ # Initialize the input photometry file.
+ key = NULL
+ if (cl != NULL) {
+ if (! coo_text) {
+ call dp_tadinit (cl, Memi[indices])
+ nrow = tbpsta (cl, TBL_NROWS)
+ #} else if (coo_text && simple == NO) {
+ } else if (simple == NO) {
+ call pt_kyinit (key)
+ Memi[indices] = DP_PAPID
+ Memi[indices+1] = DP_PAPXCEN
+ Memi[indices+2] = DP_PAPYCEN
+ Memi[indices+3] = DP_PAPMAG1
+ call dp_gappsf (Memi[indices], Memc[fields], ADD_NINCOLUMN)
+ }
+ }
+
+ # Initialize the output table.
+ if (DP_TEXT(dao) == YES)
+ call dp_xnaddstar (dao, ofd)
+ else
+ call dp_tnaddstar (dao, ofd, Memi[colpoint])
+
+ # Get some daophot pointers.
+ psffit = DP_PSFFIT (dao)
+
+ # Get the psf radius
+ if (DP_PSFSIZE(psffit) == 0)
+ radius = DP_PSFRAD(dao)
+ else
+ radius = min (DP_PSFRAD(dao), (real (DP_PSFSIZE(psffit) - 1) /
+ 2.0 - 1.0) / 2.0)
+ psfradsq = radius * radius
+
+ # Get the x and y limits for the random number generator. The
+ # magnitude limits are input by the user.
+ xmin = 1.0
+ xwide = real(IM_LEN(oim,1)) - 1.0
+ ymin = 1.0
+ ywide = real (IM_LEN(oim,2)) - 1.0
+ mwide = maxmag - minmag
+
+ if (DP_VERBOSE (dao) == YES) {
+ call printf ("OUTPUT IMAGE: %s\n")
+ call pargstr (IM_HDRFILE(oim))
+ }
+
+ # Add the stars.
+ i = 1
+ repeat {
+
+ # Get the coords and magnitudes of the star.
+ if (cl == NULL) {
+ call dp_mkcoords (x, y, mag, xmin, xwide, ymin, ywide, minmag,
+ mwide, iseed)
+ id = i + offset
+ if (i > nstar)
+ break
+ } else if (! coo_text) {
+ if (i > nrow)
+ break
+ call dp_tadread (cl, Memi[indices], iid, x, y, mag, i)
+ call dp_win (dao, iim, x, y, x, y, 1)
+ if (iid == 0)
+ iid = i + offset
+ else
+ id = iid
+ } else {
+ if (simple == YES) {
+ if (dp_gcoords (cl, x, y, mag, iid) == EOF)
+ break
+ if (iid == 0)
+ id = i + offset
+ else
+ id = iid
+ } else {
+ if (dp_apsel (key, cl, Memc[fields], Memi[indices], iid, x,
+ y, sky, mag) == EOF)
+ break
+ if (iid == 0)
+ id = i + offset
+ else
+ id = iid
+ }
+ call dp_win (dao, iim, x, y, x, y, 1)
+ }
+
+ # Increment the counter
+ i = i + 1
+
+ # Compute the psf coordinates.
+ call dp_wpsf (dao, iim, x, y, dxfrom_psf, dyfrom_psf, 1)
+ dxfrom_psf = (dxfrom_psf - 1.0) / DP_PSFX(psffit) - 1.0
+ dyfrom_psf = (dyfrom_psf - 1.0) / DP_PSFY(psffit) - 1.0
+
+ # Compute output coordinates.
+ call dp_wout (dao, iim, x, y, tx, ty, 1)
+
+ # Read in the subraster and compute the relative x-y position.
+ subim = dp_gsubrast (oim, x, y, radius, lowx, lowy, nxpix, nypix)
+ if (subim == NULL) {
+ call printf (
+ " Star: %d - X: %6.2f Y: %6.2f Mag: %7.3f off image\n")
+ call pargi (id)
+ call pargr (tx)
+ call pargr (ty)
+ call pargr (mag)
+ next
+ } else if (DP_VERBOSE (dao) == YES) {
+ call printf (
+ " Added Star: %d - X: %6.2f Y: %6.2f Mag: %7.3f\n")
+ call pargi (id)
+ call pargr (tx)
+ call pargr (ty)
+ call pargr (mag)
+ }
+
+ if (DP_TEXT(dao) == YES)
+ call dp_xwadd (ofd, id, tx, ty, mag)
+ else
+ call dp_twadd (ofd, Memi[colpoint], id, tx, ty, mag, id)
+
+ # Get the relative brightness
+ rel_bright = DAO_RELBRIGHT (psffit, mag)
+
+ # Get the output buffer.
+ subim_new = imps2r (oim, lowx, lowx + nxpix - 1, lowy,
+ lowy + nypix - 1)
+
+ # Evaluate the PSF for a single star.
+ x = x - lowx + 1.0
+ y = y - lowy + 1.0
+ call dp_artone (dao, Memr[subim], nxpix, nypix, x, y, rel_bright,
+ dxfrom_psf, dyfrom_psf, psfradsq, DP_PHOTADU(dao), iseed)
+
+ # Make sure the image buffer is flushed. Currently this is a
+ # very inefficient way to do the image i/o.
+ call amovr (Memr[subim], Memr[subim_new], nxpix * nypix)
+ if (cache == NO)
+ call imflush (oim)
+
+ }
+
+ # Release the text file structure.
+ if (key != NULL)
+ call pt_kyfree (key)
+
+ call sfree (sp)
+end
+
+
+# DP_ARTONE -- Add a single star to the image.
+
+procedure dp_artone (dao, subin, nxpix, nypix, x, y, rel_bright, xfrom_psf,
+ yfrom_psf, psfradsq, gain, iseed)
+
+pointer dao # pointer to the daophot structure
+real subin[nxpix,nypix] # input subraster
+int nxpix, nypix # dimensions of subrasters
+real x, y # input position
+real rel_bright # relative brightness
+real xfrom_psf # x distance from the psf
+real yfrom_psf # y distance from the psf
+real psfradsq # psf radius squared
+real gain # gain
+int iseed[ARB] # random number seed array
+
+int ix, iy
+pointer psffit
+real dx, dy, dxsq, dysq, radsq, dvdx, dvdy, value, err
+real dp_usepsf(), dp_nrml(), daoran()
+
+begin
+ psffit = DP_PSFFIT(dao)
+
+ do iy = 1, nypix {
+ dy = real (iy) - y
+ dysq = dy * dy
+ do ix = 1, nxpix {
+ dx = real (ix) - x
+ dxsq = dx * dx
+ radsq = dxsq + dysq
+ if (radsq < psfradsq) {
+ value = rel_bright * dp_usepsf (DP_PSFUNCTION(psffit),
+ dx, dy, DP_PSFHEIGHT(psffit), Memr[DP_PSFPARS(psffit)],
+ Memr[DP_PSFLUT(psffit)], DP_PSFSIZE(psffit),
+ DP_NVLTABLE(psffit), DP_NFEXTABLE(psffit),
+ xfrom_psf, yfrom_psf, dvdx, dvdy)
+ err = daoran (iseed[mod(ix+iy,3)+1])
+ err = sqrt (max (0.0, value / gain)) * dp_nrml (err)
+ subin[ix,iy] = subin[ix,iy] + value + err
+ }
+ }
+ }
+end
+
+
+# DP_MKCOORDS -- Construct a list of coordinates using a random number
+# generator.
+
+procedure dp_mkcoords (x, y, mag, xmin, xwide, ymin, ywide, minmag, mwide,
+ iseed)
+
+real x # x array
+real y # y array
+real mag # magnitude array
+real xmin # xmin value
+real xwide # x coordinate range
+real ymin # ymin value
+real ywide # y coordinate range
+real minmag # minimum magnitude
+real mwide # the magnitude range
+int iseed[ARB] # seed array for random number genrator
+
+real daoran()
+
+begin
+ x = xmin + daoran (iseed[1]) * xwide
+ y = ymin + daoran (iseed[2]) * ywide
+ mag = minmag + daoran (iseed[3]) * mwide
+end
+
+
+# DP_SEED3 -- Seed the random number generator.
+
+procedure dp_seed3 (seed, iseed)
+
+int seed # initial seed value
+int iseed[ARB] # the seed array
+
+int idum
+real daoran()
+
+begin
+ idum = seed
+ iseed[1] = int (524288.* daoran (idum)) + 1
+ iseed[2] = int (524288.* daoran (idum)) + 1
+ iseed[3] = int (524288.* daoran (idum)) + 1
+end
+
+
+# DP_NRML -- Convert a uniform probability distribution to a Gaussian
+# distribution with mean zero and standard deviation of unity.
+
+real procedure dp_nrml (random)
+
+real random # input random number
+
+real p, sign, t
+
+begin
+ p = random
+ sign = -1.0
+ if (p > 0.5) {
+ p = p - 0.5
+ sign = 1.0
+ } else if (p <= 0.0)
+ return (-1.0e20)
+
+ t = sqrt (log (1.0 / (p * p)))
+ return (sign * (t - (2.30753 + 0.27061 * t) /
+ (1.0 + t * (0.99229 + t * 0.04481))))
+end
diff --git a/noao/digiphot/daophot/addstar/dpnaddstar.x b/noao/digiphot/daophot/addstar/dpnaddstar.x
new file mode 100644
index 00000000..b08dd813
--- /dev/null
+++ b/noao/digiphot/daophot/addstar/dpnaddstar.x
@@ -0,0 +1,265 @@
+include <time.h>
+include <tbset.h>
+include "../lib/daophotdef.h"
+include "../lib/apseldef.h"
+
+define ADD_NOUTCOLUMN 4
+
+# DP_TNADDSTAR -- Create an output ADDSTAR table.
+
+procedure dp_tnaddstar (dao, tp, columns)
+
+pointer dao # pointer to daophot structure
+pointer tp # output table decscriptor
+int columns[ARB] # pointer to columns
+
+int i
+pointer sp, colnames, colunits, colformat, col_dtype, col_len
+
+begin
+ # Allocate space for table definition.
+ call smark (sp)
+ call salloc (colnames, ADD_NOUTCOLUMN * (SZ_COLNAME + 1), TY_CHAR)
+ call salloc (colunits, ADD_NOUTCOLUMN * (SZ_COLUNITS + 1), TY_CHAR)
+ call salloc (colformat, ADD_NOUTCOLUMN * (SZ_COLFMT + 1), TY_CHAR)
+ call salloc (col_dtype, ADD_NOUTCOLUMN, TY_INT)
+ call salloc (col_len, ADD_NOUTCOLUMN, TY_INT)
+
+ # Set up the column definitions.
+ call strcpy (ID, Memc[colnames], SZ_COLNAME)
+ call strcpy (XCENTER, Memc[colnames+SZ_COLNAME+1], SZ_COLNAME)
+ call strcpy (YCENTER, Memc[colnames+2*SZ_COLNAME+2], SZ_COLNAME)
+ call strcpy (MAG, Memc[colnames+3*SZ_COLNAME+3], SZ_COLNAME)
+
+ # Set up the column formats.
+ call strcpy ("%5d", Memc[colformat], SZ_COLFMT)
+ call strcpy ("%10.3f", Memc[colformat+SZ_COLFMT+1], SZ_COLFMT)
+ call strcpy ("%10.3f", Memc[colformat+2*SZ_COLFMT+2], SZ_COLFMT)
+ call strcpy ("%12.3f", Memc[colformat+3*SZ_COLFMT+3], SZ_COLFMT)
+
+ # Set up the units definitions.
+ call strcpy ("NUMBER", Memc[colunits], SZ_COLUNITS)
+ call strcpy ("PIXELS", Memc[colunits+SZ_COLUNITS+1], SZ_COLUNITS)
+ call strcpy ("PIXELS", Memc[colunits+2*SZ_COLUNITS+2], SZ_COLUNITS)
+ call strcpy ("MAGNITIDES", Memc[colunits+3*SZ_COLUNITS+3],
+ SZ_COLUNITS)
+
+ # Set up the data types.
+ Memi[col_dtype] = TY_INT
+ Memi[col_dtype+1] = TY_REAL
+ Memi[col_dtype+2] = TY_REAL
+ Memi[col_dtype+3] = TY_REAL
+
+ do i = 1, ADD_NOUTCOLUMN
+ Memi[col_len+i-1] = 1
+
+ call tbcdef (tp, columns, Memc[colnames], Memc[colunits],
+ Memc[colformat], Memi[col_dtype], Memi[col_len], ADD_NOUTCOLUMN)
+ call tbtcre (tp)
+
+ # Write out the header parameters.
+ call dp_tgadppars (dao, tp)
+
+ call sfree (sp)
+
+end
+
+
+define ADD_NAMESTR "#N%4tID%10tXCENTER%20tYCENTER%30tMAG%80t\\\n"
+define ADD_UNITSTR "#U%4t##%10tpixels%20tpixels%30tmagnitudes%80t\\\n"
+define ADD_FORMATSTR "#F%4t%%-9d%10t%%-10.3f%20t%%-10.3f%30t%%-12.3f%80t \n"
+define ADD_DATASTR "%4t%-6d%10t%-10.3f%20t%-10.3f%30t%-12.3f%80t \n"
+
+
+# DP_XNADDSTAR -- Write out the ADDSTAR header parameters into a text file.
+
+procedure dp_xnaddstar (dao, tp)
+
+pointer dao # pointer to the daophot structure
+int tp # group output file descriptor
+
+begin
+ # Add header parameters to the table.
+ call dp_xgadppars (dao, tp)
+
+ # Write out the banner.
+ call fprintf (tp, "#\n")
+ call fprintf (tp, ADD_NAMESTR)
+ call fprintf (tp, ADD_UNITSTR)
+ call fprintf (tp, ADD_FORMATSTR)
+ call fprintf (tp, "#\n")
+end
+
+
+# DP_XWADD -- Procedure to write out the new star to the ADDSTAR output
+# text file.
+
+procedure dp_xwadd (tp, id, x, y, mag)
+
+int tp # output file descriptor
+int id # id number
+real x # x value
+real y # y value
+real mag # magnitude
+
+begin
+ call fprintf (tp, ADD_DATASTR)
+ call pargi (id)
+ call pargr (x)
+ call pargr (y)
+ call pargr (mag)
+end
+
+
+# DP_TWADD -- Procedure to write out the new star to the ADDSTAR output
+# table.
+
+procedure dp_twadd (tp, colpoint, id, x, y, mag, row)
+
+int tp # pointer to group output table
+int colpoint[ARB] # column pointers
+int id # id number
+real x # x value
+real y # y value
+real mag # magnitude
+int row # row number to be added
+
+begin
+ call tbrpti (tp, colpoint[1], id, 1, row)
+ call tbrptr (tp, colpoint[2], x, 1, row)
+ call tbrptr (tp, colpoint[3], y, 1, row)
+ call tbrptr (tp, colpoint[4], mag, 1, row)
+end
+
+
+# DP_XGADPPARS -- Add various parameters to the header of the ADDSTAR text
+# output file.
+
+procedure dp_xgadppars (dao, tp)
+
+pointer dao # pointer to the DAOPHOT structure
+int tp # output file descriptor
+
+pointer sp, outstr, date, time
+int envfind()
+
+begin
+ # 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.
+ if (envfind ("version", Memc[outstr], SZ_LINE) <= 0)
+ call strcpy ("NOAO/IRAF", Memc[outstr], SZ_LINE)
+ call dp_rmwhite (Memc[outstr], Memc[outstr], SZ_LINE)
+ call dp_sparam (tp, "IRAF", Memc[outstr], "version", "")
+
+ if (envfind ("userid", Memc[outstr], SZ_LINE) > 0)
+ call dp_sparam (tp, "USER", Memc[outstr], "name", "")
+ call gethost (Memc[outstr], SZ_LINE)
+ call dp_sparam (tp, "HOST", Memc[outstr], "computer", "")
+ call dp_date (Memc[date], Memc[time], SZ_DATE)
+ call dp_sparam (tp, "DATE", Memc[date], "yyyy-mm-dd", "")
+ call dp_sparam (tp, "TIME", Memc[time], "hh:mm:ss", "")
+ call dp_sparam (tp, "PACKAGE", "daophot", "name", "")
+ call dp_sparam (tp, "TASK", "addstar", "name", "")
+
+ # Write the file name parameters.
+ call dp_imroot (DP_INIMAGE(dao), Memc[outstr], SZ_LINE)
+ call dp_sparam (tp, "IMAGE", Memc[outstr], "imagename", "")
+ call dp_froot (DP_INPHOTFILE(dao), Memc[outstr], SZ_LINE)
+ call dp_sparam (tp, "PHOTFILE", Memc[outstr], "filename", "")
+ call dp_imroot (DP_PSFIMAGE(dao), Memc[outstr], SZ_LINE)
+ call dp_sparam (tp, "PSFIMAGE", Memc[outstr], "imagename", "")
+ call dp_imroot (DP_OUTIMAGE(dao), Memc[outstr], SZ_LINE)
+ call dp_sparam (tp, "ADDIMAGE", Memc[outstr], "imagename", "")
+ call dp_froot (DP_OUTPHOTFILE(dao), Memc[outstr], SZ_LINE)
+ call dp_sparam (tp, "ADDFILE", Memc[outstr], "filename", "")
+
+ # Write out relevant data parameters.
+ call dp_rparam (tp, "SCALE", DP_SCALE(dao), "units/pix", "")
+ call dp_rparam (tp, "DATAMIN", DP_MINGDATA(dao), "counts", "")
+ call dp_rparam (tp, "DATAMAX", DP_MAXGDATA(dao), "counts", "")
+ call dp_rparam (tp, "GAIN", DP_PHOTADU(dao), "number", "")
+ call dp_rparam (tp, "READNOISE", DP_READNOISE(dao), "electrons", "")
+
+ # Write out the observing parameters.
+ call dp_sparam (tp, "OTIME", DP_OTIME(dao), "timeunit", "")
+ call dp_rparam (tp, "XAIRMASS", DP_XAIRMASS(dao), "number", "")
+ call dp_sparam (tp, "IFILTER", DP_IFILTER(dao), "filter", "")
+
+ # Write out the daopars parameters.
+ call dp_rparam (tp, "PSFRAD", DP_SPSFRAD(dao), "scaleunit", "")
+ call dp_rparam (tp, "FITRAD", DP_SFITRAD(dao), "scaleunit", "")
+
+ call sfree(sp)
+end
+
+
+# DP_TGADPPARS -- Add various parameters to the header of the ADDSTAR output
+# table.
+
+procedure dp_tgadppars (dao, tp)
+
+pointer dao # pointer to the DAOPHOT structure
+pointer tp # pointer to the output table
+
+pointer sp, outstr, date, time
+int envfind()
+
+begin
+ # 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.
+
+ if (envfind ("version", Memc[outstr], SZ_LINE) <= 0)
+ call strcpy ("NOAO/IRAF", Memc[outstr], SZ_LINE)
+ call dp_rmwhite (Memc[outstr], Memc[outstr], SZ_LINE)
+ call tbhadt (tp, "IRAF", Memc[outstr])
+
+ if (envfind ("userid", Memc[outstr], SZ_LINE) > 0)
+ call tbhadt (tp, "USER", Memc[outstr])
+ call gethost (Memc[outstr], SZ_LINE)
+ call tbhadt (tp, "HOST", Memc[outstr])
+ call dp_date (Memc[date], Memc[time], SZ_DATE)
+ call tbhadt (tp, "DATE", Memc[date])
+ call tbhadt (tp, "TIME", Memc[time])
+ call tbhadt (tp, "PACKAGE", "daophot")
+ call tbhadt (tp, "TASK", "group")
+
+ # Write the file name parameters.
+ call dp_imroot (DP_INIMAGE(dao), Memc[outstr], SZ_LINE)
+ call tbhadt (tp, "IMAGE", Memc[outstr])
+ call dp_froot (DP_INPHOTFILE(dao), Memc[outstr], SZ_LINE)
+ call tbhadt (tp, "PHOTFILE", Memc[outstr])
+ call dp_imroot (DP_PSFIMAGE(dao), Memc[outstr], SZ_LINE)
+ call tbhadt (tp, "PSFIMAGE", Memc[outstr])
+ call dp_imroot (DP_OUTIMAGE(dao), Memc[outstr], SZ_LINE)
+ call tbhadt (tp, "ADDIMAGE", Memc[outstr])
+ call dp_froot (DP_OUTPHOTFILE(dao), Memc[outstr], SZ_LINE)
+ call tbhadt (tp, "ADDFILE", Memc[outstr])
+
+ # Write out relevant data parameters.
+ call tbhadr (tp, "SCALE", DP_SCALE(dao))
+ call tbhadr (tp, "DATAMIN", DP_MINGDATA(dao))
+ call tbhadr (tp, "DATAMAX", DP_MAXGDATA(dao))
+ call tbhadr (tp, "GAIN", DP_PHOTADU(dao))
+ call tbhadr (tp, "READNOISE", DP_READNOISE(dao))
+
+ # Write out the observing parameters.
+ call tbhadt (tp, "OTIME", DP_OTIME(dao))
+ call tbhadr (tp, "XAIRMASS", DP_XAIRMASS(dao))
+ call tbhadt (tp, "IFILTER", DP_IFILTER(dao))
+
+ # Write out the daophot parameters.
+ call tbhadr (tp, "PSFRAD", DP_SPSFRAD(dao))
+ call tbhadr (tp, "FITRAD", DP_SFITRAD(dao))
+
+ call sfree(sp)
+end
diff --git a/noao/digiphot/daophot/addstar/mkpkg b/noao/digiphot/daophot/addstar/mkpkg
new file mode 100644
index 00000000..9092f186
--- /dev/null
+++ b/noao/digiphot/daophot/addstar/mkpkg
@@ -0,0 +1,17 @@
+# ADDSTAR task
+
+$checkout libpkg.a ".."
+$update libpkg.a
+$checkin libpkg.a ".."
+$exit
+
+libpkg.a:
+ dpaddrd.x ../lib/apseldef.h
+ dpadconfirm.x
+ dpartstar.x <tbset.h> <imhdr.h> \
+ ../lib/daophotdef.h ../lib/apseldef.h
+ dpnaddstar.x <tbset.h> <time.h> \
+ ../lib/daophotdef.h ../lib/apseldef.h
+ t_addstar.x <fset.h> <imhdr.h> \
+ ../lib/daophotdef.h
+ ;
diff --git a/noao/digiphot/daophot/addstar/t_addstar.x b/noao/digiphot/daophot/addstar/t_addstar.x
new file mode 100644
index 00000000..479188c0
--- /dev/null
+++ b/noao/digiphot/daophot/addstar/t_addstar.x
@@ -0,0 +1,331 @@
+include <fset.h>
+include <imhdr.h>
+include "../lib/daophotdef.h"
+
+define NSEED 3
+
+# T_ADDSTAR -- Add artificial stars to a list of images.
+
+procedure t_addstar ()
+
+pointer image # the input image
+pointer psfimage # the input PSF image
+pointer photfile # the input photometry file
+pointer addimage # root name for output image and file
+real minmag, maxmag # magnitude range of artificial stars
+int nstar # number of artificial stars
+int nimage # number of new images
+int cache # cache the output image pixels
+
+pointer sp, outfname, im, psffd, oim, dao, str
+int imlist, limlist, plist, lplist, pimlist, lpimlist, oimlist, loimlist
+int ifd, ofd, j, simple, idoffset, root, verbose, verify, update, wcs
+int req_size, old_size, buf_size, memstat
+int seed, iseed[NSEED]
+bool coo_text
+
+real clgetr()
+pointer immap(), tbtopn()
+int clgeti(), fstati(), btoi(), fnldir(), strlen(), strncmp()
+int access(), open(), imtopen(), imtlen(), imtgetim(), fntopnb(), fntlenb()
+int fntgfnb(), clgwrd(), sizeof(), dp_memstat()
+bool itob(), clgetb()
+
+begin
+ # Set the standard output to flush on newline.
+ if (fstati (STDOUT, F_REDIR) == NO)
+ call fseti (STDOUT, F_FLUSHNL, YES)
+
+ # Allocate some memory.
+ call smark (sp)
+ call salloc (image, SZ_FNAME, TY_CHAR)
+ call salloc (psfimage, SZ_FNAME, TY_CHAR)
+ call salloc (photfile, SZ_FNAME, TY_CHAR)
+ call salloc (addimage, SZ_FNAME, TY_CHAR)
+ call salloc (outfname, SZ_FNAME, TY_CHAR)
+ call salloc (str, SZ_FNAME, TY_CHAR)
+
+ # Get the file names.
+ call clgstr ("image", Memc[image], SZ_FNAME)
+ call clgstr ("photfile", Memc[photfile], SZ_FNAME)
+ call clgstr ("psfimage", Memc[psfimage], SZ_FNAME)
+ call clgstr ("addimage", Memc[addimage], SZ_FNAME)
+
+ # Open the file/image lists.
+ imlist = imtopen (Memc[image])
+ limlist = imtlen (imlist)
+ plist = fntopnb (Memc[photfile], NO)
+ lplist = fntlenb (plist)
+ pimlist = imtopen (Memc[psfimage])
+ lpimlist = imtlen (pimlist)
+ oimlist = imtopen (Memc[addimage])
+ loimlist = imtlen (oimlist)
+
+ # Check that the image and input photometry list lengths match.
+ if ((lplist > 1) && (lplist != limlist)) {
+ call imtclose (imlist)
+ call fntclsb (plist)
+ call imtclose (pimlist)
+ call imtclose (oimlist)
+ call sfree (sp)
+ call error (0, "Incompatible image and photometry list lengths")
+ }
+
+ # Check that the image and psf image list lengths match.
+ if ((limlist != lpimlist) && (strncmp (Memc[psfimage], DEF_DEFNAME,
+ DEF_LENDEFNAME) != 0)) {
+ call imtclose (imlist)
+ call fntclsb (plist)
+ call imtclose (pimlist)
+ call imtclose (oimlist)
+ call sfree (sp)
+ call error (0, "Incompatible image and psf image list lengths")
+ }
+
+ # Check that image and output image list lengths match.
+ if ((loimlist != limlist) && (strncmp (Memc[addimage], DEF_DEFNAME,
+ DEF_LENDEFNAME) != 0)) {
+ call imtclose (imlist)
+ call fntclsb (plist)
+ call imtclose (pimlist)
+ call imtclose (oimlist)
+ call sfree (sp)
+ call error (0, "Incompatible input and output image list lengths")
+ }
+
+ # Set the type of input text file.
+ simple = btoi (clgetb ("simple_text"))
+
+ # Get the articial star parameters.
+ nimage = clgeti ("nimage")
+ if (lplist <= 0) {
+ nstar = clgeti ("nstar")
+ minmag = clgetr ("minmag")
+ maxmag = clgetr ("maxmag")
+ }
+ seed = clgeti ("seed")
+ idoffset = clgeti ("idoffset")
+
+ verbose = btoi (clgetb ("verbose"))
+ verify = btoi (clgetb ("verify"))
+ update = btoi (clgetb ("update"))
+ cache = btoi (clgetb("cache"))
+
+ # Initialize the daophot structure.
+ call dp_gppars (dao)
+ call dp_seti (dao, VERBOSE, verbose)
+
+ # Verify, confirm, update the parameters.
+ if (verify == YES) {
+ call dp_adconfirm (dao)
+ if (update == YES)
+ call dp_pppars (dao)
+ }
+
+ # Get the wcs information.
+ wcs = clgwrd ("wcsin", Memc[str], SZ_FNAME, WCSINSTR)
+ if (wcs <= 0) {
+ call eprintf (
+ "Warning: Setting the input coordinate system to logical\n")
+ wcs = WCS_LOGICAL
+ }
+ call dp_seti (dao, WCSIN, wcs)
+ wcs = clgwrd ("wcsout", Memc[str], SZ_FNAME, WCSOUTSTR)
+ if (wcs <= 0) {
+ call eprintf (
+ "Warning: Setting the output coordinate system to logical\n")
+ wcs = WCS_LOGICAL
+ }
+ call dp_seti (dao, WCSOUT, wcs)
+ wcs = clgwrd ("wcspsf", Memc[str], SZ_FNAME, WCSPSFSTR)
+ if (wcs <= 0) {
+ call eprintf (
+ "Warning: Setting the psf coordinate system to logical\n")
+ wcs = WCS_LOGICAL
+ }
+ call dp_seti (dao, WCSPSF, wcs)
+
+
+ # Open the PSF structure
+ call dp_fitsetup (dao)
+
+ # Initialize the random number generator.
+ call dp_seed3 (seed, iseed)
+
+ # Now loop over the input image list
+ while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) {
+
+ # Open the input image.
+ im = immap (Memc[image], READ_ONLY, 0)
+ call dp_imkeys (dao, im)
+ call dp_sets (dao, INIMAGE, Memc[image])
+
+ # Cache the output image pixels.
+ req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) *
+ sizeof (IM_PIXTYPE(im))
+ memstat = dp_memstat (cache, req_size, old_size)
+ #if (memstat == YES)
+ #call dp_pcache (im, INDEFI, buf_size)
+
+ # Read the PSF image.
+ if (imtgetim (pimlist, Memc[psfimage], SZ_FNAME) == EOF)
+ call strcpy (DEF_DEFNAME, Memc[psfimage], SZ_FNAME)
+ root = fnldir (Memc[psfimage], Memc[outfname], SZ_FNAME)
+ if (strncmp (DEF_DEFNAME, Memc[psfimage+root],
+ DEF_LENDEFNAME) == 0 || root == strlen (Memc[psfimage]))
+ call dp_iimname (Memc[image], Memc[outfname], "psf",
+ Memc[outfname], SZ_FNAME)
+ else
+ call strcpy (Memc[psfimage], Memc[outfname], SZ_FNAME)
+ psffd = immap (Memc[outfname], READ_ONLY, 0)
+ call dp_sets (dao, PSFIMAGE, Memc[outfname])
+ call dp_readpsf (dao, psffd)
+
+ # Open the input photometry file.
+ if (lplist <= 0 ) {
+ ifd = NULL
+ call strcpy ("", Memc[photfile], SZ_FNAME)
+ } else if (fntgfnb (plist, Memc[photfile], SZ_FNAME) != EOF) {
+ coo_text = itob (access (Memc[photfile], 0, TEXT_FILE))
+ if (coo_text)
+ ifd = open (Memc[photfile], READ_ONLY, TEXT_FILE)
+ else
+ ifd = tbtopn (Memc[photfile], READ_ONLY, 0)
+ } else
+ call seek (ifd, BOF)
+ call dp_sets (dao, INPHOTFILE, Memc[photfile])
+
+ # Get the output image and file root name.
+ if (imtgetim (oimlist, Memc[addimage], SZ_FNAME) == EOF)
+ call strcpy (DEF_DEFNAME, Memc[addimage], SZ_FNAME)
+
+ # Now loop over the number of output images per input image.
+ do j = 1, nimage {
+
+ # Open the output image.
+ root = fnldir (Memc[addimage], Memc[outfname], SZ_FNAME)
+ if (strncmp (DEF_DEFNAME, Memc[addimage+root],
+ DEF_LENDEFNAME) == 0 || root == strlen (Memc[addimage])) {
+ call dp_oimname (Memc[image], Memc[outfname], "add",
+ Memc[outfname], SZ_FNAME)
+ oim = immap (Memc[outfname], NEW_COPY, im)
+ } else {
+ call strcpy (Memc[addimage], Memc[outfname], SZ_FNAME)
+ if (nimage > 1) {
+ call sprintf (Memc[outfname+
+ strlen(Memc[outfname])], SZ_FNAME, "%03d")
+ call pargi (j)
+ }
+ oim = immap (Memc[outfname], NEW_COPY, im)
+ }
+ call dp_sets (dao, OUTIMAGE, Memc[outfname])
+ if (memstat == YES)
+ call dp_pcache (oim, INDEFI, buf_size)
+
+ # Copy the input image to the new output image.
+ call dp_imcopy (im, oim)
+ if (memstat == NO)
+ call imflush (oim)
+
+ # Open the output photometry file.
+ root = fnldir (Memc[addimage], Memc[outfname], SZ_FNAME)
+ if (strncmp (DEF_DEFNAME, Memc[addimage+root],
+ DEF_LENDEFNAME) == 0 || root == strlen (Memc[addimage])) {
+ call dp_outname (Memc[image], Memc[outfname], "art",
+ Memc[outfname], SZ_FNAME)
+ if (DP_TEXT(dao) == YES)
+ ofd = open (Memc[outfname], NEW_FILE, TEXT_FILE)
+ else
+ ofd = tbtopn (Memc[outfname], NEW_FILE, 0)
+ } else {
+ call strcpy (Memc[addimage], Memc[outfname], SZ_FNAME)
+ if (nimage > 1) {
+ call sprintf (Memc[outfname+
+ strlen(Memc[outfname])], SZ_FNAME, "%03d")
+ call pargi (j)
+ }
+ call strcat (".art", Memc[outfname], SZ_FNAME)
+ if (DP_TEXT(dao) == YES)
+ ofd = open (Memc[outfname], NEW_FILE, TEXT_FILE)
+ else
+ ofd = tbtopn (Memc[outfname], NEW_FILE, 0)
+ }
+ call dp_sets (dao, OUTPHOTFILE, Memc[outfname])
+
+ # Now go and actually add the stars.
+ call dp_artstar (dao, im, oim, ifd, ofd, nstar, minmag,
+ maxmag, iseed, coo_text, simple, idoffset, memstat)
+
+ # Close the output image and output table.
+ call imunmap (oim)
+ if (DP_TEXT(dao) == YES)
+ call close (ofd)
+ else
+ call tbtclo (ofd)
+ }
+
+ # Close the input image
+ call imunmap (im)
+
+ # Close the PSF image.
+ call imunmap (psffd)
+
+ # Close the input photometry file if there is more than one.
+ if ((ifd != NULL) && (lplist > 1)) {
+ if (coo_text)
+ call close (ifd)
+ else
+ call tbtclo (ifd)
+ ifd = NULL
+ }
+
+ # Uncache memory.
+ call fixmem (old_size)
+ }
+
+ # If there was only a single photometry file close it.
+ if (ifd != NULL && lplist == 1) {
+ if (coo_text)
+ call close (ifd)
+ else
+ call tbtclo (ifd)
+ }
+
+ # Close the image/file lists.
+ call imtclose (imlist)
+ call fntclsb (plist)
+ call imtclose (pimlist)
+ call imtclose (oimlist)
+
+ # Close the PSF structure.
+ call dp_fitclose (dao)
+
+ # Close the daophot structure.
+ call dp_free (dao)
+
+ call sfree (sp)
+end
+
+
+# DP_IMCOPY -- Make a copy of an image.
+
+procedure dp_imcopy (in, out)
+
+pointer in # the input image
+pointer out # input and output descriptors
+
+int npix
+long v1[IM_MAXDIM], v2[IM_MAXDIM]
+pointer l1, l2
+pointer imgnlr(), impnlr()
+
+begin
+ # Initialize position vectors.
+ call amovkl (long(1), v1, IM_MAXDIM)
+ call amovkl (long(1), v2, IM_MAXDIM)
+ npix = IM_LEN(in, 1)
+
+ # Copy the image.
+ while (imgnlr (in, l1, v1) != EOF && impnlr (out, l2, v2) != EOF)
+ call amovr (Memr[l1], Memr[l2], npix)
+end