Changeset 3646
- Timestamp:
- Apr 1, 2005, 3:59:57 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/imregister/src/imstatreg.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/imregister/src/imstatreg.c
r3606 r3646 1 1 # include "imregister.h" 2 2 # include "imreg.h" 3 static char *version = "imstatreg $Revision: 3. 9$";3 static char *version = "imstatreg $Revision: 3.10 $"; 4 4 5 5 int main (int argc, char **argv) { … … 8 8 int *match, Nmatch, status, Nentry; 9 9 FILE *f; 10 FITS_DB db;10 FITS_DB image_db, temp_db; 11 11 12 12 get_version (argc, argv, version); … … 19 19 20 20 /* 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) { 25 27 fprintf (stderr, "starting imstatreg, logging to %s\n", LogFile); 26 28 exit (0); 27 29 } 28 30 29 /* child process, check for pr ocess */31 /* child process, check for previous process */ 30 32 ConfigPID (PIDFILE); 31 33 … … 39 41 } 40 42 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); 44 50 45 51 /* start loop */ … … 47 53 48 54 /* 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"); 52 58 exit (1); 53 59 } 54 if ( db.dbstate == LCK_EMPTY) {60 if (temp_db.dbstate == LCK_EMPTY) { 55 61 fprintf (stderr, "temporary database empty\n"); 56 62 goto next; 57 63 } 58 if (!fits_db_load (& db)) {64 if (!fits_db_load (&temp_db)) { 59 65 fprintf (stderr, "error reading temp db\n"); 60 66 goto next; 61 67 } 62 image = fits_table_get_RegImage (& db.ftable, &Nimage);68 image = fits_table_get_RegImage (&temp_db.ftable, &Nimage); 63 69 fprintf (stderr, "temporary database read\n"); 64 70 65 /* need to zero out this file */ 71 /* delete and unlock temporary database */ 72 fits_db_close (&temp_db); 66 73 fprintf (stderr, "temporary database closed\n"); 67 74 68 /******* need to finish this section up *****/69 75 /* 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 75 85 /* 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); 82 91 } 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 84 111 print_db_status ("temporary database resaved"); 85 112 goto next; 86 113 } 114 115 /************* this is kind of convoluted, need to simplify a bit ****/ 87 116 88 117 /* match temp image with main images / update main DB */ … … 104 133 } 105 134 } 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.
