Changeset 4854 for trunk/Ohana/src/addstar
- Timestamp:
- Aug 22, 2005, 10:08:38 AM (21 years ago)
- Location:
- trunk/Ohana/src/addstar/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/src/addstar.c
r4299 r4854 24 24 if (SKYPROBE) load_subpix (); 25 25 26 /* we use the image table to lock db access */ 26 27 lock_image_db (); 27 28 -
trunk/Ohana/src/addstar/src/gimages.c
r3649 r4854 9 9 Image *timage, *pimage; 10 10 Coords tcoords; 11 Header header;12 11 double r, d; 13 12 double Xi[5], Yi[5], Xo[5], Yo[5]; /* image and original corners */ … … 15 14 struct stat filestatus; 16 15 FILE *f; 17 16 17 FITS_DB *db; 18 18 19 /* if image.db is opened successfully, f will not be NULL. 19 20 if image.db is empty, dbstate will be LCK_EMPTY 20 21 if image.db is not locked & opened successfully, we will not reach here! 21 22 */ 22 f = GetDB (&dbstate);23 if (db state == LCK_EMPTY) {23 db = GetDB (); 24 if (db[0].dbstate == LCK_EMPTY) { 24 25 *Npimage = 0; 25 26 return (NULL); … … 27 28 fseek (f, 0, SEEK_SET); 28 29 29 /* read header */ 30 if (!fits_load_header (f, &header)) { 30 if (!dvo_image_load (db, TRUE)) { 31 31 Shutdown ("can't read image catalog %s", ImageCat); 32 32 } 33 timage = fits_table_get_Image (&db.ftable, &Ntimage); 34 /* timage represents the complete image table */ 33 35 34 fits_scan (& header, "ZERO_PT", "%lf", 1, &zeropt);36 fits_scan (&db[0].header, "ZERO_PT", "%lf", 1, &zeropt); 35 37 if (fabs (ZeroPt - zeropt) > 1e-4) { 36 38 Shutdown ("zero point in image (%f:%s) inconsistent with zero point in catalog (%f)", … … 70 72 } 71 73 72 /* advance to data segment */ 73 fseek (f, header.size, SEEK_SET); 74 75 Nimage = 0; 76 fits_scan (&header, "NIMAGES", "%d", 1, &Nimage); 77 /* check that file size makes sense */ 78 if (stat (ImageCat, &filestatus) == -1) { 79 Shutdown ("failed to get status of image catalog"); 80 } 81 size = Nimage*sizeof(Image) + header.size; 82 if (size != filestatus.st_size) { 83 int Ndata; 84 85 Ndata = (filestatus.st_size - header.size) / sizeof (Image); 86 fprintf (stderr, "error: image catalog has inconsistent size\n"); 87 fprintf (stderr, "header: %d images, data: %d images\n", Nimage, Ndata); 88 if (!FORCE_READ) Shutdown ("refuse to read image table"); 89 90 Nimage = MIN (Nimage, Ndata); 91 fprintf (stderr, "using %d images\n", Nimage); 92 } 93 94 /* kind of dangerous, see note below */ 95 NTIMAGE = MAX (MIN (Nimage, 1000), 1); 96 ALLOCATE (timage, Image, NTIMAGE); 97 74 /* pimage represents the subset of overlapping images */ 98 75 npimage = 0; 99 76 NPIMAGE = 20; 100 77 ALLOCATE (pimage, Image, NPIMAGE); 101 78 102 /* run through image table, reading images in blocks */ 103 for (Ntimage = 0; Ntimage < Nimage; Ntimage += ntimage) { 104 ntimage = Fread (timage, sizeof(Image), NTIMAGE, f, "image"); 105 if (ntimage == 0) Shutdown ("expected %d images, only found %d", Nimage, Ntimage); 106 BuildChipMatch (timage, ntimage); 79 /* setup links for mosaic WRP and DIS entries */ 80 BuildChipMatch (timage, Ntimage); 107 81 108 for (i = 0; i < ntimage; i++) { 82 /* run through image table and search for overlaps */ 83 for (i = 0; i < Ntimage; i++) { 109 84 110 /* if any of these images are WRP images, need to find matching DIS */111 if (!FindMosaicForImage (timage, ntimage, i)) continue;85 /* if any of these images are WRP images, need to find matching DIS */ 86 if (!FindMosaicForImage (timage, Ntimage, i)) continue; 112 87 113 addtolist = FALSE; 114 /* define image corners */ 115 Xi[0] = 0; Yi[0] = 0; 116 Xi[1] = timage[i].NX; Yi[1] = 0; 117 Xi[2] = timage[i].NX; Yi[2] = timage[i].NY; 118 Xi[3] = 0; Yi[3] = timage[i].NY; 119 Xi[4] = 0; Yi[4] = 0; /* so we can make a loop easily */ 120 /* transform to tcoords */ 121 for (j = 0; j < 5; j++) { 122 XY_to_RD (&r, &d, Xi[j], Yi[j], &timage[i].coords); 123 RD_to_XY (&Xi[j], &Yi[j], r, d, &tcoords); 88 addtolist = FALSE; 89 /* define image corners */ 90 Xi[0] = 0; Yi[0] = 0; 91 Xi[1] = timage[i].NX; Yi[1] = 0; 92 Xi[2] = timage[i].NX; Yi[2] = timage[i].NY; 93 Xi[3] = 0; Yi[3] = timage[i].NY; 94 Xi[4] = 0; Yi[4] = 0; /* so we can make a loop easily */ 95 /* transform to tcoords */ 96 for (j = 0; j < 5; j++) { 97 XY_to_RD (&r, &d, Xi[j], Yi[j], &timage[i].coords); 98 RD_to_XY (&Xi[j], &Yi[j], r, d, &tcoords); 99 } 100 /* check if any edges cross */ 101 /* not every robust - images must be close in size */ 102 for (j = 0; (j < 4) && !addtolist; j++) { 103 for (k = 0; (k < 4) && !addtolist; k++) { 104 addtolist |= edge_check (&Xi[j], &Yi[j], &Xo[k], &Yo[k]); 124 105 } 125 /* check if any edges cross */ 126 /* not every robust - images must be close in size */ 127 for (j = 0; (j < 4) && !addtolist; j++) { 128 for (k = 0; (k < 4) && !addtolist; k++) { 129 addtolist |= edge_check (&Xi[j], &Yi[j], &Xo[k], &Yo[k]); 130 } 131 } 132 if (addtolist) { 133 pimage[npimage] = timage[i]; 134 npimage ++; 135 if (npimage == NPIMAGE) { 136 NPIMAGE += 20; 137 REALLOCATE (pimage, Image, NPIMAGE); 138 } 106 } 107 if (addtolist) { 108 pimage[npimage] = timage[i]; 109 npimage ++; 110 if (npimage == NPIMAGE) { 111 NPIMAGE += 20; 112 REALLOCATE (pimage, Image, NPIMAGE); 139 113 } 140 114 } … … 147 121 *Npimage = npimage; 148 122 return (pimage); 149 150 123 } 151 124 … … 158 131 159 132 we are not adding the matching DIS image to the table. 133 134 we are now loading in the entire image db table into memory. 135 136 we will need to write out the new image with a vtable. 160 137 */ -
trunk/Ohana/src/addstar/src/image-db.c
r3649 r4854 4 4 5 5 /* file-pointer to Image.db table. if image db does not yet exist */ 6 static FILE *f = (FILE *) NULL; 7 static int dbstate = LCK_UNLOCK; 6 static FITS_DB db; 8 7 9 FILE *GetDB (int *state) { 10 *state = dbstate; 11 return (f); 8 FITS_DB *GetDB () { 9 return (&db); 10 } 11 12 void lock_image_db () { 13 /* lock the image catalog */ 14 check_permissions (ImageCat); 15 16 db.lockstate = LCK_XCLD; 17 db.timeout = 3600.0; 18 fits_db_init (&db); 19 20 if (!fits_db_lock (&db, ImageCat)) { 21 fprintf (stderr, "ERROR: can't lock image catalog\n"); 22 exit (1); 23 } 24 } 25 26 void unlock_image_db (Image *image) { 27 28 mode_t mode; 29 30 /* protect wimage from interrupt signals */ 31 if (MODE == M_IMAGE) { 32 SetProtect (TRUE); 33 wimage (image); 34 SetProtect (FALSE); 35 } 36 37 fits_db_close (&db); 38 39 /* force permissions to 666 */ 40 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 41 chmod (ImageCat, mode); 12 42 } 13 43 … … 27 57 28 58 SetProtect (TRUE); 29 f clearlockfile (ImageCat, f, LOCK, &dbstate);59 fits_db_close (&db); 30 60 fprintf (stderr, "ERROR: addstar halted\n"); 31 61 exit (1); 32 62 } 33 34 void lock_image_db () {35 /* lock the image catalog */36 check_permissions (ImageCat);37 f = fsetlockfile (ImageCat, 3600.0, LOCK, &dbstate);38 if (f == NULL) {39 fprintf (stderr, "ERROR: can't lock image catalog\n");40 exit (1);41 }42 fseek (f, 0, SEEK_SET);43 }44 45 void unlock_image_db (Image *image) {46 47 mode_t mode;48 49 /* protect wimage from interrupt signals */50 if (MODE == M_IMAGE) {51 SetProtect (TRUE);52 wimage (image);53 SetProtect (FALSE);54 }55 56 fclearlockfile (ImageCat, f, LOCK, &dbstate);57 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;58 chmod (ImageCat, mode);59 } -
trunk/Ohana/src/addstar/src/wimage.c
r3361 r4854 1 1 # include "addstar.h" 2 2 3 /* add image to image db */3 /* add 1 image to image db */ 4 4 void wimage (Image *image) { 5 5 … … 8 8 Header header; 9 9 10 f = GetDB (&dbstate);10 db = GetDB (); 11 11 fseek (f, 0, SEEK_SET); 12 12
Note:
See TracChangeset
for help on using the changeset viewer.
