Changeset 2823
- Timestamp:
- Dec 23, 2004, 5:18:05 PM (22 years ago)
- Location:
- trunk/Ohana/src/imregister
- Files:
-
- 1 deleted
- 22 edited
-
Makefile (modified) (1 diff)
-
base/ConfigInit.c (modified) (1 diff)
-
detrend/db.c (modified) (12 diffs)
-
detrend/delete.c (modified) (2 diffs)
-
imreg/SetSignals.c (modified) (2 diffs)
-
imreg/args.imregister.c (modified) (1 diff)
-
imreg/db.c (modified) (10 diffs)
-
imreg/delete.c (modified) (3 diffs)
-
imreg/imregclient.c (modified) (1 diff)
-
imreg/rconnect.c (modified) (2 diffs)
-
include/detrend.h (modified) (1 diff)
-
include/imregister.h (modified) (1 diff)
-
photreg/db.c (modified) (13 diffs)
-
photreg/delete.c (modified) (3 diffs)
-
src/detregister.c (modified) (2 diffs)
-
src/detsearch.c (modified) (2 diffs)
-
src/imregister.c (modified) (2 diffs)
-
src/imregtable.c (modified) (2 diffs)
-
src/imsearch.c (modified) (2 diffs)
-
src/imsort.c (deleted)
-
src/imstatreg.c (modified) (7 diffs)
-
src/photreg.c (modified) (2 diffs)
-
src/photsearch.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/imregister/Makefile
r2803 r2823 141 141 $(BIN)/detsearch.$(ARCH) : $(SRC)/detsearch.$(ARCH).o $(DS) ; $(CC) $^ -o $@ $(LFLAGS) 142 142 143 $(BIN)/imsort.$(ARCH) : $(BIN)/imregister.$(ARCH) ; rm -f $(BIN)/imsort.$(ARCH) ; ln$(BIN)/imregister.$(ARCH) $(BIN)/imsort.$(ARCH)143 $(BIN)/imsort.$(ARCH) : $(BIN)/imregister.$(ARCH) ; rm -f $(BIN)/imsort.$(ARCH) ; cp $(BIN)/imregister.$(ARCH) $(BIN)/imsort.$(ARCH) 144 144 145 145 $(BIN)/spsearch.$(ARCH) : $(SRC)/spsearch.$(ARCH).o $(SS) ; $(CC) $^ -o $@ $(LFLAGS) -
trunk/Ohana/src/imregister/base/ConfigInit.c
r2449 r2823 75 75 sprintf (PtolemyFifo, "%s.source", ElixirBase); 76 76 77 if (!ScanConfig (config, "CONNECT", "%s", 0, CONNECT)) { 78 sprintf (CONNECT, "/usr/bin/rsh"); 79 } 80 77 81 /* load Detrend Alt Databases paths */ 78 82 NDB = 10; -
trunk/Ohana/src/imregister/detrend/db.c
r2803 r2823 3 3 4 4 /* variables which describe the db */ 5 char *dBPath;5 FILE *f; 6 6 char *dBFile; 7 char *dBTrash;8 FILE *f;9 7 Header header; 10 8 Header theader; … … 13 11 DetReg *image; 14 12 int Nimage; 15 int lockstate, dbstate = LCK_UNLOCK; 13 int lockstate; 14 int dbstate; 15 16 /* special variables unique to detrend.db */ 17 char *dBPath; 18 char *dBTrash; 19 20 void init_db () { 21 f = NULL; 22 dBFile = NULL; 23 header.buffer = NULL; 24 matrix.buffer = NULL; 25 theader.buffer = NULL; 26 table.buffer = NULL; 27 table.header = &theader; 28 image = NULL; 29 Nimage = 0; 30 lockstate = LCK_EMPTY; 31 dbstate = LCK_UNLOCK; 32 dBPath = NULL; 33 dBTrash = NULL; 34 } 35 36 char *get_dBPath () { 37 dBPath = DetrendDB; 38 return (dBPath); 39 } 16 40 17 41 DetReg *get_images (int *N) { … … 24 48 int Nbytes; 25 49 26 free (image); 27 50 /* assign pointers to new data block */ 51 Nimage = Nnew; 52 image = new; 53 if (image == NULL) Nnew = 0; 54 55 /* update header, table structures */ 28 56 fits_modify (table.header, "NAXIS2", "%d", 1, Nnew); 29 57 table.header[0].Naxis[1] = Nnew; 58 table.buffer = (char *) image; 59 60 /* add padding space to buffer */ 30 61 Nbytes = fits_matrix_size (table.header); 31 32 Nimage = Nnew; 33 image = new; 34 REALLOCATE (image, DetReg, Nbytes); 35 table.buffer = (char *) image; 36 return (TRUE); 37 } 38 39 char *get_dBPath () { 40 dBPath = DetrendDB; 41 return (dBPath); 42 } 43 44 int delete_image (DetReg *item) { 45 46 int status; 47 char line[256]; 48 49 if (output.verbose) fprintf (stderr, "deleting %s\n", item[0].filename); 50 sprintf (line, "mv -f %s/%s %s", dBPath, item[0].filename, dBTrash); 51 status = system (line); 52 if (status) fprintf (stderr, "trouble moving %s to trash (%s)\n", item[0].filename, dBTrash); 53 54 if (status) 55 return (FALSE); 56 else 57 return (TRUE); 62 if (Nbytes > 0) { 63 REALLOCATE (table.buffer, char, Nbytes); 64 image = (DetReg *) table.buffer; 65 } 66 table.size = Nbytes; 67 68 return (TRUE); 58 69 } 59 70 … … 91 102 } 92 103 lockstate = (output.Modify || output.Delete) ? LCK_HARD : LCK_SOFT; 104 header.buffer = matrix.buffer = theader.buffer = table.buffer = (char *) NULL; 93 105 94 106 /* lock database (soft) */ … … 102 114 103 115 /* load in table data */ 104 table.header = &theader;105 116 if (!fits_fread_header (f, &header)) escape (UNLOCK, "ERROR: can't read primary header"); 106 if (!fits_fread_matrix (f, &matrix, &header)) escape (UNLOCK, "ERROR: can't read primary header");107 if (!fits_fread_ftable (f, &table, "DETREND_DATABASE")) escape (UNLOCK, "ERROR: can't read primary header");117 if (!fits_fread_matrix (f, &matrix, &header)) escape (UNLOCK, "ERROR: can't read primary matrix"); 118 if (!fits_fread_ftable (f, &table, "DETREND_DATABASE")) escape (UNLOCK, "ERROR: can't read table"); 108 119 109 120 /* convert to internal format */ … … 113 124 Nimage = Ny; 114 125 115 if (!ConvertStruct ((char *) image, sizeof (DetReg), Nimage, "detreg")) escape (UNLOCK, "ERROR: can't read primary header"); 126 if (!ConvertStruct ((char *) image, sizeof (DetReg), Nimage, "detreg")) 127 escape (UNLOCK, "ERROR: can't convert data"); 128 116 129 return (1); 117 130 } 118 119 131 120 132 /* save complete db file */ 121 133 int save_db () { 122 134 123 if (!ConvertStruct ((char *) image, sizeof (DetReg), Nimage, "detreg")) escape (UNLOCK, "ERROR: can't convert from native format"); 135 if (!ConvertStruct ((char *) image, sizeof (DetReg), Nimage, "detreg")) 136 escape (UNLOCK, "ERROR: can't convert from native format"); 124 137 125 138 /* write all images to file */ … … 130 143 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db"); 131 144 if (!fits_fwrite_table (f, &table)) escape (LOCK, "ERROR: can't update db"); 145 146 fits_free_table (&table); 132 147 close_db (); 148 133 149 return (TRUE); 134 150 } … … 169 185 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db"); 170 186 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't update db"); 187 188 fits_free_table (&table); 189 fits_free_vtable (&vtable); 171 190 close_db (); 172 return (TRUE); 173 } 174 191 192 return (TRUE); 193 } 194 195 /* add new entries to db, close db */ 175 196 int append_db (DetReg *new, int Nnew) { 176 197 … … 182 203 ConvertStruct ((char *) new, sizeof (DetReg), Nnew, "detreg"); 183 204 fits_vadd_rows (&vtable, (char *) new, Nnew, sizeof(DetReg)); 205 Nimage = theader.Naxis[1]; 184 206 185 207 /* write subset to file */ … … 189 211 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't append to db"); 190 212 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't append to db"); 213 214 fits_free_table (&table); 215 fits_free_vtable (&vtable); 191 216 close_db (); 217 192 218 return (TRUE); 193 219 } … … 208 234 209 235 int close_db () { 210 if (dbstate == LCK_UNLOCK) return (TRUE); 211 if (dbstate == LCK_EMPTY) return (TRUE); 236 237 /* these are safe even if db is empty */ 238 fits_free_header (&header); 239 fits_free_matrix (&matrix); 240 fits_free_header (&theader); 241 /* don't free table: db data may still be used */ 242 212 243 fclearlockfile (dBFile, f, lockstate, &dbstate); 244 if ((Nimage == 0) && (lockstate != LCK_SOFT)) unlink (dBFile); 245 213 246 return (TRUE); 214 247 } … … 220 253 exit (1); 221 254 } 255 256 int delete_image (DetReg *item) { 257 258 int status; 259 char line[256]; 260 261 if (output.verbose) fprintf (stderr, "deleting %s\n", item[0].filename); 262 sprintf (line, "mv -f %s/%s %s", dBPath, item[0].filename, dBTrash); 263 status = system (line); 264 if (status) fprintf (stderr, "trouble moving %s to trash (%s)\n", item[0].filename, dBTrash); 265 266 if (status) 267 return (FALSE); 268 else 269 return (TRUE); 270 } 271 -
trunk/Ohana/src/imregister/detrend/delete.c
r2803 r2823 2 2 # include "detrend.h" 3 3 4 intDeleteSubset (Match *match, int Nmatch) {4 void DeleteSubset (Match *match, int Nmatch) { 5 5 6 6 int i, j; … … 10 10 image = get_images (&Nimage); 11 11 12 ALLOCATE (keep, int, Nimage);12 ALLOCATE (keep, int, MAX (Nimage, 1)); 13 13 for (i = 0; i < Nimage; i++) keep[i] = TRUE; 14 fprintf (stderr, "total of %d detrend images\n", Nimage); 14 15 15 16 Ndel = 0; 16 /* list matched images */17 17 for (j = 0; j < Nmatch; j++) { 18 18 i = match[j].image; 19 19 if (i == -1) continue; 20 20 keep[i] = FALSE; 21 21 Ndel ++; 22 22 delete_image (&image[i]); 23 Ndel ++;24 23 } 24 fprintf (stderr, "delete %d images\n", Ndel); 25 25 26 26 if (Ndel == 0) { 27 27 fprintf (stderr, "SUCCESS\n"); 28 close_db (); 28 29 exit (0); 29 30 } 30 31 31 32 /* create new data list */ 32 ALLOCATE (subset, DetReg, Nimage);33 Nsubset = 0;34 f or (i = 0; i < Nimage; i++) {35 if (keep[i]) {36 subset[Nsubset] = image[i];37 Nsubset ++;38 }33 Nsubset = Nimage - Ndel; 34 ALLOCATE (subset, DetReg, MAX (1, Nsubset)); 35 fprintf (stderr, "keeping %d images\n", Nsubset); 36 for (j = i = 0; i < Nimage; i++) { 37 if (!keep[i]) continue; 38 subset[j] = image[i]; 39 j ++; 39 40 } 40 41 42 free (keep); 43 free (image); 41 44 set_images (subset, Nsubset); 42 45 43 46 save_db (); 44 close_db ();45 46 47 fprintf (stderr, "SUCCESS\n"); 47 48 exit (0); -
trunk/Ohana/src/imregister/imreg/SetSignals.c
r2802 r2823 93 93 94 94 /* send signal to remote machine */ 95 if (!rconnect (machine, "/usr/bin/rsh", &rsock, &wsock)) {95 if (!rconnect (machine, CONNECT, &rsock, &wsock)) { 96 96 fprintf (stderr, "can't make connection to machine %s to kill process %d\n", machine, pid); 97 97 exit (1); … … 100 100 write (wsock, line, strlen (line)); 101 101 102 for (i = 0; i < 100; i++) {102 for (i = 0; i < 300; i++) { 103 103 if (stat (pidfile, &filestat) == -1) exit (0); 104 104 usleep (100000); -
trunk/Ohana/src/imregister/imreg/args.imregister.c
r2803 r2823 72 72 sprintf (PIDFILE, "%s/.%s.pid", path, file); 73 73 74 /* create db.log and db.bfr */ 75 sprintf (TempDB, "%s.bfr", ImageDB); 76 sprintf (LogFile, "%s.log", ImageDB); 77 74 78 /* check for daemon mode */ 75 79 if ((N = get_argument (argc, argv, "-daemon"))) { -
trunk/Ohana/src/imregister/imreg/db.c
r2803 r2823 3 3 4 4 /* variables which describe the db */ 5 char *dBFile = (char *) NULL;6 5 FILE *f; 6 char *dBFile; 7 7 Header header; 8 8 Header theader; … … 12 12 int Nimage; 13 13 int lockstate; 14 int dbstate = LCK_UNLOCK; 14 int dbstate; 15 16 void init_db () { 17 f = NULL; 18 dBFile = NULL; 19 header.buffer = NULL; 20 matrix.buffer = NULL; 21 theader.buffer = NULL; 22 table.buffer = NULL; 23 table.header = &theader; 24 image = NULL; 25 Nimage = 0; 26 lockstate = LCK_EMPTY; 27 dbstate = LCK_UNLOCK; 28 } 15 29 16 30 int set_db (char *filename) { … … 29 43 30 44 int Nbytes; 31 char *data;32 45 33 46 /* assign pointers to new data block */ 34 free (image);35 47 Nimage = Nnew; 36 48 image = new; 49 if (image == NULL) Nnew = 0; 37 50 38 51 /* update header, table structures */ 39 52 fits_modify (table.header, "NAXIS2", "%d", 1, Nnew); 40 53 table.header[0].Naxis[1] = Nnew; 54 table.buffer = (char *) image; 55 56 /* add padding space to buffer */ 41 57 Nbytes = fits_matrix_size (table.header); 42 43 /* add padding space to buffer */ 44 data = (char *) image; 45 REALLOCATE (data, char, Nbytes); 46 image = (RegImage *) data; 47 48 table.buffer = (char *) image; 58 if (Nbytes > 0) { 59 REALLOCATE (table.buffer, char, Nbytes); 60 image = (RegImage *) table.buffer; 61 } 49 62 table.size = Nbytes; 50 63 … … 67 80 f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate); 68 81 if (dbstate == LCK_EMPTY) return (0); 82 69 83 if (f == (FILE *) NULL) { 70 84 fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile); … … 73 87 74 88 /* init & load in table data */ 75 table.header = &theader;76 89 if (!fits_fread_header (f, &header)) escape (UNLOCK, "ERROR: can't read primary header"); 77 90 if (!fits_fread_matrix (f, &matrix, &header)) escape (UNLOCK, "ERROR: can't read primary matrix"); … … 104 117 if (!fits_fwrite_table (f, &table)) escape (LOCK, "ERROR: can't update db"); 105 118 106 fits_free_header (&header);107 fits_free_matrix (&matrix);108 fits_free_header (&theader);109 119 fits_free_table (&table); 110 111 fclearlockfile (dBFile, f, lockstate, &dbstate); 120 close_db (); 121 112 122 return (TRUE); 113 123 } … … 149 159 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't update db"); 150 160 151 fits_free_header (&header); 152 fits_free_matrix (&matrix); 153 fits_free_header (&theader); 161 fits_free_table (&table); 154 162 fits_free_vtable (&vtable); 155 fits_free_table (&table);156 157 fclearlockfile (dBFile, f, lockstate, &dbstate);158 return (TRUE); 159 } 160 163 close_db (); 164 165 return (TRUE); 166 } 167 168 /* add new entries to db, close db */ 161 169 int append_db (RegImage *new, int Nnew) { 162 170 … … 168 176 ConvertStruct ((char *) new, sizeof (RegImage), Nnew, "regimage"); 169 177 fits_vadd_rows (&vtable, (char *) new, Nnew, sizeof(RegImage)); 178 Nimage = theader.Naxis[1]; 170 179 171 180 /* write subset to file */ … … 176 185 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't append to db"); 177 186 178 fits_free_header (&header); 179 fits_free_matrix (&matrix); 180 fits_free_header (&theader); 187 fits_free_table (&table); 181 188 fits_free_vtable (&vtable); 182 183 fclearlockfile (dBFile, f, lockstate, &dbstate); 189 close_db (); 190 184 191 return (TRUE); 185 192 } … … 201 208 int close_db () { 202 209 203 if (dbstate == LCK_EMPTY) return (TRUE); 204 205 fits_free_header (&header); 206 fits_free_matrix (&matrix); 207 fits_free_header (&theader); 208 /* fits_free_table (&table); */ 209 210 if (dbstate == LCK_UNLOCK) return (TRUE); 211 fclearlockfile (dBFile, f, lockstate, &dbstate); 212 return (TRUE); 213 } 214 215 int close_lock_db () { 216 217 if (dbstate == LCK_EMPTY) return (TRUE); 218 210 /* these are safe even if db is empty */ 219 211 fits_free_header (&header); 220 212 fits_free_matrix (&matrix); 221 213 fits_free_header (&theader); 222 214 /* don't free table: db data may still be used */ 223 /* fits_free_table (&table); */ 224 225 if ( dbstate == LCK_UNLOCK) return (TRUE);226 fclearlockfile (dBFile, f, LCK_XCLD, &dbstate); 215 216 fclearlockfile (dBFile, f, lockstate, &dbstate); 217 if ((Nimage == 0) && (lockstate != LCK_SOFT)) unlink (dBFile); 218 227 219 return (TRUE); 228 220 } -
trunk/Ohana/src/imregister/imreg/delete.c
r70 r2823 5 5 6 6 int i, j; 7 int *keep, N bad, Nimage, Nsubset;7 int *keep, Ndel, Nimage, Nsubset; 8 8 RegImage *image, *subset; 9 9 … … 14 14 fprintf (stderr, "total of %d images\n", Nimage); 15 15 16 N bad= 0;16 Ndel = 0; 17 17 for (i = 0; i < Nmatch; i++) { 18 18 j = match[i]; 19 19 if (j == -1) continue; 20 20 keep[j] = FALSE; 21 N bad++;21 Ndel ++; 22 22 } 23 fprintf (stderr, "delete %d images\n", N bad);23 fprintf (stderr, "delete %d images\n", Ndel); 24 24 25 Nsubset = Nimage - Nbad; 25 if (Ndel == 0) { 26 fprintf (stderr, "SUCCESS\n"); 27 close_db (); 28 exit (0); 29 } 30 31 /* create new data list */ 32 Nsubset = Nimage - Ndel; 26 33 ALLOCATE (subset, RegImage, MAX (1, Nsubset)); 27 34 fprintf (stderr, "keeping %d images\n", Nsubset); … … 29 36 if (!keep[i]) continue; 30 37 subset[j] = image[i]; 31 /* this or memcpy ? */32 38 j++; 33 39 } 34 40 35 41 free (keep); 42 free (image); 36 43 set_images (subset, Nsubset); 37 44 -
trunk/Ohana/src/imregister/imreg/imregclient.c
r2803 r2823 6 6 FILE *f; 7 7 RegImage *image; 8 char *TempDB;9 8 int i, Nentry, Nslice, status, tmpint; 10 9 float *dtime; 11 12 ALLOCATE (TempDB, char, strlen (ImageDB) + 10);13 sprintf (TempDB, "%s.bfr", ImageDB);14 10 15 11 Nentry = 0; -
trunk/Ohana/src/imregister/imreg/rconnect.c
r76 r2823 63 63 /* try to get evidence connection is alive - wait upto a few seconds */ 64 64 status = -1; 65 for (i = 0; (i < 100) && (status == -1); i++) {65 for (i = 0; (i < 300) && (status == -1); i++) { 66 66 fcntl (*rsock, F_SETFL, O_NONBLOCK); 67 67 status = SockScan ("PTOLEMY STARTED", &fifo, *rsock); 68 if (!(i % 30)) fprintf (stderr, "."); 68 69 if (status == 0) { 69 70 fprintf (stderr, "socket closed unexpectedly\n"); … … 73 74 } 74 75 } 75 if (i == 100) {76 if (i == -1) { 76 77 fprintf (stderr, "timeout while connecting\n"); 77 78 close (*wsock); -
trunk/Ohana/src/imregister/include/detrend.h
r2803 r2823 102 102 103 103 int ModifySubset (Match *match, int Nmatch); 104 intDeleteSubset (Match *match, int Nmatch);104 void DeleteSubset (Match *match, int Nmatch); 105 105 int usage (); 106 106 Criteria *MosaicCriteria (Criteria base, char *filename, int *ncrit); -
trunk/Ohana/src/imregister/include/imregister.h
r2803 r2823 19 19 char TransDB[256]; 20 20 char ImPhotDB[256]; 21 char TempDB[256]; 22 char LogFile[256]; 23 char CONNECT[64]; 21 24 22 25 int NDetrendAltDB; -
trunk/Ohana/src/imregister/photreg/db.c
r2803 r2823 3 3 4 4 /* variables which describe the db */ 5 char *dBFile = (char *) NULL;6 5 FILE *f; 6 char *dBFile; 7 7 Header header; 8 8 Header theader; … … 12 12 int Nimage; 13 13 int lockstate; 14 int dbstate = LCK_UNLOCK; 15 static char *BinaryName = (char *) NULL; 14 int dbstate; 15 char *BinaryName = NULL; 16 17 void init_db () { 18 f = NULL; 19 dBFile = NULL; 20 header.buffer = NULL; 21 matrix.buffer = NULL; 22 theader.buffer = NULL; 23 table.buffer = NULL; 24 table.header = &theader; 25 image = NULL; 26 Nimage = 0; 27 lockstate = LCK_EMPTY; 28 dbstate = LCK_UNLOCK; 29 } 16 30 17 31 /* photreg vs transreg database selection */ … … 60 74 61 75 /* assign pointers to new data block */ 62 free (image);63 76 Nimage = Nnew; 64 77 image = new; 78 if (image == NULL) Nnew = 0; 65 79 66 80 /* update header, table structures */ 67 81 fits_modify (table.header, "NAXIS2", "%d", 1, Nnew); 68 82 table.header[0].Naxis[1] = Nnew; 83 table.buffer = (char *) image; 84 85 /* add padding space to buffer */ 69 86 Nbytes = fits_matrix_size (table.header); 70 71 /* add padding space to buffer */ 72 table.buffer = (char *) image; 73 REALLOCATE (table.buffer, char, Nbytes); 74 image = (PhotPars *) table.buffer; 87 if (Nbytes > 0) { 88 REALLOCATE (table.buffer, char, Nbytes); 89 image = (PhotPars *) table.buffer; 90 } 75 91 table.size = Nbytes; 76 92 … … 89 105 90 106 lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT; 107 header.buffer = matrix.buffer = theader.buffer = table.buffer = (char *) NULL; 91 108 92 109 if (dBFile == (char *) NULL) { … … 98 115 f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate); 99 116 if (dbstate == LCK_EMPTY) return (0); 117 100 118 if (f == (FILE *) NULL) { 101 119 fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile); … … 104 122 105 123 /* load in table data */ 106 table.header = &theader;107 124 if (!fits_fread_header (f, &header)) escape (UNLOCK, "ERROR: can't read primary header"); 108 125 if (!fits_fread_matrix (f, &matrix, &header)) escape (UNLOCK, "ERROR: can't read primary header"); … … 116 133 117 134 if (!ConvertStruct ((char *) image, sizeof (PhotPars), Nimage, "photpars")) 118 escape (UNLOCK, "ERROR: can't read primary header");135 escape (UNLOCK, "ERROR: can't convert data"); 119 136 120 137 return (1); … … 139 156 /* lock database */ 140 157 f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate); 158 if (dbstate == LCK_EMPTY) return (0); 159 141 160 if (f == (FILE *) NULL) { 142 161 fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile); 143 162 exit (1); 144 163 } 145 if (dbstate == LCK_EMPTY) return (0);146 164 147 165 /* load in table data */ 148 table.header = &theader;149 166 if (!fits_fread_header (f, &header)) escape (UNLOCK, "ERROR: can't read primary header"); 150 167 if (!fits_fread_matrix (f, &matrix, &header)) escape (UNLOCK, "ERROR: can't read primary header"); … … 195 212 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db"); 196 213 if (!fits_fwrite_table (f, &table)) escape (LOCK, "ERROR: can't update db"); 197 fclearlockfile (dBFile, f, lockstate, &dbstate); 214 215 fits_free_table (&table); 216 close_db (); 217 198 218 return (TRUE); 199 219 } … … 234 254 if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db"); 235 255 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't update db"); 236 fclearlockfile (dBFile, f, lockstate, &dbstate); 256 257 fits_free_table (&table); 258 fits_free_vtable (&vtable); 259 close_db (); 260 237 261 return (TRUE); 238 262 } … … 247 271 ConvertStruct ((char *) new, sizeof (PhotPars), Nnew, "photpars"); 248 272 fits_vadd_rows (&vtable, (char *) new, Nnew, sizeof(PhotPars)); 273 Nimage = theader.Naxis[1]; 249 274 250 275 /* write subset to file */ … … 255 280 if (!fits_fwrite_vtable (f, &vtable)) escape (LOCK, "ERROR: can't append to db"); 256 281 257 fclearlockfile (dBFile, f, lockstate, &dbstate); 282 fits_free_table (&table); 283 fits_free_vtable (&vtable); 284 close_db (); 285 258 286 return (TRUE); 259 287 } … … 274 302 275 303 int close_db () { 276 if (dbstate == LCK_UNLOCK) return (TRUE); 304 305 /* these are safe even if db is empty */ 306 fits_free_header (&header); 307 fits_free_matrix (&matrix); 308 fits_free_header (&theader); 309 /* don't free table: db data may still be used */ 310 277 311 fclearlockfile (dBFile, f, lockstate, &dbstate); 278 return (TRUE); 279 } 280 281 int close_lock_db () { 282 if (dbstate == LCK_UNLOCK) return (TRUE); 283 fclearlockfile (dBFile, f, LCK_XCLD, &dbstate); 312 if ((Nimage == 0) && (lockstate != LCK_SOFT)) unlink (dBFile); 313 284 314 return (TRUE); 285 315 } -
trunk/Ohana/src/imregister/photreg/delete.c
r90 r2823 5 5 6 6 int i, j; 7 int *keep, N bad, Nphotdata, Nsubset;7 int *keep, Ndel, Nphotdata, Nsubset; 8 8 PhotPars *photdata, *subset; 9 9 … … 14 14 fprintf (stderr, "total of %d photdata\n", Nphotdata); 15 15 16 N bad= 0;16 Ndel = 0; 17 17 for (i = 0; i < Nmatch; i++) { 18 18 j = match[i]; 19 19 if (j == -1) continue; 20 20 keep[j] = FALSE; 21 N bad++;21 Ndel ++; 22 22 } 23 fprintf (stderr, "delete %d photdata\n", N bad);23 fprintf (stderr, "delete %d photdata\n", Ndel); 24 24 25 Nsubset = Nphotdata - Nbad; 25 if (Ndel == 0) { 26 fprintf (stderr, "SUCCESS\n"); 27 close_db (); 28 exit (0); 29 } 30 31 /* create new data list */ 32 Nsubset = Nphotdata - Ndel; 26 33 ALLOCATE (subset, PhotPars, MAX (1, Nsubset)); 27 34 fprintf (stderr, "keeping %d photdata\n", Nsubset); … … 29 36 if (!keep[i]) continue; 30 37 subset[j] = photdata[i]; 31 /* this or memcpy ? */32 38 j++; 33 39 } 34 40 35 41 free (keep); 42 free (photdata); 36 43 set_images (subset, Nsubset); 37 44 -
trunk/Ohana/src/imregister/src/detregister.c
r3 r2823 1 1 # include "imregister.h" 2 2 # include "detrend.h" 3 static char *version = "detregister $Revision: 3. 0$";3 static char *version = "detregister $Revision: 3.1 $"; 4 4 5 5 int main (int argc, char **argv) { … … 16 16 SaveEntry (argv[1], &newdata, descriptor.imageID); 17 17 18 init_db (); 18 19 status = load_db (); 19 20 if (!status) { -
trunk/Ohana/src/imregister/src/detsearch.c
r2803 r2823 1 1 # include "imregister.h" 2 2 # include "detrend.h" 3 static char *version = "detsearch $Revision: 3. 2$";3 static char *version = "detsearch $Revision: 3.3 $"; 4 4 5 5 int main (int argc, char **argv) { … … 15 15 if (output.Criteria) PrintCriteria (); 16 16 17 init_db (); 17 18 status = load_db (); 18 19 if (!status) { -
trunk/Ohana/src/imregister/src/imregister.c
r2803 r2823 1 1 # include "imregister.h" 2 2 # include "imreg.h" 3 static char *version = "imregister $Revision: 3. 3$";3 static char *version = "imregister $Revision: 3.4 $"; 4 4 5 5 int main (int argc, char **argv) { … … 12 12 args (argc, argv); 13 13 image = iminfo (argv[1]); 14 init_db (); 14 15 15 16 Nnew = 0; -
trunk/Ohana/src/imregister/src/imregtable.c
r2455 r2823 1 1 # include "imregister.h" 2 2 # include "imreg.h" 3 static char *version = "imregtable $Revision: 3. 3$";3 static char *version = "imregtable $Revision: 3.4 $"; 4 4 5 5 int main (int argc, char **argv) { … … 16 16 ConfigCamera (); 17 17 ConfigFilter (); 18 init_db (); 18 19 19 20 if (argc != 2) { -
trunk/Ohana/src/imregister/src/imsearch.c
r2803 r2823 1 1 # include "imregister.h" 2 2 # include "imreg.h" 3 static char *version = "imsearch $Revision: 3. 2$";3 static char *version = "imsearch $Revision: 3.3 $"; 4 4 5 5 int main (int argc, char **argv) { … … 10 10 get_version (argc, argv, version); 11 11 args (argc, argv); 12 init_db (); 12 13 13 14 set_db (ImageDB); -
trunk/Ohana/src/imregister/src/imstatreg.c
r2803 r2823 1 1 # include "imregister.h" 2 2 # include "imreg.h" 3 static char *version = "imstatreg $Revision: 3.7 $"; 3 static char *version = "imstatreg $Revision: 3.8 $"; 4 # define DEBUG 0 4 5 5 6 int main (int argc, char **argv) { … … 7 8 RegImage *image; 8 9 int *match, Nmatch, status, child, Nentry; 9 char *TempDB, *LogFile;10 10 FILE *f; 11 11 12 12 get_version (argc, argv, version); 13 13 args (argc, argv); 14 init_db (); 14 15 15 16 if (CLIENT) imregclient (argv[1], argv[2], argv[3]); 16 17 17 /* create db.log and db.bfr */18 ALLOCATE (TempDB, char, strlen (ImageDB) + 10);19 sprintf (TempDB, "%s.bfr", ImageDB);20 ALLOCATE (LogFile, char, strlen (ImageDB) + 10);21 sprintf (LogFile, "%s.log", ImageDB);22 23 18 SetSignals (); 24 19 20 # if (!DEBUG) 25 21 /* fork in background */ 26 22 if ((child = fork ())) { … … 32 28 exit (0); 33 29 } 30 # endif 34 31 35 32 /* child process, check for process */ 36 33 ConfigPID (PIDFILE); 37 34 35 # if (!DEBUG) 38 36 /* redirect stderr, stdout to logfile */ 39 37 f = freopen (LogFile, "a", stdout); … … 44 42 f = freopen (LogFile, "a", stderr); 45 43 } 44 # else 45 f = stderr; 46 # endif 46 47 47 48 /* start loop */ 48 49 while (1) { 49 50 50 /* check / load temporary database */51 /* check / load / delete temporary database */ 51 52 set_db (TempDB); 52 53 status = load_db (); … … 58 59 image = get_images (&Nentry); 59 60 print_db_status ("temporary database read"); 60 close_lock_db (); 61 /* temp DB closed, hardlock on temp DB remains */ 62 61 status = set_images (NULL, 0); 62 close_db (); 63 print_db_status ("temporary database closed"); 64 63 65 /* check / load main database */ 64 66 set_db (ImageDB); … … 67 69 print_db_status ("main database empty"); 68 70 close_db (); 71 /* add temp data back to temp database */ 72 print_db_status ("resave temporary data"); 73 set_db (TempDB); 74 status = load_db (); 75 if (!status) { 76 print_db_status ("create new temporary database"); 77 create_db (); 78 } 79 append_db (image, Nentry); 80 print_db_status ("temporary database resaved"); 69 81 goto next; 70 82 } … … 75 87 print_db_status ("main database read"); 76 88 update_db (match, Nmatch); 77 free (match);78 free (image);89 if (match != NULL) free (match); 90 if (image != NULL) free (image); 79 91 80 92 /* clear temp DB hardlock */ -
trunk/Ohana/src/imregister/src/photreg.c
r2803 r2823 1 1 # include "imregister.h" 2 2 # include "photreg.h" 3 static char *version = "photreg $Revision: 1. 2$";3 static char *version = "photreg $Revision: 1.3 $"; 4 4 5 5 int main (int argc, char **argv) { … … 12 12 regargs (argc, argv, &newdata); 13 13 14 init_db (); 14 15 status = load_db (); 15 16 if (!status) { -
trunk/Ohana/src/imregister/src/photsearch.c
r2803 r2823 1 1 # include "imregister.h" 2 2 # include "photreg.h" 3 static char *version = "photsearch $Revision: 1. 2$";3 static char *version = "photsearch $Revision: 1.3 $"; 4 4 5 5 int main (int argc, char **argv) { … … 11 11 get_version (argc, argv, version); 12 12 args (argc, argv); 13 13 14 init_db (); 14 15 status = load_db (); 15 16 if (!status) {
Note:
See TracChangeset
for help on using the changeset viewer.
