IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 88


Ignore:
Timestamp:
May 29, 2003, 7:52:19 AM (23 years ago)
Author:
eugene
Message:

fixed errors with alloc and fd

File:
1 edited

Legend:

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

    r81 r88  
    11# include "imregister.h"
    22# include "imreg.h"
    3 static char *version = "imstatreg $Revision: 3.4 $";
     3static char *version = "imstatreg $Revision: 3.5 $";
    44
    55int main (int argc, char **argv) {
     
    88  float *dtime;
    99  int i, *match, Nmatch, status, child, Nentry;
    10   char *TempDB, *LogFile;
     10  char *TempDB, *LogFile, *ccdname;
    1111  FILE *f;
    1212
     
    2424  SetSignals ();
    2525
     26  /* fork in background */
    2627  if (child = fork ()) {
    2728    if (child == -1) {
     
    4041  if (f == (FILE *) NULL) {
    4142    fprintf (stderr, "can't open log file %s, writing to stderr\n", LogFile);
     43  } else {
     44    /* an error here will be missed, but is unlikely since we have access in the above test */
     45    f = freopen (LogFile, "a", stderr);
    4246  }
    43   f = freopen (LogFile, "a", stderr);
    44   /* an error here will be missed, but is unlikely since we have access in the above test */
    4547
    4648  /* start loop */
    4749  while (1) {
    4850
     51    /* check / load temporary database */
    4952    set_db (TempDB);
    5053    status = load_db ();
    5154    if (!status) {
    52       fprintf (stderr, "temporary database is empty\n");
     55      print_db_status ("temporary database empty");
    5356      close_db ();
    54       fflush (stderr);
    55       fflush (stdout);
    56       sleep (60);
    57       continue;
     57      goto next;
    5858    }
    5959    image = get_images (&Nentry);
    60     close_lock_db (); /* file closed, hardlock on temp db remains */
     60    print_db_status ("temporary database read");
     61    close_lock_db ();
     62    /* temp DB closed, hardlock on temp DB remains */
    6163     
     64    /* check / load main database */
    6265    set_db (ImageDB);
    6366    status = load_db ();
    6467    if (!status) {
    65       fprintf (stderr, "database is empty\n");
    66       close_db (); sleep (60); continue;
     68      print_db_status ("main database empty");
     69      close_db ();
     70      goto next;
    6771    }
     72
     73    /* match temp image with main images / update main DB */
     74    match = match_images (image, Nentry, &Nmatch);
     75    if (Nmatch != Nentry) fprintf (stderr, "WARNING: some images missed\n");
     76    print_db_status ("main database read");
     77    update_db (match, Nmatch);
     78    free (match);
    6879     
    69     match = match_images (image, Nentry, &Nmatch);
    70     if (!Nmatch) {
    71       close_db ();
    72       fprintf (stderr, "ERROR: no matched images found\n");
    73       fprintf (stderr, "image: %s %s (%d) %s (%d)\n", image[0].filename, sec_to_date (image[0].obstime), image[0].obstime, ccds[image[0].ccd], image[0].ccd);
    74       exit (2);
    75     }
    76     update_db (match, Nmatch);
    77      
    78     /* clear temp db hardlock */
    79     unlink (TempDB);
     80    /* clear temp DB hardlock */
     81    unlink (TempDB);
    8082    clearlockfile2 (TempDB, -1, LCK_HARD, &status);
     83
     84  next:
    8185    fflush (stderr);
    8286    fflush (stdout);
    83     sleep (60);
     87    sleep (LOOP_DELAY);
    8488  }
    8589}
Note: See TracChangeset for help on using the changeset viewer.