Changeset 3509
- Timestamp:
- Mar 24, 2005, 4:51:08 PM (21 years ago)
- Location:
- trunk/Ohana/src/imregister
- Files:
-
- 11 edited
-
Makefile (modified) (2 diffs)
-
base/misc.c (modified) (3 diffs)
-
base/parse_time.c (modified) (1 diff)
-
include/imregister.h (modified) (1 diff)
-
include/spreg.h (modified) (4 diffs)
-
spreg/delete.c (modified) (2 diffs)
-
spreg/match.c (modified) (2 diffs)
-
spreg/modify.c (modified) (2 diffs)
-
spreg/output.c (modified) (10 diffs)
-
src/spregister.c (modified) (1 diff)
-
src/spsearch.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/imregister/Makefile
r2823 r3509 20 20 21 21 INCS = -I$(INC) -I$(LINC) -I$(XINC) 22 LIBS = -L$(LLIB) -l FITS -lohana-lm22 LIBS = -L$(LLIB) -lohana -lFITS -lm 23 23 # CFLAGS = $(INCS) -Wall -Werror 24 24 CFLAGS = $(INCS) … … 63 63 64 64 SPOBJ = \ 65 $(SPREG)/db.$(ARCH).o \66 65 $(SPREG)/delete.$(ARCH).o \ 67 66 $(SPREG)/define.$(ARCH).o \ 68 $(SPREG)/spinfo.$(ARCH).o \69 67 $(SPREG)/match.$(ARCH).o \ 70 68 $(SPREG)/modify.$(ARCH).o \ 71 $(SPREG)/fits_scan_nchar.$(ARCH).o \72 69 $(SPREG)/output.$(ARCH).o \ 73 70 $(SPREG)/unique.$(ARCH).o \ 74 71 $(SPREG)/ConfigInit.$(ARCH).o \ 72 $(SPREG)/spinfo.$(ARCH).o \ 73 $(SPREG)/fits_scan_nchar.$(ARCH).o \ 75 74 $(SPREG)/showinfo.$(ARCH).o \ 76 75 $(BASEDIR)/misc.$(ARCH).o \ 76 $(BASEDIR)/version.$(ARCH).o \ 77 77 $(BASEDIR)/parse_time.$(ARCH).o \ 78 78 $(BASEDIR)/sort.$(ARCH).o -
trunk/Ohana/src/imregister/base/misc.c
r2803 r3509 319 319 */ 320 320 321 322 /* fseek with timeout - 0.5 sec */323 int Fseek (FILE *f, long offset, int whence) {324 325 int status, k;326 327 status = fseek (f, offset, whence);328 if (status == -1) {329 for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);330 if (status == -1) {331 return (0);332 }333 }334 return (1);335 }336 321 337 322 /* return values: … … 400 385 } 401 386 402 void make_backup (char *filename) {403 404 int status, cmode;405 struct stat filestat;406 char line[256];407 408 status = stat (filename, &filestat);409 if (status == 0) { /* file exists, make backup copy */410 sprintf (line, "cp %s %s~", filename, filename);411 status = system (line);412 if (status) {413 fprintf (stderr, "ERROR: unable to create %s~, exiting\n", filename);414 exit (0);415 }416 cmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;417 sprintf (line, "%s~", filename);418 chmod (line, cmode);419 }420 }421 422 387 int get_filter_arguments (int *argc, char **argv, int **Filt, int *Nfilt) { 423 388 … … 458 423 459 424 460 void get_version (int argc, char **argv, char *version) {461 462 int N;463 char *p, *q, *line;464 465 if (get_argument (argc, argv, "-version")) {466 467 N = strlen (version) + 2;468 line = (char *) malloc (N);469 bzero (line, N);470 471 p = strstr (version, "$Revision: ");472 if (p != (char *) NULL)473 p += strlen ("$Revision: ");474 else475 p = version;476 477 q = strstr (p, "$");478 if (q != (char *) NULL)479 N = q - p;480 else481 N = strlen (p);482 483 strncpy (line, p, N);484 485 fprintf (stderr, "%s\n", line);486 exit (2);487 }488 }489 490 425 /* replaces whitespace blocks with single . */ 491 426 void clean_spaces (char *line) { -
trunk/Ohana/src/imregister/base/parse_time.c
r2803 r3509 119 119 } 120 120 121 void uppercase (char *string) {122 123 int i;124 125 for (i = 0; i < strlen (string); i++) string[i] = toupper (string[i]);126 127 } -
trunk/Ohana/src/imregister/include/imregister.h
r3466 r3509 80 80 int str_to_time (char *line, unsigned long *second); 81 81 82 int Fseek (FILE *f, long offset, int whence);83 82 int get_trange_arguments (int *argc, char **argv, unsigned long **Tstart, unsigned long **Tstop, int *ntimes); 84 83 int get_filter_arguments (int *argc, char **argv, int **Filt, int *Nfilt); 85 84 86 void make_backup (char *filename);87 85 int parse_time (Header *header); 88 void uppercase (char *string);89 86 void sort (float *value, int N); 90 87 void dsort (double *value, int N); -
trunk/Ohana/src/imregister/include/spreg.h
r3491 r3509 1 1 # include <signal.h> 2 3 /*** fits_db test APIs ***/4 typedef struct {5 FILE *f;6 char *extname;7 int dbstate;8 int lockstat;9 Header header;10 Matrix matrix;11 Header theader;12 FTable ftable;13 } DB;14 15 DB *fits_db_init ();16 DB *fits_db_lock (DB *db, char *filename);17 int fits_db_load (DB *db);18 int fits_db_save (DB *db);19 int fits_db_free (DB *db);20 int fits_db_update (DB *db, VTable *vtable);21 int fits_db_close (DB *db);22 int fits_db_print_status (DB *db, char *message);23 int fits_db_escape (DB *db, char *message);24 25 /**** move to fitsio.h ***/26 2 27 3 enum { … … 42 18 SPSTATE_N 43 19 }; 44 45 /* structure for Image Registration Database */46 typedef struct {47 float ra, dec;48 float exptime;49 float airmass;50 51 float Ws, We, dW;52 53 int Nspec;54 55 unsigned long int obstime;56 unsigned long int regtime;57 58 char mode; /* MEF, SINGLE, SPLIT */59 char state; /* MEF, SINGLE, SPLIT */60 char flag; /* image status flags */61 char extra[13];62 63 char pathname[64];64 char filename[32];65 char extname[16];66 67 char instrument[16];68 char telescope[16];69 char objname[16];70 71 } Spectrum; /* 328 bytes / image */72 20 73 21 struct { … … 132 80 133 81 int args (int argc, char **argv); 134 Spectrum *get_spectrums (int *N); 135 int set_spectrums (Spectrum *new, int Nnew); 136 int load_db (); 137 int save_db (); 138 int update_db (int *match, int Nmatch); 139 int append_db (Spectrum *new, int Nnew); 140 int create_db (); 141 int close_db (); 142 void DeleteSubset (int *match, int Nmatch); 143 Spectrum *spinfo (char *filename); 144 int *match_criteria (int *Nmatch); 145 int *match_spectrums (Spectrum *subset, int Nsubset, int *Nmatch); 146 void ModifySubset (int *match, int Nmatch); 82 int *match_criteria (Spectrum *spectrum, int Nspectrum, int *Nmatch); 83 int *unique_entries (Spectrum *spectrum, int Nspectrum, int *subset, int *Nmatch); 84 85 void ModifySubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch); 86 void DeleteSubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch); 87 void OutputSubset (Spectrum *spectrum, int Nspectrum, int *match, int Nmatch); 88 147 89 void SetOutputMode (char *mode); 148 void OutputSubset (int *match, int Nmatch);149 90 void DumpFitsBintable (char *filename, Spectrum *spectrum, int *match, int Nmatch); 150 91 void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch); 151 92 int PrintSubset (Spectrum *spectrum, int *match, int Nmatch); 152 93 int dump_data (Spectrum *spectrum, int Nspectrum); 94 95 Spectrum *spinfo (char *filename); 96 int *match_spectrums (Spectrum *subset, int Nsubset, int *Nmatch); 153 97 int SubmitSpectrums (Spectrum *spectrum); 154 98 int load_probes (char *filename, unsigned long tzero, int *wantprobe, double *values, int Nprobe); 155 99 int define_table (Header *header, Matrix *matrix, Header *theader, FTable *table); 156 100 void set_timezone (double dt); 157 158 void DumpCADCTable (char *filename, Spectrum *spectrum, int *match, int Nmatch);159 int *GetObsIDSubset (Spectrum *spectrum, int start, int *index, int *entry, int Nindex, int *Nsubset);160 int *GetUniqueObsID (Spectrum *spectrum, int *index, int *entry, int Nindex, int *Nmatch);161 void GetObsIDIndex (Spectrum *spectrum, int *match, int Nmatch, int **Index, int **Entry);162 double SigmaClipList (double *list, int N);163 double MosaicIQStats (Spectrum *spectrum, int *match, int Nmatch, MosaicRegion *region);164 MosaicLayout *CreateCFH12K ();165 MosaicLayout *CreateMegaCam ();166 int GetREFCCD (Spectrum *spectrum, int *index, int *entry, int Nindex, int start);167 101 168 102 void showinfo (Spectrum *spec); … … 173 107 int fits_scan_nchar (Header *header, int size, char *field, int N,...); 174 108 void warn_scan_nchar (Header *header, int size, char *field, int N, void *var); 175 176 int *unique_entries (int *subset, int *Nmatch); -
trunk/Ohana/src/imregister/spreg/delete.c
r3491 r3509 2 2 # include "spreg.h" 3 3 4 void DeleteSubset ( DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {4 void DeleteSubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) { 5 5 6 6 int i, j; … … 32 32 free (keep); 33 33 34 fits_table_set_Spectrum (&db[0].table, subset, Nsubset); 34 /** we may later want to pull this out and put it elsewhere **/ 35 /** free db[0].theader, db[0].table.buffer? **/ 36 fits_table_set_Spectrum (&db[0].ftable, subset, Nsubset); 35 37 fits_db_save (db); 38 fits_db_close (db); 39 fits_db_free (db); 40 41 fprintf (stderr, "SUCCESS\n"); 36 42 exit (0); 37 43 } -
trunk/Ohana/src/imregister/spreg/match.c
r3491 r3509 49 49 } 50 50 51 # if (0) 52 51 53 int *match_spectra (Spectrum *subset, int Nsubset, int *Nmatch) { 52 54 … … 82 84 return (match); 83 85 } 86 87 # endif -
trunk/Ohana/src/imregister/spreg/modify.c
r3491 r3509 2 2 # include "spreg.h" 3 3 4 void ModifySubset ( DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) {4 void ModifySubset (FITS_DB *db, Spectrum *spectrum, int Nspectrum, int *match, int Nmatch) { 5 5 6 6 int i, j, Nold; … … 38 38 } 39 39 40 fits_vtable_from_ftable (&vtable, &db[0].ftable, match, Nmatch); 40 /** we may later want to pull this out and put it elsewhere **/ 41 fits_vtable_from_ftable (&db[0].ftable, &vtable, match, Nmatch); 41 42 for (i = 0; i < Nmatch; i++) { 42 fits_convert_Spectrum ( vtable.buffer[i], 1);43 fits_convert_Spectrum ((Spectrum *) vtable.buffer[i], sizeof (Spectrum), 1); 43 44 } 44 45 fits_db_update (db, &vtable); 46 fits_db_close (db); 47 fits_db_free (db); 48 45 49 fprintf (stderr, "SUCCESS\n"); 46 50 exit (0); 47 48 51 } -
trunk/Ohana/src/imregister/spreg/output.c
r3492 r3509 3 3 4 4 static int RegTimeMode = FALSE; 5 static int PTstyle = FALSE;6 5 7 6 void SetOutputMode (char *mode) { … … 11 10 return; 12 11 } 13 if (!strcmp (mode, "PTstyle")) { 14 PTstyle = TRUE; 15 return; 16 } 17 12 return; 18 13 } 19 14 20 15 /* given a subset list, write out the selected spectra, if desired */ 21 void OutputSubset (Spectrum *spectr a, int Nspectra, int *match, int Nmatch) {16 void OutputSubset (Spectrum *spectrum, int Nspectra, int *match, int Nmatch) { 22 17 23 18 if (output.table != (char *) NULL) { … … 37 32 38 33 int i, j; 34 FILE *f; 39 35 Header header; 40 36 Matrix matrix; … … 58 54 59 55 /* create primary header */ 60 fits_init_header ( header);61 header [0].extend = TRUE;62 fits_create_header ( header);63 fits_create_matrix ( header,matrix);64 fits_print ( header, "NEXTEND", "%d", 1, 1);56 fits_init_header (&header); 57 header.extend = TRUE; 58 fits_create_header (&header); 59 fits_create_matrix (&header, &matrix); 60 fits_print (&header, "NEXTEND", "%d", 1, 1); 65 61 66 62 ftable.header = &theader; … … 70 66 fits_fwrite_matrix (f, &matrix); 71 67 fits_fwrite_Theader (f, &theader); 72 fits_fwrite_ ftable (f, &ftable);68 fits_fwrite_table (f, &ftable); 73 69 fclose (f); 74 70 … … 76 72 } 77 73 78 /* can the table definition here be autocoded as well?*/74 /* write out an ASCII table */ 79 75 void DumpFitsTable (char *filename, Spectrum *spectrum, int *match, int Nmatch) { 80 76 … … 82 78 char *obsstr, *regstr, *line, *datestr; 83 79 unsigned long tsecond; 80 FILE *f; 84 81 Header header, theader; 85 82 Matrix matrix; 86 FTable table;83 FTable ftable; 87 84 Spectrum *subset; 88 85 … … 94 91 fits_print (&header, "NEXTEND", "%d", 1, 1); 95 92 93 /* the ASCII table is always a little harder than the binary: 94 * we need to build the data line a bit carefully 95 */ 96 97 /* create an empty table which we will fill in by hand */ 96 98 ftable.header = &theader; 97 99 fits_table_set_SpectrumASCII (&ftable, NULL, 0); 98 100 99 /* the ASCII table is always a little harder than the binary100 need to build the data line a bit carefully101 */102 103 101 /* add data to table */ 104 102 for (i = 0; i < Nmatch; i++) { 105 103 subset = &spectrum[match[i]]; 106 obsstr = sec_to_date (subset[0].obstime);107 regstr = sec_to_date (subset[0].regtime);104 obsstr = sec_to_date (subset[0].obstime); 105 regstr = sec_to_date (subset[0].regtime); 108 106 109 107 /* we should get an error here if we don't construct this line correctly */ 110 line = fits_table_print (& table, subset[0].filename, subset[0].pathname, subset[0].instrument,108 line = fits_table_print (&ftable, subset[0].filename, subset[0].pathname, subset[0].instrument, 111 109 subset[0].telescope, subset[0].objname, subset[0].extname, 112 110 subset[0].ra, subset[0].dec, subset[0].exptime, subset[0].airmass, … … 115 113 subset[0].mode, subset[0].state, subset[0].flag); 116 114 117 fits_add_rows (& table, line, 1, strlen(line));115 fits_add_rows (&ftable, line, 1, strlen(line)); 118 116 free (line); 119 117 free (obsstr); … … 127 125 fits_modify (&theader, "DATE", "%s", 1, datestr); 128 126 129 fits_write_header (filename, &header); 130 fits_write_matrix (filename, &matrix); 131 fits_write_Theader (filename, &theader); 132 fits_write_table (filename, &table); 127 /* open file for output */ 128 f = fopen (filename, "w"); 129 if (f == NULL) { 130 fprintf (stderr, "ERROR: can't open output file %s\n", filename); 131 exit (1); 132 } 133 134 fits_fwrite_header (f, &header); 135 fits_fwrite_matrix (f, &matrix); 136 fits_fwrite_Theader (f, &theader); 137 fits_fwrite_table (f, &ftable); 138 fclose (f); 139 133 140 exit (0); 134 141 } -
trunk/Ohana/src/imregister/src/spregister.c
r2803 r3509 1 1 # include "imregister.h" 2 2 # include "spreg.h" 3 static char *version = "spregister $Revision: 1. 3$";3 static char *version = "spregister $Revision: 1.4 $"; 4 4 5 5 int main (int argc, char **argv) { 6 6 7 Spectrum *spectrum, *pspectrum; 8 int status, Nnew; 7 Spectrum *spectrum; 8 VTable vtable; 9 FITS_DB db; 9 10 10 11 get_version (argc, argv, version); 11 12 args (argc, argv); 13 12 14 spectrum = spinfo (argv[1]); 13 15 14 16 if (DUMP) showinfo (spectrum); 15 17 16 Nnew = 1;17 pspectrum = &spectrum[0];18 19 18 if (NoReg) exit (0); 20 19 21 set_db (SpectrumDB); 22 status = load_db (); 23 if (!status) { 24 create_db (); 20 db.lockstate = LCK_HARD; 21 db.timeout = 300.0; 22 23 fits_db_init (&db); 24 25 if (!fits_db_lock (&db, SpectrumDB)) { 26 fits_db_close (&db); 27 exit (1); 25 28 } 26 append_db (pspectrum, Nnew); 29 if (db.dbstate == LCK_EMPTY) { 30 /* create db header & matrix */ 31 } else { 32 if (!fits_db_load (&db)) { 33 fits_db_close (&db); 34 exit (1); 35 } 36 } 37 38 /** we may later want to pull this out and put it elsewhere **/ 39 fits_convert_Spectrum (spectrum, sizeof (Spectrum), 1); 40 fits_table_to_vtable (&db.ftable, &vtable, 0, 1); 41 fits_db_update (&db, &vtable); 42 fits_db_close (&db); 43 fits_db_free (&db); 44 27 45 exit (0); 28 46 } -
trunk/Ohana/src/imregister/src/spsearch.c
r3491 r3509 1 1 # include "imregister.h" 2 2 # include "spreg.h" 3 static char *version = "spsearch $Revision: 1. 2$";3 static char *version = "spsearch $Revision: 1.3 $"; 4 4 5 5 int main (int argc, char **argv) { 6 6 7 int status, Nmatch, Nspectra; 8 int *match; 9 DB *db; 10 Spectrum *spectra; 7 int Nmatch, Nspectrum, *match; 8 Spectrum *spectrum; 9 FITS_DB db; 11 10 12 11 get_version (argc, argv, version); 13 12 args (argc, argv); 14 13 15 lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;16 db = fits_db_init (lockstate);14 db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT; 15 db.timeout = 300.0; 17 16 18 if (!fits_db_lock (db, SpectrumDB)) { 19 fits_db_close (db); 17 fits_db_init (&db); 18 19 if (!fits_db_lock (&db, SpectrumDB)) { 20 fits_db_close (&db); 20 21 exit (1); 21 22 } 22 23 23 if (!fits_db_load ( db)) {24 fits_db_close ( db);24 if (!fits_db_load (&db)) { 25 fits_db_close (&db); 25 26 exit (1); 26 27 } 27 if (!output.modify && !output.delete) fits_db_close (db);28 28 29 spectrum = fits_table_get_Spectrum (&db[0].table, &Nspectrum); 29 if (!output.modify && !output.delete) fits_db_close (&db); 30 31 spectrum = fits_table_get_Spectrum (&db.ftable, &Nspectrum); 30 32 31 match = match_criteria (spectr a, Nspectra, &Nmatch);32 match = unique_entries (spectr a, Nspectra, match, &Nmatch);33 match = match_criteria (spectrum, Nspectrum, &Nmatch); 34 match = unique_entries (spectrum, Nspectrum, match, &Nmatch); 33 35 34 if (output.modify) ModifySubset ( db, spectra, Nspectra, match, Nmatch);35 if (output.delete) DeleteSubset ( db, spectra, Nspectra, match, Nmatch);36 if (output.modify) ModifySubset (&db, spectrum, Nspectrum, match, Nmatch); 37 if (output.delete) DeleteSubset (&db, spectrum, Nspectrum, match, Nmatch); 36 38 37 OutputSubset (spectr a, Nspectra, match, Nmatch);39 OutputSubset (spectrum, Nspectrum, match, Nmatch); 38 40 39 41 exit (0);
Note:
See TracChangeset
for help on using the changeset viewer.
