IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3646


Ignore:
Timestamp:
Apr 1, 2005, 3:59:57 PM (21 years ago)
Author:
eugene
Message:

working toward autocode tables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/src/imstatreg.c

    r3606 r3646  
    11# include "imregister.h"
    22# include "imreg.h"
    3 static char *version = "imstatreg $Revision: 3.9 $";
     3static char *version = "imstatreg $Revision: 3.10 $";
    44
    55int main (int argc, char **argv) {
     
    88  int *match, Nmatch, status, Nentry;
    99  FILE *f;
    10   FITS_DB db;
     10  FITS_DB image_db, temp_db;
    1111
    1212  get_version (argc, argv, version);
     
    1919
    2020  /* fork in background */
    21   if (fork () == -1) {
    22       fprintf (stderr, "error forking imstatreg -daemon \n");
    23       exit (1);
    24     }
     21  child = fork ();
     22  if (child == -1) {
     23    fprintf (stderr, "error forking imstatreg -daemon \n");
     24    exit (1);
     25  }
     26  if (child !=  0) {
    2527    fprintf (stderr, "starting imstatreg, logging to %s\n", LogFile);
    2628    exit (0);
    2729  }
    2830
    29   /* child process, check for process */
     31  /* child process, check for previous process */
    3032  ConfigPID (PIDFILE);
    3133
     
    3941  }
    4042
    41   db.lockstate = LCK_HARD;
    42   db.timeout   = 300.0;
    43   fits_db_init (&db);
     43  image_db.lockstate = LCK_HARD;
     44  image_db.timeout   = 300.0;
     45  fits_db_init (&image_db);
     46
     47  temp_db.lockstate = LCK_HARD;
     48  temp_db.timeout   = 300.0;
     49  fits_db_init (&temp_db);
    4450
    4551  /* start loop */
     
    4753
    4854    /* check / load / delete temporary database */
    49     if (!fits_db_lock (&db, TempDB)) {
    50       fits_db_close (&db);
    51       fprintf (stderr, "error locking db (path missing? access permission?)\n");
     55    if (!fits_db_lock (&temp_db, TempDB)) {
     56      fits_db_close (&temp_db);
     57      fprintf (stderr, "error locking temp db (path missing? access permission?)\n");
    5258      exit (1);
    5359    }
    54     if (db.dbstate == LCK_EMPTY) {
     60    if (temp_db.dbstate == LCK_EMPTY) {
    5561      fprintf (stderr, "temporary database empty\n");
    5662      goto next;
    5763    }
    58     if (!fits_db_load (&db)) {
     64    if (!fits_db_load (&temp_db)) {
    5965      fprintf (stderr, "error reading temp db\n");
    6066      goto next;
    6167    }
    62     image = fits_table_get_RegImage (&db.ftable, &Nimage);
     68    image = fits_table_get_RegImage (&temp_db.ftable, &Nimage);
    6369    fprintf (stderr, "temporary database read\n");
    6470
    65     /* need to zero out this file */
     71    /* delete and unlock temporary database */
     72    fits_db_close (&temp_db);
    6673    fprintf (stderr, "temporary database closed\n");
    6774 
    68     /******* need to finish this section up *****/
    6975    /* check / load main database */
    70     set_db (ImageDB);
    71     status = load_db ();
    72     if (!status) {
    73       print_db_status ("main database empty");
    74       close_db ();
     76    if (!fits_db_lock (&image_db, ImageDB)) {
     77      fits_db_close (&image_db);
     78      fprintf (stderr, "error locking image db (path missing? access permission?)\n");
     79      exit (1);
     80    }
     81    if (temp_db.dbstate == LCK_EMPTY) {
     82      fprintf (stderr, "main database empty\n");
     83      fits_db_close (&image_db);
     84
    7585      /* add temp data back to temp database */
    76       print_db_status ("resave temporary data");
    77       set_db (TempDB);
    78       status = load_db ();
    79       if (!status) {
    80         print_db_status ("create new temporary database");
    81         create_db ();
     86      fprintf (stderr, "resave temporary data\n");
     87      if (!fits_db_lock (&temp_db, TempDB)) {
     88        fits_db_close (&temp_db);
     89        fprintf (stderr, "error locking temp db (path missing? access permission?)\n");
     90        exit (1);
    8291      }
    83       append_db (image, Nentry);
     92      if (temp_db.dbstate == LCK_EMPTY) {
     93        fprintf (stderr, "temporary database empty\n");
     94        goto next;
     95      }
     96      if (!fits_db_load (&temp_db)) {
     97        fprintf (stderr, "error reading temp db\n");
     98        goto next;
     99      }
     100      image = fits_table_get_RegImage (&temp_db.ftable, &Nimage);
     101      fprintf (stderr, "temporary database read\n");
     102
     103      fits_convert_Spectrum (spectrum, sizeof (Spectrum), 1);
     104      fits_table_to_vtable (&db.ftable, &vtable, 0, 0);
     105      fits_vadd_rows (&vtable, (char *) spectrum, 1, sizeof(Spectrum));
     106
     107      fits_db_update (&db, &vtable);
     108      fits_db_close (&db);
     109      fits_db_free (&db);
     110
    84111      print_db_status ("temporary database resaved");
    85112      goto next;
    86113    }
     114
     115    /************* this is kind of convoluted, need to simplify a bit ****/
    87116
    88117    /* match temp image with main images / update main DB */
     
    104133  }
    105134}
     135
     136/* basic outline:
     137
     138   - lock temp db
     139     - if empty, continue
     140   - load temp db
     141   - clear temp db
     142
     143   - lock image db
     144     - if empty, resave temp db
     145
     146   - load image db
     147   - match temp and main
     148
     149   - update image db
     150
     151   - unlock temp db
     152*/
     153
Note: See TracChangeset for help on using the changeset viewer.