IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3491


Ignore:
Timestamp:
Mar 23, 2005, 6:18:28 PM (21 years ago)
Author:
eugene
Message:

working towards autocode FITS table support

Location:
trunk/Ohana/src/imregister
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/doc/spdb.txt

    r2773 r3491  
    7373       - spload-mef converts to a single
    7474
     75-----
     76
     77database interactions vs autocode FITS tables
     78
  • trunk/Ohana/src/imregister/include/spreg.h

    r2803 r3491  
    11# include <signal.h>
     2
     3/*** fits_db test APIs ***/
     4typedef 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
     15DB *fits_db_init ();
     16DB *fits_db_lock (DB *db, char *filename);
     17int fits_db_load (DB *db);
     18int fits_db_save (DB *db);
     19int fits_db_free (DB *db);
     20int fits_db_update (DB *db, VTable *vtable);
     21int fits_db_close (DB *db);
     22int fits_db_print_status (DB *db, char *message);
     23int fits_db_escape (DB *db, char *message);
     24
     25/**** move to fitsio.h ***/
    226
    327enum {
  • trunk/Ohana/src/imregister/spreg/delete.c

    r2488 r3491  
    22# include "spreg.h"
    33
    4 void DeleteSubset (int *match, int Nmatch) {
     4void DeleteSubset (DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
    55
    66  int i, j;
    7   int *keep, Nbad, Nspectrum, Nsubset;
    8   Spectrum *spectrum, *subset;
    9 
    10   spectrum = get_spectra (&Nspectrum);
     7  int *keep, Nbad, Nsubset;
     8  Spectrum *subset;
    119
    1210  ALLOCATE (keep, int, MAX (Nspectrum, 1));
     
    3331
    3432  free (keep);
    35   set_spectra (subset, Nsubset);
    3633
    37   save_db ();
     34  fits_table_set_Spectrum (&db[0].table, subset, Nsubset);
     35  fits_db_save (db);
    3836  exit (0);
    39 
    4037}
  • trunk/Ohana/src/imregister/spreg/match.c

    r2803 r3491  
    22# include "spreg.h"
    33
    4 int *match_criteria (int *Nmatch) {
     4int *match_criteria (Spectrum *spectrum, int Nspectrum, int *Nmatch) {
    55
    6   int i, j, Nspectrum;
     6  int i, j;
    77  int N, NMATCH;
    88  int *match;
    99  int reject;
    1010  int Nfilename, Nobject, Ntelescope, Ninstrument;
    11   Spectrum *spectrum;
    1211
    1312  /* create selection index */
     
    1817  Nfilename = Nobject = Ntelescope = Ninstrument = 0;
    1918
    20   if (criteria.FilenameSelect) Nfilename     = strlen (criteria.Filename);
    21   if (criteria.ObjectSelect) Nobject         = strlen (criteria.Object);
    22   if (criteria.TelescopeSelect) Ntelescope   = strlen (criteria.Telescope);
     19  if (criteria.FilenameSelect)   Nfilename   = strlen (criteria.Filename);
     20  if (criteria.ObjectSelect)     Nobject     = strlen (criteria.Object);
     21  if (criteria.TelescopeSelect)  Ntelescope  = strlen (criteria.Telescope);
    2322  if (criteria.InstrumentSelect) Ninstrument = strlen (criteria.Instrument);
    24 
    25   spectrum = get_spectra (&Nspectrum);
    2623
    2724  /* find entries that matches criteria */
  • trunk/Ohana/src/imregister/spreg/modify.c

    r2803 r3491  
    22# include "spreg.h"
    33
    4 void ModifySubset (int *match, int Nmatch) {
     4void ModifySubset (DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {
    55
    66  int i, j, Nold;
    77  char *tmppath;
    8   int Nspectrum;
    9   Spectrum *spectrum;
     8  VTable vtable;
    109
    1110  Nold = 0;
    1211  tmppath = NULL;
    13 
    14   spectrum = get_spectra (&Nspectrum);
    1512
    1613  /* create some necessary variables */
     
    4138  }
    4239
    43   update_db (match, Nmatch);
     40  fits_vtable_from_ftable (&vtable, &db[0].ftable, match, Nmatch);
     41  for (i = 0; i < Nmatch; i++) {
     42    fits_convert_Spectrum (vtable.buffer[i], 1);
     43  }
     44  fits_db_update (db, &vtable);
    4445  fprintf (stderr, "SUCCESS\n");
    4546  exit (0);
  • trunk/Ohana/src/imregister/spreg/output.c

    r2803 r3491  
    33
    44static int RegTimeMode = FALSE;
    5 static int PTstyle = FALSE;
     5static int PTstyle     = FALSE;
    66
    77void SetOutputMode (char *mode) {
     
    1919
    2020/* given a subset list, write out the selected spectra, if desired */
    21 void OutputSubset (int *match, int Nmatch) {
    22 
    23   int Nspectrum;
    24   Spectrum *spectrum;
    25 
    26   spectrum = get_spectra (&Nspectrum);
     21void OutputSubset (Spectrum *spectra, int Nspectra, int *match, int Nmatch) {
    2722
    2823  if (output.table != (char *) NULL) {
     
    4237
    4338  int i, j;
    44   Header header, theader;
     39  Header header;
    4540  Matrix matrix;
    46   FTable table;
     41  Header theader;
     42  FTable ftable;
    4743  Spectrum *subset;
    4844
    49   /* define table layout */
    50   define_table (&header, &matrix, &theader, &table);
    51 
     45  /* extract subset list to single array */
    5246  ALLOCATE (subset, Spectrum, MAX (1, Nmatch));
    5347  for (i = 0; i < Nmatch; i++){
     
    5549    memcpy (&subset[i], &spectrum[j], sizeof (Spectrum));
    5650  }
    57   ConvertStruct ((char *) subset, sizeof (Spectrum), Nmatch, "spectrum");
    58   fits_add_rows (&table, (char *) subset, Nmatch, sizeof (Spectrum));
    5951
    60   fits_write_header  (filename, &header);
    61   fits_write_matrix  (filename, &matrix);
    62   fits_write_Theader (filename, &theader);
    63   fits_write_table   (filename, &table);
     52  /* open file for output */
     53  f = fopen (filename, "w");
     54  if (f == NULL) {
     55    fprintf (stderr, "ERROR: can't open output file %s\n", filename);
     56    exit (1);
     57  }
     58
     59  /* 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);
     65
     66  ftable.header = &theader;
     67  fits_table_set_Spectrum (&ftable, subset, Nmatch);
     68
     69  fits_fwrite_header   (f, &header);
     70  fits_fwrite_matrix   (f, &matrix);
     71  fits_fwrite_Theader  (f, &theader);
     72  fits_fwrite_ftable   (f, &ftable));
     73  fclose (f);
     74
    6475  exit (0);
    6576}
    6677
     78/* can the table definition here be autocoded as well? */
    6779void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch) {
    6880 
     
    94106  fits_modify (&theader, "DATE", "%s", 1, datestr);
    95107
    96   /* define table layout */
     108  /* define table layout (can this be autocoded?) */
    97109  fits_define_table_column (&theader, "A32",  "FILENAME",   "filename in db",        "");
    98110  fits_define_table_column (&theader, "A64",  "PATHNAME",   "fullpath in db",        "");
  • trunk/Ohana/src/imregister/spreg/unique.c

    r2803 r3491  
    33
    44/* input is a subset index of spectrum list, output is a new subset */
    5 int *unique_entries (int *subset, int *Nmatch) {
     5int *unique_entries (Spectrum *spectrum, int Nspectrum, int *subset, int *Nmatch) {
    66
    7   int i, j, m, Nspectrum, Nsubset;
     7  int i, j, m, Nsubset;
    88  int N, NMATCH;
    99  int *match, *entry;
    10   Spectrum *spectrum;
    1110  char idxline[128];
    1211  char **index;
     
    2019
    2120  Nsubset = *Nmatch;
    22   spectrum = get_spectra (&Nspectrum);
    2321
    2422  /* index = filename */
  • trunk/Ohana/src/imregister/src/spsearch.c

    r2488 r3491  
    11# include "imregister.h"
    22# include "spreg.h"
    3 static char *version = "imsearch $Revision: 1.1.1.1 $";
     3static char *version = "spsearch $Revision: 1.2 $";
    44
    55int main (int argc, char **argv) {
    66 
    7   int status, Nmatch;
     7  int status, Nmatch, Nspectra;
    88  int *match;
     9  DB *db;
     10  Spectrum *spectra;
    911
    1012  get_version (argc, argv, version);
    1113  args (argc, argv);
    1214
    13   set_db (SpectrumDB);
     15  lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
     16  db = fits_db_init (lockstate);
    1417
    15   status = load_db ();
    16   if (!status) {
    17     close_db ();
    18     exit (0);
     18  if (!fits_db_lock (db, SpectrumDB)) {
     19    fits_db_close (db);
     20    exit (1);
    1921  }
    20   if (!output.modify && !output.delete) close_db ();
    2122 
    22   match = match_criteria (&Nmatch);
    23   match = unique_entries (match, &Nmatch);
     23  if (!fits_db_load (db)) {
     24    fits_db_close (db);
     25    exit (1);
     26  }
     27  if (!output.modify && !output.delete) fits_db_close (db);
    2428
    25   if (output.modify) ModifySubset (match, Nmatch);
    26   if (output.delete) DeleteSubset (match, Nmatch);
     29  spectrum = fits_table_get_Spectrum (&db[0].table, &Nspectrum);
     30 
     31  match = match_criteria (spectra, Nspectra, &Nmatch);
     32  match = unique_entries (spectra, Nspectra, match, &Nmatch);
    2733
    28   OutputSubset (match, Nmatch);
     34  if (output.modify) ModifySubset (db, spectra, Nspectra, match, Nmatch);
     35  if (output.delete) DeleteSubset (db, spectra, Nspectra, match, Nmatch);
     36
     37  OutputSubset (spectra, Nspectra, match, Nmatch);
    2938
    3039  exit (0);
    3140}
    32 
    33 /*
    34 
    35 FITS table version:
    36 
    37    load_db - open, read in database, store as RegImage structure
    38    match   - return index 'match' to matched images
    39    modify  - change value of selected images
    40              write out subset of rows
    41    delete  - remove selected images from image structure
    42              write out entire table
    43    output  - write out subset in various formats
    44 
    45    get_images returns pointer to complete image structure
    46 
    47 
    48 SQL version:
    49 
    50    load_db - set up connection
    51    match   - convert criteria to SQL where clause and do:
    52              'select from images [where clause]'
    53              images structure is filled with result from query
    54    modify  - change value of subset selection (identical)
    55              update selected rows
    56    delete  - user where clause and do
    57              'delete from images where clause'
    58    output  - (identical)
    59 
    60    get_images returns pointer to image subset from query
    61    match[i] = i
    62 
    63 */
Note: See TracChangeset for help on using the changeset viewer.