IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4024


Ignore:
Timestamp:
May 25, 2005, 6:23:25 AM (21 years ago)
Author:
eugene
Message:

adding autocode to imphotsearch

Location:
trunk/Ohana/src/imregister
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/Makefile

    r3650 r4024  
    1717PHOTREG =       $(HOME)/photreg
    1818IMREG   =       $(HOME)/imreg
     19IMPHOT  =       $(HOME)/imphot
    1920SPREG   =       $(HOME)/spreg
    2021
     
    3334photsearch   photreg      \
    3435cameraconfig filtnames    \
    35 imphotsearch imphotmerge  \
    36 imphotset                 
    37 
    38 # spregister   spsearch
     36imphotsearch
    3937
    4038# program under development, not installed
    41 DEVEL = spregister spsearch
     39DEVEL = spregister spsearch imphotmerge
     40
     41IMPHOTOBJ = \
     42$(IMPHOT)/args.$(ARCH).o \
     43$(IMPHOT)/db_load.$(ARCH).o \
     44$(IMPHOT)/dumpfits.$(ARCH).o \
     45$(IMPHOT)/modify.$(ARCH).o \
     46$(IMPHOT)/output.$(ARCH).o \
     47$(IMPHOT)/rfits.$(ARCH).o \
     48$(IMPHOT)/rtext.$(ARCH).o \
     49$(IMPHOT)/subset.$(ARCH).o
    4250
    4351IMOBJ  = \
     
    116124SR = $(SPREG)/args.spregister.$(ARCH).o    $(SPOBJ)   $(BASEOBJ)
    117125SS = $(SPREG)/args.spsearch.$(ARCH).o      $(SPOBJ)   $(BASEOBJ)
     126IP = $(IMPHOTOBJ) $(BASEOBJ)
    118127
    119128$(SR) : $(INC)/spreg.h $(INC)/imregister.h
     
    136145$(BIN)/spsearch.$(ARCH)     : $(SRC)/spsearch.$(ARCH).o     $(SS) ; $(CC) $^ -o $@ $(LFLAGS)
    137146$(BIN)/spregister.$(ARCH)   : $(SRC)/spregister.$(ARCH).o   $(SR) ; $(CC) $^ -o $@ $(LFLAGS)
     147
     148$(BIN)/imphotsearch.$(ARCH) : $(SRC)/imphotsearch.$(ARCH).o $(IP) ; $(CC) $^ -o $@ $(LFLAGS)
    138149
    139150# dependancy rules for binary code #########################
  • trunk/Ohana/src/imregister/base/fits_scan_nchar.c

    r3534 r4024  
    11# include "imregister.h"
    2 # include "imreg.h"
    32
    43/* scan and give a warning for missing entries */
  • trunk/Ohana/src/imregister/imphot/args.c

    r4018 r4024  
    44/* criteria struct is global */
    55int args (int argc, char **argv) {
    6 
    7 
    8   FILE *f;
    9   Header header;
    10   int i, j, status, N;
    11   char *dBFile, *timestr, *photstr;
    12   int Nimage, nimage, *index, Ntimes;
    13   unsigned long *tstart, *tstop;
    14   int VERBOSE, FORCE_READ, PHOTCODE, dbstate;
    15   Image *image;
    16   int PhotCodeSelect, Nin;
    17   int CodeSelect, Code;
    18   char *FitsOutput, *NameSelect;
    19   int NameSelectLength;
    20   struct stat filestatus;
    21   int size;
    226
    237  int N;
     
    3216
    3317  /* interpret command-line arguments */
    34   if (!get_trange_arguments (&argc, argv, &tstart, &tstop, &Ntimes)) {
     18  if (!get_trange_arguments (&argc, argv, &criteria.tstart, &criteria.tstop, &criteria.Ntimes)) {
    3519    fprintf (stderr, "ERROR: syntax error\n");
    3620    exit (1);
     
    3822
    3923  /* select by image photcode */
    40   PhotCodeSelect = FALSE;
    41   PHOTCODE = 0;
     24  criteria.PhotcodeSelect = FALSE;
     25  criteria.photcode = 0;
    4226  if ((N = get_argument (argc, argv, "-photcode"))) {
    4327    remove_argument (N, &argc, argv);
    44     if (!(PHOTCODE = GetPhotcodeCodebyName (argv[N]))) {
     28    if (!(criteria.photcode = GetPhotcodeCodebyName (argv[N]))) {
    4529      fprintf (stderr, "ERROR: photcode not found in photcode table\n");
    4630      exit (1);
    4731    }
    4832    remove_argument (N, &argc, argv);
    49     PhotCodeSelect = TRUE;
     33    criteria.PhotcodeSelect = TRUE;
    5034  }
    5135
    5236  /* string in image name */
    53   NameSelect = (char *) NULL;
    54   NameSelectLength = 0;
     37  criteria.NameSelect = FALSE;
    5538  if ((N = get_argument (argc, argv, "-name"))) {
    5639    remove_argument (N, &argc, argv);
    57     NameSelect = strcreate (argv[N]);
     40    criteria.Name = strcreate (argv[N]);
    5841    remove_argument (N, &argc, argv);
    59     NameSelectLength = strlen (NameSelect);
     42    criteria.NameSelect = TRUE;
    6043  }
    6144
    6245  /* string in image name */
    63   CodeSelect = FALSE;
    64   Code = 0;
     46  criteria.CodeSelect = FALSE;
     47  criteria.Code = 0;
    6548  if ((N = get_argument (argc, argv, "-code"))) {
    66     CodeSelect = TRUE;
     49    criteria.CodeSelect = TRUE;
    6750    remove_argument (N, &argc, argv);
    68     Code = atoi (argv[N]);
     51    criteria.Code = atoi (argv[N]);
    6952    remove_argument (N, &argc, argv);
    7053  }
    7154
    72   FitsOutput = (char *) NULL;
     55  options.table = (char *) NULL;
    7356  if ((N = get_argument (argc, argv, "-fits"))) {
    7457    remove_argument (N, &argc, argv);
    75     FitsOutput = strcreate (argv[N]);
     58    options.table = strcreate (argv[N]);
    7659    remove_argument (N, &argc, argv);
     60  }
     61
     62  options.bintable = (char *) NULL;
     63  if ((N = get_argument (argc, argv, "-binfits"))) {
     64    remove_argument (N, &argc, argv);
     65    options.bintable = strcreate (argv[N]);
     66    remove_argument (N, &argc, argv);
     67  }
     68
     69  /* desired action */
     70  options.modify = FALSE;
     71  options.ModifyValue = options.ModifyEntry = NULL;
     72  if ((N = get_argument (argc, argv, "-flag"))) {
     73    remove_argument (N, &argc, argv);
     74    options.ModifyEntry = strcreate (argv[N]);
     75    remove_argument (N, &argc, argv);
     76    options.ModifyValue = strcreate (argv[N]);
     77    remove_argument (N, &argc, argv);
     78    options.modify = TRUE;
    7779  }
    7880
     
    9395    exit (1);
    9496  }
     97}
  • trunk/Ohana/src/imregister/imphot/db_load.c

    r4018 r4024  
     1# include "imregister.h"
     2# include "imphot.h"
    13
    2 /* load the complete db table into memory - load first extension, do not validate EXTNAME */
     4enum {FITS, TEXT};
     5
    36int db_load (FITS_DB *db) {
     7
     8  int Nx, Ny, Naxis;
     9  int mode, status;
    410
    511  /* database name must be set first */
     
    1521  }
    1622
     23  fits_scan (&db[0].header, "NAXIS",  "%d", 1, &Naxis);
     24  fits_scan (&db[0].header, "NAXIS1", "%d", 1, &Nx);
     25  fits_scan (&db[0].header, "NAXIS2", "%d", 1, &Ny);
     26 
     27  mode = FITS;
     28  if ((Naxis == 2) && (Nx == 1106) && (Ny == 1024)) {
     29    mode = TEXT;
     30  }
     31 
    1732  /* how do we decide if it is text or fits? must examine header */
    1833  if (FITS) {
     
    2338  return (TRUE);
    2439}
    25 
    26 /* load the complete db table into memory - load first extension, do not validate EXTNAME */
    27 int rfits (FITS_DB *db) {
    28 
    29   /* database name must be set first */
    30   if (db == NULL) {
    31     fprintf (stderr, "db handle is not set\n");
    32     return (FALSE);
    33   }
    34   if (!fits_fread_matrix (db[0].f, &db[0].matrix, &db[0].header)) {
    35     fprintf (stderr, "can't read primary matrix");
    36     return (FALSE);
    37   }
    38   if (!fits_fread_header (db[0].f, &db[0].theader)) {
    39     fprintf (stderr, "can't read table header");
    40     return (FALSE);
    41   }
    42   if (!fits_fread_ftable_data (db[0].f, &db[0].ftable)) {
    43     fprintf (stderr, "can't read table data");
    44     return (FALSE);
    45   }
    46   return (TRUE);
    47 }
    48 
  • trunk/Ohana/src/imregister/imphot/dumpfits.c

    r3650 r4024  
    1 int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep) {
     1# include "imregister.h"
     2# include "imphot.h"
     3
     4/* write out complete binary FITS table in format of db */
     5int DumpFitsBintable (char *filename, Image *image, int *match, int Nmatch) {
     6
     7  int i, j;
     8  FILE *f;
     9  Header header;
     10  Matrix matrix;
     11  Header theader;
     12  FTable ftable;
     13  Image *subset;
     14
     15  ALLOCATE (subset, Image, MAX (1, Nmatch));
     16  for (i = 0; i < Nmatch; i++){
     17    j = match[i];
     18    memcpy (&subset[i], &image[j], sizeof (Image));
     19  }
     20
     21  /* open file for output */
     22  f = fopen (filename, "w");
     23  if (f == NULL) {
     24    fprintf (stderr, "ERROR: can't open output file %s\n", filename);
     25    exit (1);
     26  }
     27
     28  /* create primary header */
     29  fits_init_header (&header);   
     30  header.extend = TRUE;
     31  fits_create_header (&header);
     32  fits_create_matrix (&header, &matrix);
     33  fits_print (&header, "NEXTEND", "%d", 1, 1);
     34
     35  ftable.header = &theader;
     36  fits_table_set_Image (&ftable, subset, Nmatch);
     37
     38  fits_fwrite_header  (f, &header);
     39  fits_fwrite_matrix  (f, &matrix);
     40  fits_fwrite_Theader (f, &theader);
     41  fits_fwrite_table   (f, &ftable);
     42  fclose (f);
     43  exit (0);
     44}
     45
     46int DumpFitsTable (char *filename, Image *image, int *match, int Nmatch) {
    247 
    3   Header header, theader;
     48  Header header;
    449  Matrix matrix;
    5   FTable table;
    6   Image *newdata;
     50  Header theader;
     51  FTable ftable;
     52  Image *subset;
    753  FILE *f;
    854  char *startstr, *filtstr, *datestr, *line;
     
    1864  fits_print (&header, "NEXTEND", "%d", 1, 1);
    1965 
     66  /* the ASCII table is always a little harder than the binary:
     67   * we need to build the data line a bit carefully
     68   */
     69
    2070  /* create table header */
    2171  fits_create_table_header (&theader, "TABLE", "ZPTS");
    22    
     72
    2373  /* add current date/time to header */
    2474  str_to_time ("now", &tsecond);
     
    3787  fits_define_table_column (&theader, "F7.1",  "SKY",        "median sky flux",           "counts");
    3888  fits_define_table_column (&theader, "I6",    "NSTAR",      "Number of stars in image",  "stars");
    39  
     89
    4090  /* define TNULL, TNVAL values */
    4191  fits_modify (&theader, "TNULL1",  "%s", 1, "NULL"); /* START_TIME */
     
    59109  fits_modify (&theader, "TNVAL9",  "%s", 1,  "-2");  /* NSTAR      */
    60110
    61   /* create table, add data values */
    62   fits_create_table (&theader, &table);
    63  
    64   /* add selected data to table */
    65   for (i = 0; i < Nkeep; i++) {
    66     newdata  = &image[index[i]];
    67     startstr = sec_to_date (newdata[0].tzero);
    68     filtstr  = GetPhotcodeNamebyCode (newdata[0].source);
    69     zp       = 0.001*newdata[0].Mcal;
    70     dzp      = 0.001*newdata[0].dMcal;
    71    
    72     XY_to_RD (&ra, &dec, 0.0, 0.0, &newdata[0].coords);
    73     airmass  = 0.001*newdata[0].secz;
    74     sky      = newdata[0].Myyyy + 0x8000;
     111  /* add data to table */
     112  for (i = 0; i < Nmatch; i++) {
     113    subset   = &image[match[i]];
     114    startstr = sec_to_date (subset[0].tzero);
     115    filtstr  = GetPhotcodeNamebyCode (subset[0].source);
     116    zp       = 0.001*subset[0].Mcal;
     117    dzp      = 0.001*subset[0].dMcal;
     118    XY_to_RD (&ra, &dec, 0.0, 0.0, &subset[0].coords);
     119    airmass  = 0.001*subset[0].secz;
     120    sky      = subset[0].Myyyy + 0x8000;
    75121
    76     line = fits_table_print (&table, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, newdata[0].nstar);
    77     fits_add_rows (&table, line, 1, strlen(line));
    78 
     122    /* we should get an error here if we don't construct this line correctly */
     123    line = fits_table_print (&ftable, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, subset[0].nstar);
     124    fits_add_rows (&ftable, line, 1, strlen(line));
    79125    free (line);
    80126    free (startstr);
    81127  }
    82    
     128
    83129  /* write data to output file */
    84130  f = fopen (filename, "w");
    85131  if (f == (FILE *) NULL) {
    86132    fprintf (stderr, "Failure writing fits table\n");
    87     return (FALSE);
     133    exit (1);
    88134  }
    89135  fits_fwrite_header  (f, &header);
    90136  fits_fwrite_matrix  (f, &matrix);
    91137  fits_fwrite_Theader (f, &theader);
    92   fits_fwrite_table   (f, &table);
     138  fits_fwrite_table   (f, &ftable);
    93139  fclose (f);
    94140  return (TRUE);
    95141}
    96 
    97 /*
    98 
    99   selection options:
    100 
    101   CCDSelect
    102   TypeSelect
    103   TimeSelect
    104   FilterSelect
    105   ExptimeSelect
    106   EntrySelect
    107   LabelSelect
    108 
    109 */
  • trunk/Ohana/src/imregister/imphot/output.c

    r4018 r4024  
    1 int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep);
     1# include "imregister.h"
     2# include "imphot.h"
    23
     4int output (Image *image, int *match, int Nmatch) {
    35
    4 output () {
     6  int status;
     7
    58  /* output the selected entries */
    6   if (FitsOutput != (char *) NULL) {
    7     status = DumpFitsTable (FitsOutput, image, Nimage, index, Nin);
    8   } else {
    9     for (j = 0; j < Nin; j++) {
    10       i = index[j];
     9  if (options.table != (char *) NULL) {
     10    status = DumpFitsTable (options.table, image, match, Nmatch);
     11    return (TRUE);
     12  }
     13
     14  /* output the selected entries */
     15  if (options.bintable != (char *) NULL) {
     16    status = DumpFitsBintable (options.bintable, image, match, Nmatch);
     17    return (TRUE);
     18  }
     19
     20  PrintSubset (image, match, Nmatch);
     21  return (TRUE);
     22}
     23
     24int PrintSubset (Image *image, int *match, int Nmatch) {
     25
     26  int i, j;
     27  char *timestr, *photstr;
     28  static char PhotError[] = "unknown";
     29
     30  for (j = 0; j < Nmatch; j++) {
     31    i = match[j];
    1132     
    12       /* convert UNIX time to Elixir-style date string */
    13       timestr = sec_to_date (image[i].tzero);
     33    /* convert UNIX time to Elixir-style date string */
     34    timestr = sec_to_date (image[i].tzero);
    1435     
    15       /* convert photcode to filter name */
    16       photstr = GetPhotcodeNamebyCode (image[i].source);
    17       if (photstr == (char *) NULL) photstr = PhotError;
     36    /* convert photcode to filter name */
     37    photstr = GetPhotcodeNamebyCode (image[i].source);
     38    if (photstr == (char *) NULL) photstr = PhotError;
    1839     
    19       fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %5d %02x\n", image[i].name, photstr, timestr,
    20                0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar, image[i].code);
    21       free (timestr);
    22     }
     40    fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %5d %02x\n", image[i].name, photstr, timestr,
     41             0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar, image[i].code);
     42    free (timestr);
    2343  }
     44  return (TRUE);
    2445}
  • trunk/Ohana/src/imregister/imphot/rtext.c

    r4018 r4024  
     1# include "imregister.h"
     2# include "imphot.h"
    13
    24int rtext (FITS_DB *db) {
     5
     6  int Nimage, size, nimage;
     7  struct stat filestatus;
     8  Image *image;
    39
    410  /* check that file size makes sense */
    511  Nimage = 0;
    612  fits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimage);
    7   if (stat (dBFile, &filestatus) == -1) {
     13  if (stat (db[0].filename, &filestatus) == -1) {
    814    if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n");
    915    exit (1);
    1016  }
    11   size = Nimage*sizeof(Image) + header.size;
     17  size = Nimage*sizeof(Image) + db[0].header.size;
    1218  if (size != filestatus.st_size) {
    1319    int Ndata;
    1420
    15     Ndata = (filestatus.st_size - header.size) / sizeof (Image);
     21    Ndata = (filestatus.st_size - db[0].header.size) / sizeof (Image);
    1622    if (VERBOSE) fprintf (stderr, "ERROR: image catalog has inconsistent size\n");
    1723    if (VERBOSE) fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata);
     
    2733  db[0].ftable.header = &db[0].theader;
    2834
    29   /* set theader size information to match loaded data */
    30 
    3135  /* alloc, read images */
    3236  ALLOCATE (image, Image, MAX (Nimage, 1));
     
    3640    exit (1);
    3741  }
    38   db[0].ftable.buffer = image;
     42  db[0].ftable.buffer = (char *) image;
     43  fits_modify (&db[0].theader, "NAXIS2", "%d", 1, Nimage);
     44  db[0].theader.Naxis[1] = Nimage;
     45  db[0].ftable.size = fits_matrix_size (&db[0].theader);
     46 
    3947  return (TRUE);
    4048}
  • trunk/Ohana/src/imregister/imphot/subset.c

    r3650 r4024  
     1# include "imregister.h"
     2# include "imphot.h"
    13
    2 subset () {
     4int *subset (Image *image, int Nimage, int *nsubset) {
     5
     6  int i, j, status;
     7  int Nsubset, NameSelectLength;
     8  int *index;
    39
    410  /* allocate space for reference lists */
    5   Nin = 0;
     11  Nsubset = 0;
    612  ALLOCATE (index, int, Nimage);
    713 
    8   /* note that we are looking for overlap only with tstart */
     14  if (criteria.NameSelect) {
     15    NameSelectLength = strlen(criteria.Name);
     16  }
     17
    918  for (i = 0; i < Nimage; i++) {
    10     for (j = 0, status = FALSE; !status && (j < Ntimes); j++) {
    11       status = (image[i].tzero >= tstart[j]) && (image[i].tzero <= tstop[j]);
     19    for (j = 0, status = FALSE; !status && (j < criteria.Ntimes); j++) {
     20      status = (image[i].tzero >= criteria.tstart[j]) && (image[i].tzero <= criteria.tstop[j]);
    1221    }
    13     if (!status && Ntimes) continue;
    14     if (PhotCodeSelect && (image[i].source != PHOTCODE)) continue;
    15     if ((NameSelect != (char *) NULL) && (strncasecmp (image[i].name, NameSelect, NameSelectLength))) continue;
    16     if (CodeSelect && (image[i].code != Code)) continue;
     22    if (!status && criteria.Ntimes) continue;
     23    if (criteria.PhotcodeSelect && (image[i].source != criteria.photcode)) continue;
     24    if (criteria.CodeSelect     && (image[i].code != criteria.Code)) continue;
     25    if (criteria.NameSelect     && strncasecmp (image[i].name, criteria.Name, NameSelectLength)) continue;
    1726
    18     index[Nin] = i;
    19     Nin ++;
     27    index[Nsubset] = i;
     28    Nsubset ++;
    2029  }
     30  *nsubset = Nsubset;
     31  return (index);
    2132}
  • trunk/Ohana/src/imregister/src/imphotsearch.c

    r4018 r4024  
    11# include "imregister.h"
     2# include "imphot.h"
    23
    3 static char *version = "imphotsearch $Revision: 1.6 $";
     4static char *version = "imphotsearch $Revision: 1.7 $";
    45
    56int main (int argc, char **argv) {
    67 
     8  int Nmatch, Nimage;
     9  int *match;
     10  Image *image;
     11  FITS_DB db;
     12
    713  get_version (argc, argv, version);
    8   args (&argc, argv);
     14  args (argc, argv);
    915 
    10   db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
     16  db.lockstate = (options.modify) ? LCK_HARD : LCK_SOFT;
    1117  db.timeout   = 300.0;
    1218  fits_db_init (&db);
     
    2329    exit (1);
    2430  }
     31  if (!options.modify) fits_db_close (&db);
    2532
    26   if (!output.modify && !output.delete) fits_db_close (&db);
     33  image = fits_table_get_Image (&db.ftable, &Nimage);
    2734
    28   image = fits_table_get_RegImage (&db.ftable, &Nimage);
     35  match = subset (image, Nimage, &Nmatch);
     36  if (options.modify) ModifySubset (&db, image, Nimage, match, Nmatch);
    2937
    30   subset ();
    31 
    32   output ();
     38  output (image, match, Nmatch);
    3339
    3440  if (VERBOSE) fprintf (stderr, "SUCCESS\n");
    3541  exit (0);
     42}
    3643
    37 }
Note: See TracChangeset for help on using the changeset viewer.