Changeset 3376
- Timestamp:
- Mar 4, 2005, 2:48:42 PM (21 years ago)
- Location:
- trunk/Ohana/src/addstar
- Files:
-
- 1 added
- 26 edited
-
Makefile (modified) (3 diffs)
-
include/addstar.h (modified) (8 diffs)
-
src/ConfigInit.c (modified) (3 diffs)
-
src/RegionOps.c (modified) (6 diffs)
-
src/SetSignals.c (modified) (2 diffs)
-
src/addstar.c (modified) (3 diffs)
-
src/args.c (modified) (2 diffs)
-
src/conversions.c (modified) (1 diff)
-
src/find_matches.c (modified) (4 diffs)
-
src/get2mass.c (modified) (7 diffs)
-
src/getgsc.c (modified) (4 diffs)
-
src/getusno.c (modified) (2 diffs)
-
src/gimages.c (modified) (5 diffs)
-
src/greference.c (modified) (1 diff)
-
src/grefstars.c (modified) (1 diff)
-
src/gregion_image.c (modified) (1 diff)
-
src/gregion_match.c (modified) (3 diffs)
-
src/gregion_match_glob.c (modified) (1 diff)
-
src/gregion_patch.c (modified) (2 diffs)
-
src/gregion_star.c (modified) (2 diffs)
-
src/gztest.c (added)
-
src/image-db.c (modified) (5 diffs)
-
src/load_pt_catalog.c (modified) (2 diffs)
-
src/load_subpix.c (modified) (1 diff)
-
src/replace_match.c (modified) (1 diff)
-
src/sort_lists.c (modified) (5 diffs)
-
src/update_coords.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/Makefile
r3361 r3376 17 17 # 18 18 INCS = -I$(INC) -I$(LINC) -I$(XINC) 19 LIBS = -L$(LLIB) -lFITS -lohana -l m19 LIBS = -L$(LLIB) -lFITS -lohana -lz -lm 20 20 CFLAGS = $(INCS) 21 21 LFLAGS = $(LIBS) … … 24 24 $(SRC)/addstar.$(ARCH).o \ 25 25 $(SRC)/airmass.$(ARCH).o \ 26 $(SRC)/aregion.$(ARCH).o \27 26 $(SRC)/args.$(ARCH).o \ 28 27 $(SRC)/calibrate.$(ARCH).o \ … … 80 79 INSTALL = addstar 81 80 81 gztest : $(BIN)/gztest.$(ARCH) 82 $(BIN)/gztest.$(ARCH) : $(SRC)/gztest.$(ARCH).o 83 84 INSTALL = addstar 85 82 86 # dependancy rules for binary code ######################### 83 87 .PRECIOUS: %.$(ARCH).o -
trunk/Ohana/src/addstar/include/addstar.h
r3361 r3376 4 4 # include <sys/time.h> 5 5 # include <time.h> 6 # include <zlib.h> 6 7 7 8 /* used in find_matches, find_matches_refstars */ … … 12 13 /* grab named photcode */ 13 14 # define NAMED_PHOTCODE(CODE,NAME) \ 14 CODE = GetPhotcode byName (NAME); \15 CODE = GetPhotcodeCodebyName (NAME); \ 15 16 if (!CODE) { \ 16 17 fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", NAME); \ … … 47 48 char GSCFILE[256]; 48 49 char CATDIR[256]; 50 char TWO_MASS_DIR[256]; 51 char GSCDIR[256]; 52 char CDROM[256]; 49 53 double DEFAULT_RADIUS, NSIGMA, SNLIMIT; 50 54 double ZeroPt; … … 57 61 58 62 PhotCode *thiscode; 59 GSCRegion patch;63 GSCRegion UserPatch; 60 64 61 65 char DateKeyword[64]; … … 86 90 87 91 int main (int argc, char **argv); 88 int Shutdown ( );92 int Shutdown (char *message, ...); 89 93 void TrapSignal (int sig); 90 94 int SetSignals (); … … 122 126 void fsort (float *X, int N); 123 127 void fsort2 (float *X, float *Y, int N); 128 void sort_stars (Stars *stars, int N); 129 void sort_regions (GSCRegion *region, int N); 124 130 125 131 char *sec_to_date (time_t second); … … 147 153 Stars *get2mass (GSCRegion *patch, int *NSTARS); 148 154 TM_Region *get2mass_acc (GSCRegion *patch, int *nfiles); 149 Stars *get2mass_data ( char *filename, GSCRegion *patch, int *nstars);155 Stars *get2mass_data (TM_Region *region, GSCRegion *patch, int *nstars); 150 156 GSCRegion *gregion_stars (Stars *stars, int Nstars, int *Nregion); 151 157 Stars *grefstars (char *file, int *Nstars); … … 180 186 int replace_match (Average *average, Measure *measure, Stars *star); 181 187 FILE *GetDB (int *state); 182 int Shutdown ();183 188 void lock_image_db (); 184 189 void unlock_image_db (Image *image); -
trunk/Ohana/src/addstar/src/ConfigInit.c
r3339 r3376 26 26 XMIN = XMAX = YMIN = YMAX = 0; 27 27 ScanConfig (config, "NSIGMA", "%lf", 0, &NSIGMA); 28 ScanConfig (config, "XOVERSCAN", "%d", 0, &XOVERSCAN);29 ScanConfig (config, "YOVERSCAN", "%d", 0, &YOVERSCAN);30 ScanConfig (config, "ADDSTAR_XMIN", "%d", 0, &XMIN);31 ScanConfig (config, "ADDSTAR_XMAX", "%d", 0, &XMAX);32 ScanConfig (config, "ADDSTAR_YMIN", "%d", 0, &YMIN);33 ScanConfig (config, "ADDSTAR_YMAX", "%d", 0, &YMAX);28 ScanConfig (config, "XOVERSCAN", "%d", 0, &XOVERSCAN); 29 ScanConfig (config, "YOVERSCAN", "%d", 0, &YOVERSCAN); 30 ScanConfig (config, "ADDSTAR_XMIN", "%d", 0, &XMIN); 31 ScanConfig (config, "ADDSTAR_XMAX", "%d", 0, &XMAX); 32 ScanConfig (config, "ADDSTAR_YMIN", "%d", 0, &YMIN); 33 ScanConfig (config, "ADDSTAR_YMAX", "%d", 0, &YMAX); 34 34 35 ScanConfig (config, "IMAGE_CATALOG", "%s", 0, ImageCat); 36 ScanConfig (config, "IMAGE_CATALOG_TEMPLATE", "%s", 0, ImageTemplate); 37 ScanConfig (config, "CATALOG_TEMPLATE", "%s", 0, CatTemplate); 38 ScanConfig (config, "GSCFILE", "%s", 0, GSCFILE); 39 ScanConfig (config, "CATDIR", "%s", 0, CATDIR); 35 ScanConfig (config, "2MASS_DIR", "%s", 0, TWO_MASS_DIR); 36 ScanConfig (config, "GSCDIR", "%s", 0, GSCDIR); 37 ScanConfig (config, "USNO_CDROM", "%s", 0, CDROM); 38 39 ScanConfig (config, "IMAGE_CATALOG", "%s", 0, ImageCat); 40 ScanConfig (config, "IMAGE_CATALOG_TEMPLATE", "%s", 0, ImageTemplate); 41 ScanConfig (config, "CATALOG_TEMPLATE", "%s", 0, CatTemplate); 42 ScanConfig (config, "GSCFILE", "%s", 0, GSCFILE); 43 ScanConfig (config, "CATDIR", "%s", 0, CATDIR); 40 44 ScanConfig (config, "MIN_SN_FSTAT", "%lf", 0, &SNLIMIT); 41 ScanConfig (config, "PHOTCODE_FILE", "%s", 0, PhotCodeFile);45 ScanConfig (config, "PHOTCODE_FILE", "%s", 0, PhotCodeFile); 42 46 43 47 /* used by parse_time to find time-related keywords */ 44 ScanConfig (config, "DATE-KEYWORD", "%s", 0, DateKeyword);45 ScanConfig (config, "DATE-MODE", "%s", 0, DateMode);46 ScanConfig (config, "UT-KEYWORD", "%s", 0, UTKeyword);47 ScanConfig (config, "MJD-KEYWORD", "%s", 0, MJDKeyword);48 ScanConfig (config, "JD-KEYWORD", "%s", 0, JDKeyword);48 ScanConfig (config, "DATE-KEYWORD", "%s", 0, DateKeyword); 49 ScanConfig (config, "DATE-MODE", "%s", 0, DateMode); 50 ScanConfig (config, "UT-KEYWORD", "%s", 0, UTKeyword); 51 ScanConfig (config, "MJD-KEYWORD", "%s", 0, MJDKeyword); 52 ScanConfig (config, "JD-KEYWORD", "%s", 0, JDKeyword); 49 53 50 ScanConfig (config, "EXPTIME-KEYWORD", "%s", 0, ExptimeKeyword);51 ScanConfig (config, "AIRMASS-KEYWORD", "%s", 0, AirmassKeyword);52 ScanConfig (config, "CCDNUM-KEYWORD", "%s", 0, CCDNumKeyword);54 ScanConfig (config, "EXPTIME-KEYWORD", "%s", 0, ExptimeKeyword); 55 ScanConfig (config, "AIRMASS-KEYWORD", "%s", 0, AirmassKeyword); 56 ScanConfig (config, "CCDNUM-KEYWORD", "%s", 0, CCDNumKeyword); 53 57 54 58 ScanConfig (config, "ST-KEYWORD", "%s", 0, STKeyword); … … 57 61 58 62 if (!LoadPhotcodes (PhotCodeFile)) { 59 fprintf (stderr, "error loading photcode s\n");63 fprintf (stderr, "error loading photcode file %s\n", PhotCodeFile); 60 64 exit (1); 61 65 } … … 65 69 66 70 } 71 72 void GetConfig (char *config, char *field, char *format, int N, void *ptr) { 73 74 char *status; 75 76 status = ScanConfig (config, field, format, N, ptr); 77 if (status == NULL) { 78 fprintf (stderr, "error in config, cannot find %s\n", field); 79 exit (1); 80 } 81 return; 82 } -
trunk/Ohana/src/addstar/src/RegionOps.c
r3361 r3376 1 1 # include "addstar.h" 2 # define NBANDS 2 3 # define NBANDS 24 4 3 5 double DecBands[] = { 4 -90.0, -82.5, -75.0, -67.5, -60.0,5 -52.5, -45.0, -37.5, -30.0, -22.5,6 -15.0, -07.5, +00.0, +07.5, +15.0,7 +22.5, +30.0, +37.5, +45.0, +52.5,8 +60.0, +67.5, +75.0, +82.5, +90.06 -90.0, -82.5, -75.0, -67.5, -60.0, 7 -52.5, -45.0, -37.5, -30.0, -22.5, 8 -15.0, -07.5, +00.0, +07.5, +15.0, 9 +22.5, +30.0, +37.5, +45.0, +52.5, 10 +60.0, +67.5, +75.0, +82.5, +90.0 9 11 }; 10 12 11 13 char *DecNames[] = { 12 "S8230", "S7500", "S6730", "S6000", "S5230" 13 "S4500", "S3730", "S3000", "S2230", "S1500",14 "S0730", "S0000", "N0000", "N0730", "N1500",15 "N2230", "N3000", "N3730", "N4500", "N5230",16 "N6000", "N6730", "N7500", "N8230",14 "s8230", "s7500", "s6730", "s6000", "s5230", 15 "s4500", "s3730", "s3000", "s2230", "s1500", 16 "s0730", "s0000", "n0000", "n0730", "n1500", 17 "n2230", "n3000", "n3730", "n4500", "n5230", 18 "n6000", "n6730", "n7500", "n8230", 17 19 }; 18 20 19 21 GSCRegion *LoadRegions (int *nregions) { 20 22 23 int Nregions, i, N, NDec, Nx, Ny; 24 char buffer[28800], temp[50], file[256]; 25 double RA0, RA1, DEC0, DEC1, D0, D1; 26 FILE *f; 27 GSCRegion *regions; 21 28 Header header; 22 29 Header theader; 23 30 Matrix matrix; 24 31 FTable table; 25 26 char buffer[28800], temp[50], file[256];27 double RA0, RA1, DEC0, DEC1;28 int i, N, NDec, Nx, Ny;29 30 FILE *f;31 32 32 33 f = fopen (GSCFILE, "r"); … … 37 38 38 39 /* init & load in table data */ 39 if (!fits_fread_header (f, &header)) escape (UNLOCK, "ERROR: can't read primary header"); 40 if (!fits_fread_matrix (f, &matrix, &header)) escape (UNLOCK, "ERROR: can't read primary matrix"); 41 if (!fits_fread_ftable (f, &table, "REGIONS")) escape (UNLOCK, "ERROR: can't read table"); 40 table.header = &theader; 41 if (!fits_fread_header (f, &header)) Shutdown ("can't read primary header for GSC Region table"); 42 if (!fits_fread_matrix (f, &matrix, &header)) Shutdown ("can't read primary matrix for GSC Region table"); 43 if (!fits_fread_ftable (f, &table, "REGIONS")) Shutdown ("can't read GSC Region table"); 42 44 43 45 fits_scan (table.header, "NAXIS1", "%d", 1, &Nx); … … 45 47 46 48 Nregions = 0; 47 ALLOCATE (regions, GSCRegion, Ny );49 ALLOCATE (regions, GSCRegion, Ny + 2); /* allow room for N & S poles */ 48 50 49 51 /* pole region is artificial - not in table */ 50 52 sprintf (file, "%s/n8230/pole.cpt", CATDIR); 51 region [Nregions].DEC[0] = 86.25;52 region [Nregions].DEC[1] = 93.75;53 region [Nregions].RA[0] = 0.0;54 region [Nregions].RA[1] = 360.0;55 strcpy (region [Nregions].filename, file);53 regions[Nregions].DEC[0] = 86.25; 54 regions[Nregions].DEC[1] = 93.75; 55 regions[Nregions].RA[0] = 0.0; 56 regions[Nregions].RA[1] = 360.0; 57 strcpy (regions[Nregions].filename, file); 56 58 Nregions ++; 57 59 60 /* fill out GSCRegion structure */ 58 61 for (i = 0; i < Ny; i++) { 59 62 strncpy (temp, &table.buffer[i*48], 48); … … 76 79 77 80 /** convert DEC0, DEC1 to NBigDec **/ 78 NDec = -1; 79 for (N = 0; N < NBANDS; N++) { 80 if (DEC0 >= DecBand[N]) { 81 NDec = N; 82 break; 83 } 84 } 85 if (NDec < 0) { 86 fprintf (stderr, "programming / table error\n"); 87 exit (0); 88 } 81 NDec = FindDecBand (0.5*(DEC0 + DEC1), &D0, &D1); 82 if (NDec == -1) Shutdown ("programming / table error"); 89 83 90 84 temp[5] = 0; 91 sprintf (file, "%s/%s/%s.cpt", CATDIR, Dec 2Sections[NBigDec], &temp[1]);85 sprintf (file, "%s/%s/%s.cpt", CATDIR, DecNames[NDec], &temp[1]); 92 86 93 87 strcpy (regions[Nregions].filename, file); … … 100 94 } 101 95 102 int FindRegionByPoint (GSCRegion *regions, double ra, double dec, GSCRegion *gsc, int Ngsc) { 96 /* given dec value, find upper and lower bounds of enclosing dec band */ 97 int FindDecBand (double dec, double *DEC0, double *DEC1) { 98 99 int i; 100 101 for (i = 0; i < NBANDS; i++) { 102 if (DecBands[i + 0] > dec) continue; 103 if (DecBands[i + 1] <= dec) continue; 104 *DEC0 = DecBands[i+0]; 105 *DEC1 = DecBands[i+1]; 106 return (i); 107 } 108 return (-1); 109 } 110 111 /* note that region.DEC[0] is sorted, but not necessarily DEC[1] */ 112 int FindRegionDecBandStart (GSCRegion *region, int Nregion, double dec) { 113 114 int N, Nlo, Nhi; 115 double D0, D1; 116 117 /* D0, D1 are upper lower band boundaries */ 118 /* all regions in this band have DEC[0] >= D0 */ 119 N = FindDecBand (dec, &D0, &D1); 120 if (N == -1) Shutdown ("programming / table error"); 121 122 /* bracket value of interest */ 123 Nlo = 0; Nhi = Nregion; 124 while (Nhi - Nlo > 10) { 125 N = 0.5*(Nlo + Nhi); 126 if (region[N].DEC[0] < D0) { 127 Nlo = N; 128 } else { 129 Nhi = N; 130 } 131 } 132 /* Nlo - Nhi bracket the transition across dec */ 133 /* v[Nlo] < v <= v[Nhi] */ 134 135 /* find the last entry < dec */ 136 for (N = Nhi; N >= Nlo; N--) { 137 if (region[N].DEC[0] < D0) return (N); 138 } 139 return (-1); 140 /* this will fail if transition value is not in the data range */ 141 } 142 143 /* note that region.DEC[0] is sorted, but not necessarily DEC[1] */ 144 int FindRegionDecBandStop (GSCRegion *region, int Nregion, double dec) { 145 146 int N, Nlo, Nhi; 147 double D0, D1; 148 149 /* D0, D1 are upper lower band boundaries */ 150 /* all regions in this band have DEC[0] < D1 */ 151 N = FindDecBand (dec, &D0, &D1); 152 if (N == -1) Shutdown ("programming / table error"); 153 154 /* bracket value of interest */ 155 Nlo = 0; Nhi = Nregion; 156 while (Nhi - Nlo > 10) { 157 N = 0.5*(Nlo + Nhi); 158 if (region[N].DEC[0] > D1) { 159 Nhi = N; 160 } else { 161 Nlo = N; 162 } 163 } 164 /* Nlo - Nhi bracket the transition across dec */ 165 /* v[Nlo] <= v < v[Nhi] */ 166 167 /* find the last entry < dec */ 168 for (N = Nlo; N < Nhi; N++) { 169 if (region[N].DEC[0] > D1) return (N); 170 } 171 return (-1); 172 /* this will fail if transition value is not in the data range */ 173 } 174 175 int FindRegionByPoint (GSCRegion *region, double ra, double dec, GSCRegion *gsc, int Ngsc) { 176 177 int i, Ns; 103 178 104 179 Ns = FindRegionDecBandStart (gsc, Ngsc, dec); 180 if (Ns < 0) return (FALSE); 105 181 106 182 for (i = Ns; i < Ngsc; i++) { … … 115 191 } 116 192 117 int FindRegionDecBandStart (GSCRegion *region, int Nregion, double dec) {118 119 int N, Nlo, Nhi, N1, N2;120 121 /* bracket value of interest */122 Nlo = 0; Nhi = Nregion;123 while (Nhi - Nlo > 10) {124 N = 0.5*(Nlo + Nhi);125 if (region[N].DEC[0] < dec) {126 Nlo = N;127 } else {128 Nhi = N;129 }130 }131 /* Nlo - Nhi bracket the transition across dec */132 /* v[Nlo] < v <= v[Nhi] */133 134 /* find the last entry < dec */135 for (N = N2; N >= N1; N--) {136 if (region[N].DEC[0] < dec) return (N);137 }138 return (-1);139 /* this will fail if transition value is not in the data range */140 }141 142 int FindRegionDecBandStop (GSCRegion *region, int Nregion, double dec) {143 144 int N, Nlo, Nhi, N1, N2;145 146 /* bracket value of interest */147 Nlo = 0; Nhi = Nregion;148 while (Nhi - Nlo > 10) {149 N = 0.5*(Nlo + Nhi);150 if (region[N].DEC[1] > dec) {151 Nhi = N;152 } else {153 Nlo = N;154 }155 }156 /* Nlo - Nhi bracket the transition across dec */157 /* v[Nlo] <= v < v[Nhi] */158 159 /* find the last entry < dec */160 for (N = N1; N < N2; N++) {161 if (region[N].DEC[1] > dec) return (N);162 }163 return (-1);164 /* this will fail if transition value is not in the data range */165 }166 167 193 /* bracket search: 168 194 -
trunk/Ohana/src/addstar/src/SetSignals.c
r3339 r3376 5 5 6 6 void TrapSignal (int sig) { 7 fprintf (stderr, "trapped signal %d , exiting gracefully\n", sig);7 fprintf (stderr, "trapped signal %d\n", sig); 8 8 if (sig == 11) { 9 9 fprintf (stderr, "seg fault\n"); … … 15 15 return; 16 16 } 17 Shutdown ( );17 Shutdown ("halted by signal (trapped)"); 18 18 } 19 19 20 20 void SetProtect (int mode) { 21 21 Protect = mode; 22 if (Trapped && !Protect) Shutdown ( );22 if (Trapped && !Protect) Shutdown ("halted by signal (protect)"); 23 23 } 24 24 -
trunk/Ohana/src/addstar/src/addstar.c
r3361 r3376 32 32 break; 33 33 case M_REFCAT: 34 regions = gregion_patch (& patch, &Nregions);34 regions = gregion_patch (&UserPatch, &Nregions); 35 35 break; 36 36 } … … 44 44 switch (MODE) { 45 45 case M_IMAGE: 46 Nsubset = Nstars; 46 47 find_matches (®ions[i], stars, Nstars, &catalog, &image, overlap, Noverlap); 47 48 break; 48 49 case M_REFCAT: 49 stars = grefcat (argv[1], regions, &Nstars);50 stars = grefcat (argv[1], ®ions[i], &Nstars); 50 51 case M_REFLIST: 51 52 subset = find_subset (®ions[i], stars, Nstars, &Nsubset); … … 54 55 break; 55 56 } 56 save_pt_catalog (&catalog); 57 if (Nsubset == 0) { 58 unlock_catalog (&catalog); 59 } else { 60 save_pt_catalog (&catalog); 61 } 57 62 } 58 63 -
trunk/Ohana/src/addstar/src/args.c
r3361 r3376 37 37 /*** provide additional data ***/ 38 38 /* restrict to a portion of the sky? (REFCAT only) */ 39 patch.RA[0] = 0;40 patch.RA[1] = 360;41 patch.DEC[0] = -90;42 patch.DEC[1] = +90;39 UserPatch.RA[0] = 0; 40 UserPatch.RA[1] = 360; 41 UserPatch.DEC[0] = -90; 42 UserPatch.DEC[1] = +90; 43 43 if ((N = get_argument (argc, argv, "-region"))) { 44 44 remove_argument (N, &argc, argv); 45 patch.RA[0] = atof (argv[N]); 46 patch.RA[1] = atof (argv[N]); 47 patch.DEC[0] = atof (argv[N]); 48 patch.DEC[1] = atof (argv[N]); 45 UserPatch.RA[0] = atof (argv[N]); 46 remove_argument (N, &argc, argv); 47 UserPatch.RA[1] = atof (argv[N]); 48 remove_argument (N, &argc, argv); 49 UserPatch.DEC[0] = atof (argv[N]); 50 remove_argument (N, &argc, argv); 51 UserPatch.DEC[1] = atof (argv[N]); 52 remove_argument (N, &argc, argv); 49 53 } 50 54 /* override any header PHOTCODE values */ … … 125 129 126 130 if (argc != 2) { 127 fprintf (stderr, "USAGE: addstar (filename) [-dump] [-image] [-v] [-p photcode] [-accept] [-cal code1 code2]\n"); 131 fprintf (stderr, "USAGE: addstar (filename)\n"); 132 fprintf (stderr, "USAGE: addstar -cat (catalog)\n"); 133 fprintf (stderr, "USAGE: addstar -ref (filename)\n"); 134 fprintf (stderr, " cur: %s ", argv[0]); 135 for (i = 0; i < argc; i++) { fprintf (stderr, "%s ", argv[i]); } 136 fprintf (stderr, "\n"); 128 137 exit (2); 129 138 } -
trunk/Ohana/src/addstar/src/conversions.c
r3361 r3376 308 308 bzero (&now, sizeof(now)); 309 309 310 s canf (date, "%2d%2d%2d", &now.tm_year, &now.tm_mon, &now.tm_mday);310 sscanf (date, "%2d%2d%2d", &now.tm_year, &now.tm_mon, &now.tm_mday); 311 311 312 312 if (now.tm_year > 51) now.tm_year += 0; -
trunk/Ohana/src/addstar/src/find_matches.c
r3361 r3376 15 15 short int Mrel, *Mval; 16 16 17 /* photcode data */17 /* photcode data - must by of type DEP, (PRI, SEC) - probably should restrict to DEP */ 18 18 Nsecfilt = GetPhotcodeNsecfilt (); 19 Nsec = GetPhotcodeNsec (thiscode[0].code); 19 Nsec = (thiscode[0].type == PHOT_DEP) ? 20 GetPhotcodeNsec (thiscode[0].equiv) : 21 GetPhotcodeNsec (thiscode[0].code); 20 22 /* this function requires incoming stars to have the same photcode */ 21 23 … … 114 116 dY = Y1[i] - Y2[J]; 115 117 dR = dX*dX + dY*dY; 116 if (dR <RADIUS2) continue;118 if (dR > RADIUS2) continue; 117 119 118 120 Nmatch ++; … … 153 155 catalog[0].measure[Nmeas].theta = MIN ((255/360)*stars[N].df, NO_ERR); 154 156 157 /*** this should probably use the mag lookup functions - zeropoints are incorrectly applied ***/ 155 158 /* it is not valid to pass PRI/SEC/REF photcodes to this routine */ 156 159 /* check for entries in the secfilt lists */ … … 365 368 } 366 369 370 /* check if the catalog has changed? if no change, no need to write */ 367 371 catalog[0].Naverage = Nave; 368 372 catalog[0].Nmeasure = Nmeas; -
trunk/Ohana/src/addstar/src/get2mass.c
r3361 r3376 1 1 # include "addstar.h" 2 3 static short TM_J, TM_H, TM_K; 2 4 3 5 Stars *get2mass (GSCRegion *patch, int *NSTARS) { … … 7 9 Stars *refcat; 8 10 TM_Region *regions; 9 short int TM_J, TM_H, TM_K;10 11 11 12 NAMED_PHOTCODE (TM_J, "2MASS_J"); 12 13 NAMED_PHOTCODE (TM_H, "2MASS_H"); 13 14 NAMED_PHOTCODE (TM_K, "2MASS_K"); 15 if (thiscode == NULL) Shutdown ("photcode not specified"); 16 if (thiscode[0].code == TM_J) goto good_code; 17 if (thiscode[0].code == TM_H) goto good_code; 18 if (thiscode[0].code == TM_K) goto good_code; 19 Shutdown ("2MASS photcode not specified"); 14 20 21 good_code: 15 22 regions = get2mass_acc (patch, &Nregions); 16 23 … … 19 26 20 27 for (i = 0; i < Nregions; i++) { 21 refcat = get2mass_data ( regions[i].name, patch, &Nrefcat);28 refcat = get2mass_data (®ions[i], patch, &Nrefcat); 22 29 23 30 REALLOCATE (stars, Stars, MAX (1, Nstars + Nrefcat)); … … 34 41 35 42 /* watch for patch which cross 0,360 boundary */ 36 TM_Region *get2mass_acc (GSCRegion *patch, int *n files) {43 TM_Region *get2mass_acc (GSCRegion *patch, int *nregions) { 37 44 38 int Nregions45 int Nregions, NREGIONS, Nrec; 39 46 TM_Region *regions; 47 char accel[1024], line[128], filename[128]; 48 FILE *f; 49 double Rs, Re; 40 50 41 51 sprintf (accel, "%s/idr2.acc", TWO_MASS_DIR); 42 52 f = fopen (accel, "r"); 43 if (f == NULL) { 44 fprintf (stderr, "ERROR: can't read data from %s\n", file); 45 Shutdown (); 46 } 53 if (f == NULL) Shutdown ("can't read data from accelerator %s", accel); 47 54 48 55 Nregions = 0; … … 51 58 52 59 /* read in stars line-by-line */ 53 for (N = 0; scan_line (f, line) != EOF; N++) {60 while (scan_line (f, line) != EOF) { 54 61 stripwhite (line); 55 62 if (line[0] == 0) continue; 56 63 if (line[0] == '#') continue; 57 scanf (line, "%s %lf %lf %d", filename, &Rs, &Re, &Nrec); 64 sscanf (line, "%s %lf %lf %d", filename, &Rs, &Re, &Nrec); 65 Rs *= 15.0; 66 Re *= 15.0; 58 67 if (Rs > patch[0].RA[1]) continue; 59 68 if (Re < patch[0].RA[0]) continue; 60 s trcpy(regions[Nregions].filename, "%s/%s", TWO_MASS_DIR, filename);69 sprintf (regions[Nregions].filename, "%s/%s", TWO_MASS_DIR, filename); 61 70 regions[Nregions].RA[0] = Rs; 62 71 regions[Nregions].RA[1] = Re; … … 71 80 72 81 # define NBYTE 302 73 # define NLINE 10082 # define NLINE 30000 74 83 75 Stars *get2mass_data ( char *filename, GSCRegion *patch, int *nstars) {84 Stars *get2mass_data (TM_Region *region, GSCRegion *patch, int *nstars) { 76 85 77 int Nstars;86 int i, Nstars, NSTARS, Nbyte, Nline, Nval; 78 87 Stars *stars; 79 88 gzFile gf; 80 char buffer[NLINE*NBYTE]; 89 char *filename, buffer[NLINE*NBYTE], datestr[64]; 90 double RA, DEC, J, H, K, dJ, dH, dK; 91 e_time time; 92 double RA0, RA1, DEC0, DEC1; 81 93 94 RA0 = MAX (patch[0].RA[0], UserPatch.RA[0]); 95 RA1 = MIN (patch[0].RA[1], UserPatch.RA[1]); 96 DEC0 = MAX (patch[0].DEC[0], UserPatch.DEC[0]); 97 DEC1 = MIN (patch[0].DEC[1], UserPatch.DEC[1]); 98 99 filename = region[0].filename; 82 100 gf = gzopen (filename, "rb"); 83 if (gf == NULL) { 84 fprintf (stderr, "ERROR: can't read data from %s\n", file); 85 Shutdown (); 86 } 101 if (gf == NULL) Shutdown ("can't read 2mass data file: %s", filename); 87 102 88 103 Nstars = 0; … … 90 105 ALLOCATE (stars, Stars, NSTARS); 91 106 92 /* z_off_t gzseek (gzFile file, z_off_t offset, int whence); */ 107 /* don't bother to seek ahead : position is not sufficiently predictable 108 and gzseek is as expensive as gzread */ 109 /* 110 Noffset = region[0].Nrec * (patch[0].DEC[0] + 90) / 180.0; 111 gzseek (gf, Noffset * NBYTE, SEEK_SET); 112 Nbyte = gzread (gf, buffer, NLINE*NBYTE); 113 */ 93 114 94 115 while ((Nbyte = gzread (gf, buffer, NLINE*NBYTE)) != 0) { 95 96 if (Nbyte == -1) { 97 fprintf (stderr, "error reading from gzipped file %s\n", filename); 98 Shutdown (); 99 } 100 101 Nfrac = Nbyte % NBYTE; 102 if (Nfrac) { 103 fprintf (stderr, "error reading complete line from gzipped file %s\n", filename); 104 Shutdown (); 105 } 106 116 if (Nbyte == 0) Shutdown ("error reading from gzipped file %s", filename); 117 if (Nbyte == -1) Shutdown ("error reading from gzipped file %s", filename); 118 if (Nbyte % NBYTE) Shutdown ("error reading complete line from gzipped file %s", filename); 107 119 Nline = Nbyte / NBYTE; 108 120 121 /* skip past block not yet in range */ 122 sscanf (&buffer[NBYTE*(Nline - 1)], "%lf %lf", &RA, &DEC); 123 if (DEC < DEC0) continue; 124 109 125 for (i = 0; i < Nline; i++) { 110 Nval = scanf (&buffer[NBYTE*i + 0], "%lf %lf", &RA, &DEC); 111 if (RA < patch[0].RA[0]) continue; 112 if (RA > patch[0].RA[1]) continue; 113 if (DEC < patch[0].DEC[0]) continue; 114 if (DEC < patch[0].DEC[1]) continue; 126 127 dparse (&RA, 1, &buffer[NBYTE*i+ 0]); 128 dparse (&DEC, 2, &buffer[NBYTE*i+ 0]); 115 129 116 Nval += scanf (&buffer[NBYTE*i + 53], "%lf %lf", &J, &dJ); 117 Nval += scanf (&buffer[NBYTE*i + 72], "%lf %lf", &H, &dH); 118 Nval += scanf (&buffer[NBYTE*i + 91], "%lf %lf", &K, &dK); 119 Nval += scanf (&buffer[NBYTE*i + 164], "%s", datestr); 120 if (Nval != 9) { 121 fprintf (stderr, "error in 2mass data line\n"); 122 exit (1); 130 if (DEC > DEC1) goto finished; 131 if (DEC < DEC0) continue; 132 if (RA < RA0) continue; 133 if (RA > RA1) continue; 134 135 stars[Nstars].R = RA; 136 stars[Nstars].D = DEC; 137 stars[Nstars].t = short_date_to_sec (&buffer[NBYTE*i + 164]); 138 stars[Nstars].found = -1; 139 140 if (thiscode[0].code == TM_J) { 141 dparse (&J, 1, &buffer[NBYTE*i + 53]); 142 dparse (&dJ, 2, &buffer[NBYTE*i + 53]); 143 stars[Nstars].M = J; 144 stars[Nstars].dM = dJ; 145 stars[Nstars].code = TM_J; 123 146 } 124 125 time = short_date_to_set (datestr); 126 127 stars[Nstars].R = RA; 128 stars[Nstars].D = DEC; 129 stars[Nstars].M = J; 130 stars[Nstars].dM = dJ; 131 stars[Nstars].t = time; 132 stars[Nstars].code = TM_J; 147 if (thiscode[0].code == TM_H) { 148 dparse (&H, 1, &buffer[NBYTE*i + 72]); 149 dparse (&dH, 2, &buffer[NBYTE*i + 72]); 150 stars[Nstars].M = H; 151 stars[Nstars].dM = dH; 152 stars[Nstars].code = TM_H; 153 } 154 if (thiscode[0].code == TM_K) { 155 dparse (&K, 1, &buffer[NBYTE*i + 91]); 156 dparse (&dK, 2, &buffer[NBYTE*i + 91]); 157 stars[Nstars].M = K; 158 stars[Nstars].dM = dK; 159 stars[Nstars].code = TM_K; 160 } 133 161 Nstars ++; 134 135 stars[Nstars].R = RA; 136 stars[Nstars].D = DEC; 137 stars[Nstars].M = H; 138 stars[Nstars].dM = dH; 139 stars[Nstars].t = time; 140 stars[Nstars].code = TM_H; 141 Nstars ++; 142 143 stars[Nstars].R = RA; 144 stars[Nstars].D = DEC; 145 stars[Nstars].M = K; 146 stars[Nstars].dM = dK; 147 stars[Nstars].t = time; 148 stars[Nstars].code = TM_K; 149 Nstars ++; 150 151 CHECK_REALLOCATE (stars, Stars, NSTARS, Nstars - 2, 300); 152 } 153 } 162 CHECK_REALLOCATE (stars, Stars, NSTARS, Nstars, 300); 163 } 164 } 165 finished: 166 gzclose (gf); 154 167 155 168 *nstars = Nstars; 156 169 return (stars); 157 170 } 171 172 /* 173 Nval = sscanf (&buffer[NBYTE*i + 0], "%lf %lf", &RA, &DEC); 174 Nval += sscanf (&buffer[NBYTE*i + 53], "%lf %lf", &J, &dJ); 175 Nval += sscanf (&buffer[NBYTE*i + 72], "%lf %lf", &H, &dH); 176 Nval += sscanf (&buffer[NBYTE*i + 91], "%lf %lf", &K, &dK); 177 Nval += sscanf (&buffer[NBYTE*i + 164], "%s", datestr); 178 */ 158 179 159 180 /* this just scans along in the file. file is sorted by dec, so we -
trunk/Ohana/src/addstar/src/getgsc.c
r3361 r3376 4 4 # define DNSTARS 1000 5 5 6 static short GSC_M; 7 6 8 Stars *getgsc (GSCRegion *patch, int *NSTARS) { 7 9 8 10 int i, j, k, Ns, Ngsc, Nregions, Nstars; 9 Star Data*gsc;10 Star Data*stars;11 GSCRegion s*regions;12 short int GSC_M;11 Stars *gsc; 12 Stars *stars; 13 GSCRegion *regions; 14 char *tmp; 13 15 14 16 NAMED_PHOTCODE (GSC_M, "GSC_M"); 15 17 18 /* sort of sleaze way to get the right GSC files */ 19 tmp = strcreate (CATDIR); 20 strcpy (CATDIR, GSCDIR); 16 21 regions = gregion_patch (patch, &Nregions); 22 strcpy (CATDIR, tmp); 23 free (tmp); 17 24 18 25 Nstars = 0; … … 20 27 21 28 for (i = 0; i < Nregions; i++) { 22 gsc = rd_gsc (regions[i]. name, &Ngsc);29 gsc = rd_gsc (regions[i].filename, &Ngsc); 23 30 24 31 REALLOCATE (stars, Stars, MAX (1, Nstars + Ngsc)); … … 36 43 Stars *rd_gsc (char *filename, int *nstars) { 37 44 38 int i, NSTARS, Nstars, Nbytes, nbytes ;45 int i, NSTARS, Nstars, Nbytes, nbytes, Nline, Nbyte; 39 46 char *buffer; 40 47 FILE *f; … … 60 67 dparse (&stars[Nstars].R, 1, &buffer[Nbyte]); 61 68 dparse (&stars[Nstars].D, 2, &buffer[Nbyte]); 69 if (stars[Nstars].R < UserPatch.RA[0]) continue; 70 if (stars[Nstars].R > UserPatch.RA[1]) continue; 71 if (stars[Nstars].D < UserPatch.DEC[0]) continue; 72 if (stars[Nstars].D > UserPatch.DEC[1]) continue; 73 62 74 dparse (&stars[Nstars].M, 3, &buffer[Nbyte]); 63 stars[Nstars].dM = NO_ERR; 64 stars[Nstars].t = 0; 65 stars[Nstars].code = GSC_M; 75 stars[Nstars].dM = NO_ERR; 76 stars[Nstars].t = 0; 77 stars[Nstars].code = GSC_M; 78 stars[Nstars].found = -1; 66 79 Nstars ++; 67 80 CHECK_REALLOCATE (stars, Stars, NSTARS, Nstars, 1000); -
trunk/Ohana/src/addstar/src/getusno.c
r3361 r3376 24 24 short int USNO_RED, USNO_BLUE; 25 25 26 /* require photcode */ 26 27 NAMED_PHOTCODE (USNO_RED, "USNO_RED"); 27 28 NAMED_PHOTCODE (USNO_BLUE, "USNO_BLUE"); 29 if (thiscode == NULL) Shutdown ("photcode not specified"); 30 if (thiscode[0].code == USNO_RED) goto good_code; 31 if (thiscode[0].code == USNO_BLUE) goto good_code; 32 Shutdown ("USNO photcode not specified"); 33 good_code: 28 34 29 35 /* identify ra & dec range of interest */ 30 iRA0 = catstats[0].RA[0] * 360000.0; 31 iRA1 = catstats[0].RA[1] * 360000.0; 32 iDEC0 = (catstats[0].DEC[0] + 90.0) * 360000.0; 33 iDEC1 = (catstats[0].DEC[1] + 90.0) * 360000.0; 36 /* note: the use of UserPatch to restrict here limits general utility of function */ 37 iRA0 = MAX (catstats[0].RA[0], UserPatch.RA[0]) * 360000.0; 38 iRA1 = MIN (catstats[0].RA[1], UserPatch.RA[1]) * 360000.0; 39 iDEC0 = (MAX (catstats[0].DEC[0], UserPatch.DEC[0]) + 90.0) * 360000.0; 40 iDEC1 = (MIN (catstats[0].DEC[1], UserPatch.DEC[1]) + 90.0) * 360000.0; 34 41 35 42 /* data is organized in south-pole distance zones */ … … 116 123 117 124 bzero (&stars[Nusno], sizeof(Stars)); 118 stars[Nusno].R = buf[0]/360000.0; 119 stars[Nusno].D = buf[1]/360000.0 - 90.0; 120 stars[Nusno].M = fabs (0.1*(buf[2] - 1000*((int)(buf[2]/1000)))); 121 stars[Nusno].dM = NO_ERR; 122 stars[Nusno].t = 0; 123 stars[Nusno].code = USNO_RED; 124 /* r data */ 125 stars[Nusno].R = buf[0]/360000.0; 126 stars[Nusno].D = buf[1]/360000.0 - 90.0; 127 stars[Nusno].dM = NO_ERR; 128 stars[Nusno].t = 0; 129 stars[Nusno].found = -1; 130 131 /* one pass of addstar does either r or b */ 132 if (thiscode[0].code == USNO_RED) { 133 stars[Nusno].code = USNO_RED; 134 stars[Nusno].M = fabs (0.1*(buf[2] - 1000*((int)(buf[2]/1000)))); 135 } 136 if (thiscode[0].code == USNO_BLUE) { 137 stars[Nusno].code = USNO_BLUE; 138 stars[Nusno].M = fabs (0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000)); 139 } 125 140 Nusno ++; 126 stars[Nusno].R = buf[0]/360000.0; 127 stars[Nusno].D = buf[1]/360000.0 - 90.0; 128 stars[Nusno].M = fabs (0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000)); 129 stars[Nusno].dM = NO_ERR; 130 stars[Nusno].t = 0; 131 stars[Nusno].code = USNO_BLUE; 132 /* b data */ 133 Nusno ++; 134 135 CHECK_REALLOCATE (stars, Stars, NUSNO, Nusno-1, 5000); 141 CHECK_REALLOCATE (stars, Stars, NUSNO, Nusno, 5000); 136 142 } 137 143 free (buffer); -
trunk/Ohana/src/addstar/src/gimages.c
r3361 r3376 4 4 Image *gimages (Image *image, int *Npimage) { 5 5 6 int i, j, k, Nimage, addtolist, size ;6 int i, j, k, Nimage, addtolist, size, dbstate; 7 7 int NTIMAGE, Ntimage, ntimage; 8 8 int NPIMAGE, npimage; … … 14 14 double zeropt; 15 15 struct stat filestatus; 16 FILE *f; 16 17 17 f = GetDB (); 18 /* if image.db is opened successfully, f will not be NULL. 19 if image.db is empty, dbstate will be LCK_EMPTY */ 20 f = GetDB (&dbstate); 21 if (dbstate == LCK_EMPTY) { 22 *Npimage = 0; 23 return (NULL); 24 } 18 25 fseek (f, 0, SEEK_SET); 19 26 20 27 /* read header */ 21 28 if (!fits_load_header (f, &header)) { 22 if (VERBOSE) fprintf (stderr, "error: can't read image catalog %s\n", ImageCat); 23 Shutdown (); 29 Shutdown ("can't read image catalog %s", ImageCat); 24 30 } 25 31 26 32 fits_scan (&header, "ZERO_PT", "%lf", 1, &zeropt); 27 33 if (fabs (ZeroPt - zeropt) > 1e-4) { 28 fprintf (stderr, "error: zero point in image (%f:%s) inconsistent with zero point in catalog (%f)\n",34 Shutdown ("zero point in image (%f:%s) inconsistent with zero point in catalog (%f)", 29 35 ZeroPt, image[0].name, zeropt); 30 Shutdown ();31 36 } 32 37 … … 57 62 /* check that file size makes sense */ 58 63 if (stat (ImageCat, &filestatus) == -1) { 59 fprintf (stderr, "error: failed to get status of image catalog\n"); 60 Shutdown (); 64 Shutdown ("failed to get status of image catalog"); 61 65 } 62 66 size = Nimage*sizeof(Image) + header.size; … … 67 71 fprintf (stderr, "error: image catalog has inconsistent size\n"); 68 72 fprintf (stderr, "header: %d images, data: %d images\n", Nimage, Ndata); 69 if (!FORCE_READ) Shutdown ( );73 if (!FORCE_READ) Shutdown ("refuse to read image table"); 70 74 71 75 Nimage = MIN (Nimage, Ndata); … … 114 118 115 119 if (ntimage == 0) { 116 fprintf (stderr, "error: expected %d images, only found %d\n", Nimage, Ntimage); 117 Shutdown (); 120 Shutdown ("expected %d images, only found %d", Nimage, Ntimage); 118 121 } 119 122 } -
trunk/Ohana/src/addstar/src/greference.c
r3361 r3376 12 12 13 13 /* get stars from USNO for the given region */ 14 if (!strc mp (Refcat, "USNO")) {14 if (!strcasecmp (Refcat, "USNO")) { 15 15 stars = getusno (catstats, &Nstars); 16 16 } 17 17 18 18 /* get stars from HST GSC for the given region */ 19 if (!strc mp (Refcat, "GSC")) {19 if (!strcasecmp (Refcat, "GSC")) { 20 20 stars = getgsc (catstats, &Nstars); 21 21 } 22 22 23 23 /* get stars from 2MASS for the given region */ 24 if (!strc mp (Refcat, "2MASS")) {24 if (!strcasecmp (Refcat, "2MASS")) { 25 25 stars = get2mass (catstats, &Nstars); 26 26 } 27 27 28 if (Nstars == 0) { 29 fprintf (stderr, "no ref objs: %s\n", Refcat); 30 exit (1); 31 } 28 if (VERBOSE && (Nstars == 0)) fprintf (stderr, "no ref objects in region %s\n", catstats[0].filename); 29 32 30 *nstars = Nstars; 33 31 return (stars); -
trunk/Ohana/src/addstar/src/grefstars.c
r3361 r3376 9 9 char line[256]; 10 10 11 /* require photcode */ 12 if (thiscode == NULL) Shutdown ("photcode not specified"); 13 11 14 /* open file */ 12 15 f = fopen (file, "r"); 13 if (f == NULL) { 14 fprintf (stderr, "ERROR: can't read data from %s\n", file); 15 Shutdown (); 16 } 16 if (f == NULL) Shutdown ("can't read data from %s", file); 17 17 18 18 NSTARS = 100; 19 19 ALLOCATE (stars, Stars, NSTARS); 20 21 /* require photcode */22 if (thiscode == NULL) {23 fprintf (stderr, "error: photcode not specified\n");24 exit (2);25 }26 20 27 21 /* read in stars line-by-line */ -
trunk/Ohana/src/addstar/src/gregion_image.c
r3347 r3376 4 4 GSCRegion *gregion_image (Image *image, int *Nregions) { 5 5 6 GSCRegion *region; 7 FILE *f; 8 double x, y; 9 double dec, ra; 10 int i, j, done, nregion, NREGION; 6 GSCRegion *regions, impatch; 7 double x, y, X, Y, ra, dec; 11 8 12 f = fopen (GSCFILE, "r"); 13 if (f == NULL) { 14 fprintf (stderr, "ERROR: can't find GSC region file %s\n", GSCFILE); 15 exit (1); 16 } 17 18 /* find regions at image corners */ 19 NREGION = 100; 20 ALLOCATE (region, GSCRegion, NREGION); 21 nregion = 0; 9 /* this has trouble for images which overlap 0,360 */ 10 impatch.RA[0] = 360; 11 impatch.RA[1] = 0; 12 impatch.DEC[0] = +90; 13 impatch.DEC[1] = -90; 22 14 23 /* this is not efficient, nor guaranteed - fix me */ 24 /* look for new regions on grid across image */ 25 for (x = 0.0; x <= 1.0; x+=0.1) { 26 for (y = 0.0; y <= 1.0; y+=0.1) { 27 XY_to_RD (&ra, &dec, image[0].NX*(1.1*x - 0.05), image[0].NY*(1.1*y - 0.05), &image[0].coords); 28 aregion (®ion[nregion], f, ra, dec); 29 done = FALSE; 30 for (j = 0; (j < nregion) && !done; j++) { 31 if (!strcmp (region[nregion].filename, region[j].filename)) { 32 nregion --; 33 done = TRUE; 34 } 35 } 36 nregion ++; 37 CHECK_REALLOCATE (region, GSCRegion, NREGION, nregion, 100); 15 for (x = 0; x <= 1; x++) { 16 for (y = 0; y <= 1; y++) { 17 X = image[0].NX*(1.1*x - 0.05); 18 Y = image[0].NY*(1.1*y - 0.05); 19 XY_to_RD (&ra, &dec, X, Y, &image[0].coords); 20 impatch.RA[0] = MIN (ra, impatch.RA[0]); 21 impatch.RA[1] = MAX (ra, impatch.RA[1]); 22 impatch.DEC[0] = MIN (dec, impatch.DEC[0]); 23 impatch.DEC[1] = MAX (dec, impatch.DEC[1]); 38 24 } 39 25 } 40 41 if (VERBOSE) { 42 fprintf (stderr, "found %d region files:\n", nregion); 43 for (i = 0; i < nregion; i++) { 44 fprintf (stderr, " %d %s\n", i, region[i].filename); 45 } 46 } 47 *Nregions = nregion; 48 49 fclose (f); 50 return (region); 51 26 regions = gregion_patch (&impatch, Nregions); 27 return (regions); 52 28 } -
trunk/Ohana/src/addstar/src/gregion_match.c
r3347 r3376 3 3 GSCRegion *gregion_match (GSCRegion *regions, int *nregions) { 4 4 5 int i; 6 int Nsubset; 5 int i, status, Nregions, Nsubset, NSUBSET; 7 6 GSCRegion *subset; 8 7 struct stat filestats; … … 12 11 Nsubset = 0; 13 12 NSUBSET = 100; 14 ALLOCATE (subset, GSCRegion s, NSUBSET);13 ALLOCATE (subset, GSCRegion, NSUBSET); 15 14 16 15 /* match the basename against the GSCRegion file names */ … … 22 21 subset[Nsubset] = regions[i]; 23 22 Nsubset ++; 24 CHECK_ ALLOCATE (subset, GSCRegion, NSUBSET, Nsubset, 100);23 CHECK_REALLOCATE (subset, GSCRegion, NSUBSET, Nsubset, 100); 25 24 } 26 25 free (regions); -
trunk/Ohana/src/addstar/src/gregion_match_glob.c
r3347 r3376 17 17 18 18 Nregions = 0; 19 ALLOCATE (regions, GSCRegion s, MAX (1, pglob.gl_pathc));19 ALLOCATE (regions, GSCRegion, MAX (1, pglob.gl_pathc)); 20 20 21 21 /* match the basename against the GSCRegion file names */ -
trunk/Ohana/src/addstar/src/gregion_patch.c
r3347 r3376 3 3 GSCRegion *gregion_patch (GSCRegion *patch, int *nregions) { 4 4 5 int i; 6 int Ngsc, Nregions; 5 int i, Ns, Ne, Ngsc, Nregions; 7 6 GSCRegion *gsc, *regions; 8 7 … … 12 11 Ns = FindRegionDecBandStart (gsc, Ngsc, patch[0].DEC[0]); 13 12 Ne = FindRegionDecBandStop (gsc, Ngsc, patch[0].DEC[1]); 13 if (Ns < 0) Shutdown ("invalid patch lower bound %f", patch[0].DEC[0]); 14 if (Ne < 0) Shutdown ("invalid patch upper bound %f", patch[0].DEC[1]); 14 15 15 16 Nregions = 0; 16 ALLOCATE (regions, GSCRegion s, (Ne - Ns));17 ALLOCATE (regions, GSCRegion, Ne - Ns); 17 18 18 19 /* find all regions in range within ra range */ -
trunk/Ohana/src/addstar/src/gregion_star.c
r3361 r3376 3 3 GSCRegion *gregion_stars (Stars *stars, int Nstars, int *nregions) { 4 4 5 int i; 6 int Ngsc, Nregions, NREGIONS; 7 GSCRegion *gsc, regions; 5 int i, j, Ngsc, Nregions, NREGIONS; 6 GSCRegion *gsc, *regions; 8 7 9 8 gsc = LoadRegions (&Ngsc); … … 13 12 ALLOCATE (regions, GSCRegion, NREGIONS); 14 13 15 sort_stars (stars, Nstars); 14 sort_stars (stars, Nstars); /* sort by RA */ 16 15 for (i = 0; i < Nstars; i++) { 17 if (stars[ 0].found) continue;18 FindRegionByPoint (®ions[Nregions], star [0].R, star[0].D, gsc, Ngsc);19 stars[ 0].found = TRUE;16 if (stars[i].found) continue; 17 FindRegionByPoint (®ions[Nregions], stars[i].R, stars[i].D, gsc, Ngsc); 18 stars[i].found = TRUE; 20 19 /* search forward for all contained stars */ 21 20 for (j = i; j < Nstars; j++) { 22 if (stars[j].R >= regions .RA[1]) break;23 if (stars[j].D < regions .DEC[0]) continue;24 if (stars[j].D >= regions .DEC[1]) continue;21 if (stars[j].R >= regions[Nregions].RA[1]) break; 22 if (stars[j].D < regions[Nregions].DEC[0]) continue; 23 if (stars[j].D >= regions[Nregions].DEC[1]) continue; 25 24 stars[j].found = TRUE; 26 25 } -
trunk/Ohana/src/addstar/src/image-db.c
r3361 r3376 1 1 # include "addstar.h" 2 2 3 /* file-pointer to Image.db table. if image db does not yet exist, 4 5 */3 # define LOCK LCK_XCLD 4 5 /* file-pointer to Image.db table. if image db does not yet exist */ 6 6 static FILE *f = (FILE *) NULL; 7 7 static int dbstate = LCK_UNLOCK; … … 13 13 14 14 /* clean up open / locked ImageCat before shutting down */ 15 int Shutdown () { 15 int Shutdown (char *format, ...) { 16 va_list argp; 17 char *formatplus; 18 19 ALLOCATE (formatplus, char, strlen(format)); 20 strcpy (formatplus, format); 21 strcat (formatplus, "\n"); 22 23 va_start (argp, format); 24 vfprintf (stderr, formatplus, argp); 25 free (formatplus); 26 va_end (argp); 27 16 28 SetProtect (TRUE); 17 fclearlockfile (ImageCat, f, L CK_HARD, &dbstate);29 fclearlockfile (ImageCat, f, LOCK, &dbstate); 18 30 fprintf (stderr, "ERROR: addstar halted\n"); 19 31 exit (1); … … 23 35 /* lock the image catalog */ 24 36 check_permissions (ImageCat); 25 f = fsetlockfile (ImageCat, 3600.0, L CK_HARD, &dbstate);37 f = fsetlockfile (ImageCat, 3600.0, LOCK, &dbstate); 26 38 if ((f == (FILE *) NULL) && (dbstate != LCK_EMPTY)) { 27 39 fprintf (stderr, "ERROR: can't lock image catalog\n"); … … 33 45 void unlock_image_db (Image *image) { 34 46 47 mode_t mode; 48 35 49 /* protect wimage from interrupt signals */ 36 if ( mode== M_IMAGE) {50 if (MODE == M_IMAGE) { 37 51 SetProtect (TRUE); 38 52 wimage (image); … … 40 54 } 41 55 42 fclearlockfile (ImageCat, f, L CK_HARD, &dbstate);56 fclearlockfile (ImageCat, f, LOCK, &dbstate); 43 57 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 44 58 chmod (ImageCat, mode); -
trunk/Ohana/src/addstar/src/load_pt_catalog.c
r3361 r3376 3 3 int load_pt_catalog (Catalog *catalog, GSCRegion *region) { 4 4 5 check_permissions (region[0].filename); 6 5 7 /* don't free region before catalog! */ 6 8 catalog[0].filename = region[0].filename; … … 11 13 /* catalog file is locked. this is an unexpected error because 12 14 ImageCat was NOT locked so we should be the only locking entity */ 13 fprintf (stderr, "ERROR: can't lock file %s\n", catalog .filename);15 fprintf (stderr, "ERROR: can't lock file %s\n", catalog[0].filename); 14 16 exit (1); 15 17 case 1: -
trunk/Ohana/src/addstar/src/load_subpix.c
r3339 r3376 19 19 20 20 f = fopen (SubpixDatafile, "r"); 21 if (f == (FILE *) NULL) { 22 fprintf (stderr, "can't load subpix datafile %s\n", SubpixDatafile); 23 Shutdown (); 24 } 21 if (f == NULL) Shutdown ("can't load subpix datafile %s", SubpixDatafile); 22 25 23 for (i = 0; i < Nsubpix; i++) { 26 24 fscanf (f, "%*s %*s %lf %lf %lf %*s\n", -
trunk/Ohana/src/addstar/src/replace_match.c
r3361 r3376 3 3 int replace_match (Average *average, Measure *measure, Stars *star) { 4 4 5 int i; 6 5 7 if (!REPLACE) return (FALSE); 6 8 7 9 /** in replace mode, search for entry and replace values M, dM, R, D */ 8 for ( k = 0; k < average[0].Nm; k++) {9 if (measure[ k].source != thiscode[0].code) continue;10 measure[ k].dR = 360000.0*(average[0].R - stars[0].R);11 measure[ k].dD = 360000.0*(average[0].D - stars[0].D);12 measure[ k].M = MIN (1000*stars[0].M, NO_MAG);13 measure[ k].dM = MIN (1000*stars[0].dM, NO_ERR);14 star s[N].found = average[0].offset + k;10 for (i = 0; i < average[0].Nm; i++) { 11 if (measure[i].source != thiscode[0].code) continue; 12 measure[i].dR = 360000.0*(average[0].R - star[0].R); 13 measure[i].dD = 360000.0*(average[0].D - star[0].D); 14 measure[i].M = MIN (1000*star[0].M, NO_MAG); 15 measure[i].dM = MIN (1000*star[0].dM, NO_ERR); 16 star[0].found = average[0].offset + i; 15 17 return (TRUE); 16 18 } -
trunk/Ohana/src/addstar/src/sort_lists.c
r3339 r3376 1 # include "addstar.h" 1 2 2 void sort_GSCregions (GSCRegion *region, int Nregion) { 3 void sort_stars (Stars *stars, int N) { 4 5 int l,j,ir,i; 6 Stars tmp; 7 8 l = N >> 1; 9 ir = N - 1; 10 for (;;) { 11 if (l > 0) { 12 l--; 13 tmp = stars[l]; 14 } 15 else { 16 tmp = stars[ir]; 17 stars[ir] = stars[0]; 18 if (--ir == 0) { 19 stars[0] = tmp; 20 return; 21 } 22 } 23 i = l; 24 j = (l << 1) + 1; 25 while (j <= ir) { 26 if (j < ir && stars[j].R < stars[j+1].R) j++; 27 if (tmp.R < stars[j].R) { 28 stars[i] = stars[j]; 29 j += (i=j) + 1; 30 } 31 else j = ir + 1; 32 } 33 stars[i] = tmp; 34 } 35 } 36 37 void sort_regions (GSCRegion *region, int N) { 3 38 4 39 int l,j,ir,i; … … 11 46 l--; 12 47 tmp = region[l]; 13 } 14 else { 48 } else { 15 49 tmp = region[ir]; 16 50 region[ir] = region[0]; … … 23 57 j = (l << 1) + 1; 24 58 while (j <= ir) { 25 if (j < ir && region[j].DEC < region[j+1].DEC) j++;26 if (tmp.DEC < region[j].DEC) {59 if (j < ir && region[j].DEC[0] < region[j+1].DEC[0]) j++; 60 if (tmp.DEC[0] < region[j].DEC[0]) { 27 61 region[i] = region[j]; 28 62 j += (i=j) + 1; … … 47 81 tY = Y[l]; 48 82 tS = S[l]; 49 } 50 else { 83 } else { 51 84 tX = X[ir]; 52 85 X[ir] = X[0]; … … 91 124 l--; 92 125 tX = X[l]; 93 } 94 else { 126 } else { 95 127 tX = X[ir]; 96 128 X[ir] = X[0]; -
trunk/Ohana/src/addstar/src/update_coords.c
r3361 r3376 4 4 void update_coords (Average *average, Measure *measure, int *next) { 5 5 6 int i, m, Npt; 6 7 double R, D, r, d; 7 8 double r2, d2, dR2, dD2; 8 int Npt;9 9 10 10 Npt = r = d = r2 = d2 = 0; … … 14 14 /* find the average & sum-square */ 15 15 m = average[0].offset; /* first measurement of this star */ 16 for ( k = 0; k < average[0].Nm; k++) {16 for (i = 0; i < average[0].Nm; i++) { 17 17 if (measure[m].t == 0) { 18 18 m = next[m]; … … 36 36 average[0].D -= d / 360000.0; 37 37 m = average[0].offset; /* first measurement of this star */ 38 for ( k = 0; k < average[0].Nm; k++) {38 for (i = 0; i < average[0].Nm; i++) { 39 39 measure[m].dR -= r; 40 40 measure[m].dD -= d;
Note:
See TracChangeset
for help on using the changeset viewer.
