Changeset 4864 for trunk/Ohana/src/addstar
- Timestamp:
- Aug 23, 2005, 8:55:22 PM (21 years ago)
- Location:
- trunk/Ohana/src/addstar
- Files:
-
- 1 added
- 7 edited
-
Makefile (modified) (1 diff)
-
include/addstar.h (modified) (3 diffs)
-
src/Shutdown.c (added)
-
src/addstar.c (modified) (4 diffs)
-
src/gimages.c (modified) (6 diffs)
-
src/image-db.c (modified) (2 diffs)
-
src/rfits.c (modified) (1 diff)
-
src/wimage.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/Makefile
r4805 r4864 61 61 $(SRC)/update_coords.$(ARCH).o \ 62 62 $(SRC)/wcatalog.$(ARCH).o \ 63 $(SRC)/ wimage.$(ARCH).o \63 $(SRC)/Shutdown.$(ARCH).o \ 64 64 $(SRC)/rfits.$(ARCH).o \ 65 65 $(SRC)/rtext.$(ARCH).o -
trunk/Ohana/src/addstar/include/addstar.h
r4826 r4864 138 138 Stars *getgsc PROTO((GSCRegion *patch, int *NSTARS)); 139 139 Stars *getusno PROTO((GSCRegion *catstats, int *Nstars)); 140 Image *gimages PROTO(( Image *image, int *Npimage));140 Image *gimages PROTO((FITS_DB *db, Image *image, int *Npimage)); 141 141 Stars *grefcat PROTO((char *Refcat, GSCRegion *catstats, int *nstars)); 142 142 Stars *grefstars PROTO((char *file, int *Nstars)); … … 152 152 int load_pt_catalog PROTO((Catalog *catalog, GSCRegion *region)); /*** choose new name ***/ 153 153 void load_subpix PROTO(()); 154 void lock_image_db PROTO(( ));154 void lock_image_db PROTO((FITS_DB *db, char *filename)); 155 155 int main PROTO((int argc, char **argv)); 156 156 void make_backup PROTO((char *filename)); … … 170 170 void sort_stars PROTO((Stars *stars, int N)); 171 171 int str_to_radec PROTO((double *ra, double *dec, char *str1, char *str2)); 172 void unlock_image_db PROTO(( Image *image));172 void unlock_image_db PROTO((FITS_DB *db)); 173 173 void update_coords PROTO((Average *average, Measure *measure, int *next)); 174 174 void wcatalog PROTO((Catalog *catalog)); 175 void wimage PROTO((Image *image)); 175 void wimage PROTO((FITS_DB *db, Image *image)); 176 void create_image_db PROTO((FITS_DB *db)); 177 void set_db PROTO((FITS_DB *in)); 176 178 177 179 void uppercase PROTO((char *string)); -
trunk/Ohana/src/addstar/src/addstar.c
r4854 r4864 8 8 GSCRegion *regions; 9 9 Catalog catalog; 10 FITS_DB db; 10 11 11 12 double dtime; … … 21 22 overlap = NULL; 22 23 regions = NULL; 24 set_db (&db); 23 25 24 26 if (SKYPROBE) load_subpix (); 25 27 26 /* we use the image table to lock db access */27 lock_image_db ( );28 /* we use the image table to lock db access -- perhaps this is not necessary?*/ 29 lock_image_db (&db, ImageCat); 28 30 29 31 switch (MODE) { … … 32 34 if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars); 33 35 regions = gregion_image (&image, &Nregions); 34 overlap = gimages (&image, &Noverlap); 36 /* lock_image_db (&db, ImageCat); */ 37 overlap = gimages (&db, &image, &Noverlap); 38 /* unlock_image_db (&db); */ 35 39 break; 36 40 case M_REFLIST: … … 75 79 76 80 if (CALIBRATE) { FindCalibration (&image); } 77 unlock_image_db (&image); 81 82 if (db.dbstate == LCK_EMPTY) { 83 create_image_db (&db); 84 } 85 86 ohana_memcheck (FALSE); 87 88 /* write out new image */ 89 if (MODE == M_IMAGE) { 90 dvo_image_addrows (&db, &image, 1); 91 SetProtect (TRUE); 92 dvo_image_update (&db, VERBOSE); 93 SetProtect (FALSE); 94 } 95 ohana_memcheck (FALSE); 96 /* unlock_image_db (&db); */ 78 97 79 98 gettimeofday (&stop, NULL); -
trunk/Ohana/src/addstar/src/gimages.c
r4854 r4864 2 2 3 3 /* given image, find catalog images which overlap it */ 4 Image *gimages ( Image *image, int *Npimage) {4 Image *gimages (FITS_DB *db, Image *image, int *Npimage) { 5 5 6 int i, j, k, Nimage, addtolist, size, dbstate; 7 int NTIMAGE, Ntimage, ntimage; 8 int NPIMAGE, npimage; 6 int i, j, k, addtolist; 7 int NPIMAGE, npimage, Ntimage; 9 8 Image *timage, *pimage; 10 9 Coords tcoords; … … 12 11 double Xi[5], Yi[5], Xo[5], Yo[5]; /* image and original corners */ 13 12 double zeropt; 14 struct stat filestatus;15 FILE *f;16 17 FITS_DB *db;18 13 19 14 /* if image.db is opened successfully, f will not be NULL. … … 21 16 if image.db is not locked & opened successfully, we will not reach here! 22 17 */ 23 db = GetDB ();24 18 if (db[0].dbstate == LCK_EMPTY) { 25 19 *Npimage = 0; 26 20 return (NULL); 27 21 } 28 fseek (f, 0, SEEK_SET);29 22 30 if (!dvo_image_load (db, TRUE)) { 31 Shutdown ("can't read image catalog %s", ImageCat); 23 /* read entire db table (use block read eventually?) */ 24 if (!dvo_image_load (db, VERBOSE, FORCE_READ)) { 25 Shutdown ("can't read image catalog %s", db[0].filename); 32 26 } 33 timage = fits_table_get_Image (&db.ftable, &Ntimage); 34 /* timage represents the complete image table */ 27 timage = fits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped); 35 28 36 29 fits_scan (&db[0].header, "ZERO_PT", "%lf", 1, &zeropt); … … 80 73 BuildChipMatch (timage, Ntimage); 81 74 82 /* run through image table and search for overlaps */ 75 /* run through image table and search for overlaps 76 also define the vtable entries for the images we keep */ 77 83 78 for (i = 0; i < Ntimage; i++) { 84 79 … … 116 111 117 112 BuildChipMatch (pimage, npimage); 118 113 119 114 if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", npimage); 120 115 … … 134 129 we are now loading in the entire image db table into memory. 135 130 136 we will need to write out the new image with a vtable.137 131 */ -
trunk/Ohana/src/addstar/src/image-db.c
r4854 r4864 1 1 # include "addstar.h" 2 2 3 # define LOCK LCK_XCLD 3 void lock_image_db (FITS_DB *db, char *filename) { 4 4 5 /* file-pointer to Image.db table. if image db does not yet exist*/6 static FITS_DB db;5 /* lock the image catalog */ 6 check_permissions (filename); 7 7 8 FITS_DB *GetDB () { 9 return (&db);10 } 8 db[0].lockstate = LCK_XCLD; 9 db[0].timeout = 3600.0; 10 fits_db_init (db); 11 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)) { 12 if (!fits_db_lock (db, filename)) { 21 13 fprintf (stderr, "ERROR: can't lock image catalog\n"); 22 14 exit (1); … … 24 16 } 25 17 26 void unlock_image_db ( Image *image) {18 void unlock_image_db (FITS_DB *db) { 27 19 28 20 mode_t mode; 29 21 30 /* protect wimage from interrupt signals */ 31 if (MODE == M_IMAGE) { 32 SetProtect (TRUE); 33 wimage (image); 34 SetProtect (FALSE); 22 fprintf (stderr, "closing file\n"); 23 if (db[0].f == NULL) { 24 fprintf (stderr, "re-closing file??\n"); 35 25 } 36 37 fits_db_close (&db);26 fits_db_close (db); 27 db[0].f = NULL; 38 28 39 29 /* force permissions to 666 */ 40 30 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 41 chmod ( ImageCat, mode);31 chmod (db[0].filename, mode); 42 32 } 43 33 44 /* clean up open / locked ImageCat before shutting down */ 45 int Shutdown (char *format, ...) { 46 va_list argp; 47 char *formatplus; 48 49 ALLOCATE (formatplus, char, strlen(format)); 50 strcpy (formatplus, format); 51 strcat (formatplus, "\n"); 34 void create_image_db (FITS_DB *db) { 52 35 53 va_start (argp, format); 54 vfprintf (stderr, formatplus, argp); 55 free (formatplus); 56 va_end (argp); 36 if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat); 57 37 58 SetProtect (TRUE); 59 fits_db_close (&db); 60 fprintf (stderr, "ERROR: addstar halted\n"); 61 exit (1); 38 /* create new header */ 39 fits_init_header (&db[0].header); 40 41 if (!strcmp (CATMODE, "RAW")) { 42 /* make header a fake image */ 43 db[0].header.bitpix = 16; 44 db[0].header.Naxes = 2; 45 db[0].header.Naxis[0] = 1; 46 db[0].header.Naxis[1] = 1; 47 fits_create_header (&db[0].header); 48 } 49 50 if (!strcmp (CATMODE, "MEF") || !strcmp (CATMODE, "SPLIT")) { 51 fits_create_header (&db[0].header); 52 } 53 54 fits_create_matrix (&db[0].header, &db[0].matrix); 55 fits_table_set_Image (&db[0].ftable, NULL, 0); 56 57 /* assign Zero Point provided by first image in dB */ 58 fits_modify (&db[0].header, "ZERO_PT", "%lf", 1, ZeroPt); 59 fits_modify (&db[0].header, "NIMAGES", "%d", 1, 0); 62 60 } 61 -
trunk/Ohana/src/addstar/src/rfits.c
r4299 r4864 16 16 if (!fits_fread_ftable (f, &table, "SMPFILE")) goto escape; 17 17 18 smpdata = fits_table_get_SMPData (&table, &Nstars );18 smpdata = fits_table_get_SMPData (&table, &Nstars, NULL); 19 19 20 20 ALLOCATE (stars, Stars, Nstars); -
trunk/Ohana/src/addstar/src/wimage.c
r4854 r4864 2 2 3 3 /* add 1 image to image db */ 4 void wimage (Image *image) {4 void wimages (FITS_DB *db, Image *image, int Nimage) { 5 5 6 FILE *f; 7 int Nimages, status, offset, dbstate; 8 Header header; 6 int status, Nimages; 9 7 10 db = GetDB (); 11 fseek (f, 0, SEEK_SET); 8 /* set permissions somewhere ... 9 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 10 fchmod (ImageCat, mode); */ 12 11 13 if (dbstate == LCK_EMPTY) { 14 if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat); 15 if (!fits_read_header (ImageTemplate, &header)) { 16 fprintf (stderr, "ERROR: can't find template header %s\n", ImageTemplate); 17 exit (1); 18 } 19 /* assign Zero Point provided by first image in dB */ 20 fits_modify (&header, "ZERO_PT", "%lf", 1, ZeroPt); 21 fits_modify (&header, "NIMAGES", "%d", 1, 0); 22 } else { 23 if (!fits_load_header (f, &header)) { 24 fprintf (stderr, "ERROR: can't read image header %s\n", ImageCat); 25 exit (1); 26 } 27 } 28 12 /* adjust header */ 29 13 Nimages = 0; 30 fits_scan (& header, "NIMAGES", "%d", 1, &Nimages);14 fits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimages); 31 15 Nimages ++; 32 fits_modify (& header, "NIMAGES", "%d", 1, Nimages);16 fits_modify (&db[0].header, "NIMAGES", "%d", 1, Nimages); 33 17 34 /* position to begining of file to write header */ 35 fseek (f, 0, SEEK_SET); 36 status = Fwrite (header.buffer, 1, header.size, f, "char"); 37 if (status != header.size) { 38 fprintf (stderr, "ERROR: failed writing data to image header\n"); 39 exit (1); 18 fits_table_to_vtable (&db[0].ftable, &db[0].vtable, 0, 0); 19 for (i = 0; i < Nimage; i++) { 20 fits_vadd_rows (&db[0].vtable, (char *) image, 1, sizeof(Image)); 40 21 } 41 22 42 /* position to end of data array */ 43 offset = (Nimages - 1)*sizeof(Image) + header.size; 44 fseek (f, offset, SEEK_SET); 23 /* check that primary header and table header agree */ 24 if (Nimages != db[0].header.Naxis[1]) { 25 fprintf (stderr, "header / table length mismatch!\n"); 26 } 45 27 46 status = Fwrite (image, sizeof(Image), 1, f, "image"); 47 if (status != 1) { 28 SetProtect (TRUE); 29 status = dvo_image_update (db, VERBOSE); 30 SetProtect (FALSE); 31 32 if (!status) { 48 33 fprintf (stderr, "ERROR: failed writing data to image catalog\n"); 49 34 exit (1); … … 51 36 } 52 37 53 /* the image we add in this routine is always a new image. 54 We only need to do two things: 55 1) append the data for the image to the end of the file 56 2) update the NIMAGES field in the header (which means, read in header, re-write) 57 */ 38 /* add the new image to the image table: 39 - use the table header (from ftable) 40 - create an empty vtable 41 - add the new image to the end of the vtable 42 43 - write out the vtable, either as TEXT or FITS 44 * dvo_image_update performs the needed byte-swap on the image data 45 */
Note:
See TracChangeset
for help on using the changeset viewer.
