- Timestamp:
- Nov 21, 2002, 10:06:13 PM (23 years ago)
- Location:
- trunk/Ohana/src/imregister
- Files:
-
- 2 edited
-
imreg/db.c (modified) (8 diffs)
-
src/imregtable.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/imregister/imreg/db.c
r3 r4 11 11 RegImage *image; 12 12 int Nimage; 13 int lockstate, dbstate; 13 int lockstate; 14 int dbstate = LCK_UNLOCK; 14 15 15 16 RegImage *get_images (int *N) { … … 44 45 /* lock database (soft) */ 45 46 f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate); 46 if (dbstate == LCK_EMPTY) return (0);47 48 47 if (f == (FILE *) NULL) { 49 48 fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile); 50 49 exit (1); 51 50 } 51 if (dbstate == LCK_EMPTY) return (0); 52 52 53 53 /* load in table data */ 54 54 table.header = &theader; 55 fits_fread_header (f, &header);56 fits_fread_matrix (f, &matrix, &header);57 fits_fread_ftable (f, &table, "IMAGE_DATABASE");55 if (!fits_fread_header (f, &header)) escape (UNLOCK, "ERROR: can't read primary header"); 56 if (!fits_fread_matrix (f, &matrix, &header)) escape (UNLOCK, "ERROR: can't read primary header"); 57 if (!fits_fread_ftable (f, &table, "IMAGE_DATABASE")) escape (UNLOCK, "ERROR: can't read primary header"); 58 58 59 59 /* convert to internal format */ … … 63 63 Nimage = Ny; 64 64 65 ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage"); 65 if (!ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage")) 66 escape (UNLOCK, "ERROR: can't read primary header"); 67 66 68 return (1); 67 69 } … … 70 72 int save_db () { 71 73 72 ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage"); 74 if (!ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage")) 75 escape (UNLOCK, "ERROR: can't convert from native format"); 73 76 74 77 /* write all images to file */ 75 78 make_backup (dBFile); 76 79 Fseek (f, 0, SEEK_SET); 77 fits_fwrite_header (f, &header);78 fits_fwrite_matrix (f, &matrix);79 fits_fwrite_Theader (f, &theader);80 fits_fwrite_table (f, &table);80 if (!fits_fwrite_header (f, &header)) escape (LOCK, "ERROR: can't update db"); 81 if (!fits_fwrite_matrix (f, &matrix)) escape (LOCK, "ERROR: can't update db"); 82 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db"); 83 if (!fits_fwrite_table (f, &table)) escape (LOCK, "ERROR: can't update db"); 81 84 fclearlockfile (dBFile, f, lockstate, &dbstate); 82 85 return (TRUE); … … 114 117 make_backup (dBFile); 115 118 Fseek (f, 0, SEEK_SET); 116 fits_fwrite_header (f, &header);117 fits_fwrite_matrix (f, &matrix);118 fits_fwrite_Theader (f, &theader);119 fits_fwrite_vtable (f, &vtable);119 if (!fits_fwrite_header (f, &header)) escape (LOCK, "ERROR: can't update db"); 120 if (!fits_fwrite_matrix (f, &matrix)) escape (LOCK, "ERROR: can't update db"); 121 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db"); 122 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't update db"); 120 123 fclearlockfile (dBFile, f, lockstate, &dbstate); 121 124 return (TRUE); … … 126 129 VTable vtable; 127 130 128 fits_table_to_vtable (&table, &vtable); 131 /* add error checks! */ 132 fits_table_to_vtable (&table, &vtable, 0, 0); 129 133 130 134 ConvertStruct ((char *) new, sizeof (RegImage), Nnew, "regimage"); … … 133 137 /* write subset to file */ 134 138 Fseek (f, 0, SEEK_SET); 135 fits_fwrite_header (f, &header); 136 fits_fwrite_matrix (f, &matrix); 137 fits_fwrite_Theader (f, &theader); 138 fits_fwrite_vtable (f, &vtable); 139 if (!fits_fwrite_header (f, &header)) escape (LOCK, "ERROR: can't append to db"); 140 if (!fits_fwrite_matrix (f, &matrix)) escape (LOCK, "ERROR: can't append to db"); 141 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't append to db"); 142 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't append to db"); 143 139 144 fclearlockfile (dBFile, f, lockstate, &dbstate); 140 145 return (TRUE); … … 156 161 157 162 int close_db () { 158 fclearlockfile (dBFile, f, LCK_HARD, &dbstate); 163 if (dbstate == LCK_UNLOCK) return (TRUE); 164 fclearlockfile (dBFile, f, lockstate, &dbstate); 159 165 return (TRUE); 160 166 } 161 167 168 int escape (int mode, char *message) { 169 170 if (mode == UNLOCK) close_db (); 171 fprintf (stderr, "%s\n", message); 172 exit (1); 173 } -
trunk/Ohana/src/imregister/src/imregtable.c
r3 r4 1 1 # include "imregister.h" 2 2 # include "imreg.h" 3 static char *version = "imregtable $Revision: 3. 0$";3 static char *version = "imregtable $Revision: 3.1 $"; 4 4 5 5 int main (int argc, char **argv) { … … 22 22 } 23 23 infile = argv[1]; 24 output.modify = TRUE; 24 25 25 26 /* load in table data */ 26 27 table.header = &theader; 27 fits_read_header (infile, &header);28 fits_read_matrix (infile, &matrix, &header);29 fits_read_ftable (infile, &table, "IMAGE_DATABASE");28 if (!fits_read_header (infile, &header)) escape (UNLOCK, "can't open file header"); 29 if (!fits_read_matrix (infile, &matrix, &header)) escape (UNLOCK, "can't open file matrix"); 30 if (!fits_read_ftable (infile, &table, "IMAGE_DATABASE")) escape (UNLOCK, "can't open file table"); 30 31 31 32 /* convert to internal format */ … … 46 47 exit (0); 47 48 } 48
Note:
See TracChangeset
for help on using the changeset viewer.
