Changeset 4024
- Timestamp:
- May 25, 2005, 6:23:25 AM (21 years ago)
- Location:
- trunk/Ohana/src/imregister
- Files:
-
- 4 added
- 9 edited
-
Makefile (modified) (4 diffs)
-
base/fits_scan_nchar.c (modified) (1 diff)
-
imphot/ConfigInit.c (added)
-
imphot/args.c (modified) (4 diffs)
-
imphot/db_load.c (modified) (3 diffs)
-
imphot/dumpfits.c (modified) (4 diffs)
-
imphot/modify.c (added)
-
imphot/output.c (modified) (1 diff)
-
imphot/rfits.c (added)
-
imphot/rtext.c (modified) (3 diffs)
-
imphot/subset.c (modified) (1 diff)
-
include/imphot.h (added)
-
src/imphotsearch.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/imregister/Makefile
r3650 r4024 17 17 PHOTREG = $(HOME)/photreg 18 18 IMREG = $(HOME)/imreg 19 IMPHOT = $(HOME)/imphot 19 20 SPREG = $(HOME)/spreg 20 21 … … 33 34 photsearch photreg \ 34 35 cameraconfig filtnames \ 35 imphotsearch imphotmerge \ 36 imphotset 37 38 # spregister spsearch 36 imphotsearch 39 37 40 38 # program under development, not installed 41 DEVEL = spregister spsearch 39 DEVEL = spregister spsearch imphotmerge 40 41 IMPHOTOBJ = \ 42 $(IMPHOT)/args.$(ARCH).o \ 43 $(IMPHOT)/db_load.$(ARCH).o \ 44 $(IMPHOT)/dumpfits.$(ARCH).o \ 45 $(IMPHOT)/modify.$(ARCH).o \ 46 $(IMPHOT)/output.$(ARCH).o \ 47 $(IMPHOT)/rfits.$(ARCH).o \ 48 $(IMPHOT)/rtext.$(ARCH).o \ 49 $(IMPHOT)/subset.$(ARCH).o 42 50 43 51 IMOBJ = \ … … 116 124 SR = $(SPREG)/args.spregister.$(ARCH).o $(SPOBJ) $(BASEOBJ) 117 125 SS = $(SPREG)/args.spsearch.$(ARCH).o $(SPOBJ) $(BASEOBJ) 126 IP = $(IMPHOTOBJ) $(BASEOBJ) 118 127 119 128 $(SR) : $(INC)/spreg.h $(INC)/imregister.h … … 136 145 $(BIN)/spsearch.$(ARCH) : $(SRC)/spsearch.$(ARCH).o $(SS) ; $(CC) $^ -o $@ $(LFLAGS) 137 146 $(BIN)/spregister.$(ARCH) : $(SRC)/spregister.$(ARCH).o $(SR) ; $(CC) $^ -o $@ $(LFLAGS) 147 148 $(BIN)/imphotsearch.$(ARCH) : $(SRC)/imphotsearch.$(ARCH).o $(IP) ; $(CC) $^ -o $@ $(LFLAGS) 138 149 139 150 # dependancy rules for binary code ######################### -
trunk/Ohana/src/imregister/base/fits_scan_nchar.c
r3534 r4024 1 1 # include "imregister.h" 2 # include "imreg.h"3 2 4 3 /* scan and give a warning for missing entries */ -
trunk/Ohana/src/imregister/imphot/args.c
r4018 r4024 4 4 /* criteria struct is global */ 5 5 int args (int argc, char **argv) { 6 7 8 FILE *f;9 Header header;10 int i, j, status, N;11 char *dBFile, *timestr, *photstr;12 int Nimage, nimage, *index, Ntimes;13 unsigned long *tstart, *tstop;14 int VERBOSE, FORCE_READ, PHOTCODE, dbstate;15 Image *image;16 int PhotCodeSelect, Nin;17 int CodeSelect, Code;18 char *FitsOutput, *NameSelect;19 int NameSelectLength;20 struct stat filestatus;21 int size;22 6 23 7 int N; … … 32 16 33 17 /* interpret command-line arguments */ 34 if (!get_trange_arguments (&argc, argv, & tstart, &tstop, &Ntimes)) {18 if (!get_trange_arguments (&argc, argv, &criteria.tstart, &criteria.tstop, &criteria.Ntimes)) { 35 19 fprintf (stderr, "ERROR: syntax error\n"); 36 20 exit (1); … … 38 22 39 23 /* select by image photcode */ 40 PhotCodeSelect = FALSE;41 PHOTCODE= 0;24 criteria.PhotcodeSelect = FALSE; 25 criteria.photcode = 0; 42 26 if ((N = get_argument (argc, argv, "-photcode"))) { 43 27 remove_argument (N, &argc, argv); 44 if (!( PHOTCODE= GetPhotcodeCodebyName (argv[N]))) {28 if (!(criteria.photcode = GetPhotcodeCodebyName (argv[N]))) { 45 29 fprintf (stderr, "ERROR: photcode not found in photcode table\n"); 46 30 exit (1); 47 31 } 48 32 remove_argument (N, &argc, argv); 49 PhotCodeSelect = TRUE;33 criteria.PhotcodeSelect = TRUE; 50 34 } 51 35 52 36 /* string in image name */ 53 NameSelect = (char *) NULL; 54 NameSelectLength = 0; 37 criteria.NameSelect = FALSE; 55 38 if ((N = get_argument (argc, argv, "-name"))) { 56 39 remove_argument (N, &argc, argv); 57 NameSelect= strcreate (argv[N]);40 criteria.Name = strcreate (argv[N]); 58 41 remove_argument (N, &argc, argv); 59 NameSelectLength = strlen (NameSelect);42 criteria.NameSelect = TRUE; 60 43 } 61 44 62 45 /* string in image name */ 63 CodeSelect = FALSE;64 Code = 0;46 criteria.CodeSelect = FALSE; 47 criteria.Code = 0; 65 48 if ((N = get_argument (argc, argv, "-code"))) { 66 CodeSelect = TRUE;49 criteria.CodeSelect = TRUE; 67 50 remove_argument (N, &argc, argv); 68 Code = atoi (argv[N]);51 criteria.Code = atoi (argv[N]); 69 52 remove_argument (N, &argc, argv); 70 53 } 71 54 72 FitsOutput= (char *) NULL;55 options.table = (char *) NULL; 73 56 if ((N = get_argument (argc, argv, "-fits"))) { 74 57 remove_argument (N, &argc, argv); 75 FitsOutput= strcreate (argv[N]);58 options.table = strcreate (argv[N]); 76 59 remove_argument (N, &argc, argv); 60 } 61 62 options.bintable = (char *) NULL; 63 if ((N = get_argument (argc, argv, "-binfits"))) { 64 remove_argument (N, &argc, argv); 65 options.bintable = strcreate (argv[N]); 66 remove_argument (N, &argc, argv); 67 } 68 69 /* desired action */ 70 options.modify = FALSE; 71 options.ModifyValue = options.ModifyEntry = NULL; 72 if ((N = get_argument (argc, argv, "-flag"))) { 73 remove_argument (N, &argc, argv); 74 options.ModifyEntry = strcreate (argv[N]); 75 remove_argument (N, &argc, argv); 76 options.ModifyValue = strcreate (argv[N]); 77 remove_argument (N, &argc, argv); 78 options.modify = TRUE; 77 79 } 78 80 … … 93 95 exit (1); 94 96 } 97 } -
trunk/Ohana/src/imregister/imphot/db_load.c
r4018 r4024 1 # include "imregister.h" 2 # include "imphot.h" 1 3 2 /* load the complete db table into memory - load first extension, do not validate EXTNAME */ 4 enum {FITS, TEXT}; 5 3 6 int db_load (FITS_DB *db) { 7 8 int Nx, Ny, Naxis; 9 int mode, status; 4 10 5 11 /* database name must be set first */ … … 15 21 } 16 22 23 fits_scan (&db[0].header, "NAXIS", "%d", 1, &Naxis); 24 fits_scan (&db[0].header, "NAXIS1", "%d", 1, &Nx); 25 fits_scan (&db[0].header, "NAXIS2", "%d", 1, &Ny); 26 27 mode = FITS; 28 if ((Naxis == 2) && (Nx == 1106) && (Ny == 1024)) { 29 mode = TEXT; 30 } 31 17 32 /* how do we decide if it is text or fits? must examine header */ 18 33 if (FITS) { … … 23 38 return (TRUE); 24 39 } 25 26 /* load the complete db table into memory - load first extension, do not validate EXTNAME */27 int rfits (FITS_DB *db) {28 29 /* database name must be set first */30 if (db == NULL) {31 fprintf (stderr, "db handle is not set\n");32 return (FALSE);33 }34 if (!fits_fread_matrix (db[0].f, &db[0].matrix, &db[0].header)) {35 fprintf (stderr, "can't read primary matrix");36 return (FALSE);37 }38 if (!fits_fread_header (db[0].f, &db[0].theader)) {39 fprintf (stderr, "can't read table header");40 return (FALSE);41 }42 if (!fits_fread_ftable_data (db[0].f, &db[0].ftable)) {43 fprintf (stderr, "can't read table data");44 return (FALSE);45 }46 return (TRUE);47 }48 -
trunk/Ohana/src/imregister/imphot/dumpfits.c
r3650 r4024 1 int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep) { 1 # include "imregister.h" 2 # include "imphot.h" 3 4 /* write out complete binary FITS table in format of db */ 5 int DumpFitsBintable (char *filename, Image *image, int *match, int Nmatch) { 6 7 int i, j; 8 FILE *f; 9 Header header; 10 Matrix matrix; 11 Header theader; 12 FTable ftable; 13 Image *subset; 14 15 ALLOCATE (subset, Image, MAX (1, Nmatch)); 16 for (i = 0; i < Nmatch; i++){ 17 j = match[i]; 18 memcpy (&subset[i], &image[j], sizeof (Image)); 19 } 20 21 /* open file for output */ 22 f = fopen (filename, "w"); 23 if (f == NULL) { 24 fprintf (stderr, "ERROR: can't open output file %s\n", filename); 25 exit (1); 26 } 27 28 /* create primary header */ 29 fits_init_header (&header); 30 header.extend = TRUE; 31 fits_create_header (&header); 32 fits_create_matrix (&header, &matrix); 33 fits_print (&header, "NEXTEND", "%d", 1, 1); 34 35 ftable.header = &theader; 36 fits_table_set_Image (&ftable, subset, Nmatch); 37 38 fits_fwrite_header (f, &header); 39 fits_fwrite_matrix (f, &matrix); 40 fits_fwrite_Theader (f, &theader); 41 fits_fwrite_table (f, &ftable); 42 fclose (f); 43 exit (0); 44 } 45 46 int DumpFitsTable (char *filename, Image *image, int *match, int Nmatch) { 2 47 3 Header header , theader;48 Header header; 4 49 Matrix matrix; 5 FTable table; 6 Image *newdata; 50 Header theader; 51 FTable ftable; 52 Image *subset; 7 53 FILE *f; 8 54 char *startstr, *filtstr, *datestr, *line; … … 18 64 fits_print (&header, "NEXTEND", "%d", 1, 1); 19 65 66 /* the ASCII table is always a little harder than the binary: 67 * we need to build the data line a bit carefully 68 */ 69 20 70 /* create table header */ 21 71 fits_create_table_header (&theader, "TABLE", "ZPTS"); 22 72 23 73 /* add current date/time to header */ 24 74 str_to_time ("now", &tsecond); … … 37 87 fits_define_table_column (&theader, "F7.1", "SKY", "median sky flux", "counts"); 38 88 fits_define_table_column (&theader, "I6", "NSTAR", "Number of stars in image", "stars"); 39 89 40 90 /* define TNULL, TNVAL values */ 41 91 fits_modify (&theader, "TNULL1", "%s", 1, "NULL"); /* START_TIME */ … … 59 109 fits_modify (&theader, "TNVAL9", "%s", 1, "-2"); /* NSTAR */ 60 110 61 /* create table, add data values */ 62 fits_create_table (&theader, &table); 63 64 /* add selected data to table */ 65 for (i = 0; i < Nkeep; i++) { 66 newdata = &image[index[i]]; 67 startstr = sec_to_date (newdata[0].tzero); 68 filtstr = GetPhotcodeNamebyCode (newdata[0].source); 69 zp = 0.001*newdata[0].Mcal; 70 dzp = 0.001*newdata[0].dMcal; 71 72 XY_to_RD (&ra, &dec, 0.0, 0.0, &newdata[0].coords); 73 airmass = 0.001*newdata[0].secz; 74 sky = newdata[0].Myyyy + 0x8000; 111 /* add data to table */ 112 for (i = 0; i < Nmatch; i++) { 113 subset = &image[match[i]]; 114 startstr = sec_to_date (subset[0].tzero); 115 filtstr = GetPhotcodeNamebyCode (subset[0].source); 116 zp = 0.001*subset[0].Mcal; 117 dzp = 0.001*subset[0].dMcal; 118 XY_to_RD (&ra, &dec, 0.0, 0.0, &subset[0].coords); 119 airmass = 0.001*subset[0].secz; 120 sky = subset[0].Myyyy + 0x8000; 75 121 76 line = fits_table_print (&table, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, newdata[0].nstar);77 fits_add_rows (&table, line, 1, strlen(line));78 122 /* we should get an error here if we don't construct this line correctly */ 123 line = fits_table_print (&ftable, startstr, filtstr, zp, dzp, ra, dec, airmass, sky, subset[0].nstar); 124 fits_add_rows (&ftable, line, 1, strlen(line)); 79 125 free (line); 80 126 free (startstr); 81 127 } 82 128 83 129 /* write data to output file */ 84 130 f = fopen (filename, "w"); 85 131 if (f == (FILE *) NULL) { 86 132 fprintf (stderr, "Failure writing fits table\n"); 87 return (FALSE);133 exit (1); 88 134 } 89 135 fits_fwrite_header (f, &header); 90 136 fits_fwrite_matrix (f, &matrix); 91 137 fits_fwrite_Theader (f, &theader); 92 fits_fwrite_table (f, & table);138 fits_fwrite_table (f, &ftable); 93 139 fclose (f); 94 140 return (TRUE); 95 141 } 96 97 /*98 99 selection options:100 101 CCDSelect102 TypeSelect103 TimeSelect104 FilterSelect105 ExptimeSelect106 EntrySelect107 LabelSelect108 109 */ -
trunk/Ohana/src/imregister/imphot/output.c
r4018 r4024 1 int DumpFitsTable (char *filename, Image *image, int Nentry, int *index, int Nkeep); 1 # include "imregister.h" 2 # include "imphot.h" 2 3 4 int output (Image *image, int *match, int Nmatch) { 3 5 4 output () { 6 int status; 7 5 8 /* output the selected entries */ 6 if (FitsOutput != (char *) NULL) { 7 status = DumpFitsTable (FitsOutput, image, Nimage, index, Nin); 8 } else { 9 for (j = 0; j < Nin; j++) { 10 i = index[j]; 9 if (options.table != (char *) NULL) { 10 status = DumpFitsTable (options.table, image, match, Nmatch); 11 return (TRUE); 12 } 13 14 /* output the selected entries */ 15 if (options.bintable != (char *) NULL) { 16 status = DumpFitsBintable (options.bintable, image, match, Nmatch); 17 return (TRUE); 18 } 19 20 PrintSubset (image, match, Nmatch); 21 return (TRUE); 22 } 23 24 int PrintSubset (Image *image, int *match, int Nmatch) { 25 26 int i, j; 27 char *timestr, *photstr; 28 static char PhotError[] = "unknown"; 29 30 for (j = 0; j < Nmatch; j++) { 31 i = match[j]; 11 32 12 /* convert UNIX time to Elixir-style date string */13 timestr = sec_to_date (image[i].tzero);33 /* convert UNIX time to Elixir-style date string */ 34 timestr = sec_to_date (image[i].tzero); 14 35 15 /* convert photcode to filter name */16 photstr = GetPhotcodeNamebyCode (image[i].source);17 if (photstr == (char *) NULL) photstr = PhotError;36 /* convert photcode to filter name */ 37 photstr = GetPhotcodeNamebyCode (image[i].source); 38 if (photstr == (char *) NULL) photstr = PhotError; 18 39 19 fprintf (stdout, "%s %s %s %7.4f %7.4f %7.4f %5d %02x\n", image[i].name, photstr, timestr, 20 0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar, image[i].code); 21 free (timestr); 22 } 40 fprintf (stdout, "%s %s %s %7.4f %7.4f %7.4f %5d %02x\n", image[i].name, photstr, timestr, 41 0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar, image[i].code); 42 free (timestr); 23 43 } 44 return (TRUE); 24 45 } -
trunk/Ohana/src/imregister/imphot/rtext.c
r4018 r4024 1 # include "imregister.h" 2 # include "imphot.h" 1 3 2 4 int rtext (FITS_DB *db) { 5 6 int Nimage, size, nimage; 7 struct stat filestatus; 8 Image *image; 3 9 4 10 /* check that file size makes sense */ 5 11 Nimage = 0; 6 12 fits_scan (&db[0].header, "NIMAGES", "%d", 1, &Nimage); 7 if (stat (d BFile, &filestatus) == -1) {13 if (stat (db[0].filename, &filestatus) == -1) { 8 14 if (VERBOSE) fprintf (stderr, "ERROR: failed to get status of image catalog\n"); 9 15 exit (1); 10 16 } 11 size = Nimage*sizeof(Image) + header.size;17 size = Nimage*sizeof(Image) + db[0].header.size; 12 18 if (size != filestatus.st_size) { 13 19 int Ndata; 14 20 15 Ndata = (filestatus.st_size - header.size) / sizeof (Image);21 Ndata = (filestatus.st_size - db[0].header.size) / sizeof (Image); 16 22 if (VERBOSE) fprintf (stderr, "ERROR: image catalog has inconsistent size\n"); 17 23 if (VERBOSE) fprintf (stderr, "header: %d, data: %d\n", Nimage, Ndata); … … 27 33 db[0].ftable.header = &db[0].theader; 28 34 29 /* set theader size information to match loaded data */30 31 35 /* alloc, read images */ 32 36 ALLOCATE (image, Image, MAX (Nimage, 1)); … … 36 40 exit (1); 37 41 } 38 db[0].ftable.buffer = image; 42 db[0].ftable.buffer = (char *) image; 43 fits_modify (&db[0].theader, "NAXIS2", "%d", 1, Nimage); 44 db[0].theader.Naxis[1] = Nimage; 45 db[0].ftable.size = fits_matrix_size (&db[0].theader); 46 39 47 return (TRUE); 40 48 } -
trunk/Ohana/src/imregister/imphot/subset.c
r3650 r4024 1 # include "imregister.h" 2 # include "imphot.h" 1 3 2 subset () { 4 int *subset (Image *image, int Nimage, int *nsubset) { 5 6 int i, j, status; 7 int Nsubset, NameSelectLength; 8 int *index; 3 9 4 10 /* allocate space for reference lists */ 5 N in= 0;11 Nsubset = 0; 6 12 ALLOCATE (index, int, Nimage); 7 13 8 /* note that we are looking for overlap only with tstart */ 14 if (criteria.NameSelect) { 15 NameSelectLength = strlen(criteria.Name); 16 } 17 9 18 for (i = 0; i < Nimage; i++) { 10 for (j = 0, status = FALSE; !status && (j < Ntimes); j++) {11 status = (image[i].tzero >= tstart[j]) && (image[i].tzero <=tstop[j]);19 for (j = 0, status = FALSE; !status && (j < criteria.Ntimes); j++) { 20 status = (image[i].tzero >= criteria.tstart[j]) && (image[i].tzero <= criteria.tstop[j]); 12 21 } 13 if (!status && Ntimes) continue;14 if ( PhotCodeSelect && (image[i].source != PHOTCODE)) continue;15 if ( (NameSelect != (char *) NULL) && (strncasecmp (image[i].name, NameSelect, NameSelectLength))) continue;16 if ( CodeSelect && (image[i].code != Code)) continue;22 if (!status && criteria.Ntimes) continue; 23 if (criteria.PhotcodeSelect && (image[i].source != criteria.photcode)) continue; 24 if (criteria.CodeSelect && (image[i].code != criteria.Code)) continue; 25 if (criteria.NameSelect && strncasecmp (image[i].name, criteria.Name, NameSelectLength)) continue; 17 26 18 index[N in] = i;19 N in++;27 index[Nsubset] = i; 28 Nsubset ++; 20 29 } 30 *nsubset = Nsubset; 31 return (index); 21 32 } -
trunk/Ohana/src/imregister/src/imphotsearch.c
r4018 r4024 1 1 # include "imregister.h" 2 # include "imphot.h" 2 3 3 static char *version = "imphotsearch $Revision: 1. 6$";4 static char *version = "imphotsearch $Revision: 1.7 $"; 4 5 5 6 int main (int argc, char **argv) { 6 7 8 int Nmatch, Nimage; 9 int *match; 10 Image *image; 11 FITS_DB db; 12 7 13 get_version (argc, argv, version); 8 args ( &argc, argv);14 args (argc, argv); 9 15 10 db.lockstate = (o utput.modify || output.delete) ? LCK_HARD : LCK_SOFT;16 db.lockstate = (options.modify) ? LCK_HARD : LCK_SOFT; 11 17 db.timeout = 300.0; 12 18 fits_db_init (&db); … … 23 29 exit (1); 24 30 } 31 if (!options.modify) fits_db_close (&db); 25 32 26 i f (!output.modify && !output.delete) fits_db_close (&db);33 image = fits_table_get_Image (&db.ftable, &Nimage); 27 34 28 image = fits_table_get_RegImage (&db.ftable, &Nimage); 35 match = subset (image, Nimage, &Nmatch); 36 if (options.modify) ModifySubset (&db, image, Nimage, match, Nmatch); 29 37 30 subset (); 31 32 output (); 38 output (image, match, Nmatch); 33 39 34 40 if (VERBOSE) fprintf (stderr, "SUCCESS\n"); 35 41 exit (0); 42 } 36 43 37 }
Note:
See TracChangeset
for help on using the changeset viewer.
