IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3650


Ignore:
Timestamp:
Apr 3, 2005, 9:51:44 PM (21 years ago)
Author:
eugene
Message:

working on autocode tables (imphot now)

Location:
trunk/Ohana/src/imregister
Files:
6 added
6 edited

Legend:

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

    r3649 r3650  
    5757$(IMREG)/FifoOps.$(ARCH).o   \
    5858$(IMREG)/SockScan.$(ARCH).o   \
    59 $(IMREG)/submit.$(ARCH).o
    60 
    61 # $(IMREG)/imregclient.$(ARCH).o   \
     59$(IMREG)/submit.$(ARCH).o \
     60$(IMREG)/imregclient.$(ARCH).o
    6261
    6362SPOBJ  = \
  • trunk/Ohana/src/imregister/detrend/entry.c

    r3649 r3650  
    107107    exit (1);
    108108  }
    109   fclearlockfile2 (fullname, f, LCK_XCLD, &filestate);
     109  fclearlockfile (fullname, f, LCK_XCLD, &filestate);
    110110
    111111  return (TRUE);
  • trunk/Ohana/src/imregister/imreg/imregclient.c

    r2823 r3650  
    44int imregclient (char *fitsfile, char *statfile, char *datfile) {
    55
     6  int i, Nentry, Nslice, status, tmpint;
    67  FILE *f;
    78  RegImage *image;
    8   int i, Nentry, Nslice, status, tmpint;
    9   float *dtime;
     9  VTable vtable;
     10  FITS_DB db;
    1011
    1112  Nentry = 0;
     
    4546    }
    4647    status = 3;
    47     Nslice = image[0].ccd;
     48    Nslice = image[0].seq;
    4849    Nentry = Nslice + 1;
    4950    REALLOCATE (image, RegImage, Nentry);
    50     dtime = (float *)&image[0].junk[0];
    5151    for (i = 0; i < Nentry; i++) {
    5252      image[i] = image[0];
    5353      status = fscanf (f, "%d %f %f", &tmpint, &image[i].sky, &image[i].fwhm);
    54       image[i].ccd = tmpint;
    55       if (image[i].ccd == Nslice) continue;
    56       image[i].obstime += *dtime*image[i].ccd;
     54      image[i].seq = tmpint;
     55      if (image[i].seq == Nslice) continue;
     56      image[i].obstime += image[0].seqtime*image[i].seq;
    5757    }
    5858    fclose (f);
     
    6262  if (NoReg) dump_data (image, Nentry);
    6363
    64   set_db (TempDB);
     64  db.lockstate = LCK_HARD;
     65  db.timeout   = 300.0;
     66  fits_db_init (&db);
    6567
    66   status = load_db ();
    67   if (!status) {
    68     create_db ();
     68  if (!fits_db_lock (&db, TempDB)) {
     69    fprintf (stderr, "ERROR: failure to lock db\n");
     70    fits_db_close (&db);
     71    exit (1);
    6972  }
    70   append_db (image, Nentry);
     73  if (db.dbstate == LCK_EMPTY) {
     74    fits_db_create (&db);
     75    fits_table_set_RegImage (&db.ftable, NULL, 0);
     76  } else { 
     77    if (!fits_db_load (&db)) {
     78      fprintf (stderr, "ERROR: failure to load db\n");
     79      fits_db_close (&db);
     80      exit (1);
     81    }
     82  }
     83
     84  fits_convert_RegImage (image, sizeof (RegImage), Nentry);
     85  fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
     86  fits_vadd_rows (&vtable, (char *) image, Nentry, sizeof(RegImage));
     87
     88  fits_db_update (&db, &vtable);
     89  fits_db_close (&db);
     90  fits_db_free (&db);
     91
    7192  fprintf (stderr, "SUCCESS: wrote temp image data\n");
    7293  exit (0);
  • trunk/Ohana/src/imregister/spreg/delete.c

    r3593 r3650  
    2222  if (Nbad == 0) {
    2323    fprintf (stderr, "SUCCESS\n");
    24     fits_close_db (&db);
     24    fits_db_close (db);
    2525    exit (0);
    2626  }
  • trunk/Ohana/src/imregister/src/imphotsearch.c

    r2803 r3650  
    22
    33static char PhotError[] = "unknown";
    4 static char *version = "imphotsearch $Revision: 1.4 $";
     4static char *version = "imphotsearch $Revision: 1.5 $";
    55
    66int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep);
     
    2626  ConfigInit (&argc, argv);
    2727
    28   /* load photcode data */
    29   if (!LoadPhotcodes (PhotCodeFile)) {
    30     fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
    31     exit (1);
    32   }
    33 
    34   /* interpret command-line arguments */
    35   if (!get_trange_arguments (&argc, argv, &tstart, &tstop, &Ntimes)) {
    36     fprintf (stderr, "ERROR: syntax error\n");
    37     exit (1);
    38   }
    39 
    40   /* select by image photcode */
    41   PhotCodeSelect = FALSE;
    42   PHOTCODE = 0;
    43   if ((N = get_argument (argc, argv, "-photcode"))) {
    44     remove_argument (N, &argc, argv);
    45     if (!(PHOTCODE = GetPhotcodeCodebyName (argv[N]))) {
    46       fprintf (stderr, "ERROR: photcode not found in photcode table\n");
    47       exit (1);
    48     }
    49     remove_argument (N, &argc, argv);
    50     PhotCodeSelect = TRUE;
    51   }
    52 
    53   /* string in image name */
    54   NameSelect = (char *) NULL;
    55   NameSelectLength = 0;
    56   if ((N = get_argument (argc, argv, "-name"))) {
    57     remove_argument (N, &argc, argv);
    58     NameSelect = strcreate (argv[N]);
    59     remove_argument (N, &argc, argv);
    60     NameSelectLength = strlen (NameSelect);
    61   }
    62 
    63   /* string in image name */
    64   CodeSelect = FALSE;
    65   Code = 0;
    66   if ((N = get_argument (argc, argv, "-code"))) {
    67     CodeSelect = TRUE;
    68     remove_argument (N, &argc, argv);
    69     Code = atoi (argv[N]);
    70     remove_argument (N, &argc, argv);
    71   }
    72 
    73   FitsOutput = (char *) NULL;
    74   if ((N = get_argument (argc, argv, "-fits"))) {
    75     remove_argument (N, &argc, argv);
    76     FitsOutput = strcreate (argv[N]);
    77     remove_argument (N, &argc, argv);
    78   }
    79 
    80   VERBOSE = FALSE;
    81   if ((N = get_argument (argc, argv, "-v"))) {
    82     remove_argument (N, &argc, argv);
    83     VERBOSE = TRUE;
    84   }
    85 
    86   FORCE_READ = FALSE;
    87   if ((N = get_argument (argc, argv, "-force"))) {
    88     remove_argument (N, &argc, argv);
    89     FORCE_READ = TRUE;
    90   }
    91 
    92   if (argc != 1) {
    93     fprintf (stderr, "USAGE: imphotsearch [config ops] [-trange start stop/delta] [-photcode code] [-fits out.fits]\n");
    94     exit (1);
    95   }
     28  args (&argc, argv);
    9629 
    9730  /* load image database - still a non-FITS file */
    9831  dBFile = ImPhotDB;
    9932
    100   f = fsetlockfile (dBFile, 120.0, LCK_SOFT, &dbstate);
    101   if (f == (FILE *) NULL) {
    102     fprintf (stderr, "ERROR: can't set lock on %s, state is %d\n", dBFile, dbstate);
    103     exit (1);
    104   }
    105   Fseek (f, 0, SEEK_SET);
    106 
    107   /* read header */
    108   if (!fits_fread_header (f, &header)) {
    109     if (VERBOSE) fprintf (stderr, "ERROR: can't read image catalog %s\n", dBFile);
    110     exit (1);
     33  /* how do we decide if it is text or fits? must examine header */
     34  if (FITS) {
     35    image = rtext (&Nimage);
     36  } else {
     37    image = rfits (&Nimage);
    11138  }
    11239
    113   /* check that file size makes sense */
    114   Nimage = 0;
    115   fits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
    116   if (stat (dBFile, &filestatus) == -1) {
    117     if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n");
    118     exit (1);
    119   }
    120   size = Nimage*sizeof(Image) + header.size;
    121   if (size != filestatus.st_size) {
    122     int Ndata;
     40  subset ();
    12341
    124     Ndata = (filestatus.st_size - header.size) / sizeof (Image);
    125     if (VERBOSE) fprintf (stderr, "ERROR: image catalog has inconsistent size\n");
    126     if (VERBOSE) fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata);
    127     if (!FORCE_READ) exit (1);
    128     Nimage = Ndata;
    129   }
    130 
    131   /* alloc, read images */
    132   ALLOCATE (image, Image, MAX (Nimage, 1));
    133   nimage = Fread (image, sizeof(Image), Nimage, f, "image");
    134   if (nimage != Nimage) {
    135     if (VERBOSE) fprintf (stderr, "ERROR: problem loading image catalog\n");
    136     exit (1);
    137   }
    138   fclearlockfile (dBFile, f, LCK_SOFT, &dbstate);
    139 
    140   /* allocate space for reference lists */
    141   Nin = 0;
    142   ALLOCATE (index, int, Nimage);
    143  
    144   /* note that we are looking for overlap only with tstart */
    145   for (i = 0; i < Nimage; i++) {
    146     for (j = 0, status = FALSE; !status && (j < Ntimes); j++) {
    147       status = (image[i].tzero >= tstart[j]) && (image[i].tzero <= tstop[j]);
    148     }
    149     if (!status && Ntimes) continue;
    150     if (PhotCodeSelect && (image[i].source != PHOTCODE)) continue;
    151     if ((NameSelect != (char *) NULL) && (strncasecmp (image[i].name, NameSelect, NameSelectLength))) continue;
    152     if (CodeSelect && (image[i].code != Code)) continue;
    153 
    154     index[Nin] = i;
    155     Nin ++;
    156   }
    157 
    158   /* output the selected entries */
    159   if (FitsOutput != (char *) NULL) {
    160     status = DumpFitsTable (FitsOutput, image, Nimage, index, Nin);
    161   } else {
    162     for (j = 0; j < Nin; j++) {
    163       i = index[j];
    164      
    165       /* convert UNIX time to Elixir-style date string */
    166       timestr = sec_to_date (image[i].tzero);
    167      
    168       /* convert photcode to filter name */
    169       photstr = GetPhotcodeNamebyCode (image[i].source);
    170       if (photstr == (char *) NULL) photstr = PhotError;
    171      
    172       fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %5d %02x\n", image[i].name, photstr, timestr,
    173                0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar, image[i].code);
    174       free (timestr);
    175     }
    176   }
     42  output ();
    17743
    17844  if (VERBOSE) fprintf (stderr, "SUCCESS\n");
     
    18046
    18147}
    182 
    183 int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep) {
    184  
    185   Header header, theader;
    186   Matrix matrix;
    187   FTable table;
    188   Image *newdata;
    189   FILE *f;
    190   char *startstr, *filtstr, *datestr, *line;
    191   int i;
    192   double zp, dzp, ra, dec, airmass, sky;
    193   unsigned long tsecond;
    194 
    195   /* create primary header */
    196   fits_init_header (&header);   
    197   header.extend = TRUE;
    198   fits_create_header (&header);
    199   fits_create_matrix (&header, &matrix);
    200   fits_print (&header, "NEXTEND", "%d", 1, 1);
    201  
    202   /* create table header */
    203   fits_create_table_header (&theader, "TABLE", "ZPTS");
    204    
    205   /* add current date/time to header */
    206   str_to_time ("now", &tsecond);
    207   datestr = sec_to_date (tsecond);
    208   fits_modify (&header,  "DATE", "%s", 1, datestr);
    209   fits_modify (&theader, "DATE", "%s", 1, datestr);
    210  
    211   /* define table layout */
    212   fits_define_table_column (&theader, "A20",   "START_TIME", "start time of measurement", "yyyy/mm/dd,hh:mm:ss");
    213   fits_define_table_column (&theader, "A10",   "FILTER",     "filter and camera name",    "");
    214   fits_define_table_column (&theader, "F8.4",  "ZP_OBS",     "measured zero point",       "mag");
    215   fits_define_table_column (&theader, "F7.4",  "ZP_ERR",     "error on zero point",       "mag");
    216   fits_define_table_column (&theader, "F11.6", "RA",         "RA (J2000)",                "dec. degrees");
    217   fits_define_table_column (&theader, "F11.6", "DEC",        "DEC (J2000)",               "dec. degrees");
    218   fits_define_table_column (&theader, "F7.3",  "C_AIRMASS",  "airmass coeff",             "mag per airmass");
    219   fits_define_table_column (&theader, "F7.1",  "SKY",        "median sky flux",           "counts");
    220   fits_define_table_column (&theader, "I6",    "NSTAR",      "Number of stars in image",  "stars");
    221  
    222   /* define TNULL, TNVAL values */
    223   fits_modify (&theader, "TNULL1",  "%s", 1, "NULL"); /* START_TIME */
    224   fits_modify (&theader, "TNULL2",  "%s", 1, "NULL"); /* FILTER     */
    225   fits_modify (&theader, "TNULL3",  "%s", 1, "NaN");  /* ZP_OBS     */
    226   fits_modify (&theader, "TNULL4",  "%s", 1, "NaN");  /* ZP_ERR     */
    227   fits_modify (&theader, "TNULL5",  "%s", 1, "NaN");  /* RA         */
    228   fits_modify (&theader, "TNULL6",  "%s", 1, "NaN");  /* DEC        */
    229   fits_modify (&theader, "TNULL7",  "%s", 1, "NaN");  /* C_AIRMASS  */
    230   fits_modify (&theader, "TNULL8",  "%s", 1, "NaN");  /* SKY        */
    231   fits_modify (&theader, "TNULL9",  "%s", 1,  "-1");  /* NSTAR      */
    232 
    233   fits_modify (&theader, "TNVAL1",  "%s", 1, "NA");   /* START_TIME */
    234   fits_modify (&theader, "TNVAL2",  "%s", 1, "NA");   /* FILTER     */
    235   fits_modify (&theader, "TNVAL3",  "%s", 1, "Inf");  /* ZP_OBS     */
    236   fits_modify (&theader, "TNVAL4",  "%s", 1, "Inf");  /* ZP_ERR     */
    237   fits_modify (&theader, "TNVAL5",  "%s", 1, "Inf");  /* RA         */
    238   fits_modify (&theader, "TNVAL6",  "%s", 1, "Inf");  /* DEC        */
    239   fits_modify (&theader, "TNVAL7",  "%s", 1, "Inf");  /* C_AIRMASS  */
    240   fits_modify (&theader, "TNVAL8",  "%s", 1, "Inf");  /* SKY        */
    241   fits_modify (&theader, "TNVAL9",  "%s", 1,  "-2");  /* NSTAR      */
    242 
    243   /* create table, add data values */
    244   fits_create_table (&theader, &table);
    245  
    246   /* add selected data to table */
    247   for (i = 0; i < Nkeep; i++) {
    248     newdata  = &image[index[i]];
    249     startstr = sec_to_date (newdata[0].tzero);
    250     filtstr  = GetPhotcodeNamebyCode (newdata[0].source);
    251     zp       = 0.001*newdata[0].Mcal;
    252     dzp      = 0.001*newdata[0].dMcal;
    253    
    254     XY_to_RD (&ra, &dec, 0.0, 0.0, &newdata[0].coords);
    255     airmass  = 0.001*newdata[0].secz;
    256     sky      = newdata[0].Myyyy + 0x8000;
    257 
    258     line = fits_table_print (&table, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, newdata[0].nstar);
    259     fits_add_rows (&table, line, 1, strlen(line));
    260 
    261     free (line);
    262     free (startstr);
    263   }
    264    
    265   /* write data to output file */
    266   f = fopen (filename, "w");
    267   if (f == (FILE *) NULL) {
    268     fprintf (stderr, "Failure writing fits table\n");
    269     return (FALSE);
    270   }
    271   fits_fwrite_header  (f, &header);
    272   fits_fwrite_matrix  (f, &matrix);
    273   fits_fwrite_Theader (f, &theader);
    274   fits_fwrite_table   (f, &table);
    275   fclose (f);
    276   return (TRUE);
    277 }
    278 
    279 /*
    280 
    281   selection options:
    282 
    283   CCDSelect
    284   TypeSelect
    285   TimeSelect
    286   FilterSelect
    287   ExptimeSelect
    288   EntrySelect
    289   LabelSelect
    290 
    291 */
  • trunk/Ohana/src/imregister/src/imstatreg.c

    r3649 r3650  
    11# include "imregister.h"
    22# include "imreg.h"
    3 static char *version = "imstatreg $Revision: 3.12 $";
     3static char *version = "imstatreg $Revision: 3.13 $";
    44
    55int main (int argc, char **argv) {
    66 
    7   RegImage *image;
    8   int *match, Nmatch, status, Nentry;
     7  int i, child, status;
     8  int *match, Nmatch, Nimage, Nsubset;
    99  FILE *f;
     10  RegImage *image, *subset;
    1011  FITS_DB image_db, temp_db;
     12  VTable vtable;
    1113
    1214  get_version (argc, argv, version);
     
    6870    fprintf (stderr, "temporary database read\n");
    6971
    70     /* DELETE and unlock temporary database */
    71     truncate or delete_db; /****** *****/
     72    /* delete, unlock existing database */
     73    truncate (TempDB, 0);
    7274    fits_db_close (&temp_db);
    7375    fprintf (stderr, "temporary database closed\n");
     
    115117  }
    116118}
    117 
    118 /* basic outline:
    119 
    120    - lock temp db
    121      - if empty, continue
    122    - load temp db
    123    - clear temp db
    124 
    125    - lock image db
    126      - if empty, resave temp db
    127 
    128    - load image db
    129    - match temp and main
    130 
    131    - update image db
    132 
    133    - unlock temp db
    134 */
    135 
Note: See TracChangeset for help on using the changeset viewer.