Index: /trunk/Ohana/src/imregister/src/imstatreg.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 87)
+++ /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 88)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imstatreg $Revision: 3.4 $";
+static char *version = "imstatreg $Revision: 3.5 $";
 
 int main (int argc, char **argv) {
@@ -8,5 +8,5 @@
   float *dtime;
   int i, *match, Nmatch, status, child, Nentry;
-  char *TempDB, *LogFile;
+  char *TempDB, *LogFile, *ccdname;
   FILE *f;
 
@@ -24,4 +24,5 @@
   SetSignals ();
 
+  /* fork in background */
   if (child = fork ()) {
     if (child == -1) {
@@ -40,46 +41,49 @@
   if (f == (FILE *) NULL) {
     fprintf (stderr, "can't open log file %s, writing to stderr\n", LogFile);
+  } else {
+    /* an error here will be missed, but is unlikely since we have access in the above test */
+    f = freopen (LogFile, "a", stderr);
   }
-  f = freopen (LogFile, "a", stderr);
-  /* an error here will be missed, but is unlikely since we have access in the above test */
 
   /* start loop */
   while (1) {
 
+    /* check / load temporary database */
     set_db (TempDB);
     status = load_db ();
     if (!status) {
-      fprintf (stderr, "temporary database is empty\n");
+      print_db_status ("temporary database empty");
       close_db (); 
-      fflush (stderr);
-      fflush (stdout);
-      sleep (60); 
-      continue;
+      goto next;
     }
     image = get_images (&Nentry);
-    close_lock_db (); /* file closed, hardlock on temp db remains */
+    print_db_status ("temporary database read");
+    close_lock_db (); 
+    /* temp DB closed, hardlock on temp DB remains */
       
+    /* check / load main database */
     set_db (ImageDB);
     status = load_db ();
     if (!status) {
-      fprintf (stderr, "database is empty\n");
-      close_db (); sleep (60); continue;
+      print_db_status ("main database empty");
+      close_db (); 
+      goto next;
     }
+
+    /* match temp image with main images / update main DB */
+    match = match_images (image, Nentry, &Nmatch);
+    if (Nmatch != Nentry) fprintf (stderr, "WARNING: some images missed\n");
+    print_db_status ("main database read");
+    update_db (match, Nmatch);
+    free (match);
       
-    match = match_images (image, Nentry, &Nmatch);
-    if (!Nmatch) {
-      close_db ();
-      fprintf (stderr, "ERROR: no matched images found\n");
-      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);
-      exit (2);
-    }
-    update_db (match, Nmatch);
-      
-    /* clear temp db hardlock */
-    unlink (TempDB);
+    /* clear temp DB hardlock */
+    unlink (TempDB); 
     clearlockfile2 (TempDB, -1, LCK_HARD, &status);
+
+  next:
     fflush (stderr);
     fflush (stdout);
-    sleep (60);
+    sleep (LOOP_DELAY);
   }
 }
