IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3376


Ignore:
Timestamp:
Mar 4, 2005, 2:48:42 PM (21 years ago)
Author:
eugene
Message:

addstar works for -cat, -image

Location:
trunk/Ohana/src/addstar
Files:
1 added
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/Makefile

    r3361 r3376  
    1717
    1818INCS    =       -I$(INC) -I$(LINC) -I$(XINC)
    19 LIBS    =       -L$(LLIB) -lFITS -lohana -lm
     19LIBS    =       -L$(LLIB) -lFITS -lohana -lz -lm
    2020CFLAGS  =       $(INCS)
    2121LFLAGS  =       $(LIBS)
     
    2424$(SRC)/addstar.$(ARCH).o \
    2525$(SRC)/airmass.$(ARCH).o \
    26 $(SRC)/aregion.$(ARCH).o \
    2726$(SRC)/args.$(ARCH).o \
    2827$(SRC)/calibrate.$(ARCH).o \
     
    8079INSTALL = addstar
    8180
     81gztest                : $(BIN)/gztest.$(ARCH)
     82$(BIN)/gztest.$(ARCH) : $(SRC)/gztest.$(ARCH).o
     83
     84INSTALL = addstar
     85
    8286# dependancy rules for binary code #########################
    8387.PRECIOUS: %.$(ARCH).o
  • trunk/Ohana/src/addstar/include/addstar.h

    r3361 r3376  
    44# include <sys/time.h>
    55# include <time.h>
     6# include <zlib.h>
    67
    78/* used in find_matches, find_matches_refstars */
     
    1213/* grab named photcode */
    1314# define NAMED_PHOTCODE(CODE,NAME) \
    14   CODE = GetPhotcodebyName (NAME); \
     15  CODE = GetPhotcodeCodebyName (NAME); \
    1516  if (!CODE) { \
    1617    fprintf (stderr, "ERROR:  photcode %s not found in photcode table\n", NAME); \
     
    4748char   GSCFILE[256];
    4849char   CATDIR[256];
     50char   TWO_MASS_DIR[256];
     51char   GSCDIR[256];
     52char   CDROM[256];
    4953double DEFAULT_RADIUS, NSIGMA, SNLIMIT;
    5054double ZeroPt;
     
    5761
    5862PhotCode *thiscode;
    59 GSCRegion patch;
     63GSCRegion UserPatch;
    6064
    6165char DateKeyword[64];
     
    8690
    8791int main (int argc, char **argv);
    88 int Shutdown (); 
     92int Shutdown (char *message, ...); 
    8993void TrapSignal (int sig);
    9094int SetSignals ();
     
    122126void fsort (float *X, int N);
    123127void fsort2 (float *X, float *Y, int N);
     128void sort_stars (Stars *stars, int N);
     129void sort_regions (GSCRegion *region, int N);
    124130
    125131char *sec_to_date (time_t second);
     
    147153Stars *get2mass (GSCRegion *patch, int *NSTARS);
    148154TM_Region *get2mass_acc (GSCRegion *patch, int *nfiles);
    149 Stars *get2mass_data (char *filename, GSCRegion *patch, int *nstars);
     155Stars *get2mass_data (TM_Region *region, GSCRegion *patch, int *nstars);
    150156GSCRegion *gregion_stars (Stars *stars, int Nstars, int *Nregion);
    151157Stars *grefstars (char *file, int *Nstars);
     
    180186int replace_match (Average *average, Measure *measure, Stars *star);
    181187FILE *GetDB (int *state);
    182 int Shutdown ();
    183188void lock_image_db ();
    184189void unlock_image_db (Image *image);
  • trunk/Ohana/src/addstar/src/ConfigInit.c

    r3339 r3376  
    2626  XMIN = XMAX = YMIN = YMAX = 0;
    2727  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);
    3434
    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);
    4044  ScanConfig (config, "MIN_SN_FSTAT",           "%lf", 0, &SNLIMIT);
    41   ScanConfig (config, "PHOTCODE_FILE",          "%s", 0, PhotCodeFile);
     45  ScanConfig (config, "PHOTCODE_FILE",          "%s",  0, PhotCodeFile);
    4246
    4347  /* 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);
    4953
    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);
    5357
    5458  ScanConfig (config, "ST-KEYWORD",             "%s",  0, STKeyword);
     
    5761
    5862  if (!LoadPhotcodes (PhotCodeFile)) {
    59     fprintf (stderr, "error loading photcodes\n");
     63    fprintf (stderr, "error loading photcode file %s\n", PhotCodeFile);
    6064    exit (1);
    6165  }
     
    6569
    6670}
     71
     72void 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  
    11# include "addstar.h"
    2 # define NBANDS
     2
     3# define NBANDS 24
     4
    35double 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.0
     6  -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
    911};
    1012
    1113char *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",
    1719};
    1820
    1921GSCRegion *LoadRegions (int *nregions) {
    2022 
     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;
    2128  Header header;
    2229  Header theader;
    2330  Matrix matrix;
    2431  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;
    3132 
    3233  f = fopen (GSCFILE, "r");
     
    3738
    3839  /* 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");
    4244
    4345  fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
     
    4547
    4648  Nregions = 0;
    47   ALLOCATE (regions, GSCRegion, Ny);
     49  ALLOCATE (regions, GSCRegion, Ny + 2);  /* allow room for N & S poles */
    4850
    4951  /* pole region is artificial - not in table */
    5052  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);
    5658  Nregions ++;
    5759
     60  /* fill out GSCRegion structure */
    5861  for (i = 0; i < Ny; i++) {
    5962    strncpy (temp, &table.buffer[i*48], 48);
     
    7679
    7780    /** 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");
    8983
    9084    temp[5] = 0;
    91     sprintf (file, "%s/%s/%s.cpt", CATDIR, Dec2Sections[NBigDec], &temp[1]);
     85    sprintf (file, "%s/%s/%s.cpt", CATDIR, DecNames[NDec], &temp[1]);
    9286
    9387    strcpy (regions[Nregions].filename, file);
     
    10094}
    10195
    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 */
     97int 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] */
     112int 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] */
     144int 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
     175int FindRegionByPoint (GSCRegion *region, double ra, double dec, GSCRegion *gsc, int Ngsc) {
     176
     177  int i, Ns;
    103178
    104179  Ns = FindRegionDecBandStart (gsc, Ngsc, dec);
     180  if (Ns < 0) return (FALSE);
    105181
    106182  for (i = Ns; i < Ngsc; i++) {
     
    115191}
    116192
    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 
    167193/* bracket search:
    168194
  • trunk/Ohana/src/addstar/src/SetSignals.c

    r3339 r3376  
    55
    66void TrapSignal (int sig) {
    7     fprintf (stderr, "trapped signal %d, exiting gracefully\n", sig);
     7    fprintf (stderr, "trapped signal %d\n", sig);
    88    if (sig == 11) {
    99      fprintf (stderr, "seg fault\n");
     
    1515      return;
    1616    }
    17     Shutdown ();
     17    Shutdown ("halted by signal (trapped)");
    1818}   
    1919
    2020void SetProtect (int mode) {
    2121  Protect = mode;
    22   if (Trapped && !Protect) Shutdown ();
     22  if (Trapped && !Protect) Shutdown ("halted by signal (protect)");
    2323}
    2424
  • trunk/Ohana/src/addstar/src/addstar.c

    r3361 r3376  
    3232    break;
    3333  case M_REFCAT:
    34     regions = gregion_patch (&patch, &Nregions);
     34    regions = gregion_patch (&UserPatch, &Nregions);
    3535    break;
    3636  }
     
    4444    switch (MODE) {
    4545    case M_IMAGE:
     46      Nsubset = Nstars;
    4647      find_matches (&regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap);
    4748      break;
    4849    case M_REFCAT:
    49       stars = grefcat (argv[1], regions, &Nstars);
     50      stars = grefcat (argv[1], &regions[i], &Nstars);
    5051    case M_REFLIST:
    5152      subset = find_subset (&regions[i], stars, Nstars, &Nsubset);
     
    5455      break;
    5556    }
    56     save_pt_catalog (&catalog);
     57    if (Nsubset == 0) {
     58      unlock_catalog (&catalog);
     59    } else {
     60      save_pt_catalog (&catalog);
     61    }
    5762  }
    5863
  • trunk/Ohana/src/addstar/src/args.c

    r3361 r3376  
    3737  /*** provide additional data ***/
    3838  /* 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;
    4343  if ((N = get_argument (argc, argv, "-region"))) {
    4444    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);
    4953  }
    5054  /* override any header PHOTCODE values */
     
    125129
    126130  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"); 
    128137    exit (2);
    129138  }
  • trunk/Ohana/src/addstar/src/conversions.c

    r3361 r3376  
    308308  bzero (&now, sizeof(now));
    309309
    310   scanf (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);
    311311
    312312  if (now.tm_year >   51) now.tm_year +=   0;
  • trunk/Ohana/src/addstar/src/find_matches.c

    r3361 r3376  
    1515  short int Mrel, *Mval;
    1616
    17   /* photcode data */
     17  /* photcode data - must by of type DEP, (PRI, SEC) - probably should restrict to DEP */
    1818  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);
    2022  /* this function requires incoming stars to have the same photcode */
    2123
     
    114116      dY = Y1[i] - Y2[J];
    115117      dR = dX*dX + dY*dY;
    116       if (dR < RADIUS2) continue;
     118      if (dR > RADIUS2) continue;
    117119
    118120      Nmatch ++;
     
    153155      catalog[0].measure[Nmeas].theta    = MIN ((255/360)*stars[N].df, NO_ERR);
    154156       
     157      /*** this should probably use the mag lookup functions - zeropoints are incorrectly applied ***/
    155158      /* it is not valid to pass PRI/SEC/REF photcodes to this routine */
    156159      /* check for entries in the secfilt lists */
     
    365368  }
    366369
     370  /* check if the catalog has changed?  if no change, no need to write */
    367371  catalog[0].Naverage = Nave;
    368372  catalog[0].Nmeasure = Nmeas;
  • trunk/Ohana/src/addstar/src/get2mass.c

    r3361 r3376  
    11# include "addstar.h"
     2
     3static short TM_J, TM_H, TM_K;
    24
    35Stars *get2mass (GSCRegion *patch, int *NSTARS) {
     
    79  Stars     *refcat;
    810  TM_Region *regions;
    9   short int TM_J, TM_H, TM_K;
    1011
    1112  NAMED_PHOTCODE (TM_J, "2MASS_J");
    1213  NAMED_PHOTCODE (TM_H, "2MASS_H");
    1314  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");
    1420
     21good_code:
    1522  regions = get2mass_acc (patch, &Nregions);
    1623 
     
    1926 
    2027  for (i = 0; i < Nregions; i++) {
    21     refcat = get2mass_data (regions[i].name, patch, &Nrefcat);
     28    refcat = get2mass_data (&regions[i], patch, &Nrefcat);
    2229
    2330    REALLOCATE (stars, Stars, MAX (1, Nstars + Nrefcat));
     
    3441
    3542/* watch for patch which cross 0,360 boundary */
    36 TM_Region *get2mass_acc (GSCRegion *patch, int *nfiles) {
     43TM_Region *get2mass_acc (GSCRegion *patch, int *nregions) {
    3744
    38   int       Nregions
     45  int Nregions, NREGIONS, Nrec;
    3946  TM_Region *regions;
     47  char accel[1024], line[128], filename[128];
     48  FILE     *f;
     49  double Rs, Re;
    4050
    4151  sprintf (accel, "%s/idr2.acc", TWO_MASS_DIR);
    4252  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);
    4754
    4855  Nregions = 0;
     
    5158
    5259  /* read in stars line-by-line */
    53   for (N = 0; scan_line (f, line) != EOF; N++) {
     60  while (scan_line (f, line) != EOF) {
    5461    stripwhite (line);
    5562    if (line[0] == 0) continue;
    5663    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;
    5867    if (Rs > patch[0].RA[1]) continue;
    5968    if (Re < patch[0].RA[0]) continue;
    60     strcpy (regions[Nregions].filename, "%s/%s", TWO_MASS_DIR, filename);
     69    sprintf (regions[Nregions].filename, "%s/%s", TWO_MASS_DIR, filename);
    6170    regions[Nregions].RA[0] = Rs;
    6271    regions[Nregions].RA[1] = Re;
     
    7180
    7281# define NBYTE 302
    73 # define NLINE 100
     82# define NLINE 30000
    7483
    75 Stars *get2mass_data (char *filename, GSCRegion *patch, int *nstars) {
     84Stars *get2mass_data (TM_Region *region, GSCRegion *patch, int *nstars) {
    7685 
    77   int Nstars;
     86  int i, Nstars, NSTARS, Nbyte, Nline, Nval;
    7887  Stars *stars;
    7988  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;
    8193
     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;
    82100  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);
    87102
    88103  Nstars = 0;
     
    90105  ALLOCATE (stars, Stars, NSTARS);
    91106
    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  */
    93114
    94115  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);
    107119    Nline = Nbyte / NBYTE;
    108120
     121    /* skip past block not yet in range */
     122    sscanf (&buffer[NBYTE*(Nline - 1)], "%lf %lf", &RA, &DEC);
     123    if (DEC < DEC0) continue;
     124
    109125    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]);
    115129
    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;
    123146      }
    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      }
    133161      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  } 
     165finished:
     166  gzclose (gf);
    154167
    155168  *nstars = Nstars;
    156169  return (stars);
    157170}
     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*/
    158179
    159180    /* this just scans along in the file.  file is sorted by dec, so we
  • trunk/Ohana/src/addstar/src/getgsc.c

    r3361 r3376  
    44# define DNSTARS 1000
    55
     6static short GSC_M;
     7
    68Stars *getgsc (GSCRegion *patch, int *NSTARS) {
    79 
    810  int i, j, k, Ns, Ngsc, Nregions, Nstars;
    9   StarData *gsc;
    10   StarData *stars;
    11   GSCRegions *regions;
    12   short int GSC_M;
     11  Stars *gsc;
     12  Stars *stars;
     13  GSCRegion *regions;
     14  char *tmp;
    1315
    1416  NAMED_PHOTCODE (GSC_M, "GSC_M");
    1517
     18  /* sort of sleaze way to get the right GSC files */
     19  tmp = strcreate (CATDIR);
     20  strcpy (CATDIR, GSCDIR);
    1621  regions = gregion_patch (patch, &Nregions);
     22  strcpy (CATDIR, tmp);
     23  free (tmp);
    1724 
    1825  Nstars = 0;
     
    2027 
    2128  for (i = 0; i < Nregions; i++) {
    22     gsc = rd_gsc (regions[i].name, &Ngsc);
     29    gsc = rd_gsc (regions[i].filename, &Ngsc);
    2330
    2431    REALLOCATE (stars, Stars, MAX (1, Nstars + Ngsc));
     
    3643Stars *rd_gsc (char *filename, int *nstars) {
    3744 
    38   int i, NSTARS, Nstars, Nbytes, nbytes;
     45  int i, NSTARS, Nstars, Nbytes, nbytes, Nline, Nbyte;
    3946  char *buffer;
    4047  FILE *f;
     
    6067      dparse (&stars[Nstars].R, 1, &buffer[Nbyte]);
    6168      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
    6274      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;
    6679      Nstars ++;
    6780      CHECK_REALLOCATE (stars, Stars, NSTARS, Nstars, 1000);
  • trunk/Ohana/src/addstar/src/getusno.c

    r3361 r3376  
    2424  short int USNO_RED, USNO_BLUE;
    2525
     26  /* require photcode */
    2627  NAMED_PHOTCODE (USNO_RED, "USNO_RED");
    2728  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");
     33good_code:
    2834
    2935  /* 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;
    3441 
    3542  /* data is organized in south-pole distance zones */
     
    116123
    117124        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        }
    125140        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);
    136142      }
    137143      free (buffer);
  • trunk/Ohana/src/addstar/src/gimages.c

    r3361 r3376  
    44Image *gimages (Image *image, int *Npimage) {
    55 
    6   int i, j, k, Nimage, addtolist, size;
     6  int i, j, k, Nimage, addtolist, size, dbstate;
    77  int NTIMAGE, Ntimage, ntimage;
    88  int NPIMAGE, npimage;
     
    1414  double zeropt;
    1515  struct stat filestatus;
     16  FILE *f;
    1617 
    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  }
    1825  fseek (f, 0, SEEK_SET);
    1926
    2027  /* read header */
    2128  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);
    2430  }
    2531
    2632  fits_scan (&header, "ZERO_PT", "%lf", 1, &zeropt);
    2733  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)",
    2935             ZeroPt, image[0].name, zeropt);
    30     Shutdown ();
    3136  }
    3237
     
    5762  /* check that file size makes sense */
    5863  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");
    6165  }
    6266  size = Nimage*sizeof(Image) + header.size;
     
    6771    fprintf (stderr, "error: image catalog has inconsistent size\n");
    6872    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");
    7074
    7175    Nimage = MIN (Nimage, Ndata);
     
    114118
    115119    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);
    118121    }
    119122  }
  • trunk/Ohana/src/addstar/src/greference.c

    r3361 r3376  
    1212
    1313  /* get stars from USNO for the given region */
    14   if (!strcmp (Refcat, "USNO")) {
     14  if (!strcasecmp (Refcat, "USNO")) {
    1515    stars = getusno (catstats, &Nstars);
    1616  }
    1717
    1818  /* get stars from HST GSC for the given region */
    19   if (!strcmp (Refcat, "GSC")) {
     19  if (!strcasecmp (Refcat, "GSC")) {
    2020    stars = getgsc (catstats, &Nstars);
    2121  }
    2222 
    2323  /* get stars from 2MASS for the given region */
    24   if (!strcmp (Refcat, "2MASS")) {
     24  if (!strcasecmp (Refcat, "2MASS")) {
    2525    stars = get2mass (catstats, &Nstars);
    2626  }
    2727 
    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
    3230  *nstars = Nstars;
    3331  return (stars);
  • trunk/Ohana/src/addstar/src/grefstars.c

    r3361 r3376  
    99  char line[256];
    1010
     11  /* require photcode */
     12  if (thiscode == NULL) Shutdown ("photcode not specified");
     13
    1114  /* open file */
    1215  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);
    1717
    1818  NSTARS = 100;
    1919  ALLOCATE (stars, Stars, NSTARS);
    20 
    21   /* require photcode */
    22   if (thiscode == NULL) {
    23     fprintf (stderr, "error: photcode not specified\n");
    24     exit (2);
    25   }
    2620
    2721  /* read in stars line-by-line */
  • trunk/Ohana/src/addstar/src/gregion_image.c

    r3347 r3376  
    44GSCRegion *gregion_image (Image *image, int *Nregions) {
    55 
    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;
    118 
    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;
    2214
    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 (&region[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]);
    3824    }
    3925  }
    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);
    5228}
  • trunk/Ohana/src/addstar/src/gregion_match.c

    r3347 r3376  
    33GSCRegion *gregion_match (GSCRegion *regions, int *nregions) {
    44 
    5   int i;
    6   int       Nsubset;
     5  int i, status, Nregions, Nsubset, NSUBSET;
    76  GSCRegion *subset;
    87  struct stat filestats;
     
    1211  Nsubset = 0;
    1312  NSUBSET = 100;
    14   ALLOCATE (subset, GSCRegions, NSUBSET);
     13  ALLOCATE (subset, GSCRegion, NSUBSET);
    1514
    1615  /* match the basename against the GSCRegion file names */
     
    2221    subset[Nsubset] = regions[i];
    2322    Nsubset ++;
    24     CHECK_ALLOCATE (subset, GSCRegion, NSUBSET, Nsubset, 100);
     23    CHECK_REALLOCATE (subset, GSCRegion, NSUBSET, Nsubset, 100);
    2524  }
    2625  free (regions);
  • trunk/Ohana/src/addstar/src/gregion_match_glob.c

    r3347 r3376  
    1717
    1818  Nregions = 0;
    19   ALLOCATE (regions, GSCRegions, MAX (1, pglob.gl_pathc));
     19  ALLOCATE (regions, GSCRegion, MAX (1, pglob.gl_pathc));
    2020
    2121  /* match the basename against the GSCRegion file names */
  • trunk/Ohana/src/addstar/src/gregion_patch.c

    r3347 r3376  
    33GSCRegion *gregion_patch (GSCRegion *patch, int *nregions) {
    44 
    5   int i;
    6   int       Ngsc, Nregions;
     5  int i, Ns, Ne, Ngsc, Nregions;
    76  GSCRegion *gsc, *regions;
    87 
     
    1211  Ns = FindRegionDecBandStart (gsc, Ngsc, patch[0].DEC[0]);
    1312  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]);
    1415 
    1516  Nregions = 0;
    16   ALLOCATE (regions, GSCRegions, (Ne - Ns));
     17  ALLOCATE (regions, GSCRegion, Ne - Ns);
    1718
    1819  /* find all regions in range within ra range */
  • trunk/Ohana/src/addstar/src/gregion_star.c

    r3361 r3376  
    33GSCRegion *gregion_stars (Stars *stars, int Nstars, int *nregions) {
    44 
    5   int i;
    6   int       Ngsc, Nregions, NREGIONS;
    7   GSCRegion *gsc, regions;
     5  int i, j, Ngsc, Nregions, NREGIONS;
     6  GSCRegion *gsc, *regions;
    87 
    98  gsc = LoadRegions (&Ngsc);
     
    1312  ALLOCATE (regions, GSCRegion, NREGIONS);
    1413
    15   sort_stars (stars, Nstars);
     14  sort_stars (stars, Nstars); /* sort by RA */
    1615  for (i = 0; i < Nstars; i++) {
    17     if (stars[0].found) continue;
    18     FindRegionByPoint (&regions[Nregions], star[0].R, star[0].D, gsc, Ngsc);
    19     stars[0].found = TRUE;
     16    if (stars[i].found) continue;
     17    FindRegionByPoint (&regions[Nregions], stars[i].R, stars[i].D, gsc, Ngsc);
     18    stars[i].found = TRUE;
    2019    /* search forward for all contained stars */
    2120    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;
    2524      stars[j].found = TRUE;
    2625    }
  • trunk/Ohana/src/addstar/src/image-db.c

    r3361 r3376  
    11# include "addstar.h"
    22
    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 */
    66static FILE *f = (FILE *) NULL;
    77static int dbstate = LCK_UNLOCK;
     
    1313
    1414/* clean up open / locked ImageCat before shutting down */
    15 int Shutdown () { 
     15int 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
    1628  SetProtect (TRUE);
    17   fclearlockfile (ImageCat, f, LCK_HARD, &dbstate);
     29  fclearlockfile (ImageCat, f, LOCK, &dbstate);
    1830  fprintf (stderr, "ERROR: addstar halted\n");
    1931  exit (1);
     
    2335  /* lock the image catalog */
    2436  check_permissions (ImageCat);
    25   f = fsetlockfile (ImageCat, 3600.0, LCK_HARD, &dbstate);
     37  f = fsetlockfile (ImageCat, 3600.0, LOCK, &dbstate);
    2638  if ((f == (FILE *) NULL) && (dbstate != LCK_EMPTY)) {
    2739    fprintf (stderr, "ERROR: can't lock image catalog\n");
     
    3345void unlock_image_db (Image *image) {
    3446
     47  mode_t mode;
     48
    3549  /* protect wimage from interrupt signals */
    36   if (mode == M_IMAGE) {
     50  if (MODE == M_IMAGE) {
    3751    SetProtect (TRUE);
    3852    wimage (image);
     
    4054  }
    4155
    42   fclearlockfile (ImageCat, f, LCK_HARD, &dbstate);
     56  fclearlockfile (ImageCat, f, LOCK, &dbstate);
    4357  mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    4458  chmod (ImageCat, mode);
  • trunk/Ohana/src/addstar/src/load_pt_catalog.c

    r3361 r3376  
    33int load_pt_catalog (Catalog *catalog, GSCRegion *region) {
    44 
     5  check_permissions (region[0].filename);
     6
    57  /* don't free region before catalog! */
    68  catalog[0].filename = region[0].filename;
     
    1113    /* catalog file is locked.  this is an unexpected error because
    1214       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);
    1416    exit (1);
    1517  case 1:
  • trunk/Ohana/src/addstar/src/load_subpix.c

    r3339 r3376  
    1919
    2020  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
    2523  for (i = 0; i < Nsubpix; i++) {
    2624    fscanf (f, "%*s %*s %lf %lf %lf %*s\n",
  • trunk/Ohana/src/addstar/src/replace_match.c

    r3361 r3376  
    33int replace_match (Average *average, Measure *measure, Stars *star) {
    44
     5  int i;
     6
    57  if (!REPLACE) return (FALSE);
    68
    79  /** 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     stars[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;
    1517    return (TRUE);
    1618  }
  • trunk/Ohana/src/addstar/src/sort_lists.c

    r3339 r3376  
     1# include "addstar.h"
    12
    2 void sort_GSCregions (GSCRegion *region, int Nregion) {
     3void 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
     37void sort_regions (GSCRegion *region, int N) {
    338
    439  int l,j,ir,i;
     
    1146      l--;
    1247      tmp = region[l];
    13     }
    14     else {
     48    } else {
    1549      tmp = region[ir];
    1650      region[ir] = region[0];
     
    2357    j = (l << 1) + 1;
    2458    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]) {
    2761        region[i] = region[j];
    2862        j += (i=j) + 1;
     
    4781      tY = Y[l];
    4882      tS = S[l];
    49     }
    50     else {
     83    } else {
    5184      tX = X[ir];
    5285      X[ir] = X[0];
     
    91124      l--;
    92125      tX = X[l];
    93     }
    94     else {
     126    } else {
    95127      tX = X[ir];
    96128      X[ir] = X[0];
  • trunk/Ohana/src/addstar/src/update_coords.c

    r3361 r3376  
    44void update_coords (Average *average, Measure *measure, int *next) {
    55
     6  int i, m, Npt;
    67  double R, D, r, d;
    78  double r2, d2, dR2, dD2;
    8   int Npt;
    99
    1010  Npt = r = d = r2 = d2 = 0;
     
    1414  /* find the average & sum-square */
    1515  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++) {
    1717    if (measure[m].t == 0) {
    1818      m = next[m];
     
    3636  average[0].D -= d / 360000.0;
    3737  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++) {
    3939    measure[m].dR -= r;
    4040    measure[m].dD -= d;
Note: See TracChangeset for help on using the changeset viewer.