IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38553


Ignore:
Timestamp:
Jun 25, 2015, 10:41:05 PM (11 years ago)
Author:
eugene
Message:

merge changes from branches/eam_branches/ipp-20150616

Location:
trunk/Ohana/src
Files:
2 deleted
104 edited
18 copied

Legend:

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

    r38467 r38553  
    2424sedstar      : $(BIN)/sedstar.$(ARCH)
    2525load2mass    : $(BIN)/load2mass.$(ARCH)
     26loadgalphot  : $(BIN)/loadgalphot.$(ARCH)
    2627loadstarpar  : $(BIN)/loadstarpar.$(ARCH)
    2728loadstarpar_client : $(BIN)/loadstarpar_client.$(ARCH)
     
    3637mkcmf        : $(BIN)/mkcmf.$(ARCH)
    3738
    38 all: addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadtycho loadsupercos dumpskycells findskycell
    39 
    40 INSTALL = addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadtycho loadsupercos dumpskycells findskycell
     39# programs in 'OTHERS' have not been updated since moving from Stars to Catalog as an internal carrier
     40# programs in 'SERVER' use the client-server concept and are out of date
     41
     42INSTALL = addstar sedstar loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf dumpskycells findskycell
     43OTHERS  = load2mass loadwise loadtycho loadsupercos
     44SERVER  = addstar_client addstarc addstard addstart
     45
     46old: $(OTHERS)
     47all: $(INSTALL)
    4148
    4249# I need to fix the client/server version of addstar now that I have dropped Stars
    4350# as an autocode type and have converted to carrying average and measure
    44 # all: addstar addstarc addstard addstart sedstar load2mass skycells
     51# all: addstar sedstar load2mass skycells
     52
     53# $(SRC)/find_matches.$(ARCH).o \
     54# $(SRC)/find_matches_closest.$(ARCH).o \
     55# $(SRC)/find_matches_refstars.$(ARCH).o \
     56# $(SRC)/find_matches_closest_refstars.$(ARCH).o \
     57# $(SRC)/find_subset.$(ARCH).o \
     58# $(SRC)/getgsc.$(ARCH).o \
     59# $(SRC)/getusno.$(ARCH).o \
     60# $(SRC)/getusnob.$(ARCH).o \
     61# $(SRC)/greference.$(ARCH).o \
     62# $(SRC)/grefstars.$(ARCH).o \
     63# $(SRC)/dump.$(ARCH).o \
     64# $(SRC)/ReadStarsTEXT.$(ARCH).o \
     65# $(SRC)/StarOps.$(ARCH).o \
     66# $(SRC)/replace_match.$(ARCH).o \
     67#
    4568
    4669ADDSTAR = \
     
    5679$(SRC)/build_links.$(ARCH).o \
    5780$(SRC)/calibrate.$(ARCH).o \
    58 $(SRC)/dump.$(ARCH).o \
    5981$(SRC)/edge_check.$(ARCH).o \
    6082$(SRC)/fakeimage.$(ARCH).o \
    6183$(SRC)/find_matches.$(ARCH).o \
    6284$(SRC)/find_matches_closest.$(ARCH).o \
    63 $(SRC)/find_matches_refstars.$(ARCH).o \
    64 $(SRC)/find_matches_closest_refstars.$(ARCH).o \
    65 $(SRC)/find_subset.$(ARCH).o \
    66 $(SRC)/getgsc.$(ARCH).o \
    67 $(SRC)/getusno.$(ARCH).o \
    68 $(SRC)/getusnob.$(ARCH).o \
    69 $(SRC)/greference.$(ARCH).o \
    70 $(SRC)/grefstars.$(ARCH).o \
    7185$(SRC)/GetZeroPointExposure.$(ARCH).o \
     86$(SRC)/LoadFilenames.$(ARCH).o \
    7287$(SRC)/LoadStars.$(ARCH).o \
    7388$(SRC)/LoadHeaders.$(ARCH).o \
     
    8196$(SRC)/opening_angle.$(ARCH).o \
    8297$(SRC)/parse_time.$(ARCH).o \
    83 $(SRC)/replace_match.$(ARCH).o \
    8498$(SRC)/resort_catalogs.$(ARCH).o \
    8599$(SRC)/resort_threaded.$(ARCH).o \
    86100$(SRC)/resort_unthreaded.$(ARCH).o \
    87101$(SRC)/resort_catalog.$(ARCH).o \
    88 $(SRC)/StarOps.$(ARCH).o \
    89102$(SRC)/ReadStarsFITS.$(ARCH).o \
    90 $(SRC)/ReadStarsTEXT.$(ARCH).o \
    91103$(SRC)/ReadStarsSDSS.$(ARCH).o \
    92104$(SRC)/ReadStarsUKIRT.$(ARCH).o \
     
    100112$(SRC)/update_coords.$(ARCH).o \
    101113$(SRC)/psps_ids.$(ARCH).o
     114
     115##
    102116
    103117# this is the client for parallel operations
     
    244258$(SRC)/psps_ids.$(ARCH).o
    245259
     260LOAD-GALPHOT = \
     261$(SRC)/loadgalphot.$(ARCH).o \
     262$(SRC)/ConfigInit.$(ARCH).o \
     263$(SRC)/SetSignals.$(ARCH).o \
     264$(SRC)/Shutdown.$(ARCH).o \
     265$(SRC)/args_loadgalphot.$(ARCH).o \
     266$(SRC)/find_matches_galphot.$(ARCH).o \
     267$(SRC)/loadgalphot_catalog.$(ARCH).o \
     268$(SRC)/loadgalphot_make_subset.$(ARCH).o \
     269$(SRC)/loadgalphot_readstars.$(ARCH).o \
     270$(SRC)/loadgalphot_fit2d.$(ARCH).o \
     271$(SRC)/loadgalphot_join.$(ARCH).o \
     272$(SRC)/loadgalphot_table.$(ARCH).o \
     273$(SRC)/strhash.$(ARCH).o \
     274$(SRC)/sortIDs.$(ARCH).o \
     275$(SRC)/psps_ids.$(ARCH).o
     276
     277# $(SRC)/SkyRegionUtils.$(ARCH).o
     278# $(SRC)/loadstarpar_io.$(ARCH).o
     279# $(SRC)/loadgalphot_remote_hosts.$(ARCH).o
     280# $(SRC)/loadgalphot_save_remote.$(ARCH).o
     281
    246282LOAD-STARPAR = \
    247283$(SRC)/loadstarpar.$(ARCH).o \
     
    338374$(SRC)/find_matches_closest_refstars.$(ARCH).o \
    339375$(SRC)/build_links.$(ARCH).o \
    340 $(SRC)/replace_match.$(ARCH).o \
    341376$(SRC)/SetSignals.$(ARCH).o \
    342377$(SRC)/update_coords.$(ARCH).o \
     
    404439$(FINDSKYCELL)         : $(INC)/addstar.h
    405440$(LOAD-2MASS)          : $(INC)/addstar.h $(INC)/2mass.h
     441$(LOAD-GALPHOT)        : $(INC)/addstar.h $(INC)/loadgalphot.h
    406442$(LOAD-STARPAR)        : $(INC)/addstar.h $(INC)/loadstarpar.h
    407443$(LOAD-STARPAR-CLIENT) : $(INC)/addstar.h $(INC)/loadstarpar.h
     
    421457$(BIN)/loadwise.$(ARCH)       : $(LOAD-WISE)
    422458$(BIN)/loadtycho.$(ARCH)      : $(LOAD-TYCHO)
     459$(BIN)/loadgalphot.$(ARCH)    : $(LOAD-GALPHOT)
    423460$(BIN)/loadstarpar.$(ARCH)    : $(LOAD-STARPAR)
    424461$(BIN)/loadstarpar_client.$(ARCH) : $(LOAD-STARPAR-CLIENT)
  • trunk/Ohana/src/addstar/include/addstar.h

    r38467 r38553  
    3333
    3434# define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
     35
     36// things that are needed for a single file
     37typedef struct {
     38  char *filename;  // name of the file on disk (full path)
     39  char *imagename; // name of the image for user reference (eg, base of neb path, full path, etc)
     40} AddstarFile;
    3541
    3642typedef struct {
     
    4450} HeaderSet;
    4551
     52# if (0)
    4653typedef struct {
    4754  Average  average;
     
    6168  char *refcat;
    6269} DVO_DATA;
     70# endif
    6371
    6472# define IDTYPE int
     
    190198AddstarClientOptions args                 PROTO((int argc, char **argv, AddstarClientOptions options));
    191199AddstarClientOptions args_parallel_client PROTO((int argc, char **argv, AddstarClientOptions options));
     200void FreeConfig PROTO((void));
    192201
    193202void       AddToCalibration       PROTO((Average *average, SecFilt *secfilt, Measure *measure, Measure *new, off_t *next, off_t Nstar));
     
    205214SkyTable  *SkyTableFromTychoIndex PROTO((char *filename, int VERBOSE));
    206215void       check_permissions      PROTO((char *basefile));
    207 int        dump_rawstars          PROTO((Stars *stars, unsigned int Nstars));
    208216int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
    209217Image     *fakeimage              PROTO((char *rootname, off_t *Nimage, int photcode));
    210218
    211 int        find_matches                  PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
    212 int        find_matches_closest          PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
     219double     get_subpix             PROTO((double x, double y));
     220
     221int        find_matches_closest   PROTO((SkyRegion *region, Catalog *newcat, Catalog *catalog, AddstarClientOptions options));
     222int        find_matches           PROTO((SkyRegion *region, Catalog *newcat, Catalog *catalog, AddstarClientOptions options));
     223
     224# if (0)
    213225int        find_matches_refstars         PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
    214226int        find_matches_closest_refstars PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
     227
     228int        dump_rawstars          PROTO((Stars *stars, unsigned int Nstars));
    215229
    216230Stars    **find_subset            PROTO((SkyRegion *region, Stars *stars, unsigned int Nstars, unsigned int *NSTARS));
    217231int        gcatalog               PROTO((Catalog *catalog));
    218232Stars     *get2mass               PROTO((SkyRegion *patch, int photcode, int mode, unsigned int *NSTARS));
    219 double     get_subpix             PROTO((double x, double y));
    220233
    221234Stars     *greference             PROTO((char *Refcat, SkyRegion *catstats, int photcode, unsigned int *nstars));
     
    227240Stars     *grefstars              PROTO((char *file, int photcode, unsigned int *Nstars));
    228241
    229 Stars     *LoadStars              PROTO((char *file, unsigned int *Nstars, Image **images, off_t *Nimages, AddstarClientOptions *options));
     242Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
     243
     244int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
     245# endif
     246
     247Catalog   *LoadStars              PROTO((char *file, Image **images, off_t *Nimages, AddstarClientOptions *options));
    230248Header   **LoadHeaders            PROTO((FILE *f, int *mode, int *Nheader));
    231249HeaderSet *MatchHeaders           PROTO((off_t **extsize, off_t *nimage, int mode, Header **headers, int Nheaders));
    232 int        LoadData               PROTO((FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
     250void       HeaderSetFree          PROTO((HeaderSet *headerSets, off_t NheaderSets));
     251Catalog   *LoadData               PROTO((FILE *f, AddstarFile *file, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, int NheaderSets, AddstarClientOptions *options));
    233252int        GetZeroPointExposure   PROTO((Header **headers, HeaderSet *headerSets, off_t Nimages));
    234253
     
    240259double     opening_angle          PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
    241260int        parse_time             PROTO((Header *header));
    242 Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
    243 int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
    244261int        resort_catalogs        PROTO((AddstarClientOptions *options, SkyTable *sky));
    245262int        resort_catalogs_parallel PROTO((AddstarClientOptions *options, SkyList *sky));
     
    249266void       resort_catalog_old     PROTO((Catalog *catalog));
    250267
    251 Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
    252 Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
    253 Stars     *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars));
     268// Stars  *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
     269
    254270int        ReadImageHeader        PROTO((Header *header, Image *image, int photcode));
    255 Stars     *FilterStars            PROTO((Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options));
    256 Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
    257 
    258 int        ReadXradFITS           PROTO((FILE *f, Header *theader, Stars *stars, unsigned int Nstars));
     271
     272Catalog   *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader));
     273Catalog   *FilterStars            PROTO((Catalog *newcat, Image *image, unsigned int imageID, const AddstarClientOptions *options));
     274int        ReadXradFITS           PROTO((FILE *f, Header *theader, Catalog *catalog));
     275
     276Catalog   *LoadDataSDSS           PROTO((FILE *f, char *file, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages));
     277Catalog   *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages));
    259278
    260279double     scat_subpix            PROTO((double x, double y));
     
    276295AddstarClientOptions args_load2mass PROTO((int argc, char **argv, AddstarClientOptions options));
    277296AddstarClientOptions args_sedstar PROTO((int argc, char **argv, AddstarClientOptions options));
     297
     298SkyList   *SkyListExistingSubset  PROTO((SkyList *input, char *path));
     299
     300// these are all for the addstar client/server which has not been maintained
     301# if (0)
    278302void       args_server            PROTO((int argc, char **argv));
    279303int        CheckPassword          PROTO((int BindSocket));
     
    288312int        UpdateDatabase_Refcat  PROTO((AddstarClientOptions *options, SkyRegion *UserPatch, char *refcat));
    289313SkyList   *SkyListForStars        PROTO((SkyTable *table, int depth, Stars *stars, unsigned int Nstars));
    290 SkyList   *SkyListExistingSubset  PROTO((SkyList *input, char *path));
    291314int        SkyListSetPath         PROTO((SkyList *list, char *path));
    292315int        InitDataset            PROTO((void));
     
    297320int        NewRefcat_Thread       PROTO((int BindSocket));
    298321int        NewReflist_Thread      PROTO((int BindSocket));
    299 
    300 int        InitStar               PROTO((Stars *star));
     322# endif
    301323
    302324int args_skycells (int argc, char **argv);
    303325int ConfigInit_skycells (int *argc, char **argv);
    304 int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages);
     326int UpdateImageIDs (Catalog *catalog, Image *images, off_t Nimages);
    305327
    306328int CheckDuplicateImageIDs (Image *images, off_t Nimages);
    307329int ImageIndexFileInit ();
    308330
    309 int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages);
    310 int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars);
     331Catalog *LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid);
    311332
    312333PhotCode *LoadMetadataPMM (char *datafile, Image *image);
     
    330351void saveMosaicCoords (Coords *input);
    331352
    332 
    333 Stars *ReadStarsUKIRT (FILE *f, char *name, Header *header, Image *images, off_t *nimages, unsigned int *nstars);
    334 int LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets);
     353Catalog *ReadStarsUKIRT (FILE *f, char *name, Header *header, Image *images, off_t *nimages);
     354Catalog *LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets);
     355
     356AddstarFile *LoadFilenames (int *nfile, char *filename, AddstarClientOptions *options);
     357void AddstarFileFree (AddstarFile *file, int Nfile);
     358
     359Catalog *addstar_catalog_init (int Nstars);
    335360
    336361/**
  • trunk/Ohana/src/addstar/src/ConfigInit.c

    r38441 r38553  
    224224  }
    225225
     226  FreeConfigFile();
    226227  free (config);
    227228  free (file);
     
    240241  return;
    241242}
     243
     244void FreeConfig (void) {
     245  FREE (CATDIR);
     246}
  • trunk/Ohana/src/addstar/src/FilterStars.c

    r38467 r38553  
    1010// the imageID supplied here is the sequence **within this set**
    1111// this value is updated based on the image table later (in UpdateImageIDs)
    12 Stars *FilterStars (Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options) {
     12Catalog *FilterStars (Catalog *newcat, Image *image, unsigned int imageID, const AddstarClientOptions *options) {
    1313
    1414  int j, N;
    1515  float MTIME, dMs, dMx;
    16   Stars *stars;
    1716  float RMIN, RMAX, DMIN, DMAX;
    1817
     
    2625
    2726  /* modify resulting star list */
    28   ALLOCATE (stars, Stars, image[0].nstar);
    29   for (N = j = 0; j < image[0].nstar; j++) {
    30 
    31     if (instars[j].measure.photFlags & options->detectionFilter) continue;
     27  Catalog *outcat = addstar_catalog_init (newcat->Nmeasure);
     28  ALLOCATE (outcat->average, Average, newcat->Nmeasure);
     29  if (newcat->lensing) {
     30    ALLOCATE (outcat->lensing, Lensing, newcat->Nlensing);
     31  }
     32 
     33  for (N = j = 0; j < newcat->Nmeasure; j++) {
     34
     35    if (newcat->measure[j].photFlags & options->detectionFilter) continue;
    3236
    3337    /* allow for some dynamic filtering of star list */
    34     if (SNLIMIT && instars[j].measure.dM > SNLIMIT) continue;
    35     if (XMAX && (instars[j].measure.Xccd > XMAX)) continue;
    36     if (XMIN && (instars[j].measure.Xccd < XMIN)) continue;
    37     if (YMAX && (instars[j].measure.Yccd > YMAX)) continue;
    38     if (YMIN && (instars[j].measure.Yccd < YMIN)) continue;
    39     if (PHOTFLAG_EXCLUDE && (instars[j].measure.photFlags & PHOTFLAG_EXCLUDE)) continue;
    40 
    41     stars[N] = instars[j];
    42 
    43     XY_to_RD (&stars[N].average.R, &stars[N].average.D, stars[N].measure.Xccd, stars[N].measure.Yccd, &image[0].coords);
    44     stars[N].average.R = ohana_normalize_angle (stars[N].average.R);
    45     stars[N].measure.R = stars[N].average.R;
    46     stars[N].measure.D = stars[N].average.D;
    47 
    48     stars[N].measure.photcode = image[0].photcode;
     38    if (SNLIMIT && newcat->measure[j].dM > SNLIMIT) continue;
     39    if (XMAX && (newcat->measure[j].Xccd > XMAX)) continue;
     40    if (XMIN && (newcat->measure[j].Xccd < XMIN)) continue;
     41    if (YMAX && (newcat->measure[j].Yccd > YMAX)) continue;
     42    if (YMIN && (newcat->measure[j].Yccd < YMIN)) continue;
     43    if (PHOTFLAG_EXCLUDE && (newcat->measure[j].photFlags & PHOTFLAG_EXCLUDE)) continue;
     44
     45    dvo_average_init (&outcat->average[N]);
     46    outcat->measure[N] = newcat->measure[j];
     47
     48    if (newcat->lensing) {
     49      outcat->lensing[N] = newcat->lensing[j];
     50      outcat->average[N].Nlensing = 1;
     51      outcat->average[N].lensingOffset = N;
     52    }
     53
     54    outcat->average[N].Nmeasure = 1;
     55    outcat->average[N].measureOffset = N;
     56
     57    XY_to_RD (&outcat->average[N].R, &outcat->average[N].D, outcat->measure[N].Xccd, outcat->measure[N].Yccd, &image[0].coords);
     58    outcat->average[N].R = ohana_normalize_angle (outcat->average[N].R);
     59    outcat->measure[N].R = outcat->average[N].R;
     60    outcat->measure[N].D = outcat->average[N].D;
     61
     62    outcat->measure[N].photcode = image[0].photcode;
    4963
    5064    // determine the full coverage of this set of measurements
    51     RMIN = MIN (RMIN, stars[N].average.R);
    52     RMAX = MAX (RMAX, stars[N].average.R);
    53     DMIN = MIN (DMIN, stars[N].average.D);
    54     DMAX = MAX (DMAX, stars[N].average.D);
     65    RMIN = MIN (RMIN, outcat->average[N].R);
     66    RMAX = MAX (RMAX, outcat->average[N].R);
     67    DMIN = MIN (DMIN, outcat->average[N].D);
     68    DMAX = MAX (DMAX, outcat->average[N].D);
    5569
    5670    /** additional quantities to supply to Stars based on the image data **/
    5771
    5872    /* calculate accurate per-star airmass and azimuth */
    59     stars[N].measure.airmass = airmass (image[0].secz, stars[N].average.R, stars[N].average.D, image[0].sidtime, image[0].latitude);
    60     stars[N].measure.az      = azimuth (15.0*image[0].sidtime - stars[N].average.R, stars[N].average.D, image[0].latitude);
    61     stars[N].measure.Mcal    = image[0].Mcal;
    62     stars[N].measure.t       = image[0].tzero + 1e-4*stars[N].measure.Yccd*image[0].trate;  /* trate is in 0.1 msec / row */
    63     stars[N].measure.dt      = MTIME;
     73    outcat->measure[N].airmass = airmass (image[0].secz, outcat->average[N].R, outcat->average[N].D, image[0].sidtime, image[0].latitude);
     74    outcat->measure[N].az      = azimuth (15.0*image[0].sidtime - outcat->average[N].R, outcat->average[N].D, image[0].latitude);
     75    outcat->measure[N].Mcal    = image[0].Mcal;
     76    outcat->measure[N].t       = image[0].tzero + 1e-4*outcat->measure[N].Yccd*image[0].trate;  /* trate is in 0.1 msec / row */
     77    outcat->measure[N].dt      = MTIME;
    6478
    6579    // watch out for any strange values:
    66     if ((stars[N].measure.M > 25.0) && (stars[N].measure.M < 32.0)) {
     80    if ((outcat->measure[N].M > 25.0) && (outcat->measure[N].M < 32.0)) {
    6781      fprintf (stderr, "*");
    6882    }
     
    7387    dMx = 0.0;
    7488    if (SUBPIX) {
    75       dMs =  get_subpix (stars[N].measure.Xccd, stars[N].measure.Yccd);
    76       dMx = scat_subpix (stars[N].measure.Xccd, stars[N].measure.Yccd);
    77       if (!isnan(stars[N].measure.dM)) {
    78         stars[N].measure.dM = hypot (stars[N].measure.dM, dMx);
     89      dMs =  get_subpix (outcat->measure[N].Xccd, outcat->measure[N].Yccd);
     90      dMx = scat_subpix (outcat->measure[N].Xccd, outcat->measure[N].Yccd);
     91      if (!isnan(outcat->measure[N].dM)) {
     92        outcat->measure[N].dM = hypot (outcat->measure[N].dM, dMx);
    7993      }
    8094    }
    8195
    82     if (!isnan(stars[N].measure.M)) {
    83       stars[N].measure.M   += MTIME - dMs;
    84     }
    85     if (!isnan(stars[N].measure.Map)) {
    86       stars[N].measure.Map += MTIME - dMs;
    87     }
    88     if (!isnan(stars[N].measure.Mkron)) {
    89       stars[N].measure.Mkron += MTIME - dMs;
    90     }
    91     if (!isnan(stars[N].measure.FluxPSF)) {
    92       stars[N].measure.FluxPSF /= image[0].exptime;
    93     }
    94     if (!isnan(stars[N].measure.dFluxPSF)) {
    95       stars[N].measure.dFluxPSF /= image[0].exptime;
    96     }
    97     if (!isnan(stars[N].measure.FluxKron)) {
    98       stars[N].measure.FluxKron /= image[0].exptime;
    99     }
    100     if (!isnan(stars[N].measure.dFluxKron)) {
    101       stars[N].measure.dFluxKron /= image[0].exptime;
    102     }
    103     if (!isnan(stars[N].measure.FluxAp)) {
    104       stars[N].measure.FluxAp /= image[0].exptime;
    105     }
    106     if (!isnan(stars[N].measure.dFluxAp)) {
    107       stars[N].measure.dFluxAp /= image[0].exptime;
    108     }
    109     if (stars[N].lensing) {
    110       if (!isnan(stars[N].lensing-> F_ApR5)) stars[N].lensing-> F_ApR5 /= image[0].exptime;
    111       if (!isnan(stars[N].lensing->dF_ApR5)) stars[N].lensing->dF_ApR5 /= image[0].exptime;
    112       if (!isnan(stars[N].lensing->sF_ApR5)) stars[N].lensing->sF_ApR5 /= image[0].exptime;
    113       if (!isnan(stars[N].lensing->fF_ApR5)) stars[N].lensing->fF_ApR5 /= image[0].exptime;
    114 
    115       if (!isnan(stars[N].lensing-> F_ApR6)) stars[N].lensing-> F_ApR6 /= image[0].exptime;
    116       if (!isnan(stars[N].lensing->dF_ApR6)) stars[N].lensing->dF_ApR6 /= image[0].exptime;
    117       if (!isnan(stars[N].lensing->sF_ApR6)) stars[N].lensing->sF_ApR6 /= image[0].exptime;
    118       if (!isnan(stars[N].lensing->fF_ApR6)) stars[N].lensing->fF_ApR6 /= image[0].exptime;
    119 
    120       if (!isnan(stars[N].lensing-> F_ApR7)) stars[N].lensing-> F_ApR7 /= image[0].exptime;
    121       if (!isnan(stars[N].lensing->dF_ApR7)) stars[N].lensing->dF_ApR7 /= image[0].exptime;
    122       if (!isnan(stars[N].lensing->sF_ApR7)) stars[N].lensing->sF_ApR7 /= image[0].exptime;
    123       if (!isnan(stars[N].lensing->fF_ApR7)) stars[N].lensing->fF_ApR7 /= image[0].exptime;
     96    if (!isnan(outcat->measure[N].M)) {
     97      outcat->measure[N].M   += MTIME - dMs;
     98    }
     99    if (!isnan(outcat->measure[N].Map)) {
     100      outcat->measure[N].Map += MTIME - dMs;
     101    }
     102    if (!isnan(outcat->measure[N].Mkron)) {
     103      outcat->measure[N].Mkron += MTIME - dMs;
     104    }
     105    if (!isnan(outcat->measure[N].FluxPSF)) {
     106      outcat->measure[N].FluxPSF /= image[0].exptime;
     107    }
     108    if (!isnan(outcat->measure[N].dFluxPSF)) {
     109      outcat->measure[N].dFluxPSF /= image[0].exptime;
     110    }
     111    if (!isnan(outcat->measure[N].FluxKron)) {
     112      outcat->measure[N].FluxKron /= image[0].exptime;
     113    }
     114    if (!isnan(outcat->measure[N].dFluxKron)) {
     115      outcat->measure[N].dFluxKron /= image[0].exptime;
     116    }
     117    if (!isnan(outcat->measure[N].FluxAp)) {
     118      outcat->measure[N].FluxAp /= image[0].exptime;
     119    }
     120    if (!isnan(outcat->measure[N].dFluxAp)) {
     121      outcat->measure[N].dFluxAp /= image[0].exptime;
     122    }
     123    if (outcat->lensing) {
     124      // correct things which scale like exptime with the exptime
     125      if (!isnan(outcat->lensing[N]. F_ApR5)) outcat->lensing[N]. F_ApR5 /= image[0].exptime;
     126      if (!isnan(outcat->lensing[N].dF_ApR5)) outcat->lensing[N].dF_ApR5 /= image[0].exptime;
     127      if (!isnan(outcat->lensing[N].sF_ApR5)) outcat->lensing[N].sF_ApR5 /= image[0].exptime;
     128      if (!isnan(outcat->lensing[N]. F_ApR6)) outcat->lensing[N]. F_ApR6 /= image[0].exptime;
     129      if (!isnan(outcat->lensing[N].dF_ApR6)) outcat->lensing[N].dF_ApR6 /= image[0].exptime;
     130      if (!isnan(outcat->lensing[N].sF_ApR6)) outcat->lensing[N].sF_ApR6 /= image[0].exptime;
     131      if (!isnan(outcat->lensing[N]. F_ApR7)) outcat->lensing[N]. F_ApR7 /= image[0].exptime;
     132      if (!isnan(outcat->lensing[N].dF_ApR7)) outcat->lensing[N].dF_ApR7 /= image[0].exptime;
     133      if (!isnan(outcat->lensing[N].sF_ApR7)) outcat->lensing[N].sF_ApR7 /= image[0].exptime;
    124134    }
    125135   
    126136    // the external ID is supplied, but do we trust it?
    127137    if (!EXTERNAL_ID) {
    128       stars[N].measure.detID = N; // sequence number within image
     138      outcat->measure[N].detID = N; // sequence number within image
    129139    }
    130140
     
    135145
    136146      if (isStack) {
    137         stars[N].measure.extID = CreatePSPSStackDetectionID(image[0].sourceID, image[0].externID, stars[N].measure.detID);
     147        outcat->measure[N].extID = CreatePSPSStackDetectionID(image[0].sourceID, image[0].externID, outcat->measure[N].detID);
    138148      } else {
    139         stars[N].measure.extID = CreatePSPSDetectionID(mjd, image[0].ccdnum, stars[N].measure.detID);
     149        outcat->measure[N].extID = CreatePSPSDetectionID(mjd, image[0].ccdnum, outcat->measure[N].detID);
    140150      }
    141151    } else {
    142       stars[N].measure.extID = 0;
    143     }
    144 
    145     stars[N].measure.imageID = imageID; // this value is updated in UpdateImageIDs
     152      outcat->measure[N].extID = 0;
     153    }
     154
     155    outcat->measure[N].imageID = imageID; // this value is updated in UpdateImageIDs
    146156
    147157    // add imageID to lensing entry, if it exists
    148     if (stars[N].lensing) {
    149       stars[N].lensing->imageID = imageID;
     158    if (outcat->lensing) {
     159      outcat->lensing[N].imageID = imageID;
    150160    }
    151161
     
    156166 
    157167  image[0].nstar = N;
    158   REALLOCATE (stars, Stars, image[0].nstar);
    159   free (instars);
    160 
    161   if (VERBOSE) fprintf (stderr, "read %d stars from target file\n", image[0].nstar);
     168
     169  REALLOCATE (outcat->measure, Measure, N);
     170  REALLOCATE (outcat->average, Average, N);
     171  if (outcat->lensing) {
     172    REALLOCATE (outcat->average, Average, N);
     173  }
     174  dvo_catalog_free (newcat);
     175  free (newcat);
     176
     177  outcat->Naverage = N;
     178  outcat->Nmeasure = N;
     179  outcat->Nlensing = outcat->lensing ? N : 0;
     180
     181  if (VERBOSE) fprintf (stderr, "read %d stars from target file\n", N);
    162182  if (VERBOSE) fprintf (stderr, "stars cover region %f,%f - %f,%f\n", RMIN, DMIN, RMAX, DMAX);
    163   return (stars);
     183
     184  return (outcat);
    164185}
    165186
     187# if (0)
    166188Stars *MergeStars (Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars) {
    167189
     
    181203  return (stars);
    182204}
     205# endif
  • trunk/Ohana/src/addstar/src/ImageIndex.c

    r35579 r38553  
    11# include "addstar.h"
     2
     3void ImageIndexFree (ImageIndex *index) {
     4  if (!index) return;
     5  FREE (index->externID);
     6  FREE (index->imageID);
     7  FREE (index->found);
     8  FREE (index);
     9}
    210
    311ImageIndex *ImageIndexLoad (char *filename) {
     
    1624  if (!f) {
    1725    fprintf (stderr, "ERROR: cannot open image index file %s\n", filename);
     26    FREE (index);
    1827    return NULL;
    1928  }
     
    2332    if (VERBOSE) fprintf (stderr, "can't read image index header\n");
    2433    fclose (f);
     34    FREE (index);
    2535    return NULL;
    2636  }
     
    2838    if (VERBOSE) fprintf (stderr, "can't read image index matrix\n");
    2939    gfits_free_header (&header);
    30     fclose (f);
    31     return NULL;
    32   }
    33 
     40    FREE (index);
     41    fclose (f);
     42    return NULL;
     43  }
    3444  ftable.header = &theader;
    3545
     
    3747  if (!gfits_load_header (f, &theader)) {
    3848    fclose (f);
     49    gfits_free_header (&header);
     50    FREE (index);
    3951    return NULL;
    4052  }
     
    4355  if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
    4456    fclose (f);
     57    gfits_free_header (&header);
     58    gfits_free_header (&theader);
     59    FREE (index);
    4560    return (NULL);
    4661  }
     
    7691  }
    7792
     93  gfits_free_header (&header);
     94  gfits_free_matrix (&matrix);
     95  gfits_free_header (&theader);
     96  gfits_free_table (&ftable);
     97
    7898  return index;
    7999}
     
    179199 
    180200  // extend the storage arrays
     201  // no reason to extend 'found'
    181202  REALLOCATE (index->imageID,  IDTYPE, index->Nimage + Nimages);
    182203  REALLOCATE (index->externID, IDTYPE, index->Nimage + Nimages);
     
    192213  // do this as an 'extend' operation
    193214  ImageIndexSave (filename, index);
     215  ImageIndexFree (index);
    194216  return TRUE;
    195217}
     
    205227  ALLOCATE (index->imageID,  IDTYPE, 1);
    206228  ALLOCATE (index->externID, IDTYPE, 1);
     229  ALLOCATE (index->found, char, 1);
    207230  index->Nimage = 0;
    208231
    209232  // do this as an 'extend' operation
    210233  ImageIndexSave (filename, index);
     234  ImageIndexFree (index);
    211235  return TRUE;
    212236}
  • trunk/Ohana/src/addstar/src/LoadData.c

    r37807 r38553  
    11# include "addstar.h"
    22
    3 // XXX this function is somewhat specific to the elixir format output files
    4 // it is capable of distinguishing several format versions defined for elixir/psphot
     3// load photometry data from psphot, sextractor, and a few other formats
     4// examine the header sets and set the Image entries for the the valid images
     5Catalog *LoadData (FILE *f, AddstarFile *file, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
    56
    6 // examine the header sets and set the Image entries for the the valid images
    7 int LoadData (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, int Nimages, AddstarClientOptions *options) {
    8 
    9   char *name;
    107  off_t Nskip, Nvalid, NVALID;
    118  int i, j, Nhead, Ndata;
    129  uint32_t parentID = UINT32_MAX;
    13   Stars *inStars;
     10
     11  Catalog *catalog = NULL;
     12  ALLOCATE (catalog, Catalog, 1);
     13  dvo_catalog_init (catalog, TRUE);
     14  ALLOCATE (catalog->average, Average, 1);
     15  ALLOCATE (catalog->measure, Measure, 1);
     16  ALLOCATE (catalog->lensing, Lensing, 1);
    1417
    1518  if (images[0] == NULL) {
     
    2225    REALLOCATE (images[0], Image, NVALID);
    2326  }   
    24 
    25   // find image rootname
    26   if (USE_NAME) {
    27       name = filebasename (USE_NAME);
    28   } else {
    29       name = filebasename (file);
    30   }
    3127
    3228  // if zero points are calculated for the full exposure using more than just the matched chip header,
     
    5854    // XXX use something to set the chip name? EXTNAME?
    5955    if (!strcmp(headerSets[i].exthead, "PHU") && (Nimages == 1)) {
    60       snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s", name);
     56      snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s", file->imagename);
    6157    } else {
    62       snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s[%s]", name, headerSets[i].exthead);
     58      snprintf (images[0][Nvalid].name, DVO_IMAGE_NAME_LEN, "%s[%s]", file->imagename, headerSets[i].exthead);
    6359    }
    6460
     
    8480    fseeko (f, Nskip, SEEK_SET);
    8581         
    86     inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar);
    87     if (!inStars) {
    88       // XXX need to free the data here or in ReadStarsFITS on error
    89       continue;
    90     }
     82    // ReadStarsFITS populates catalog->measure,Nmeasure
     83    Catalog *newcat = ReadStarsFITS (f, headers[Nhead], headers[Ndata]);
     84    if (!newcat) continue;
     85
     86    images[0][Nvalid].nstar = newcat->Nmeasure;
    9187
    9288    // XRAD : if we want to read the xrad table, skip to that table here:
     
    9995      fseeko (f, Nskip, SEEK_SET);
    10096     
    101       if (!ReadXradFITS (f, headers[Nxrad], inStars, images[0][Nvalid].nstar)) {
     97      if (!ReadXradFITS (f, headers[Nxrad], newcat)) {
    10298        fprintf (stderr, "problem reading the radial flux data for %s\n", headerSets[i].extdata);
    10399      }
    104100    }
    105101
    106     inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid, options);
    107     *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
     102    // replace full input catalog newcat with subset version
     103    newcat = FilterStars (newcat, &images[0][Nvalid], Nvalid, options);
     104
     105    double Rref, Dref;
     106    XY_to_RD (&Rref, &Dref, 0.0, 0.0, &images[0][Nvalid].coords);
     107    SkyRegion region;
     108    region.Rmin = Rref - 180.0;
     109    region.Rmax = Rref + 180.0;
     110    region.Dmin = Dref -  90.0;
     111    region.Dmax = Dref +  90.0;
     112   
     113    AddstarClientOptions matchOptions = *options;
     114    matchOptions.radius = 0.4; // tight radius at this stage
     115    matchOptions.calibrate = FALSE;
     116    matchOptions.only_match = FALSE;
     117    matchOptions.nosort = FALSE;
     118    matchOptions.photcode = 0; // use an invalid photcode to avoid touching secfilt
     119
     120    find_matches_closest (&region, newcat, catalog, matchOptions);
     121    dvo_catalog_free (newcat);
     122    free (newcat);
     123
    108124    Nvalid++;
    109125    CHECK_REALLOCATE (images[0], Image, NVALID, Nvalid, 10);
     
    111127
    112128  if (isfinite(OFFSET_ZPT)) {
    113     for (i = 0; i < *Nstars; i++) {
    114       stars[0][i].measure.M   += OFFSET_ZPT;
    115       stars[0][i].measure.Map += OFFSET_ZPT;
     129    for (i = 0; i < catalog->Nmeasure; i++) {
     130      catalog->measure[i].M   += OFFSET_ZPT;
     131      catalog->measure[i].Map += OFFSET_ZPT;
    116132    }
    117 
    118133  }
    119134
    120   free (name);
    121135  *nvalid = Nvalid;
    122   return (TRUE);
     136  return catalog;
    123137}
    124138
     139// thoughts:
     140// 1) I read the data from a single image file into a catalog structure (instead of Stars)
     141// 2) merge these into a single catalog here or in LoadData above?
  • trunk/Ohana/src/addstar/src/LoadDataPMM.c

    r37807 r38553  
    1515# define MAG_INDEX_ASC 22
    1616
    17 int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars) {
     17Catalog *LoadDataPMM (FILE *f, char *imagename, Image **images, off_t *nvalid) {
    1818
    1919  off_t Nvalid, NVALID;
    20   char *name, *buffer;
     20  char *buffer;
    2121  int i, fd, Nbyte, Nline, code;
    2222  double ra, dec, mag, airmass, az, ZeroPoint, ZeroPt;
    2323  unsigned int Ninstars, NINSTARS;
    24   Stars *inStars;
    2524  PhotCode *photcode;
    2625  gzFile gz;
     
    3837  }   
    3938
    40   // find image rootname
    41   name = filebasename (file);
    42 
    4339  // there is only one PMM image per file
    44   if (VERBOSE) fprintf (stderr, "reading data for %s\n", file);
     40  if (VERBOSE) fprintf (stderr, "reading data for %s\n", imagename);
    4541
    4642  ZeroPt = GetZeroPoint();
    4743
    4844  // need to get the metadata from the PMM_CCD_TABLE
    49   photcode = LoadMetadataPMM (name, &images[0][Nvalid]);
     45  photcode = LoadMetadataPMM (imagename, &images[0][Nvalid]);
    5046  code = photcode[0].code;
    5147  ZeroPoint = 0.001*photcode[0].C;
     
    6157
    6258  NINSTARS = 10000;
    63   ALLOCATE (inStars, Stars, NINSTARS);
     59  Catalog *catalog = addstar_catalog_init (NINSTARS);
     60  ALLOCATE (catalog->average, Average, NINSTARS);
     61  for (i = 0; i < NINSTARS; i++) {
     62    dvo_measure_init (&catalog->measure[i]);
     63    dvo_average_init (&catalog->average[i]);
     64  }
    6465
    6566  minR0 = minR1 = 360.0;
     
    8586      dparse (&dec, 2, &buffer[i*NBYTE_ASC_TABLE]);
    8687      dparse (&mag, 3, &buffer[i*NBYTE_ASC_TABLE]);
    87 
    88       InitStar (&inStars[Ninstars]);
    8988
    9089      if (ra > 180) {
     
    9897      maxD = MAX(maxD, dec);
    9998
    100       inStars[Ninstars].average.R        = ra;
    101       inStars[Ninstars].average.D        = dec;
    102 
    103       inStars[Ninstars].measure.M        = mag - ZeroPoint + ZeroPt;
    104       inStars[Ninstars].measure.t        = images[0][0].tzero;
    105       inStars[Ninstars].measure.dt       = images[0][0].exptime;
    106       inStars[Ninstars].measure.photcode = code;
    107       inStars[Ninstars].measure.airmass  = airmass;
    108       inStars[Ninstars].measure.az       = az;
     99      catalog->average[Ninstars].R        = ra;
     100      catalog->average[Ninstars].D        = dec;
     101      catalog->average[Ninstars].Nmeasure = 1;
     102      catalog->average[Ninstars].measureOffset = Ninstars;
     103
     104      catalog->measure[Ninstars].R        = ra;
     105      catalog->measure[Ninstars].D        = dec;
     106      catalog->measure[Ninstars].M        = mag - ZeroPoint + ZeroPt;
     107      catalog->measure[Ninstars].t        = images[0][0].tzero;
     108      catalog->measure[Ninstars].dt       = images[0][0].exptime;
     109      catalog->measure[Ninstars].photcode = code;
     110      catalog->measure[Ninstars].airmass  = airmass;
     111      catalog->measure[Ninstars].az       = az;
     112
     113      // imageID, detID ?
    109114
    110115      Ninstars++;
    111       CHECK_REALLOCATE (inStars, Stars, NINSTARS, Ninstars, 10000);
     116      if (Ninstars == NINSTARS) {
     117        NINSTARS += 10000;
     118        REALLOCATE (catalog->measure, Measure, NINSTARS);
     119        REALLOCATE (catalog->average, Average, NINSTARS);
     120        for (i = Ninstars; i < NINSTARS; i++) {
     121          dvo_measure_init (&catalog->measure[i]);
     122          dvo_average_init (&catalog->average[i]);
     123        }
     124      }
    112125    }
    113126  }
     127  catalog->Nmeasure = Ninstars;
     128  catalog->Naverage = Ninstars;
    114129
    115130  fprintf (stderr, "ra ranges: %f - %f, %f - %f; dec ranges: %f - %f\n", minR0, maxR0, minR1, maxR1, minD, maxD);
     
    118133  images[0][0].imageID = 0;
    119134
    120   *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
    121 
    122   free (inStars);
    123   free (name);
    124135  *nvalid = Nvalid + 1;
    125136
    126137  gzclose (gz);
    127138  free (buffer);
    128   return (TRUE);
     139
     140  return (catalog);
    129141}
    130142
  • trunk/Ohana/src/addstar/src/LoadDataSDSS.c

    r27435 r38553  
    44// there should only be a single data set (phu + table) in this file
    55// each SDSS data set corresponds to 5 images (ugriz)
    6 int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages) {
     6Catalog *LoadDataSDSS (FILE *f, char *imagename, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages) {
    77
    88  off_t Nskip, Nvalid, NVALID;
    9   char *name;
    109  int j, Nhead, Ndata;
    11   unsigned int Ninstars;
    12   Stars *inStars;
    1310
    1411  if (images[0] == NULL) {
     
    2118    REALLOCATE (images[0], Image, NVALID);
    2219  }   
    23 
    24   // find image rootname
    25   name = filebasename (file);
    2620
    2721  // there is only one SDSS image per file (TRUE?)
     
    3933  fseeko (f, Nskip, SEEK_SET);
    4034         
    41   // XXX I think this is an error?  should this be &images[0][Nvalid] ??
    42   inStars = ReadStarsSDSS (f, name, headers[Nhead], headers[Ndata], images[0], &Nvalid, &Ninstars);
    43   *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
     35  // we pass in images[0] so the function updates the end of the array
     36  Catalog *catalog = ReadStarsSDSS (f, imagename, headers[Nhead], headers[Ndata], images[0], &Nvalid);
    4437
    45   free (name);
    4638  *nvalid = Nvalid;
    47   return (TRUE);
     39  return (catalog);
    4840}
    4941
  • trunk/Ohana/src/addstar/src/LoadDataUKIRT.c

    r38467 r38553  
    33// examine the header sets and set the Image entries for the the valid images
    44// UKIRT data has the WCS/image metadata header intermixed with the bintable header
    5 int LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets) {
     5
     6int MergeCatalogs (Catalog *tgt, Catalog *src);
     7
     8Catalog *LoadDataUKIRT (FILE *f, char *imagename, Image **images, off_t *nimages, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets) {
    69
    710  off_t Nskip, Nvalid, NVALID;
    8   char *name;
    911  int i, j, Nhead, Ndata;
    10   unsigned int Ninstars;
    11   Stars *inStars;
     12
     13  Catalog *catalog = NULL;
     14  ALLOCATE (catalog, Catalog, 1);
     15  dvo_catalog_init (catalog, TRUE);
     16  ALLOCATE (catalog->average, Average, 1);
     17  ALLOCATE (catalog->measure, Measure, 1);
    1218
    1319  // create or update image table
     
    2127    REALLOCATE (images[0], Image, NVALID);
    2228  }   
    23 
    24   // find image rootname
    25   name = filebasename (file);
    2629
    2730  // validate the number of headers sets == 4
     
    3841    fseeko (f, Nskip, SEEK_SET);
    3942
    40     inStars = ReadStarsUKIRT (f, name, headers[Nhead], images[0], &Nvalid, &Ninstars);
    41     *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
     43    Catalog *newcat = ReadStarsUKIRT (f, imagename, headers[Nhead], images[0], &Nvalid);
     44    MergeCatalogs (catalog, newcat);
     45
     46    dvo_catalog_free (newcat);
     47    free (newcat);
    4248
    4349    *nimages = Nvalid;
    4450  }   
    45   return (TRUE);
     51  return (catalog);
    4652}
    4753
     54int MergeCatalogs (Catalog *tgt, Catalog *src) {
     55
     56  // this function assumes the src and tgt catalog do NOT overlap (otherwise just use find_match_closest)
     57
     58  off_t Naverage_tgt = tgt->Naverage;
     59  off_t Nmeasure_tgt = tgt->Nmeasure;
     60
     61  tgt->Naverage += src->Naverage;
     62  tgt->Nmeasure += src->Nmeasure;
     63
     64  REALLOCATE (tgt->average, Average, tgt->Naverage);
     65  REALLOCATE (tgt->measure, Measure, tgt->Nmeasure);
     66
     67  off_t i;
     68  for (i = 0; i < src->Naverage; i++) {
     69    tgt->average[i+Naverage_tgt] = src->average[i];
     70    tgt->average[i+Naverage_tgt].measureOffset += Nmeasure_tgt;
     71  }
     72
     73  for (i = 0; i < src->Nmeasure; i++) {
     74    tgt->measure[i+Nmeasure_tgt] = src->measure[i];
     75  }
     76
     77  return TRUE;
     78}
  • trunk/Ohana/src/addstar/src/LoadHeaders.c

    r38467 r38553  
    1717    status = gfits_fread_header (f, headers[i]);
    1818    if (!status) {
     19      gfits_free_header (headers[i]);
     20      FREE (headers[i]);
    1921      *Nheaders = i;
    2022      return (headers);
  • trunk/Ohana/src/addstar/src/LoadStars.c

    r38467 r38553  
    11# include "addstar.h"
    22
    3 Stars *LoadStars (char *filename, unsigned int *Nstars, Image **images, off_t *Nimages, AddstarClientOptions *options) {
     3Catalog *LoadStars (char *filename, Image **images, off_t *Nimages, AddstarClientOptions *options) {
    44
    5   off_t *extsize, NheaderSets;
    6   int i, Nfile, NFILE, Nheaders, mode;
    7   char **file, line[1024];
    8   FILE *f;
    9   glob_t globList;
    10   Header **headers;
    11   Stars *stars;
    12   HeaderSet *headerSets;
     5  off_t *extsize;
     6  int i, Nfile, mode;
    137
    14   if (options[0].filelist) {
    15     // read the list of input files from the supplied file
    16     f = fopen (filename, "r");
    17     if (f == NULL) {
    18       fprintf (stderr, "can't read input list %s, giving up\n", filename);
    19       exit (1);
    20     }
    21 
    22     NFILE = 10;
    23     ALLOCATE (file, char *, NFILE);
    24     for (i = 0; (fscanf (f, "%s", line) != EOF); i++) {
    25       // filename limited to 1024 chars
    26       fprintf (stderr, "file: %s\n", line);
    27       file[i] = strcreate (line);
    28       if (i == NFILE - 1) {
    29         NFILE += 10;
    30         REALLOCATE (file, char *, NFILE);
    31       }
    32     }
    33     Nfile = i;
    34   } else {
    35     // parse the filename as a glob
    36     globList.gl_offs = 0;
    37     glob (filename, 0, NULL, &globList);
    38 
    39     // if the glob does not match, save the literal word:
    40     // otherwise save all glob matches
    41     if (globList.gl_pathc == 0) {
    42       Nfile = 1;
    43       ALLOCATE (file, char *, Nfile);
    44       file[0] = strcreate (filename);
    45     } else {
    46       Nfile = globList.gl_pathc;
    47       ALLOCATE (file, char *, Nfile);
    48       for (i = 0; i < Nfile; i++) {
    49         file[i] = strcreate (globList.gl_pathv[i]);
    50       }
    51     }
    52   }
     8  AddstarFile *file = LoadFilenames (&Nfile, filename, options);
    539
    5410  *Nimages = 0;
    55   *Nstars = 0;
    5611  *images = NULL;
    57   stars = NULL;
     12
     13  Catalog *catalog = NULL;
     14  ALLOCATE (catalog, Catalog, 1);
     15  dvo_catalog_init (catalog, TRUE);
     16  ALLOCATE (catalog->average, Average, 1);
     17  ALLOCATE (catalog->measure, Measure, 1);
     18  ALLOCATE (catalog->lensing, Lensing, 1);
    5819
    5920  for (i = 0; i < Nfile; i++) {
    60     f = fopen (file[i], "r");
     21    FILE *f = fopen (file[i].filename, "r");
    6122    if (f == NULL) {
    62       fprintf (stderr, "can't read file %s, skipping\n", file[i]);
     23      fprintf (stderr, "can't read file %s, skipping\n", file[i].filename);
    6324      continue;
    6425    }
    6526
     27    int Nheaders = 0;
     28    Header **headers = NULL;
     29    off_t NheaderSets = 0;
     30    HeaderSet *headerSets = NULL;
     31
     32    off_t NimagesStart = *Nimages;
     33    Catalog *newcat = NULL;
     34
    6635    // load PMM data if specified (these are not stored as FITS-tables)
    6736    if (PMM_CCD_TABLE != NULL) {
    68       LoadDataPMM (f, file[i], images, Nimages, &stars, Nstars);
    69       continue;
     37      newcat = LoadDataPMM (f, file[i].imagename, images, Nimages);
     38      goto next_file;
    7039    }
    7140
     
    7443    headerSets = MatchHeaders (&extsize, &NheaderSets, mode, headers, Nheaders);
    7544    if (headerSets == NULL) {
    76       fprintf (stderr, "ERROR: can't read headers for %s\n", file[i]);
    77       continue;
     45      fprintf (stderr, "ERROR: can't read headers for %s\n", file[i].filename);
     46      goto next_file;
    7847    }
    7948    if (NheaderSets == 0) {
    80       fprintf (stderr, "no object data in file %s, skipping\n", file[i]);
    81       continue;
     49      fprintf (stderr, "no object data in file %s, skipping\n", file[i].filename);
     50      goto next_file;
    8251    }
    83     if (VERBOSE) fprintf (stderr, "file %s has %d headers, including "OFF_T_FMT" images\n", file[i], Nheaders,  NheaderSets);
     52    if (VERBOSE) fprintf (stderr, "file %s has %d headers, including "OFF_T_FMT" images\n", file[i].filename, Nheaders,  NheaderSets);
    8453
    8554    /* supplied photcode is incompatible with multi-chip images */
     
    9665    // if these are SDSS data, load with SDSS-specific wrapper
    9766    if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "SDSS_OBJ")) {
    98       LoadDataSDSS (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
    99       continue;
     67      newcat = LoadDataSDSS (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
     68      goto next_file;
    10069    }
    10170
    10271    // if these are SDSS data, load with SDSS-specific wrapper
    10372    if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "UKIRT_OBJ")) {
    104       LoadDataUKIRT (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
    105       continue;
     73      newcat = LoadDataUKIRT (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
     74      goto next_file;
    10675    }
    10776
    108     LoadData (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets, options);
     77    newcat = LoadData (f, &file[i], images, Nimages, headers, extsize, headerSets, NheaderSets, options);
    10978
    110     // XXX add a function to (optionally) load the extended source measurements
    111     # if (0)
    112     if (extSources) {
    113       // not sure how to link the measurements here to the psf measurements above (though there is an ID in the det list)
    114       LoadDataXSRC (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
     79  next_file:
     80
     81    // if we added data from an image, then we can merge it in
     82    if (*Nimages > NimagesStart) {
     83      double Rref, Dref;
     84      XY_to_RD (&Rref, &Dref, 0.0, 0.0, &images[0][*Nimages-1].coords);
     85      SkyRegion region;
     86      region.Rmin = Rref - 180.0;
     87      region.Rmax = Rref + 180.0;
     88      region.Dmin = Dref -  90.0;
     89      region.Dmax = Dref +  90.0;
     90     
     91      AddstarClientOptions matchOptions = *options;
     92      matchOptions.radius = 0.4; // tight radius at this stage
     93      matchOptions.calibrate = FALSE;
     94      matchOptions.only_match = FALSE;
     95      matchOptions.nosort = FALSE;
     96      matchOptions.photcode = 0; // use an invalid photcode to avoid touching secfilt
     97     
     98      find_matches_closest (&region, newcat, catalog, matchOptions);
    11599    }
    116     if (extFits) {
    117       LoadDataXFIT (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
     100
     101    if (newcat) {
     102      dvo_catalog_free (newcat);
     103      free (newcat);
    118104    }
    119     # endif
    120105
     106    HeaderSetFree (headerSets, NheaderSets);
     107    int j;
     108    for (j = 0; j < Nheaders; j++) {
     109      gfits_free_header (headers[j]);
     110      FREE (headers[j]);
     111    }
     112    FREE (headers);
     113    FREE (extsize);
    121114  }
    122115
     
    129122  }
    130123
    131   return stars;
     124  AddstarFileFree (file, Nfile);
     125  return catalog;
    132126}
    133127
  • trunk/Ohana/src/addstar/src/MatchHeaders.c

    r38467 r38553  
    22
    33// XXX largely psphot specific
     4
     5void HeaderSetFree (HeaderSet *headerSets, off_t NheaderSets) {
     6  int i;
     7
     8  if (!headerSets) return;
     9  for (i = 0; i < NheaderSets; i++) {
     10    FREE (headerSets[i].exthead);
     11    FREE (headerSets[i].exttype);
     12    FREE (headerSets[i].extdata);
     13    FREE (headerSets[i].extxrad);
     14  }
     15  FREE (headerSets);
     16}
    417
    518HeaderSet *MatchHeaders (off_t **extsize, off_t *nimage, int mode, Header **headers, int Nheaders) {
     
    2235    headerSets[Nimage].exthead     = strcreate ("PHU");
    2336    headerSets[Nimage].extdata     = strcreate ("NONE");
     37    headerSets[Nimage].exttype     = NULL;
     38    headerSets[Nimage].extxrad     = NULL;
    2439    headerSets[Nimage].extnum_data = -1;
    2540    headerSets[Nimage].extnum_head =  0;
     
    3449    headerSets[0].exttype     = strcreate ("SDSS_OBJ");
    3550    headerSets[0].exthead     = strcreate ("PHU");
     51    headerSets[0].extxrad     = NULL;
    3652    headerSets[0].extnum_head = 0;
    3753    headerSets[0].extnum_data = 1;
     
    112128
    113129  keep:
    114     headerSets[Nimage].exttype = strcreate (exttype);
    115 
    116130    gfits_scan (headers[i], ExtnameKeyword, "%s", 1, extname);
    117131    gfits_scan (headers[i], "EXTHEAD", "%s", 1, exthead);
    118132
     133    headerSets[Nimage].exttype     = strcreate (exttype);
    119134    headerSets[Nimage].extdata     = strcreate (extname);
    120135    headerSets[Nimage].exthead     = strcreate (exthead);
     
    171186      headerSets[Nimage].exttype     = strcreate ("SMPDATA");
    172187      headerSets[Nimage].exthead     = strcreate ("PHU");
     188      headerSets[Nimage].extxrad     = NULL;
    173189      headerSets[Nimage].extnum_head = 0;
    174190      headerSets[Nimage].extnum_data = 1;
  • trunk/Ohana/src/addstar/src/ReadStarsFITS.c

    r38441 r38553  
    44// (excluding SDSS data and reference database info, such as 2MASS)
    55// NOTE: these must also be listed in MatchHeaders.c (line ~ 62)
    6 Stars     *Convert_SMPDATA           PROTO((FTable *table, unsigned int *nstars));
    7 Stars     *Convert_PS1_DEV_0         PROTO((FTable *table, unsigned int *nstars));
    8 Stars     *Convert_PS1_DEV_1         PROTO((FTable *table, unsigned int *nstars));
    9 Stars     *Convert_PS1_V1            PROTO((FTable *table, unsigned int *nstars));
    10 Stars     *Convert_PS1_V1_Alt        PROTO((FTable *table, unsigned int *nstars));
    11 Stars     *Convert_PS1_V2            PROTO((FTable *table, unsigned int *nstars));
    12 Stars     *Convert_PS1_V3            PROTO((FTable *table, unsigned int *nstars));
    13 Stars     *Convert_PS1_V4            PROTO((FTable *table, unsigned int *nstars));
    14 Stars     *Convert_PS1_V5            PROTO((FTable *table, unsigned int *nstars));
    15 Stars     *Convert_PS1_V5_R0_Lensing PROTO((FTable *table, unsigned int *nstars));
    16 Stars     *Convert_PS1_V5_R1_Lensing PROTO((FTable *table, unsigned int *nstars));
    17 Stars     *Convert_PS1_V5_R2_Lensing PROTO((FTable *table, unsigned int *nstars));
    18 Stars     *Convert_PS1_SV1           PROTO((FTable *table, unsigned int *nstars));
    19 Stars     *Convert_PS1_SV1_Alt       PROTO((FTable *table, unsigned int *nstars));
    20 Stars     *Convert_PS1_SV2           PROTO((FTable *table, unsigned int *nstars));
    21 Stars     *Convert_PS1_SV3           PROTO((FTable *table, unsigned int *nstars));
    22 Stars     *Convert_PS1_SV4           PROTO((FTable *table, unsigned int *nstars));
    23 Stars     *Convert_PS1_DV3           PROTO((FTable *table, unsigned int *nstars));
    24 Stars     *Convert_PS1_DV4           PROTO((FTable *table, unsigned int *nstars));
    25 Stars     *Convert_PS1_DV5           PROTO((FTable *table, unsigned int *nstars));
     6Catalog *Convert_SMPDATA           PROTO((FTable *table));
     7Catalog *Convert_PS1_DEV_0         PROTO((FTable *table));
     8Catalog *Convert_PS1_DEV_1         PROTO((FTable *table));
     9Catalog *Convert_PS1_V1            PROTO((FTable *table));
     10Catalog *Convert_PS1_V1_Alt        PROTO((FTable *table));
     11Catalog *Convert_PS1_V2            PROTO((FTable *table));
     12Catalog *Convert_PS1_V3            PROTO((FTable *table));
     13Catalog *Convert_PS1_V4            PROTO((FTable *table));
     14Catalog *Convert_PS1_V5            PROTO((FTable *table));
     15Catalog *Convert_PS1_V5_R0_Lensing PROTO((FTable *table));
     16Catalog *Convert_PS1_V5_R1_Lensing PROTO((FTable *table));
     17Catalog *Convert_PS1_V5_R2_Lensing PROTO((FTable *table));
     18Catalog *Convert_PS1_SV1           PROTO((FTable *table));
     19Catalog *Convert_PS1_SV1_Alt       PROTO((FTable *table));
     20Catalog *Convert_PS1_SV2           PROTO((FTable *table));
     21Catalog *Convert_PS1_SV3           PROTO((FTable *table));
     22Catalog *Convert_PS1_SV4           PROTO((FTable *table));
     23Catalog *Convert_PS1_DV3           PROTO((FTable *table));
     24Catalog *Convert_PS1_DV4           PROTO((FTable *table));
     25Catalog *Convert_PS1_DV5           PROTO((FTable *table));
     26
     27Catalog *addstar_catalog_init (int Nstars) {
     28  Catalog *catalog = NULL;
     29  ALLOCATE (catalog, Catalog, 1);
     30  dvo_catalog_init (catalog, TRUE);
     31
     32  ALLOCATE (catalog->measure, Measure, Nstars);
     33
     34  int i;
     35  for (i = 0; i < Nstars; i++) {
     36    dvo_measure_init (&catalog->measure[i]);
     37  }
     38  catalog->Nmeasure = Nstars;
     39  return catalog;
     40}
    2641
    2742// given a file with the pointer at the start of the table block and the
    2843// corresponding image header, load the stars from the table
    29 Stars *ReadStarsFITS (FILE *f, Header *header, Header *in_theader, unsigned int *nstars) {
     44Catalog *ReadStarsFITS (FILE *f, Header *header, Header *in_theader) {
    3045
    3146  off_t Nskip;
    32   unsigned int Nstars;
    3347  char type[80];
    3448  Header theader;
    3549  FTable table;
    36   Stars *stars; // Stars contains Average and Measure
    3750 
    3851  if (in_theader == NULL) {
     
    5568  }
    5669
    57   stars = NULL;
     70  Catalog *catalog = NULL;
    5871  if (!strcmp (type, "SMPDATA")) {
    59     stars = Convert_SMPDATA (&table, &Nstars);
     72    catalog = Convert_SMPDATA (&table);
    6073  }
    6174  if (!strcmp (type, "PS1_DEV_0")) {
    62     stars = Convert_PS1_DEV_0 (&table, &Nstars);
     75    catalog = Convert_PS1_DEV_0 (&table);
    6376  }
    6477  if (!strcmp (type, "PS1_DEV_1")) {
    65     stars = Convert_PS1_DEV_1 (&table, &Nstars);
     78    catalog = Convert_PS1_DEV_1 (&table);
    6679  }
    6780  if (!strcmp (type, "PS1_V1")) {
    68     stars = Convert_PS1_V1 (&table, &Nstars);
     81    catalog = Convert_PS1_V1 (&table);
    6982  }
    7083  if (!strcmp (type, "PS1_V2")) {
     
    7386      return (NULL);
    7487    }
    75     stars = Convert_PS1_V2 (&table, &Nstars);
     88    catalog = Convert_PS1_V2 (&table);
    7689  }
    7790  if (!strcmp (type, "PS1_V3")) {
    78     stars = Convert_PS1_V3 (&table, &Nstars);
     91    catalog = Convert_PS1_V3 (&table);
    7992  }
    8093  if (!strcmp (type, "PS1_V4")) {
    81     stars = Convert_PS1_V4 (&table, &Nstars);
     94    catalog = Convert_PS1_V4 (&table);
    8295  }
    8396  if (!strcmp (type, "PS1_V5")) {
    8497    switch (table.header[0].Naxis[0]) {
    8598      case 232:
    86         stars = Convert_PS1_V5 (&table, &Nstars);
    87         break;
     99        catalog = Convert_PS1_V5 (&table);
     100        break;
    88101      case 312:
    89         stars = Convert_PS1_V5_R0_Lensing (&table, &Nstars);
    90         break;
     102        catalog = Convert_PS1_V5_R0_Lensing (&table);
     103        break;
    91104      case 320:
    92         stars = Convert_PS1_V5_R1_Lensing (&table, &Nstars);
    93         break;
     105        catalog = Convert_PS1_V5_R1_Lensing (&table);
     106        break;
    94107      case 328:
    95         stars = Convert_PS1_V5_R2_Lensing (&table, &Nstars);
    96         break;
     108        catalog = Convert_PS1_V5_R2_Lensing (&table);
     109        break;
    97110      default:
    98         fprintf (stderr, "invalid PS1_V5 table size %d\n", (int) table.header[0].Naxis[0]);
    99         return NULL;
     111        fprintf (stderr, "invalid PS1_V5 table size %d\n", (int) table.header[0].Naxis[0]);
     112        return NULL;
    100113    }
    101114  }
    102115  if (!strcmp (type, "PS1_SV1")) {
    103     stars = Convert_PS1_SV1 (&table, &Nstars);
     116    catalog = Convert_PS1_SV1 (&table);
    104117  }
    105118  if (!strcmp (type, "PS1_SV2")) {
    106     stars = Convert_PS1_SV2 (&table, &Nstars);
     119    catalog = Convert_PS1_SV2 (&table);
    107120  }
    108121  if (!strcmp (type, "PS1_SV3")) {
    109     stars = Convert_PS1_SV3 (&table, &Nstars);
     122    catalog = Convert_PS1_SV3 (&table);
    110123  }
    111124  if (!strcmp (type, "PS1_SV4")) {
    112     stars = Convert_PS1_SV4 (&table, &Nstars);
     125    catalog = Convert_PS1_SV4 (&table);
    113126  }
    114127  if (!strcmp (type, "PS1_DV3")) {
    115     stars = Convert_PS1_DV3 (&table, &Nstars);
     128    catalog = Convert_PS1_DV3 (&table);
    116129  }
    117130  if (!strcmp (type, "PS1_DV4")) {
    118     stars = Convert_PS1_DV4 (&table, &Nstars);
     131    catalog = Convert_PS1_DV4 (&table);
    119132  }
    120133  if (!strcmp (type, "PS1_DV5")) {
    121     stars = Convert_PS1_DV5 (&table, &Nstars);
    122   }
    123   if (stars == NULL) {
     134    catalog = Convert_PS1_DV5 (&table);
     135  }
     136  if (catalog == NULL) {
    124137    fprintf (stderr, "invalid table type %s\n", type);
    125138    return (NULL);
    126139  }
    127   // Nstars is not necessarily == *nstars (The former is the number of detections, the
    128   // latter are the 'good' detections reported by the photometry system.
    129   *nstars = Nstars;
    130 
    131   return stars;
     140
     141  gfits_free_table (&table);
     142  return catalog;
    132143}
    133144
     
    149160}
    150161
    151 Stars *Convert_SMPDATA (FTable *table, unsigned int *nstars) {
     162Catalog *Convert_SMPDATA (FTable *table) {
    152163
    153164  off_t Nstars;
    154165  unsigned int i;
    155166  double ZeroPt;
    156   Stars *stars = NULL;
    157167  SMPData *smpdata = NULL;
    158168
     
    164174  ZeroPt = GetZeroPoint();
    165175
    166   ALLOCATE (stars, Stars, Nstars);
    167   for (i = 0; i < Nstars; i++) {
    168     InitStar (&stars[i]);
    169 
    170     stars[i].measure.Xccd       = smpdata[i].X;
    171     stars[i].measure.Yccd       = smpdata[i].Y;
    172     stars[i].measure.dXccd      = NAN_S_SHORT; // not provided by SMPDATA:
    173     stars[i].measure.dYccd      = NAN_S_SHORT; // not provided by SMPDATA:
     176  Catalog *catalog = addstar_catalog_init (Nstars);
     177
     178  for (i = 0; i < Nstars; i++) {
     179    catalog->measure[i].Xccd       = smpdata[i].X;
     180    catalog->measure[i].Yccd       = smpdata[i].Y;
     181    catalog->measure[i].dXccd      = NAN_S_SHORT; // not provided by SMPDATA:
     182    catalog->measure[i].dYccd      = NAN_S_SHORT; // not provided by SMPDATA:
    174183   
    175     stars[i].measure.posangle   = NAN_S_SHORT; // not provided by SMPDATA:
    176     stars[i].measure.pltscale   = NAN;         // not provided by SMPDATA:
     184    catalog->measure[i].posangle   = NAN_S_SHORT; // not provided by SMPDATA:
     185    catalog->measure[i].pltscale   = NAN;         // not provided by SMPDATA:
    177186
    178187    if ((smpdata[i].M >= ZeroPt) || isnan(smpdata[i].M)) {
    179       stars[i].measure.M        = NAN;
    180       stars[i].measure.Map      = NAN;
    181       stars[i].measure.FluxPSF  = NAN;
    182       stars[i].measure.dFluxPSF = NAN;
    183     } else {
    184       stars[i].measure.M        = smpdata[i].M;
    185       stars[i].measure.Map      = smpdata[i].M;
    186       stars[i].measure.FluxPSF  = pow(10.0, -0.4*smpdata[i].M);
    187       stars[i].measure.dFluxPSF = stars[i].measure.FluxPSF * smpdata[i].dM;
    188     }
    189     stars[i].measure.dM         = smpdata[i].dM*0.001;
    190     stars[i].measure.dMcal      = NAN; // not provided by SMPDATA:
    191 
    192     stars[i].measure.Mkron      = NAN; // not provided by SMPDATA:
    193     stars[i].measure.dMkron     = NAN; // not provided by SMPDATA:
    194     stars[i].measure.FluxKron   = NAN; // not provided by SMPDATA:
    195     stars[i].measure.dFluxKron  = NAN; // not provided by SMPDATA:
    196 
    197     stars[i].measure.Sky        = NAN; // not provided by SMPDATA:
    198     stars[i].measure.dSky       = NAN; // not provided by SMPDATA:
    199 
    200     stars[i].measure.psfChisq   = NAN;       // not provided by SMPDATA:
    201     stars[i].measure.psfQF      = NAN;       // not provided by SMPDATA:
    202     stars[i].measure.psfNdof    = NAN_S_INT; // not provided by SMPDATA:
    203     stars[i].measure.psfNpix    = NAN_S_INT; // not provided by SMPDATA:
    204     stars[i].measure.extNsigma  = NAN;       // not provided by SMPDATA:
    205 
    206     stars[i].measure.FWx        = ToShortPixels (smpdata[i].fx);
    207     stars[i].measure.FWy        = ToShortPixels (smpdata[i].fy);
    208     stars[i].measure.theta      = ToShortDegrees (smpdata[i].df);
    209 
    210     stars[i].measure.Mxx        = NAN_S_SHORT; // not provided by SMPDATA:
    211     stars[i].measure.Mxy        = NAN_S_SHORT; // not provided by SMPDATA:
    212     stars[i].measure.Myy        = NAN_S_SHORT; // not provided by SMPDATA:
     188      catalog->measure[i].M        = NAN;
     189      catalog->measure[i].Map      = NAN;
     190      catalog->measure[i].FluxPSF  = NAN;
     191      catalog->measure[i].dFluxPSF = NAN;
     192    } else {
     193      catalog->measure[i].M        = smpdata[i].M;
     194      catalog->measure[i].Map      = smpdata[i].M;
     195      catalog->measure[i].FluxPSF  = pow(10.0, -0.4*smpdata[i].M);
     196      catalog->measure[i].dFluxPSF = catalog->measure[i].FluxPSF * smpdata[i].dM;
     197    }
     198    catalog->measure[i].dM         = smpdata[i].dM*0.001;
     199    catalog->measure[i].dMcal      = NAN; // not provided by SMPDATA:
     200
     201    catalog->measure[i].Mkron      = NAN; // not provided by SMPDATA:
     202    catalog->measure[i].dMkron     = NAN; // not provided by SMPDATA:
     203    catalog->measure[i].FluxKron   = NAN; // not provided by SMPDATA:
     204    catalog->measure[i].dFluxKron  = NAN; // not provided by SMPDATA:
     205
     206    catalog->measure[i].Sky        = NAN; // not provided by SMPDATA:
     207    catalog->measure[i].dSky       = NAN; // not provided by SMPDATA:
     208
     209    catalog->measure[i].psfChisq   = NAN;       // not provided by SMPDATA:
     210    catalog->measure[i].psfQF      = NAN;       // not provided by SMPDATA:
     211    catalog->measure[i].psfNdof    = NAN_S_INT; // not provided by SMPDATA:
     212    catalog->measure[i].psfNpix    = NAN_S_INT; // not provided by SMPDATA:
     213    catalog->measure[i].extNsigma  = NAN;       // not provided by SMPDATA:
     214
     215    catalog->measure[i].FWx        = ToShortPixels (smpdata[i].fx);
     216    catalog->measure[i].FWy        = ToShortPixels (smpdata[i].fy);
     217    catalog->measure[i].theta      = ToShortDegrees (smpdata[i].df);
     218
     219    catalog->measure[i].Mxx        = NAN_S_SHORT; // not provided by SMPDATA:
     220    catalog->measure[i].Mxy        = NAN_S_SHORT; // not provided by SMPDATA:
     221    catalog->measure[i].Myy        = NAN_S_SHORT; // not provided by SMPDATA:
    213222                       
    214223    // the dophot type information gets pushed into the upper 2 bytes of photFlags
    215     stars[i].measure.photFlags  = (smpdata[i].dophot << 16);
    216   }   
    217   *nstars = Nstars;
    218   return (stars);
    219 }
    220 
    221 Stars *Convert_PS1_DEV_0 (FTable *table, unsigned int *nstars) {
     224    catalog->measure[i].photFlags  = (smpdata[i].dophot << 16);
     225  }   
     226  return catalog;
     227}
     228
     229Catalog *Convert_PS1_DEV_0 (FTable *table) {
    222230
    223231  off_t Nstars;
    224232  unsigned int i;
    225233  double ZeroPt;
    226   Stars *stars;
    227234  PS1_DEV_0 *ps1data;
    228235
     
    234241  ZeroPt = GetZeroPoint();
    235242
    236   ALLOCATE (stars, Stars, Nstars);
    237   for (i = 0; i < Nstars; i++) {
    238     InitStar (&stars[i]);
    239     stars[i].measure.Xccd       = ps1data[i].X;
    240     stars[i].measure.Yccd       = ps1data[i].Y;
    241     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    242     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
     243  Catalog *catalog = addstar_catalog_init (Nstars);
     244
     245  for (i = 0; i < Nstars; i++) {
     246    catalog->measure[i].Xccd       = ps1data[i].X;
     247    catalog->measure[i].Yccd       = ps1data[i].Y;
     248    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     249    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
    243250   
    244     stars[i].measure.posangle   = NAN_S_SHORT; // not provided by PS1_DEV_0:
    245     stars[i].measure.pltscale   = NAN;         // not provided by PS1_DEV_0:
     251    catalog->measure[i].posangle   = NAN_S_SHORT; // not provided by PS1_DEV_0:
     252    catalog->measure[i].pltscale   = NAN;         // not provided by PS1_DEV_0:
    246253
    247254    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    248       stars[i].measure.M        = NAN;
    249       stars[i].measure.FluxPSF  = NAN;
    250       stars[i].measure.dFluxPSF = NAN;
    251     } else {
    252       stars[i].measure.M        = ps1data[i].M + ZeroPt;
    253       stars[i].measure.FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
    254       stars[i].measure.dFluxPSF = stars[i].measure.FluxPSF * ps1data[i].dM;
    255     }
    256     stars[i].measure.dM         = ps1data[i].dM;
    257     stars[i].measure.dMcal      = NAN; // not provided by PS1_DEV_0:
    258     stars[i].measure.Map        = NAN; // not provided by PS1_DEV_0:
    259 
    260     stars[i].measure.Mkron      = NAN; // not provided by PS1_DEV_0:
    261     stars[i].measure.dMkron     = NAN; // not provided by PS1_DEV_0:
    262     stars[i].measure.FluxKron   = NAN; // not provided by PS1_DEV_0:
    263     stars[i].measure.dFluxKron  = NAN; // not provided by PS1_DEV_0:
    264 
    265     stars[i].measure.Sky        = ps1data[i].sky;
    266     stars[i].measure.dSky       = ps1data[i].dSky;
    267 
    268     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    269     stars[i].measure.psfQF      = ps1data[i].psfQF;
    270     stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_0:
    271     stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_0:
    272     stars[i].measure.extNsigma  = NAN;        // not provided by PS1_DEV_0:
    273 
    274     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    275     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    276     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    277 
    278     stars[i].measure.Mxx        = NAN_S_SHORT; // not provided by PS1_DEV_0:
    279     stars[i].measure.Mxy        = NAN_S_SHORT; // not provided by PS1_DEV_0:
    280     stars[i].measure.Myy        = NAN_S_SHORT; // not provided by PS1_DEV_0:
    281                        
    282     stars[i].measure.photFlags  = 0; // not provided by PS1_DEV_0:
    283 
    284     stars[i].measure.detID      = ps1data[i].detID;
    285   }   
    286   *nstars = Nstars;
    287   return (stars);
     255      catalog->measure[i].M        = NAN;
     256      catalog->measure[i].FluxPSF  = NAN;
     257      catalog->measure[i].dFluxPSF = NAN;
     258    } else {
     259      catalog->measure[i].M        = ps1data[i].M + ZeroPt;
     260      catalog->measure[i].FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
     261      catalog->measure[i].dFluxPSF = catalog->measure[i].FluxPSF * ps1data[i].dM;
     262    }
     263    catalog->measure[i].dM         = ps1data[i].dM;
     264    catalog->measure[i].dMcal      = NAN; // not provided by PS1_DEV_0:
     265    catalog->measure[i].Map        = NAN; // not provided by PS1_DEV_0:
     266
     267    catalog->measure[i].Mkron      = NAN; // not provided by PS1_DEV_0:
     268    catalog->measure[i].dMkron     = NAN; // not provided by PS1_DEV_0:
     269    catalog->measure[i].FluxKron   = NAN; // not provided by PS1_DEV_0:
     270    catalog->measure[i].dFluxKron  = NAN; // not provided by PS1_DEV_0:
     271
     272    catalog->measure[i].Sky        = ps1data[i].sky;
     273    catalog->measure[i].dSky       = ps1data[i].dSky;
     274
     275    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     276    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     277    catalog->measure[i].psfNdof    = NAN_S_INT; // not provided by PS1_DEV_0:
     278    catalog->measure[i].psfNpix    = NAN_S_INT; // not provided by PS1_DEV_0:
     279    catalog->measure[i].extNsigma  = NAN;        // not provided by PS1_DEV_0:
     280
     281    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     282    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     283    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     284
     285    catalog->measure[i].Mxx        = NAN_S_SHORT; // not provided by PS1_DEV_0:
     286    catalog->measure[i].Mxy        = NAN_S_SHORT; // not provided by PS1_DEV_0:
     287    catalog->measure[i].Myy        = NAN_S_SHORT; // not provided by PS1_DEV_0:
     288                       
     289    catalog->measure[i].photFlags  = 0; // not provided by PS1_DEV_0:
     290
     291    catalog->measure[i].detID      = ps1data[i].detID;
     292  }   
     293  return catalog;
    288294}
    289295
    290296// XXX I need to make the IPP I/O functions and these functions
    291297// consistent wrt ZERO_POINT....
    292 Stars *Convert_PS1_DEV_1 (FTable *table, unsigned int *nstars) {
     298Catalog *Convert_PS1_DEV_1 (FTable *table) {
    293299
    294300  off_t Nstars;
    295301  unsigned int i;
    296302  double ZeroPt;
    297   Stars *stars;
    298303  PS1_DEV_1 *ps1data;
    299304
     
    305310  ZeroPt = GetZeroPoint();
    306311
    307   ALLOCATE (stars, Stars, Nstars);
    308   for (i = 0; i < Nstars; i++) {
    309     InitStar (&stars[i]);
    310     stars[i].measure.Xccd       = ps1data[i].X;
    311     stars[i].measure.Yccd       = ps1data[i].Y;
    312     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    313     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    314 
    315     stars[i].measure.posangle   = NAN_S_SHORT; // not provided by PS1_DEV_1:
    316     stars[i].measure.pltscale   = NAN;         // not provided by PS1_DEV_1:
     312  Catalog *catalog = addstar_catalog_init (Nstars);
     313
     314  for (i = 0; i < Nstars; i++) {
     315    catalog->measure[i].Xccd       = ps1data[i].X;
     316    catalog->measure[i].Yccd       = ps1data[i].Y;
     317    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     318    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     319
     320    catalog->measure[i].posangle   = NAN_S_SHORT; // not provided by PS1_DEV_1:
     321    catalog->measure[i].pltscale   = NAN;         // not provided by PS1_DEV_1:
    317322
    318323    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    319       stars[i].measure.M      = NAN;
    320       stars[i].measure.FluxPSF  = NAN;
    321       stars[i].measure.dFluxPSF = NAN;
    322     } else {
    323       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    324       stars[i].measure.FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
    325       stars[i].measure.dFluxPSF = stars[i].measure.FluxPSF * ps1data[i].dM;
    326     }
    327     stars[i].measure.dM         = ps1data[i].dM;
    328     stars[i].measure.dMcal      = NAN; // not provided by PS1_DEV_1:
    329     stars[i].measure.Map        = NAN; // not provided by PS1_DEV_1:
    330 
    331     stars[i].measure.Mkron      = NAN; // not provided by PS1_DEV_1:
    332     stars[i].measure.dMkron     = NAN; // not provided by PS1_DEV_1:
    333     stars[i].measure.FluxKron   = NAN; // not provided by PS1_DEV_1:
    334     stars[i].measure.dFluxKron  = NAN; // not provided by PS1_DEV_1:
    335 
    336     stars[i].measure.Sky        = ps1data[i].sky;
    337     stars[i].measure.dSky       = ps1data[i].dSky;
    338 
    339     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    340     stars[i].measure.psfQF      = ps1data[i].psfQF;
    341     stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_1:
    342     stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_1:
    343     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    344 
    345     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    346     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    347     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    348 
    349     stars[i].measure.Mxx        = NAN_S_SHORT; // not provided by PS1_DEV_1:
    350     stars[i].measure.Mxy        = NAN_S_SHORT; // not provided by PS1_DEV_1:
    351     stars[i].measure.Myy        = NAN_S_SHORT; // not provided by PS1_DEV_1:
    352                        
    353     stars[i].measure.photFlags  = ps1data[i].flags;
    354 
    355     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    356     stars[i].measure.detID      = ps1data[i].detID;
    357   }   
    358   *nstars = Nstars;
    359   return (stars);
    360 }
    361 
    362 Stars *Convert_PS1_V1 (FTable *table, unsigned int *nstars) {
     324      catalog->measure[i].M      = NAN;
     325      catalog->measure[i].FluxPSF  = NAN;
     326      catalog->measure[i].dFluxPSF = NAN;
     327    } else {
     328      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     329      catalog->measure[i].FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
     330      catalog->measure[i].dFluxPSF = catalog->measure[i].FluxPSF * ps1data[i].dM;
     331    }
     332    catalog->measure[i].dM         = ps1data[i].dM;
     333    catalog->measure[i].dMcal      = NAN; // not provided by PS1_DEV_1:
     334    catalog->measure[i].Map        = NAN; // not provided by PS1_DEV_1:
     335
     336    catalog->measure[i].Mkron      = NAN; // not provided by PS1_DEV_1:
     337    catalog->measure[i].dMkron     = NAN; // not provided by PS1_DEV_1:
     338    catalog->measure[i].FluxKron   = NAN; // not provided by PS1_DEV_1:
     339    catalog->measure[i].dFluxKron  = NAN; // not provided by PS1_DEV_1:
     340
     341    catalog->measure[i].Sky        = ps1data[i].sky;
     342    catalog->measure[i].dSky       = ps1data[i].dSky;
     343
     344    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     345    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     346    catalog->measure[i].psfNdof    = NAN_S_INT; // not provided by PS1_DEV_1:
     347    catalog->measure[i].psfNpix    = NAN_S_INT; // not provided by PS1_DEV_1:
     348    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     349
     350    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     351    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     352    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     353
     354    catalog->measure[i].Mxx        = NAN_S_SHORT; // not provided by PS1_DEV_1:
     355    catalog->measure[i].Mxy        = NAN_S_SHORT; // not provided by PS1_DEV_1:
     356    catalog->measure[i].Myy        = NAN_S_SHORT; // not provided by PS1_DEV_1:
     357                       
     358    catalog->measure[i].photFlags  = ps1data[i].flags;
     359
     360    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     361    catalog->measure[i].detID      = ps1data[i].detID;
     362  }   
     363  return catalog;
     364}
     365
     366Catalog *Convert_PS1_V1 (FTable *table) {
    363367
    364368  off_t Nstars;
    365369  unsigned int i;
    366370  double ZeroPt;
    367   Stars *stars;
    368371  CMF_PS1_V1 *ps1data;
    369372
     
    377380
    378381  if (table[0].header[0].Naxis[0] == 136) {
    379     stars = Convert_PS1_V1_Alt (table, nstars);
    380     return (stars);
     382    Catalog *catalog = Convert_PS1_V1_Alt (table);
     383    return catalog;
    381384  }
    382385
     
    388391  ZeroPt = GetZeroPoint();
    389392
    390   ALLOCATE (stars, Stars, Nstars);
    391   for (i = 0; i < Nstars; i++) {
    392     InitStar (&stars[i]);
    393     stars[i].measure.Xccd       = ps1data[i].X;
    394     stars[i].measure.Yccd       = ps1data[i].Y;
    395     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    396     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    397 
    398     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    399     stars[i].measure.pltscale   = ps1data[i].pltscale;
     393  Catalog *catalog = addstar_catalog_init (Nstars);
     394
     395  for (i = 0; i < Nstars; i++) {
     396    catalog->measure[i].Xccd       = ps1data[i].X;
     397    catalog->measure[i].Yccd       = ps1data[i].Y;
     398    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     399    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     400
     401    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     402    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    400403
    401404    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    402       stars[i].measure.M      = NAN;
    403       stars[i].measure.FluxPSF  = NAN;
    404       stars[i].measure.dFluxPSF = NAN;
    405     } else {
    406       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    407       stars[i].measure.FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
    408       stars[i].measure.dFluxPSF = stars[i].measure.FluxPSF * ps1data[i].dM;
    409     }
    410     stars[i].measure.dM         = ps1data[i].dM;
    411     stars[i].measure.dMcal      = ps1data[i].dMcal;
    412     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    413     stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    414                        
    415     stars[i].measure.Mkron      = NAN; // not provided by PS1_V1:
    416     stars[i].measure.dMkron     = NAN; // not provided by PS1_V1:
    417     stars[i].measure.FluxKron   = NAN; // not provided by PS1_V1:
    418     stars[i].measure.dFluxKron  = NAN; // not provided by PS1_V1:
    419 
    420     stars[i].measure.Sky        = ps1data[i].sky;
    421     stars[i].measure.dSky       = ps1data[i].dSky;
    422                        
    423     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    424     stars[i].measure.psfQF      = ps1data[i].psfQF;
    425     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    426     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    427     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    428 
    429     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    430     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    431     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    432 
    433     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    434     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    435     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    436                        
    437     stars[i].measure.photFlags  = ps1data[i].flags;
    438 
    439     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    440     stars[i].measure.detID      = ps1data[i].detID;
     405      catalog->measure[i].M      = NAN;
     406      catalog->measure[i].FluxPSF  = NAN;
     407      catalog->measure[i].dFluxPSF = NAN;
     408    } else {
     409      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     410      catalog->measure[i].FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
     411      catalog->measure[i].dFluxPSF = catalog->measure[i].FluxPSF * ps1data[i].dM;
     412    }
     413    catalog->measure[i].dM         = ps1data[i].dM;
     414    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     415    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     416    catalog->measure[i].dMap       = ps1data[i].dM; // a proxy measure
     417                       
     418    catalog->measure[i].Mkron      = NAN; // not provided by PS1_V1:
     419    catalog->measure[i].dMkron     = NAN; // not provided by PS1_V1:
     420    catalog->measure[i].FluxKron   = NAN; // not provided by PS1_V1:
     421    catalog->measure[i].dFluxKron  = NAN; // not provided by PS1_V1:
     422
     423    catalog->measure[i].Sky        = ps1data[i].sky;
     424    catalog->measure[i].dSky       = ps1data[i].dSky;
     425                       
     426    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     427    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     428    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     429    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     430    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     431
     432    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     433    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     434    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     435
     436    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     437    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     438    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     439                       
     440    catalog->measure[i].photFlags  = ps1data[i].flags;
     441
     442    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     443    catalog->measure[i].detID      = ps1data[i].detID;
    441444
    442445    // the Average fields and the following Measure fields are set in FilterStars after
     
    446449    // the following fields are currently not being set anywhere: t_msec
    447450  }   
    448   *nstars = Nstars;
    449   return (stars);
    450 }
    451 
    452 Stars *Convert_PS1_V1_Alt (FTable *table, unsigned int *nstars) {
     451  return catalog;
     452}
     453
     454Catalog *Convert_PS1_V1_Alt (FTable *table) {
    453455
    454456  off_t Nstars;
    455457  unsigned int i;
    456458  double ZeroPt;
    457   Stars *stars;
    458459  CMF_PS1_V2 *ps1data;
    459460
     
    466467  // call a special conversion function if it is found.
    467468
    468   ps1data = gfits_table_get_CMF_PS1_V1_Alt (table, &Nstars, NULL);
     469  ps1data = gfits_table_get_CMF_PS1_V1_Alt (table, &Nstars, NULL); 
    469470  if (!ps1data) {
    470471    fprintf (stderr, "skipping inconsistent entry\n");
     
    473474  ZeroPt = GetZeroPoint();
    474475
    475   ALLOCATE (stars, Stars, Nstars);
    476   for (i = 0; i < Nstars; i++) {
    477     InitStar (&stars[i]);
    478     stars[i].measure.Xccd       = ps1data[i].X;
    479     stars[i].measure.Yccd       = ps1data[i].Y;
    480     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    481     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    482 
    483     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    484     stars[i].measure.pltscale   = ps1data[i].pltscale;
     476  Catalog *catalog = addstar_catalog_init (Nstars);
     477
     478  for (i = 0; i < Nstars; i++) {
     479    catalog->measure[i].Xccd       = ps1data[i].X;
     480    catalog->measure[i].Yccd       = ps1data[i].Y;
     481    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     482    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     483
     484    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     485    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    485486
    486487    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    487       stars[i].measure.M      = NAN;
    488       stars[i].measure.FluxPSF  = NAN;
    489       stars[i].measure.dFluxPSF = NAN;
    490     } else {
    491       stars[i].measure.M        = ps1data[i].M + ZeroPt;
    492       stars[i].measure.FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
    493       stars[i].measure.dFluxPSF = stars[i].measure.FluxPSF * ps1data[i].dM;
    494     }
    495     stars[i].measure.dM         = ps1data[i].dM;
    496     stars[i].measure.dMcal      = ps1data[i].dMcal;
    497     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    498     stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    499                        
    500     stars[i].measure.Mkron      = NAN; // not provided by PS1_V1_Alt:
    501     stars[i].measure.dMkron     = NAN; // not provided by PS1_V1_Alt:
    502     stars[i].measure.FluxKron   = NAN; // not provided by PS1_V1_Alt:
    503     stars[i].measure.dFluxKron  = NAN; // not provided by PS1_V1_Alt:
    504 
    505     stars[i].measure.Sky        = ps1data[i].sky;
    506     stars[i].measure.dSky       = ps1data[i].dSky;
    507                        
    508     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    509     stars[i].measure.psfQF      = ps1data[i].psfQF;
    510     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    511     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    512     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    513 
    514     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    515     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    516     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    517 
    518     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    519     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    520     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    521                        
    522     stars[i].measure.photFlags  = ps1data[i].flags;
    523 
    524     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    525     stars[i].measure.detID      = ps1data[i].detID;
     488      catalog->measure[i].M      = NAN;
     489      catalog->measure[i].FluxPSF  = NAN;
     490      catalog->measure[i].dFluxPSF = NAN;
     491    } else {
     492      catalog->measure[i].M        = ps1data[i].M + ZeroPt;
     493      catalog->measure[i].FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
     494      catalog->measure[i].dFluxPSF = catalog->measure[i].FluxPSF * ps1data[i].dM;
     495    }
     496    catalog->measure[i].dM         = ps1data[i].dM;
     497    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     498    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     499    catalog->measure[i].dMap       = ps1data[i].dM; // a proxy measure
     500                       
     501    catalog->measure[i].Mkron      = NAN; // not provided by PS1_V1_Alt:
     502    catalog->measure[i].dMkron     = NAN; // not provided by PS1_V1_Alt:
     503    catalog->measure[i].FluxKron   = NAN; // not provided by PS1_V1_Alt:
     504    catalog->measure[i].dFluxKron  = NAN; // not provided by PS1_V1_Alt:
     505
     506    catalog->measure[i].Sky        = ps1data[i].sky;
     507    catalog->measure[i].dSky       = ps1data[i].dSky;
     508                       
     509    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     510    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     511    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     512    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     513    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     514
     515    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     516    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     517    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     518
     519    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     520    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     521    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     522                       
     523    catalog->measure[i].photFlags  = ps1data[i].flags;
     524
     525    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     526    catalog->measure[i].detID      = ps1data[i].detID;
    526527
    527528    // the Average fields and the following Measure fields are set in FilterStars after
     
    531532    // the following fields are currently not being set anywhere: t_msec
    532533  }   
    533   *nstars = Nstars;
    534   return (stars);
    535 }
    536 
    537 Stars *Convert_PS1_V2 (FTable *table, unsigned int *nstars) {
     534  return catalog;
     535}
     536
     537Catalog *Convert_PS1_V2 (FTable *table) {
    538538
    539539  off_t Nstars;
    540540  unsigned int i;
    541541  double ZeroPt;
    542   Stars *stars;
    543542  CMF_PS1_V2 *ps1data;
    544543
     
    550549  ZeroPt = GetZeroPoint();
    551550
    552   ALLOCATE (stars, Stars, Nstars);
    553   for (i = 0; i < Nstars; i++) {
    554     InitStar (&stars[i]);
    555     stars[i].measure.Xccd       = ps1data[i].X;
    556     stars[i].measure.Yccd       = ps1data[i].Y;
    557     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    558     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    559 
    560     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    561     stars[i].measure.pltscale   = ps1data[i].pltscale;
     551  Catalog *catalog = addstar_catalog_init (Nstars);
     552
     553  for (i = 0; i < Nstars; i++) {
     554    catalog->measure[i].Xccd       = ps1data[i].X;
     555    catalog->measure[i].Yccd       = ps1data[i].Y;
     556    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     557    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     558
     559    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     560    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    562561
    563562    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    564       stars[i].measure.M        = NAN;
    565       stars[i].measure.FluxPSF  = NAN;
    566       stars[i].measure.dFluxPSF = NAN;
    567     } else {
    568       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    569       stars[i].measure.FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
    570       stars[i].measure.dFluxPSF = stars[i].measure.FluxPSF * ps1data[i].dM;
    571     }
    572     stars[i].measure.dM         = ps1data[i].dM;
    573     stars[i].measure.dMcal      = ps1data[i].dMcal;
    574     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    575     stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    576                        
    577     stars[i].measure.Mkron      = NAN; // not provided by PS1_V2:
    578     stars[i].measure.dMkron     = NAN; // not provided by PS1_V2:
    579     stars[i].measure.FluxKron   = NAN; // not provided by PS1_V2:
    580     stars[i].measure.dFluxKron  = NAN; // not provided by PS1_V2:
    581 
    582     stars[i].measure.Sky        = ps1data[i].sky;
    583     stars[i].measure.dSky       = ps1data[i].dSky;
    584                        
    585     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    586     stars[i].measure.psfQF      = ps1data[i].psfQF;
    587     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    588     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    589     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    590 
    591     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    592     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    593     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    594 
    595     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    596     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    597     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    598                        
    599     stars[i].measure.photFlags  = ps1data[i].flags;
    600 
    601     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    602     stars[i].measure.detID      = ps1data[i].detID;
     563      catalog->measure[i].M        = NAN;
     564      catalog->measure[i].FluxPSF  = NAN;
     565      catalog->measure[i].dFluxPSF = NAN;
     566    } else {
     567      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     568      catalog->measure[i].FluxPSF  = pow(10.0, -0.4*ps1data[i].M);
     569      catalog->measure[i].dFluxPSF = catalog->measure[i].FluxPSF * ps1data[i].dM;
     570    }
     571    catalog->measure[i].dM         = ps1data[i].dM;
     572    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     573    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     574    catalog->measure[i].dMap       = ps1data[i].dM; // a proxy measure
     575                       
     576    catalog->measure[i].Mkron      = NAN; // not provided by PS1_V2:
     577    catalog->measure[i].dMkron     = NAN; // not provided by PS1_V2:
     578    catalog->measure[i].FluxKron   = NAN; // not provided by PS1_V2:
     579    catalog->measure[i].dFluxKron  = NAN; // not provided by PS1_V2:
     580
     581    catalog->measure[i].Sky        = ps1data[i].sky;
     582    catalog->measure[i].dSky       = ps1data[i].dSky;
     583                       
     584    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     585    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     586    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     587    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     588    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     589
     590    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     591    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     592    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     593
     594    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     595    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     596    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     597                       
     598    catalog->measure[i].photFlags  = ps1data[i].flags;
     599
     600    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     601    catalog->measure[i].detID      = ps1data[i].detID;
    603602
    604603    // the Average fields and the following Measure fields are set in FilterStars after
     
    608607    // the following fields are currently not being set anywhere: t_msec
    609608  }   
    610   *nstars = Nstars;
    611   return (stars);
    612 }
    613 
    614 Stars *Convert_PS1_V3 (FTable *table, unsigned int *nstars) {
     609  return catalog;
     610}
     611
     612Catalog *Convert_PS1_V3 (FTable *table) {
    615613
    616614  off_t Nstars;
    617615  unsigned int i;
    618616  double ZeroPt;
    619   Stars *stars;
    620617  CMF_PS1_V3 *ps1data;
    621618
     
    627624  ZeroPt = GetZeroPoint();
    628625
    629   ALLOCATE (stars, Stars, Nstars);
    630   for (i = 0; i < Nstars; i++) {
    631     InitStar (&stars[i]);
    632     stars[i].measure.Xccd       = ps1data[i].X;
    633     stars[i].measure.Yccd       = ps1data[i].Y;
    634     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    635     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    636 
    637     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    638     stars[i].measure.pltscale   = ps1data[i].pltscale;
     626  Catalog *catalog = addstar_catalog_init (Nstars);
     627
     628  for (i = 0; i < Nstars; i++) {
     629    catalog->measure[i].Xccd       = ps1data[i].X;
     630    catalog->measure[i].Yccd       = ps1data[i].Y;
     631    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     632    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     633
     634    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     635    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    639636
    640637    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    641       stars[i].measure.M      = NAN;
    642     } else {
    643       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    644     }
    645     stars[i].measure.dM         = ps1data[i].dM;
    646     stars[i].measure.dMcal      = ps1data[i].dMcal;
    647     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    648     stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    649                        
    650     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    651     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     638      catalog->measure[i].M      = NAN;
     639    } else {
     640      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     641    }
     642    catalog->measure[i].dM         = ps1data[i].dM;
     643    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     644    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     645    catalog->measure[i].dMap       = ps1data[i].dM; // a proxy measure
     646                       
     647    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     648    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    652649                       
    653650    // these fluxes are converted from counts to counts/sec in FilterStars.c
    654     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    655     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    656     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    657     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    658     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
    659     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
    660 
    661     stars[i].measure.Sky        = ps1data[i].sky;
    662     stars[i].measure.dSky       = ps1data[i].dSky;
    663                        
    664     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    665     stars[i].measure.psfQF      = ps1data[i].psfQF;
    666     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    667     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    668     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    669     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    670 
    671     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    672     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    673     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    674 
    675     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    676     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    677     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    678                        
    679     stars[i].measure.photFlags  = ps1data[i].flags;
    680     stars[i].measure.photFlags2 = ps1data[i].flags2;
    681 
    682     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    683     stars[i].measure.detID      = ps1data[i].detID;
     651    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     652    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     653    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     654    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     655    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     656    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (NAN, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     657
     658    catalog->measure[i].Sky        = ps1data[i].sky;
     659    catalog->measure[i].dSky       = ps1data[i].dSky;
     660                       
     661    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     662    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     663    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     664    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     665    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     666    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     667
     668    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     669    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     670    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     671
     672    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     673    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     674    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     675                       
     676    catalog->measure[i].photFlags  = ps1data[i].flags;
     677    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     678
     679    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     680    catalog->measure[i].detID      = ps1data[i].detID;
    684681
    685682    // the Average fields and the following Measure fields are set in FilterStars after
     
    692689    // the following fields are currently not being set anywhere: t_msec
    693690  }   
    694   *nstars = Nstars;
    695   return (stars);
    696 }
    697 
    698 Stars *Convert_PS1_V4 (FTable *table, unsigned int *nstars) {
     691  return catalog;
     692}
     693
     694Catalog *Convert_PS1_V4 (FTable *table) {
    699695
    700696  off_t Nstars;
    701697  unsigned int i;
    702698  double ZeroPt;
    703   Stars *stars;
    704699  CMF_PS1_V4 *ps1data;
    705700
     
    711706  ZeroPt = GetZeroPoint();
    712707
    713   ALLOCATE (stars, Stars, Nstars);
    714   for (i = 0; i < Nstars; i++) {
    715     InitStar (&stars[i]);
    716     stars[i].measure.Xccd       = ps1data[i].X;
    717     stars[i].measure.Yccd       = ps1data[i].Y;
    718     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    719     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    720 
    721     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    722     stars[i].measure.pltscale   = ps1data[i].pltscale;
     708  Catalog *catalog = addstar_catalog_init (Nstars);
     709
     710  for (i = 0; i < Nstars; i++) {
     711    catalog->measure[i].Xccd       = ps1data[i].X;
     712    catalog->measure[i].Yccd       = ps1data[i].Y;
     713    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     714    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     715
     716    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     717    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    723718
    724719    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    725       stars[i].measure.M      = NAN;
    726     } else {
    727       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    728     }
    729     stars[i].measure.dM         = ps1data[i].dM;
    730     stars[i].measure.dMcal      = ps1data[i].dMcal;
    731     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    732     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    733                        
    734     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    735     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     720      catalog->measure[i].M      = NAN;
     721    } else {
     722      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     723    }
     724    catalog->measure[i].dM         = ps1data[i].dM;
     725    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     726    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     727    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     728                       
     729    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     730    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    736731                       
    737732    // these fluxes are converted from counts to counts/sec in FilterStars.c
    738     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    739     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    740     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    741     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    742     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    743     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    744 
    745     stars[i].measure.Sky        = ps1data[i].sky;
    746     stars[i].measure.dSky       = ps1data[i].dSky;
    747                        
    748     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    749     stars[i].measure.psfQF      = ps1data[i].psfQF;
    750     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    751 
    752     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    753     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    754     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    755 
    756     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    757     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    758     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    759 
    760     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    761     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    762     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    763                        
    764     stars[i].measure.photFlags  = ps1data[i].flags;
    765     stars[i].measure.photFlags2 = ps1data[i].flags2;
    766 
    767     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    768     stars[i].measure.detID      = ps1data[i].detID;
     733    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     734    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     735    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     736    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     737    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     738    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     739
     740    catalog->measure[i].Sky        = ps1data[i].sky;
     741    catalog->measure[i].dSky       = ps1data[i].dSky;
     742                       
     743    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     744    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     745    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     746
     747    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     748    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     749    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     750
     751    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     752    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     753    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     754
     755    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     756    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     757    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     758                       
     759    catalog->measure[i].photFlags  = ps1data[i].flags;
     760    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     761
     762    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     763    catalog->measure[i].detID      = ps1data[i].detID;
    769764
    770765    // the Average fields and the following Measure fields are set in FilterStars after
     
    777772    // the following fields are currently not being set anywhere: t_msec
    778773  }   
    779   *nstars = Nstars;
    780   return (stars);
    781 }
    782 
    783 Stars *Convert_PS1_V5 (FTable *table, unsigned int *nstars) {
     774  return catalog;
     775}
     776
     777Catalog *Convert_PS1_V5 (FTable *table) {
    784778
    785779  off_t Nstars;
    786780  unsigned int i;
    787781  double ZeroPt;
    788   Stars *stars;
    789782  CMF_PS1_V5 *ps1data;
    790783
     
    796789  ZeroPt = GetZeroPoint();
    797790
    798   ALLOCATE (stars, Stars, Nstars);
    799   for (i = 0; i < Nstars; i++) {
    800     InitStar (&stars[i]);
    801     stars[i].measure.Xccd       = ps1data[i].X;
    802     stars[i].measure.Yccd       = ps1data[i].Y;
    803     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    804     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    805 
    806     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    807     stars[i].measure.pltscale   = ps1data[i].pltscale;
     791  Catalog *catalog = addstar_catalog_init (Nstars);
     792
     793  for (i = 0; i < Nstars; i++) {
     794    catalog->measure[i].Xccd       = ps1data[i].X;
     795    catalog->measure[i].Yccd       = ps1data[i].Y;
     796    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     797    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     798
     799    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     800    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    808801
    809802    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    810       stars[i].measure.M      = NAN;
    811     } else {
    812       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    813     }
    814     stars[i].measure.dM         = ps1data[i].dM;
    815     stars[i].measure.dMcal      = ps1data[i].dMcal;
    816     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    817     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    818                        
    819     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    820     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     803      catalog->measure[i].M      = NAN;
     804    } else {
     805      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     806    }
     807    catalog->measure[i].dM         = ps1data[i].dM;
     808    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     809    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     810    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     811                       
     812    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     813    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    821814                       
    822815    // these fluxes are converted from counts to counts/sec in FilterStars.c
    823     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    824     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    825     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    826     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    827     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    828     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    829 
    830     stars[i].measure.Sky        = ps1data[i].sky;
    831     stars[i].measure.dSky       = ps1data[i].dSky;
    832                        
    833     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    834     stars[i].measure.psfQF      = ps1data[i].psfQF;
    835     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    836 
    837     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    838     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    839     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    840 
    841     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    842     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    843     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    844 
    845     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    846     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    847     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    848                        
    849     stars[i].measure.photFlags  = ps1data[i].flags;
    850     stars[i].measure.photFlags2 = ps1data[i].flags2;
    851 
    852     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    853     stars[i].measure.detID      = ps1data[i].detID;
     816    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     817    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     818    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     819    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     820    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     821    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     822
     823    catalog->measure[i].Sky        = ps1data[i].sky;
     824    catalog->measure[i].dSky       = ps1data[i].dSky;
     825                       
     826    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     827    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     828    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     829
     830    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     831    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     832    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     833
     834    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     835    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     836    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     837
     838    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     839    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     840    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     841                       
     842    catalog->measure[i].photFlags  = ps1data[i].flags;
     843    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     844
     845    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     846    catalog->measure[i].detID      = ps1data[i].detID;
    854847
    855848    // the Average fields and the following Measure fields are set in FilterStars after
     
    862855    // the following fields are currently not being set anywhere: t_msec
    863856  }   
    864   *nstars = Nstars;
    865   return (stars);
    866 }
    867 
    868 Stars *Convert_PS1_V5_R0_Lensing (FTable *table, unsigned int *nstars) {
     857  return catalog;
     858}
     859
     860Catalog *Convert_PS1_V5_R0_Lensing (FTable *table) {
    869861
    870862  off_t Nstars;
    871863  unsigned int i;
    872864  double ZeroPt;
    873   Stars *stars;
    874865  CMF_PS1_V5_R0_Lensing *ps1data;
    875866
     
    881872  ZeroPt = GetZeroPoint();
    882873
    883   ALLOCATE (stars, Stars, Nstars);
    884   for (i = 0; i < Nstars; i++) {
    885     InitStar (&stars[i]);
    886     stars[i].measure.Xccd       = ps1data[i].X;
    887     stars[i].measure.Yccd       = ps1data[i].Y;
    888     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    889     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    890 
    891     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    892     stars[i].measure.pltscale   = ps1data[i].pltscale;
     874  Catalog *catalog = addstar_catalog_init (Nstars);
     875  ALLOCATE (catalog->lensing, Lensing, Nstars);
     876  catalog->Nlensing = Nstars;
     877
     878  for (i = 0; i < Nstars; i++) {
     879    catalog->measure[i].Xccd       = ps1data[i].X;
     880    catalog->measure[i].Yccd       = ps1data[i].Y;
     881    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     882    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     883
     884    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     885    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    893886
    894887    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    895       stars[i].measure.M      = NAN;
    896     } else {
    897       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    898     }
    899     stars[i].measure.dM         = ps1data[i].dM;
    900     stars[i].measure.dMcal      = ps1data[i].dMcal;
    901     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    902     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    903                        
    904     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    905     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     888      catalog->measure[i].M      = NAN;
     889    } else {
     890      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     891    }
     892    catalog->measure[i].dM         = ps1data[i].dM;
     893    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     894    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     895    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     896                       
     897    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     898    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    906899                       
    907900    // these fluxes are converted from counts to counts/sec in FilterStars.c
    908     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    909     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    910     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    911     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    912     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    913     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    914 
    915     stars[i].measure.Sky        = ps1data[i].sky;
    916     stars[i].measure.dSky       = ps1data[i].dSky;
    917                        
    918     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    919     stars[i].measure.psfQF      = ps1data[i].psfQF;
    920     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    921 
    922     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    923     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    924     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    925 
    926     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    927     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    928     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    929 
    930     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    931     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    932     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    933                        
    934     stars[i].measure.photFlags  = ps1data[i].flags;
    935     stars[i].measure.photFlags2 = ps1data[i].flags2;
    936 
    937     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    938     stars[i].measure.detID      = ps1data[i].detID;
    939 
    940     ALLOCATE (stars[i].lensing, Lensing, 1);
    941     dvo_lensing_init (stars[i].lensing);
    942 
    943     stars[i].lensing->X11_sm_obj  = ps1data[i].X11_sm_obj;
    944     stars[i].lensing->X12_sm_obj  = ps1data[i].X12_sm_obj;
    945     stars[i].lensing->X22_sm_obj  = ps1data[i].X22_sm_obj;
    946     stars[i].lensing->E1_sm_obj   = ps1data[i].E1_sm_obj;
    947     stars[i].lensing->E2_sm_obj   = ps1data[i].E2_sm_obj;
    948 
    949     stars[i].lensing->X11_sh_obj  = ps1data[i].X11_sh_obj;
    950     stars[i].lensing->X12_sh_obj  = ps1data[i].X12_sh_obj;
    951     stars[i].lensing->X22_sh_obj  = ps1data[i].X22_sh_obj;
    952     stars[i].lensing->E1_sh_obj   = ps1data[i].E1_sh_obj;
    953     stars[i].lensing->E2_sh_obj   = ps1data[i].E2_sh_obj;
    954 
    955     stars[i].lensing->X11_sm_psf  = ps1data[i].X11_sm_psf;
    956     stars[i].lensing->X12_sm_psf  = ps1data[i].X12_sm_psf;
    957     stars[i].lensing->X22_sm_psf  = ps1data[i].X22_sm_psf;
    958     stars[i].lensing->E1_sm_psf   = ps1data[i].E1_sm_psf;
    959     stars[i].lensing->E2_sm_psf   = ps1data[i].E2_sm_psf;
    960 
    961     stars[i].lensing->X11_sh_psf  = ps1data[i].X11_sh_psf;
    962     stars[i].lensing->X12_sh_psf  = ps1data[i].X12_sh_psf;
    963     stars[i].lensing->X22_sh_psf  = ps1data[i].X22_sh_psf;
    964     stars[i].lensing->E1_sh_psf   = ps1data[i].E1_sh_psf;
    965     stars[i].lensing->E2_sh_psf   = ps1data[i].E2_sh_psf;
    966 
    967     // stars[i].lensing->F_ApR5    = ps1data[i].F_ApR5;
    968     // stars[i].lensing->dF_ApR5   = ps1data[i].dF_ApR5;
    969     // stars[i].lensing->sF_ApR5   = ps1data[i].sF_ApR5;
    970     // stars[i].lensing->fF_ApR5   = ps1data[i].fF_ApR5;
     901    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     902    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     903    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     904    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     905    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     906    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     907
     908    catalog->measure[i].Sky        = ps1data[i].sky;
     909    catalog->measure[i].dSky       = ps1data[i].dSky;
     910                       
     911    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     912    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     913    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     914
     915    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     916    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     917    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     918
     919    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     920    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     921    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     922
     923    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     924    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     925    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     926                       
     927    catalog->measure[i].photFlags  = ps1data[i].flags;
     928    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     929
     930    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     931    catalog->measure[i].detID      = ps1data[i].detID;
     932
     933    dvo_lensing_init (&catalog->lensing[i]);
     934
     935    catalog->lensing[i].X11_sm_obj  = ps1data[i].X11_sm_obj;
     936    catalog->lensing[i].X12_sm_obj  = ps1data[i].X12_sm_obj;
     937    catalog->lensing[i].X22_sm_obj  = ps1data[i].X22_sm_obj;
     938    catalog->lensing[i].E1_sm_obj   = ps1data[i].E1_sm_obj;
     939    catalog->lensing[i].E2_sm_obj   = ps1data[i].E2_sm_obj;
     940
     941    catalog->lensing[i].X11_sh_obj  = ps1data[i].X11_sh_obj;
     942    catalog->lensing[i].X12_sh_obj  = ps1data[i].X12_sh_obj;
     943    catalog->lensing[i].X22_sh_obj  = ps1data[i].X22_sh_obj;
     944    catalog->lensing[i].E1_sh_obj   = ps1data[i].E1_sh_obj;
     945    catalog->lensing[i].E2_sh_obj   = ps1data[i].E2_sh_obj;
     946
     947    catalog->lensing[i].X11_sm_psf  = ps1data[i].X11_sm_psf;
     948    catalog->lensing[i].X12_sm_psf  = ps1data[i].X12_sm_psf;
     949    catalog->lensing[i].X22_sm_psf  = ps1data[i].X22_sm_psf;
     950    catalog->lensing[i].E1_sm_psf   = ps1data[i].E1_sm_psf;
     951    catalog->lensing[i].E2_sm_psf   = ps1data[i].E2_sm_psf;
     952
     953    catalog->lensing[i].X11_sh_psf  = ps1data[i].X11_sh_psf;
     954    catalog->lensing[i].X12_sh_psf  = ps1data[i].X12_sh_psf;
     955    catalog->lensing[i].X22_sh_psf  = ps1data[i].X22_sh_psf;
     956    catalog->lensing[i].E1_sh_psf   = ps1data[i].E1_sh_psf;
     957    catalog->lensing[i].E2_sh_psf   = ps1data[i].E2_sh_psf;
     958
     959    // catalog->lensing[i].F_ApR5    = ps1data[i].F_ApR5;
     960    // catalog->lensing[i].dF_ApR5   = ps1data[i].dF_ApR5;
     961    // catalog->lensing[i].sF_ApR5   = ps1data[i].sF_ApR5;
     962    // catalog->lensing[i].fF_ApR5   = ps1data[i].fF_ApR5;
    971963    //
    972     // stars[i].lensing->F_ApR6    = ps1data[i].F_ApR6;
    973     // stars[i].lensing->dF_ApR6   = ps1data[i].dF_ApR6;
    974     // stars[i].lensing->sF_ApR6   = ps1data[i].sF_ApR6;
    975     // stars[i].lensing->fF_ApR6   = ps1data[i].fF_ApR6;
    976 
    977     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    978     stars[i].lensing->detID      = ps1data[i].detID;
     964    // catalog->lensing[i].F_ApR6    = ps1data[i].F_ApR6;
     965    // catalog->lensing[i].dF_ApR6   = ps1data[i].dF_ApR6;
     966    // catalog->lensing[i].sF_ApR6   = ps1data[i].sF_ApR6;
     967    // catalog->lensing[i].fF_ApR6   = ps1data[i].fF_ApR6;
     968
     969    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     970    catalog->lensing[i].detID      = ps1data[i].detID;
    979971
    980972    // the Average fields and the following Measure fields are set in FilterStars after
     
    987979    // the following fields are currently not being set anywhere: t_msec
    988980  }   
    989   *nstars = Nstars;
    990   return (stars);
    991 }
    992 
    993 Stars *Convert_PS1_V5_R1_Lensing (FTable *table, unsigned int *nstars) {
     981  return catalog;
     982}
     983
     984Catalog *Convert_PS1_V5_R1_Lensing (FTable *table) {
    994985
    995986  off_t Nstars;
    996987  unsigned int i;
    997988  double ZeroPt;
    998   Stars *stars;
    999989  CMF_PS1_V5_R1_Lensing *ps1data;
    1000990
     
    1006996  ZeroPt = GetZeroPoint();
    1007997
    1008   ALLOCATE (stars, Stars, Nstars);
    1009   for (i = 0; i < Nstars; i++) {
    1010     InitStar (&stars[i]);
    1011     stars[i].measure.Xccd       = ps1data[i].X;
    1012     stars[i].measure.Yccd       = ps1data[i].Y;
    1013     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1014     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1015 
    1016     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1017     stars[i].measure.pltscale   = ps1data[i].pltscale;
     998  Catalog *catalog = addstar_catalog_init (Nstars);
     999  ALLOCATE (catalog->lensing, Lensing, Nstars);
     1000  catalog->Nlensing = Nstars;
     1001
     1002  for (i = 0; i < Nstars; i++) {
     1003    catalog->measure[i].Xccd       = ps1data[i].X;
     1004    catalog->measure[i].Yccd       = ps1data[i].Y;
     1005    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1006    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1007
     1008    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1009    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    10181010
    10191011    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1020       stars[i].measure.M      = NAN;
    1021     } else {
    1022       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1023     }
    1024     stars[i].measure.dM         = ps1data[i].dM;
    1025     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1026     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1027     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1028                        
    1029     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1030     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1012      catalog->measure[i].M      = NAN;
     1013    } else {
     1014      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1015    }
     1016    catalog->measure[i].dM         = ps1data[i].dM;
     1017    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1018    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1019    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1020                       
     1021    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1022    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    10311023                       
    10321024    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1033     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1034     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1035     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1036     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1037     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1038     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1039 
    1040     stars[i].measure.Sky        = ps1data[i].sky;
    1041     stars[i].measure.dSky       = ps1data[i].dSky;
    1042                        
    1043     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1044     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1045     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1046 
    1047     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1048     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1049     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1050 
    1051     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1052     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1053     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1054 
    1055     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1056     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1057     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1058                        
    1059     stars[i].measure.photFlags  = ps1data[i].flags;
    1060     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1061 
    1062     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1063     stars[i].measure.detID      = ps1data[i].detID;
    1064 
    1065     ALLOCATE (stars[i].lensing, Lensing, 1);
    1066     dvo_lensing_init (stars[i].lensing);
    1067 
    1068     stars[i].lensing->X11_sm_obj  = ps1data[i].X11_sm_obj;
    1069     stars[i].lensing->X12_sm_obj  = ps1data[i].X12_sm_obj;
    1070     stars[i].lensing->X22_sm_obj  = ps1data[i].X22_sm_obj;
    1071     stars[i].lensing->E1_sm_obj   = ps1data[i].E1_sm_obj;
    1072     stars[i].lensing->E2_sm_obj   = ps1data[i].E2_sm_obj;
    1073 
    1074     stars[i].lensing->X11_sh_obj  = ps1data[i].X11_sh_obj;
    1075     stars[i].lensing->X12_sh_obj  = ps1data[i].X12_sh_obj;
    1076     stars[i].lensing->X22_sh_obj  = ps1data[i].X22_sh_obj;
    1077     stars[i].lensing->E1_sh_obj   = ps1data[i].E1_sh_obj;
    1078     stars[i].lensing->E2_sh_obj   = ps1data[i].E2_sh_obj;
    1079 
    1080     stars[i].lensing->X11_sm_psf  = ps1data[i].X11_sm_psf;
    1081     stars[i].lensing->X12_sm_psf  = ps1data[i].X12_sm_psf;
    1082     stars[i].lensing->X22_sm_psf  = ps1data[i].X22_sm_psf;
    1083     stars[i].lensing->E1_sm_psf   = ps1data[i].E1_sm_psf;
    1084     stars[i].lensing->E2_sm_psf   = ps1data[i].E2_sm_psf;
    1085 
    1086     stars[i].lensing->X11_sh_psf  = ps1data[i].X11_sh_psf;
    1087     stars[i].lensing->X12_sh_psf  = ps1data[i].X12_sh_psf;
    1088     stars[i].lensing->X22_sh_psf  = ps1data[i].X22_sh_psf;
    1089     stars[i].lensing->E1_sh_psf   = ps1data[i].E1_sh_psf;
    1090     stars[i].lensing->E2_sh_psf   = ps1data[i].E2_sh_psf;
    1091 
    1092     // stars[i].lensing->F_ApR5    = ps1data[i].F_ApR5;
    1093     // stars[i].lensing->dF_ApR5   = ps1data[i].dF_ApR5;
    1094     // stars[i].lensing->sF_ApR5   = ps1data[i].sF_ApR5;
    1095     // stars[i].lensing->fF_ApR5   = ps1data[i].fF_ApR5;
     1025    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1026    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1027    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1028    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1029    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1030    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1031
     1032    catalog->measure[i].Sky        = ps1data[i].sky;
     1033    catalog->measure[i].dSky       = ps1data[i].dSky;
     1034                       
     1035    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1036    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1037    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1038
     1039    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1040    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1041    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1042
     1043    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1044    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1045    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1046
     1047    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1048    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1049    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1050                       
     1051    catalog->measure[i].photFlags  = ps1data[i].flags;
     1052    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1053
     1054    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1055    catalog->measure[i].detID      = ps1data[i].detID;
     1056
     1057    dvo_lensing_init (&catalog->lensing[i]);
     1058
     1059    catalog->lensing[i].X11_sm_obj  = ps1data[i].X11_sm_obj;
     1060    catalog->lensing[i].X12_sm_obj  = ps1data[i].X12_sm_obj;
     1061    catalog->lensing[i].X22_sm_obj  = ps1data[i].X22_sm_obj;
     1062    catalog->lensing[i].E1_sm_obj   = ps1data[i].E1_sm_obj;
     1063    catalog->lensing[i].E2_sm_obj   = ps1data[i].E2_sm_obj;
     1064
     1065    catalog->lensing[i].X11_sh_obj  = ps1data[i].X11_sh_obj;
     1066    catalog->lensing[i].X12_sh_obj  = ps1data[i].X12_sh_obj;
     1067    catalog->lensing[i].X22_sh_obj  = ps1data[i].X22_sh_obj;
     1068    catalog->lensing[i].E1_sh_obj   = ps1data[i].E1_sh_obj;
     1069    catalog->lensing[i].E2_sh_obj   = ps1data[i].E2_sh_obj;
     1070
     1071    catalog->lensing[i].X11_sm_psf  = ps1data[i].X11_sm_psf;
     1072    catalog->lensing[i].X12_sm_psf  = ps1data[i].X12_sm_psf;
     1073    catalog->lensing[i].X22_sm_psf  = ps1data[i].X22_sm_psf;
     1074    catalog->lensing[i].E1_sm_psf   = ps1data[i].E1_sm_psf;
     1075    catalog->lensing[i].E2_sm_psf   = ps1data[i].E2_sm_psf;
     1076
     1077    catalog->lensing[i].X11_sh_psf  = ps1data[i].X11_sh_psf;
     1078    catalog->lensing[i].X12_sh_psf  = ps1data[i].X12_sh_psf;
     1079    catalog->lensing[i].X22_sh_psf  = ps1data[i].X22_sh_psf;
     1080    catalog->lensing[i].E1_sh_psf   = ps1data[i].E1_sh_psf;
     1081    catalog->lensing[i].E2_sh_psf   = ps1data[i].E2_sh_psf;
     1082
     1083    // catalog->lensing[i].F_ApR5    = ps1data[i].F_ApR5;
     1084    // catalog->lensing[i].dF_ApR5   = ps1data[i].dF_ApR5;
     1085    // catalog->lensing[i].sF_ApR5   = ps1data[i].sF_ApR5;
     1086    // catalog->lensing[i].fF_ApR5   = ps1data[i].fF_ApR5;
    10961087    //
    1097     // stars[i].lensing->F_ApR6    = ps1data[i].F_ApR6;
    1098     // stars[i].lensing->dF_ApR6   = ps1data[i].dF_ApR6;
    1099     // stars[i].lensing->sF_ApR6   = ps1data[i].sF_ApR6;
    1100     // stars[i].lensing->fF_ApR6   = ps1data[i].fF_ApR6;
    1101 
    1102     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1103     stars[i].lensing->detID      = ps1data[i].detID;
     1088    // catalog->lensing[i].F_ApR6    = ps1data[i].F_ApR6;
     1089    // catalog->lensing[i].dF_ApR6   = ps1data[i].dF_ApR6;
     1090    // catalog->lensing[i].sF_ApR6   = ps1data[i].sF_ApR6;
     1091    // catalog->lensing[i].fF_ApR6   = ps1data[i].fF_ApR6;
     1092
     1093    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1094    catalog->lensing[i].detID      = ps1data[i].detID;
    11041095
    11051096    // the Average fields and the following Measure fields are set in FilterStars after
     
    11121103    // the following fields are currently not being set anywhere: t_msec
    11131104  }   
    1114   *nstars = Nstars;
    1115   return (stars);
    1116 }
    1117 
    1118 Stars *Convert_PS1_V5_R2_Lensing (FTable *table, unsigned int *nstars) {
     1105  return catalog;
     1106}
     1107
     1108Catalog *Convert_PS1_V5_R2_Lensing (FTable *table) {
    11191109
    11201110  off_t Nstars;
    11211111  unsigned int i;
    11221112  double ZeroPt;
    1123   Stars *stars;
    11241113  CMF_PS1_V5_R2_Lensing *ps1data;
    11251114
    1126   ps1data = gfits_table_get_CMF_PS1_V5_R2_Lensing (table, &Nstars, NULL);
     1115  // this code expects the output cmf files to have a fixed column order
     1116  // unfortunatly, psphot is not consistent for the obj lensing values:
     1117  // if the first object in the list is not a valid object for the lensing measurement, then
     1118  // the lensingOBJ structure is not allocated for that source and the corresponding rows
     1119  // are not added to the output metadata until an object which does include the
     1120  // measurement.
     1121
     1122  char field[128];
     1123  gfits_scan (table->header, "TTYPE45", "%s", 1, field);
     1124
     1125  int mode = 0;
     1126  if (!strcmp (field, "LENS_X11_SM_OBJ")) { mode = 1; }
     1127  if (!strcmp (field, "LENS_X11_SM_PSF")) { mode = 2; }
     1128  myAssert (mode, "invalid table layout\n");
     1129
     1130  if (mode == 1) {
     1131    ps1data = gfits_table_get_CMF_PS1_V5_R2_Lensing (table, &Nstars, NULL);
     1132    fprintf (stderr, "PS1_V5_R2_Lensing mode 1\n");
     1133  }
     1134  if (mode == 2) {
     1135    ps1data = gfits_table_get_CMF_PS1_V5_R2x_Lensing (table, &Nstars, NULL);
     1136    fprintf (stderr, "PS1_V5_R2_Lensing mode 2\n");
     1137  }
     1138
    11271139  if (!ps1data) {
    11281140    fprintf (stderr, "skipping inconsistent entry\n");
     
    11311143  ZeroPt = GetZeroPoint();
    11321144
    1133   ALLOCATE (stars, Stars, Nstars);
    1134   for (i = 0; i < Nstars; i++) {
    1135     InitStar (&stars[i]);
    1136     stars[i].measure.Xccd       = ps1data[i].X;
    1137     stars[i].measure.Yccd       = ps1data[i].Y;
    1138     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1139     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1140 
    1141     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1142     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1145  Catalog *catalog = addstar_catalog_init (Nstars);
     1146  ALLOCATE (catalog->lensing, Lensing, Nstars);
     1147  catalog->Nlensing = Nstars;
     1148
     1149  for (i = 0; i < Nstars; i++) {
     1150    catalog->measure[i].Xccd       = ps1data[i].X;
     1151    catalog->measure[i].Yccd       = ps1data[i].Y;
     1152    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1153    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1154
     1155    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1156    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    11431157
    11441158    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1145       stars[i].measure.M      = NAN;
    1146     } else {
    1147       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1148     }
    1149     stars[i].measure.dM         = ps1data[i].dM;
    1150     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1151     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1152     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1153                        
    1154     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1155     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1159      catalog->measure[i].M      = NAN;
     1160    } else {
     1161      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1162    }
     1163    catalog->measure[i].dM         = ps1data[i].dM;
     1164    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1165    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1166    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1167                       
     1168    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1169    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    11561170                       
    11571171    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1158     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1159     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1160     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1161     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1162     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1163     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1164 
    1165     stars[i].measure.Sky        = ps1data[i].sky;
    1166     stars[i].measure.dSky       = ps1data[i].dSky;
    1167                        
    1168     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1169     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1170     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1171 
    1172     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1173     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1174     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1175 
    1176     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1177     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1178     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1179 
    1180     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1181     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1182     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1183                        
    1184     stars[i].measure.photFlags  = ps1data[i].flags;
    1185     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1186 
    1187     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1188     stars[i].measure.detID      = ps1data[i].detID;
    1189 
    1190     ALLOCATE (stars[i].lensing, Lensing, 1);
    1191     dvo_lensing_init (stars[i].lensing);
    1192 
    1193     stars[i].lensing->X11_sm_obj  = ps1data[i].X11_sm_obj;
    1194     stars[i].lensing->X12_sm_obj  = ps1data[i].X12_sm_obj;
    1195     stars[i].lensing->X22_sm_obj  = ps1data[i].X22_sm_obj;
    1196     stars[i].lensing->E1_sm_obj   = ps1data[i].E1_sm_obj;
    1197     stars[i].lensing->E2_sm_obj   = ps1data[i].E2_sm_obj;
    1198 
    1199     stars[i].lensing->X11_sh_obj  = ps1data[i].X11_sh_obj;
    1200     stars[i].lensing->X12_sh_obj  = ps1data[i].X12_sh_obj;
    1201     stars[i].lensing->X22_sh_obj  = ps1data[i].X22_sh_obj;
    1202     stars[i].lensing->E1_sh_obj   = ps1data[i].E1_sh_obj;
    1203     stars[i].lensing->E2_sh_obj   = ps1data[i].E2_sh_obj;
    1204 
    1205     stars[i].lensing->X11_sm_psf  = ps1data[i].X11_sm_psf;
    1206     stars[i].lensing->X12_sm_psf  = ps1data[i].X12_sm_psf;
    1207     stars[i].lensing->X22_sm_psf  = ps1data[i].X22_sm_psf;
    1208     stars[i].lensing->E1_sm_psf   = ps1data[i].E1_sm_psf;
    1209     stars[i].lensing->E2_sm_psf   = ps1data[i].E2_sm_psf;
    1210 
    1211     stars[i].lensing->X11_sh_psf  = ps1data[i].X11_sh_psf;
    1212     stars[i].lensing->X12_sh_psf  = ps1data[i].X12_sh_psf;
    1213     stars[i].lensing->X22_sh_psf  = ps1data[i].X22_sh_psf;
    1214     stars[i].lensing->E1_sh_psf   = ps1data[i].E1_sh_psf;
    1215     stars[i].lensing->E2_sh_psf   = ps1data[i].E2_sh_psf;
    1216 
    1217     stars[i].lensing->E1_psf      = ps1data[i].E1_psf;
    1218     stars[i].lensing->E2_psf      = ps1data[i].E2_psf;
    1219 
    1220     // stars[i].lensing->F_ApR5    = ps1data[i].F_ApR5;
    1221     // stars[i].lensing->dF_ApR5   = ps1data[i].dF_ApR5;
    1222     // stars[i].lensing->sF_ApR5   = ps1data[i].sF_ApR5;
    1223     // stars[i].lensing->fF_ApR5   = ps1data[i].fF_ApR5;
    1224     //
    1225     // stars[i].lensing->F_ApR6    = ps1data[i].F_ApR6;
    1226     // stars[i].lensing->dF_ApR6   = ps1data[i].dF_ApR6;
    1227     // stars[i].lensing->sF_ApR6   = ps1data[i].sF_ApR6;
    1228     // stars[i].lensing->fF_ApR6   = ps1data[i].fF_ApR6;
    1229 
    1230     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1231     stars[i].lensing->detID      = ps1data[i].detID;
     1172    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1173    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1174    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1175    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1176    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1177    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1178
     1179    catalog->measure[i].Sky        = ps1data[i].sky;
     1180    catalog->measure[i].dSky       = ps1data[i].dSky;
     1181                       
     1182    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1183    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1184    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1185
     1186    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1187    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1188    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1189
     1190    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1191    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1192    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1193
     1194    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1195    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1196    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1197                       
     1198    catalog->measure[i].photFlags  = ps1data[i].flags;
     1199    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1200
     1201    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1202    catalog->measure[i].detID      = ps1data[i].detID;
     1203
     1204    dvo_lensing_init (&catalog->lensing[i]);
     1205
     1206    catalog->lensing[i].X11_sm_obj  = ps1data[i].X11_sm_obj;
     1207    catalog->lensing[i].X12_sm_obj  = ps1data[i].X12_sm_obj;
     1208    catalog->lensing[i].X22_sm_obj  = ps1data[i].X22_sm_obj;
     1209    catalog->lensing[i].E1_sm_obj   = ps1data[i].E1_sm_obj;
     1210    catalog->lensing[i].E2_sm_obj   = ps1data[i].E2_sm_obj;
     1211
     1212    catalog->lensing[i].X11_sh_obj  = ps1data[i].X11_sh_obj;
     1213    catalog->lensing[i].X12_sh_obj  = ps1data[i].X12_sh_obj;
     1214    catalog->lensing[i].X22_sh_obj  = ps1data[i].X22_sh_obj;
     1215    catalog->lensing[i].E1_sh_obj   = ps1data[i].E1_sh_obj;
     1216    catalog->lensing[i].E2_sh_obj   = ps1data[i].E2_sh_obj;
     1217
     1218    catalog->lensing[i].X11_sm_psf  = ps1data[i].X11_sm_psf;
     1219    catalog->lensing[i].X12_sm_psf  = ps1data[i].X12_sm_psf;
     1220    catalog->lensing[i].X22_sm_psf  = ps1data[i].X22_sm_psf;
     1221    catalog->lensing[i].E1_sm_psf   = ps1data[i].E1_sm_psf;
     1222    catalog->lensing[i].E2_sm_psf   = ps1data[i].E2_sm_psf;
     1223
     1224    catalog->lensing[i].X11_sh_psf  = ps1data[i].X11_sh_psf;
     1225    catalog->lensing[i].X12_sh_psf  = ps1data[i].X12_sh_psf;
     1226    catalog->lensing[i].X22_sh_psf  = ps1data[i].X22_sh_psf;
     1227    catalog->lensing[i].E1_sh_psf   = ps1data[i].E1_sh_psf;
     1228    catalog->lensing[i].E2_sh_psf   = ps1data[i].E2_sh_psf;
     1229
     1230    catalog->lensing[i].E1_psf      = ps1data[i].E1_psf;
     1231    catalog->lensing[i].E2_psf      = ps1data[i].E2_psf;
     1232
     1233    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1234    catalog->lensing[i].detID       = ps1data[i].detID;
    12321235
    12331236    // the Average fields and the following Measure fields are set in FilterStars after
     
    12401243    // the following fields are currently not being set anywhere: t_msec
    12411244  }   
    1242   *nstars = Nstars;
    1243   return (stars);
    1244 }
    1245 
    1246 Stars *Convert_PS1_SV1 (FTable *table, unsigned int *nstars) {
     1245  return catalog;
     1246}
     1247
     1248Catalog *Convert_PS1_SV1 (FTable *table) {
    12471249
    12481250  off_t Nstars;
    12491251  unsigned int i;
    12501252  double ZeroPt;
    1251   Stars *stars;
    12521253  CMF_PS1_SV1 *ps1data;
    12531254
    12541255  if (table[0].header[0].Naxis[0] == 196) {
    1255     stars = Convert_PS1_SV1_Alt (table, nstars);
    1256     return (stars);
     1256    Catalog *catalog = Convert_PS1_SV1_Alt (table);
     1257    return catalog;
    12571258  }
    12581259
     
    12641265  ZeroPt = GetZeroPoint();
    12651266
    1266   ALLOCATE (stars, Stars, Nstars);
    1267   for (i = 0; i < Nstars; i++) {
    1268     InitStar (&stars[i]);
    1269     stars[i].measure.Xccd       = ps1data[i].X;
    1270     stars[i].measure.Yccd       = ps1data[i].Y;
    1271     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1272     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1273 
    1274     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1275     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1267  Catalog *catalog = addstar_catalog_init (Nstars);
     1268
     1269  for (i = 0; i < Nstars; i++) {
     1270    catalog->measure[i].Xccd       = ps1data[i].X;
     1271    catalog->measure[i].Yccd       = ps1data[i].Y;
     1272    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1273    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1274
     1275    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1276    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    12761277
    12771278    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1278       stars[i].measure.M      = NAN;
    1279     } else {
    1280       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1281     }
    1282     stars[i].measure.dM         = ps1data[i].dM;
    1283     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1284     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1285     stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    1286                        
    1287     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1288     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1279      catalog->measure[i].M      = NAN;
     1280    } else {
     1281      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1282    }
     1283    catalog->measure[i].dM         = ps1data[i].dM;
     1284    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1285    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1286    catalog->measure[i].dMap       = ps1data[i].dM; // a proxy measure
     1287                       
     1288    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1289    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    12891290
    12901291    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1291     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1292     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1293     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1294     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1295     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
    1296     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1297 
    1298     stars[i].measure.Sky        = ps1data[i].sky;
    1299     stars[i].measure.dSky       = ps1data[i].dSky;
    1300                        
    1301     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1302     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1303     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1304 
    1305     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1306     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1307     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1308 
    1309     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1310     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1311     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1312 
    1313     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1314     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1315     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1316                        
    1317     stars[i].measure.photFlags  = ps1data[i].flags;
    1318     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1319 
    1320     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1321     stars[i].measure.detID      = ps1data[i].detID;
     1292    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1293    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1294    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1295    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1296    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     1297    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (NAN, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1298
     1299    catalog->measure[i].Sky        = ps1data[i].sky;
     1300    catalog->measure[i].dSky       = ps1data[i].dSky;
     1301                       
     1302    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1303    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1304    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1305
     1306    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1307    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1308    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1309
     1310    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1311    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1312    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1313
     1314    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1315    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1316    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1317                       
     1318    catalog->measure[i].photFlags  = ps1data[i].flags;
     1319    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1320
     1321    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1322    catalog->measure[i].detID      = ps1data[i].detID;
    13221323
    13231324    // the Average fields and the following Measure fields are set in FilterStars after
     
    13271328    // the following fields are currently not being set anywhere: t_msec
    13281329  }   
    1329   *nstars = Nstars;
    1330   return (stars);
    1331 }
    1332 
    1333 Stars *Convert_PS1_SV1_Alt (FTable *table, unsigned int *nstars) {
     1330  return catalog;
     1331}
     1332
     1333Catalog *Convert_PS1_SV1_Alt (FTable *table) {
    13341334
    13351335  off_t Nstars;
    13361336  unsigned int i;
    13371337  double ZeroPt;
    1338   Stars *stars;
    13391338  CMF_PS1_SV1 *ps1data;
    13401339
    13411340  // some test output files were produced called CMF_PS1_SV1 but with mismatch byte boundaries
    1342 
    13431341  ps1data = gfits_table_get_CMF_PS1_SV1_Alt (table, &Nstars, NULL);
    13441342  if (!ps1data) {
     
    13481346  ZeroPt = GetZeroPoint();
    13491347
    1350   ALLOCATE (stars, Stars, Nstars);
    1351   for (i = 0; i < Nstars; i++) {
    1352     InitStar (&stars[i]);
    1353     stars[i].measure.Xccd       = ps1data[i].X;
    1354     stars[i].measure.Yccd       = ps1data[i].Y;
    1355     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1356     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1357 
    1358     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1359     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1348  Catalog *catalog = addstar_catalog_init (Nstars);
     1349
     1350  for (i = 0; i < Nstars; i++) {
     1351    catalog->measure[i].Xccd       = ps1data[i].X;
     1352    catalog->measure[i].Yccd       = ps1data[i].Y;
     1353    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1354    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1355
     1356    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1357    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    13601358
    13611359    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1362       stars[i].measure.M      = NAN;
    1363     } else {
    1364       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1365     }
    1366     stars[i].measure.dM         = ps1data[i].dM;
    1367     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1368     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1369     stars[i].measure.dMap       = ps1data[i].dM; // a proxy measure
    1370                        
    1371     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1372     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1360      catalog->measure[i].M      = NAN;
     1361    } else {
     1362      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1363    }
     1364    catalog->measure[i].dM         = ps1data[i].dM;
     1365    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1366    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1367    catalog->measure[i].dMap       = ps1data[i].dM; // a proxy measure
     1368                       
     1369    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1370    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    13731371
    13741372    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1375     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1376     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1377     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1378     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1379     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
    1380     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (NAN, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1381 
    1382     stars[i].measure.Sky        = ps1data[i].sky;
    1383     stars[i].measure.dSky       = ps1data[i].dSky;
    1384                        
    1385     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1386     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1387     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1388     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1389     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1390 
    1391     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1392     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1393     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1394 
    1395     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1396     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1397     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1398                        
    1399     stars[i].measure.photFlags  = ps1data[i].flags;
    1400     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1401 
    1402     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1403     stars[i].measure.detID      = ps1data[i].detID;
     1373    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1374    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1375    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1376    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1377    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (NAN, ps1data[i].Map);
     1378    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (NAN, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1379
     1380    catalog->measure[i].Sky        = ps1data[i].sky;
     1381    catalog->measure[i].dSky       = ps1data[i].dSky;
     1382                       
     1383    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1384    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1385    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1386    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1387    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1388
     1389    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1390    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1391    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1392
     1393    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1394    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1395    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1396                       
     1397    catalog->measure[i].photFlags  = ps1data[i].flags;
     1398    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1399
     1400    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1401    catalog->measure[i].detID      = ps1data[i].detID;
    14041402
    14051403    // the Average fields and the following Measure fields are set in FilterStars after
     
    14091407    // the following fields are currently not being set anywhere: t_msec
    14101408  }   
    1411   *nstars = Nstars;
    1412   return (stars);
    1413 }
    1414 
    1415 Stars *Convert_PS1_SV2 (FTable *table, unsigned int *nstars) {
     1409  return catalog;
     1410}
     1411
     1412Catalog *Convert_PS1_SV2 (FTable *table) {
    14161413
    14171414  off_t Nstars;
    14181415  unsigned int i;
    14191416  double ZeroPt;
    1420   Stars *stars;
    14211417  CMF_PS1_SV2 *ps1data;
    14221418
     
    14281424  ZeroPt = GetZeroPoint();
    14291425
    1430   ALLOCATE (stars, Stars, Nstars);
    1431   for (i = 0; i < Nstars; i++) {
    1432     InitStar (&stars[i]);
    1433     stars[i].measure.Xccd       = ps1data[i].X;
    1434     stars[i].measure.Yccd       = ps1data[i].Y;
    1435     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1436     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1437 
    1438     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1439     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1426  Catalog *catalog = addstar_catalog_init (Nstars);
     1427
     1428  for (i = 0; i < Nstars; i++) {
     1429    catalog->measure[i].Xccd       = ps1data[i].X;
     1430    catalog->measure[i].Yccd       = ps1data[i].Y;
     1431    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1432    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1433
     1434    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1435    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    14401436
    14411437    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1442       stars[i].measure.M      = NAN;
    1443     } else {
    1444       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1445     }
    1446     stars[i].measure.dM         = ps1data[i].dM;
    1447     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1448     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1449     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1450                        
    1451     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1452     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1438      catalog->measure[i].M      = NAN;
     1439    } else {
     1440      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1441    }
     1442    catalog->measure[i].dM         = ps1data[i].dM;
     1443    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1444    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1445    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1446                       
     1447    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1448    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    14531449
    14541450    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1455     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1456     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1457     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1458     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1459     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1460     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1461 
    1462     stars[i].measure.Sky        = ps1data[i].sky;
    1463     stars[i].measure.dSky       = ps1data[i].dSky;
    1464                        
    1465     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1466     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1467     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1468 
    1469     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1470     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1471     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1472 
    1473     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1474     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1475     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1476 
    1477     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1478     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1479     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1480                        
    1481     stars[i].measure.photFlags  = ps1data[i].flags;
    1482     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1483 
    1484     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1485     stars[i].measure.detID      = ps1data[i].detID;
     1451    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1452    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1453    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1454    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1455    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1456    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1457
     1458    catalog->measure[i].Sky        = ps1data[i].sky;
     1459    catalog->measure[i].dSky       = ps1data[i].dSky;
     1460                       
     1461    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1462    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1463    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1464
     1465    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1466    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1467    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1468
     1469    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1470    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1471    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1472
     1473    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1474    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1475    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1476                       
     1477    catalog->measure[i].photFlags  = ps1data[i].flags;
     1478    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1479
     1480    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1481    catalog->measure[i].detID      = ps1data[i].detID;
    14861482
    14871483    // the Average fields and the following Measure fields are set in FilterStars after
     
    14911487    // the following fields are currently not being set anywhere: t_msec
    14921488  }   
    1493   *nstars = Nstars;
    1494   return (stars);
    1495 }
    1496 
    1497 Stars *Convert_PS1_SV3 (FTable *table, unsigned int *nstars) {
     1489  return catalog;
     1490}
     1491
     1492Catalog *Convert_PS1_SV3 (FTable *table) {
    14981493
    14991494  off_t Nstars;
    15001495  unsigned int i;
    15011496  double ZeroPt;
    1502   Stars *stars;
    15031497  CMF_PS1_SV3 *ps1data;
    15041498
     
    15101504  ZeroPt = GetZeroPoint();
    15111505
    1512   ALLOCATE (stars, Stars, Nstars);
    1513   for (i = 0; i < Nstars; i++) {
    1514     InitStar (&stars[i]);
    1515     stars[i].measure.Xccd       = ps1data[i].X;
    1516     stars[i].measure.Yccd       = ps1data[i].Y;
    1517     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1518     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1519 
    1520     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1521     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1506  Catalog *catalog = addstar_catalog_init (Nstars);
     1507
     1508  for (i = 0; i < Nstars; i++) {
     1509    catalog->measure[i].Xccd       = ps1data[i].X;
     1510    catalog->measure[i].Yccd       = ps1data[i].Y;
     1511    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1512    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1513
     1514    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1515    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    15221516
    15231517    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1524       stars[i].measure.M      = NAN;
    1525     } else {
    1526       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1527     }
    1528     stars[i].measure.dM         = ps1data[i].dM;
    1529     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1530     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1531     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1532                        
    1533     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1534     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1518      catalog->measure[i].M      = NAN;
     1519    } else {
     1520      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1521    }
     1522    catalog->measure[i].dM         = ps1data[i].dM;
     1523    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1524    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1525    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1526                       
     1527    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1528    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    15351529
    15361530    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1537     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1538     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1539     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1540     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1541     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1542     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1543 
    1544     stars[i].measure.Sky        = ps1data[i].sky;
    1545     stars[i].measure.dSky       = ps1data[i].dSky;
    1546                        
    1547     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1548     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1549     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1550 
    1551     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1552     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1553     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1554 
    1555     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1556     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1557     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1558 
    1559     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1560     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1561     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1562                        
    1563     stars[i].measure.photFlags  = ps1data[i].flags;
    1564     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1565 
    1566     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1567     stars[i].measure.detID      = ps1data[i].detID;
     1531    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1532    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1533    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1534    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1535    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1536    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1537
     1538    catalog->measure[i].Sky        = ps1data[i].sky;
     1539    catalog->measure[i].dSky       = ps1data[i].dSky;
     1540                       
     1541    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1542    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1543    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1544
     1545    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1546    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1547    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1548
     1549    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1550    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1551    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1552
     1553    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1554    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1555    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1556                       
     1557    catalog->measure[i].photFlags  = ps1data[i].flags;
     1558    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1559
     1560    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1561    catalog->measure[i].detID      = ps1data[i].detID;
    15681562
    15691563    // the Average fields and the following Measure fields are set in FilterStars after
     
    15731567    // the following fields are currently not being set anywhere: t_msec
    15741568  }   
    1575   *nstars = Nstars;
    1576   return (stars);
    1577 }
    1578 
    1579 Stars *Convert_PS1_SV4 (FTable *table, unsigned int *nstars) {
     1569  return catalog;
     1570}
     1571
     1572Catalog *Convert_PS1_SV4 (FTable *table) {
    15801573
    15811574  off_t Nstars;
    15821575  unsigned int i;
    15831576  double ZeroPt;
    1584   Stars *stars;
    15851577  CMF_PS1_SV4 *ps1data;
    15861578
     
    15921584  ZeroPt = GetZeroPoint();
    15931585
    1594   ALLOCATE (stars, Stars, Nstars);
    1595   for (i = 0; i < Nstars; i++) {
    1596     InitStar (&stars[i]);
    1597     stars[i].measure.Xccd       = ps1data[i].X;
    1598     stars[i].measure.Yccd       = ps1data[i].Y;
    1599     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1600     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1601 
    1602     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1603     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1586  Catalog *catalog = addstar_catalog_init (Nstars);
     1587
     1588  for (i = 0; i < Nstars; i++) {
     1589    catalog->measure[i].Xccd       = ps1data[i].X;
     1590    catalog->measure[i].Yccd       = ps1data[i].Y;
     1591    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1592    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1593
     1594    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1595    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    16041596
    16051597    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1606       stars[i].measure.M      = NAN;
    1607     } else {
    1608       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1609     }
    1610     stars[i].measure.dM         = ps1data[i].dM;
    1611     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1612     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1613     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1614                        
    1615     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1616     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1598      catalog->measure[i].M      = NAN;
     1599    } else {
     1600      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1601    }
     1602    catalog->measure[i].dM         = ps1data[i].dM;
     1603    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1604    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1605    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1606                       
     1607    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1608    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    16171609
    16181610    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1619     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1620     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1621     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1622     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1623     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1624     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1625 
    1626     stars[i].measure.Sky        = ps1data[i].sky;
    1627     stars[i].measure.dSky       = ps1data[i].dSky;
    1628                        
    1629     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1630     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1631     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1632 
    1633     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1634     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1635     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1636 
    1637     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1638     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1639     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1640 
    1641     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1642     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1643     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1644                        
    1645     stars[i].measure.photFlags  = ps1data[i].flags;
    1646     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1647 
    1648     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1649     stars[i].measure.detID      = ps1data[i].detID;
     1611    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1612    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1613    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1614    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1615    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1616    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1617
     1618    catalog->measure[i].Sky        = ps1data[i].sky;
     1619    catalog->measure[i].dSky       = ps1data[i].dSky;
     1620                       
     1621    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1622    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1623    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1624
     1625    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1626    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1627    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1628
     1629    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1630    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1631    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1632
     1633    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1634    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1635    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1636                       
     1637    catalog->measure[i].photFlags  = ps1data[i].flags;
     1638    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1639
     1640    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1641    catalog->measure[i].detID      = ps1data[i].detID;
    16501642
    16511643    // the Average fields and the following Measure fields are set in FilterStars after
     
    16551647    // the following fields are currently not being set anywhere: t_msec
    16561648  }   
    1657   *nstars = Nstars;
    1658   return (stars);
    1659 }
    1660 
    1661 Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
     1649  return catalog;
     1650}
     1651
     1652Catalog *Convert_PS1_DV3 (FTable *table) {
    16621653
    16631654  off_t Nstars;
    16641655  unsigned int i;
    16651656  double ZeroPt;
    1666   Stars *stars;
    16671657  CMF_PS1_DV3 *ps1data;
    16681658
     
    16741664  ZeroPt = GetZeroPoint();
    16751665
    1676   ALLOCATE (stars, Stars, Nstars);
    1677   for (i = 0; i < Nstars; i++) {
    1678     InitStar (&stars[i]);
    1679     stars[i].measure.Xccd       = ps1data[i].X;
    1680     stars[i].measure.Yccd       = ps1data[i].Y;
    1681     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1682     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1683 
    1684     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1685     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1666  Catalog *catalog = addstar_catalog_init (Nstars);
     1667
     1668  for (i = 0; i < Nstars; i++) {
     1669    catalog->measure[i].Xccd       = ps1data[i].X;
     1670    catalog->measure[i].Yccd       = ps1data[i].Y;
     1671    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1672    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1673
     1674    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1675    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    16861676
    16871677    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1688       stars[i].measure.M      = NAN;
    1689     } else {
    1690       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1691     }
    1692     stars[i].measure.dM         = ps1data[i].dM;
    1693     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1694     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1695     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1696                        
    1697     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1698     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1678      catalog->measure[i].M      = NAN;
     1679    } else {
     1680      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1681    }
     1682    catalog->measure[i].dM         = ps1data[i].dM;
     1683    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1684    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1685    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1686                       
     1687    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1688    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    16991689                       
    17001690    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1701     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1702     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1703     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1704     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1705     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1706     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1707 
    1708     stars[i].measure.Sky        = ps1data[i].sky;
    1709     stars[i].measure.dSky       = ps1data[i].dSky;
    1710                        
    1711     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1712     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1713     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1714     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1715     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1716     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1717 
    1718     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1719     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1720     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1721 
    1722     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1723     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1724     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1725                        
    1726     stars[i].measure.photFlags  = ps1data[i].flags;
    1727     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1728 
    1729     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1730     stars[i].measure.detID      = ps1data[i].detID;
     1691    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1692    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1693    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1694    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1695    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1696    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1697
     1698    catalog->measure[i].Sky        = ps1data[i].sky;
     1699    catalog->measure[i].dSky       = ps1data[i].dSky;
     1700                       
     1701    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1702    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1703    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1704    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1705    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1706    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1707
     1708    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1709    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1710    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1711
     1712    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1713    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1714    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1715                       
     1716    catalog->measure[i].photFlags  = ps1data[i].flags;
     1717    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1718
     1719    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1720    catalog->measure[i].detID      = ps1data[i].detID;
    17311721
    17321722    // the Average fields and the following Measure fields are set in FilterStars after
     
    17391729    // the following fields are currently not being set anywhere: t_msec
    17401730  }   
    1741   *nstars = Nstars;
    1742   return (stars);
    1743 }
    1744 
    1745 Stars *Convert_PS1_DV4 (FTable *table, unsigned int *nstars) {
     1731  return catalog;
     1732}
     1733
     1734Catalog *Convert_PS1_DV4 (FTable *table) {
    17461735
    17471736  off_t Nstars;
    17481737  unsigned int i;
    17491738  double ZeroPt;
    1750   Stars *stars;
    17511739  CMF_PS1_DV4 *ps1data;
    17521740
     
    17601748  fprintf (stderr, "WARNING: Convert_PS1_DV4 not yet updated to match real format\n");
    17611749
    1762   ALLOCATE (stars, Stars, Nstars);
    1763   for (i = 0; i < Nstars; i++) {
    1764     InitStar (&stars[i]);
    1765     stars[i].measure.Xccd       = ps1data[i].X;
    1766     stars[i].measure.Yccd       = ps1data[i].Y;
    1767     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1768     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1769 
    1770     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1771     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1750  Catalog *catalog = addstar_catalog_init (Nstars);
     1751
     1752  for (i = 0; i < Nstars; i++) {
     1753    catalog->measure[i].Xccd       = ps1data[i].X;
     1754    catalog->measure[i].Yccd       = ps1data[i].Y;
     1755    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1756    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1757
     1758    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1759    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    17721760
    17731761    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1774       stars[i].measure.M      = NAN;
    1775     } else {
    1776       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1777     }
    1778     stars[i].measure.dM         = ps1data[i].dM;
    1779     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1780     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1781     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1782                        
    1783     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1784     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1762      catalog->measure[i].M      = NAN;
     1763    } else {
     1764      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1765    }
     1766    catalog->measure[i].dM         = ps1data[i].dM;
     1767    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1768    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1769    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1770                       
     1771    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1772    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    17851773                       
    17861774    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1787     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1788     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1789     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1790     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1791     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1792     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1793 
    1794     stars[i].measure.Sky        = ps1data[i].sky;
    1795     stars[i].measure.dSky       = ps1data[i].dSky;
    1796                        
    1797     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1798     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1799     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1800     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1801     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1802     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1803 
    1804     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1805     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1806     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1807 
    1808     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1809     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1810     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1811                        
    1812     stars[i].measure.photFlags  = ps1data[i].flags;
    1813     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1814 
    1815     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1816     stars[i].measure.detID      = ps1data[i].detID;
     1775    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1776    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1777    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1778    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1779    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1780    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1781
     1782    catalog->measure[i].Sky        = ps1data[i].sky;
     1783    catalog->measure[i].dSky       = ps1data[i].dSky;
     1784                       
     1785    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1786    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1787    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1788    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1789    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1790    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1791
     1792    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1793    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1794    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1795
     1796    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1797    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1798    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1799                       
     1800    catalog->measure[i].photFlags  = ps1data[i].flags;
     1801    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1802
     1803    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1804    catalog->measure[i].detID      = ps1data[i].detID;
    18171805
    18181806    // the Average fields and the following Measure fields are set in FilterStars after
     
    18251813    // the following fields are currently not being set anywhere: t_msec
    18261814  }   
    1827   *nstars = Nstars;
    1828   return (stars);
    1829 }
    1830 
    1831 Stars *Convert_PS1_DV5 (FTable *table, unsigned int *nstars) {
     1815  return catalog;
     1816}
     1817
     1818Catalog *Convert_PS1_DV5 (FTable *table) {
    18321819
    18331820  off_t Nstars;
    18341821  unsigned int i;
    18351822  double ZeroPt;
    1836   Stars *stars;
    18371823  CMF_PS1_DV5 *ps1data;
    18381824
     
    18441830  ZeroPt = GetZeroPoint();
    18451831
    1846   ALLOCATE (stars, Stars, Nstars);
    1847   for (i = 0; i < Nstars; i++) {
    1848     InitStar (&stars[i]);
    1849     stars[i].measure.Xccd       = ps1data[i].X;
    1850     stars[i].measure.Yccd       = ps1data[i].Y;
    1851     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
    1852     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
    1853 
    1854     stars[i].measure.posangle   = ToShortDegrees(ps1data[i].posangle);
    1855     stars[i].measure.pltscale   = ps1data[i].pltscale;
     1832  Catalog *catalog = addstar_catalog_init (Nstars);
     1833
     1834  for (i = 0; i < Nstars; i++) {
     1835    catalog->measure[i].Xccd       = ps1data[i].X;
     1836    catalog->measure[i].Yccd       = ps1data[i].Y;
     1837    catalog->measure[i].dXccd      = ToShortPixels(ps1data[i].dX);
     1838    catalog->measure[i].dYccd      = ToShortPixels(ps1data[i].dY);
     1839
     1840    catalog->measure[i].posangle   = ToShortDegrees(ps1data[i].posangle);
     1841    catalog->measure[i].pltscale   = ps1data[i].pltscale;
    18561842
    18571843    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    1858       stars[i].measure.M      = NAN;
    1859     } else {
    1860       stars[i].measure.M      = ps1data[i].M + ZeroPt;
    1861     }
    1862     stars[i].measure.dM         = ps1data[i].dM;
    1863     stars[i].measure.dMcal      = ps1data[i].dMcal;
    1864     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
    1865     stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
    1866                        
    1867     stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
    1868     stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
     1844      catalog->measure[i].M      = NAN;
     1845    } else {
     1846      catalog->measure[i].M      = ps1data[i].M + ZeroPt;
     1847    }
     1848    catalog->measure[i].dM         = ps1data[i].dM;
     1849    catalog->measure[i].dMcal      = ps1data[i].dMcal;
     1850    catalog->measure[i].Map        = ps1data[i].Map + ZeroPt;
     1851    catalog->measure[i].dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
     1852                       
     1853    catalog->measure[i].Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
     1854    catalog->measure[i].dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
    18691855                       
    18701856    // these fluxes are converted from counts to counts/sec in FilterStars.c
    1871     stars[i].measure.FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
    1872     stars[i].measure.dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, stars[i].measure.FluxPSF, ps1data[i].dM);
    1873     stars[i].measure.FluxKron   = ps1data[i].kronFlux;
    1874     stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
    1875     stars[i].measure.FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
    1876     stars[i].measure.dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, stars[i].measure.FluxAp, stars[i].measure.dMap);
    1877 
    1878     stars[i].measure.Sky        = ps1data[i].sky;
    1879     stars[i].measure.dSky       = ps1data[i].dSky;
    1880                        
    1881     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
    1882     stars[i].measure.psfQF      = ps1data[i].psfQF;
    1883     stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
    1884     stars[i].measure.psfNdof    = ps1data[i].psfNdof;
    1885     stars[i].measure.psfNpix    = ps1data[i].psfNpix;
    1886     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
    1887 
    1888     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
    1889     stars[i].measure.FWy        = ToShortPixels(ps1data[i].fy);
    1890     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
    1891 
    1892     stars[i].measure.Mxx        = ToShortPixels(ps1data[i].Mxx);
    1893     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
    1894     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
    1895                        
    1896     stars[i].measure.photFlags  = ps1data[i].flags;
    1897     stars[i].measure.photFlags2 = ps1data[i].flags2;
    1898 
    1899     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    1900     stars[i].measure.detID      = ps1data[i].detID;
     1857    catalog->measure[i].FluxPSF    = GetFluxFromFluxOrMag (ps1data[i].Flux, ps1data[i].M);
     1858    catalog->measure[i].dFluxPSF   = GetFluxErrFromFluxOrMag (ps1data[i].dFlux, catalog->measure[i].FluxPSF, ps1data[i].dM);
     1859    catalog->measure[i].FluxKron   = ps1data[i].kronFlux;
     1860    catalog->measure[i].dFluxKron  = ps1data[i].kronFluxErr;
     1861    catalog->measure[i].FluxAp     = GetFluxFromFluxOrMag (ps1data[i].apFlux, ps1data[i].Map);
     1862    catalog->measure[i].dFluxAp    = GetFluxErrFromFluxOrMag (ps1data[i].apFluxErr, catalog->measure[i].FluxAp, catalog->measure[i].dMap);
     1863
     1864    catalog->measure[i].Sky        = ps1data[i].sky;
     1865    catalog->measure[i].dSky       = ps1data[i].dSky;
     1866                       
     1867    catalog->measure[i].psfChisq   = ps1data[i].psfChisq;
     1868    catalog->measure[i].psfQF      = ps1data[i].psfQF;
     1869    catalog->measure[i].psfQFperf  = ps1data[i].psfQFperf;
     1870    catalog->measure[i].psfNdof    = ps1data[i].psfNdof;
     1871    catalog->measure[i].psfNpix    = ps1data[i].psfNpix;
     1872    catalog->measure[i].extNsigma  = ps1data[i].extNsigma;
     1873
     1874    catalog->measure[i].FWx        = ToShortPixels(ps1data[i].fx);
     1875    catalog->measure[i].FWy        = ToShortPixels(ps1data[i].fy);
     1876    catalog->measure[i].theta      = ToShortDegrees(ps1data[i].df);
     1877
     1878    catalog->measure[i].Mxx        = ToShortPixels(ps1data[i].Mxx);
     1879    catalog->measure[i].Mxy        = ToShortPixels(ps1data[i].Mxy);
     1880    catalog->measure[i].Myy        = ToShortPixels(ps1data[i].Myy);
     1881                       
     1882    catalog->measure[i].photFlags  = ps1data[i].flags;
     1883    catalog->measure[i].photFlags2 = ps1data[i].flags2;
     1884
     1885    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     1886    catalog->measure[i].detID      = ps1data[i].detID;
    19011887
    19021888    // the Average fields and the following Measure fields are set in FilterStars after
     
    19091895    // the following fields are currently not being set anywhere: t_msec
    19101896  }   
    1911   *nstars = Nstars;
    1912   return (stars);
    1913 }
    1914 
    1915 
    1916 
     1897  return catalog;
     1898}
  • trunk/Ohana/src/addstar/src/ReadStarsSDSS.c

    r38467 r38553  
    11# include "addstar.h"
    22
    3 int SetSDSSFlags (Stars *star, unsigned int flags1, unsigned int flags2);
     3int SetSDSSFlags (Measure *measure, unsigned int flags1, unsigned int flags2);
    44
    55# define NFILTER 5
     
    3333// given a file with the pointer at the start of the table block and the
    3434// corresponding image header, load the stars from the table
    35 Stars *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars) {
     35Catalog *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages) {
    3636
    3737  off_t Nskip, Nrow;
     
    4040  Header theader;
    4141  FTable table;
    42   Stars *stars;
    4342  double clockRate, mjd[5], jd, sidtime, alt, az;
    4443  float seeing[5], photErr[5], zeropt[5], ZeroPt;
     
    113112  // create a Star entry for each filter and detection
    114113  Nstars = table.header[0].Naxis[1];
    115   ALLOCATE (stars, Stars, NFILTER*Nstars);
     114
     115  Catalog *catalog = NULL;
     116  ALLOCATE (catalog, Catalog, 1);
     117  dvo_catalog_init (catalog, TRUE);
     118
     119  ALLOCATE (catalog->average, Average, Nstars);
     120  ALLOCATE (catalog->measure, Measure, NFILTER*Nstars);
     121
     122  for (i = 0; i < Nstars; i++) {
     123    for (j = 0; j < NFILTER; j++) {
     124      dvo_measure_init (&catalog->measure[i*NFILTER + j]);
     125    }
     126    dvo_average_init (&catalog->average[i]);
     127  }
    116128
    117129  GET_COLUMN_5 (rowc, float);
     
    145157
    146158  for (i = 0; i < Nstars; i++) {
     159    // any values not explicitly set are left at 0.0
     160    catalog->average[i].R             = ra[i] + dCOS(dec[i]) * offsetRa[i*NFILTER] / 3600.0;
     161    catalog->average[i].D             = dec[i] + offsetDec[i*NFILTER] / 3600.0;
     162    catalog->average[i].dR            = NAN;
     163    catalog->average[i].dD            = NAN;
     164    catalog->average[i].Nmeasure      = NFILTER;
     165    catalog->average[i].measureOffset = i*NFILTER;
     166
    147167    for (j = 0; j < NFILTER; j++) {
    148168      N = NFILTER*i + j;
    149       InitStar (&stars[N]);
    150169     
    151       // any values not explicitly set are left at 0.0
    152       stars[N].average.R         = ra[i] + dCOS(dec[i]) * offsetRa[N] / 3600.0;
    153       stars[N].average.D         = dec[i] + offsetDec[N] / 3600.0;
    154       stars[N].average.dR        = NAN;
    155       stars[N].average.dD        = NAN;
    156 
    157       stars[N].measure.R         = stars[N].average.R;
    158       stars[N].measure.D         = stars[N].average.D;
    159       stars[N].measure.Xccd      = colc[N];
    160       stars[N].measure.Yccd      = rowc[N];
    161       stars[N].measure.dXccd     = ToShortPixels(colcErr[N]);
    162       stars[N].measure.dYccd     = ToShortPixels(rowcErr[N]);
    163       stars[N].measure.M         = psfCounts[N] + ZeroPt - zeropt[j];
    164       stars[N].measure.dM        = psfCountsErr[N];
    165       stars[N].measure.Map       = fiberCounts[N] + ZeroPt - zeropt[j];
    166       stars[N].measure.Sky       = sky[N]; // adjust this to counts?
    167       stars[N].measure.dSky      = skyErr[N];
    168       stars[N].measure.FWx       = ToShortPixels(seeing[j]); // reported in arcsec?
    169       stars[N].measure.FWy       = ToShortPixels(seeing[j]);
     170      catalog->measure[N].R         = catalog->average[i].R;
     171      catalog->measure[N].D         = catalog->average[i].D;
     172      catalog->measure[N].Xccd      = colc[N];
     173      catalog->measure[N].Yccd      = rowc[N];
     174      catalog->measure[N].dXccd     = ToShortPixels(colcErr[N]);
     175      catalog->measure[N].dYccd     = ToShortPixels(rowcErr[N]);
     176      catalog->measure[N].M         = psfCounts[N] + ZeroPt - zeropt[j];
     177      catalog->measure[N].dM        = psfCountsErr[N];
     178      catalog->measure[N].Map       = fiberCounts[N] + ZeroPt - zeropt[j];
     179      catalog->measure[N].Sky       = sky[N]; // adjust this to counts?
     180      catalog->measure[N].dSky      = skyErr[N];
     181      catalog->measure[N].FWx       = ToShortPixels(seeing[j]); // reported in arcsec?
     182      catalog->measure[N].FWy       = ToShortPixels(seeing[j]);
    170183      if (prob_psf) {
    171           stars[N].measure.psfChisq  = prob_psf[N]; // XXX not really the correct value...
     184          catalog->measure[N].psfChisq  = prob_psf[N]; // XXX not really the correct value...
    172185      } else {
    173           stars[N].measure.psfChisq  = NAN;
     186          catalog->measure[N].psfChisq  = NAN;
    174187      }
    175       stars[N].measure.detID     = N;
    176       stars[N].measure.t         = tzero[j] + clockRate*rowc[N]; // time since row 0
    177       stars[N].measure.dt        = 4.32912209; // 2.5 * log(53.907456) the sdss exposure time // old comment is 53907456 is this 2048*clockRate ?
    178 
    179       SetSDSSFlags (&stars[N], flags[N], flags2[N]);
     188      catalog->measure[N].detID     = N;
     189      catalog->measure[N].t         = tzero[j] + clockRate*rowc[N]; // time since row 0
     190      catalog->measure[N].dt        = 4.32912209; // 2.5 * log(53.907456) the sdss exposure time // old comment is 53907456 is this 2048*clockRate ?
     191
     192      SetSDSSFlags (&catalog->measure[N], flags[N], flags2[N]);
    180193
    181194      // longitude and latitude for SDSS:
     
    187200      double Latitude = 32.7803611755; // degrees
    188201
    189       jd = ohana_sec_to_jd (stars[N].measure.t);
     202      jd = ohana_sec_to_jd (catalog->measure[N].t);
    190203      sidtime  = 15.0*ohana_lst (jd, Longitude); // sidtime in degrees
    191       altaz (&alt, &az, sidtime - stars[N].average.R, stars[N].average.D, Latitude);
    192 
    193       stars[N].measure.airmass   = 1.0 / dCOS(90.0 - alt);
    194       stars[N].measure.az        = az;
    195       stars[N].measure.photcode  = photcode[j];
    196       stars[N].measure.imageID   = j + *nimages; // set imageID to entry for this filter
     204      altaz (&alt, &az, sidtime - catalog->average[i].R, catalog->average[i].D, Latitude);
     205
     206      catalog->measure[N].airmass   = 1.0 / dCOS(90.0 - alt);
     207      catalog->measure[N].az        = az;
     208      catalog->measure[N].photcode  = photcode[j];
     209      catalog->measure[N].imageID   = j + *nimages; // set imageID to entry for this filter
    197210    }
    198211  }   
     
    204217    // XXX for now, we define a totally fake coordinate system centered on the first listed star
    205218    InitCoords (&images[N].coords, "DEC--TAN");
    206     images[N].coords.crval1 = stars[0].average.R;
    207     images[N].coords.crval2 = stars[0].average.D;
    208     images[N].coords.crpix1 = stars[0].measure.Xccd;
    209     images[N].coords.crpix2 = stars[0].measure.Yccd;
     219    images[N].coords.crval1 = catalog->average[0].R;
     220    images[N].coords.crval2 = catalog->average[0].D;
     221    images[N].coords.crpix1 = catalog->measure[0].Xccd;
     222    images[N].coords.crpix2 = catalog->measure[0].Yccd;
    210223    images[N].coords.cdelt1 = images[N].coords.cdelt2 = 0.4 / 3600.0;
    211224
     
    244257
    245258    images[N].trate = clockRate * 1e-4;
    246     images[N].secz = stars[0].measure.airmass;
     259    images[N].secz = catalog->measure[0].airmass;
    247260    images[N].ccdnum = camcol;
    248261
     
    263276  }
    264277
    265   NSTAR_GROUP = NFILTER;
    266278  *nimages += NFILTER;
    267   *nstars = Nstars*NFILTER;
    268   return (stars);
     279  return (catalog);
    269280}
    270281
    271 int SetSDSSFlags (Stars *star, unsigned int flags1, unsigned int flags2) {
     282int SetSDSSFlags (Measure *measure, unsigned int flags1, unsigned int flags2) {
    272283
    273284  // XXX this is wrong, need to roll left to set the correct bit
    274   if (flags1 & 0x00000002) star[0].measure.photFlags |= 0x0001; // BRIGHT            - 1  1
    275   if (flags1 & 0x00000004) star[0].measure.photFlags |= 0x0002; // EDGE              - 1  2
    276   if (flags1 & 0x00000008) star[0].measure.photFlags |= 0x0004; // BLENDED           - 1  3
    277   if (flags1 & 0x00000010) star[0].measure.photFlags |= 0x0008; // CHILD             - 1  4
    278   if (flags1 & 0x00000020) star[0].measure.photFlags |= 0x0010; // PEAKCENTER        - 1  5
    279   if (flags1 & 0x00000040) star[0].measure.photFlags |= 0x0020; // NODEBLEND         - 1  6
    280   if (flags1 & 0x00040000) star[0].measure.photFlags |= 0x0040; // SATUR             - 1 18
    281   if (flags1 & 0x00080000) star[0].measure.photFlags |= 0x0080; // NOTCHECKED        - 1 19
    282   if (flags1 & 0x10000000) star[0].measure.photFlags |= 0x0100; // BINNED1           - 1 28
    283   if (flags1 & 0x20000000) star[0].measure.photFlags |= 0x0200; // BINNED2           - 1 29
    284   if (flags1 & 0x40000000) star[0].measure.photFlags |= 0x0400; // BINNED4           - 1 30
    285   if (flags2 & 0x00000040) star[0].measure.photFlags |= 0x0800; // LOCAL_EDGE        - 2  7
    286   if (flags2 & 0x00000800) star[0].measure.photFlags |= 0x1000; // INTERP_CENTER     - 2 12
    287   if (flags2 & 0x00002000) star[0].measure.photFlags |= 0x2000; // DEBLEND_NOPEAK    - 2 14
    288   if (flags2 & 0x02000000) star[0].measure.photFlags |= 0x4000; // NOTCHECKED_CENTER - 2 26
     285  if (flags1 & 0x00000002) measure->photFlags |= 0x0001; // BRIGHT            - 1  1
     286  if (flags1 & 0x00000004) measure->photFlags |= 0x0002; // EDGE              - 1  2
     287  if (flags1 & 0x00000008) measure->photFlags |= 0x0004; // BLENDED           - 1  3
     288  if (flags1 & 0x00000010) measure->photFlags |= 0x0008; // CHILD             - 1  4
     289  if (flags1 & 0x00000020) measure->photFlags |= 0x0010; // PEAKCENTER        - 1  5
     290  if (flags1 & 0x00000040) measure->photFlags |= 0x0020; // NODEBLEND         - 1  6
     291  if (flags1 & 0x00040000) measure->photFlags |= 0x0040; // SATUR             - 1 18
     292  if (flags1 & 0x00080000) measure->photFlags |= 0x0080; // NOTCHECKED        - 1 19
     293  if (flags1 & 0x10000000) measure->photFlags |= 0x0100; // BINNED1           - 1 28
     294  if (flags1 & 0x20000000) measure->photFlags |= 0x0200; // BINNED2           - 1 29
     295  if (flags1 & 0x40000000) measure->photFlags |= 0x0400; // BINNED4           - 1 30
     296  if (flags2 & 0x00000040) measure->photFlags |= 0x0800; // LOCAL_EDGE        - 2  7
     297  if (flags2 & 0x00000800) measure->photFlags |= 0x1000; // INTERP_CENTER     - 2 12
     298  if (flags2 & 0x00002000) measure->photFlags |= 0x2000; // DEBLEND_NOPEAK    - 2 14
     299  if (flags2 & 0x02000000) measure->photFlags |= 0x4000; // NOTCHECKED_CENTER - 2 26
    289300  return (TRUE);
    290301
  • trunk/Ohana/src/addstar/src/ReadStarsUKIRT.c

    r38467 r38553  
    88// given a file with the pointer at the start of the table block and the
    99// corresponding image header, load the stars from the table
    10 Stars *ReadStarsUKIRT (FILE *f, char *name, Header *header, Image *images, off_t *nimages, unsigned int *nstars) {
     10Catalog *ReadStarsUKIRT (FILE *f, char *imagename, Header *header, Image *images, off_t *nimages) {
    1111
    1212  off_t Nrow;
     
    1414  char type[80];
    1515  FTable table;
    16   Stars *stars;
    17  
    18   // ohana_memcheck_func (TRUE);
    19 
     16 
    2017  // the FITS binary table header is the same as the image header
    2118  table.header = header;
     
    3027    exit (1);
    3128  }
    32 
    33   // ohana_memcheck_func (TRUE);
    3429
    3530  Coords coords;
     
    110105  }
    111106
    112   // ohana_memcheck_func (TRUE);
     107  // ohana_memcheck (TRUE);
    113108
    114109  double mjd;
     
    129124  float ZeroPt = GetZeroPoint();
    130125
    131   // ohana_memcheck_func (TRUE);
     126  // ohana_memcheck (TRUE);
    132127
    133128  // create a Star entry for each filter and detection
    134129  int Nstars = table.header[0].Naxis[1];
    135   ALLOCATE (stars, Stars, Nstars);
     130
     131  Catalog *catalog = NULL;
     132  ALLOCATE (catalog, Catalog, 1);
     133  dvo_catalog_init (catalog, TRUE);
     134
     135  ALLOCATE (catalog->average, Average, Nstars);
     136  ALLOCATE (catalog->measure, Measure, Nstars);
     137
     138  int i;
     139  for (i = 0; i < Nstars; i++) {
     140    dvo_measure_init (&catalog->measure[i]);
     141    dvo_average_init (&catalog->average[i]);
     142  }
    136143
    137144  GET_COLUMN (X_coordinate, float);
     
    155162  double R, D, alt, az;
    156163
    157   // ohana_memcheck_func (TRUE);
    158 
    159   int i;
     164  // ohana_memcheck (TRUE);
     165
    160166  for (i = 0; i < Nstars; i++) {
    161     InitStar (&stars[i]);
    162      
     167
    163168    // any values not explicitly set are left at 0.0
    164169    XY_to_RD (&R, &D, X_coordinate[i], Y_coordinate[i], &coords);
    165170
    166     stars[i].average.R         = R;
    167     stars[i].average.D         = D;
    168     stars[i].average.dR        = NAN;
    169     stars[i].average.dD        = NAN;
    170 
    171     stars[i].measure.R         = stars[i].average.R;
    172     stars[i].measure.D         = stars[i].average.D;
    173     stars[i].measure.Xccd      = X_coordinate[i];
    174     stars[i].measure.Yccd      = Y_coordinate[i];
    175     stars[i].measure.dXccd     = ToShortPixels(X_coordinate_err[i]);
    176     stars[i].measure.dYccd     = ToShortPixels(Y_coordinate_err[i]);
    177 
    178     stars[i].measure.M         = -2.5*log10(Aper_flux_4[i]) + ZeroPt + magtime + ApCor4;
    179     stars[i].measure.dM        = Aper_flux_4_err[i] / Aper_flux_4[i];
    180     stars[i].measure.Map       = -2.5*log10(Aper_flux_7[i]) + ZeroPt + magtime + ApCor7;
    181     stars[i].measure.dMap      = Aper_flux_7_err[i] / Aper_flux_7[i];
    182     stars[i].measure.Mkron     = -2.5*log10(Kron_flux[i]) + ZeroPt + magtime;
    183     stars[i].measure.dMkron    = Kron_flux_err[i] / Kron_flux[i];
    184     stars[i].measure.Sky       = Sky_level[i]; // adjust this to counts?
    185     stars[i].measure.dSky      = Sky_rms[i];
    186     stars[i].measure.FWx       = ToShortPixels(seeing); // reported in arcsec?
    187     stars[i].measure.FWy       = ToShortPixels(seeing);
    188 
    189     stars[i].measure.Mcal      = Mcal;
    190 
    191     stars[i].measure.detID     = i;
    192     stars[i].measure.t         = tzero; // time since row 0
    193     stars[i].measure.dt        = magtime; // 2.5 * log(exptime)
    194 
    195     altaz (&alt, &az, sidtime_deg - stars[i].average.R, stars[i].average.D, Latitude);
    196 
    197     stars[i].measure.airmass   = 1.0 / dCOS(90.0 - alt);
    198     stars[i].measure.az        = az;
    199     stars[i].measure.photcode  = photcode;
    200     stars[i].measure.imageID   = *nimages; // set imageID to entry for this filter
     171    catalog->average[i].R             = R;
     172    catalog->average[i].D             = D;
     173    catalog->average[i].dR            = NAN;
     174    catalog->average[i].dD            = NAN;
     175    catalog->average[i].Nmeasure      = 1;
     176    catalog->average[i].measureOffset = i;
     177
     178    catalog->measure[i].R         = catalog->average[i].R;
     179    catalog->measure[i].D         = catalog->average[i].D;
     180    catalog->measure[i].Xccd      = X_coordinate[i];
     181    catalog->measure[i].Yccd      = Y_coordinate[i];
     182    catalog->measure[i].dXccd     = ToShortPixels(X_coordinate_err[i]);
     183    catalog->measure[i].dYccd     = ToShortPixels(Y_coordinate_err[i]);
     184
     185    catalog->measure[i].M         = -2.5*log10(Aper_flux_4[i]) + ZeroPt + magtime + ApCor4;
     186    catalog->measure[i].dM        = Aper_flux_4_err[i] / Aper_flux_4[i];
     187    catalog->measure[i].Map       = -2.5*log10(Aper_flux_7[i]) + ZeroPt + magtime + ApCor7;
     188    catalog->measure[i].dMap      = Aper_flux_7_err[i] / Aper_flux_7[i];
     189    catalog->measure[i].Mkron     = -2.5*log10(Kron_flux[i]) + ZeroPt + magtime;
     190    catalog->measure[i].dMkron    = Kron_flux_err[i] / Kron_flux[i];
     191    catalog->measure[i].Sky       = Sky_level[i]; // adjust this to counts?
     192    catalog->measure[i].dSky      = Sky_rms[i];
     193    catalog->measure[i].FWx       = ToShortPixels(seeing); // reported in arcsec?
     194    catalog->measure[i].FWy       = ToShortPixels(seeing);
     195
     196    catalog->measure[i].Mcal      = Mcal;
     197
     198    catalog->measure[i].detID     = i;
     199    catalog->measure[i].t         = tzero; // time since row 0
     200    catalog->measure[i].dt        = magtime; // 2.5 * log(exptime)
     201
     202    altaz (&alt, &az, sidtime_deg - catalog->average[i].R, catalog->average[i].D, Latitude);
     203
     204    catalog->measure[i].airmass   = 1.0 / dCOS(90.0 - alt);
     205    catalog->measure[i].az        = az;
     206    catalog->measure[i].photcode  = photcode;
     207    catalog->measure[i].imageID   = *nimages; // set imageID to entry for this filter
    201208  }
    202209
     
    204211    int N = *nimages;
    205212   
    206     // ohana_memcheck_func (TRUE);
     213    // ohana_memcheck (TRUE);
    207214
    208215    images[N].coords = coords;
     
    254261
    255262    // save the filename
    256     snprintf (images[N].name, DVO_IMAGE_NAME_LEN, "%s[%02d]", name, detID);
     263    snprintf (images[N].name, DVO_IMAGE_NAME_LEN, "%s[%02d]", imagename, detID);
    257264    *nimages = N + 1;
    258265  }
    259266 
    260   // ohana_memcheck_func (TRUE);
    261 
    262   *nstars = Nstars;
    263   return (stars);
     267  // ohana_memcheck (TRUE);
     268
     269  return (catalog);
    264270}
  • trunk/Ohana/src/addstar/src/ReadXradFITS.c

    r38153 r38553  
    33// given a file with the pointer at the start of the table block and the
    44// corresponding image header, load the xrad data from the table
    5 int ReadXradFITS (FILE *f, Header *theader, Stars *stars, unsigned int Nstars) {
     5int ReadXradFITS (FILE *f, Header *theader, Catalog *catalog) {
    66
    77  FTable table;
     
    5151  myAssert (Nrow == NrowAlt, "column mismatch?");
    5252
    53   if (Nrow > Nstars) {
     53  if (Nrow > catalog->Nmeasure) {
    5454    myAbort("more radial measurements than stars?  seems like a bug\n");
    5555  }
    5656
     57  myAssert (catalog->lensing, "lensing is not allocated");
     58  // we could allocate here, or just insist this is an error?
     59  // if (!catalog->lensing) {
     60  //   ALLOCATE (catalog->lensing, Lensing, catalog->Nmeasure);
     61  // }
     62
    5763  int i;
    5864  int Nap = 0;
    59   for (i = 0; i < Nstars; i++) {
    60     if (stars[i].measure.detID < RadID[Nap]) {
    61       continue; // this star does not have an aperture
     65  for (i = 0; i < catalog->Nmeasure; i++) {
     66    if (catalog->measure[i].detID < RadID[Nap]) {
     67      myAbort("star without radial aperture, seems like a bug"); // this star does not have an aperture
    6268    }
    63     if (stars[i].measure.detID > RadID[Nap]) {
     69    if (catalog->measure[i].detID > RadID[Nap]) {
    6470      myAbort("radial apertures out of order?  seems like a bug\n");
    6571    }
    6672
    67     // we could allocate here, or just insist this is an error?
    68     if (!stars[i].lensing) {
    69       fprintf (stderr, "!");
    70       ALLOCATE (stars[i].lensing, Lensing, 1);
    71       dvo_lensing_init (stars[i].lensing);
    72     }
     73    // we assumed we have already set up lensing in ReadStarsFITS.c
    7374
    7475    // XXX this is all hard-wired and should make use of the headers.
     
    7778    // SDSS  3, 4, 5, 6, 7
    7879
    79     stars[i].lensing-> F_ApR5 = AperFlux   [Nap*Ncol + 2];
    80     stars[i].lensing->dF_ApR5 = AperFluxErr[Nap*Ncol + 2];
    81     stars[i].lensing->sF_ApR5 = AperFluxStd[Nap*Ncol + 2];
    82     stars[i].lensing->fF_ApR5 = AperFill   [Nap*Ncol + 2];
     80    catalog->lensing[i]. F_ApR5 = AperFlux   [Nap*Ncol + 2];
     81    catalog->lensing[i].dF_ApR5 = AperFluxErr[Nap*Ncol + 2];
     82    catalog->lensing[i].sF_ApR5 = AperFluxStd[Nap*Ncol + 2];
     83    catalog->lensing[i].fF_ApR5 = AperFill   [Nap*Ncol + 2];
    8384
    84     stars[i].lensing-> F_ApR6 = AperFlux   [Nap*Ncol + 3];
    85     stars[i].lensing->dF_ApR6 = AperFluxErr[Nap*Ncol + 3];
    86     stars[i].lensing->sF_ApR6 = AperFluxStd[Nap*Ncol + 3];
    87     stars[i].lensing->fF_ApR6 = AperFill   [Nap*Ncol + 3];
     85    catalog->lensing[i]. F_ApR6 = AperFlux   [Nap*Ncol + 3];
     86    catalog->lensing[i].dF_ApR6 = AperFluxErr[Nap*Ncol + 3];
     87    catalog->lensing[i].sF_ApR6 = AperFluxStd[Nap*Ncol + 3];
     88    catalog->lensing[i].fF_ApR6 = AperFill   [Nap*Ncol + 3];
    8889
    89     stars[i].lensing-> F_ApR7 = AperFlux   [Nap*Ncol + 4];
    90     stars[i].lensing->dF_ApR7 = AperFluxErr[Nap*Ncol + 4];
    91     stars[i].lensing->sF_ApR7 = AperFluxStd[Nap*Ncol + 4];
    92     stars[i].lensing->fF_ApR7 = AperFill   [Nap*Ncol + 4];
     90    catalog->lensing[i]. F_ApR7 = AperFlux   [Nap*Ncol + 4];
     91    catalog->lensing[i].dF_ApR7 = AperFluxErr[Nap*Ncol + 4];
     92    catalog->lensing[i].sF_ApR7 = AperFluxStd[Nap*Ncol + 4];
     93    catalog->lensing[i].fF_ApR7 = AperFill   [Nap*Ncol + 4];
    9394    Nap ++;
    9495  }
     96  catalog->Nlensing = Nap;
     97
     98  gfits_free_table (&table);
     99  free (AperFlux);
     100  free (AperFluxErr);
     101  free (AperFluxStd);
     102  free (AperFill);
     103  free (RadID);
    95104
    96105  return TRUE;
  • trunk/Ohana/src/addstar/src/SkyListForStars.c

    r27435 r38553  
    11# include "addstar.h"
    22
     3# if (0)
    34void sort_stars_ra (Stars *stars, int N) {
    45
     
    6970
    7071*/
     72# endif
  • trunk/Ohana/src/addstar/src/UpdateImageIDs.c

    r38467 r38553  
    11# include "addstar.h"
    22
    3 int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages) {
     3int UpdateImageIDs (Catalog *catalog, Image *images, off_t Nimages) {
    44
    55  int i, status, isEmpty;
     
    5454  }
    5555
    56   for (i = 0; i < Nstars; i++) {
    57     stars[i].measure.imageID += imageID;
    58     if (stars[i].lensing) {
    59       stars[i].lensing->imageID += imageID;
     56  off_t j, m;
     57  for (i = 0; i < catalog->Naverage; i++) {
     58    m = catalog->average[i].measureOffset;
     59    for (j = 0; j < catalog->average[i].Nmeasure; j++, m++) {
     60      catalog->measure[m].imageID += imageID;
     61    }
     62    m = catalog->average[i].lensingOffset;
     63    for (j = 0; j < catalog->average[i].Nlensing; j++, m++) {
     64      catalog->lensing[m].imageID += imageID;
    6065    }
    6166  }
     
    8792
    8893  dvo_image_unlock (&db);
     94  gfits_db_free (&db);
    8995
    9096  return TRUE;
  • trunk/Ohana/src/addstar/src/addstar.c

    r38471 r38553  
    66int main (int argc, char **argv) {
    77
    8   unsigned int Nstars, Nsubset;
    98  int Nmatch, status, loadObjects;
    109  off_t i, Nimages;
    1110  off_t Naverage, Nmeasure, Nlensing;
    12   Stars *stars, **subset;
    13   Image *images;
    1411  Catalog catalog;
    1512  FITS_DB db;
     
    4845  MARKTIME ("init and config: %f sec\n", dtime); RESETTIME;
    4946
    50   stars = NULL;
     47  Catalog *newcat = NULL;
     48  Image *images = NULL;
    5149
    5250  /*** load in the new data (images, stars) ***/
    5351  switch (options.mode) {
    5452    case ADDSTAR_MODE_IMAGE:
    55       stars = LoadStars (argv[1], &Nstars, &images, &Nimages, &options);
     53      newcat = LoadStars (argv[1], &images, &Nimages, &options);
    5654      MARKTIME ("load smf: %f sec\n", dtime); RESETTIME;
    5755
    5856      // set and update the imageID sequence
    59       UpdateImageIDs (stars, Nstars, images, Nimages);
    60 
    61       if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars);
     57      UpdateImageIDs (newcat, images, Nimages);
     58
     59      // if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars);
    6260      for (i = 0; i < Nimages; i++) {
    6361        newlist = SkyListByImage (sky, -1, &images[i]);
     
    6866      ImageOptions (&options, images, Nimages);
    6967      break;
     68# if (0)
    7069    case ADDSTAR_MODE_REFLIST:
    7170      stars = grefstars (argv[1], options.photcode, &Nstars);
     
    8180      skylist[0].ownElements = FALSE;
    8281      break;
     82# endif
    8383
    8484    default:
     
    146146    switch (options.mode) {
    147147      case ADDSTAR_MODE_IMAGE:
    148         Nsubset = Nstars;
     148        // Nsubset = Nstars;
    149149        if (options.closest) {
    150           Nmatch += find_matches_closest (skylist[0].regions[i], stars, Nstars, &catalog, options);
     150          Nmatch += find_matches_closest (skylist[0].regions[i], newcat, &catalog, options);
    151151        } else {
    152           Nmatch += find_matches (skylist[0].regions[i], stars, Nstars, &catalog, options);
     152          Nmatch += find_matches (skylist[0].regions[i], newcat, &catalog, options);
    153153        }
    154154        break;
     155# if (0)
    155156      case ADDSTAR_MODE_REFCAT:
    156157        stars = greference (argv[1], skylist[0].regions[i], options.photcode, &Nstars);
    157       case ADDSTAR_MODE_REFLIST:
    158         subset = find_subset (skylist[0].regions[i], stars, Nstars, &Nsubset);
     158      case ADDSTAR_MODE_REFLIST: {
     159        Stars **subset = find_subset (skylist[0].regions[i], stars, Nstars, &Nsubset);
    159160        if (options.closest) {
    160161          Nmatch += find_matches_closest_refstars (skylist[0].regions[i], subset, Nsubset, &catalog, options);
     
    164165        if (Nsubset) free (subset);
    165166        break;
     167      }
     168# endif
     169      default:
     170        abort();
    166171    }
    167172    if (VERBOSE) MARKTIME ("match stars: %f sec\n", dtime); RESETTIME;
     
    173178
    174179    // write out catalog, if appropriate
    175     if (Nsubset && !options.only_images) {
     180    if (newcat->Naverage && !options.only_images) {
    176181      SetProtect (TRUE);
    177182      if (options.update) {
     
    187192    if (VERBOSE) MARKTIME ("save cpt: %f sec\n", dtime); RESETTIME;
    188193
    189     if (options.mode == ADDSTAR_MODE_REFCAT) free (stars);
    190   }
     194    if (options.mode == ADDSTAR_MODE_REFCAT) dvo_catalog_free (newcat);
     195  }
     196  SkyListFree (skylist);
    191197
    192198  // We only measure a single value for the entire mosaic (add all images to this function)
     
    218224    SetProtect (FALSE);
    219225  }
     226  FREE (images);
    220227  dvo_image_unlock (&db); /* unlock? */
     228  gfits_db_free (&db); /* unlock? */
    221229
    222230  gettimeofday (&stopAddstar, (void *) NULL);
    223231  float dtime = DTIME (stopAddstar, startAddstar);
    224   fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for %5d stars (%5d matches), "OFF_T_FMT" average, "OFF_T_FMT" measure, "OFF_T_FMT" lensing\n", dtime, Nstars, Nmatch,  Naverage,  Nmeasure, Nlensing);
    225 
     232  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec for "OFF_T_FMT" stars (%5d matches), "OFF_T_FMT" average, "OFF_T_FMT" measure, "OFF_T_FMT" lensing\n", dtime, newcat->Naverage, Nmatch,  Naverage,  Nmeasure, Nlensing);
     233
     234  if (options.mode != ADDSTAR_MODE_REFCAT) {
     235    dvo_catalog_free (newcat);
     236    free (newcat);
     237  }
     238
     239  // XXX test
     240  FreeConfig ();
     241  FreePhotcodeTable ();
     242  SkyTableFree (sky);
     243  ohana_memcheck (1);
     244  ohana_memdump (1);
    226245  exit (0);
    227246}
  • trunk/Ohana/src/addstar/src/find_matches.c

    r38467 r38553  
    11# include "addstar.h"
    22
    3 int find_matches (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
    4 
    5   off_t i, j, n, N, J, Nstars;
     3int find_matches (SkyRegion *region, Catalog *srccat, Catalog *tgtcat, AddstarClientOptions options) {
     4
     5  off_t i, j, n, N, J, Nstars, mSrc;
    66  double RADIUS, RADIUS2;
    77  double *X1, *Y1, *X2, *Y2;
    88  double dX, dY, dR;
    9   off_t *N1, *N2, *next_meas;
     9  off_t *N1, *N2;
    1010  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch;
    1111  int Nsecfilt, Nsec, status;
     
    1313  Coords tcoords;
    1414
    15   if (NSTAR_GROUP <= 0) {
    16     fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
    17     exit (1);
    18   }
    19 
    2015  /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
    2116     images this function requires incoming stars to have the same photcode.equiv value.  if
     
    2722
    2823  /** allocate local arrays (stars) **/
    29   ALLOCATE (X1, double, NstarsIn);
    30   ALLOCATE (Y1, double, NstarsIn);
    31   ALLOCATE (N1, off_t,  NstarsIn);
    32 
    33   /** allocate local arrays (catalog) **/
    34   NAVE = Nave = catalog[0].Naverage;
     24  ALLOCATE (X1, double, srccat->Naverage);
     25  ALLOCATE (Y1, double, srccat->Naverage);
     26  ALLOCATE (N1, off_t,  srccat->Naverage);
     27
     28  myAbort ("figure out if found_t needs to be tracking Naverage or Nmeasure");
     29  if (!srccat->found_t) {
     30    ALLOCATE (srccat->found_t, off_t, srccat->Naverage);
     31    for (i = 0; i < srccat->Naverage; i++) {
     32      srccat->found_t[i] = -1;
     33    }
     34  }
     35
     36  /** allocate local arrays (tgtcat) **/
     37  NAVE = Nave = tgtcat[0].Naverage;
    3538  ALLOCATE (X2, double, NAVE);
    3639  ALLOCATE (Y2, double, NAVE);
    3740  ALLOCATE (N2, off_t,  NAVE);
    38   ALLOCATE (catalog[0].found_t, off_t, NAVE);
     41
     42  if (!tgtcat->found_t) {
     43    ALLOCATE (tgtcat[0].found_t, off_t, NAVE);
     44    for (i = 0; i < NAVE; i++) {
     45      tgtcat->found_t[i] = -1;
     46    }
     47  }
    3948  /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
    4049
    4150  /* internal counters */
    4251  Nmatch = 0;
    43   NMEAS = Nmeas = catalog[0].Nmeasure;
     52  NMEAS = Nmeas = tgtcat[0].Nmeasure;
    4453 
    45   // current max obj ID for this catalog
    46   objID = catalog[0].objID;
    47   catID = catalog[0].catID;
     54  off_t *next_meas = NULL;
     55
     56  // current max obj ID for this tgtcat
     57  objID = tgtcat[0].objID;
     58  catID = tgtcat[0].catID;
    4859
    4960  /* project onto rectilinear grid with 1 arcsec pixels. the choice of ZEA projection has the
     
    5162   * possible X,Y points map back to R,D and the local plate scale changes substantially far from
    5263   * the projection pole.  a better mapping might be ARC, not yet implemented (see
    53    * coordops.update.c).  We use the center of the region (catalog) for crval1,2.
     64   * coordops.update.c).  We use the center of the region (tgtcat) for crval1,2.
    5465   */
    5566  InitCoords (&tcoords, "DEC--ARC");
     
    6475  /* build spatial index (RA sort) referencing input array sequence */
    6576  Nstars = 0;
    66   for (i = 0; i < NstarsIn; i++) {
    67     status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].average.R, stars[i].average.D, &tcoords);
     77  for (i = 0; i < srccat->Naverage; i++) {
     78    status = RD_to_XY (&X1[Nstars], &Y1[Nstars], srccat->average[i].R, srccat->average[i].D, &tcoords);
    6879    if (!status) continue;
    6980    N1[Nstars] = i;
     
    7182  }
    7283  if (Nstars < 1) {
    73     if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", catalog[0].filename);
     84    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", tgtcat[0].filename);
    7485    free (X1);
    7586    free (Y1);
     
    8495  /* build spatial index (RA sort) */
    8596  for (i = 0; i < Nave; i++) {
    86     RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
     97    RD_to_XY (&X2[i], &Y2[i], tgtcat[0].average[i].R, tgtcat[0].average[i].D, &tcoords);
    8798    N2[i] = i;
    88     catalog[0].found_t[N2[i]] = -1;
     99    tgtcat[0].found_t[N2[i]] = -1;
    89100  }
    90101  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
    91102
    92103  /* set up pointers for linked list of measure */
    93   if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeasure_disk)) {
    94     next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     104  if (tgtcat[0].sorted && (tgtcat[0].Nmeasure == tgtcat[0].Nmeasure_disk)) {
     105    next_meas = init_measure_links (tgtcat[0].average, Nave, tgtcat[0].measure, Nmeas);
    95106  } else {
    96     next_meas = build_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
     107    next_meas = build_measure_links (tgtcat[0].average, Nave, tgtcat[0].measure, Nmeas);
    97108  }   
    98109
     
    102113
    103114  /** find matched stars **/
    104   // XXX could use NSTAR_GROUP to do this match more quicky if NSTAR_GROUP > 1
    105115  for (i = j = 0; (i < Nstars) && (j < Nave); ) {
    106116    if (!finite(X1[i]) || !finite(Y1[i])) {
     
    138148
    139149      /* make sure there is space for next entry */
    140       if (Nmeas >= NMEAS) {
    141         NMEAS = Nmeas + 1000;
     150      if (Nmeas >= NMEAS - srccat->average[N].Nmeasure) {
     151        NMEAS = Nmeas + 1000 + srccat->average[N].Nmeasure;
    142152        REALLOCATE (next_meas, off_t, NMEAS);
    143 
    144         REALLOCATE (catalog[0].measure, Measure, NMEAS);
    145       }
    146 
    147       /* add to end of measurement list */
    148       add_meas_link (&catalog[0].average[n], next_meas, Nmeas, NMEAS);
     153        REALLOCATE (tgtcat[0].measure, Measure, NMEAS);
     154      }
    149155
    150156      /** add measurements for this star **/
    151 
    152       // set the new measurements
    153       catalog[0].measure[Nmeas]          = stars[N].measure;
    154 
    155       // the following measure elements cannot be set until here:
    156       catalog[0].measure[Nmeas].dbFlags  = 0;
    157       catalog[0].measure[Nmeas].averef   = n; // this must be an absolute sequence number, if partial average is loaded
    158       catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
    159       catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    160 
    161       float dRoff = dvoOffsetR(&catalog[0].measure[Nmeas], &catalog[0].average[n]);
    162 
    163       // rationalize R:
    164       if (dRoff > +180.0*3600.0) {
    165         // average on high end of boundary, move star up
    166         catalog[0].measure[Nmeas].R += 360.0;
    167         dRoff -= 360.0*3600.0;
    168       }
    169       if (dRoff < -180.0*3600.0) {
    170         // average on low end of boundary, move star down
    171         catalog[0].measure[Nmeas].R -= 360.0;
    172         dRoff += 360.0*3600.0;
    173       }
    174       if (fabs(dRoff) > 10*RADIUS) {
    175         // take declination into account and check again.
    176         double cosD = cos(RAD_DEG*catalog[0].average[n].D);
    177         if (fabs(dRoff*cosD) > 10*RADIUS) {
    178           fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    179                    catalog[0].average[n].R, catalog[0].average[n].D,
    180                    stars[N].average.R, stars[N].average.D,
    181                    X1[i], X2[J],
    182                    Y1[i], Y2[J]);
    183         }
    184       }
    185 
    186       /* adds the measurement to the calibration if appropriate color terms are found */
    187       /* we call this before (optionally) setting the average magnitude to avoid auto-correlations */
    188       if (options.calibrate) {
    189         AddToCalibration (&catalog[0].average[n], &catalog[0].secfilt[n*Nsecfilt], catalog[0].measure, &catalog[0].measure[Nmeas], next_meas, N);
    190       }
    191 
    192       /* set the average magnitude if not already set and if photcode.equiv is not 0 */
    193       /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    194       if (Nsec > -1) {
    195         if (isnan(catalog[0].secfilt[n*Nsecfilt+Nsec].M)) {
    196           catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
    197         }
    198       }
    199 
    200       /*** flag multiple stars */
    201       /* this image star matches more than one catalog star */
    202       if (stars[N].found > -1) {
    203         catalog[0].measure[stars[N].found].dbFlags |= ID_MEAS_BLEND_MEAS;
    204         catalog[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_MEAS;
    205       }
    206       if (stars[N].found == -2) { /* this image star matches a catalog star on a neighboring catalog */
    207         catalog[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_MEAS_X;
    208       }
    209       if (stars[N].found == -1) { /* this image star matches only this catalog star */
    210         stars[N].found = Nmeas;  /* save first match, in case coincidences are found */
    211       }
    212       /* this catalog star matches more than one image star */
    213       if (catalog[0].found_t[n] > -1) {
    214         catalog[0].measure[catalog[0].found_t[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
    215         catalog[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_OBJ;
    216       } else {
    217         catalog[0].found_t[n] = Nmeas;
    218       }
    219       /* Nm is updated, but not written out in -update mode (for existing entries)
    220          Nm is recalculated in build_meas_links if loaded table is not sorted */
    221       catalog[0].average[n].Nmeasure ++;
    222       Nmeas ++;
     157      off_t mOff = srccat->average[N].measureOffset;
     158      for (mSrc = 0; mSrc < srccat->average[N].Nmeasure; mSrc++) {
     159        /* add to end of measurement list */
     160        add_meas_link (&tgtcat[0].average[n], next_meas, Nmeas, NMEAS);
     161       
     162        /** add measurements for this star **/
     163       
     164        // set the new measurements
     165        tgtcat[0].measure[Nmeas]          = srccat->measure[mSrc + mOff];
     166       
     167        // the following measure elements cannot be set until here:
     168        tgtcat[0].measure[Nmeas].dbFlags  = 0;
     169        tgtcat[0].measure[Nmeas].averef   = n; // this must be an absolute sequence number, if partial average is loaded
     170        tgtcat[0].measure[Nmeas].objID    = tgtcat[0].average[n].objID;
     171        tgtcat[0].measure[Nmeas].catID    = tgtcat[0].catID;
     172
     173        float dRoff = dvoOffsetR(&tgtcat[0].measure[Nmeas], &tgtcat[0].average[n]);
     174
     175        // rationalize R:
     176        if (dRoff > +180.0*3600.0) {
     177          // average on high end of boundary, move star up
     178          tgtcat[0].measure[Nmeas].R += 360.0;
     179          dRoff -= 360.0*3600.0;
     180        }
     181        if (dRoff < -180.0*3600.0) {
     182          // average on low end of boundary, move star down
     183          tgtcat[0].measure[Nmeas].R -= 360.0;
     184          dRoff += 360.0*3600.0;
     185        }
     186        if (fabs(dRoff) > 10*RADIUS) {
     187          // take declination into account and check again.
     188          double cosD = cos(RAD_DEG*tgtcat[0].average[n].D);
     189          if (fabs(dRoff*cosD) > 10*RADIUS) {
     190            fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
     191                     tgtcat[0].average[n].R, tgtcat[0].average[n].D,
     192                     srccat->average[N].R, srccat->average[N].D,
     193                     X1[i], X2[J],
     194                     Y1[i], Y2[J]);
     195          }
     196        }
     197
     198        /* adds the measurement to the calibration if appropriate color terms are found */
     199        /* we call this before (optionally) setting the average magnitude to avoid auto-correlations */
     200        if (options.calibrate) {
     201          AddToCalibration (&tgtcat[0].average[n], &tgtcat[0].secfilt[n*Nsecfilt], tgtcat[0].measure, &tgtcat[0].measure[Nmeas], next_meas, N);
     202        }
     203
     204        /* set the average magnitude if not already set and if photcode.equiv is not 0 */
     205        /* in UPDATE mode, this value is not saved; use relphot to recalculate */
     206        if (Nsec > -1) {
     207          if (isnan(tgtcat[0].secfilt[n*Nsecfilt+Nsec].M)) {
     208            tgtcat[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     209          }
     210        }
     211
     212        myAbort ("fix logic on multiple detections");
     213
     214        /*** flag multiple stars */
     215        /* this image star matches more than one tgtcat star */
     216        if (srccat->found_t[N] > -1) {
     217          tgtcat[0].measure[srccat->found_t[N]].dbFlags |= ID_MEAS_BLEND_MEAS;
     218          tgtcat[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_MEAS;
     219        }
     220        if (srccat->found_t[N] == -2) { /* this image star matches a tgtcat star on a neighboring tgtcat */
     221          tgtcat[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_MEAS_X;
     222        }
     223        if (srccat->found_t[N] == -1) { /* this image star matches only this tgtcat star */
     224          srccat->found_t[N] = Nmeas;  /* save first match, in case coincidences are found */
     225        }
     226        /* this tgtcat star matches more than one image star */
     227        if (tgtcat[0].found_t[n] > -1) {
     228          tgtcat[0].measure[tgtcat[0].found_t[n]].dbFlags |= ID_MEAS_BLEND_OBJ;
     229          tgtcat[0].measure[Nmeas].dbFlags |= ID_MEAS_BLEND_OBJ;
     230        } else {
     231          tgtcat[0].found_t[n] = Nmeas;
     232        }
     233        /* Nm is updated, but not written out in -update mode (for existing entries)
     234           Nm is recalculated in build_meas_links if loaded table is not sorted */
     235        tgtcat[0].average[n].Nmeasure ++;
     236        Nmeas ++;
     237      }
    223238
    224239      if (!options.update) {
    225240        /* in UPDATE mode, newly calculated coordinates are not saved */
    226         update_coords (&catalog[0].average[n], &catalog[0].measure[0], next_meas);
     241        update_coords (&tgtcat[0].average[n], &tgtcat[0].measure[0], next_meas);
    227242      }
    228243    }
     
    230245  }
    231246
    232 /* incorporate unmatched image stars, if this star is in field of this catalog */
     247/* incorporate unmatched image stars, if this star is in field of this tgtcat */
    233248/* these new entries are all written out in UPDATE mode */
    234   for (i = 0; (i < Nstars) && !options.only_match; i += NSTAR_GROUP) {
     249  for (i = 0; (i < Nstars) && !options.only_match; i ++) {
    235250    /* make sure there is space for next entry */
    236     if (Nmeas >= NMEAS - NSTAR_GROUP) {
    237       NMEAS = Nmeas + 1000;
     251    if (Nmeas >= NMEAS - srccat->average[i].Nmeasure) {
     252      NMEAS = Nmeas + 1000 + srccat->average[i].Nmeasure;
    238253      REALLOCATE (next_meas, off_t, NMEAS);
    239       REALLOCATE (catalog[0].measure, Measure, NMEAS);
     254      REALLOCATE (tgtcat[0].measure, Measure, NMEAS);
    240255    }
    241256    if (Nave >= NAVE) {
    242257      NAVE = Nave + 1000;
    243       REALLOCATE (catalog[0].average, Average, NAVE);
    244       REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);
    245     }
    246 
    247     if (stars[i].found >= 0) continue;
    248     if (!IN_REGION (stars[i].average.R, stars[i].average.D)) continue;
    249 
    250     dvo_average_init (&catalog[0].average[Nave]);
    251     catalog[0].average[Nave].R             = stars[i].average.R;
    252     catalog[0].average[Nave].D             = stars[i].average.D;
    253 
    254     catalog[0].average[Nave].Nmeasure      = NSTAR_GROUP;
    255     catalog[0].average[Nave].measureOffset = Nmeas;
    256     catalog[0].average[Nave].objID         = objID;
    257     catalog[0].average[Nave].catID         = catID;
     258      REALLOCATE (tgtcat[0].average, Average, NAVE);
     259      if (tgtcat[0].secfilt) {
     260        // we only update the secfilt table if it has been allocated for output
     261        REALLOCATE (tgtcat[0].secfilt, SecFilt, NAVE*tgtcat[0].Nsecfilt);
     262      }
     263    }
     264
     265    if (srccat->found_t[i] >= 0) continue;
     266    if (!IN_REGION (srccat->average[i].R, srccat->average[i].D)) continue;
     267
     268    dvo_average_init (&tgtcat[0].average[Nave]);
     269    tgtcat[0].average[Nave].R              = srccat->average[i].R;
     270    tgtcat[0].average[Nave].D              = srccat->average[i].D;
     271
     272    tgtcat[0].average[Nave].Nmeasure       = srccat->average[i].Nmeasure;
     273    tgtcat[0].average[Nave].measureOffset  = Nmeas;
     274    tgtcat[0].average[Nave].objID          = objID;
     275    tgtcat[0].average[Nave].catID          = catID;
    258276
    259277    if (PSPS_ID) {
    260       catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R, catalog[0].average[Nave].D);
     278      tgtcat[0].average[Nave].extID = CreatePSPSObjectID(tgtcat[0].average[Nave].R, tgtcat[0].average[Nave].D);
    261279    }
    262280
    263281    objID ++;
    264282
    265     for (j = 0; j < Nsecfilt; j++) {
    266       dvo_secfilt_init (&catalog[0].secfilt[Nave*Nsecfilt+j], SECFILT_RESET_ALL);
    267     }
    268 
    269     for (j = 0; j < NSTAR_GROUP; j++) {
     283    for (j = 0; tgtcat[0].secfilt && (j < Nsecfilt); j++) {
     284      dvo_secfilt_init (&tgtcat[0].secfilt[Nave*Nsecfilt+j], SECFILT_RESET_ALL);
     285    }
     286
     287    off_t mOff = srccat->average[i].measureOffset;
     288    for (mSrc = 0; mSrc < srccat->average[i].Nmeasure; mSrc++) {
    270289      // supply the measurments from this detection
    271       catalog[0].measure[Nmeas]           = stars[i + j].measure;
     290      dvo_measure_init (&tgtcat[0].measure[Nmeas]);
     291      tgtcat[0].measure[Nmeas] = srccat->measure[mSrc + mOff];
    272292
    273293      // the following measure elements cannot be set until here:
    274       catalog[0].measure[Nmeas].dbFlags   = 0;
    275       catalog[0].measure[Nmeas].averef    = Nave; // XXX EAM : must be absolute Nave if partial read
    276       catalog[0].measure[Nmeas].objID     = catalog[0].average[Nave].objID;
    277       catalog[0].measure[Nmeas].catID     = catalog[0].catID;
     294      tgtcat[0].measure[Nmeas].dbFlags   = 0;
     295      tgtcat[0].measure[Nmeas].averef    = Nave; // XXX EAM : must be absolute Nave if partial read
     296      tgtcat[0].measure[Nmeas].objID     = tgtcat[0].average[Nave].objID;
     297      tgtcat[0].measure[Nmeas].catID     = tgtcat[0].catID;
    278298
    279299      /* set the average magnitude if not already set and the photcode.equiv is not 0 */
    280300      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    281301      if (Nsec > -1) {
    282         catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
     302        tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
    283303      }
    284304
    285305      /* next[Nmeas] should always be -1 in this context (it is always the only
    286306         measurement for the star) */
    287       stars[i].found = Nmeas;
    288       next_meas[Nmeas] = -1;  // initial value here update below
     307      srccat->found_t[i] = Nmeas;
    289308      Nmeas ++;
    290     }
    291     for (j = 0; j < NSTAR_GROUP - 1; j++) {
    292       next_meas[Nmeas - NSTAR_GROUP + j] = Nmeas - NSTAR_GROUP + j + 1;
     309
     310      // update the next_meas pointer for this entry (last one for this star is -1)
     311      next_meas[Nmeas-1] = (mSrc < srccat->average[i].Nmeasure - 1) ? Nmeas : -1;
    293312    }
    294313    Nave ++;
    295314  }
    296315     
    297   REALLOCATE (catalog[0].average, Average, Nave);
    298   REALLOCATE (catalog[0].measure, Measure, Nmeas);
     316  REALLOCATE (tgtcat[0].average, Average, Nave);
     317  REALLOCATE (tgtcat[0].measure, Measure, Nmeas);
    299318 
    300319  if (options.nosort) {
    301     catalog[0].sorted = FALSE;
     320    tgtcat[0].sorted = FALSE;
    302321  } else {
    303     catalog[0].sorted = TRUE;
    304     catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas);
    305   }
    306 
    307 /* note stars which have been found in this catalog */
    308   for (i = 0; i < NstarsIn; i++) {
    309     if (stars[i].found > -1) {
    310       stars[i].found = -2;
    311     }
    312   }
    313 
    314 /* check if the catalog has changed?  if no change, no need to write */
    315   catalog[0].objID    = objID; // new max value, save on catalog close
    316   catalog[0].Naverage = Nave;
    317   catalog[0].Nmeasure = Nmeas;
    318   catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
     322    tgtcat[0].sorted = TRUE;
     323    tgtcat[0].measure = sort_measure (tgtcat[0].average, Nave, tgtcat[0].measure, Nmeas, next_meas);
     324  }
     325
     326/* note stars which have been found in this tgtcat */
     327  for (i = 0; i < srccat->Nmeasure; i++) {
     328    if (srccat->found_t[i] > -1) {
     329      srccat->found_t[i] = -2;
     330    }
     331  }
     332
     333/* check if the tgtcat has changed?  if no change, no need to write */
     334  tgtcat[0].objID    = objID; // new max value, save on tgtcat close
     335  tgtcat[0].Naverage = Nave;
     336  tgtcat[0].Nmeasure = Nmeas;
     337  tgtcat[0].Nsecfilt_mem = Nave*Nsecfilt;
    319338  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nmatch);
    320339
     
    333352   notes:
    334353   
    335    for finding if a catalog star is in an image or an image star is in the catalog:
     354   for finding if a tgtcat star is in an image or an image star is in the tgtcat:
    336355   
    337    catalogs have boundaries defined by RA and DEC, but they may curve in projection
     356   tgtcats have boundaries defined by RA and DEC, but they may curve in projection
    338357   images have boundaries which are lines in pixels coords, but curve in RA and DEC
    339358   
    340    catalog[0].found[Ncat] but stars[Nstar].found
     359   tgtcat[0].found[Ncat] but stars[Nstar].found
    341360   
    342361*/
  • trunk/Ohana/src/addstar/src/find_matches_closest.c

    r38467 r38553  
    11# include "addstar.h"
    22
    3 int find_matches_closest (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
    4  
    5   off_t i, j, n, N, J, Jmin, status, Nstars;
     3int find_matches_closest (SkyRegion *region, Catalog *srccat, Catalog *tgtcat, AddstarClientOptions options) {
     4
     5  off_t i, j, n, N, J, Jmin, status, Nstars, mSrc;
    66  double RADIUS, RADIUS2, Rmin;
    77  double *X1, *Y1, *X2, *Y2;
    88  double dX, dY, dR;
    9   off_t *N1, *N2, *next_meas, *next_lens;
     9  off_t *N1, *N2;
    1010  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS;
    1111  int Nsecfilt, Nsec;
     
    1313  Coords tcoords;
    1414
    15   if (NSTAR_GROUP <= 0) {
    16       fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
    17       exit (1);
    18   }
    19 
    2015  /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
    2116     images this function requires incoming stars to have the same photcode.equiv value.  if
     
    2621  Nsec     = GetPhotcodeNsec (options.photcode);
    2722
    28   /** allocate local arrays (stars) **/
    29   ALLOCATE (X1, double, NstarsIn);
    30   ALLOCATE (Y1, double, NstarsIn);
    31   ALLOCATE (N1, off_t,  NstarsIn);
    32 
    33   /** allocate local arrays (catalog) **/
    34   NAVE = Nave = catalog[0].Naverage;
     23  /** allocate local arrays (srccat) **/
     24  ALLOCATE (X1, double, srccat->Naverage);
     25  ALLOCATE (Y1, double, srccat->Naverage);
     26  ALLOCATE (N1, off_t,  srccat->Naverage);
     27
     28  if (!srccat->found_t) {
     29    ALLOCATE (srccat->found_t, off_t, srccat->Naverage);
     30    for (i = 0; i < srccat->Naverage; i++) {
     31      srccat->found_t[i] = -1;
     32    }
     33  }
     34
     35  /** allocate local arrays (tgtcat) **/
     36  NAVE = Nave = tgtcat[0].Naverage;
    3537  ALLOCATE (X2, double, NAVE);
    3638  ALLOCATE (Y2, double, NAVE);
    3739  ALLOCATE (N2, off_t,  NAVE);
    38   ALLOCATE (catalog[0].found_t, off_t, NAVE);
     40
     41  if (!tgtcat->found_t) {
     42    ALLOCATE (tgtcat[0].found_t, off_t, NAVE);
     43    for (i = 0; i < NAVE; i++) {
     44      tgtcat->found_t[i] = -1;
     45    }
     46  }
    3947  /* for secfilt j and star i, secfilt[i*Nsecfilt+j] */
    4048
    4149  /* internal counters */
    4250  Nmatch = 0;
    43   NMEAS = Nmeas = catalog[0].Nmeasure;
    44   NLENS = Nlens = catalog[0].Nlensing;
    45 
    46   // current max obj ID for this catalog
    47   objID = catalog[0].objID;
    48   catID = catalog[0].catID;
     51  NMEAS = Nmeas = tgtcat[0].Nmeasure;
     52  NLENS = Nlens = tgtcat[0].Nlensing;
     53
     54  off_t *next_meas = NULL;
     55  off_t *next_lens = NULL;
     56
     57  // current max obj ID for this tgtcat
     58  objID = tgtcat[0].objID;
     59  catID = tgtcat[0].catID;
    4960
    5061  /* project onto rectilinear grid with 1 arcsec pixels. the choice of ARC projection has
    5162   * the advantage that every point in R,D has a mapping to a unique X,Y.  However, note
    5263   * that not all possible X,Y points map back to R,D and the local plate scale changes
    53    * far from the projection pole. We use the center of the region (catalog) for crval1,2.
     64   * far from the projection pole. We use the center of the region (tgtcat) for crval1,2.
    5465   */
    5566  InitCoords (&tcoords, "DEC--ARC");
     
    6475  /* build spatial index (RA sort) referencing input array sequence */
    6576  Nstars = 0;
    66   for (i = 0; i < NstarsIn; i++) {
    67     status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].average.R, stars[i].average.D, &tcoords);
     77  for (i = 0; i < srccat->Naverage; i++) {
     78    status = RD_to_XY (&X1[Nstars], &Y1[Nstars], srccat->average[i].R, srccat->average[i].D, &tcoords);
    6879    if (!status) continue;
    6980    N1[Nstars] = i;
     
    7182  }
    7283  if (Nstars < 1) {
    73     if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", catalog[0].filename);
     84    if (VERBOSE) fprintf (stderr, "skipping %s, no overlapping stars\n", tgtcat[0].filename);
    7485    free (X1);
    7586    free (Y1);
     
    7990    free (N2);
    8091    return (0);
     92    // XXX check on this
    8193  }
    8294  if (Nstars > 1) sort_coords_index (X1, Y1, N1, Nstars);
     
    8496  /* build spatial index (RA sort) */
    8597  for (i = 0; i < Nave; i++) {
    86     RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
     98    RD_to_XY (&X2[i], &Y2[i], tgtcat[0].average[i].R, tgtcat[0].average[i].D, &tcoords);
    8799    N2[i] = i;
    88     catalog[0].found_t[N2[i]] = -1;
     100    tgtcat[0].found_t[N2[i]] = -1;
    89101  }
    90102  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
    91103
    92104  /* set up pointers for linked list of measure */
    93   if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeasure_disk)) {
    94     // this version is only valid if we have done a full catalog load, and if the catalog
     105  if (tgtcat[0].sorted && (tgtcat[0].Nmeasure == tgtcat[0].Nmeasure_disk)) {
     106    // this version is only valid if we have done a full tgtcat load, and if the tgtcat
    95107    // is sorted while processed
    96     next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
    97     next_lens = init_lensing_links (catalog[0].average, Nave, catalog[0].lensing, Nlens);
     108    next_meas = init_measure_links (tgtcat[0].average, Nave, tgtcat[0].measure, Nmeas);
     109    next_lens = init_lensing_links (tgtcat[0].average, Nave, tgtcat[0].lensing, Nlens);
    98110  } else {
    99     next_meas = build_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
    100     next_lens = build_lensing_links (catalog[0].average, Nave, catalog[0].lensing, Nlens);
     111    next_meas = build_measure_links (tgtcat[0].average, Nave, tgtcat[0].measure, Nmeas);
     112    next_lens = build_lensing_links (tgtcat[0].average, Nave, tgtcat[0].lensing, Nlens);
    101113  }   
    102114
     
    105117  RADIUS2 = RADIUS*RADIUS;
    106118
    107   /** find matched stars **/
    108   // XXX could use NSTAR_GROUP to do this match more quicky if NSTAR_GROUP > 1
     119  /****************** find matched stars ********************/
     120
    109121  for (i = j = 0; (i < Nstars) && (j < Nave); ) {
    110122    if (!finite(X1[i]) || !finite(Y1[i])) {
     
    129141    }
    130142
    131     if (stars[N1[i]].found != -1) {
    132         /* this star has already been assigned to an object in this or another catalog */
     143    // XXX check that this is allocated
     144    if (srccat->found_t[N1[i]] != -1) {
     145        /* this star has already been assigned to an object in this or another tgtcat */
    133146        i++;
    134147        continue;
     
    169182
    170183    /* make sure there is space for next entry */
    171     if (Nmeas >= NMEAS) {
    172       NMEAS = Nmeas + 1000;
     184    if (Nmeas >= NMEAS - srccat->average[N].Nmeasure) {
     185      NMEAS = Nmeas + 1000 + srccat->average[N].Nmeasure;
    173186      REALLOCATE (next_meas, off_t, NMEAS);
    174       REALLOCATE (catalog[0].measure, Measure, NMEAS);
    175     }
    176     if (Nlens >= NLENS) {
    177       NLENS = Nlens + 1000;
     187      REALLOCATE (tgtcat[0].measure, Measure, NMEAS);
     188    }
     189    if (Nlens >= NLENS - srccat->average[N].Nlensing) {
     190      NLENS = Nlens + 1000 + srccat->average[N].Nlensing;
    178191      REALLOCATE (next_lens, off_t, NLENS);
    179       REALLOCATE (catalog[0].lensing, Lensing, NLENS);
    180     }
    181 
    182     /* add to end of measurement list */
    183     add_meas_link (&catalog[0].average[n], next_meas, Nmeas, NMEAS);
    184        
     192      REALLOCATE (tgtcat[0].lensing, Lensing, NLENS);
     193    }
     194
    185195    /** add measurements for this star **/
    186 
    187     // set the new measurements
    188     catalog[0].measure[Nmeas]          = stars[N].measure;
    189 
    190     // measure now carries R,D (not dR,dD)
    191     catalog[0].measure[Nmeas].dbFlags  = 0;
    192     catalog[0].measure[Nmeas].averef   = n;
    193     catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
    194     catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    195 
    196     float dRoff = dvoOffsetR(&catalog[0].measure[Nmeas], &catalog[0].average[n]);
    197 
    198     // rationalize dR
    199     if (dRoff > +180.0*3600.0) {
    200       // average on high end of boundary, move star up
    201       catalog[0].measure[Nmeas].R += 360.0;
    202       dRoff -= 360.0*3600.0;
    203     }
    204     if (dRoff < -180.0*3600.0) {
    205       // average on low end of boundary, move star down
    206       catalog[0].measure[Nmeas].R -= 360.0;
    207       dRoff += 360.0*3600.0;
    208     }
    209     if (fabs(dRoff) > 10*RADIUS) {
     196    off_t mOff = srccat->average[N].measureOffset;
     197    for (mSrc = 0; mSrc < srccat->average[N].Nmeasure; mSrc++) {
     198      /* add to end of measurement list */
     199      add_meas_link (&tgtcat[0].average[n], next_meas, Nmeas, NMEAS);
     200
     201      // set the new measurements
     202      tgtcat[0].measure[Nmeas]          = srccat->measure[mSrc + mOff];
     203
     204      // measure now carries R,D (not dR,dD)
     205      tgtcat[0].measure[Nmeas].dbFlags  = 0;
     206      tgtcat[0].measure[Nmeas].averef   = n;
     207      tgtcat[0].measure[Nmeas].objID    = tgtcat[0].average[n].objID;
     208      tgtcat[0].measure[Nmeas].catID    = tgtcat[0].catID;
     209
     210      float dRoff = dvoOffsetR(&tgtcat[0].measure[Nmeas], &tgtcat[0].average[n]);
     211
     212      // rationalize dR
     213      if (dRoff > +180.0*3600.0) {
     214        // average on high end of boundary, move star up
     215        tgtcat[0].measure[Nmeas].R += 360.0;
     216        dRoff -= 360.0*3600.0;
     217      }
     218      if (dRoff < -180.0*3600.0) {
     219        // average on low end of boundary, move star down
     220        tgtcat[0].measure[Nmeas].R -= 360.0;
     221        dRoff += 360.0*3600.0;
     222      }
     223      if (fabs(dRoff) > 10*RADIUS) {
    210224        // take declination into account and check again.
    211         double cosD = cos(RAD_DEG*catalog[0].average[n].D);
     225        double cosD = cos(RAD_DEG*tgtcat[0].average[n].D);
    212226        if (fabs(dRoff*cosD) > 10*RADIUS) {
    213             fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    214                      catalog[0].average[n].R, catalog[0].average[n].D,
    215                      stars[N].average.R, stars[N].average.D,
    216                      X1[i], X2[Jmin],
    217                      Y1[i], Y2[Jmin]);
    218             // XXX abort on this? -- this is a bad failure...
     227          fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
     228                   tgtcat[0].average[n].R, tgtcat[0].average[n].D,
     229                   srccat->average[N].R, srccat->average[N].D,
     230                   X1[i], X2[Jmin],
     231                   Y1[i], Y2[Jmin]);
     232          // XXX abort on this? -- this is a bad failure...
    219233        }
    220     }
    221 
    222     // add the lensing values if they exist
    223     if (stars[N].lensing) {
    224       add_lens_link (&catalog[0].average[n], next_lens, Nlens, NLENS); // ?
    225       catalog[0].lensing[Nlens] = stars[N].lensing[0];
    226      
    227       catalog[0].lensing[Nlens].averef = n;
    228       catalog[0].lensing[Nlens].objID = catalog[0].average[n].objID;
    229       catalog[0].lensing[Nlens].catID = catalog[0].catID;
    230       catalog[0].average[n].Nlensing ++;
    231       Nlens ++;
    232     }
    233 
    234     /* adds the measurement to the calibration if appropriate color terms are found */
    235     /* we call this before (optionally) setting the average magnitude to avoid auto-correlations */
    236     if (options.calibrate) {
    237       AddToCalibration (&catalog[0].average[n], &catalog[0].secfilt[n*Nsecfilt], catalog[0].measure, &catalog[0].measure[Nmeas], next_meas, N);
    238     }
    239 
    240     /* set the average magnitude if not already set and the photcode.equiv is not 0 */
    241     /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    242     if (Nsec > -1) {
    243       if (isnan(catalog[0].secfilt[n*Nsecfilt+Nsec].M)) {
    244         catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
    245       }
    246     }
    247 
    248     /* if we choose to flag close encounters, see find_matches.c */
    249     /* if we choose to calculate RA,DEC averages, see update_coords.c */
    250 
    251     /* Nm is updated, but not written out in -update mode (for existing entries)
    252        Nm is recalculated in build_meas_links if loaded table is not sorted */
    253     stars[N].found = Nmeas;
    254     catalog[0].found_t[n] = Nmeas;
    255     catalog[0].average[n].Nmeasure ++;
    256     Nmeas ++;
    257     i++;
    258   }
    259 
    260   /** incorporate unmatched image stars, if this star is in field of this catalog **/
    261   /* these new entries are all written out in UPDATE mode */
    262   for (i = 0; (i < Nstars) && !options.only_match; i += NSTAR_GROUP) {
    263     /* make sure there is space for next entry */
    264     if (Nmeas >= NMEAS - NSTAR_GROUP) {
    265       NMEAS = Nmeas + 1000;
    266       REALLOCATE (next_meas, off_t, NMEAS);
    267       REALLOCATE (catalog[0].measure, Measure, NMEAS);
    268     }
    269     if (Nlens >= NLENS - NSTAR_GROUP) {
    270       NLENS = Nlens + 1000;
    271       REALLOCATE (next_lens, off_t, NLENS);
    272       REALLOCATE (catalog[0].lensing, Lensing, NLENS);
    273     }
    274     if (Nave >= NAVE) {
    275       NAVE = Nave + 1000;
    276       REALLOCATE (catalog[0].average, Average, NAVE);
    277       REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);
    278     }
    279 
    280     if (stars[i].found != -1) continue;
    281     if (!IN_REGION (stars[i].average.R, stars[i].average.D)) continue;
    282 
    283     dvo_average_init (&catalog[0].average[Nave]);
    284     catalog[0].average[Nave].R             = stars[i].average.R;
    285     catalog[0].average[Nave].D             = stars[i].average.D;
    286 
    287     catalog[0].average[Nave].Nmeasure      = NSTAR_GROUP;
    288     catalog[0].average[Nave].measureOffset = Nmeas;
    289     catalog[0].average[Nave].objID         = objID;
    290     catalog[0].average[Nave].catID         = catID;
    291 
    292     if (PSPS_ID) {
    293         catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R, catalog[0].average[Nave].D);
    294     }
    295 
    296     objID ++;
    297 
    298     for (j = 0; j < Nsecfilt; j++) {
    299       dvo_secfilt_init (&catalog[0].secfilt[Nave*Nsecfilt+j], SECFILT_RESET_ALL);
    300     }
    301 
    302     for (j = 0; j < NSTAR_GROUP; j++) {
    303       // supply the measurments from this detection
    304       dvo_measure_init (&catalog[0].measure[Nmeas]);
    305       catalog[0].measure[Nmeas]           = stars[i + j].measure;
    306 
    307       // the following measure elements cannot be set until here:
    308       catalog[0].measure[Nmeas].dbFlags  = 0;
    309       catalog[0].measure[Nmeas].averef   = Nave;
    310       catalog[0].measure[Nmeas].objID    = catalog[0].average[Nave].objID;
    311       catalog[0].measure[Nmeas].catID    = catalog[0].catID;
     234      }
     235
     236      /* adds the measurement to the calibration if appropriate color terms are found */
     237      /* we call this before (optionally) setting the average magnitude to avoid auto-correlations */
     238      if (options.calibrate) {
     239        AddToCalibration (&tgtcat[0].average[n], &tgtcat[0].secfilt[n*Nsecfilt], tgtcat[0].measure, &tgtcat[0].measure[Nmeas], next_meas, N);
     240      }
    312241
    313242      /* set the average magnitude if not already set and the photcode.equiv is not 0 */
    314243      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    315244      if (Nsec > -1) {
    316         catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas], MAG_CLASS_PSF);
    317       }
    318 
    319       /* next[Nmeas] should always be -1 in this context (it is always the only
    320          measurement for the star) */
    321       stars[i+j].found = Nmeas;
    322       next_meas[Nmeas] = -1;  // inital value here update below
     245        if (isnan(tgtcat[0].secfilt[n*Nsecfilt+Nsec].M)) {
     246          tgtcat[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     247        }
     248      }
     249
     250      /* Nm is updated, but not written out in -update mode (for existing entries)
     251         Nm is recalculated in build_meas_links if loaded table is not sorted */
     252      tgtcat[0].average[n].Nmeasure ++;
    323253      Nmeas ++;
    324254    }
    325     for (j = 0; j < NSTAR_GROUP - 1; j++) {
    326       next_meas[Nmeas - NSTAR_GROUP + j] = Nmeas - NSTAR_GROUP + j + 1;
    327     }
     255
     256    // add the lensing values if they exist
     257    if (srccat->lensing) {
     258      /** add measurements for this star **/
     259      off_t mOff = srccat->average[N].lensingOffset;
     260      for (mSrc = 0; mSrc < srccat->average[N].Nlensing; mSrc++) {
     261        /* add to end of lensing list */
     262
     263        add_lens_link (&tgtcat[0].average[n], next_lens, Nlens, NLENS); // ?
     264        tgtcat[0].lensing[Nlens] = srccat->lensing[mSrc + mOff];
     265     
     266        tgtcat[0].lensing[Nlens].averef = n;
     267        tgtcat[0].lensing[Nlens].objID = tgtcat[0].average[n].objID;
     268        tgtcat[0].lensing[Nlens].catID = tgtcat[0].catID;
     269        tgtcat[0].average[n].Nlensing ++;
     270        Nlens ++;
     271      }
     272    }
     273
     274    /* if we choose to flag close encounters, see find_matches.c */
     275    /* if we choose to calculate RA,DEC averages, see update_coords.c */
     276
     277    srccat->found_t[N] = n;
     278    tgtcat[0].found_t[n] = -1;
     279    i++;
     280  }
     281
     282  /*************** add unmatched stars *************************/
     283
     284  /** incorporate unmatched image stars, if this star is in field of this tgtcat **/
     285  /* these new entries are all written out in UPDATE mode */
     286  for (i = 0; (i < Nstars) && !options.only_match; i++) {
     287    /* make sure there is space for next entry */
     288    if (Nmeas >= NMEAS - srccat->average[i].Nmeasure) {
     289      NMEAS = Nmeas + 1000 + srccat->average[i].Nmeasure;
     290      REALLOCATE (next_meas, off_t, NMEAS);
     291      REALLOCATE (tgtcat[0].measure, Measure, NMEAS);
     292    }
     293    if (Nlens >= NLENS - srccat->average[i].Nlensing) {
     294      NLENS = Nlens + 1000 + srccat->average[i].Nlensing;
     295      REALLOCATE (next_lens, off_t, NLENS);
     296      REALLOCATE (tgtcat[0].lensing, Lensing, NLENS);
     297    }
     298    if (Nave >= NAVE) {
     299      NAVE = Nave + 1000;
     300      REALLOCATE (tgtcat[0].average, Average, NAVE);
     301      REALLOCATE (tgtcat[0].found_t, off_t, NAVE);
     302      if (tgtcat[0].secfilt) {
     303        // we only update the secfilt table if it has been allocated for output
     304        REALLOCATE (tgtcat[0].secfilt, SecFilt, NAVE*tgtcat[0].Nsecfilt);
     305      }
     306    }
     307
     308    if (srccat->found_t[i] != -1) continue;
     309    if (!IN_REGION (srccat->average[i].R, srccat->average[i].D)) continue;
     310
     311    dvo_average_init (&tgtcat[0].average[Nave]);
     312    tgtcat[0].average[Nave].R              = srccat->average[i].R;
     313    tgtcat[0].average[Nave].D              = srccat->average[i].D;
     314
     315    tgtcat[0].average[Nave].Nmeasure       = srccat->average[i].Nmeasure;
     316    tgtcat[0].average[Nave].measureOffset  = Nmeas;
     317    tgtcat[0].average[Nave].objID          = objID;
     318    tgtcat[0].average[Nave].catID          = catID;
     319
     320    // this star has not yet been merged into another tgtcat
     321    tgtcat[0].found_t[Nave]                = -1;
     322
     323    if (PSPS_ID) {
     324        tgtcat[0].average[Nave].extID = CreatePSPSObjectID(tgtcat[0].average[Nave].R, tgtcat[0].average[Nave].D);
     325    }
     326
     327    objID ++;
     328
     329    // we only update the secfilt table if it has been allocated for output
     330    for (j = 0; tgtcat[0].secfilt && (j < Nsecfilt); j++) {
     331      dvo_secfilt_init (&tgtcat[0].secfilt[Nave*Nsecfilt+j], SECFILT_RESET_ALL);
     332    }
     333
     334    off_t mOff = srccat->average[i].measureOffset;
     335    for (mSrc = 0; mSrc < srccat->average[i].Nmeasure; mSrc++) {
     336      // supply the measurements from this detection
     337      dvo_measure_init (&tgtcat[0].measure[Nmeas]);
     338      tgtcat[0].measure[Nmeas] = srccat->measure[mSrc + mOff];
     339
     340      // the following measure elements cannot be set until here:
     341      tgtcat[0].measure[Nmeas].dbFlags  = 0;
     342      tgtcat[0].measure[Nmeas].averef   = Nave;
     343      tgtcat[0].measure[Nmeas].objID    = tgtcat[0].average[Nave].objID;
     344      tgtcat[0].measure[Nmeas].catID    = tgtcat[0].catID;
     345
     346      /* set the average magnitude if not already set and the photcode.equiv is not 0 */
     347      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
     348      if (Nsec > -1) {
     349        tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     350      }
     351
     352      Nmeas ++;
     353
     354      // update the next_meas pointer for this entry (last one for this star is -1)
     355      next_meas[Nmeas-1] = (mSrc < srccat->average[i].Nmeasure - 1) ? Nmeas : -1;
     356    }
     357    srccat->found_t[i] = Nave;
    328358
    329359    // if we have lensing data, insert that as well
    330     if (stars[i].lensing) {
    331       catalog[0].average[Nave].Nlensing = NSTAR_GROUP;
    332       catalog[0].average[Nave].lensingOffset = Nlens;
    333       for (j = 0; j < NSTAR_GROUP; j++) {
    334         // add the lensing values if they exist
    335         if (stars[i + j].lensing) {
    336           dvo_lensing_init (&catalog[0].lensing[Nlens]);
    337           catalog[0].lensing[Nlens] = stars[i + j].lensing[0];
     360    if (srccat->lensing) {
     361      tgtcat[0].average[Nave].Nlensing = srccat->average[i].Nlensing;
     362      tgtcat[0].average[Nave].lensingOffset = Nlens;
     363
     364      off_t mOff = srccat->average[i].lensingOffset;
     365      for (mSrc = 0; mSrc < srccat->average[i].Nlensing; mSrc++) {
     366        dvo_lensing_init (&tgtcat[0].lensing[Nlens]);
     367        tgtcat[0].lensing[Nlens] = srccat->lensing[mSrc + mOff];
    338368         
    339           catalog[0].lensing[Nlens].averef = Nave;
    340           catalog[0].lensing[Nlens].objID = catalog[0].average[Nave].objID;
    341           catalog[0].lensing[Nlens].catID = catalog[0].catID;
    342           next_lens[Nlens] = -1;
    343           Nlens ++;
    344         }
    345       }
    346       for (j = 0; j < NSTAR_GROUP - 1; j++) {
    347         next_lens[Nlens - NSTAR_GROUP + j] = Nlens - NSTAR_GROUP + j + 1;
    348       }
    349     }
    350 
     369        tgtcat[0].lensing[Nlens].averef = Nave;
     370        tgtcat[0].lensing[Nlens].objID = tgtcat[0].average[Nave].objID;
     371        tgtcat[0].lensing[Nlens].catID = tgtcat[0].catID;
     372        Nlens ++;
     373        next_lens[Nlens-1] = (mSrc < srccat->average[i].Nlensing - 1) ? Nlens : -1;
     374      }
     375    }
    351376    Nave ++;
    352377  }
    353      
    354   REALLOCATE (catalog[0].average, Average, Nave);
    355   REALLOCATE (catalog[0].measure, Measure, Nmeas);
    356   REALLOCATE (catalog[0].lensing, Lensing, Nlens);
     378
     379  REALLOCATE (tgtcat[0].average, Average, Nave);
     380  REALLOCATE (tgtcat[0].measure, Measure, Nmeas);
     381  REALLOCATE (tgtcat[0].lensing, Lensing, Nlens);
    357382 
    358383  if (options.nosort) {
    359     catalog[0].sorted = FALSE;
     384    tgtcat[0].sorted = FALSE;
    360385  } else {
    361     catalog[0].sorted = TRUE;
    362     catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas);
    363     catalog[0].lensing = sort_lensing (catalog[0].average, Nave, catalog[0].lensing, Nlens, next_lens);
    364   }
    365 
    366   /* note stars which have been found in this catalog */
    367   for (i = 0; i < NstarsIn; i++) {
    368     if (stars[i].found > -1) {
    369       stars[i].found = -2;
    370     }
    371   }
    372 
    373   /* check if the catalog has changed?  if no change, no need to write */
    374   catalog[0].objID    = objID; // new max value, save on catalog close
    375   catalog[0].Naverage = Nave;
    376   catalog[0].Nmeasure = Nmeas;
    377   catalog[0].Nlensing = Nlens;
    378   catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
     386    tgtcat[0].sorted = TRUE;
     387    tgtcat[0].measure = sort_measure (tgtcat[0].average, Nave, tgtcat[0].measure, Nmeas, next_meas);
     388    tgtcat[0].lensing = sort_lensing (tgtcat[0].average, Nave, tgtcat[0].lensing, Nlens, next_lens);
     389  }
     390
     391  /* note stars which have been found in this tgtcat */
     392  for (i = 0; i < srccat->Naverage; i++) {
     393    if (srccat->found_t[i] > -1) {
     394      srccat->found_t[i] = -2;
     395    }
     396  }
     397
     398  /* check if the tgtcat has changed?  if no change, no need to write */
     399  tgtcat[0].objID    = objID; // new max value, save on tgtcat close
     400  tgtcat[0].Naverage = Nave;
     401  tgtcat[0].Nmeasure = Nmeas;
     402  tgtcat[0].Nlensing = Nlens;
     403  tgtcat[0].Nsecfilt_mem = tgtcat[0].secfilt ? Nave*Nsecfilt : 0;
    379404  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Nmatch);
    380405
     
    394419   notes:
    395420   
    396    for finding if a catalog star is in an image or an image star is in the catalog:
     421   for finding if a tgtcat star is in an image or an image star is in the tgtcat:
    397422   
    398    catalogs have boundaries defined by RA and DEC, but they may curve in projection
     423   tgtcats have boundaries defined by RA and DEC, but they may curve in projection
    399424   images have boundaries which are lines in pixels coords, but curve in RA and DEC
    400425   
    401    catalog[0].found[Ncat] but stars[Nstar].found
     426   tgtcat[0].found[Ncat] but stars[Nstar].found
    402427   
    403428*/
  • trunk/Ohana/src/addstar/test

  • trunk/Ohana/src/addstar/test/compress.dvo

    r38441 r38553  
    22
    33input tap.dvo
     4input ptolemy.dvo
     5
     6# generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     7mkptolemy.rc
     8
    49$CATDIR = catdir.test.v0
    510
     
    3843  mkinput
    3944  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
    40   tapEXEC addstar -D CATCOMPRESS $3 -D CATDIR $CATDIR -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
     45  tapEXEC addstar -D CATCOMPRESS $3 -D CATDIR $CATDIR -D CAMERA gpc1 test.cmf -D CATFORMAT $2 -quick-airmass
    4146
    4247  list testfields -copy testfields_$1
  • trunk/Ohana/src/addstar/test/dvomerge.dvo

    r29938 r38553  
    22
    33input tap.dvo
     4input ptolemy.dvo
     5
     6# generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     7mkptolemy.rc
     8
     9macro test.all
     10  $TAP_VERBOSE = 1
     11  test.dvomerge.update.new
     12end
    413
    514# create 2 populated catdirs, each with a couple of cmf files
     
    817  tapPLAN 51
    918
    10   exec rm -rf catdir.test1
    11   exec rm -rf catdir.test2
    12   exec rm -rf catdir.test3
     19  tapEXEC rm -rf catdir.test1
     20  tapEXEC rm -rf catdir.test2
     21  tapEXEC rm -rf catdir.test3
    1322
    1423  $RA = 10.0
     
    1625
    1726  mkinput
    18   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec 10.0 20.0
    19   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    20 
    21   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec 10.0 20.0
    22   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    23 
    24   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec 9.9 20.0
    25   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    26 
    27   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec 9.9 20.0
    28   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    29 
    30   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 05:00:00 -radec 10.0 19.9
    31   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    32 
    33   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 06:00:00 -radec 10.0 19.9
    34   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    35 
    36   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 07:00:00 -radec 9.9 19.9
    37   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    38 
    39   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 08:00:00 -radec 9.9 19.9
    40   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
     27  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec 10.0 20.0
     28  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     29
     30  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec 10.0 20.0
     31  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     32
     33  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec 9.9 20.0
     34  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     35
     36  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec 9.9 20.0
     37  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     38
     39  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 05:00:00 -radec 10.0 19.9
     40  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     41
     42  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 06:00:00 -radec 10.0 19.9
     43  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     44
     45  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 07:00:00 -radec 9.9 19.9
     46  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     47
     48  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 08:00:00 -radec 9.9 19.9
     49  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
    4150
    4251  break
    4352
    44   exec rsync -auc catdir.test2/ catdir.test3/
     53  tapEXEC rsync -auc catdir.test2/ catdir.test3/
    4554
    4655  date -var t1 -seconds -reftime 1276000000
    47   exec dvomerge catdir.test1 into catdir.test3
     56  tapEXEC dvomerge catdir.test1 into catdir.test3
    4857  date -var t2 -seconds -reftime 1276000000
    4958  echo "merge time: {$t2 - $t1}"
     
    114123  end
    115124
    116   # exec rm test.in.txt test.cmf
    117   # exec rm -rf catdir.test1
    118   # exec rm -rf catdir.test2
    119   # exec rm -rf catdir.test3
     125  # tapEXEC rm test.in.txt test.cmf
     126  # tapEXEC rm -rf catdir.test1
     127  # tapEXEC rm -rf catdir.test2
     128  # tapEXEC rm -rf catdir.test3
    120129
    121130  tapDONE
     
    127136  tapPLAN 51
    128137
    129   exec rm -rf catdir.test1
    130   exec rm -rf catdir.test2
    131   exec rm -rf catdir.test3
     138  tapEXEC rm -rf catdir.test1
     139  tapEXEC rm -rf catdir.test2
     140  tapEXEC rm -rf catdir.test3
    132141
    133142  $RA = 10.0
     
    135144
    136145  mkinput
    137   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
    138   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    139 
    140   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
    141   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    142 
    143   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
    144   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    145 
    146   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
    147   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    148 
    149   break
    150 
    151   exec rsync -auc catdir.test2/ catdir.test3/
     146  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
     147  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     148
     149  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
     150  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     151
     152  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
     153  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     154
     155  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
     156  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     157
     158  tapEXEC rsync -auc catdir.test2/ catdir.test3/
    152159
    153160  date -var t1 -seconds -reftime 1276000000
    154   exec dvomerge catdir.test1 into catdir.test3
     161  tapEXEC dvomerge catdir.test1 into catdir.test3
    155162  date -var t2 -seconds -reftime 1276000000
    156163  echo "merge time: {$t2 - $t1}"
     
    221228  end
    222229
    223   # exec rm test.in.txt test.cmf
    224   # exec rm -rf catdir.test1
    225   # exec rm -rf catdir.test2
    226   # exec rm -rf catdir.test3
     230  # tapEXEC rm test.in.txt test.cmf
     231  # tapEXEC rm -rf catdir.test1
     232  # tapEXEC rm -rf catdir.test2
     233  # tapEXEC rm -rf catdir.test3
    227234
    228235  tapDONE
     
    234241  tapPLAN 51
    235242
    236   exec rm -rf catdir.test1
    237   exec rm -rf catdir.test2
     243  tapEXEC rm -rf catdir.test1
     244  tapEXEC rm -rf catdir.test2
    238245
    239246  $RA = 10.0
     
    241248
    242249  mkinput
    243   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
    244   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    245 
    246   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
    247   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
     250  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
     251  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     252
     253  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
     254  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
    248255
    249256  date -var t1 -seconds -reftime 1276000000
    250   exec dvomerge catdir.test1 into catdir.test2
     257  tapEXEC dvomerge catdir.test1 into catdir.test2
    251258  date -var t2 -seconds -reftime 1276000000
    252259  echo "merge time: {$t2 - $t1}"
     
    297304  end
    298305
    299   # exec rm test.in.txt test.cmf
    300   # exec rm -rf catdir.test1
    301   # exec rm -rf catdir.test2
    302   # exec rm -rf catdir.test3
     306  # tapEXEC rm test.in.txt test.cmf
     307  # tapEXEC rm -rf catdir.test1
     308  # tapEXEC rm -rf catdir.test2
     309  # tapEXEC rm -rf catdir.test3
    303310
    304311  tapDONE
     
    310317  tapPLAN 51
    311318
    312   exec rm -rf catdir.test1
    313   exec rm -rf catdir.test2
    314   exec rm -rf catdir.test3
     319  tapEXEC rm -rf catdir.test1
     320  tapEXEC rm -rf catdir.test2
     321  tapEXEC rm -rf catdir.test3
    315322
    316323  $RA = 10.0
     
    318325
    319326  mkinput
    320   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
    321   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    322 
    323   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
    324   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
     327  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
     328  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     329
     330  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
     331  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
    325332
    326333  # generate a few extra unmatched sources
    327334  mkinput.extras
    328   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
    329   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    330 
    331   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
    332   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    333 
    334   exec rsync -auc catdir.test2/ catdir.test3/
    335 
    336   exec dvomerge catdir.test1 into catdir.test3
     335  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
     336  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     337
     338  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
     339  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     340
     341  tapEXEC rsync -auc catdir.test2/ catdir.test3/
     342
     343  tapEXEC dvomerge catdir.test1 into catdir.test3
    337344
    338345  catdir catdir.test3
     
    401408  end
    402409
    403   # exec rm test.in.txt test.cmf
    404   # exec rm -rf catdir.test1
    405   # exec rm -rf catdir.test2
    406   # exec rm -rf catdir.test3
     410  # tapEXEC rm test.in.txt test.cmf
     411  # tapEXEC rm -rf catdir.test1
     412  # tapEXEC rm -rf catdir.test2
     413  # tapEXEC rm -rf catdir.test3
    407414
    408415  tapDONE
     
    414421  tapPLAN 21
    415422
    416   exec rm -rf catdir.test1
    417   exec rm -rf catdir.test2
    418   exec rm -rf catdir.test3
     423  tapEXEC rm -rf catdir.test1
     424  tapEXEC rm -rf catdir.test2
     425  tapEXEC rm -rf catdir.test3
    419426
    420427  $RA = 10.0
     
    422429
    423430  mkinput
    424   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
    425   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    426 
    427   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
    428   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
    429 
    430   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
    431   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    432 
    433   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
    434   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
    435 
    436   exec dvomerge catdir.test1 and catdir.test2 to catdir.test3
     431  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
     432  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     433
     434  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
     435  tapEXEC addstar -D CATDIR catdir.test1 -D CAMERA gpc1 test.cmf -quick-airmass
     436
     437  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
     438  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     439
     440  tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
     441  tapEXEC addstar -D CATDIR catdir.test2 -D CAMERA gpc1 test.cmf -quick-airmass
     442
     443  tapEXEC dvomerge catdir.test1 and catdir.test2 to catdir.test3
    437444
    438445  catdir catdir.test3
     
    501508  end
    502509
    503   # exec rm test.in.txt test.cmf
    504   # exec rm -rf catdir.test1
    505   # exec rm -rf catdir.test2
    506   # exec rm -rf catdir.test3
     510  # tapEXEC rm test.in.txt test.cmf
     511  # tapEXEC rm -rf catdir.test1
     512  # tapEXEC rm -rf catdir.test2
     513  # tapEXEC rm -rf catdir.test3
    507514
    508515  tapDONE
     
    511518# make a simple input file for mkcmf
    512519macro mkinput.alt
    513   exec rm -f test.in.txt
     520  tapEXEC rm -f test.in.txt
    514521
    515522  output test.in.txt
     
    524531# make a simple input file for mkcmf
    525532macro mkinput
    526   exec rm -f test.in.txt
     533  tapEXEC rm -f test.in.txt
    527534
    528535  output test.in.txt
     
    537544# make a simple input file for mkcmf
    538545macro mkinput.extras
    539   exec rm -f test.in.txt
     546  tapEXEC rm -f test.in.txt
    540547
    541548  output test.in.txt
  • trunk/Ohana/src/addstar/test/relastro.dvo

    r27582 r38553  
    22
    33input tap.dvo
     4input ptolemy.dvo
     5
     6# generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     7mkptolemy.rc
    48
    59macro test.all
     
    6064    mkinput $offset:$i
    6165    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC -type $1
    62     exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2
     66    exec addstar -D CATDIR catdir.test -D CAMERA gpc1 test.cmf -D CATFORMAT $2
    6367  end
    6468
  • trunk/Ohana/src/addstar/test/relphot.dvo

    r38441 r38553  
    33
    44input tap.dvo
     5input ptolemy.dvo
     6
     7# generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     8mkptolemy.rc
    59
    610macro test.all
     
    3943    mkinput $offset:$i
    4044    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC -type $1
    41     exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
     45    exec addstar -D CATDIR catdir.test -D CAMERA gpc1 test.cmf -D CATFORMAT $2 -quick-airmass
    4246  end
    4347
  • trunk/Ohana/src/addstar/test/relphot.flatcorr.dvo

    r38471 r38553  
    1717$TAP_VERBOSE = 1
    1818input tap.dvo
     19input ptolemy.dvo
    1920
    2021# set globals
     
    3132# set various global variables
    3233macro init
    33   # generate a fake ptolemy.rc (to make this a contained test)
    34   exec rm -f ptolemy.rc
    35   output ptolemy.rc
    36     echo "\#"
    37     echo PHOTCODE_FILE dvo.photcodes
    38     echo GSCFILE GSCregions.tbl
    39     echo ZERO_PT 25.0
    40     echo ADDSTAR_RADIUS 1.0
    41     echo CATMODE                 SPLIT
    42     echo CATFORMAT               PS1_V5
    43     # echo CATFORMAT               PS1_V2 -- must be at least PS1_V3 for ubercaldist to work
    44     echo SKY_DEPTH               4
    45     echo CAMERA                  gpc1
    46     echo CAMERA_CONFIG           dvo.layout
    47     echo "input dvo.config"
    48   output stdout
    49 
    50   # we need to define a photcode table consistent with the fake construction
    51   $zpt_nominal:g = 24.0
    52   $zpt_nominal:r = 24.5
    53 
    54   # klam is negative, so klam*(airmass - 1) increases the zero point
    55   $klam_nominal:g = -0.15
    56   $klam_nominal:r = -0.10
    57 
    58   # generate a fake dvo.photcode
    59   exec rm -f dvo.photcodes
    60   output dvo.photcodes
    61     echo "\# code  name                type    zero  slope offset c1    c2   slope   zero  equiv  sys scale   scale  sys     poor   bad     poor   bad"
    62     echo "1     g                    sec   0.000  0.000 0.000     1     3 0.0000     0  1051   0.000 0.000 0.000  0.000   0x0000 0x0000  0x0000 0x0000"
    63     echo "2     r                    sec   0.000  0.000 0.000     2     3 0.0000     0  1052   0.000 0.000 0.000  0.000   0x0000 0x0000  0x0000 0x0000"
    64     echo "10000 GPC1.g.XY00          dep  $zpt_nominal:g $klam_nominal:g 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    65     echo "10001 GPC1.g.XY01          dep  $zpt_nominal:g $klam_nominal:g 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    66     echo "10010 GPC1.g.XY10          dep  $zpt_nominal:g $klam_nominal:g 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    67     echo "10011 GPC1.g.XY11          dep  $zpt_nominal:g $klam_nominal:g 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    68     echo "10100 GPC1.r.XY00          dep  $zpt_nominal:r $klam_nominal:r 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    69     echo "10101 GPC1.r.XY01          dep  $zpt_nominal:r $klam_nominal:r 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    70     echo "10110 GPC1.r.XY10          dep  $zpt_nominal:r $klam_nominal:r 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    71     echo "10111 GPC1.r.XY11          dep  $zpt_nominal:r $klam_nominal:r 0.000     -     - 0.0000     0     1   0.015 0.000 1.000  0.000   0x0000 0x0000  0xe0440130 0x1003bc88"
    72     echo "2011  2MASS_J              ref   0.000  0.000 0.000     -     - 0.0000     0     6   0.080 0.000 2.000  0.000   0x0000 0x0000  0x0000 0x0000"
    73     echo "3001  SYNTH.g              ref   0.000  0.000 0.000     -     - 0.0000     0     1     nan 0.000 2.000  0.600   0x0000 0x0000  0x0000 0x0000"
    74     echo "2020  TYCHO_B              ref   0.000  0.000 0.000     -     - 0.0000     0     -   0.000 0.000 0.000  0.000   0x0000 0x0000  0x0000 0x0000"
    75   output stdout     
     34
     35  # generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     36  mkptolemy.rc
    7637
    7738  $RA_CENTER = 10.0
     
    897858    mkinput test.in.txt $offset:$i
    898859    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC -type $1
    899     exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2
     860    exec addstar -D CATDIR catdir.test -D CAMERA gpc1 test.cmf -D CATFORMAT $2
    900861  end
    901862
  • trunk/Ohana/src/addstar/test/relphot.parallel.dvo

    r37807 r38553  
    55
    66input tap.dvo
     7input ptolemy.dvo
     8
     9# generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     10mkptolemy.rc
    711
    812# set globals
  • trunk/Ohana/src/addstar/test/relphot.reject.dvo

    r33653 r38553  
    1515
    1616input tap.dvo
     17input ptolemy.dvo
     18
     19# generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     20mkptolemy.rc
    1721
    1822# set globals
  • trunk/Ohana/src/addstar/test/simple.dvo

    r38441 r38553  
    22
    33input tap.dvo
     4input ptolemy.dvo
     5
     6# generates ptolemy.rc, dvo.photcodes, $zpt_nominal:g,r $klam_nominal:g,r
     7mkptolemy.rc
     8
     9macro test.one
     10  test.fields PS1_V5 PS1_V5
     11end
    412
    513macro test.all
     
    5462
    5563  mkinput
    56   tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
    57   tapEXEC addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
     64  # tapEXEC mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
     65
     66  $options =
     67  $options = $options -type $1
     68  $options = $options -radec $RA $DEC
     69  $options = $options -mjd 54466.041667
     70  $options = $options -date 2008/1/1 -time 01:00:00
     71  $options = $options -photcode GPC1.g.XY00
     72  $options = $options $NO_NOISE
     73
     74  # $options = $options -flags
     75  # $options = $options -bad-psfqf-frac $DEFECT_FRAC
     76  # $options = $options -size $CHIP_DX $CHIP_DY
     77  # $options = $options -crpix {0.5*$CHIP_DX} {0.5*$CHIP_DY}
     78  # $options = $options -airmass $AIRMASS
     79  # $options = $options -exptime $EXPTIME
     80  # $options = $options -coords
     81
     82  tapEXEC mkcmf test.in.txt test.cmf $options
     83  tapEXEC addstar -D CATDIR catdir.test -D CAMERA gpc1 test.cmf -D CATFORMAT $2 -quick-airmass
    5884
    5985  list testfields -copy testfields_$1
  • trunk/Ohana/src/dvomerge/include/dvomerge.h

    r38468 r38553  
    3030int    VERIFY_CATALOG_ONLY;
    3131int    IMAGES_ONLY;
    32 char   CATDIR[256];
    33 char   GSCFILE[256];
    34 char   CATMODE[16];    /* raw, mef, split, mysql */
    35 char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
    36 char   ImageCat[256];
     32char   CATDIR[DVO_MAX_PATH];
     33char   GSCFILE[DVO_MAX_PATH];
     34char   ImageCat[DVO_MAX_PATH];
     35char   CATMODE[256];    /* raw, mef, split, mysql */
     36char   CATFORMAT[256];  /* internal, elixir, loneos, panstarrs */
    3737float  RADIUS;
    3838int    SKY_DEPTH;
    3939int    NTHREADS;
    40 char  *ALTERNATE_PHOTCODE_FILE;
    4140int    REPLACE_BY_PHOTCODE;
    4241int    REPLACE_TYCHO;
    4342int    FORCE_MERGE;
    4443int    MAX_CLIENTS;
     44char  *ALTERNATE_PHOTCODE_FILE;
    4545char  *UPDATE_CATFORMAT;
    4646char  *UPDATE_CATCOMPRESS;
     
    116116void       dvomerge_help          PROTO((int argc, char **argv));
    117117int        dvomerge_args          PROTO((int *argc, char **argv));
     118void       dvomerge_args_free     PROTO((void));
    118119
    119120void       dvomerge_client_usage  PROTO((void));
     
    174175off_t      dvo_map_image_ID       PROTO((IDmapType *IDmap, off_t oldID));
    175176int        dvo_update_image_IDs   PROTO((IDmapType *IDmap, Catalog *catalog));
     177void       dvo_image_map_free     PROTO((IDmapType *IDmap));
     178void       dvo_image_map_init     PROTO((IDmapType *IDmap));
    176179
    177180// dvorepair prototypes
     
    212215int dmhObjectCheck (dmhObject *history, dmhObjectStats *inStats);
    213216dmhObject *dmhObjectRead (char *filename);
     217dmhObject *dmhObjectAlloc (void);
     218void dmhObjectFree (dmhObject *history);
    214219
    215220void dmhObjectStatsFree (dmhObjectStats *stats);
     
    217222
    218223int dmhImageAdd (FITS_DB *db, dmhImage *history, char *dbID);
    219 dmhImage *dmhImageRead (FITS_DB *db) ;
     224dmhImage *dmhImageRead (FITS_DB *db);
    220225int dmhImageCheck (dmhImage *history, char *dbID);
     226void dmhImageFree(dmhImage *history);
    221227
    222228char *dmhImageReadID (FITS_DB *db);
  • trunk/Ohana/src/dvomerge/include/dvoverify.h

    r37360 r38553  
    5353void AddFailures (char *filename);
    5454char **GetFailures (int *N);
     55void FreeFailures (void);
    5556
    5657int LoadImageIDs (char *catdir);
     
    5960int SaveImageIDsSmall(char *filename);
    6061int LoadImageIDsSmall (char *filename);
     62
     63void FreeImageIDs (void);
  • trunk/Ohana/src/dvomerge/src/ConfigInit.c

    r27435 r38553  
    4747  VERBOSE = TRUE;
    4848
     49  FreeConfigFile();
    4950  free (config);
    5051  free (file);
  • trunk/Ohana/src/dvomerge/src/args.c

    r38468 r38553  
    66  int N;
    77
     8  HOSTDIR = NULL;
     9  SINGLE_CPT = NULL;
     10
    811  /* extra error messages */
    912  VERBOSE = FALSE;
     
    5356
    5457  /* use a different photcode file to define mean values */
     58  ALTERNATE_PHOTCODE_FILE = NULL;
    5559  if ((N = get_argument (*argc, argv, "-photcode-file"))) {
    5660    remove_argument (N, argc, argv);
     
    156160}
    157161
     162void dvomerge_args_free (void) {
     163  FREE (HOSTDIR);
     164  FREE (ALTERNATE_PHOTCODE_FILE);
     165  FREE (UPDATE_CATFORMAT);
     166  FREE (UPDATE_CATCOMPRESS);
     167  FREE (SINGLE_CPT);
     168}
     169
    158170/*** check for command line options ***/
    159171int dvomerge_client_args (int *argc, char **argv) {
  • trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r38441 r38553  
    55void SortTgtByTimes (e_time *S, off_t *I, short *C, off_t N);
    66off_t getTgtIndex (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt);
     7
     8void dvo_image_map_init (IDmapType *IDmap) {
     9  // we don't own the IDmap, just the elements
     10  IDmap->old = NULL;
     11  IDmap->new = NULL;
     12  IDmap->notFound = NULL;
     13  IDmap->Nmap = 0;
     14}
     15
     16void dvo_image_map_free (IDmapType *IDmap) {
     17  // we don't own the IDmap, just the elements
     18  FREE (IDmap->old);
     19  FREE (IDmap->new);
     20  FREE (IDmap->notFound);
     21}
    722
    823// we have two tables; 'tgt' contains some exposures from 'src' : find them and match a map
  • trunk/Ohana/src/dvomerge/src/dvomerge.c

    r35765 r38553  
    77  ConfigInit (&argc, argv);
    88  dvomerge_args (&argc, argv);
     9
     10  if ((argc < 4) || (argc > 6)) dvomerge_usage();
    911
    1012  if (argc == 6) {
     
    3840    }
    3941  }
    40   dvomerge_usage();
    41   exit (2); // cannot reach here.
     42  dvomerge_args_free ();
     43  ohana_memcheck (TRUE);
     44  ohana_memdump (TRUE);
     45  exit (0);
    4246}
    4347
  • trunk/Ohana/src/dvomerge/src/dvomergeHistory.c

    r34578 r38553  
    2828  char *ID = strcreate (dbID);
    2929  return ID;
     30}
     31
     32void dmhImageFree(dmhImage *history) {
     33  if (!history) return;
     34 
     35  int i;
     36  for (i = 0; i < history->Nmerge; i++) {
     37    FREE (history->IDs[i]);
     38  }
     39  FREE (history->IDs);
     40  FREE (history);
    3041}
    3142
     
    125136}
    126137
     138dmhObject *dmhObjectAlloc (void) {
     139
     140  dmhObject *history = NULL;
     141  ALLOCATE (history, dmhObject, 1);
     142  history->Nmerge = 0;
     143 
     144  // ALLOCATE full list
     145  ALLOCATE (history->size, off_t,  history->Nmerge);
     146  ALLOCATE (history->time, time_t, history->Nmerge);
     147  ALLOCATE (history->date, char *, history->Nmerge);
     148  return history;
     149}
     150
     151void dmhObjectFree (dmhObject *history) {
     152  if (!history) return;
     153
     154  FREE (history->size);
     155  FREE (history->time);
     156
     157  if (history->date) {
     158    int i;
     159    for (i = 0; i < history->Nmerge; i++) {
     160      FREE (history->date[i]);
     161    }
     162  }
     163  FREE (history->date);
     164  FREE (history);
     165  return;
     166}
     167
    127168// read the array of merged history information from this file's header
    128169dmhObject *dmhObjectRead (char *filename) {
     
    133174  if (stat_result) {
    134175    if (errno == ENOENT) {
    135       dmhObject *history = NULL;
    136       ALLOCATE (history, dmhObject, 1);
    137       history->Nmerge = 0;
    138    
    139       // ALLOCATE full list
    140       ALLOCATE (history->size, off_t,  history->Nmerge);
    141       ALLOCATE (history->time, time_t, history->Nmerge);
    142       ALLOCATE (history->date, char *, history->Nmerge);
     176      dmhObject *history = dmhObjectAlloc();
    143177      return history;
    144178    }
     
    162196  fclose (fout);
    163197
    164   dmhObject *history = NULL;
    165   ALLOCATE (history, dmhObject, 1);
     198  dmhObject *history = dmhObjectAlloc();
    166199
    167200  int status = gfits_scan (&outheader, "NMERGE", "%d", 1, &history->Nmerge);     
     
    171204
    172205  // ALLOCATE full list
    173   ALLOCATE (history->size, off_t,  history->Nmerge);
    174   ALLOCATE (history->time, time_t, history->Nmerge);
    175   ALLOCATE (history->date, char *, history->Nmerge);
     206  REALLOCATE (history->size, off_t,  history->Nmerge);
     207  REALLOCATE (history->time, time_t, history->Nmerge);
     208  REALLOCATE (history->date, char *, history->Nmerge);
    176209
    177210  int i;
     
    199232    history->time[i] = ohana_date_to_sec (date);
    200233  }
     234  gfits_free_header (&outheader);
    201235  return history;
    202236}
     
    239273  history->size[last] = inStats->size;
    240274  history->time[last] = inStats->time;
    241   history->date[last] = inStats->date;
     275  history->date[last] = strcreate (inStats->date);
    242276
    243277  char name[16];
     
    280314  int i;
    281315  for (i = 0; i < N; i++) {
    282     if (outstat[i].history)  { free (outstat[i].history); }
     316    if (outstat[i].history)  { dmhObjectFree (outstat[i].history); }
    283317    if (outstat[i].filename) { free (outstat[i].filename); }
    284318  }
  • trunk/Ohana/src/dvomerge/src/dvomergeImageIDs.c

    r38441 r38553  
    6464    dvo_image_match_dbs(IDmap, &outDB, &inDB);
    6565    dvo_image_unlock (&outDB); // unlock output
     66
     67    gfits_db_free (&inDB);
     68    gfits_db_free (&outDB);
     69    dmhImageFree (history);
     70    FREE (indbID);
    6671    return TRUE;
    6772  }
     
    8085  SetProtect (FALSE);
    8186  dvo_image_unlock (&outDB); // unlock output
     87
     88  gfits_db_free (&inDB);
     89  gfits_db_free (&outDB);
     90
     91  dmhImageFree (history);
     92  FREE (indbID);
    8293
    8394  return TRUE;
     
    136147  dvo_image_match_dbs(IDmap, &outDB, &inDB);
    137148
     149  gfits_db_free (&inDB);
     150  gfits_db_free (&outDB);
     151
    138152  return TRUE;
    139153}
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r38468 r38553  
    88  char filename[256], *input, *output;
    99  IDmapType IDmap;
    10   PhotCodeData *inputPhotcodes;
    11   PhotCodeData *outputPhotcodes;
    1210  int *secfiltMap = NULL;
    1311  int NsecfiltInput, NsecfiltOutput;
    1412
    1513  INITTIME;
     14
     15  dvo_image_map_init (&IDmap);
    1616
    1717  CONTINUE = FALSE;
     
    3434    exit (1);
    3535  }
     36
     37  PhotCodeData *inputPhotcodes  = NULL;
     38  PhotCodeData *outputPhotcodes = NULL;
    3639
    3740  SetPhotcodeTable(NULL);
     
    120123    exit (1);
    121124  }
     125  FREE (skyfile);
     126
     127  SkyTableFree (insky);
     128  SkyTableFree (outsky);
     129  SkyListFree (inlist);
     130
     131  FREE (secfiltMap);
     132  dvo_image_map_free (&IDmap);
     133  if (outputPhotcodes != inputPhotcodes) { FreePhotcodeData (outputPhotcodes); }
     134  FreePhotcodeData (inputPhotcodes);
     135  FreePhotcodeTable ();
    122136
    123137  if (!status) {
     
    127141
    128142  MARKTIME ("SUCCESS: elapsed time %9.4f sec\n", dtime);
    129   exit (0);
     143  return TRUE;
    130144}
  • trunk/Ohana/src/dvomerge/src/dvoverify.c

    r34405 r38553  
    2424
    2525    // check the photcode table
    26     sprintf (filename, "%s/Photcodes.dat", CATDIR);
     26    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/Photcodes.dat", CATDIR) < DVO_MAX_PATH, "overflow");
    2727    if (!VerifyTableFile (filename)) {
    2828      Nbad ++;
     
    3434      Nbad ++;
    3535    }
     36    free (skyfile);
    3637
    3738    // check the image table
    38     sprintf (filename, "%s/Images.dat", CATDIR);
     39    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/Images.dat", CATDIR) < DVO_MAX_PATH, "overflow");
    3940    if (!VerifyTableFile (filename)) {
    4041      Nbad ++;
     
    7172    fprintf (stderr, "NOTE: %d files are not sorted\n", NNotSorted);
    7273  }
     74
     75  FreeImageIDs ();
     76  FreeFailures ();
     77  SkyTableFree (sky);
     78  SkyListFree (skylist);
     79
     80  ohana_memcheck (TRUE);
     81  ohana_memdump (TRUE);
    7382  exit (0);
    7483}
  • trunk/Ohana/src/dvomerge/src/dvoverify_args.c

    r37360 r38553  
    4545    }
    4646
     47    CHECK_IMAGE_ID = FALSE;
     48
    4749    int isGood = dvoverify_single (filename);
     50    free (filename);
     51
     52    ohana_memcheck (TRUE);
     53    ohana_memdump (TRUE);
     54
    4855    if (!isGood) exit (1);
    4956    exit (0);
  • trunk/Ohana/src/dvomerge/src/dvoverify_catalogs.c

    r37360 r38553  
    2727    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
    2828
    29     sprintf (filename, "%s/%s.cpt", mycatdir, skylist[0].regions[i][0].name);
     29    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/%s.cpt", mycatdir, skylist[0].regions[i][0].name) < DVO_MAX_PATH, "overflow");
    3030    if (!VerifyTableFile (filename)) {
    3131      Nbad ++;
     
    3434    }
    3535
    36     sprintf (filename, "%s/%s.cps", mycatdir, skylist[0].regions[i][0].name);
     36    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/%s.cps", mycatdir, skylist[0].regions[i][0].name) < DVO_MAX_PATH, "overflow");
    3737    if (!VerifyTableFile (filename)) {
    3838      Nbad ++;
     
    4040    }
    4141
    42     sprintf (filename, "%s/%s.cpm", mycatdir, skylist[0].regions[i][0].name);
     42    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/%s.cpm", mycatdir, skylist[0].regions[i][0].name) < DVO_MAX_PATH, "overflow");
    4343    if (!VerifyTableFile (filename)) {
    4444      Nbad ++;
     
    4747    }
    4848
    49     sprintf (filename, "%s/%s.cpx", mycatdir, skylist[0].regions[i][0].name);
     49    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/%s.cpx", mycatdir, skylist[0].regions[i][0].name) < DVO_MAX_PATH, "overflow");
    5050    if (!VerifyTableFile (filename)) {
    5151      Nbad ++;
     
    5454    }
    5555
    56     sprintf (filename, "%s/%s.cpy", mycatdir, skylist[0].regions[i][0].name);
     56    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/%s.cpy", mycatdir, skylist[0].regions[i][0].name) < DVO_MAX_PATH, "overflow");
    5757    if (!VerifyTableFile (filename)) {
    5858      Nbad ++;
     
    6161    }
    6262
    63     sprintf (filename, "%s/%s.cpt", mycatdir, skylist[0].regions[i][0].name);
     63    myAssert (snprintf (filename, DVO_MAX_PATH, "%s/%s.cpt", mycatdir, skylist[0].regions[i][0].name) < DVO_MAX_PATH, "overflow");
    6464    if (!skipIndexCheck) {
    6565      if (!CheckCatalogIndexes(filename, skylist[0].regions[i])){
  • trunk/Ohana/src/dvomerge/src/dvoverify_utils.c

    r38471 r38553  
    55static char **failures = NULL;
    66
    7 void InitFailures () {
    8   ALLOCATE (failures, char *, NFAILURES);
     7void InitFailures (void) {
     8  ALLOCATE_ZERO (failures, char *, NFAILURES);
     9}
     10
     11void FreeFailures (void) {
     12  int i;
     13
     14  if (!failures) return;
     15  for (i = 0; i < NFAILURES; i++) {
     16    FREE (failures[i]);
     17  }
     18  FREE (failures);
    919}
    1020
     
    128138        fprintf (stderr, "unable to read header for %s, extension %d (or file has excess bytes)\n", filename, Next);
    129139      }
    130       fclose(file);
     140      fclose (file);
     141      gfits_free_header (&header);
    131142      return (FALSE);
    132143    }
     
    175186
    176187  // set the parameters which guide catalog open/load/create
    177     dvo_catalog_init (&catalog, TRUE);
     188  dvo_catalog_init (&catalog, TRUE);
    178189  catalog.filename  = filename;
    179190  catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ;
     
    183194  if (!dvo_catalog_open (&catalog, region, VERBOSE, "r")) {
    184195    fprintf (stderr, "ERROR: failure to open catalog file %s\n", catalog.filename);
     196    dvo_catalog_free (&catalog);
    185197    return FALSE;
    186198  }
     
    463475
    464476  char ImageCat[DVO_MAX_PATH];
    465   snprintf (ImageCat, DVO_MAX_PATH, "%s/Images.dat", catdir);
     477  myAssert (snprintf (ImageCat, DVO_MAX_PATH, "%s/Images.dat", catdir) < DVO_MAX_PATH, "overflow");
    466478
    467479  // load the iage database table
     
    506518    IDlist[id] = i;
    507519  }
    508 
    509   // free image table here?
     520 
    510521  // (in the future, I'll have to do the image table read in segments
    511522  // it is just getting to be too large...)
    512523  dvo_image_unlock (&inDB); // unlock input
     524  gfits_db_free (&inDB);
    513525
    514526  return TRUE;
     527}
     528
     529void FreeImageIDs (void) {
     530  FREE (IDlist);
    515531}
    516532
  • trunk/Ohana/src/imregister/photreg/output.c

    r38441 r38553  
    9696    extname = strcreate ("SUMMARY_ZPTS");
    9797  }
     98
    9899  gfits_create_table_header (&theader, "TABLE", extname);
    99100   
  • trunk/Ohana/src/kapa2/src/bDrawIt.c

    r38465 r38553  
    33bDrawBuffer *bDrawIt (png_color *palette, int Npalette, int Nbyte) {
    44
    5   int i, Nsection;
     5  int i, j, Nsection;
    66  bDrawBuffer *buffer;
    77  bDrawColor black;
     
    2323      section = GetSectionByNumber (i);
    2424      bDrawImage (buffer, section->image, graphic);
    25       for (i = 0; section->image && (i < NOVERLAYS); i++) {
    26         if (section->image->overlay[i].active) bDrawOverlay (buffer, section->image, i);
     25      for (j = 0; section->image && (j < NOVERLAYS); j++) {
     26        if (section->image->overlay[j].active) bDrawOverlay (buffer, section->image, j);
    2727      }
    2828      bDrawGraph (buffer, section->graph);
  • trunk/Ohana/src/libautocode/Makefile.Targets

    r38441 r38553  
    5555$(ASRC)/starpar-ps1-v5.$(ARCH).o \
    5656$(ASRC)/starpar-ps1-sim.$(ARCH).o \
    57 $(ASRC)/galshape.$(ARCH).o \
    58 $(ASRC)/galshape-ps1-v5.$(ARCH).o \
     57$(ASRC)/galphot.$(ARCH).o \
     58$(ASRC)/galphot-ps1-v5.$(ARCH).o \
    5959$(ASRC)/missing.$(ARCH).o \
    6060$(ASRC)/photcode.$(ARCH).o \
     
    167167$(AINC)/starpar-ps1-v5.h \
    168168$(AINC)/starpar-ps1-sim.h \
    169 $(AINC)/galshape.h \
    170 $(AINC)/galshape-ps1-v5.h \
     169$(AINC)/galphot.h \
     170$(AINC)/galphot-ps1-v5.h \
    171171$(AINC)/missing.h \
    172172$(AINC)/photcode.h \
  • trunk/Ohana/src/libdvo/include/cmf-ps1-v5-r2-lensing.h

    r37993 r38553  
    9595
    9696CMF_PS1_V5_R2_Lensing *gfits_table_get_CMF_PS1_V5_R2_Lensing (FTable *table, off_t *Ndata, char *swapped);
     97CMF_PS1_V5_R2_Lensing *gfits_table_get_CMF_PS1_V5_R2x_Lensing (FTable *ftable, off_t *Ndata, char *swapped);
     98
    9799int      gfits_table_set_CMF_PS1_V5_R2_Lensing (FTable *ftable, CMF_PS1_V5_R2_Lensing *data, off_t Ndata);
    98100int      gfits_table_mkheader_CMF_PS1_V5_R2_Lensing (Header *header);
  • trunk/Ohana/src/libdvo/include/convert.h

    r31635 r38553  
    1313int           hh_hms                PROTO((double hh, int *hr, int *mn, double *sc));
    1414int           dd_dms                PROTO((double dd, int *dg, int *mn, double *sc));
    15 int           hms_format            PROTO((char *line, double value));
    16 int           dms_format            PROTO((char *line, double value));
     15int           hms_format            PROTO((char *line, int length, double value));
     16int           dms_format            PROTO((char *line, int length, double value));
    1717int           hh_hm                 PROTO((double hh, int *hr, double *mn));
    1818int           day_to_sec            PROTO((char *string, time_t *second));
  • trunk/Ohana/src/libdvo/include/dvo.h

    r38472 r38553  
    259259typedef struct {
    260260  off_t Nregions;
     261  off_t Nalloc;
    261262  char **filename;
    262263  SkyRegion *regions;
     
    920921PhotCodeData *GetPhotcodeTable (void);
    921922void SetPhotcodeTable (PhotCodeData *);
     923void FreePhotcodeData (PhotCodeData *myPhotcodes);
     924void FreePhotcodeTable (void);
    922925
    923926int *GetSecFiltMap(PhotCodeData *ouput, PhotCodeData* input);
  • trunk/Ohana/src/libdvo/src/HostTable.c

    r38441 r38553  
    6262  char *filename = NULL;
    6363
    64   ALLOCATE (filename, char, strlen(catdir) + strlen(rootname) + 2); // one slash and one EOL
    65   sprintf (filename, "%s/%s", catdir, rootname);
     64  int Nchar = strlen(catdir) + strlen(rootname) + 16;
     65  ALLOCATE (filename, char, Nchar); // one slash and one EOL
     66  snprintf (filename, Nchar, "%s/%s", catdir, rootname);
    6667
    6768  FILE *f = fopen (filename, "r");
  • trunk/Ohana/src/libdvo/src/LoadImages.c

    r38441 r38553  
    2323
    2424  catdir = dvo_get_catdir ();
    25   sprintf (filename, "%s/Images.dat", catdir);
     25  snprintf (filename, 256, "%s/Images.dat", catdir);
    2626
    2727  if (lastFilename) {
  • trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r38441 r38553  
    5151    }                                                                   \
    5252    photcode = PhotCode_##FORMAT##_To_Internal (photcode_input, Ncode); \
    53     free (photcode_input);                                              \
    5453  }
    5554
     
    6564  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V4",    PS1_V4);
    6665  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V5",    PS1_V5);
     66
     67  gfits_db_free (&db);
    6768
    6869  table = GetPhotcodeTable ();
  • trunk/Ohana/src/libdvo/src/RegionHostTable.c

    r37807 r38553  
    6464  char *filename = NULL;
    6565
    66   ALLOCATE (filename, char, strlen(catdir) + strlen(rootname) + 2); // one slash and one EOL
    67   sprintf (filename, "%s/%s", catdir, rootname);
     66  int Nchar = strlen(catdir) + strlen(rootname) + 16;
     67
     68  ALLOCATE (filename, char, Nchar); // one slash and one EOL
     69  snprintf (filename, Nchar, "%s/%s", catdir, rootname);
    6870
    6971  FILE *f = fopen (filename, "r");
  • trunk/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r38441 r38553  
    3737  if (!gfits_db_save (&db)) return (FALSE);
    3838  if (!gfits_db_close (&db)) return (FALSE);
     39  if (!gfits_db_free (&db)) return (FALSE);
    3940
    4041  free (photcode_output);
  • trunk/Ohana/src/libdvo/src/cmf-ps1-v5-r2-lensing.c

    r37992 r38553  
    480480}
    481481
     482/** ****/
     483int fix_lensing (char *data, int Nrows) {
     484
     485  off_t i;
     486
     487  int Nbytes = sizeof (CMF_PS1_V5_R2_Lensing);
     488
     489  char buffer[64];
     490
     491  char *ptr = data;
     492  for (i = 0; i < Nrows; i++, ptr += Nbytes) {
     493    // bytes 184 - 224 (exclusive) are now at 288 - 328 (exclusive)
     494    memcpy (buffer, &ptr[288], 40);
     495    memmove (&ptr[224], &ptr[184], 104);
     496    memcpy (&ptr[184], buffer, 40);
     497  }
     498  return TRUE;
     499}
     500
     501/**************************************/
     502CMF_PS1_V5_R2_Lensing *gfits_table_get_CMF_PS1_V5_R2x_Lensing (FTable *ftable, off_t *Ndata, char *swapped) {
     503
     504  int Ncols;
     505  CMF_PS1_V5_R2_Lensing *data;
     506
     507  Ncols = ftable[0].header[0].Naxis[0];
     508  if (Ncols != ST_SIZE) {
     509    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, ST_SIZE);
     510    return NULL;
     511  }
     512
     513  *Ndata = ftable[0].header[0].Naxis[1];
     514
     515  fix_lensing (ftable[0].buffer, *Ndata);
     516  data = (CMF_PS1_V5_R2_Lensing *) ftable[0].buffer;
     517  if ((swapped == NULL) || (*swapped == FALSE)) {
     518    if (!gfits_convert_CMF_PS1_V5_R2_Lensing ((unsigned char *) data, sizeof (CMF_PS1_V5_R2_Lensing), *Ndata, TRUE)) {
     519      return NULL;
     520    }
     521    off_t i;
     522    for (i = 0; i < *Ndata; i++) {
     523      data[i].detID   += 0x80000000;
     524      data[i].flags   += 0x80000000;
     525      data[i].flags2  += 0x80000000;
     526      data[i].nFrames += 0x8000;
     527    }
     528    // gfits_table_scale_data (ftable);
     529    if (swapped != NULL) *swapped = TRUE;
     530  }
     531  return (data);
     532}
     533
  • trunk/Ohana/src/libdvo/src/convert.c

    r31635 r38553  
    4646}
    4747 
    48 int hms_format (char *line, double value) {
     48int hms_format (char *line, int length, double value) {
    4949
    5050  int hr, mn;
     
    5454  hr = (int) value;
    5555  if (isnan (value))
    56     sprintf (line, "xx:xx:xx.xx");
     56    snprintf (line, length, "xx:xx:xx.xx");
    5757  else {
    5858    if (value < 0) {
    59       sprintf (line, "-%02d:%02d:%05.2f", abs(hr), mn, sc);
     59      snprintf (line, length, "-%02d:%02d:%05.2f", abs(hr), mn, sc);
    6060    } else {
    61       sprintf (line, "+%02d:%02d:%05.2f", hr, mn, sc);
     61      snprintf (line, length, "+%02d:%02d:%05.2f", hr, mn, sc);
    6262    }
    6363  }     
     
    6565}
    6666
    67 int dms_format (char *line, double value) {
     67int dms_format (char *line, int length, double value) {
    6868
    6969  int dg, mn;
     
    7272  dd_dms (value, &dg, &mn, &sc);
    7373  if (value < 0) {
    74     sprintf (line, "-%02d:%02d:%05.2f", abs(dg), mn, sc);
     74    snprintf (line, length, "-%02d:%02d:%05.2f", abs(dg), mn, sc);
    7575  } else {
    76     sprintf (line, "+%02d:%02d:%05.2f", dg, mn, sc);
     76    snprintf (line, length, "+%02d:%02d:%05.2f", dg, mn, sc);
    7777  }
    7878  return (TRUE);
     
    134134  ALLOCATE (line, char, 64);
    135135  gmt   = gmtime (&second);
    136   sprintf (line, "%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     136  snprintf (line, 64, "%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    137137  return (line);
    138138}
     
    148148  switch (gmt[0].tm_wday) {
    149149    case 0:
    150       sprintf (line, "Sun@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     150      snprintf (line, 64, "Sun@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    151151      break;
    152152    case 1:
    153       sprintf (line, "Mon@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     153      snprintf (line, 64, "Mon@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    154154      break;
    155155    case 2:
    156       sprintf (line, "Tue@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     156      snprintf (line, 64, "Tue@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    157157      break;
    158158    case 3:
    159       sprintf (line, "Wed@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     159      snprintf (line, 64, "Wed@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    160160      break;
    161161    case 4:
    162       sprintf (line, "Thu@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     162      snprintf (line, 64, "Thu@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    163163      break;
    164164    case 5:
    165       sprintf (line, "Fri@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     165      snprintf (line, 64, "Fri@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    166166      break;
    167167    case 6:
    168       sprintf (line, "Sat@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     168      snprintf (line, 64, "Sat@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    169169      break;
    170170  }
     
    195195  hh_hm (deg, &hr, &mn);
    196196
    197   sprintf (line, "%03d:%04.1f", abs(hr), mn);
     197  snprintf (line, 16, "%03d:%04.1f", abs(hr), mn);
    198198  return (line);
    199199}
     
    209209  hh_hm (deg/15.0, &hr, &mn);
    210210
    211   sprintf (line, "%02d:%04.1f", abs(hr), mn);
     211  snprintf (line, 16, "%02d:%04.1f", abs(hr), mn);
    212212  return (line);
    213213}
     
    224224
    225225  if (deg < 0) {
    226     sprintf (line, "-%02d:%04.1f", abs(hr), mn);
     226    snprintf (line, 16, "-%02d:%04.1f", abs(hr), mn);
    227227  } else {
    228     sprintf (line, "+%02d:%04.1f", hr, mn);
     228    snprintf (line, 16, "+%02d:%04.1f", hr, mn);
    229229  }     
    230230  return (line);
  • trunk/Ohana/src/libdvo/src/coordops.c

    r38462 r38553  
    740740        for (i = 0; i < 14; i++) {
    741741          char name[64];
    742           sprintf (name, "PV2_%d", i);
     742          snprintf (name, 64, "PV2_%d", i);
    743743          if (i < 7) {
    744744            found = gfits_scan (header, name, "%f", 1, &coords[0].polyterms[0][i]);
     
    834834    if (!strncmp (coords[0].ctype, "SLAT", 4)) strcpy (csys, "SLON");
    835835    if (!strcmp (csys, "NONE")) return (FALSE);
    836     sprintf (ctype, "%s-%s", csys, &coords[0].ctype[5]);
     836    snprintf (ctype, 16, "%s-%s", csys, &coords[0].ctype[5]);
    837837    gfits_modify (header, "CTYPE1",   "%s",  1, ctype);
    838838  }   
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r38462 r38553  
    8585
    8686// we can return a static string here unless we run multiple outputs threads at once
    87 static char compress_string[16];
    8887char *dvo_catalog_compress_string (DVOCatCompress catcompress) {
    89 
     88  char *compress_string = NULL;
    9089  switch (catcompress) {
    9190    case DVO_COMPRESS_NONE:
    92       strcpy (compress_string, "NONE");
     91      compress_string = strcreate("NONE");
    9392      break;
    9493    case DVO_COMPRESS_AUTO:
    95       strcpy (compress_string, "AUTO");
     94      compress_string = strcreate("AUTO");
    9695      break;
    9796    case DVO_COMPRESS_GZIP_1:
    98       strcpy (compress_string, "GZIP_1");
     97      compress_string = strcreate("GZIP_1");
    9998      break;
    10099    case DVO_COMPRESS_GZIP_2:
    101       strcpy (compress_string, "GZIP_2");
     100      compress_string = strcreate("GZIP_2");
    102101      break;
    103102    case DVO_COMPRESS_NONE_1:
    104       strcpy (compress_string, "NONE_1");
     103      compress_string = strcreate("NONE_1");
    105104      break;
    106105    case DVO_COMPRESS_NONE_2:
    107       strcpy (compress_string, "NONE_2");
     106      compress_string = strcreate("NONE_2");
    108107      break;
    109108    case DVO_COMPRESS_RICE_1:
    110       strcpy (compress_string, "RICE_1");
     109      compress_string = strcreate("RICE_1");
    111110      break;
    112111    default:
     
    532531  galphot->minorAxisErr = NAN;
    533532  galphot->theta        = NAN;
    534   galphot->theta_err    = NAN;
     533  galphot->thetaErr     = NAN;
    535534  galphot->index        = NAN;
    536535  galphot->chisq        = NAN;
     
    541540  galphot->catID   = -1;
    542541  galphot->imageID = -1;
     542  galphot->averef  = 0;
    543543
    544544  galphot->photcode = 0;
     
    11571157    return FALSE;
    11581158  }
    1159      
     1159 
     1160  int outStatus = TRUE;
    11601161  status = unlink (tmpfilename);
    11611162  if (status) {
     1163    perror ("unlink: ");
    11621164    fprintf (stderr, "failed to unlink catalog %s~\n", catalog->filename);
    1163     return FALSE;
     1165    outStatus = FALSE;
    11641166  }
    11651167     
     
    11671169    if (catalog[0].measure_catalog != NULL) {
    11681170      if (!dvo_catalog_unlink_backup (catalog[0].measure_catalog, FALSE)) {
    1169         return FALSE;
     1171        outStatus = FALSE;
    11701172      }
    11711173    }
    11721174    if (catalog[0].missing_catalog != NULL) {
    11731175      if (!dvo_catalog_unlink_backup (catalog[0].missing_catalog, FALSE)) {
    1174         return FALSE;
     1176        outStatus = FALSE;
    11751177      }
    11761178    }
    11771179    if (catalog[0].secfilt_catalog != NULL) {
    11781180      if (!dvo_catalog_unlink_backup (catalog[0].secfilt_catalog, FALSE)) {
    1179         return FALSE;
     1181        outStatus = FALSE;
    11801182      }
    11811183    }
    11821184    if ((catalog[0].lensing_catalog != NULL) && (catalog[0].Nlensing_disk > 0)) {
    11831185      if (!dvo_catalog_unlink_backup (catalog[0].lensing_catalog, FALSE)) {
    1184         return FALSE;
     1186        outStatus = FALSE;
    11851187      }
    11861188    }
    11871189    if ((catalog[0].lensobj_catalog != NULL) && (catalog[0].Nlensobj_disk > 0)) {
    11881190      if (!dvo_catalog_unlink_backup (catalog[0].lensobj_catalog, FALSE)) {
    1189         return FALSE;
     1191        outStatus = FALSE;
    11901192      }
    11911193    }
    11921194    if ((catalog[0].starpar_catalog != NULL) && (catalog[0].Nstarpar_disk > 0)) {
    11931195      if (!dvo_catalog_unlink_backup (catalog[0].starpar_catalog, FALSE)) {
    1194         return FALSE;
     1196        outStatus = FALSE;
    11951197      }
    11961198    }
    11971199    if ((catalog[0].galphot_catalog != NULL) && (catalog[0].Ngalphot_disk > 0)) {
    11981200      if (!dvo_catalog_unlink_backup (catalog[0].galphot_catalog, FALSE)) {
    1199         return FALSE;
    1200       }
    1201     }
    1202   }
    1203   return TRUE;
    1204 }
    1205 
    1206 
     1201        outStatus = FALSE;
     1202      }
     1203    }
     1204  }
     1205  return outStatus;
     1206}
     1207
     1208
  • trunk/Ohana/src/libdvo/src/dvo_catalog_create.c

    r38441 r38553  
    105105  char *path = pathname (catalog[0].filename);
    106106  char *root = filerootname (catalog[0].filename);
    107   int length = strlen(path) + strlen(root) + 6;
     107
     108  int length = strlen(path) + strlen(root) + 16;
    108109   
    109110  Catalog *subcat;
     
    120121  ALLOCATE (subcat->filename, char, length);
    121122
    122   sprintf (subcat->filename, "%s/%s.%s", path, root, ext);
     123  snprintf (subcat->filename, length, "%s/%s.%s", path, root, ext);
    123124
    124125  char *file = filebasename (subcat->filename);
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r38441 r38553  
    9090int dvo_catalog_save_subcat (Catalog *catalog, FTable *ftable, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal) {
    9191
    92   Matrix matrix;
    93  
    94   if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     92  if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
    9593 
    9694  /* rewind file pointers and truncate (file is still open) */
     
    108106  off_t fullsize = catalog->header.datasize;
    109107
     108# if (1)
    110109  // write the PHU matrix; this is probably a NOP, do I have to keep it in?
     110  Matrix matrix;
    111111  gfits_create_matrix (&catalog->header, &matrix);
    112112  if (!gfits_fwrite_matrix  (catalog->f, &matrix)) {
     
    117117  fullsize += matrix.datasize;
    118118  gfits_free_matrix (&matrix);
     119# endif
    119120
    120121  FTable *outtable = ftable;
     
    128129  int isCompressed = output_is_compressed (start, Nrows, Ntotal, catalog->catcompress);
    129130
    130   if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     131  if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
    131132
    132133  if (isCompressed) {
     
    136137    if (!gfits_compress_table (ftable, &cmptable, 1000, compressMode)) {
    137138      fprintf (stderr, "compression failure\n");
     139      free (compressMode);
    138140      return (FALSE);
    139141    }
    140142    if (!byteswap_varlength_ftable (&cmpheader, &cmptable)) {
    141143      fprintf (stderr, "failed to swap varlength column\n");
     144      free (compressMode);
    142145      return FALSE;
    143146    }
    144147    if (!gfits_modify (cmptable.header, "DVO_CMP", "%s", 1, compressMode)) {
    145148      fprintf (stderr, "can't save compression mode\n");
    146       return (FALSE);
    147     }
     149      free (compressMode);
     150      return (FALSE);
     151    }
     152    free (compressMode);
    148153    outtable = &cmptable;
    149154  }
    150155
    151   if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     156  if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
    152157
    153158  // write the table data
     
    169174  fullsize += outtable->datasize + outtable->header->datasize;
    170175
    171   if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     176  // XXX test of repeated failure
     177  if (0) {
     178    Matrix myMatrix;
     179
     180    // write the PHU matrix; this is probably a NOP, do I have to keep it in?
     181    gfits_create_matrix (&catalog->header, &myMatrix);
     182
     183    int niter;
     184    for (niter = 0; niter < 5; niter ++) {
     185      char name[1024];
     186      snprintf (name, 1024, "%s.v.%d", catalog->filename, niter);
     187      FILE *f = fopen (name, "w");
     188
     189      myAssert (gfits_fwrite_header  (f, &catalog->header), "failed to write header");
     190      myAssert (gfits_fwrite_matrix  (f, &myMatrix), "failed to write matrix");
     191      myAssert (gfits_fwrite_Theader (f, outtable->header), "can't write table header");
     192      myAssert (gfits_fwrite_table (f, outtable), "can't write table data");
     193      myAssert (!fflush (f), "failed to flush");
     194      myAssert (!fclose (f), "failed to close");
     195      int fd = fileno(f);
     196      myAssert (fsync(fd), "failed to sync");
     197      fprintf (stderr, "wrote to %s\n", name);
     198    }
     199    gfits_free_matrix (&myMatrix);
     200  }
     201
     202  if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
    172203
    173204  // since we init'ed the structures above, these operations are safe whether or not we compressed the table
     
    191222  off_t Nskip;
    192223  int status;
    193   char *path, string[80];
     224  char *path, string[256];
    194225  Catalog *subcat;
    195226
     
    215246    return (DVO_CAT_OPEN_FAIL);
    216247  }
    217   ALLOCATE (subcat[0].filename, char, strlen(path) + strlen(string) + 2);
    218   sprintf (subcat[0].filename, "%s/%s", path, string);
     248  int Nchar = strlen(path) + strlen(string) + 10;
     249  ALLOCATE (subcat[0].filename, char, Nchar);
     250  snprintf (subcat[0].filename, Nchar, "%s/%s", path, string);
    219251  free (path);
    220252
     
    282314    }
    283315
    284     char compressMode[80];
     316    char compressMode[256];
    285317    if (!gfits_scan (ftable->header, "DVO_CMP", "%s", 1, compressMode)) {
    286318      strcpy (compressMode, "AUTO");
     
    759791}
    760792
     793# if (0)
     794void compare_file_ptr (FILE *copy_ptr, FILE *real_ptr, char *name) {
     795  return;
     796
     797  int i;
     798 
     799  char *real = (char *) real_ptr;
     800  char *copy = (char *) copy_ptr;
     801
     802  for (i = 0; i < sizeof(FILE); i++, real++, copy++) {
     803    if (*real != *copy) {
     804      fprintf (stderr, "file pointers %s differ @ %d\n", name, (int) ((char *) real - (char *) real_ptr));
     805    }
     806  }
     807}
     808# endif
     809
    761810/* save_catalog_split writes all data currently in memory to disk */
    762811int dvo_catalog_save_split (Catalog *catalog, char VERBOSE) {
     
    845894      goto failure;
    846895    }
     896
    847897    gfits_free_header (&header);
    848898    gfits_free_table (&ftable);
     
    887937      goto failure;
    888938    }
     939
    889940    gfits_free_header (&header);
    890941    gfits_free_table (&ftable);
  • trunk/Ohana/src/libdvo/src/dvo_convert.c

    r38441 r38553  
    10351035  Nimage = theader[0].Naxis[1];
    10361036
    1037 # define FORMAT_CASE(FORMAT, TYPE) \
    1038     case DVO_FORMAT_##FORMAT: { \
    1039       Image_##TYPE *tmpImage; \
     1037# define FORMAT_CASE(FORMAT, TYPE)              \
     1038  case DVO_FORMAT_##FORMAT: {                   \
     1039    Image_##TYPE *tmpImage;                                             \
    10401040      tmpImage = ImageInternalTo_##TYPE ((Image *) ftable[0].buffer, Nimage); \
    1041       free (ftable[0].buffer); \
    1042       gfits_table_set_Image_##TYPE (ftable, tmpImage, Nimage, TRUE); \
    1043       free (tmpImage); \
    1044       break; }
     1041        free (ftable[0].buffer);                                        \
     1042        gfits_free_header (ftable->header);                             \
     1043        gfits_table_set_Image_##TYPE (ftable, tmpImage, Nimage, TRUE);  \
     1044          free (tmpImage);                                              \
     1045          break; }
    10451046
    10461047  /* convert from the internal format */
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r38462 r38553  
    990990
    991991    out[i].Xfit          = in[i].Xfit;
    992     out[i]. Yfit         = in[i]. Yfit;
    993     out[i]. mag          = in[i]. mag;
    994     out[i]. magErr       = in[i]. magErr;
    995     out[i]. majorAxis    = in[i]. majorAxis;
    996     out[i]. minorAxis    = in[i]. minorAxis;
    997     out[i]. majorAxisErr = in[i]. majorAxisErr;
    998     out[i]. minorAxisErr = in[i]. minorAxisErr;
    999     out[i]. theta        = in[i]. theta;
    1000     out[i]. theta_err    = in[i]. theta_err;
    1001     out[i]. index        = in[i]. index;
    1002     out[i]. chisq        = in[i]. chisq;
    1003     out[i]. Npix         = in[i]. Npix;
    1004     out[i]. objID        = in[i]. objID;
    1005     out[i]. catID        = in[i]. catID;
    1006     out[i]. detID        = in[i]. detID;
    1007     out[i]. imageID      = in[i]. imageID;
    1008     out[i]. photcode     = in[i]. photcode;
    1009     out[i]. modelType    = in[i]. modelType;
     992    out[i].Yfit          = in[i].Yfit;
     993    out[i].mag           = in[i].mag;
     994    out[i].magErr        = in[i].magErr;
     995    out[i].majorAxis     = in[i].majorAxis;
     996    out[i].minorAxis     = in[i].minorAxis;
     997    out[i].majorAxisErr  = in[i].majorAxisErr;
     998    out[i].minorAxisErr  = in[i].minorAxisErr;
     999    out[i].theta         = in[i].theta;
     1000    out[i].thetaErr      = in[i].thetaErr;
     1001    out[i].index         = in[i].index;
     1002    out[i].chisq         = in[i].chisq;
     1003    out[i].Npix          = in[i].Npix;
     1004    out[i].objID         = in[i].objID;
     1005    out[i].catID         = in[i].catID;
     1006    out[i].detID         = in[i].detID;
     1007    out[i].imageID       = in[i].imageID;
     1008    out[i].averef        = in[i].averef;
     1009    out[i].photcode      = in[i].photcode;
     1010    out[i].modelType     = in[i].modelType;
    10101011  }
    10111012  return (out);
     
    10291030    out[i].minorAxisErr  = in[i].minorAxisErr;
    10301031    out[i].theta         = in[i].theta;
    1031     out[i].theta_err     = in[i].theta_err;
     1032    out[i].thetaErr      = in[i].thetaErr;
    10321033    out[i].index         = in[i].index;
    10331034    out[i].chisq         = in[i].chisq;
     
    10371038    out[i].detID         = in[i].detID;
    10381039    out[i].imageID       = in[i].imageID;
     1040    out[i].averef        = in[i].averef;
    10391041    out[i].photcode      = in[i].photcode;
    10401042    out[i].modelType     = in[i].modelType;
  • trunk/Ohana/src/libdvo/src/dvo_image.c

    r38441 r38553  
    231231int dvo_image_createID (Header *header) {
    232232 
    233   char dbID[33];
     233  char dbID[64];
    234234
    235235  if (!header->buffer) return FALSE;
     
    259259  int i;
    260260  for (i = 0; i < 32; i++) {
    261     sprintf (&dbID[i], "%1x", (int)(16.0*drand48()));
     261    myAssert (snprintf (&dbID[i], 2, "%1x", (int)(16.0*drand48())) < 2, "overflow");
    262262  }
    263263
  • trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r38153 r38553  
    4343}
    4444
    45 // set the photcode table. This is used to switch between serveral previously
     45// free a specified photcode set
     46void FreePhotcodeData (PhotCodeData *myPhotcodes) {
     47  if (!myPhotcodes) return;
     48  FREE(myPhotcodes->code);
     49  FREE(myPhotcodes);
     50}
     51
     52// free the internal table
     53void FreePhotcodeTable (void) {
     54  FreePhotcodeData (photcodes);
     55  FREE(genericCodeMag);
     56  FREE(genericCodeFlux);
     57}
     58
     59// set the photcode table. This is used to switch between several previously
    4660// allocated tables
    4761void SetPhotcodeTable (PhotCodeData *new) {
  • trunk/Ohana/src/libdvo/src/dvo_util.c

    r38471 r38553  
    6363    }
    6464
    65     sprintf (dvoConfig->photcodeFile, "%s/Photcodes.dat", dvoConfig->catdir);
     65    snprintf (dvoConfig->photcodeFile, 256, "%s/Photcodes.dat", dvoConfig->catdir);
    6666    if (!LoadPhotcodes (dvoConfig->photcodeFile, MasterPhotcodeFile, FALSE)) {
    6767        fprintf (stderr, "error loading photcode table %s or master file %s\n",
     
    101101    char filename[256];
    102102 
    103     sprintf (filename, "%s/Images.dat", dvoConfig->catdir);
     103    snprintf (filename, 256, "%s/Images.dat", dvoConfig->catdir);
    104104
    105105    gfits_db_init (&dvoConfig->imageDB);
  • trunk/Ohana/src/libdvo/src/skydb.c

    r19823 r38553  
    224224  /* north dec bands */
    225225  for (dec = 0; dec < 90; dec += 7.5) {
    226     sprintf (db[N].name, "n%04d.cpt", (int) 100*dec);
     226    myAssert (snprintf (db[N].name, 18, "n%04d.cpt", (int) 100*dec) < 18, "overflow");
    227227    db[N].Rmin =   0; db[N].Rmax = 360;
    228228    db[N].Dmin = dec; db[N].Dmax = dec + 7.5;
     
    233233  /* south dec bands */
    234234  for (dec = 0; dec > -90; dec -= 7.5) {
    235     sprintf (db[N].name, "s%04d.cpt", (int) 100*dec);
     235    myAssert (snprintf (db[N].name, 18, "s%04d.cpt", (int) 100*dec) < 18, "overflow");
    236236    db[N].Rmin =   0;       db[N].Rmax = 360;
    237237    db[N].Dmin = dec - 7.5; db[N].Dmax = dec;
     
    276276      new[Nnew].child = FALSE;
    277277      strncpy (root, db[i].name, 5); root[5] = 0;
    278       sprintf (new[Nnew].name, "%s/r%04d.cpt", root, Rnumber);
     278      myAssert (snprintf (new[Nnew].name, 18, "%s/r%04d.cpt", root, Rnumber) < 18, "overflow");
    279279      Rnumber ++;     
    280280      Nnew ++;
     
    365365        db[N].child = FALSE;
    366366        strncpy (root, db[i].name, 10); root[10] = 0;
    367         sprintf (db[N].name, "%s.%02d.cpt", root, Rnumber);
     367        myAssert (snprintf (db[N].name, 18, "%s.%02d.cpt", root, Rnumber) < 18, "overflow");
    368368        Rnumber ++;
    369369        N ++;
  • trunk/Ohana/src/libdvo/src/skyregion_gsc.c

    r37807 r38553  
    4646  FTable ftable;
    4747  SkyTable *skytable;
    48   SkyTable *band;
    4948  SkyTable L0, L1, L2, L3, L4;
    5049  SkyRegionZone *zones;
     
    7978/* L0 : full sky */
    8079  L0.Nregions = 1;
    81   ALLOCATE (L0.regions, SkyRegion, L0.Nregions);
     80  L0.Nalloc = 1;
     81  ALLOCATE (L0.regions, SkyRegion, L0.Nalloc);
    8282  L0.regions[0].Rmin    =   0;
    8383  L0.regions[0].Rmax    = 360;
     
    9999  /* allocate space for all levels */
    100100  L1.Nregions = L2.Nregions = L3.Nregions = L4.Nregions = 0;
    101   ALLOCATE (L1.regions, SkyRegion, 1);
    102   ALLOCATE (L2.regions, SkyRegion, 1);
    103   ALLOCATE (L3.regions, SkyRegion, 1);
    104   ALLOCATE (L4.regions, SkyRegion, 1);
     101  L1.Nalloc = NDECBANDS;         ALLOCATE (L1.regions, SkyRegion, L1.Nalloc);
     102  L2.Nalloc = NDECBANDS*0x10;    ALLOCATE (L2.regions, SkyRegion, L2.Nalloc);
     103  L3.Nalloc = NDECBANDS*0x100;   ALLOCATE (L3.regions, SkyRegion, L3.Nalloc);
     104  L4.Nalloc = NDECBANDS*0x1000;  ALLOCATE (L4.regions, SkyRegion, L4.Nalloc);
    105105
    106106  // skipLines = 0;
     
    130130
    131131    /* load all GSC Regions in this band */
    132     band = SkyRegionForDecBand (&ftable.buffer[skipLines*48], DecLines[i], DecNames[i], L1.regions[i].Dmin, L1.regions[i].Dmax);
     132    SkyTable *band = SkyRegionForDecBand (&ftable.buffer[skipLines*48], DecLines[i], DecNames[i], L1.regions[i].Dmin, L1.regions[i].Dmax);
    133133    skipLines += DecLines[i];
    134134
     
    151151
    152152    L1.Nregions ++;
    153     REALLOCATE (L1.regions, SkyRegion, L1.Nregions + 1);
     153    myAssert (L1.Nregions <= NDECBANDS, "too many L1 regions");
    154154  }
    155155
     
    225225
    226226    temp[5] = 0;
    227     sprintf (name, "%s/%s", DecName, &temp[1]);
     227    snprintf (name, 80, "%s/%s", DecName, &temp[1]);
    228228    strcpy (regions[i].name, name);
    229229  }
     
    231231  band[0].regions = regions;
    232232  band[0].Nregions = Nregions;
     233  band[0].Nalloc   = Nregions;
    233234  return (band);
    234235}
     
    277278  Nregions = band[0].Nregions;
    278279
    279   NZ = 10;
     280  NZ = 100;
    280281  ALLOCATE (zones, SkyRegionZone, NZ);
    281282 
     
    312313      /* go to the next zone */
    313314      Nz++;
    314       CHECK_REALLOCATE (zones, SkyRegionZone, NZ, Nz, 10);
     315      CHECK_REALLOCATE (zones, SkyRegionZone, NZ, Nz, 100);
    315316
    316317      /* start info for the new zone */
     
    365366        band[0].regions[Nregions + i].Dmax = -86.250;
    366367      }
    367       sprintf (band[0].regions[Nregions + i].name, "%s.%d", basename, i);
     368      myAssert (snprintf (band[0].regions[Nregions + i].name, 18, "%s.%d", basename, i) < 18, "overflow");
    368369    }
    369370    band[0].regions[Nregions + i].Rmin = 0.0;
     
    376377      band[0].regions[Nregions + i].Dmax = -88.125;
    377378    }
    378     sprintf (band[0].regions[Nregions + i].name, "%s.%d", basename, i);
     379    myAssert (snprintf (band[0].regions[Nregions + i].name, 18, "%s.%d", basename, i) < 18, "overflow");
    379380
    380381    zones[0].Nset = 6;
     
    401402void SkyTableL2fromZone (SkyTable *L2, SkyTable *L3, SkyTable *L4, SkyTable *band, SkyRegionZone *zone, int parent) {
    402403
    403   int i, Nr, Ns, Ne;
     404  int i, Ns, Ne;
    404405  char *p, name[80];
    405406
    406   Nr = L2[0].Nregions;
    407   REALLOCATE (L2[0].regions, SkyRegion, Nr + 1);
     407  int Nr = L2[0].Nregions;
     408  CHECK_REALLOCATE (L2[0].regions, SkyRegion, L2[0].Nalloc, L2[0].Nregions, 100);
    408409 
    409410  /* divide this zone into L2 regions with Nset L3 regions each (fewer on ends) */
     
    435436    }
    436437    *p = 0;
    437     sprintf (name, "%s/z%03d", band[0].regions[Ns].name, Nr);
     438    myAssert (snprintf (name, 80, "%s/z%03d", band[0].regions[Ns].name, Nr) < 80, "overflow");
    438439    *p = '/';
    439440    strcpy (L2[0].regions[Nr].name, name);
     
    444445
    445446    Nr++;
    446     REALLOCATE (L2[0].regions, SkyRegion, Nr + 1);
     447    CHECK_REALLOCATE (L2[0].regions, SkyRegion, L2[0].Nalloc, Nr, 100);
    447448  }
    448449  L2[0].Nregions = Nr;
     
    456457  Nr = L3[0].Nregions;
    457458  L3[0].Nregions += Ne - Ns;
    458   REALLOCATE (L3[0].regions, SkyRegion, L3[0].Nregions);
     459  CHECK_REALLOCATE (L3[0].regions, SkyRegion, L3[0].Nalloc, L3[0].Nregions, 0.5*L3[0].Nalloc);
    459460
    460461  L2[0].child  = TRUE;
     
    498499  Nr = L4[0].Nregions;
    499500  L4[0].Nregions += NDIV*NDIV;
    500   REALLOCATE (L4[0].regions, SkyRegion, L4[0].Nregions);
     501  CHECK_REALLOCATE (L4[0].regions, SkyRegion, L4[0].Nalloc, L4[0].Nregions, 0.5*L4[0].Nalloc);
    501502
    502503  L3[0].child  = TRUE;
     
    531532      L4[0].regions[Nr].backupID  = 0;
    532533
    533       sprintf (name, "%s.%02d", L3[0].name, Nbox);
     534      myAssert (snprintf (name, 80, "%s.%02d", L3[0].name, Nbox) < 80, "overflow");
    534535      strcpy (L4[0].regions[Nr].name, name);
    535536      if (DEBUG >= 4) SkyRegionPrint (&L4[0].regions[Nr]);
  • trunk/Ohana/src/libdvo/src/skyregion_io.c

    r38441 r38553  
    113113  fclose (f);
    114114
     115  gfits_free_header  (&header);
     116  gfits_free_matrix  (&matrix);
     117  gfits_free_header  (&theader);
     118  gfits_free_table   (&ftable);
     119
    115120  return (TRUE);
    116121}
     
    131136    exit (1);
    132137  }
     138  free (filename);
    133139  return (sky);
    134140
     
    195201  // this generates the names, be sure to free when not needed
    196202  for (i = 0; i < list[0].Nregions; i++) {
    197     sprintf (line, "%s/%s.%s", path, list[0].regions[i][0].name, ext);
     203    snprintf (line, 256, "%s/%s.%s", path, list[0].regions[i][0].name, ext);
    198204    list[0].filename[i] = strcreate (line);
    199205  }
     
    209215  // this generates the names, be sure to free when not needed
    210216  for (i = 0; i < sky[0].Nregions; i++) {
    211     sprintf (line, "%s/%s.%s", path, sky[0].regions[i].name, ext);
     217    snprintf (line, 256, "%s/%s.%s", path, sky[0].regions[i].name, ext);
    212218    sky[0].filename[i] = strcreate (line);
    213219  }
     
    222228 
    223229  char *skyfile;
    224   ALLOCATE (skyfile, char, strlen(catdir) + strlen("/SkyTable.fits") + 1);
    225   sprintf (skyfile, "%s/SkyTable.fits", catdir);
     230
     231  int Nchar = strlen(catdir) + strlen("/SkyTable.fits") + 16;
     232  ALLOCATE (skyfile, char, Nchar);
     233  snprintf (skyfile, Nchar, "%s/SkyTable.fits", catdir);
    226234
    227235  return skyfile;
  • trunk/Ohana/src/libdvo/src/skyregion_ops.c

    r37807 r38553  
    550550    }
    551551    free (list[0].regions);
     552    free (list[0].filename);
    552553  }
    553554  free (list);
  • trunk/Ohana/src/libfits/header/F_write_H.c

    r27435 r38553  
    55int gfits_write_header (char *filename, Header *header) {
    66
    7   FILE *f;
    8   off_t Nbytes;
    9   int status;
    10  
    11   status = TRUE;
     7  FILE *f = fopen (filename, "w");
     8  if (!f) return (FALSE);
    129
    13   f = fopen (filename, "w");
    14   if (f == (FILE *) NULL) return (FALSE);
    15 
    16   Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
    17 
    18   if (Nbytes != header[0].datasize) {
    19     status = FALSE;
    20   }
    21 
     10  int status = gfits_fwrite_header (f, header);
    2211  fclose (f);
    2312
     
    2918
    3019  off_t Nbytes;
    31   int status;
    32  
    33   status = TRUE;
     20
     21# ifdef OHANA_MEMORY 
     22  { // check memory before writing:
     23    // memblock of supplied pointer
     24    OhanaMemblock *myBlock = (OhanaMemblock *) header[0].buffer - 1;
     25    myAssert (myBlock->startblock == OHANA_MEMMAGIC, "bad memory");
     26    myAssert (myBlock->endblock == OHANA_MEMMAGIC, "bad memory");
     27    myAssert (myBlock->size >= header[0].datasize, "overflow");
     28  }
     29# endif
    3430
    3531  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
    36 
    37   if (Nbytes != header[0].datasize) {
    38     status = FALSE;
     32  if (Nbytes != header[0].datasize) {
     33    perror ("fwrite: ");
     34    return FALSE;
    3935  }
    40 
    41   return (status);
     36  return TRUE;
    4237}       
    4338
    4439
    4540int gfits_fwrite_header (FILE *f, Header *header) {
    46 
    47   int status;
    48   status = gfits_save_header (f, header);
     41  int status = gfits_save_header (f, header);
    4942  return (status);
    5043}
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r38441 r38553  
    9999
    100100typedef struct {
    101   char ttype[16];             // TTYPE field of original table
    102   char ttype_cmt[80];         // comment associated with TTYPE
    103   char tunit[16];             // TUNIT field of original table
    104   char tunit_cmt[80];         // comment associated with TUNIT
    105   char tformat[16];           // TFORM field of original table
    106   char tformat_cmt[80];       // comment associated with TFORM
    107   char zctype[80];            // compression type for this field
     101  char ttype[256];            // TTYPE field of original table
     102  char ttype_cmt[256];        // comment associated with TTYPE
     103  char tunit[256];            // TUNIT field of original table
     104  char tunit_cmt[256];        // comment associated with TUNIT
     105  char tformat[256];          // TFORM field of original table
     106  char tformat_cmt[256];      // comment associated with TFORM
     107  char zctype[256];           // compression type for this field
    108108  VarLengthColumn zdef;       // description of the output variable length column
    109109
    110   char datatype[80];          // named data type associated with ttype (eg, 18J -> int, 18D -> double)
     110  char datatype[256];         // named data type associated with ttype (eg, 18J -> int, 18D -> double)
    111111  int Nvalues;                // number of values per row (eg 18J -> 18 int values)
    112112  int pixsize;                // number of bytes per value of this row (eg, 18J -> 4 bytes)
  • trunk/Ohana/src/libfits/matrix/F_write_M.c

    r33648 r38553  
    3535  else
    3636    nbytes = FT_RECORD_SIZE * ((off_t) (matrix[0].datasize / FT_RECORD_SIZE));
     37
     38  // fprintf (stderr, "write matrix: %d bytes (%d datasize)\n", (int) nbytes, (int) matrix[0].datasize);
     39  if (nbytes == 0) return TRUE;
    3740
    3841# define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; }
  • trunk/Ohana/src/libfits/table/F_compress_T.c

    r38471 r38553  
    5757  char *raw = NULL;
    5858  char *zdata = NULL;
     59  TableField *fields = NULL;
    5960
    6061  Header *srcheader = srctable->header;
     
    100101  gettimeofday (&startTimer, (void *) NULL);
    101102
    102   TableField *fields = NULL;
    103103  ALLOCATE_ZERO (fields, TableField, Nfields);
    104104  for (i = 0; i < Nfields; i++) {
     
    351351  gfits_dump_cmp_table (tgttable, "cmp");
    352352
    353   free (raw);
    354   free (zdata);
     353  FREE (raw);
     354  FREE (zdata);
     355  FREE (fields);
    355356  return (TRUE);
    356357
     
    358359  FREE (raw);
    359360  FREE (zdata);
     361  FREE (fields);
    360362  return FALSE;
    361363}
  • trunk/Ohana/src/libfits/table/F_create_TH.c

    r28241 r38553  
    1111 
    1212  int i;
    13   char axis[10];
     13  char axis[128];
    1414 
    1515  header[0].datasize = NBYTES;
    1616
     17  myAssert (!header->buffer, "failed to init header or free buffer?");
    1718  ALLOCATE (header[0].buffer, char, NBYTES);
    1819 
     
    2627 
    2728  for (i = 0; i < header[0].Naxes; i++) {
    28     sprintf (axis, "NAXIS%d", i + 1);
     29    snprintf (axis, 64, "NAXIS%d", i + 1);
    2930    gfits_modify (header,  axis, OFF_T_FMT, 1,  header[0].Naxis[i]);
    3031  }
  • trunk/Ohana/src/libfits/table/F_define_column.c

    r38441 r38553  
    1111  off_t Naxis1;
    1212  int Nfields, Nbytes, Nval;
    13   char type[16], field[16];
     13  char type[64], field[64];
    1414 
    1515  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
     
    2121  Naxis1 += Nbytes*Nval;
    2222
    23   sprintf (field, "TTYPE%d", Nfields);
     23  snprintf (field, 64, "TTYPE%d", Nfields);
    2424  gfits_modify (header, field, "%s", 1, label);
    2525  gfits_modify_alt (header, field, "%C", 1, comment);
    26   sprintf (field, "TUNIT%d", Nfields);
     26  snprintf (field, 64, "TUNIT%d", Nfields);
    2727  gfits_modify (header, field, "%s", 1, unit);
    28   sprintf (field, "TFORM%d", Nfields);
     28  snprintf (field, 64, "TFORM%d", Nfields);
    2929  gfits_modify (header, field, "%s", 1, format);
    3030
    3131  // add scaling parameters unless they amount to a noop
    3232  if ((bscale != 1.0) || (bzero != 0.0)) {
    33       sprintf (field, "TSCAL%d", Nfields);
     33      snprintf (field, 64, "TSCAL%d", Nfields);
    3434      gfits_modify (header, field, "%lf", 1, bscale);
    35       sprintf (field, "TZERO%d", Nfields);
     35      snprintf (field, 64, "TZERO%d", Nfields);
    3636      gfits_modify (header, field, "%lf", 1, bzero);
    3737  }
     
    5454  off_t Naxis1;
    5555  int Nfields, Nbytes, Nval;
    56   char type[16], field[16];
     56  char type[64], field[64];
    5757 
    5858  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
     
    6464  Naxis1 += Nbytes*Nval;
    6565
    66   sprintf (field, "TTYPE%d", Nfields);
     66  snprintf (field, 64, "TTYPE%d", Nfields);
    6767  gfits_modify (header, field, "%s", 1, label);
    6868  if (comment) {
     
    7070  }
    7171  if (unit) {
    72     sprintf (field, "TUNIT%d", Nfields);
     72    snprintf (field, 64, "TUNIT%d", Nfields);
    7373    gfits_modify (header, field, "%s", 1, unit);
    7474  }
    75   sprintf (field, "TFORM%d", Nfields);
     75  snprintf (field, 64, "TFORM%d", Nfields);
    7676  gfits_modify (header, field, "%s", 1, format);
    7777
    7878  // add scaling parameters unless they amount to a noop
    7979  if ((bscale != 1.0) || (bzero != 0.0)) {
    80       sprintf (field, "TSCAL%d", Nfields);
     80      snprintf (field, 64, "TSCAL%d", Nfields);
    8181      gfits_modify (header, field, "%lf", 1, bscale);
    82       sprintf (field, "TZERO%d", Nfields);
     82      snprintf (field, 64, "TZERO%d", Nfields);
    8383      gfits_modify (header, field, "%lf", 1, bzero);
    8484  }
     
    9797  off_t Naxis1;
    9898  int Nstart, Nfields, Nbytes, Nval;
    99   char type[16], field[16], cformat[16];
     99  char type[64], field[64], cformat[64];
    100100
    101101  strcpy (cformat, format);
     
    109109  Naxis1 += Nbytes*Nval;
    110110
    111   sprintf (field, "TTYPE%d", Nfields);
     111  snprintf (field, 64, "TTYPE%d", Nfields);
    112112  gfits_modify (header, field, "%s", 1, label);
    113113  gfits_modify_alt (header, field, "%C", 1, comment);
    114   sprintf (field, "TUNIT%d", Nfields);
     114  snprintf (field, 64, "TUNIT%d", Nfields);
    115115  gfits_modify (header, field, "%s", 1, unit);
    116   sprintf (field, "TFORM%d", Nfields);
     116  snprintf (field, 64, "TFORM%d", Nfields);
    117117  gfits_modify (header, field, "%s", 1, format);
    118118
    119   sprintf (field, "TBCOL%d", Nfields);
     119  snprintf (field, 64, "TBCOL%d", Nfields);
    120120  gfits_modify (header, field, "%d", 1, Nstart);
    121121
  • trunk/Ohana/src/libfits/table/F_get_T_column.c

    r7054 r38553  
    99{
    1010 
    11   char Tform[100], field[100], tmp[100];
     11  char Tform[256], field[256], tmp[256];
    1212  int  start, Nchar, i, N;
    1313 
     
    2222  /* should I count fields from 0 or from 1? */
    2323 
    24   sprintf (field, "TBCOL%d\0", X);
     24  snprintf (field, 256, "TBCOL%d\0", X);
    2525  gfits_scan (&table[0].header, field, "%d", &start, 1);
    2626  start --;
    27   sprintf (field, "TFORM%d\0", X);
     27  snprintf (field, 256, "TFORM%d\0", X);
    2828  gfits_scan (&table[0].header, field, "%s", Tform, 1);
    2929  Nchar = atof (&Tform[1]);
  • trunk/Ohana/src/libfits/table/F_get_T_value.c

    r7054 r38553  
    1010{
    1111 
    12   char Tform[100], field[100];
     12  char Tform[256], field[256];
    1313  int  start, Nchar, byte;
    1414  char tmp[1000];
     
    1616  /* no error checking, all sorts of problems! */
    1717 
    18   sprintf (field, "TBCOL%d\0", X);
     18  snprintf (field, 256, "TBCOL%d\0", X);
    1919  gfits_scan (&table[0].header, field, "%d", &start, 1);
    2020  start --;
    2121 
    22   sprintf (field, "TFORM%d\0", X);
     22  snprintf (field, 256, "TFORM%d\0", X);
    2323  gfits_scan (&table[0].header, field, "%s", Tform, 1);
    2424  Nchar = atof (&Tform[1]);
     25  myAssert (Nchar < 999, "overflow");
    2526 
    2627  byte = Y*table[0].Naxis[0] + start;
  • trunk/Ohana/src/libfits/table/F_get_column.c

    r38441 r38553  
    2525  off_t Nx, Ny;
    2626  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
    27   char tlabel[80], field[80], format[80], tmpline[16];
     27  char tlabel[256], field[256], format[256], tmpline[64];
    2828  char *Pin, *Pout, *array;
    2929  double Bscale, Bzero;
     
    3636  if (!gfits_scan (header, "TFIELDS", "%d", 1, &Nfields)) return (NULL);
    3737  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    38     sprintf (field, "TTYPE%d", i);
     38    snprintf (field, 256, "TTYPE%d", i);
    3939    gfits_scan (header, field, "%s", 1, tlabel);
    4040  }
     
    4646
    4747  /* interpret format */
    48   sprintf (field, "TSCAL%d", N);
     48  snprintf (field, 256, "TSCAL%d", N);
    4949  gfits_scan (header, field, "%lf", 1, &Bscale);
    50   sprintf (field, "TZERO%d", N);
     50  snprintf (field, 256, "TZERO%d", N);
    5151  gfits_scan (header, field, "%lf", 1, &Bzero);
    52   sprintf (field, "TFORM%d", N);
     52  snprintf (field, 256, "TFORM%d", N);
    5353  gfits_scan (header, field, "%s", 1, format);
    5454
     
    6262  Nstart = 0;
    6363  for (i = 1; i < N; i++) {
    64     sprintf (field, "TFORM%d", i);
     64    snprintf (field, 256, "TFORM%d", i);
    6565    gfits_scan (header, field, "%s", 1, format);
    6666    gfits_bintable_format (format, tmpline, &Nv, &Nb);
     
    145145
    146146  int Nbytes;
    147   char field[80], format[80];
     147  char field[256], format[256];
    148148
    149149  assert (N > 0);
    150150
    151   sprintf (field, "TFORM%d", N);
     151  snprintf (field, 256, "TFORM%d", N);
    152152  if (!gfits_scan (header, field, "%s", 1, format)) return FALSE;
    153153  if (!gfits_bintable_format (format, type, Nval, &Nbytes)) return (FALSE);
     
    159159
    160160  int i, N, Nfields;
    161   char tlabel[80], field[80];
     161  char tlabel[256], field[256];
    162162
    163163  if (label == (char *) NULL) return (FALSE);
     
    168168  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    169169  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    170     sprintf (field, "TTYPE%d", i);
     170    snprintf (field, 256, "TTYPE%d", i);
    171171    gfits_scan (header, field, "%s", 1, tlabel);
    172172  }
     
    181181int gfits_get_bintable_column_raw (Header *header, FTable *table, char *label, void **data, char nativeOrder) {
    182182
    183   char type[16];
     183  char type[64];
    184184  off_t Nrow;
    185185  int Ncol;
     
    195195int gfits_get_bintable_column (Header *header, FTable *table, char *label, void **data) {
    196196
    197   char type[16];
     197  char type[64];
    198198  off_t Nrow;
    199199  int Ncol;
     
    229229
    230230  int i, N, Nfields, Nval, Nbytes;
    231   char tlabel[80], field[80], format[80];
     231  char tlabel[256], field[256], format[256];
    232232
    233233  if (label == (char *) NULL) return (FALSE);
     
    238238  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    239239  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    240     sprintf (field, "TTYPE%d", i);
     240    snprintf (field, 256, "TTYPE%d", i);
    241241    gfits_scan (header, field, "%s", 1, tlabel);
    242242  }
     
    245245
    246246  /* interpret format */
    247   sprintf (field, "TFORM%d", N);
     247  snprintf (field, 256, "TFORM%d", N);
    248248  gfits_scan (header, field, "%s", 1, format);
    249249
     
    257257  off_t Nx, Ny;
    258258  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
    259   char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16];
     259  char tlabel[256], field[256], format[256], cformat[256], type[64], tmp[64];
    260260  char *array, *Pin, *Pout, *line;
    261261
     
    268268  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    269269  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    270     sprintf (field, "TTYPE%d", i);
     270    snprintf (field, 256, "TTYPE%d", i);
    271271    gfits_scan (header, field, "%s", 1, tlabel);
    272272  }
     
    275275
    276276  /* interpret format */
    277   sprintf (field, "TFORM%d", N);
     277  snprintf (field, 256, "TFORM%d", N);
    278278  gfits_scan (header, field, "%s", 1, format);
    279279
     
    288288  Nstart = 0;
    289289  for (i = 1; i < N; i++) {
    290     sprintf (field, "TFORM%d", i);
     290    snprintf (field, 256, "TFORM%d", i);
    291291    gfits_scan (header, field, "%s", 1, format);
    292292    gfits_table_format (format, tmp, &Nv, &Nb);
  • trunk/Ohana/src/libfits/table/F_set_column.c

    r38441 r38553  
    3030  int i, N, Nfields;
    3131  int Nval, Nbytes, Nstart, Nv, Nb;
    32   char tlabel[80], field[80], format[80], type[16], tmpline[16];
     32  char tlabel[256], field[256], format[256], type[64], tmpline[64];
    3333  char *Pin, *Pout, *array;
    3434  double Bscale, Bzero;
     
    4141  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    4242  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    43     sprintf (field, "TTYPE%d", i);
     43    snprintf (field, 256, "TTYPE%d", i);
    4444    gfits_scan (header, field, "%s", 1, tlabel);
    4545  }
     
    4848
    4949  /* interpret format */
    50   sprintf (field, "TSCAL%d", N);
     50  snprintf (field, 256, "TSCAL%d", N);
    5151  if (!gfits_scan (header, field, "%lf", 1, &Bscale)) {
    5252    Bscale = 1.0;
    5353  }
    54   sprintf (field, "TZERO%d", N);
     54  snprintf (field, 256, "TZERO%d", N);
    5555  if (!gfits_scan (header, field, "%lf", 1, &Bzero)) {
    5656    Bzero = 0.0;
    5757  }
    58   sprintf (field, "TFORM%d", N);
     58  snprintf (field, 256, "TFORM%d", N);
    5959  gfits_scan (header, field, "%s", 1, format);
    6060
     
    7575  Nstart = 0;
    7676  for (i = 1; i < N; i++) {
    77     sprintf (field, "TFORM%d", i);
     77    snprintf (field, 256, "TFORM%d", i);
    7878    gfits_scan (header, field, "%s", 1, format);
    7979    gfits_bintable_format (format, tmpline, &Nv, &Nb);
     
    190190  int i, N, Nfields;
    191191  int Nval, NbytesOut, Nstart, Nv, Nb;
    192   char tlabel[80], field[80], format[80], outtype[16], tmpline[16];
     192  char tlabel[256], field[256], format[256], outtype[64], tmpline[64];
    193193  char *Pin, *Pout, *array;
    194194  double Bscale, Bzero;
     
    201201  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    202202  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    203     sprintf (field, "TTYPE%d", i);
     203    snprintf (field, 256, "TTYPE%d", i);
    204204    gfits_scan (header, field, "%s", 1, tlabel);
    205205  }
     
    208208
    209209  /* interpret format */
    210   sprintf (field, "TSCAL%d", N);
     210  snprintf (field, 256, "TSCAL%d", N);
    211211  if (!gfits_scan (header, field, "%lf", 1, &Bscale)) {
    212212    Bscale = 1.0;
    213213  }
    214   sprintf (field, "TZERO%d", N);
     214  snprintf (field, 256, "TZERO%d", N);
    215215  if (!gfits_scan (header, field, "%lf", 1, &Bzero)) {
    216216    Bzero = 0.0;
    217217  }
    218   sprintf (field, "TFORM%d", N);
     218  snprintf (field, 256, "TFORM%d", N);
    219219  gfits_scan (header, field, "%s", 1, format);
    220220
     
    233233  Nstart = 0;
    234234  for (i = 1; i < N; i++) {
    235     sprintf (field, "TFORM%d", i);
     235    snprintf (field, 256, "TFORM%d", i);
    236236    gfits_scan (header, field, "%s", 1, format);
    237237    gfits_bintable_format (format, tmpline, &Nv, &Nb);
     
    780780  off_t Nx, Ny;
    781781  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
    782   char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16];
     782  char tlabel[256], field[256], format[256], cformat[256], type[64], tmp[64];
    783783  char *array, *Pin, *Pout, *line;
    784784
     
    790790  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    791791  for (i = 1; strcmp (label, tlabel) && (i < Nfields + 1); i++) {
    792     sprintf (field, "TTYPE%d", i);
     792    snprintf (field, 256, "TTYPE%d", i);
    793793    gfits_scan (header, field, "%s", 1, tlabel);
    794794  }
     
    797797
    798798  /* interpret format */
    799   sprintf (field, "TFORM%d", N);
     799  snprintf (field, 256, "TFORM%d", N);
    800800  gfits_scan (header, field, "%s", 1, format);
    801801
     
    815815  Nstart = 0;
    816816  for (i = 1; i < N; i++) {
    817     sprintf (field, "TFORM%d", i);
     817    snprintf (field, 256, "TFORM%d", i);
    818818    gfits_scan (header, field, "%s", 1, format);
    819819    gfits_table_format (format, tmp, &Nv, &Nb);
  • trunk/Ohana/src/libfits/table/F_table_column.c

    r7054 r38553  
    66/* we expect one more field: the pointer to the array we read in */
    77
    8   char string[80], this_field[80], form[80], temp[80];
     8  char string[256], this_field[256], form[256], temp[256];
    99  int i, j, N, start, end, width, M;
    1010  va_list argp;
     
    1818  /* find the correct field */
    1919  for (i = 0; i < table[0].Nfields; i++) {
    20     sprintf (string, "TTYPE%d\0", i+1);
     20    snprintf (string, 256, "TTYPE%d\0", i+1);
    2121    gfits_scan (&table[0].header, string, "%s", 1, this_field);
    2222    if (!strcmp (field, this_field)) {
     
    3232  N = i + 1;
    3333
    34   sprintf (string, "TBCOL%d\0", N);
     34  snprintf (string, 256, "TBCOL%d\0", N);
    3535  gfits_scan (&table[0].header, string, "%d", 1, &start);
    36   sprintf (string, "TFORM%d\0", N);
     36  snprintf (string, 256, "TFORM%d\0", N);
    3737  gfits_scan (&table[0].header, string, "%s", 1, form);
    3838  /* we could use some error checking from the FITS table form, but
     
    4242    end = table[0].Naxis[0];
    4343  } else {
    44     sprintf (string, "TBCOL%d\0", N+1);
     44    snprintf (string, 256, "TBCOL%d\0", N+1);
    4545    gfits_scan (&table[0].header, string, "%d", 1, &end);
    4646  }
  • trunk/Ohana/src/libfits/table/F_table_format.c

    r38441 r38553  
    113113  if (!*Nbytes) { return (FALSE); }
    114114 
     115  // XXXX : check usage:
     116  myAbort ("need to check length");
    115117  sprintf (format, "%%-%s%c", Size, Type);
    116118
     
    191193  off_t Nx, off;
    192194  int i, Nchar, Nval, Nbytes, Nfields;
    193   char *line, format[64], field[16], type[16];
     195  char *line, format[64], field[64], type[64];
    194196  va_list argp;
    195197 
     
    204206  for (i = 1; i <= Nfields; i++) {
    205207
    206     sprintf (field, "TFORM%d", i);
     208    snprintf (field, 64, "TFORM%d", i);
    207209    gfits_scan (table[0].header, field, "%s", 1, format);       /* get field format */
    208210    gfits_table_format (format, type, &Nval, &Nbytes); /* convert to c-style */
     
    232234  int i, j, n, Nfields;
    233235  int Nchar, Nval, Nbytes, status;
    234   char format[64], field[16], type[16];
     236  char format[64], field[64], type[64];
    235237  double tzero, tscale;
    236238  char *tmpChar;
     
    246248
    247249  for (i = 1; i <= Nfields; i++) {
    248     sprintf (field, "TFORM%d", i);
     250    snprintf (field, 64, "TFORM%d", i);
    249251    gfits_scan (ftable[0].header, field, "%s", 1, format);       /* get field format */
    250252    gfits_bintable_format (format, type, &Nval, &Nbytes); /* convert to c-style */
    251253    Nchar = Nval * Nbytes;
    252254
    253     sprintf (field, "TZERO%d", i);
     255    snprintf (field, 64, "TZERO%d", i);
    254256    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tzero);       /* get field format */
    255257    if (!status) {
     
    258260    }
    259261
    260     sprintf (field, "TSCAL%d", i);
     262    snprintf (field, 64, "TSCAL%d", i);
    261263    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tscale);       /* get field format */
    262264    if (!status) {
     
    325327  int i, j, n, Nfields;
    326328  int Nchar, Nval, Nbytes, status;
    327   char format[64], field[16], type[16];
     329  char format[64], field[64], type[64];
    328330  double tzero, tscale;
    329331  char *tmpChar;
     
    339341
    340342  for (i = 1; i <= Nfields; i++) {
    341     sprintf (field, "TFORM%d", i);
     343    snprintf (field, 64, "TFORM%d", i);
    342344    gfits_scan (ftable[0].header, field, "%s", 1, format);       /* get field format */
    343345    gfits_bintable_format (format, type, &Nval, &Nbytes); /* convert to c-style */
    344346    Nchar = Nval * Nbytes;
    345347
    346     sprintf (field, "TZERO%d", i);
     348    snprintf (field, 64, "TZERO%d", i);
    347349    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tzero);       /* get field format */
    348350    if (!status) {
     
    351353    }
    352354
    353     sprintf (field, "TSCAL%d", i);
     355    snprintf (field, 64, "TSCAL%d", i);
    354356    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tscale);       /* get field format */
    355357    if (!status) {
  • trunk/Ohana/src/libfits/table/F_table_varlength.c

    r38441 r38553  
    88  int Nv, Nb;
    99  char *p1, *p2, *p3;
    10   char field[81];
    11   char format[81];
    12   char tmpline[81];
     10  char field[256];
     11  char format[256];
     12  char tmpline[256];
    1313
    1414  // grab the value of TFORMn for this column
     
    6161  def->offset = 0;
    6262  for (i = 1; i < column; i++) {
    63     sprintf (field, "TFORM%d", i);
     63    snprintf (field, 256, "TFORM%d", i);
    6464    gfits_scan (ftable->header, field, "%s", 1, format);
    6565    gfits_bintable_format (format, tmpline, &Nv, &Nb);
  • trunk/Ohana/src/libfits/table/F_uncompress_T.c

    r38471 r38553  
    7878  int i;
    7979
    80   char keyword[81];
     80  char keyword[256];
    8181
    8282  char *raw = NULL;
    8383  char *zdata = NULL;
     84  TableField *fields = NULL;
    8485
    8586  Header *srcheader = srctable->header;
     
    111112  int offset = 0;
    112113
    113   TableField *fields = NULL;
    114114  ALLOCATE (fields, TableField, Nfields);
    115115  for (i = 0; i < Nfields; i++) {
     
    336336  free (raw);
    337337  free (zdata);
     338  free (fields);
    338339  return (TRUE);
    339340
     
    341342  FREE (raw);
    342343  FREE (zdata);
     344  FREE (fields);
    343345  return FALSE;
    344346}
  • trunk/Ohana/src/libfits/table/F_write_T.c

    r38441 r38553  
    55int gfits_write_table (char *filename, FTable *table) {
    66 
    7   FILE *f;
    8   int status;
    9  
    10   status = TRUE;
    11  
    12   f = fopen (filename, "a+");
     7  FILE *f = fopen (filename, "a+");
    138  if (f == (FILE *) NULL) return (FALSE);
    149 
    15   status = fseeko (f, 0LL, SEEK_END);  /* write table to end of file! */
     10  int status = fseeko (f, 0LL, SEEK_END);  /* write table to end of file! */
    1611  if (status) { perror ("fseeko: "); return (FALSE);  }
    1712  status = gfits_fwrite_table (f, table);
     
    2520 
    2621  off_t Nbytes;
    27  
     22
     23# ifdef OHANA_MEMORY 
     24  { // check memory before writing:
     25    // memblock of supplied pointer
     26    OhanaMemblock *myBlock = (OhanaMemblock *) table[0].buffer - 1;
     27    myAssert (myBlock->startblock == OHANA_MEMMAGIC, "bad memory");
     28    myAssert (myBlock->endblock == OHANA_MEMMAGIC, "bad memory");
     29    myAssert (myBlock->size >= table[0].datasize, "overflow");
     30  }
     31# endif
     32
    2833  Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].datasize, f);
    29   if (Nbytes != table[0].datasize) { perror ("fwrite: "); return (FALSE);  }
     34  if (Nbytes != table[0].datasize) {
     35    perror ("fwrite: ");
     36    return (FALSE); 
     37  }
    3038  return (TRUE);
    3139}       
  • trunk/Ohana/src/libfits/table/F_write_TH.c

    r38441 r38553  
    55int gfits_write_Theader (char *filename, Header *header) {
    66 
    7   FILE *f;
    8   int status;
     7  FILE *f = fopen (filename, "a+");
     8  if (!f) return (FALSE);
    99 
    10   status = TRUE;
    11  
    12   f = fopen (filename, "a+");
    13   if (f == (FILE *) NULL) return (FALSE);
    14  
    15   status = fseeko (f, 0LL, SEEK_END);  /* write header to end of file! */
     10  int status = fseeko (f, 0LL, SEEK_END);  /* write header to end of file! */
    1611  if (status) { perror ("fseeko: "); return (FALSE);  }
    1712  status = gfits_fwrite_Theader (f, header);
     
    2621  off_t Nbytes;
    2722 
     23# ifdef OHANA_MEMORY 
     24  {
     25    // memblock of supplied pointer
     26    OhanaMemblock *myBlock = (OhanaMemblock *) header[0].buffer - 1;
     27    myAssert (myBlock->startblock == OHANA_MEMMAGIC, "bad memory");
     28    myAssert (myBlock->endblock == OHANA_MEMMAGIC, "bad memory");
     29    myAssert (myBlock->size >= header[0].datasize, "overflow");
     30  }
     31# endif
     32
    2833  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
    29   if (Nbytes != header[0].datasize) { perror ("fwrite: "); return (FALSE);  }
     34  if (Nbytes != header[0].datasize) {
     35    perror ("fwrite: ");
     36    return (FALSE); 
     37  }
    3038
    3139  return (TRUE);
  • trunk/Ohana/src/libfits/test

    • Property svn:ignore
      •  

        old new  
        22ricetest
        33tablecomp
         4tcomptiming
        45test.cmp.fits
        56test.fpk.fits
  • trunk/Ohana/src/libfits/test/imagecomp.c

    r38427 r38553  
    1111int bitpix[] = {8, 16, 32, -32, -64, 0};
    1212
    13 //char *cmptype[] = {"GZIP_1", NULL};
    14 //int bitpix[] = {16, 0};
     13// char *cmptype[] = {"NONE", NULL};
     14// int bitpix[] = {16, 0};
    1515
    1616static int NX = 10;
     
    3131      test_compress_fulltile (bitpix[j], cmptype[i]);
    3232      test_compress_fullrange (bitpix[j], cmptype[i]);
     33      ok (ohana_memcheck (TRUE), "no memory corruption");
    3334    }
    3435  }
     
    4243      test_compress_fulltile (bitpix[j], cmptype[i]);
    4344      test_compress_fullrange (bitpix[j], cmptype[i]);
     45      ok (ohana_memcheck (TRUE), "no memory corruption");
    4446    }
    4547  }
     
    5355      test_compress_fulltile (bitpix[j], cmptype[i]);
    5456      test_compress_fullrange (bitpix[j], cmptype[i]);
     57      ok (ohana_memcheck (TRUE), "no memory corruption");
    5558    }
    5659  }
  • trunk/Ohana/src/libfits/test/tablecomp.c

    r38418 r38553  
    2727    test_compress_fullrange (cmptype[i]);
    2828    test_compress_empty (cmptype[i]);
    29     ok (ohana_memcheck_func (TRUE), "no memory corruption");
     29    ok (ohana_memcheck (TRUE), "no memory corruption");
    3030  }
    3131
  • trunk/Ohana/src/libfits/test/tcomptiming.c

    r38429 r38553  
    2929    gfits_uncompress_timing();
    3030  }
    31   ok (ohana_memcheck_func (TRUE), "no memory corruption");
     31  ok (ohana_memcheck (TRUE), "no memory corruption");
    3232
    3333  return exit_status();
  • trunk/Ohana/src/libohana/include/ohana.h

    r38459 r38553  
    333333char   *SelectConfigFile       PROTO((int *argc, char **argv, char *progname));
    334334char   *LoadConfigFile         PROTO((char *filename));
     335void    FreeConfigFile         PROTO((void));
    335336char   *ScanConfig             PROTO((char *config, char *field, char *mode, int N,...)) OHANA_FORMAT(scanf, 3, 5);
    336337char   *expandline             PROTO((char *line, char *config));
  • trunk/Ohana/src/libohana/include/ohana_allocate.h

    r38441 r38553  
    11# ifndef OHANA_ALLOCATE
    22# define OHANA_ALLOCATE
     3
     4# define OHANA_MEMMAGIC (uint32_t) 0xdeadbeef
     5
     6typedef struct OhanaMemblock {
     7  uint32_t startblock;        // endpost marker
     8  struct OhanaMemblock *prevBlock; // previously allocated memory
     9  struct OhanaMemblock *nextBlock; // next allocated memory
     10  size_t size;                // size of memory
     11  const char *file;           // file (re)allocated
     12  const char *func;           // func (re)allocated
     13  int line;                   // line (re)allocated
     14  int freed;                  // memory has been freed
     15  int dummy;                  // need to put endblock on the endpost
     16  uint32_t endblock;          // endpost marker
     17} OhanaMemblock;
    318
    419typedef struct {
     
    2944void  real_free (void *in);
    3045
    31 # define ohana_memcheck(X) ohana_memcheck_func (X);
     46# define ohana_memcheck(X) ohana_memcheck_func (X)
    3247# define ohana_memdump(X) ohana_memdump_func (X);
    3348
     
    5671# else  /* below: not OHANA_MEMORY */
    5772
    58 # define ohana_memcheck(X) TRUE
     73int   ohana_memcheck_noop (int mode);
     74
     75# define ohana_memcheck(X) ohana_memcheck_noop (X)
    5976# define ohana_memdump(X) /* NOP */
    6077void  real_free (void *in);
  • trunk/Ohana/src/libohana/src/config.c

    r38459 r38553  
    77static char **DefineVariable;
    88static char **DefineValue;
     9
     10void FreeConfigFile (void) {
     11  int i;
     12  for (i = 0; i < NDefineVariable; i++) {
     13    free (DefineVariable[i]);
     14    free (DefineValue[i]);
     15  }
     16  free (DefineVariable);
     17  free (DefineValue);
     18  free (ConfigVariable);
     19}
    920
    1021char *SelectConfigFile (int *argc, char **argv, char *progname) {
     
    8091  uid = getuid();
    8192  gid = getgid();
    82   ALLOCATE (find, char, strlen(progname) + 32);
     93
     94  int Nchar = strlen(progname) + 32;
     95  ALLOCATE (find, char, Nchar);
    8396
    8497  /* look for progname.rc */
    85   sprintf (find, "%s.rc", progname);
     98  snprintf (find, Nchar, "%s.rc", progname);
    8699  status = stat (find, &filestat);
    87100  if (status == 0) {
     
    114127  if (home == (char *) NULL) { return ((char *) NULL); }
    115128  ALLOCATE (find, char, 1024);
    116   sprintf (find, "%s/.%src", home, progname);
     129  snprintf (find, 1024, "%s/.%src", home, progname);
    117130  status = stat (find, &filestat);
    118131  if (status == 0) {
     
    264277  va_start (argp, Nentry);
    265278
    266   ALLOCATE (tfield, char, strlen (field) + 3);
    267   sprintf (tfield, "\n%s", field);
     279  int Nchar = strlen (field) + 16;
     280  ALLOCATE (tfield, char, Nchar);
     281  snprintf (tfield, Nchar, "\n%s", field);
    268282
    269283  /* we search for Nentry matching fields,
  • trunk/Ohana/src/libohana/src/findexec.c

    r38062 r38553  
    113113  /* check permission to write to backup file */
    114114  if (BACKUP) {
    115     ALLOCATE (filename, char, strlen(basefile) + 2);
    116     sprintf (filename, "%s~", basefile);
     115    int Nchar = strlen(basefile) + 16;
     116    ALLOCATE (filename, char, Nchar);
     117    snprintf (filename, Nchar, "%s~", basefile);
    117118    status = stat (filename, &filestat);
    118119    if (status == 0) { /* file exists, are permissions OK? */
     
    289290        e = strchr (c, ':');
    290291      }
    291       sprintf (name, "%s/%s", path, argv[0]);
     292      snprintf (name, 1024, "%s/%s", path, argv[0]);
    292293      status = check_file_exec (name);
    293294
     
    374375  int status, cmode;
    375376  struct stat filestat;
    376   char line[256];
     377  char line[1024];
    377378
    378379  status = stat (filename, &filestat);
    379380  if (status == 0) { /* file exists, make backup copy */
    380     sprintf (line, "cp %s %s~", filename, filename);
     381    snprintf (line, 1024, "cp %s %s~", filename, filename);
    381382    status = system (line);
    382383    if (status) {
     
    385386    }
    386387    cmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    387     sprintf (line, "%s~", filename);
     388    snprintf (line, 1024, "%s~", filename);
    388389    chmod (line, cmode);
    389390  }
  • trunk/Ohana/src/libohana/src/gaussj.c

    r37807 r38553  
    144144    if (fabs(growth) > MAX_RANGE) {
    145145      fprintf (stderr, "max range\n");
     146# if (VERY_VERBOSE)
     147      fprintf (stderr, "full A matrix:\n");
     148      for (row = 0; row < N; row++) {
     149        for (col = 0; col < N; col++) {
     150          fprintf (stderr, "%10.3e ", A[row][col]);
     151        }
     152        fprintf (stderr, "\n");
     153      }
     154      fprintf (stderr, "\n");
     155# endif
    146156      goto escape;
    147157    }
  • trunk/Ohana/src/libohana/src/glockfile.c

    r37807 r38553  
    152152    path = pathname (filename);
    153153    file = filebasename (filename);
    154     ALLOCATE (lockname, char, strlen (path) + strlen (file) + 10);
    155     sprintf (lockname, "%s/.%s.lck", path, file);
     154    int Nchar = strlen (path) + strlen (file) + 16;
     155    ALLOCATE (lockname, char, Nchar);
     156    snprintf (lockname, Nchar, "%s/.%s.lck", path, file);
    156157
    157158    status = stat (lockname, &filestat);
     
    261262    path = pathname (filename);
    262263    file = filebasename (filename);
    263     ALLOCATE (lockname, char, strlen (path) + strlen (file) + 10);
    264     sprintf (lockname, "%s/.%s.lck", path, file);
     264    int Nchar = strlen (path) + strlen (file) + 16;
     265    ALLOCATE (lockname, char, Nchar);
     266    snprintf (lockname, Nchar, "%s/.%s.lck", path, file);
    265267   
    266268    /* check for lockfile existance */
  • trunk/Ohana/src/libohana/src/ohana_allocate.c

    r38441 r38553  
    44# include <stdint.h>
    55# include <pthread.h>
     6# include <string.h>
     7
     8# define TEST_SAVE_FREE_BLOCKS 0
     9# define TEST_SAVE_DROP_BLOCKS 0
    610
    711# undef OHANA_MEMORY
     
    1317# define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
    1418
    15 # define OHANA_MEMMAGIC (uint32_t) 0xdeadbeef
    16 
    17 typedef struct Memblock {
    18   uint32_t startblock;        // endpost marker
    19   struct Memblock *prevBlock; // previously allocated memory
    20   struct Memblock *nextBlock; // next allocated memory
    21   size_t size;                // size of memory
    22   const char *file;           // file (re)allocated
    23   const char *func;           // func (re)allocated
    24   int line;                   // line (re)allocated
    25   uint32_t endblock;          // endpost marker
    26 } Memblock;
    27 
    28 static Memblock *lastBlock = NULL;
     19static OhanaMemblock *lastBlock = NULL;
     20
     21# if (TEST_SAVE_FREE_BLOCKS)
     22static OhanaMemblock *freeBlock = NULL;
     23# endif
     24
     25# if (TEST_SAVE_DROP_BLOCKS)
     26static OhanaMemblock *dropBlock = NULL;
     27# endif
    2928
    3029static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     
    4645
    4746  void *ptr;                  // actual user memory allocated
    48   Memblock *new;              // new memblock created to track the user memory
     47  OhanaMemblock *new;         // new memblock created to track the user memory
    4948  size_t size;                // total number of bytes requested (not items)
    5049
     
    5352
    5453  // total size is : memblock + data + endpost
    55   new = (Memblock *) malloc (sizeof(Memblock) + size + sizeof(void *));
     54  new = (OhanaMemblock *) malloc (sizeof(OhanaMemblock) + size + sizeof(void *));
    5655  if (new == NULL) ohana_memabort ("failed to allocate memory (%s, %d, %s)\n", file, line, func);
    5756
     
    6968  new->line = line;
    7069  new->func = func;
     70  new->freed = FALSE;
     71
     72  // to be clean, zero out the memory
     73  // memset (ptr, 0, new->size);
    7174
    7275  // new memblock becomes the 'lastBlock':
     
    99102void *ohana_realloc (const char *file, int line, const char *func, void *in, size_t Nelem, size_t esize) {
    100103
    101   void *ptr;                  // actual user memory allocated
    102   Memblock *old;              // original memblock associated with user memory
    103   Memblock *new;              // new memblock associated with user memory
     104  OhanaMemblock *old;         // original memblock associated with user memory
     105  OhanaMemblock *new;         // new memblock associated with user memory
    104106  size_t size;
    105107
    106108  // just allocate if not previously allocated
    107109  if (!in) {
    108     ptr = ohana_malloc (file, line, func, Nelem, esize);
     110    void *ptr = ohana_malloc (file, line, func, Nelem, esize);
    109111    return ptr;
    110112  }
    111113
    112114  // memblock of supplied pointer
    113   old = (Memblock *) in - 1;
     115  old = (OhanaMemblock *) in - 1;
    114116
    115117  if (old->startblock != OHANA_MEMMAGIC) ohana_memabort ("corrupt memory (%s, %d, %s)\n", file, line, func);
     
    126128  pthread_mutex_lock(&memBlockListMutex);
    127129
    128   Memblock *nextBlock = old->nextBlock;
    129   Memblock *prevBlock = old->prevBlock;
     130  OhanaMemblock *nextBlock = old->nextBlock;
     131  OhanaMemblock *prevBlock = old->prevBlock;
    130132
    131133  int isLast = (old == lastBlock);
    132134
     135  // ask for new memory
     136
     137# if (TEST_SAVE_DROP_BLOCKS)
     138  // XXX for a test, we are going to always alloc a new block, copy the old data to the new block
     139  // poison the old block, then free it
     140  new = (OhanaMemblock *) malloc (sizeof(OhanaMemblock) + size + sizeof(void *));
     141  if (new == NULL) ohana_memabort ("failed to reallocate memory (%s, %d, %s)\n", file, line, func);
     142  void *ptr_new = (char *) (new + 1);
     143  void *ptr_old = (char *) (old + 1);
     144  size_t copy_bytes = old->size < size ? old->size : size;
     145  memcpy (ptr_new, ptr_old, copy_bytes);
     146  memset (ptr_old, 0x7f, old->size);
     147  new->nextBlock = old->nextBlock;
     148  new->prevBlock = old->prevBlock;
     149# else
    133150  // ask for new memory
    134151  // total size is : memblock + data + endpost
    135   new = (Memblock *) realloc (old, sizeof(Memblock) + size + sizeof(void *));
     152  new = (OhanaMemblock *) realloc (old, sizeof(OhanaMemblock) + size + sizeof(void *));
    136153  if (new == NULL) ohana_memabort ("failed to reallocate memory (%s, %d, %s)\n", file, line, func);
    137   ptr = (char *) (new + 1);
    138  
    139   // give the realloc location:
     154  void *ptr_new = (char *) (new + 1);
     155# endif
     156 
     157  // set the end-post values
     158  new->startblock = OHANA_MEMMAGIC;
     159  new->endblock = OHANA_MEMMAGIC;
     160  *(uint32_t *)(ptr_new + size) = OHANA_MEMMAGIC;
     161
     162  // set the memory metadata
    140163  new->size = size;
    141164  new->file = file;
    142165  new->line = line;
    143166  new->func = func;
     167  new->freed = FALSE;
    144168
    145169  // update the endpost (the others were set originally
    146   *(uint32_t *)(ptr + size) = OHANA_MEMMAGIC;
     170  *(uint32_t *)(ptr_new + size) = OHANA_MEMMAGIC;
    147171
    148172  // need to reset lastBlock in case we moved
     
    159183  }
    160184 
     185  // XXX FOR TESTING, save the realloc blocks
     186# if (TEST_SAVE_DROP_BLOCKS)
     187  if (dropBlock) {
     188    dropBlock->nextBlock = old;
     189  }
     190  old->nextBlock = NULL;
     191  old->prevBlock = dropBlock;
     192  dropBlock = old;
     193# endif
     194
    161195  pthread_mutex_unlock(&memBlockListMutex);
    162196
    163   return (ptr);
     197  return (ptr_new);
    164198}
    165199
     
    174208void ohana_free (const char *file, int line, const char *func, void *in) {
    175209
    176   Memblock *ref;
     210  OhanaMemblock *ref;
    177211
    178212  if (!in) return;
     
    180214  // fprintf (stderr, "free %zx\n", (size_t) in);
    181215
    182   ref = (Memblock *) in - 1;
     216  ref = (OhanaMemblock *) in - 1;
     217
     218  if (ref->freed) ohana_memabort ("memory already freed (%s, %d, %s [%d bytes])\n", ref->file, ref->line, ref->func, ref->size);
     219  ref->freed = TRUE;
    183220
    184221  // fprintf (stderr, "  file: %s, line: %d, func: %s, size: %zd, addr: %zx\n",
     
    187224  pthread_mutex_lock(&memBlockListMutex);
    188225 
    189   Memblock *nextBlock = ref->nextBlock;
    190   Memblock *prevBlock = ref->prevBlock;
    191 
     226  OhanaMemblock *nextBlock = ref->nextBlock;
     227  OhanaMemblock *prevBlock = ref->prevBlock;
     228
     229  // remove this memBlock from the list
    192230  if (nextBlock) {
    193231    nextBlock->prevBlock = prevBlock;
     
    200238  }
    201239 
     240  // XXX FOR TESTING, save the freed blocks
     241# if (TEST_SAVE_FREE_BLOCKS)
     242  if (freeBlock) {
     243    freeBlock->nextBlock = ref;
     244  }
     245  ref->nextBlock = NULL;
     246  ref->prevBlock = freeBlock;
     247  freeBlock = ref;
     248# endif
     249
     250  // pointer to the start of the user memory
     251  void *ptr = (char *)(ref + 1);
     252  memset (ptr, 0x77, ref->size);
     253
    202254  pthread_mutex_unlock(&memBlockListMutex);
    203255 
     256# if (!TEST_SAVE_FREE_BLOCKS)
    204257  free (ref);
     258# endif
    205259
    206260  return;
     261}
     262
     263int ohana_memcheck_noop (int allmemory) {
     264  return TRUE;
    207265}
    208266
     
    211269  if (!lastBlock) {
    212270    fprintf (stderr, "no memory allocated\n");
    213     return TRUE;
    214   }
    215 
    216   Memblock *thisBlock = lastBlock;
     271  }
     272
     273  OhanaMemblock *thisBlock = lastBlock;
    217274
    218275  size_t Ngood  = 0;
     
    220277  size_t Ntotal = 0;
    221278  size_t Nbytes = 0;
     279  int status = TRUE;
    222280
    223281  while (thisBlock) {
     
    250308    thisBlock = thisBlock->prevBlock;
    251309  }
     310  fprintf (stderr, "%zd memory blocks allocated (%zd bytes total), %zd good, %zd bad\n", Ntotal, Nbytes, Ngood, Nbad);
     311  if (Nbad) status = FALSE;
     312
     313# if (TEST_SAVE_FREE_BLOCKS)
    252314 
    253   fprintf (stderr, "%zd memory blocks allocated (%zd bytes total), %zd good, %zd bad\n", Ntotal, Nbytes, Ngood, Nbad);
    254 
    255   if (Nbad) return FALSE;
    256   return TRUE;
     315  thisBlock = freeBlock;
     316
     317  size_t Ngood_free  = 0;
     318  size_t Nbad_free   = 0;
     319  size_t Ntotal_free = 0;
     320  size_t Nbytes_free = 0;
     321
     322  while (thisBlock) {
     323
     324    int i;
     325    int good = TRUE;
     326   
     327    if (thisBlock->startblock != OHANA_MEMMAGIC) good = FALSE;
     328    if (thisBlock->endblock != OHANA_MEMMAGIC) good = FALSE;
     329
     330    // pointer to the end of the user memory
     331    char *ptr = (char *)(thisBlock + 1) + thisBlock->size;
     332    uint32_t endpost = *(uint32_t *)ptr;
     333    if (endpost != OHANA_MEMMAGIC) good = FALSE;
     334
     335    // pointer to the start of the user memory
     336    ptr = (char *)(thisBlock + 1);
     337    for (i = 0; i < thisBlock->size; i++, ptr++) {
     338      if (*ptr != 0x77) good = FALSE;
     339    }
     340
     341    // XXX keep checking even if memory is corrupted?
     342    if (!good) {
     343      if (Nbad_free < 1) {
     344        fprintf (stderr, "memory corruption\n");
     345      }
     346      if (Nbad_free < 100) {
     347        fprintf (stderr, "  file: %s, line: %d, func: %s\n", thisBlock->file, thisBlock->line, thisBlock->func);
     348      }
     349      Nbad_free ++;
     350    } else {
     351      Ngood_free ++;
     352    }
     353    Ntotal_free ++;
     354    Nbytes_free += thisBlock->size;
     355
     356    thisBlock = thisBlock->prevBlock;
     357  }
     358  fprintf (stderr, "%zd memory blocks freed     (%zd bytes total), %zd good, %zd bad\n", Ntotal_free, Nbytes_free, Ngood_free, Nbad_free);
     359  if (Nbad_free) status = FALSE;
     360
     361# endif
     362 
     363# if (TEST_SAVE_DROP_BLOCKS)
     364  thisBlock = dropBlock;
     365
     366  size_t Ngood_drop  = 0;
     367  size_t Nbad_drop   = 0;
     368  size_t Ntotal_drop = 0;
     369  size_t Nbytes_drop = 0;
     370
     371  while (thisBlock) {
     372
     373    int i;
     374    int good = TRUE;
     375   
     376    if (thisBlock->startblock != OHANA_MEMMAGIC) good = FALSE;
     377    if (thisBlock->endblock != OHANA_MEMMAGIC) good = FALSE;
     378
     379    // pointer to the end of the user memory
     380    char *ptr = (char *)(thisBlock + 1) + thisBlock->size;
     381    uint32_t endpost = *(uint32_t *)ptr;
     382    if (endpost != OHANA_MEMMAGIC) good = FALSE;
     383
     384    // pointer to the start of the user memory
     385    ptr = (char *)(thisBlock + 1);
     386    for (i = 0; i < thisBlock->size; i++, ptr++) {
     387      if (*ptr != 0x7f) good = FALSE;
     388    }
     389
     390    // XXX keep checking even if memory is corrupted?
     391    if (!good) {
     392      if (Nbad_drop < 1) {
     393        fprintf (stderr, "memory corruption\n");
     394      }
     395      if (Nbad_drop < 100) {
     396        fprintf (stderr, "  file: %s, line: %d, func: %s\n", thisBlock->file, thisBlock->line, thisBlock->func);
     397      }
     398      Nbad_drop ++;
     399    } else {
     400      Ngood_drop ++;
     401    }
     402    Ntotal_drop ++;
     403    Nbytes_drop += thisBlock->size;
     404
     405    thisBlock = thisBlock->prevBlock;
     406  }
     407  fprintf (stderr, "%zd memory blocks dropped   (%zd bytes total), %zd good, %zd bad\n", Ntotal_drop, Nbytes_drop, Ngood_drop, Nbad_drop);
     408  if (Nbad_drop) status = FALSE;
     409# endif
     410 
     411  return status;
    257412}
    258413
     
    264419  }
    265420
    266   Memblock *thisBlock = lastBlock;
     421  OhanaMemblock *thisBlock = lastBlock;
    267422
    268423  size_t Ntotal = 0;
     
    312467  memstats.Nbad = 0;
    313468 
    314   Memblock *thisBlock = lastBlock;
     469  OhanaMemblock *thisBlock = lastBlock;
    315470
    316471  while (thisBlock) {
  • trunk/Ohana/src/libohana/src/time.c

    r34088 r38553  
    141141      ALLOCATE (tmpline, char, 64);
    142142      gmt   = gmtime (&tsec);
    143       sprintf (tmpline, "%04d/%02d/%02d,%s", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, &line[6]);
     143      snprintf (tmpline, 64, "%04d/%02d/%02d,%s", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, &line[6]);
    144144      *second = ohana_date_to_sec (tmpline);
    145145      free (tmpline);
     
    251251  ALLOCATE (line, char, 64);
    252252  gmt   = gmtime (&second);
    253   sprintf (line, "%04d/%02d/%02d,%02d:%02d:%02d", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     253  snprintf (line, 64, "%04d/%02d/%02d,%02d:%02d:%02d", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
    254254  return (line);
    255255
  • trunk/Ohana/src/opihi/cmd.astro/radec.c

    r18718 r38553  
    4545
    4646  // convert to hms, dms
    47   hms_format (ra_string, ra/15.0);
    48   hms_format (dec_string, dec);
     47  hms_format (ra_string, 32, ra/15.0);
     48  hms_format (dec_string, 32, dec);
    4949
    5050  set_str_variable ("RA", ra_string);
  • trunk/Ohana/src/opihi/cmd.astro/sexigesimal.c

    r14590 r38553  
    3535  } else {
    3636    value = atof (argv[1]);
    37     hms_format (string, value);
     37    hms_format (string, 80, value);
    3838    if (argc == 3) {
    3939      set_str_variable (argv[2], string);
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r38441 r38553  
    7777  if ((argc < 3) || !(argc % 2)) {
    7878    gprint (GP_ERR, "USAGE: read name N name N ...\n");
     79    gprint (GP_ERR, "  options:\n");
     80    gprint (GP_ERR, "     -fits EXTNAME : read a fits file from the given extension (vector names are column names)\n");
     81    gprint (GP_ERR, "     -v : verbose mode\n");
     82    gprint (GP_ERR, "     -csv : comma-separated values (columns may be identified in excel-style: A, AC\n");
     83    gprint (GP_ERR, "     -skip N : skip N lines before reading\n");
     84    gprint (GP_ERR, "     column names may include a type: name:type\n");
     85    gprint (GP_ERR, "       type is int, float, char, time\n");
     86    gprint (GP_ERR, "       for char, values are placed into a list $name:0 - $name:n\n");
     87    gprint (GP_ERR, "       for time, values are human-readable date/time strings YYYY/MM/DD,hh:mm:ss\n");
     88    gprint (GP_ERR, "       the resulting vector is a float based on the TIMEFORMAT, TIMEREF values\n");
    7989    return (FALSE);
    8090  }
  • trunk/Ohana/src/opihi/dimm/telescope_cmds.c

    r23530 r38553  
    8787    set_variable ("RA", ra);
    8888    set_variable ("DEC", dec);
    89     dms_format (line, (ra/15.0));
     89    dms_format (line, 64, (ra/15.0));
    9090    set_str_variable ("Rs", line);
    91     dms_format (line, dec);
     91    dms_format (line, 64, dec);
    9292    set_str_variable ("Ds", line);
    9393
  • trunk/Ohana/src/opihi/lib.shell/stack_math.c

    r38441 r38553  
    3232
    3333  switch (op[0]) {
    34   case '?': SSS_FUNC(M1 ? M2: M3);
    35   default:
    36     snprintf (line, 512, "error: op %c not defined!", op[0]);
    37     push_error (line);
    38     return (FALSE);
    39 }
     34    case '?': SSS_FUNC(M1 ? M2: M3);
     35    default:
     36      snprintf (line, 512, "error: op %c not defined!", op[0]);
     37      push_error (line);
     38      return (FALSE);
     39  }
    4040# undef SSS_FUNC
    4141
     
    447447
    448448  switch (op[0]) {
    449   case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
    450   case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
    451   case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
    452   case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
    453   case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
    454   case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
    455   case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
    456   case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
    457   case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
    458   case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
    459   case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
    460   case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
    461   case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
    462   case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
    463   case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
    464   case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
    465   case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
    466   case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
    467   case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
    468   case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
    469   default:
    470     snprintf (line, 512, "error: op %c not defined!", op[0]);
    471     push_error (line);
    472     return (FALSE);
    473 }
     449    case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
     450    case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
     451    case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
     452    case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
     453    case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
     454    case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
     455    case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     456    case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     457    case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
     458    case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
     459    case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
     460    case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
     461    case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
     462    case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
     463    case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
     464    case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
     465    case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
     466    case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
     467    case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
     468    case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
     469    default:
     470      snprintf (line, 512, "error: op %c not defined!", op[0]);
     471      push_error (line);
     472      return (FALSE);
     473  }
    474474# undef SV_FUNC
    475475
    476476  /** free up any temporary buffers: **/
    477477  if (V2[0].type == ST_VECTOR_TMP) {
    478   free (V2[0].vector[0].elements.Ptr);
    479   free (V2[0].vector);
    480 }
     478    free (V2[0].vector[0].elements.Ptr);
     479    free (V2[0].vector);
     480  }
    481481
    482482  clear_stack (V1);
     
    554554
    555555  switch (op[0]) {
    556   case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
    557   case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
    558   case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
    559   case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
    560   case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
    561   case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
    562   case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
    563   case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
    564   case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
    565   case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
    566   case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
    567   case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
    568   case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
    569   case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
    570   case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
    571   case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
    572   case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
    573   case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
    574   case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
    575   case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
    576   default:
    577     snprintf (line, 512, "error: op %c not defined!", op[0]);
    578     push_error (line);
    579     return (FALSE);
    580 }
     556    case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
     557    case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
     558    case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
     559    case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
     560    case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
     561    case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
     562    case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     563    case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     564    case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
     565    case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
     566    case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
     567    case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
     568    case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
     569    case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
     570    case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
     571    case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
     572    case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
     573    case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
     574    case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
     575    case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
     576    default:
     577      snprintf (line, 512, "error: op %c not defined!", op[0]);
     578      push_error (line);
     579      return (FALSE);
     580  }
    581581# undef VS_FUNC
    582582
     
    584584
    585585  if (V1[0].type == ST_VECTOR_TMP) {
    586   free (V1[0].vector[0].elements.Ptr);
    587   free (V1[0].vector);
    588 }
     586    free (V1[0].vector[0].elements.Ptr);
     587    free (V1[0].vector);
     588  }
    589589
    590590  clear_stack (V1);
     
    10611061
    10621062  switch (op[0]) {
    1063   case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
    1064   case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
    1065   case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
    1066   case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
    1067   case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
    1068   case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
    1069   case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
    1070   case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
    1071   case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
    1072   case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
    1073   case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
    1074   case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
    1075   case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
    1076   case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
    1077   case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
    1078   case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
    1079   case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
    1080   case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
    1081   case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
    1082   case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
    1083   default:
    1084     snprintf (line, 512, "error: op %c not defined!", op[0]);
    1085     push_error (line);
    1086     return (FALSE);
    1087 }
     1063    case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
     1064    case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
     1065    case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
     1066    case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
     1067    case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
     1068    case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
     1069    case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1070    case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1071    case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
     1072    case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
     1073    case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
     1074    case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
     1075    case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
     1076    case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
     1077    case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
     1078    case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
     1079    case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
     1080    case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
     1081    case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
     1082    case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
     1083    default:
     1084      snprintf (line, 512, "error: op %c not defined!", op[0]);
     1085      push_error (line);
     1086      return (FALSE);
     1087  }
    10881088# undef SS_FUNC
    10891089
     
    11331133    case 'E':
    11341134      value = strcmp (V1[0].name, V2[0].name) ? 0 : 1;
    1135     break;
     1135      break;
    11361136    case 'N':
    11371137      value = strcmp (V1[0].name, V2[0].name) ? 1 : 0;
    1138     break;
     1138      break;
    11391139    default:
    11401140      snprintf (line, 512, "error: op %c not defined for string operations!", op[0]);
  • trunk/Ohana/src/relastro/src/BrightCatalog.c

    r38441 r38553  
    349349  /*** MeasureTiny ***/
    350350  {
    351     ohana_memcheck_func (1);
     351    ohana_memcheck (1);
    352352    gfits_create_table_header (&theader, "BINTABLE", "MEASURE_TINY");
    353353
    354     ohana_memcheck_func (1);
     354    ohana_memcheck (1);
    355355    gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degrees", 1.0, 0.0);
    356356    gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degrees", 1.0, 0.0);
     
    375375
    376376    // generate the output array that carries the data
    377     ohana_memcheck_func (1);
     377    ohana_memcheck (1);
    378378    gfits_create_table (&theader, &ftable);
    379     ohana_memcheck_func (1);
     379    ohana_memcheck (1);
    380380
    381381    // create intermediate storage arrays
     
    400400    int    *catID     ; ALLOCATE (catID    ,  int  ,  catalog->Nmeasure);
    401401    short  *photcode  ; ALLOCATE (photcode ,  short,  catalog->Nmeasure);
    402     ohana_memcheck_func (1);
     402    ohana_memcheck (1);
    403403
    404404    // assign the storage arrays
     
    426426      photcode[i] = measure[i].photcode ;
    427427    }
    428     ohana_memcheck_func (1);
     428    ohana_memcheck (1);
    429429
    430430    // add the columns to the output array
    431431    gfits_set_bintable_column (&theader, &ftable, "RA",         R,         catalog->Nmeasure);
    432     ohana_memcheck_func (1);
     432    ohana_memcheck (1);
    433433    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
    434     ohana_memcheck_func (1);
     434    ohana_memcheck (1);
    435435    gfits_set_bintable_column (&theader, &ftable, "ROFF_GAL",   RoffGAL,   catalog->Nmeasure);
    436436    gfits_set_bintable_column (&theader, &ftable, "DOFF_GAL",   DoffGAL,   catalog->Nmeasure);
  • trunk/Ohana/src/relastro/src/FrameCorrectionUtils.c

    r37807 r38553  
    6262    ALLOCATE (frame->Roff[i], double, frame->Nra[i]);
    6363    ALLOCATE (frame->Doff[i], double, frame->Nra[i]);
    64     // ohana_memcheck_func (TRUE);
     64    // ohana_memcheck (TRUE);
    6565    // fprintf (stderr, "alloc : %d : %lx %lx\n", i, (long unsigned int)(size_t *) frame->Roff[i], (long unsigned int) (size_t *) frame->Doff[i]);
    6666  }
Note: See TracChangeset for help on using the changeset viewer.