IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3509


Ignore:
Timestamp:
Mar 24, 2005, 4:51:08 PM (21 years ago)
Author:
eugene
Message:

updating spreg to autocode

Location:
trunk/Ohana/src/imregister
Files:
11 edited

Legend:

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

    r2823 r3509  
    2020
    2121INCS    =       -I$(INC) -I$(LINC) -I$(XINC)
    22 LIBS    =       -L$(LLIB) -lFITS -lohana -lm
     22LIBS    =       -L$(LLIB) -lohana -lFITS -lm
    2323# CFLAGS        =       $(INCS) -Wall -Werror
    2424CFLAGS  =       $(INCS)
     
    6363
    6464SPOBJ  = \
    65 $(SPREG)/db.$(ARCH).o     \
    6665$(SPREG)/delete.$(ARCH).o \
    6766$(SPREG)/define.$(ARCH).o \
    68 $(SPREG)/spinfo.$(ARCH).o \
    6967$(SPREG)/match.$(ARCH).o  \
    7068$(SPREG)/modify.$(ARCH).o \
    71 $(SPREG)/fits_scan_nchar.$(ARCH).o \
    7269$(SPREG)/output.$(ARCH).o \
    7370$(SPREG)/unique.$(ARCH).o \
    7471$(SPREG)/ConfigInit.$(ARCH).o    \
     72$(SPREG)/spinfo.$(ARCH).o \
     73$(SPREG)/fits_scan_nchar.$(ARCH).o \
    7574$(SPREG)/showinfo.$(ARCH).o  \
    7675$(BASEDIR)/misc.$(ARCH).o        \
     76$(BASEDIR)/version.$(ARCH).o        \
    7777$(BASEDIR)/parse_time.$(ARCH).o  \
    7878$(BASEDIR)/sort.$(ARCH).o
  • trunk/Ohana/src/imregister/base/misc.c

    r2803 r3509  
    319319   */
    320320
    321 
    322 /* fseek with timeout - 0.5 sec */
    323 int Fseek (FILE *f, long offset, int whence) {
    324 
    325   int status, k;
    326 
    327   status = fseek (f, offset, whence);
    328   if (status == -1) {
    329     for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
    330     if (status == -1) {
    331       return (0);
    332     }
    333   }
    334   return (1);
    335 }
    336321
    337322/* return values:
     
    400385}
    401386 
    402 void make_backup (char *filename) {
    403 
    404   int status, cmode;
    405   struct stat filestat;
    406   char line[256];
    407 
    408   status = stat (filename, &filestat);
    409   if (status == 0) { /* file exists, make backup copy */
    410     sprintf (line, "cp %s %s~", filename, filename);
    411     status = system (line);
    412     if (status) {
    413       fprintf (stderr, "ERROR: unable to create %s~, exiting\n", filename);
    414       exit (0);
    415     }
    416     cmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    417     sprintf (line, "%s~", filename);
    418     chmod (line, cmode);
    419   }
    420 }
    421 
    422387int get_filter_arguments (int *argc, char **argv, int **Filt, int *Nfilt) {
    423388
     
    458423 
    459424   
    460 void get_version (int argc, char **argv, char *version) {
    461 
    462   int N;
    463   char *p, *q, *line;
    464 
    465   if (get_argument (argc, argv, "-version")) {
    466 
    467     N = strlen (version) + 2;
    468     line = (char *) malloc (N);
    469     bzero (line, N);
    470 
    471     p = strstr (version, "$Revision: ");
    472     if (p != (char *) NULL)
    473       p += strlen ("$Revision: ");
    474     else
    475       p = version;
    476 
    477     q = strstr (p, "$");
    478     if (q != (char *) NULL)
    479       N = q - p;
    480     else
    481       N = strlen (p);
    482 
    483     strncpy (line, p, N);
    484 
    485     fprintf (stderr, "%s\n", line);
    486     exit (2);
    487   }
    488 
    489 
    490425/* replaces whitespace blocks with single . */
    491426void clean_spaces (char *line) {
  • trunk/Ohana/src/imregister/base/parse_time.c

    r2803 r3509  
    119119}
    120120
    121 void uppercase (char *string) {
    122 
    123   int i;
    124    
    125   for (i = 0; i < strlen (string); i++) string[i] = toupper (string[i]);
    126 
    127 }
  • trunk/Ohana/src/imregister/include/imregister.h

    r3466 r3509  
    8080int str_to_time (char *line, unsigned long *second);
    8181
    82 int Fseek (FILE *f, long offset, int whence);
    8382int get_trange_arguments (int *argc, char **argv, unsigned long **Tstart, unsigned long **Tstop, int *ntimes);
    8483int get_filter_arguments (int *argc, char **argv, int **Filt, int *Nfilt);
    8584
    86 void make_backup (char *filename);
    8785int parse_time (Header *header);
    88 void uppercase (char *string);
    8986void sort (float *value, int N);
    9087void dsort (double *value, int N);
  • trunk/Ohana/src/imregister/include/spreg.h

    r3491 r3509  
    11# include <signal.h>
    2 
    3 /*** fits_db test APIs ***/
    4 typedef struct {
    5   FILE  *f;
    6   char  *extname;
    7   int    dbstate;
    8   int    lockstat;
    9   Header header;
    10   Matrix matrix;
    11   Header theader;
    12   FTable ftable;
    13 } DB;
    14 
    15 DB *fits_db_init ();
    16 DB *fits_db_lock (DB *db, char *filename);
    17 int fits_db_load (DB *db);
    18 int fits_db_save (DB *db);
    19 int fits_db_free (DB *db);
    20 int fits_db_update (DB *db, VTable *vtable);
    21 int fits_db_close (DB *db);
    22 int fits_db_print_status (DB *db, char *message);
    23 int fits_db_escape (DB *db, char *message);
    24 
    25 /**** move to fitsio.h ***/
    262
    273enum {
     
    4218  SPSTATE_N
    4319};
    44 
    45 /* structure for Image Registration Database */
    46 typedef struct {
    47   float ra, dec;
    48   float exptime;
    49   float airmass;
    50 
    51   float Ws, We, dW;
    52 
    53   int  Nspec;
    54 
    55   unsigned long int obstime;
    56   unsigned long int regtime;
    57 
    58   char mode;                       /* MEF, SINGLE, SPLIT */
    59   char state;                      /* MEF, SINGLE, SPLIT */
    60   char flag;                       /* image status flags */
    61   char extra[13];
    62 
    63   char pathname[64];
    64   char filename[32];
    65   char extname[16];
    66 
    67   char instrument[16];
    68   char telescope[16];
    69   char objname[16];
    70 
    71 } Spectrum;  /* 328 bytes / image */
    7220
    7321struct {
     
    13280
    13381int args (int argc, char **argv);
    134 Spectrum *get_spectrums (int *N);
    135 int set_spectrums (Spectrum *new, int Nnew);
    136 int load_db ();
    137 int save_db ();
    138 int update_db (int *match, int Nmatch);
    139 int append_db (Spectrum *new, int Nnew);
    140 int create_db ();
    141 int close_db ();
    142 void DeleteSubset (int *match, int Nmatch);
    143 Spectrum *spinfo (char *filename);
    144 int *match_criteria (int *Nmatch);
    145 int *match_spectrums (Spectrum *subset, int Nsubset, int *Nmatch);
    146 void ModifySubset (int *match, int Nmatch);
     82int *match_criteria (Spectrum *spectrum, int Nspectrum, int *Nmatch);
     83int *unique_entries (Spectrum *spectrum, int Nspectrum, int *subset, int *Nmatch);
     84
     85void ModifySubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
     86void DeleteSubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
     87void OutputSubset (Spectrum *spectrum, int Nspectrum, int *match, int Nmatch);
     88
    14789void SetOutputMode (char *mode);
    148 void OutputSubset (int *match, int Nmatch);
    14990void DumpFitsBintable (char *filename, Spectrum *spectrum, int *match, int Nmatch);
    15091void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch);
    15192int PrintSubset (Spectrum *spectrum, int *match, int Nmatch);
    15293int dump_data (Spectrum *spectrum, int Nspectrum);
     94
     95Spectrum *spinfo (char *filename);
     96int *match_spectrums (Spectrum *subset, int Nsubset, int *Nmatch);
    15397int SubmitSpectrums (Spectrum *spectrum);
    15498int load_probes (char *filename, unsigned long tzero, int *wantprobe, double *values, int Nprobe);
    15599int define_table (Header *header, Matrix *matrix, Header *theader, FTable *table);
    156100void set_timezone (double dt);
    157 
    158 void DumpCADCTable (char *filename, Spectrum *spectrum, int *match, int Nmatch);
    159 int *GetObsIDSubset (Spectrum *spectrum, int start, int *index, int *entry, int Nindex, int *Nsubset);
    160 int *GetUniqueObsID (Spectrum *spectrum, int *index, int *entry, int Nindex, int *Nmatch);
    161 void GetObsIDIndex (Spectrum *spectrum, int *match, int Nmatch, int **Index, int **Entry);
    162 double SigmaClipList (double *list, int N);
    163 double MosaicIQStats (Spectrum *spectrum, int *match, int Nmatch, MosaicRegion *region);
    164 MosaicLayout *CreateCFH12K ();
    165 MosaicLayout *CreateMegaCam ();
    166 int GetREFCCD (Spectrum *spectrum, int *index, int *entry, int Nindex, int start);
    167101
    168102void showinfo (Spectrum *spec);
     
    173107int fits_scan_nchar (Header *header, int size, char *field, int N,...);
    174108void warn_scan_nchar (Header *header, int size, char *field, int N, void *var);
    175 
    176 int *unique_entries (int *subset, int *Nmatch);
  • trunk/Ohana/src/imregister/spreg/delete.c

    r3491 r3509  
    22# include "spreg.h"
    33
    4 void DeleteSubset (DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
     4void DeleteSubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
    55
    66  int i, j;
     
    3232  free (keep);
    3333
    34   fits_table_set_Spectrum (&db[0].table, subset, Nsubset);
     34  /** we may later want to pull this out and put it elsewhere **/
     35  /** free db[0].theader, db[0].table.buffer? **/
     36  fits_table_set_Spectrum (&db[0].ftable, subset, Nsubset);
    3537  fits_db_save (db);
     38  fits_db_close (db);
     39  fits_db_free (db);
     40
     41  fprintf (stderr, "SUCCESS\n");
    3642  exit (0);
    3743}
  • trunk/Ohana/src/imregister/spreg/match.c

    r3491 r3509  
    4949}
    5050
     51# if (0)
     52
    5153int *match_spectra (Spectrum *subset, int Nsubset, int *Nmatch) {
    5254 
     
    8284  return (match);
    8385}
     86
     87# endif
  • trunk/Ohana/src/imregister/spreg/modify.c

    r3491 r3509  
    22# include "spreg.h"
    33
    4 void ModifySubset (DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
     4void ModifySubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
    55
    66  int i, j, Nold;
     
    3838  }
    3939
    40   fits_vtable_from_ftable (&vtable, &db[0].ftable, match, Nmatch);
     40  /** we may later want to pull this out and put it elsewhere **/
     41  fits_vtable_from_ftable (&db[0].ftable, &vtable, match, Nmatch);
    4142  for (i = 0; i < Nmatch; i++) {
    42     fits_convert_Spectrum (vtable.buffer[i], 1);
     43    fits_convert_Spectrum ((Spectrum *) vtable.buffer[i], sizeof (Spectrum), 1);
    4344  }
    4445  fits_db_update (db, &vtable);
     46  fits_db_close (db);
     47  fits_db_free (db);
     48
    4549  fprintf (stderr, "SUCCESS\n");
    4650  exit (0);
    47 
    4851}
  • trunk/Ohana/src/imregister/spreg/output.c

    r3492 r3509  
    33
    44static int RegTimeMode = FALSE;
    5 static int PTstyle     = FALSE;
    65
    76void SetOutputMode (char *mode) {
     
    1110    return;
    1211  }
    13   if (!strcmp (mode, "PTstyle")) {
    14     PTstyle = TRUE;
    15     return;
    16   }
    17 
     12  return;
    1813}
    1914
    2015/* given a subset list, write out the selected spectra, if desired */
    21 void OutputSubset (Spectrum *spectra, int Nspectra, int *match, int Nmatch) {
     16void OutputSubset (Spectrum *spectrum, int Nspectra, int *match, int Nmatch) {
    2217
    2318  if (output.table != (char *) NULL) {
     
    3732
    3833  int i, j;
     34  FILE *f;
    3935  Header header;
    4036  Matrix matrix;
     
    5854
    5955  /* create primary header */
    60   fits_init_header (header);   
    61   header[0].extend = TRUE;
    62   fits_create_header (header);
    63   fits_create_matrix (header, matrix);
    64   fits_print (header, "NEXTEND", "%d", 1, 1);
     56  fits_init_header (&header);   
     57  header.extend = TRUE;
     58  fits_create_header (&header);
     59  fits_create_matrix (&header, &matrix);
     60  fits_print (&header, "NEXTEND", "%d", 1, 1);
    6561
    6662  ftable.header = &theader;
     
    7066  fits_fwrite_matrix   (f, &matrix);
    7167  fits_fwrite_Theader  (f, &theader);
    72   fits_fwrite_ftable   (f, &ftable);
     68  fits_fwrite_table   (f, &ftable);
    7369  fclose (f);
    7470
     
    7672}
    7773
    78 /* can the table definition here be autocoded as well? */
     74/* write out an ASCII table */
    7975void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch) {
    8076 
     
    8278  char *obsstr, *regstr, *line, *datestr;
    8379  unsigned long tsecond;
     80  FILE *f;
    8481  Header header, theader;
    8582  Matrix matrix;
    86   FTable table;
     83  FTable ftable;
    8784  Spectrum *subset;
    8885
     
    9491  fits_print (&header, "NEXTEND", "%d", 1, 1);
    9592 
     93  /* the ASCII table is always a little harder than the binary:
     94   * we need to build the data line a bit carefully
     95   */
     96
     97  /* create an empty table which we will fill in by hand */
    9698  ftable.header = &theader;
    9799  fits_table_set_SpectrumASCII (&ftable, NULL, 0);
    98100 
    99   /* the ASCII table is always a little harder than the binary
    100      need to build the data line a bit carefully
    101    */
    102 
    103101  /* add data to table */
    104102  for (i = 0; i < Nmatch; i++) {
    105103    subset = &spectrum[match[i]];
    106     obsstr   = sec_to_date (subset[0].obstime);
    107     regstr   = sec_to_date (subset[0].regtime);
     104    obsstr = sec_to_date (subset[0].obstime);
     105    regstr = sec_to_date (subset[0].regtime);
    108106
    109107    /* we should get an error here if we don't construct this line correctly */
    110     line = fits_table_print (&table, subset[0].filename, subset[0].pathname, subset[0].instrument,
     108    line = fits_table_print (&ftable, subset[0].filename, subset[0].pathname, subset[0].instrument,
    111109                             subset[0].telescope, subset[0].objname, subset[0].extname,
    112110                             subset[0].ra, subset[0].dec, subset[0].exptime, subset[0].airmass,
     
    115113                             subset[0].mode, subset[0].state, subset[0].flag);
    116114
    117     fits_add_rows (&table, line, 1, strlen(line));
     115    fits_add_rows (&ftable, line, 1, strlen(line));
    118116    free (line);
    119117    free (obsstr);
     
    127125  fits_modify (&theader, "DATE", "%s", 1, datestr);
    128126
    129   fits_write_header  (filename, &header);
    130   fits_write_matrix  (filename, &matrix);
    131   fits_write_Theader (filename, &theader);
    132   fits_write_table   (filename, &table);
     127  /* open file for output */
     128  f = fopen (filename, "w");
     129  if (f == NULL) {
     130    fprintf (stderr, "ERROR: can't open output file %s\n", filename);
     131    exit (1);
     132  }
     133
     134  fits_fwrite_header  (f, &header);
     135  fits_fwrite_matrix  (f, &matrix);
     136  fits_fwrite_Theader (f, &theader);
     137  fits_fwrite_table   (f, &ftable);
     138  fclose (f);
     139
    133140  exit (0);
    134141}
  • trunk/Ohana/src/imregister/src/spregister.c

    r2803 r3509  
    11# include "imregister.h"
    22# include "spreg.h"
    3 static char *version = "spregister $Revision: 1.3 $";
     3static char *version = "spregister $Revision: 1.4 $";
    44
    55int main (int argc, char **argv) {
    66 
    7   Spectrum *spectrum, *pspectrum;
    8   int status, Nnew;
     7  Spectrum *spectrum;
     8  VTable vtable;
     9  FITS_DB db;
    910
    1011  get_version (argc, argv, version);
    1112  args (argc, argv);
     13
    1214  spectrum = spinfo (argv[1]);
    1315
    1416  if (DUMP) showinfo (spectrum);
    1517
    16   Nnew = 1;
    17   pspectrum = &spectrum[0];
    18 
    1918  if (NoReg) exit (0);
    2019
    21   set_db (SpectrumDB);
    22   status = load_db ();
    23   if (!status) {
    24     create_db ();
     20  db.lockstate = LCK_HARD;
     21  db.timeout   = 300.0;
     22
     23  fits_db_init (&db);
     24
     25  if (!fits_db_lock (&db, SpectrumDB)) {
     26    fits_db_close (&db);
     27    exit (1);
    2528  }
    26   append_db (pspectrum, Nnew);
     29  if (db.dbstate == LCK_EMPTY) {
     30    /* create db header & matrix */
     31  } else { 
     32    if (!fits_db_load (&db)) {
     33      fits_db_close (&db);
     34      exit (1);
     35    }
     36  }
     37
     38  /** we may later want to pull this out and put it elsewhere **/
     39  fits_convert_Spectrum (spectrum, sizeof (Spectrum), 1);
     40  fits_table_to_vtable (&db.ftable, &vtable, 0, 1);
     41  fits_db_update (&db, &vtable);
     42  fits_db_close (&db);
     43  fits_db_free (&db);
     44
    2745  exit (0);
    2846}
  • trunk/Ohana/src/imregister/src/spsearch.c

    r3491 r3509  
    11# include "imregister.h"
    22# include "spreg.h"
    3 static char *version = "spsearch $Revision: 1.2 $";
     3static char *version = "spsearch $Revision: 1.3 $";
    44
    55int main (int argc, char **argv) {
    66 
    7   int status, Nmatch, Nspectra;
    8   int *match;
    9   DB *db;
    10   Spectrum *spectra;
     7  int Nmatch, Nspectrum, *match;
     8  Spectrum *spectrum;
     9  FITS_DB db;
    1110
    1211  get_version (argc, argv, version);
    1312  args (argc, argv);
    1413
    15   lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
    16   db = fits_db_init (lockstate);
     14  db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
     15  db.timeout   = 300.0;
    1716
    18   if (!fits_db_lock (db, SpectrumDB)) {
    19     fits_db_close (db);
     17  fits_db_init (&db);
     18
     19  if (!fits_db_lock (&db, SpectrumDB)) {
     20    fits_db_close (&db);
    2021    exit (1);
    2122  }
    2223 
    23   if (!fits_db_load (db)) {
    24     fits_db_close (db);
     24  if (!fits_db_load (&db)) {
     25    fits_db_close (&db);
    2526    exit (1);
    2627  }
    27   if (!output.modify && !output.delete) fits_db_close (db);
    2828
    29   spectrum = fits_table_get_Spectrum (&db[0].table, &Nspectrum);
     29  if (!output.modify && !output.delete) fits_db_close (&db);
     30
     31  spectrum = fits_table_get_Spectrum (&db.ftable, &Nspectrum);
    3032 
    31   match = match_criteria (spectra, Nspectra, &Nmatch);
    32   match = unique_entries (spectra, Nspectra, match, &Nmatch);
     33  match = match_criteria (spectrum, Nspectrum, &Nmatch);
     34  match = unique_entries (spectrum, Nspectrum, match, &Nmatch);
    3335
    34   if (output.modify) ModifySubset (db, spectra, Nspectra, match, Nmatch);
    35   if (output.delete) DeleteSubset (db, spectra, Nspectra, match, Nmatch);
     36  if (output.modify) ModifySubset (&db, spectrum, Nspectrum, match, Nmatch);
     37  if (output.delete) DeleteSubset (&db, spectrum, Nspectrum, match, Nmatch);
    3638
    37   OutputSubset (spectra, Nspectra, match, Nmatch);
     39  OutputSubset (spectrum, Nspectrum, match, Nmatch);
    3840
    3941  exit (0);
Note: See TracChangeset for help on using the changeset viewer.