diff options
Diffstat (limited to 'noao/digiphot/daophot/select')
-rw-r--r-- | noao/digiphot/daophot/select/dpgwselect.x | 141 | ||||
-rw-r--r-- | noao/digiphot/daophot/select/dppfmerge.x | 81 | ||||
-rw-r--r-- | noao/digiphot/daophot/select/dpsgroup.x | 95 | ||||
-rw-r--r-- | noao/digiphot/daophot/select/mkpkg | 15 | ||||
-rw-r--r-- | noao/digiphot/daophot/select/t_grpselect.x | 105 | ||||
-rw-r--r-- | noao/digiphot/daophot/select/t_pfmerge.x | 110 |
6 files changed, 547 insertions, 0 deletions
diff --git a/noao/digiphot/daophot/select/dpgwselect.x b/noao/digiphot/daophot/select/dpgwselect.x new file mode 100644 index 00000000..dcaafece --- /dev/null +++ b/noao/digiphot/daophot/select/dpgwselect.x @@ -0,0 +1,141 @@ +include "../lib/daophotdef.h" +include "../lib/apseldef.h" + +define NCOLUMN 6 + +define GR_DATASTR "%-9d%10t%-6d%16t%-10.3f%26t%-10.3f%36t%-12.3f%48t%-15.7g%80t \n" + +# DP_XWRTSELECT -- Write out the groups into an ST Table. + +procedure dp_xwrtselect (dao, grp, ngroup, group_id) + +pointer dao # pointer to the daophot structure +pointer grp # pointer to group output file +int ngroup # number in the group +int group_id # the id of the group + +int i +pointer apsel + +begin + # Get the daophot pointer. + apsel = DP_APSEL(dao) + + # Write out the data. + do i = 1, ngroup { + call fprintf (grp, GR_DATASTR) + call pargi (group_id) + call pargi (Memi[DP_APID(apsel)+i-1]) + call pargr (Memr[DP_APXCEN(apsel)+i-1]) + call pargr (Memr[DP_APYCEN(apsel)+i-1]) + call pargr (Memr[DP_APMAG(apsel)+i-1]) + call pargr (Memr[DP_APMSKY(apsel)+i-1]) + } +end + + +# DP_TWRTSELECT -- Write out the groups into an ST Table. + +procedure dp_twrtselect (dao, grp, colpoint, ngroup, cur_group, row) + +pointer dao # pointer to the daophot structure +pointer grp # pointer to group output file +pointer colpoint[ARB] # column pointers +int ngroup # number in group +int cur_group # current group + +int i, row +pointer apsel + +begin + # Get the daophot pointer. + apsel = DP_APSEL(dao) + + # Write out the data. + do i = 1, ngroup { + row = row + 1 + call tbrpti (grp, colpoint[1], Memi[DP_APID(apsel)+i-1], 1, row) + call tbrpti (grp, colpoint[2], cur_group, 1, row) + call tbrptr (grp, colpoint[3], Memr[DP_APXCEN(apsel)+i-1], 1, row) + call tbrptr (grp, colpoint[4], Memr[DP_APYCEN(apsel)+i-1], 1, row) + call tbrptr (grp, colpoint[5], Memr[DP_APMAG(apsel)+i-1], 1, row) + call tbrptr (grp, colpoint[6], Memr[DP_APMSKY(apsel)+i-1], 1, row) + + } +end + + +# DP_XGSELPARS -- Add various parameters to the header of the group table. + +procedure dp_xgselpars (tp, min_group, max_group) + +pointer tp # pointer to the table +int min_group # minimum group size +int max_group # maximum group size + +begin + # Add the min_group and max_group parameters. + call dp_iparam (tp, "MINSZGROUP", min_group, "number", "") + call dp_iparam (tp, "MAXSZGROUP", max_group, "number", "") +end + + +# DP_TGSELCOL -- Set the column pointers for the output file. + +procedure dp_tgselcol (tp, colpoints) + +pointer tp # table pointer +pointer colpoints[ARB] # column pointers + +begin + call tbcfnd (tp, ID, colpoints[1], 1) + if (colpoints[1] == NULL) + call tbcfnd (tp, "ID", colpoints[1], 1) + if (colpoints[1] == NULL) + call printf ("Error reading ID.\n") + + call tbcfnd (tp, GROUP, colpoints[2], 1) + if (colpoints[2] == NULL) + call tbcfnd (tp, "GROUP", colpoints[2], 1) + if (colpoints[2] == NULL) + call printf ("Error reading GROUP.\n") + + call tbcfnd (tp, XCENTER, colpoints[3], 1) + if (colpoints[3] == NULL) + call tbcfnd (tp, "XCENTER", colpoints[3], 1) + if (colpoints[3] == NULL) + call printf ("Error reading XCENTER.\n") + + call tbcfnd (tp, YCENTER, colpoints[4], 1) + if (colpoints[4] == NULL) + call tbcfnd (tp, "YCENTER", colpoints[4], 1) + if (colpoints[4] == NULL) + call printf ("Error reading YCENTER.\n") + + call tbcfnd (tp, MAG, colpoints[5], 1) + if (colpoints[5] == NULL) + call tbcfnd (tp, APMAG, colpoints[5], 1) + if (colpoints[5] == NULL) + call printf ("Error reading MAG.\n") + + call tbcfnd (tp, SKY, colpoints[6], 1) + if (colpoints[6] == NULL) + call tbcfnd (tp, SKY, colpoints[6], 1) + if (colpoints[6] == NULL) + call printf ("Error reading SKY.\n") +end + + +# DP_TGSELPARS -- Add various parameters to the header of the group table. + +procedure dp_tgselpars (tp, min_group, max_group) + +pointer tp # pointer to the table +int min_group # minimum group size +int max_group # maximum group size + +begin + # Add the min_group and max_group parameters. + call tbhadi (tp, "MINSZGROUP", min_group) + call tbhadi (tp, "MAXSZGROUP", max_group) +end diff --git a/noao/digiphot/daophot/select/dppfmerge.x b/noao/digiphot/daophot/select/dppfmerge.x new file mode 100644 index 00000000..1d48cfba --- /dev/null +++ b/noao/digiphot/daophot/select/dppfmerge.x @@ -0,0 +1,81 @@ +include <tbset.h> +include "../lib/apseldef.h" + +# DP_PFMERGE -- Read the input photometry file, extract the fields ID, +# XCENTER, YCENTER, MAG, and MSKY from each input record and add these +# records to the output file. + +define NCOLUMN 5 + +procedure dp_pfmerge (infd, outfd, in_text, out_text, first_file) + +int infd # the input file descriptor +int outfd # the output file descriptor +int in_text # input text file ? +int out_text # output text file ? +int first_file # first file ? + +int nrow, instar, outstar, id +pointer sp, indices, fields, ocolpoint, key +real x, y, mag, sky +int tbpsta(), dp_rrphot() + +begin + # Allocate some memory. + call smark (sp) + call salloc (indices, NAPPAR, TY_INT) + call salloc (fields, SZ_LINE, TY_CHAR) + call salloc (ocolpoint, NCOLUMN, TY_POINTER) + + # Initialize the output file. + if (first_file == YES) { + if (out_text == YES) { + call seek (infd, BOF) + call dp_apheader (infd, outfd) + call dp_xpbanner (outfd) + } else { + call dp_tpdefcol (outfd, Memi[ocolpoint]) + call tbhcal (infd, outfd) + } + outstar = 0 + } + + # Initialize the input file + if (in_text == YES) { + call pt_kyinit (key) + Memi[indices] = DP_PAPID + Memi[indices+1] = DP_PAPXCEN + Memi[indices+2] = DP_PAPYCEN + Memi[indices+3] = DP_PAPMAG1 + Memi[indices+4] = DP_PAPSKY + call dp_gappsf (Memi[indices], Memc[fields], NAPRESULT) + nrow = 0 + } else { + call dp_tpkinit (infd, Memi[indices]) + nrow = tbpsta (infd, TBL_NROWS) + } + + # Loop over the stars. + instar = 0 + repeat { + + # Read the input record. + if (dp_rrphot (infd, key, Memc[fields], Memi[indices], id, + x, y, sky, mag, instar, nrow) == EOF) + break + + # Write the output record. + outstar = outstar + 1 + if (out_text == YES) + call dp_xpselmer (outfd, id, x, y, mag, sky) + else + call dp_tpselmer (outfd, id, x, y, mag, sky, Memi[ocolpoint], + outstar) + } + + + if (in_text == YES) + call pt_kyfree (key) + + call sfree (sp) +end diff --git a/noao/digiphot/daophot/select/dpsgroup.x b/noao/digiphot/daophot/select/dpsgroup.x new file mode 100644 index 00000000..02b77ee7 --- /dev/null +++ b/noao/digiphot/daophot/select/dpsgroup.x @@ -0,0 +1,95 @@ +include <tbset.h> +include "../lib/daophotdef.h" +include "../lib/apseldef.h" + +define NCOLUMN 6 + +# DP_SGROUP -- Read in each group from the input file and write it to the +# output file if its size is between min_group and max_group. + +procedure dp_sgroup (dao, tp_in, tp_out, text_file, min_group, max_group) + +pointer dao # pointer to the daophot structure +pointer tp_in # the input file descriptor +pointer tp_out # the output file descriptor +bool text_file # text or table file +int min_group # minimum sized group to extract +int max_group # maximum sized group to extract + +int nrow_in_table, output_row, in_record, ngroup, cur_group +pointer sp, indices, fields, key, icolpoint, ocolpoint +int tbpsta(), dp_ggroup() + +begin + # Allocate some working memory. + call smark (sp) + call salloc (icolpoint, NAPGROUP, TY_POINTER) + call salloc (indices, NAPGROUP, TY_INT) + call salloc (fields, SZ_LINE, TY_CHAR) + call salloc (ocolpoint, NCOLUMN, TY_POINTER) + + # Allocate some memory for reading in the group. + call dp_gnindices (Memi[indices]) + call dp_memapsel (dao, Memi[indices], NAPPAR, max_group + 1) + + # Initialize the output file. + if (text_file) { + call dp_apheader (tp_in, tp_out) + call dp_xgselpars (tp_out, min_group, max_group) + call dp_apbanner (tp_in, tp_out) + } else { + call tbtcre (tp_out) + call tbhcal (tp_in, tp_out) + call dp_tgselcol (tp_out, Memi[ocolpoint]) + call dp_tgselpars (tp_out, min_group, max_group) + } + + # Initialize the input file. + if (text_file) { + call pt_kyinit (key) + call dp_gnstpsf (Memi[indices], Memc[fields], NAPGROUP) + nrow_in_table = 0 + } else { + key = NULL + call dp_tnsinit (tp_in, Memi[icolpoint]) + nrow_in_table = tbpsta (tp_in, TBL_NROWS) + } + + # Initialize the output record counter. + output_row = 0 + + # Initialize the input record counter. + in_record = 1 + + repeat { + + # Read in the group. + ngroup = dp_ggroup (dao, tp_in, key, Memc[fields], Memi[indices], + Memi[icolpoint], nrow_in_table, max_group, in_record, + cur_group) + if (ngroup <= 0) + break + if (ngroup < min_group || ngroup > max_group) + next + + # Print a message to the terminal. + if (DP_VERBOSE(dao) == YES) { + call printf ("Selecting group: %6d of %6d star(s)\n") + call pargi (cur_group) + call pargi (ngroup) + } + + # Write the group to the output file. + if (text_file) + call dp_xwrtselect (dao, tp_out, ngroup, cur_group) + else + call dp_twrtselect (dao, tp_out, Memi[ocolpoint], ngroup, + cur_group, output_row) + } + + if (text_file) + call pt_kyfree (key) + + # Free memory. + call sfree (sp) +end diff --git a/noao/digiphot/daophot/select/mkpkg b/noao/digiphot/daophot/select/mkpkg new file mode 100644 index 00000000..38c8bb67 --- /dev/null +++ b/noao/digiphot/daophot/select/mkpkg @@ -0,0 +1,15 @@ +# GRPSELECT and PFMERGE tasks + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + dppfmerge.x <tbset.h> ../lib/apseldef.h + dpsgroup.x <tbset.h> ../lib/daophotdef.h \ + ../lib/apseldef.h + dpgwselect.x ../lib/apseldef.h ../lib/daophotdef.h + t_grpselect.x <fset.h> ../lib/daophotdef.h + t_pfmerge.x <fset.h> + ; diff --git a/noao/digiphot/daophot/select/t_grpselect.x b/noao/digiphot/daophot/select/t_grpselect.x new file mode 100644 index 00000000..89377270 --- /dev/null +++ b/noao/digiphot/daophot/select/t_grpselect.x @@ -0,0 +1,105 @@ +include <fset.h> +include "../lib/daophotdef.h" + +# T_GRPSELECT -- Select groups from a GROUP file on the basis of the size +# of the group. Only groups of the sizes specified are copied into the +# output table. + +procedure t_grpselect () + +pointer ingroup # the input GROUP file +pointer outgroup # the output GROUP file +int min_group # the minimum group size +int max_group # the maximum group size + +bool gr_text +int ilist, lilist, olist, lolist, verbose +pointer sp, tp_in, tp_out, dao + +bool clgetb(), itob() +int open(), tbtopn(), clgeti(), fstati(), btoi(), access() +int fntopnb(), fntlenb(), fntgfnb() + +begin + # Set the standard output to flush on newline. + if (fstati (STDOUT, F_REDIR) == NO) + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get some memory. + call smark (sp) + call salloc (ingroup, SZ_FNAME, TY_CHAR) + call salloc (outgroup, SZ_FNAME, TY_CHAR) + + # Get the various task parameters. + call clgstr ("ingroupfile", Memc[ingroup], SZ_FNAME) + call clgstr ("outgroupfile", Memc[outgroup], SZ_FNAME) + min_group = clgeti ("min_group") + max_group = clgeti ("max_group") + verbose = btoi (clgetb ("verbose")) + + # Open the daophot structure. + call dp_init (dao) + + # Open the photometry structure. + call dp_apsetup (dao) + + # Set some parameters. + call dp_seti (dao, VERBOSE, verbose) + + # Get the lists. + ilist = fntopnb (Memc[ingroup], NO) + lilist = fntlenb (ilist) + olist = fntopnb (Memc[outgroup], NO) + lolist = fntlenb (olist) + + # Check the list lengths. + if (lilist != lolist) { + call fntclsb (ilist) + call fntclsb (olist) + call sfree (sp) + call error (0, + "The input and output list lengths are not compatible") + } + + # Loop over the files. + while ((fntgfnb (ilist, Memc[ingroup], SZ_FNAME) != EOF) && + (fntgfnb (olist, Memc[outgroup], SZ_FNAME) != EOF)) { + + # Open the input file. + gr_text = itob (access (Memc[ingroup], 0, TEXT_FILE)) + if (gr_text) + tp_in = open (Memc[ingroup], READ_ONLY, TEXT_FILE) + else + tp_in = tbtopn (Memc[ingroup], READ_ONLY, 0) + + # Open an output file of the same type as the input file. + if (gr_text) + tp_out = open (Memc[outgroup], NEW_FILE, TEXT_FILE) + else + tp_out = tbtopn (Memc[outgroup], NEW_COPY, tp_in) + + # Read in the groups and select by group size. + call dp_sgroup (dao, tp_in, tp_out, gr_text, min_group, max_group) + + # Close the input and output files. + if (gr_text) { + call close (tp_in) + call close (tp_out) + } else { + call tbtclo (tp_in) + call tbtclo (tp_out) + } + } + + # Close the lists. + call fntclsb (ilist) + call fntclsb (olist) + + # Free the photometry structure. + call dp_apclose (dao) + + # Free the daophot structure. + call dp_free (dao) + + call sfree (sp) +end diff --git a/noao/digiphot/daophot/select/t_pfmerge.x b/noao/digiphot/daophot/select/t_pfmerge.x new file mode 100644 index 00000000..f9f096e1 --- /dev/null +++ b/noao/digiphot/daophot/select/t_pfmerge.x @@ -0,0 +1,110 @@ +include <fset.h> + +# T_PFMERGE -- Merge photometry files written by PHOT, PSF, PEAK, GROUP, +# NSTAR or ALLSTAR into one photometry file. The fields ID, XCENTER, +# YCENTER, MAG, and MKSKY are read from each input file and written +# without change to the output file. The input files may be text files or +# binary ST tables files. The output file will have the same file type as the +# the first input file. The header of the output file will be the header +# of the first input file. + +procedure t_pfmerge () + +pointer inphotfiles # the input photometry files +pointer outphotfile # the output photometry file +bool verbose # verbose output ? + +int plist, lplist, infd, outfd, first_file, in_text, out_text +pointer sp, infname +bool clgetb() +int fstati(), fntopnb(), fntlenb(), fntgfnb(), access(), open() +pointer tbtopn() + +begin + # Set the standard output to flush on newline. + if (fstati (STDOUT, F_REDIR) == NO) + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get some working memory. + call smark (sp) + call salloc (inphotfiles, SZ_FNAME, TY_CHAR) + call salloc (outphotfile, SZ_FNAME, TY_CHAR) + call salloc (infname, SZ_FNAME, TY_CHAR) + + # Get the various task parameters. + call clgstr ("inphotfiles", Memc[inphotfiles], SZ_FNAME) + call clgstr ("outphotfile", Memc[outphotfile], SZ_FNAME) + verbose = clgetb ("verbose") + + # Open the input file list and determine the file type of the first + # file. + plist = fntopnb (Memc[inphotfiles], NO) + lplist = fntlenb (plist) + if (lplist <= 0) { + call fntclsb (plist) + call sfree (sp) + return + } + if (fntgfnb (plist, Memc[infname], SZ_FNAME) == EOF) { + call fntclsb (plist) + call sfree (sp) + return + } else { + out_text = access (Memc[infname], 0, TEXT_FILE) + call fntrewb (plist) + } + + # Open the output file. + if (out_text == YES) + outfd = open (Memc[outphotfile], NEW_FILE, TEXT_FILE) + else + outfd = tbtopn (Memc[outphotfile], NEW_FILE, 0) + + # Loop over the list of input files + first_file = YES + while (fntgfnb (plist, Memc[infname], SZ_FNAME) != EOF) { + + # Print message. + if (verbose) { + call printf ("Merging photometry file %s into %s\n") + call pargstr (Memc[infname]) + call pargstr (Memc[outphotfile]) + } + + # Open the input file. + in_text = access (Memc[infname], 0, TEXT_FILE) + if (verbose && (in_text != out_text)) { + if (in_text == YES) + call eprintf ("File %s is not an ST table file.\n") + else + call eprintf ("File %s is not a text file.\n") + call pargstr (Memc[infname]) + } + if (in_text == YES) + infd = open (Memc[infname], READ_ONLY, TEXT_FILE) + else + infd = tbtopn (Memc[infname], READ_ONLY, 0) + + # Now merge the files. + call dp_pfmerge (infd, outfd, in_text, out_text, first_file) + + # Close the photometry file. + if (in_text == YES) + call close (infd) + else + call tbtclo (infd) + + first_file = NO + } + + # Close the output file. + if (out_text == YES) + call close (outfd) + else + call tbtclo (outfd) + + # Close the input file list. + call fntclsb (plist) + + call sfree(sp) +end |