IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38441


Ignore:
Timestamp:
Jun 12, 2015, 6:18:23 PM (11 years ago)
Author:
eugene
Message:

merge changes from EAM dev branch ohana.20150429

Location:
trunk/Ohana
Files:
326 edited
14 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/Makefile.Common

    r16093 r38441  
    99BASE_CPPFLAGS = $(CPPFLAGS) -I$(INC) -I$(DESTINC) $(INCDIRS) -D$(ARCH)
    1010BASE_LDFLAGS  = $(LDFLAGS) -L$(LIB) -L$(DESTLIB) $(LIBDIRS) $(LIBFLAGS)
     11
     12FULL_CFLAGS   = $(BASE_CFLAGS)
     13FULL_CPPFLAGS = $(BASE_CPPFLAGS)
     14FULL_LDFLAGS  = $(BASE_LDFLAGS)
     15
     16TEST_CFLAGS   = $(BASE_CFLAGS)
     17TEST_CPPFLAGS = $(BASE_CPPFLAGS)
     18TEST_LDFLAGS  = $(BASE_LDFLAGS)
     19
     20TESTHARNESS   = $(ROOT)/src/libtap/tapcheck.pl
    1121
    1222DVO_LIBS  = $(DESTLIB)/libdvo.a $(DESTLIB)/libFITS.a $(DESTLIB)/libohana.a
     
    3444        $(CC) $(FULL_CFLAGS) -o $@ $^ $(FULL_LDFLAGS)
    3545        @echo "compiled $*"
     46        @echo ""
     47
     48$(TESTDIR)/%.$(ARCH): $(TESTDIR)/%.c
     49        @echo $@
     50        @echo $*
     51        @echo $<
     52        @echo $^
     53        @if [ ! -d $(TESTDIR) ]; then mkdir -p $(TESTDIR); fi
     54        $(CC) $(TEST_CFLAGS) -o $@ $^ $(TEST_LDFLAGS)
     55        @echo "compiled $*"
     56        @echo ""
     57
     58$(TESTBIN)/%: $(TESTDIR)/%.$(ARCH)
     59        @if [ ! -d $(TESTBIN) ]; then mkdir -p $(TESTBIN); fi
     60        rm -f $(TESTBIN)/$*
     61        cp $(TESTDIR)/$*.$(ARCH) $(TESTBIN)/$*
     62        @echo "installed $*"
    3663        @echo ""
    3764
     
    103130        rm -f `find . -name "#*"`
    104131
     132test.clean:
     133        for i in $(TESTPROG); do rm -f $(TESTBIN)/$$i; done
     134        for i in $(TESTPROG); do rm -f $(TESTDIR)/$$i.$(ARCH); done
     135
    105136dist: clean
    106137        rm -rf $(BIN)
  • trunk/Ohana/src/addstar/include/addstar.h

    r37807 r38441  
    8484char   GSCFILE[256];
    8585char  *CATDIR;
    86 char   CATMODE[16];    /* raw, mef, split, mysql */
    87 char   CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
     86char   CATMODE[16];     /* raw, mef, split, mysql */
     87char   CATFORMAT[16];   /* internal, elixir, loneos, panstarrs */
     88char   CATCOMPRESS[16]; /* GZIP_1, NONE */
    8889char   TWO_MASS_DIR_AS[256];
    8990char   TWO_MASS_DIR_DR2[256];
     
    326327void *memrchr(const void *s, int c, size_t n);
    327328int addstar_create_ID ();
    328 int strextend (char *input, char *format,...);
    329329
    330330void initMosaicCoords ();
  • trunk/Ohana/src/addstar/src/ConfigInit.c

    r33963 r38441  
    134134  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
    135135  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
     136  if (!ScanConfig (config, "CATCOMPRESS",       "%s",  0, CATCOMPRESS)) {
     137    strcpy (CATCOMPRESS, "NONE");
     138  }
    136139  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
    137140    SKY_DEPTH = SKY_DEPTH_HST;
  • trunk/Ohana/src/addstar/src/ReadStarsFITS.c

    r37995 r38441  
    153153  off_t Nstars;
    154154  unsigned int i;
    155   char swapped;
    156155  double ZeroPt;
    157156  Stars *stars = NULL;
    158157  SMPData *smpdata = NULL;
    159158
    160   swapped = FALSE;
    161   smpdata = gfits_table_get_SMPData (table, &Nstars, &swapped);
     159  smpdata = gfits_table_get_SMPData (table, &Nstars, NULL, NULL);
    162160  if (!smpdata) {
    163161    fprintf (stderr, "skipping inconsistent entry\n");
     
    229227  PS1_DEV_0 *ps1data;
    230228
    231   ps1data = gfits_table_get_PS1_DEV_0 (table, &Nstars, NULL);
     229  ps1data = gfits_table_get_PS1_DEV_0 (table, &Nstars, NULL, NULL);
    232230  if (!ps1data) {
    233231    fprintf (stderr, "skipping inconsistent entry\n");
     
    300298  PS1_DEV_1 *ps1data;
    301299
    302   ps1data = gfits_table_get_PS1_DEV_1 (table, &Nstars, NULL);
     300  ps1data = gfits_table_get_PS1_DEV_1 (table, &Nstars, NULL, NULL);
    303301  if (!ps1data) {
    304302    fprintf (stderr, "skipping inconsistent entry\n");
     
    383381  }
    384382
    385   ps1data = gfits_table_get_CMF_PS1_V1 (table, &Nstars, NULL);
     383  ps1data = gfits_table_get_CMF_PS1_V1 (table, &Nstars, NULL, NULL);
    386384  if (!ps1data) {
    387385    fprintf (stderr, "skipping inconsistent entry\n");
     
    545543  CMF_PS1_V2 *ps1data;
    546544
    547   ps1data = gfits_table_get_CMF_PS1_V2 (table, &Nstars, NULL);
     545  ps1data = gfits_table_get_CMF_PS1_V2 (table, &Nstars, NULL, NULL);
    548546  if (!ps1data) {
    549547    fprintf (stderr, "skipping inconsistent entry\n");
     
    622620  CMF_PS1_V3 *ps1data;
    623621
    624   ps1data = gfits_table_get_CMF_PS1_V3 (table, &Nstars, NULL);
     622  ps1data = gfits_table_get_CMF_PS1_V3 (table, &Nstars, NULL, NULL);
    625623  if (!ps1data) {
    626624    fprintf (stderr, "skipping inconsistent entry\n");
     
    706704  CMF_PS1_V4 *ps1data;
    707705
    708   ps1data = gfits_table_get_CMF_PS1_V4 (table, &Nstars, NULL);
     706  ps1data = gfits_table_get_CMF_PS1_V4 (table, &Nstars, NULL, NULL);
    709707  if (!ps1data) {
    710708    fprintf (stderr, "skipping inconsistent entry\n");
     
    12591257  }
    12601258
    1261   ps1data = gfits_table_get_CMF_PS1_SV1 (table, &Nstars, NULL);
     1259  ps1data = gfits_table_get_CMF_PS1_SV1 (table, &Nstars, NULL, NULL);
    12621260  if (!ps1data) {
    12631261    fprintf (stderr, "skipping inconsistent entry\n");
     
    14231421  CMF_PS1_SV2 *ps1data;
    14241422
    1425   ps1data = gfits_table_get_CMF_PS1_SV2 (table, &Nstars, NULL);
     1423  ps1data = gfits_table_get_CMF_PS1_SV2 (table, &Nstars, NULL, NULL);
    14261424  if (!ps1data) {
    14271425    fprintf (stderr, "skipping inconsistent entry\n");
     
    17531751  CMF_PS1_DV4 *ps1data;
    17541752
    1755   ps1data = gfits_table_get_CMF_PS1_DV4 (table, &Nstars, NULL);
     1753  ps1data = gfits_table_get_CMF_PS1_DV4 (table, &Nstars, NULL, NULL);
    17561754  if (!ps1data) {
    17571755    fprintf (stderr, "skipping inconsistent entry\n");
     
    18391837  CMF_PS1_DV5 *ps1data;
    18401838
    1841   ps1data = gfits_table_get_CMF_PS1_DV5 (table, &Nstars, NULL);
     1839  ps1data = gfits_table_get_CMF_PS1_DV5 (table, &Nstars, NULL, NULL);
    18421840  if (!ps1data) {
    18431841    fprintf (stderr, "skipping inconsistent entry\n");
  • trunk/Ohana/src/addstar/src/SEDfit.c

    r37036 r38441  
    198198  outcat[0].Naverage  = Nave;
    199199  outcat[0].Nmeasure  = Nmeas;
    200   outcat[0].Nsecf_mem = Nave*Nsec;
     200  outcat[0].Nsecfilt_mem = Nave*Nsec;
    201201 
    202202  free (sourceValue.mags);
  • trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c

    r37807 r38441  
    1212  }
    1313
    14   catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    15   if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
     14  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     15  if (options[0].update) catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    1616 
    1717  // XXX this is probably not needed anymore
     
    4747    catalog.filename  = skylist[0].filename[i];
    4848    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    49     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    50     if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
     49    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     50    if (options[0].update) catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    5151
    5252    // an error exit status here is a significant error
     
    5656    }
    5757
    58     // Naves_disk == 0 implies an empty catalog file
     58    // Naverage_disk == 0 implies an empty catalog file
    5959    // for only_match, skip empty catalogs
    60     if ((catalog.Naves_disk == 0) && options[0].only_match) {
     60    if ((catalog.Naverage_disk == 0) && options[0].only_match) {
    6161      dvo_catalog_unlock (&catalog);
    6262      dvo_catalog_free (&catalog);
     
    7373      SetProtect (TRUE);
    7474      if (options[0].update) {
    75         catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     75        catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    7676        dvo_catalog_update (&catalog, VERBOSE);
    7777      } else {
     
    9292    /*** update the image table ***/
    9393    /* setup image table format and lock */
     94    gfits_db_init (&db);
    9495    db.mode   = dvo_catalog_catmode (CATMODE);
    9596    db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/addstar/src/UpdateDatabase_Refcat.c

    r15743 r38441  
    3636    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    3737    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    38     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    39     if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
     38    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     39    if (options[0].update) catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4040 
    4141    // an error exit status here is a significant error
     
    4545    }
    4646
    47     // Naves_disk == 0 implies an empty catalog file
     47    // Naverage_disk == 0 implies an empty catalog file
    4848    // for only_match, skip empty catalogs
    49     if ((catalog.Naves_disk == 0) && options[0].only_match) {
     49    if ((catalog.Naverage_disk == 0) && options[0].only_match) {
    5050      dvo_catalog_unlock (&catalog);
    5151      dvo_catalog_free (&catalog);
     
    6363      SetProtect (TRUE);
    6464      if (options[0].update) {
    65         catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     65        catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    6666        dvo_catalog_update (&catalog, VERBOSE);
    6767      } else {
  • trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c

    r27435 r38441  
    3636    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    3737    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    38     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    39     if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
     38    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     39    if (options[0].update) catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4040
    4141    // an error exit status here is a significant error
     
    4646
    4747    /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
    48     if ((catalog.Naves_disk == 0) && options[0].only_match) {
     48    if ((catalog.Naverage_disk == 0) && options[0].only_match) {
    4949      dvo_catalog_unlock (&catalog);
    5050      dvo_catalog_free (&catalog);
     
    5959      SetProtect (TRUE);
    6060      if (options[0].update) {
    61         catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     61        catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    6262        dvo_catalog_update (&catalog, VERBOSE);
    6363      } else {
  • trunk/Ohana/src/addstar/src/UpdateImageIDs.c

    r37357 r38441  
    99  /*** update the image table ***/
    1010  /* setup image table format and lock */
     11  gfits_db_init (&db);
    1112  db.mode   = dvo_catalog_catmode (CATMODE);
    1213  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/addstar/src/addstar.c

    r37807 r38441  
    104104
    105105    // set the parameters which guide catalog open/load/create
    106     catalog.filename  = skylist[0].filename[i];
    107     catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    108     catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    109     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING;
    110     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     106    catalog.filename    = skylist[0].filename[i];
     107    catalog.catmode     = dvo_catalog_catmode (CATMODE);         // set the default catmode from config data
     108    catalog.catformat   = dvo_catalog_catformat (CATFORMAT);     // set the default catformat from config data
     109    catalog.catcompress = dvo_catalog_catcompress (CATCOMPRESS); // set the default catcompress from config data
     110    catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING;
     111    catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
    111112
    112113    // XXX need to do something to enforce consistency.  we can change options.update
     
    117118    if (catalog.catmode != DVO_MODE_SPLIT) options.update = FALSE;
    118119
    119     if (options.update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
     120    if (options.update) catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    120121
    121122    // open as read or write, depending on desire
     
    134135    if (VERBOSE) MARKTIME ("load cpt: %f sec\n", dtime); RESETTIME;
    135136
    136     // Naves_disk == 0 implies an empty catalog file
     137    // Naverage_disk == 0 implies an empty catalog file
    137138    // for only_match, skip empty catalogs
    138     if ((catalog.Naves_disk == 0) && options.only_match) {
     139    if ((catalog.Naverage_disk == 0) && options.only_match) {
    139140      dvo_catalog_unlock (&catalog);
    140141      dvo_catalog_free (&catalog);
     
    174175      SetProtect (TRUE);
    175176      if (options.update) {
    176         catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING;
     177        catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING;
    177178        dvo_catalog_update (&catalog, VERBOSE);
    178179      } else {
     
    193194  /*** update the image table ***/
    194195  /* setup image table format and lock */
     196  gfits_db_init (&db);
    195197  db.mode   = dvo_catalog_catmode (CATMODE);
    196198  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/addstar/src/addstar_create_ID.c

    r35760 r38441  
    1010  /*** update the image table ***/
    1111  /* setup image table format and lock */
    12   // gfits_db_init (&db);
     12  gfits_db_init (&db);
    1313  db.mode   = dvo_catalog_catmode (CATMODE);
    1414  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/addstar/src/args.c

    r37807 r38441  
    480480}
    481481
    482 int strextend (char *input, char *format,...) {
    483 
    484   char tmpextra[1024], tmpline[1024];
    485   va_list argp;
    486 
    487   va_start (argp, format);
    488   vsnprintf (tmpextra, 1024, format, argp);
    489   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    490   strcpy (input, tmpline);
    491 
    492   return TRUE;
    493 }
    494 
    495482/** addstar modes:
    496483 
  • trunk/Ohana/src/addstar/src/args_parallel_client.c

    r37116 r38441  
    125125}
    126126
    127 int strextend (char *input, char *format,...) {
    128 
    129   char tmpextra[1024], tmpline[1024];
    130   va_list argp;
    131 
    132   va_start (argp, format);
    133   vsnprintf (tmpextra, 1024, format, argp);
    134   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    135   strcpy (input, tmpline);
    136 
    137   return TRUE;
    138 }
    139 
  • trunk/Ohana/src/addstar/src/dumpskycells.c

    r33719 r38441  
    4646  /*** open the image table ***/
    4747  /* setup image table format and lock */
     48  gfits_db_init (&db);
    4849  db.mode   = dvo_catalog_catmode (CATMODE);
    4950  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/addstar/src/find_matches.c

    r37807 r38441  
    9191
    9292  /* set up pointers for linked list of measure */
    93   if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) {
     93  if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeasure_disk)) {
    9494    next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
    9595  } else {
     
    320320  catalog[0].Naverage = Nave;
    321321  catalog[0].Nmeasure = Nmeas;
    322   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     322  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    323323  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);
    324324
  • trunk/Ohana/src/addstar/src/find_matches_ICRF.c

    r37807 r38441  
    164164  catalog[0].Naverage  = Nave;
    165165  catalog[0].Nmeasure  = Nmeas;
    166   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     166  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    167167  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d "OFF_T_FMT" "OFF_T_FMT" ("OFF_T_FMT" matches)\n",  Nstars, Nave, Nmeas, Nmatch);
    168168
  • trunk/Ohana/src/addstar/src/find_matches_closest.c

    r37807 r38441  
    9191
    9292  /* set up pointers for linked list of measure */
    93   if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) {
     93  if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeasure_disk)) {
    9494    // this version is only valid if we have done a full catalog load, and if the catalog
    9595    // is sorted while processed
     
    381381  catalog[0].Nmeasure = Nmeas;
    382382  catalog[0].Nlensing = Nlens;
    383   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     383  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    384384  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);
    385385
  • trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c

    r37807 r38441  
    8585
    8686  /* set up pointers for linked list of measure */
    87   if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) {
     87  if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeasure_disk)) {
    8888    // this version is only valid if we have done a full catalog load, and if the catalog
    8989    // is sorted while processed
     
    322322  catalog[0].Naverage = Nave;
    323323  catalog[0].Nmeasure = Nmeas;
    324   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     324  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    325325  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);
    326326
  • trunk/Ohana/src/addstar/src/find_matches_refstars.c

    r37807 r38441  
    7070
    7171  /* set up pointers for linked list of measurements */
    72   if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) {
     72  if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeasure_disk)) {
    7373    // this version is only valid if we have done a full catalog load, and if the catalog
    7474    // is sorted while processed
     
    298298  catalog[0].Naverage = Nave;
    299299  catalog[0].Nmeasure = Nmeas;
    300   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     300  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    301301  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nmatch);
    302302
  • trunk/Ohana/src/addstar/src/find_matches_starpar.c

    r37807 r38441  
    205205  catalog[0].Naverage  = Nave;
    206206  catalog[0].Nstarpar  = Nstarpar;
    207   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     207  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    208208  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nstarpar: %d "OFF_T_FMT" "OFF_T_FMT" ("OFF_T_FMT" matches)\n",  Nstars, Nave, Nstarpar, Nmatch);
    209209
  • trunk/Ohana/src/addstar/src/findskycell.c

    r37116 r38441  
    173173  snprintf (imagefile, DVO_MAX_PATH, "%s/Images.dat", catdir);
    174174
     175  gfits_db_init (&db);
    175176  status = dvo_image_lock (&db, imagefile, 2.0, LCK_XCLD);
    176177  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
     
    183184  // convert database table to internal structure (binary to Image)
    184185  // 'image' points to the same memory as db->ftable->buffer
    185   image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     186  image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    186187  if (!image) {
    187188      fprintf (stderr, "ERROR: failed to read images\n");
     
    557558  snprintf (imagefile, DVO_MAX_PATH, "%s/Images.dat", catdir);
    558559
     560  gfits_db_init (&db);
    559561  status = dvo_image_lock (&db, imagefile, 2.0, LCK_XCLD);
    560562  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
     
    567569  // convert database table to internal structure (binary to Image)
    568570  // 'image' points to the same memory as db->ftable->buffer
    569   image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     571  image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    570572  if (!image) {
    571573    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/addstar/src/load2mass_as_rawdata.c

    r34088 r38441  
    181181        catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    182182        catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    183         catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     183        catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    184184        catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    185185
  • trunk/Ohana/src/addstar/src/load2mass_catalog.c

    r37036 r38441  
    5656  catalog[0].Naverage = Nave;
    5757  catalog[0].Nmeasure = Nmeas;
    58   catalog[0].Nsecf_mem = Nave*Nsec;
     58  catalog[0].Nsecfilt_mem = Nave*Nsec;
    5959  return (TRUE);
    6060}
  • trunk/Ohana/src/addstar/src/loadICRF_catalog.c

    r37807 r38441  
    1010  catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    1111  catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    12   catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
     12  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_MEASURE;
    1313  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    1414   
  • trunk/Ohana/src/addstar/src/loadICRF_save_remote.c

    r37807 r38441  
    22# include "loadICRF.h"
    33# define DEBUG 1
    4 
    5 int strextend (char *input, char *format,...) {
    6 
    7   char tmpextra[1024], tmpline[1024];
    8   va_list argp;
    9 
    10   va_start (argp, format);
    11   vsnprintf (tmpextra, 1024, format, argp);
    12   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    13   strcpy (input, tmpline);
    14 
    15   return TRUE;
    16 }
    174
    185int loadICRF_save_remote (ICRF_Stars *stars, int Nstars, HostTable *hosts, SkyRegion *region, char *fullname, AddstarClientOptions *options) {
     
    6451
    6552    // need to generate the remote command
    66     char command[1024];
    67     snprintf (command, 1024, "loadICRF_client");
    68     strextend (command, "-hostID %d", host->hostID);
    69     strextend (command, "-D CATDIR %s", CATDIR);
    70     strextend (command, "-hostdir %s", host->pathname);
    71     strextend (command, "-cpt %s", region->name);
    72     strextend (command, "-input %s", filename);
    73     strextend (command, "-D ADDSTAR_RADIUS %f", options->radius);
     53    char *command = NULL;
     54    strextend (&command, "loadICRF_client");
     55    strextend (&command, "-hostID %d", host->hostID);
     56    strextend (&command, "-D CATDIR %s", CATDIR);
     57    strextend (&command, "-hostdir %s", host->pathname);
     58    strextend (&command, "-cpt %s", region->name);
     59    strextend (&command, "-input %s", filename);
     60    strextend (&command, "-D ADDSTAR_RADIUS %f", options->radius);
    7461
    7562    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/addstar/src/loadICRF_table.c

    r37807 r38441  
    11# include "addstar.h"
    22# include "loadICRF.h"
    3 
    4 # define GET_COLUMN(OUT,NAME,TYPE) \
    5   TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
    6   myAssert (!strcmp(type, #TYPE), "wrong column type");
    73
    84int loadICRF_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options) {
  • trunk/Ohana/src/addstar/src/loadstarpar_catalog.c

    r37807 r38441  
    1010  catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    1111  catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    12   catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_STARPAR;
     12  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_STARPAR;
    1313  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    1414   
  • trunk/Ohana/src/addstar/src/loadstarpar_save_remote.c

    r37807 r38441  
    22# include "loadstarpar.h"
    33# define DEBUG 1
    4 
    5 int strextend (char *input, char *format,...) {
    6 
    7   char tmpextra[1024], tmpline[1024];
    8   va_list argp;
    9 
    10   va_start (argp, format);
    11   vsnprintf (tmpextra, 1024, format, argp);
    12   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    13   strcpy (input, tmpline);
    14 
    15   return TRUE;
    16 }
    174
    185int loadstarpar_save_remote (StarPar_Stars *stars, int Nstars, HostTable *hosts, SkyRegion *region, char *fullname, AddstarClientOptions *options) {
     
    6249
    6350    // need to generate the remote command
    64     char command[1024];
    65     snprintf (command, 1024, "loadstarpar_client");
    66     strextend (command, "-hostID %d", host->hostID);
    67     strextend (command, "-D CATDIR %s", CATDIR);
    68     strextend (command, "-hostdir %s", host->pathname);
    69     strextend (command, "-cpt %s", region->name);
    70     strextend (command, "-input %s", filename);
     51    char *command = NULL;
     52    strextend (&command, "loadstarpar_client");
     53    strextend (&command, "-hostID %d", host->hostID);
     54    strextend (&command, "-D CATDIR %s", CATDIR);
     55    strextend (&command, "-hostdir %s", host->pathname);
     56    strextend (&command, "-cpt %s", region->name);
     57    strextend (&command, "-input %s", filename);
    7158
    7259    // launch the job on the remote machine (no handshake)
     
    7865    }
    7966    host->pid = pid; // save for future reference
     67    free (command);
    8068   
    8169    save_remote_host (host);
  • trunk/Ohana/src/addstar/src/loadstarpar_table.c

    r37807 r38441  
    11# include "addstar.h"
    22# include "loadstarpar.h"
    3 
    4 # define GET_COLUMN(OUT,NAME,TYPE) \
    5   TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
    6   myAssert (!strcmp(type, #TYPE), "wrong column type");
    73
    84int loadstarpar_table (SkyList *skylistInput, HostTable *hosts, char *filename, AddstarClientOptions *options) {
  • trunk/Ohana/src/addstar/src/loadsupercos.c

    r33653 r38441  
    4747
    4848  // attempt to open the existing images table.  if it does not exist, we will save the loaded images
     49  gfits_db_init (&db);
    4950  db.mode   = dvo_catalog_catmode (CATMODE);
    5051  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/addstar/src/loadsupercos_rawdata.c

    r33653 r38441  
    168168        catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    169169        catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    170         catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     170        catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    171171        catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    172172
  • trunk/Ohana/src/addstar/src/loadwise_prelim_rawdata.c

    r33653 r38441  
    186186        catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    187187        catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    188         catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     188        catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    189189        catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    190190
  • trunk/Ohana/src/addstar/src/loadwise_rawdata.c

    r38062 r38441  
    198198        catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    199199        catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    200         catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     200        catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    201201        catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    202202
  • trunk/Ohana/src/addstar/src/mkcmf.c

    r37995 r38441  
    500500  }
    501501
    502   gfits_table_set_PS1_DEV_0 (ftable, stars, Nstars);
     502  gfits_table_set_PS1_DEV_0 (ftable, stars, Nstars, TRUE);
    503503  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_DEV_0");
    504504}
     
    547547  }
    548548
    549   gfits_table_set_PS1_DEV_1 (ftable, stars, Nstars);
     549  gfits_table_set_PS1_DEV_1 (ftable, stars, Nstars, TRUE);
    550550  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_DEV_1");
    551551}
     
    596596  }
    597597
    598   gfits_table_set_CMF_PS1_V1 (ftable, stars, Nstars);
     598  gfits_table_set_CMF_PS1_V1 (ftable, stars, Nstars, TRUE);
    599599  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V1");
    600600}
     
    651651  }
    652652
    653   gfits_table_set_CMF_PS1_V2 (ftable, stars, Nstars);
     653  gfits_table_set_CMF_PS1_V2 (ftable, stars, Nstars, TRUE);
    654654  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V2");
    655655}
     
    710710  }
    711711
    712   gfits_table_set_CMF_PS1_V3 (ftable, stars, Nstars);
     712  gfits_table_set_CMF_PS1_V3 (ftable, stars, Nstars, TRUE);
    713713  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V3");
    714714}
     
    778778  }
    779779
    780   gfits_table_set_CMF_PS1_V4 (ftable, stars, Nstars);
     780  gfits_table_set_CMF_PS1_V4 (ftable, stars, Nstars, TRUE);
    781781  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V4");
    782782}
  • trunk/Ohana/src/addstar/src/resort_catalogs.c

    r37116 r38441  
    7474    table->hosts[i].pathname = tmppath;
    7575
    76     char command[1024];
    77     snprintf (command, 1024, "addstar_client -resort");
    78     strextend (command, "-D CATDIR %s", CATDIR);
    79     strextend (command, "-hostID %d", table->hosts[i].hostID);
    80     strextend (command, "-hostdir %s", table->hosts[i].pathname);
    81     strextend (command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
     76    char *command = NULL;
     77    strextend (&command, "addstar_client -resort");
     78    strextend (&command, "-D CATDIR %s", CATDIR);
     79    strextend (&command, "-hostID %d", table->hosts[i].hostID);
     80    strextend (&command, "-hostdir %s", table->hosts[i].pathname);
     81    strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    8282
    83     if (VERBOSE)                   strextend (command, "%s -v");
    84     if (NTHREADS)                  strextend (command, "%s -threads %d", NTHREADS);
    85     if (OLD_RESORT)                strextend (command, "%s -old-resort");
    86     if (options->nosort == 3)      strextend (command, "%s -force-sort");
    87     if (options->existing_regions) strextend (command, "%s -existing-regions");
     83    if (VERBOSE)                   strextend (&command, "-v");
     84    if (NTHREADS)                  strextend (&command, "-threads %d", NTHREADS);
     85    if (OLD_RESORT)                strextend (&command, "-old-resort");
     86    if (options->nosort == 3)      strextend (&command, "-force-sort");
     87    if (options->existing_regions) strextend (&command, "-existing-regions");
    8888
    8989    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/addstar/src/resort_threaded.c

    r37116 r38441  
    4343
    4444    // set the parameters which guide catalog open/load/create
    45     catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    46     catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    47     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
    48     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     45    catalog.catformat   = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     46    catalog.catmode     = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     47    catalog.catcompress = dvo_catalog_catcompress (CATCOMPRESS); // set the default catcompress from config data
     48    catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_LENSING;
     49    catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
    4950 
    5051    // an error exit status here is a significant error (disk I/O or file access)
     
    5758    }
    5859
    59     // Naves_disk == 0 implies an empty catalog file, skip empty catalogs
    60     if (catalog.Naves_disk == 0) {
     60    // Naverage_disk == 0 implies an empty catalog file, skip empty catalogs
     61    if (catalog.Naverage_disk == 0) {
    6162      dvo_catalog_unlock (&catalog);
    6263      dvo_catalog_free (&catalog);
  • trunk/Ohana/src/addstar/src/resort_unthreaded.c

    r37116 r38441  
    2121
    2222    // set the parameters which guide catalog open/load/create
    23     catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    24     catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    25     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING;
    26     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     23    catalog.catformat   = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     24    catalog.catmode     = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     25    catalog.catcompress = dvo_catalog_catcompress (CATCOMPRESS); // set the default catcompress from config data
     26    catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_LENSING;
     27    catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
    2728
    2829    // an error exit status here is a significant error (disk I/O or file access)
     
    3233    }
    3334
    34     // Naves_disk == 0 implies an empty catalog file, skip empty catalogs
    35     if (catalog.Naves_disk == 0) {
     35    // Naverage_disk == 0 implies an empty catalog file, skip empty catalogs
     36    if (catalog.Naverage_disk == 0) {
    3637      dvo_catalog_unlock (&catalog);
    3738      dvo_catalog_free (&catalog);
  • trunk/Ohana/src/addstar/src/sedstar.c

    r25757 r38441  
    2626  for (i = 0; i < skylist[0].Nregions; i++) {
    2727    incatalog.filename = skylist[0].filename[i];
    28     incatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     28    incatalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    2929
    3030    // an error exit status here is a significant error
     
    3434    }
    3535
    36     // Naves_disk == 0 implies an empty catalog file
    37     if ((incatalog.Naves_disk == 0) && options.only_match) {
     36    // Naverage_disk == 0 implies an empty catalog file
     37    if ((incatalog.Naverage_disk == 0) && options.only_match) {
    3838      if (VERBOSE) fprintf (stderr, "skipping empty region\n");
    3939      dvo_catalog_unlock (&incatalog);
     
    5454    outcatalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    5555    outcatalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    56     outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     56    outcatalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    5757
    5858    // an error exit status here is a significant error
  • trunk/Ohana/src/addstar/src/skycells.c

    r21048 r38441  
    1212  /*** update the image table ***/
    1313  /* setup image table format and lock */
     14  gfits_db_init (&db);
    1415  db.mode   = dvo_catalog_catmode (CATMODE);
    1516  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/addstar/src/skycells_to_mdc.c

    r33720 r38441  
    55    // Convert FITS_DB to images structure
    66    off_t NdbImages;
    7     Image *dbImages = gfits_table_get_Image(&db->ftable, &NdbImages, &db->swapped);
     7    Image *dbImages = gfits_table_get_Image(&db->ftable, &NdbImages, &db->scaledValue, &db->nativeOrder);
    88
    99    // If tess_id was not supplied assume that it is the basename of the CATDIR
  • trunk/Ohana/src/addstar/test

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

    r35760 r38441  
    11# -*-sh-*-
     2if (not($?VERBOSE)) set VERBOSE = 0
    23
    34input tap.dvo
     
    4142  end
    4243
    43   echo relphot -D CATDIR catdir.test r -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update -nloop 10.0
    44   exec relphot -D CATDIR catdir.test r -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update -nloop 10.0 >& /dev/null
     44  $output = >& /dev/null
     45  if ($VERBOSE > 2)
     46    $output =
     47  end
     48  $command = relphot -D CATDIR catdir.test -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update -nloop 10.0 -images r
     49  echo $command
     50  exec $command $output
    4551
    4652  catdir catdir.test
  • trunk/Ohana/src/addstar/test/relphot.flatcorr.dvo

    r33653 r38441  
    1414# * no other mechanism to tell DVO about a flat-field correction
    1515
     16$TAP_BREAK = 1
     17$TAP_VERBOSE = 1
    1618input tap.dvo
    1719
    1820# set globals
    19 if (not($?PLOT)) set PLOT = 0
     21if (not($?PLOT)) set PLOT = 0
     22
     23$USE_CELL_OFFSETS = 1; # turn on non-zero cell offsets
     24$SET_UC_RESID = 1; # write a non-zero resid value to the ubercal table (should not have an impact)
     25$DO_2MASS = 1
     26$DO_SYNTH = 1
     27$DO_TYCHO = 1
     28$NC_CLOUDS = 0.08
     29$UC_CLOUDS = 0.02
    2030
    2131# set various global variables
    2232macro 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     
     76
    2377  $RA_CENTER = 10.0
    2478  $DEC_CENTER = 20.0
     
    3286  $CHIP_DX = 1000
    3387  $CHIP_DY = 1000
    34 
    35   # images are loaded into dvo with GPC1 photcodes, so we need to get the nominal zps for those filters
    36   $zpt_nominal:g = 24.58
    37   $zpt_nominal:r = 24.80
    38   $zpt_nominal:i = 24.74
    39   $zpt_nominal:z = 24.26
    40   $zpt_nominal:y = 23.41
    41 
    42   # klam is negative, so klam*(airmass - 1) increase the zero point
    43   $klam_nominal:g = -0.15
    44   $klam_nominal:r = -0.10
    45   $klam_nominal:i = -0.04
    46   $klam_nominal:z = -0.03
    47   $klam_nominal:y = -0.03
     88  $DEFECT_FRAC = 0.05
     89  $OFFSET_FRAC_UC = 0.0
     90  $OFFSET_FRAC_NC = 0.5
    4891
    4992  # we have two sets of images: ubercaled and not-ubercaled
    5093
    51   # sequence to count images (only used in this function)
    52   create tmpseq 0 9
    53 
    54   $filt_uc:n = 9
    55   $filt_uc:0 = g
    56   $filt_uc:1 = g
    57   $filt_uc:2 = g
    58   $filt_uc:3 = r
    59   $filt_uc:4 = r
    60   $filt_uc:5 = r
    61   $filt_uc:6 = i
    62   $filt_uc:7 = i
    63   $filt_uc:8 = i
    64 
    65   # airmass slopes for these sequnece
     94  # the number of exposures is defined by filt_uc:n
     95  list filt_uc -split g g g g r r r r
     96  $filt_uc:n = 4
     97
     98  # tmpseq is used to generate vectors in this function
     99  create tmpseq 0 $filt_uc:n
     100
     101  # exptime and airmasses for uc images
     102  set exptime_uc = 10.0 + zero(tmpseq)
     103  set airmass_uc =  1.3 + zero(tmpseq)
    66104  set klam_uc = zero(tmpseq)
    67   for i 0 tmpseq[]
    68     klam_uc[$i] = $klam_nominal:$filt_uc:$i
    69   end   
    70 
    71   # mjd and zpt values for ubercal'ed imaged
    72   set exptime_uc = 10.0 + zero(tmpseq)
    73   set airmass_uc = 1.3 + zero(tmpseq)
     105  set zpt_uc = zero(tmpseq)
    74106
    75107  # ubercal zero points are defined as ZP_nominal + 2.5log(exptime) + K*(airmass - 1.0)
    76108  # note that K is defined as a negative value (is this sensible?)
    77   set zpt_uc = 25.0 + 2.5*log(exptime_uc) + klam_uc*(airmass_uc - 1.0) + tmpseq*0.0050 - 0.0025
    78 
    79   set mjd_uc = zero(zpt_uc)
    80   mjd_uc[0] = 55000.01
    81   mjd_uc[1] = 55000.02
    82   mjd_uc[2] = 55000.03
    83   mjd_uc[3] = 55015.01
    84   mjd_uc[4] = 55015.02
    85   mjd_uc[5] = 55015.03
    86   mjd_uc[6] = 55025.01
    87   mjd_uc[7] = 55025.02
    88   mjd_uc[8] = 55025.03
     109
     110  # zero points and airmass slopes for these sequnece
     111  for i 0 $filt_uc:n
     112    klam_uc[$i] = $klam_nominal:$filt_uc:$i
     113    zpt_uc[$i]  = $zpt_nominal:$filt_uc:$i + 2.5*log(exptime_uc[$i]) + klam_uc[$i]*(airmass_uc[$i] - 1.0) + $UC_CLOUDS*(rnd(klam_uc[$i]) - 0.5)
     114  end   
     115  set mjd_uc = 55000.00 + 0.01*(tmpseq % 3) + 10.0*int(tmpseq / 3)
    89116
    90117  # mjd and zpt values for not-ubercal'ed images
    91   $filt_nc:n = 9
    92   $filt_nc:0 = g
    93   $filt_nc:1 = g
    94   $filt_nc:2 = g
    95   $filt_nc:3 = r
    96   $filt_nc:4 = r
    97   $filt_nc:5 = r
    98   $filt_nc:6 = i
    99   $filt_nc:7 = i
    100   $filt_nc:8 = i
     118  list filt_nc -split g g g g r r r r
     119  $filt_nc:n = 4
     120
     121  # tmpseq is used to generate vectors in this function
     122  create tmpseq 0 $filt_nc:n
     123
     124  # place this within a valid season (55000.0 - 55010.0 - 55020.0 - 55030.0)
     125  set exptime_nc = 10.0 + zero(tmpseq)
     126  set airmass_nc =  1.6 + zero(tmpseq)
     127  set klam_nc = zero(tmpseq)
     128  set zpt_nc = zero(tmpseq)
    101129
    102130  # airmass slopes for these sequnece
    103   set klam_nc = zero(tmpseq)
    104   for i 0 tmpseq[]
    105     klam_nc[$i] = $klam_nominal:$filt_nc:$i
     131  for i 0 $filt_nc:n
     132    klam_nc[$i] = $klam_nominal:$filt_nc:$i
     133    zpt_nc[$i]  = $zpt_nominal:$filt_nc:$i + 2.5*log(exptime_nc[$i]) + klam_nc[$i]*(airmass_nc[$i] - 1.0) + $NC_CLOUDS*(rnd(klam_nc[$i]) - 0.5)
    106134  end   
    107 
    108   # place this within a valid season (55000.0 - 55010.0 - 55020.0 - 55030.0)
    109   set exptime_nc = 15.0 + zero(tmpseq)
    110   set airmass_nc = 1.6 + zero(tmpseq)
    111 
    112   # ubercal zero points are defined as ZP_nominal + 2.5log(exptime) + K*(airmass - 1.0)
    113   set zpt_nc = 25.0 + 2.5*log(exptime_nc) + klam_nc*(airmass_nc - 1.0) - tmpseq*0.0050 + 0.0025
    114 
    115   set mjd_nc = zero(zpt_nc)
    116   mjd_nc[0] = 55000.11
    117   mjd_nc[1] = 55000.12
    118   mjd_nc[2] = 55000.13
    119   mjd_nc[3] = 55015.11
    120   mjd_nc[4] = 55015.12
    121   mjd_nc[5] = 55015.13
    122   mjd_nc[6] = 55025.11
    123   mjd_nc[7] = 55025.12
    124   mjd_nc[8] = 55025.13
     135  set mjd_nc = 55000.10 + 0.01*(tmpseq % 3) + 10.0*int(tmpseq / 3)
     136
     137  delete tmpseq
    125138end
    126139
     
    139152  mkdir $rootdir
    140153
     154  break -auto off
    141155  exec rm -rf $catdir
     156  exec rm -rf $fileroot*
     157  break -auto on
    142158
    143159  init
    144160  mkzptfile
    145   mkstars 500
     161  mkstars 1000
     162
     163  catdir $catdir
     164
     165  mk2mass $fileroot $catdir
     166  ck2mass addstar
     167 
     168  mksynth $fileroot $catdir
     169  cksynth addstar
     170
     171  # to add a valid tycho test, I need to generate a zpt table for tycho as well
     172  mktycho $fileroot $catdir
     173  cktycho addstar
    146174
    147175  tapPLAN {((mjd_uc[]*4 + mjd_nc[]*4) + (mjd_uc[] + mjd_nc[]) + (mjd_uc[] + mjd_nc[])) / 3}
     
    149177  # generate the basic images and check they were correctly ingested by dvo
    150178  mksequence $fileroot $catdir
    151   for i 0 mjd_uc[] 3
    152     ckexposure catdir.test mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i raw
    153   end
    154   for i 0 mjd_nc[] 3
    155     ckexposure catdir.test mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i raw
     179  for i 0 mjd_uc[]
     180    ckexposure $catdir mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i raw
     181  end
     182  for i 0 mjd_nc[]
     183    ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i raw
    156184  end
    157185
    158186  # run setphot on the db and check that the images now match the expected values
    159   exec setphot -update -ubercal testzpt.fits -D CATDIR $catdir
    160   for i 0 mjd_uc[] 3
    161     ckexposure catdir.test mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i setphot_uc
    162   end
    163   for i 0 mjd_nc[] 3
    164     ckexposure catdir.test mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i setphot_nc
     187  tapEXEC setphot -update -ubercal testzpt.fits -D CATDIR $catdir
     188  for i 0 mjd_uc[]
     189    ckexposure $catdir mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i setphot_uc
     190  end
     191  for i 0 mjd_nc[]
     192    ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i setphot_nc
    165193  end
    166194
    167195  # run relphot on the db and check that the images now match the expected values
    168   exec relphot g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR catdir.test -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& tmp.log
    169   for i 0 mjd_uc[] 3
    170     ckexposure catdir.test mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i relphot
    171   end
    172   for i 0 mjd_nc[] 3
    173     ckexposure catdir.test mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot
    174   end
     196  tapEXEC relphot -images g,r -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update -synthphot_zpts $fileroot.synthzpts.fits
     197  for i 0 mjd_uc[]
     198    ckexposure $catdir mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i relphot_uc
     199  end
     200  for i 0 mjd_nc[]
     201    ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
     202  end
     203  ck2mass relphot
     204  cksynth relphot
     205  cktycho relphot
    175206
    176207  tapDONE
     208end
     209
     210macro try.relphot
     211  if ($0 != 3)
     212    echo "go (fileroot) (catdir)"
     213    break
     214  end
     215
     216  local i fileroot rootdir catdir
     217
     218  $fileroot = $1
     219  $catdir = $2
     220
     221  # run relphot on the db and check that the images now match the expected values
     222  tapEXEC relphot -images g,r -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update -synthphot_zpts $fileroot.synthzpts.fits -nloop 24
     223
     224  for i 0 mjd_uc[]
     225    # ckexposure $catdir mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i relphot_uc
     226      ckexposure $catdir mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i relphot_uc
     227  end
     228  for i 0 mjd_nc[]
     229    # ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
     230      ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
     231  end
    177232end
    178233
     
    215270  $AIRMASS     = $5
    216271  $FILTER      = $6
    217   $MODE        = $7
     272  $FUNC_MODE   = $7
    218273
    219274  # XXX need a function to extract the nominal zpt for a given filter / photcode from the db
     
    235290
    236291  skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2}
    237   mextract ra dec mag xccd yccd where (abs(time - $MJD_IMAGE) < 0.0001)
     292  mextract ra dec mag xccd yccd dbflags photflags where (abs(time - $MJD_IMAGE) < 0.0001)
    238293 
    239294  match2d -closest ra dec stars_ra stars_dec 0.001 -index1 index1 -index2 index2
     
    246301  set dm = mag - stars_mag_m
    247302
     303  set good_photom = (not(photflags & 0x02))
     304  foreach field dm xccd yccd
     305    subset $field\_good = $field if good_photom
     306  end
     307
    248308  if ($PLOT)
    249309    dev -n 1
    250     lim mag dm; clear; box; plot mag dm
    251   end
    252 
    253   set cell_xbin = int(xccd / ($CHIP_DX / $NCELL_X))
    254   set cell_ybin = int(yccd / ($CHIP_DY / $NCELL_Y))
    255   subset dm00 = dm if (cell_xbin == 0) && (cell_ybin == 0)
    256   subset dm01 = dm if (cell_xbin == 0) && (cell_ybin == 1)
    257   subset dm10 = dm if (cell_xbin == 1) && (cell_ybin == 0)
    258   subset dm11 = dm if (cell_xbin == 1) && (cell_ybin == 1)
     310    lim mag dm; clear; box; plot mag dm; plot -c red -pt 7 mag dm where (photflags & 0x00000002)
     311    dev -n 2
     312    lim xccd dm; clear; box; plot xccd dm; plot -c red -pt 7 xccd dm where (photflags & 0x00000002)
     313    dev -n 3
     314    lim ra dm; clear; box; plot ra dm; plot -c red -pt 7 ra dm where (photflags & 0x00000002)
     315    echo "red points are known bad photometry"
     316  end
     317
     318  # reproduce eddie's esoteric padding
     319  set cell_xbin = max(0 , min(1 , int((xccd_good +  8) / ($CHIP_DX / $NCELL_X))))
     320  set cell_ybin = max(0 , min(1 , int((yccd_good + 10) / ($CHIP_DY / $NCELL_Y))))
     321  subset dm00 = dm_good if (cell_xbin == 0) && (cell_ybin == 0)
     322  subset dm01 = dm_good if (cell_xbin == 0) && (cell_ybin == 1)
     323  subset dm10 = dm_good if (cell_xbin == 1) && (cell_ybin == 0)
     324  subset dm11 = dm_good if (cell_xbin == 1) && (cell_ybin == 1)
    259325
    260326  # uncorrected values behave like this:
     
    273339  $ZPT_REAL_NORM = $ZPT_REAL - 2.5*log($EXPTIME) - $KLAM_NOMINAL*($AIRMASS - 1.0)
    274340
    275   if ("$MODE" == "raw")
     341  if ("$FUNC_MODE" == "raw")
    276342    for ix 0 $NCELL_X
    277343      for iy 0 $NCELL_Y
     
    280346 
    281347        set dm_adjust = dm$ix\$iy - $ZPT_NOMINAL + $ZPT_REAL_NORM + cell_off[$ix][$iy]
     348        # echo set dm_adjust = dm$ix\$iy - $ZPT_NOMINAL + $ZPT_REAL_NORM + cell_off[$ix][$iy]
     349
    282350        vstat -q dm_adjust
    283         tapOK {abs($MEAN) < 0.005} "addstar raw ZP $MJD_IMAGE $FILTER"
     351        sprintf line "addstar raw ZP %8.2f $FILTER %6.3f %6.3f %6.3f: %7.4f %7.4f : cell%d%d %6.3f : %3d" $MJD_IMAGE $ZPT_REAL $ZPT_REAL_NORM $ZPT_NOMINAL $MEAN $SIGMA $ix $iy cell_off[$ix][$iy] dm_adjust[]
     352        tapOK {abs($MEAN) < 0.005} "$line"
    284353      end
    285354    end
     
    287356  end
    288357
    289   if ("$MODE" == "setphot_uc")
    290     vstat -q dm
    291     tapOK {abs($MEAN) < 0.005} "setphot_uc  ZP $MJD_IMAGE $FILTER"
     358  if ("$FUNC_MODE" == "setphot_uc")
     359    vstat -q dm_good
     360    sprintf line "setphot_uc  ZP %8.2f $FILTER %6.3f %6.3f %6.3f: %7.4f %7.4f : %3d" $MJD_IMAGE $ZPT_REAL $ZPT_REAL_NORM $ZPT_NOMINAL $MEAN $SIGMA dm_good[]
     361    tapOK {abs($MEAN) < 0.005} "$line"
     362
     363    subset tmp = dm if (dbflags & 0x00008000)
     364    tapOK {tmp[] == dm[]} "ubercal detections have ubercal bit set"
     365
     366    imextract MCAL FLAGS where (abs(time - $MJD_IMAGE) < 0.0001)
     367    subset tmp = FLAGS if (FLAGS & 0x0000200)
     368    tapOK {tmp[] == FLAGS[]} "ubercal images have ubercal bit set"
     369   
    292370    return
    293371  end
    294372
    295   if ("$MODE" == "setphot_nc")
    296     vstat -q dm
    297     tapOK {abs($MEAN - $ZPT_NOMINAL + $ZPT_REAL_NORM) < 0.005} "setphot_nc  ZP $MJD_IMAGE $FILTER"
     373  if ("$FUNC_MODE" == "setphot_nc")
     374    vstat -q dm_good
     375    sprintf line "setphot_nc  ZP %8.2f $FILTER %6.3f %6.3f %6.3f: %7.4f %7.4f : %3d" $MJD_IMAGE $ZPT_REAL $ZPT_REAL_NORM $ZPT_NOMINAL $MEAN $SIGMA dm_good[]
     376    tapOK {abs($MEAN - $ZPT_NOMINAL + $ZPT_REAL_NORM) < 0.005} "$line"
     377
     378    subset tmp = dm if (not(dbflags & 0x00008000))
     379    tapOK {tmp[] == dm[]} "non-ubercal detections do NOT have ubercal bit set"
     380
     381    imextract FLAGS where (abs(time - $MJD_IMAGE) < 0.0001)
     382    subset tmp = FLAGS if (not(FLAGS & 0x0000200))
     383    tapOK {tmp[] == FLAGS[]} "non-ubercal images do NOT have ubercal bit set"
     384   
    298385    return
    299386  end
    300387
    301   if ("$MODE" == "relphot")
    302     vstat -q dm
    303     tapOK {abs($MEAN) < 0.005} "relphot    ZP $MJD_IMAGE $FILTER"
     388  if (("$FUNC_MODE" == "relphot_uc") || ("$FUNC_MODE" == "relphot_nc"))
     389    vstat -q dm_good
     390    sprintf line "relphot     ZP %8.2f $FILTER %6.3f %6.3f %6.3f: %7.4f %7.4f : %3d" $MJD_IMAGE $ZPT_REAL $ZPT_REAL_NORM $ZPT_NOMINAL $MEAN $SIGMA dm_good[]
     391
     392    if ("$FUNC_MODE" == "relphot_uc")
     393      tapOK {abs($MEAN) < 0.001} "$line"
     394      tapOK {abs($SIGMA) < 0.001} "$line"
     395    end
     396    if ("$FUNC_MODE" == "relphot_nc")
     397      # XXX NOTE relaxed condition : bad photometry points are partly clipped but still cause a bias
     398      tapOK {abs($MEAN) < 0.020} "$line"
     399      tapOK {abs($SIGMA) < 0.020} "$line"
     400    end
     401
     402    mextract ra dec mag dbflags
     403    subset rs = ra  if ((dbflags & 0x8000) && (mag > 13.5))
     404    subset ds = dec if ((dbflags & 0x8000) && (mag > 13.5))
     405    avmatch rs ds 0.1 $FILTER\:flags $FILTER\:uc_dist
     406
     407    subset tmp = rs if (($FILTER\:flags & 0x8) || ($FILTER\:flags & 0x4))
     408    tapOK {tmp[] == rs[]} "objects with ubercal detections have ubercal bit set or used SYNTH photometry (tmp[] vs rs[])"
     409 
     410    subset tmp = rs if (($FILTER\:uc_dist < 0.1) || ($FILTER\:flags & 0x4))
     411    tapOK {tmp[] == rs[]} "objects with ubercal detections have ubercal dist of 0.0 or used SYNTH photometry"
    304412    return
    305413  end
     414
     415  echo "ERROR: unknown mode for ckexposure : $FUNC_MODE"
    306416
    307417end
     
    316426
    317427  # we have defined a set of mjd and zero point values for ubercal'ed images
    318   # for i 0 mjd_uc[]
    319   for i 0 mjd_uc[] 3
     428  for i 0 mjd_uc[]
    320429    mkexposure $1.uc.$i $RA_CENTER $DEC_CENTER zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] mjd_uc[$i] $filt_uc:$i $2
    321430  end
    322431
    323432  # we have a second set of mjd and zero point values for non-ubercal'ed images
    324   # for i 0 mjd_nc[]
    325   for i 0 mjd_nc[] 3
     433  for i 0 mjd_nc[]
    326434    mkexposure $1.nc.$i $RA_CENTER $DEC_CENTER zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] mjd_nc[$i] $filt_nc:$i $2
    327435  end
     
    334442 end
    335443
    336  local ix iy date time datetime ra dec ROOT RAo DECo ZPT MJD FILTER EXPTIME AIRMASS CATDIR
     444 local ix iy date time datetime ra dec ROOT RAo DECo ZPT MJD FILTER EXPTIME AIRMASS CATDIR cmd
    337445
    338446 $ROOT    = $1
     
    366474    $options = -mjd $MJD
    367475    $options = $options -radec $ra $dec
    368     $options = $options -type PS1_V2
     476
     477    #$options = $options -type PS1_V2
     478    #$options = $options -type PS1_V3
     479    #$options = $options -type PS1_V4
     480    $options = $options -type PS1_V5
     481
    369482    $options = $options -coords
    370483    $options = $options -photcode GPC1.$FILTER.XY$ix\$iy
    371484    $options = $options -no-noise
     485    $options = $options -flags
     486    $options = $options -bad-psfqf-frac $DEFECT_FRAC
    372487    $options = $options -size $CHIP_DX $CHIP_DY
    373488    $options = $options -crpix {0.5*$CHIP_DX} {0.5*$CHIP_DY}
    374489    $options = $options -airmass $AIRMASS
    375490    $options = $options -exptime $EXPTIME
    376     exec mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options
    377     echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options
    378    
     491
     492    tapEXEC mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options
     493
    379494    # the fake images have inconsistent ra,dec and airmass,sidtime values
    380     echo addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass
    381     exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass >& tmp.log
     495    tapEXEC addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass
    382496  end
    383497 end
     
    405519  subset stars_mr = stars_mag if valid
    406520
    407   set cell_x = int(stars_x / ($CHIP_DX / $NCELL_X))
    408   set cell_y = int(stars_y / ($CHIP_DX / $NCELL_X))
     521  # note eddie's esoteric padding rule:
     522  set cell_x = max(0 , min(1 , int((stars_x +  8) / ($CHIP_DX / $NCELL_X))))
     523  set cell_y = max(0 , min(1 , int((stars_y + 10) / ($CHIP_DX / $NCELL_X))))
    409524
    410525  # eddie says: M_real = M_inst + zpt + ff_offset
     
    418533  end
    419534
    420   write -f "%10.6f %10.6f %7.3f  %6.1f %6.1f %7.3f" $1 stars_r stars_d stars_mr stars_x stars_y stars_mi
     535  # create bad detections / detections to ignore or avoid, save to a file?
     536
     537  # create 3 types of things to ignore / avoid
     538  # * badPhot (deviate the photometry)
     539  # * badFlag (set a bad flag bit)
     540  # * poorFlag (set a bad flag bit)
     541  set badPhot  = rnd(stars_r) <  $DEFECT_FRAC
     542  set badFlag  = rnd(stars_r) <  $DEFECT_FRAC
     543  set poorFlag = rnd(stars_r) <  $DEFECT_FRAC
     544
     545  # create deviant photometry (1%)
     546  # I'm setting the flag value 0x02 (EXTMODEL) if the object is deviated.  This is a simple way to pass the info
     547  # note that outlier rejection only occurs for Nmeas > 5
     548  set stars_mi = stars_mi + 0.2*badPhot
     549  set stars_fl = zero(stars_mi) + 0x00000080*badFlag + 0x00000100*poorFlag + 0x00000002*badPhot
     550
     551  # bad flags that we sould respect:
     552  # PM_SOURCE_MODE_FAIL             = 0x00000008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
     553  # PM_SOURCE_MODE_SATSTAR          = 0x00000080, ///< Source model peak is above saturation
     554  # PM_SOURCE_MODE_BADPSF           = 0x00000400, ///< Failed to get good estimate of object's PSF
     555  # PM_SOURCE_MODE_DEFECT           = 0x00000800, ///< Source is thought to be a defect
     556  # PM_SOURCE_MODE_SATURATED        = 0x00001000, ///< Source is thought to be saturated pixels (bleed trail)
     557  # PM_SOURCE_MODE_CR_LIMIT         = 0x00002000, ///< Source has crNsigma above limit
     558  # PM_SOURCE_MODE_MOMENTS_FAILURE  = 0x00008000, ///< could not measure the moments
     559  # PM_SOURCE_MODE_SKY_FAILURE      = 0x00010000, ///< could not measure the local sky
     560  # PM_SOURCE_MODE_SKYVAR_FAILURE   = 0x00020000, ///< could not measure the local sky variance
     561  # PM_SOURCE_MODE_SIZE_SKIPPED     = 0x10000000, ///< size could not be determined
     562
     563  # poor flags that we should respect:
     564  # PM_SOURCE_MODE_POOR             = 0x00000010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
     565  # PM_SOURCE_MODE_PAIR             = 0x00000020, ///< Source fitted with a double psf
     566  # PM_SOURCE_MODE_BLEND            = 0x00000100, ///< Source is a blend with other sources
     567  # PM_SOURCE_MODE_BELOW_MOMENTS_SN = 0x00040000, ///< moments not measured due to low S/N
     568  # PM_SOURCE_MODE_BLEND_FIT        = 0x00400000, ///< source was fitted as a blend
     569  # PM_SOURCE_MODE_ON_SPIKE         = 0x20000000, ///< peak lands on diffraction spike
     570  # PM_SOURCE_MODE_ON_GHOST         = 0x40000000, ///< peak lands on ghost or glint
     571  # PM_SOURCE_MODE_OFF_CHIP         = 0x80000000, ///< peak lands off edge of chip
     572
     573  write -f "%10.6f %10.6f %7.3f  %6.1f %6.1f %7.3f 0x%x" $1 stars_r stars_d stars_mr stars_x stars_y stars_mi stars_fl
    421574end
    422575
     
    439592  set stars_ra  = $RA_CENTER  + $RA_RANGE  * (rnd(tmp) - 0.5) / 3600 / dcos ($DEC_CENTER)
    440593  set stars_dec = $DEC_CENTER + $DEC_RANGE * (rnd(tmp) - 0.5) / 3600
    441   set stars_mag = 15.0 + 4.0 * rnd(tmp)
     594  set stars_mag = 10.0 + 10.0 * rnd(tmp)
     595  set stars_dmag = 0.02 + 0.1*rnd(tmp)
     596end
     597
     598macro mk2mass
     599  if ($0 != 3)
     600    echo "USAGE: mk2mass (fileroot) (catdir)"
     601    break
     602  end
     603
     604  if (not($DO_2MASS)) return
     605
     606  local ROOT CATDIR
     607
     608  $ROOT    = $1
     609  $CATDIR  = $2
     610
     611  set stars_flags = 0x00c00000*(rnd(stars_ra) < 0.1) + 0x7*(rnd(stars_ra) < 0.8)
     612  write $ROOT.2mass.dat -f "%10.6f %10.6f %6.3f %6.3f 0x%x" stars_ra stars_dec stars_mag stars_dmag stars_flags
     613
     614  tapEXEC addstar -ref $ROOT.2mass.dat -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass -photcode 2MASS_J
     615
     616  set r_2mass = stars_ra
     617  set d_2mass = stars_dec
     618  set m_2mass = stars_mag
     619  set dm_2mass = stars_dmag
     620  set fl_2mass = stars_flags
     621end
     622
     623macro ck2mass
     624  if ($0 != 2)
     625    echo "USAGE: ck2mass (stage)"
     626    break
     627  end
     628
     629  if (not($DO_2MASS)) return
     630
     631  if ("$1" == "addstar")
     632    skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2}
     633    mextract ra dec mag xccd yccd dbflags photflags where (photcode == 2011)
     634    tapOK {ra[] == r_2mass[]} "read in as many 2mass stars as we generated"
     635   
     636    match2d -closest ra dec r_2mass d_2mass 0.001 -index1 index1 -index2 index2
     637    subset tmp = index1 if (index1 >= 0)
     638    tapOK {tmp[] == ra[]} "2mass sources match those generated"
     639  end
     640
     641  if ("$1" == "relphot")
     642    subset rs = r_2mass if (fl_2mass & 0x00c00000)
     643    subset ds = d_2mass if (fl_2mass & 0x00c00000)
     644    avmatch rs ds 0.1 flags
     645    subset tmp = rs if (flags & 0x02000000); # extended in 2mass
     646    tapOK {tmp[] == rs[]} "2mass extended objects properly marked"
     647   
     648    subset rs = r_2mass if (fl_2mass & 0x07)
     649    subset ds = d_2mass if (fl_2mass & 0x07)
     650    avmatch rs ds 0.1 flags
     651    subset tmp = rs if (flags & 0x08000000); # extended in 2mass
     652    tapOK {tmp[] == rs[]} "2mass good objects properly marked"
     653  end
     654end
     655
     656macro mksynth
     657  if ($0 != 3)
     658    echo "USAGE: mksynth (fileroot) (catdir)"
     659    break
     660  end
     661
     662  if (not($DO_SYNTH)) return
     663
     664  local ROOT CATDIR
     665
     666  $ROOT    = $1
     667  $CATDIR  = $2
     668 
     669  subset r_synth  = stars_ra    if (stars_mag < 17)
     670  subset d_synth  = stars_dec   if (stars_mag < 17)
     671  subset m_synth  = stars_mag   if (stars_mag < 17)
     672  subset dm_synth = stars_dmag  if (stars_mag < 17)
     673  subset fl_synth = stars_flags if (stars_mag < 17)
     674
     675  write $ROOT.synth.dat -f "%10.6f %10.6f %6.3f %6.3f 0x%x" r_synth d_synth m_synth dm_synth fl_synth
     676
     677  tapEXEC addstar -ref $ROOT.synth.dat -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass -photcode SYNTH.g
     678end
     679
     680macro cksynth
     681  if ($0 != 2)
     682    echo "USAGE: cksynth (stage)"
     683    break
     684  end
     685
     686  if (not($DO_SYNTH)) return
     687
     688  if ("$1" == "addstar")
     689    skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2}
     690    mextract ra dec mag xccd yccd dbflags photflags where (photcode == 3001)
     691    tapOK {ra[] == r_synth[]} "read in as many synth stars as we generated"
     692   
     693    match2d -closest ra dec r_synth d_synth 0.001 -index1 index1 -index2 index2
     694    subset tmp = index1 if (index1 >= 0)
     695    tapOK {tmp[] == ra[]} "synth sources match those generated"
     696  end
     697
     698  if ("$1" == "relphot")
     699    subset rs = r_synth if (m_synth < 13.5)
     700    subset ds = d_synth if (m_synth < 13.5)
     701    avmatch rs ds 0.1 g:flags
     702    subset tmp = rs if (g:flags & 0x04); # synth used for photometry
     703    tapOK {tmp[] == rs[]} "synth objects used for photometry properly marked"
     704  end
     705end
     706
     707macro mktycho
     708  if ($0 != 3)
     709    echo "USAGE: mktycho (fileroot) (catdir)"
     710    break
     711  end
     712
     713  if (not($DO_TYCHO)) return
     714
     715  local ROOT CATDIR
     716
     717  $ROOT    = $1
     718  $CATDIR  = $2
     719
     720  subset r_tycho  = stars_ra    if (stars_mag < 12)
     721  subset d_tycho  = stars_dec   if (stars_mag < 12)
     722  subset m_tycho  = stars_mag   if (stars_mag < 12)
     723  subset dm_tycho = stars_dmag  if (stars_mag < 12)
     724  subset fl_tycho = stars_flags if (stars_mag < 12)
     725
     726  write $ROOT.tycho.dat -f "%10.6f %10.6f %6.3f %6.3f 0x%x" r_tycho d_tycho m_tycho dm_tycho fl_tycho
     727
     728  tapEXEC addstar -ref $ROOT.tycho.dat -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass -photcode TYCHO_B
     729
     730  $KAPA = kapa -noX
     731  dev -n tmpdev
     732  # resize 100 100
     733  resize 50 50
     734  region $RA_CENTER $DEC_CENTER 0.2
     735  section default -imtool none
     736  # causes trouble for this to come before region...
     737  create tmp 0 1
     738  cdensify tmpmap tmp tmp
     739  set map = zero(tmpmap) + 0.2
     740  close
     741  $KAPA = kapa
     742
     743  local filter 
     744  foreach filter g r i z y
     745    if ("$filter" == "g")
     746      wd map $ROOT.synthzpts.fits -bitpix -32 -bzero 0.0 -bscale 1.0
     747    end
     748    keyword map EXTNAME -w "map_$filter"
     749    wd map $ROOT.synthzpts.fits -bitpix -32 -bzero 0.0 -bscale 1.0 -extend
     750  end
     751end
     752
     753macro cktycho
     754  if ($0 != 2)
     755    echo "USAGE: cktycho (stage)"
     756    break
     757  end
     758
     759  if (not($DO_TYCHO)) return
     760
     761  if ("$1" == "addstar")
     762    skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2}
     763    mextract ra dec mag xccd yccd dbflags photflags where (photcode == 2020)
     764    tapOK {ra[] == r_tycho[]} "read in as many tycho stars as we generated"
     765   
     766    match2d -closest ra dec r_tycho d_tycho 0.001 -index1 index1 -index2 index2
     767    subset tmp = index1 if (index1 >= 0)
     768    tapOK {tmp[] == ra[]} "tycho sources match those generated"
     769  end
     770
     771  if ("$1" == "relphot")
     772    subset rst = r_tycho if (m_tycho < 12)
     773    subset dst = d_tycho if (m_tycho < 12)
     774    # XXX : should not restrict to 'g'
     775    avmatch rst dst 0.1 g:flags
     776    subset tmp = rst if (g:flags & 0x40); # tycho used for photometry
     777    tapOK {tmp[] == rst[]} "tycho objects used for photometry properly marked"
     778
     779    # non-tycho stars with synth phot should be repaired
     780    subset rsn = r_synth if (m_synth > 12) && (m_synth < 13.5)
     781    subset dsn = d_synth if (m_synth > 12) && (m_synth < 13.5)
     782    # XXX : should not restrict to 'g'
     783    avmatch rsn dsn 0.1 g:flags
     784    subset tmp = rsn if (g:flags & 0x80); # synth photometry repaired
     785    tapOK {tmp[] == rsn[]} "tycho objects used for photometry properly marked"
     786  end
    442787end
    443788
     
    456801
    457802  # define the season boundaries
    458   keyword phu TS0_0000 -wf 55000.0
    459   keyword phu TS1_0000 -wf 55010.0
    460   keyword phu TS0_0001 -wf 55010.0
    461   keyword phu TS1_0001 -wf 55020.0
    462   keyword phu TS0_0002 -wf 55020.0
    463   keyword phu TS1_0002 -wf 55030.0
     803  keyword phu S0_MJD0 -wf 55000.0
     804  keyword phu S1_MJD0 -wf 55010.0
     805  keyword phu S0_MJD1 -wf 55010.0
     806  keyword phu S1_MJD1 -wf 55020.0
     807  keyword phu S0_MJD2 -wf 55020.0
     808  keyword phu S1_MJD2 -wf 55030.0
    464809
    465810  # create a single flat-field correction map for a single chip
    466811  mcreate cell_off 2 2
    467   cell_off[0][0] =  0.01
    468   cell_off[1][0] = -0.01
    469   cell_off[0][1] =  0.02
    470   cell_off[1][1] = -0.02
     812  if ($USE_CELL_OFFSETS)
     813    cell_off[0][0] =  0.05
     814    cell_off[1][0] = -0.03
     815    cell_off[0][1] =  0.08
     816    cell_off[1][1] = -0.10
     817  end
    471818
    472819  # in the correction table, we have an image of the full exposure
     
    481828    for iyc 0 $NCELL_Y
    482829      for ix 0 $NCHIP_X
     830        set tcell_off = cell_off
     831        if ($ix < 4)
     832          rotate tcell_off 180
     833        end
    483834        for ixc 0 $NCELL_X
    484           concat cell_off[$ixc][$iyc] image_offset
     835          concat tcell_off[$ixc][$iyc] image_offset
    485836        end
    486837      end
     
    498849  set mjd_obs = mjd_uc
    499850  set zp = zpt_uc
    500   set resid = 0.02*rnd(zpt_uc) - 0.01
     851
     852  if ($SET_UC_RESID)
     853    set resid = 0.02*rnd(zpt_uc) - 0.01
     854  else
     855    set resid = zero(zpt_uc)
     856  end
    501857
    502858  delete -q flatcorr
  • trunk/Ohana/src/addstar/test/simple.dvo

    r37036 r38441  
    1010  test.fields PS1_V2    PS1_V1
    1111  test.fields PS1_V3    PS1_V1
    12   test.fields PS1_V4    PS1_V1
     12  test.fields PS1_V5    PS1_V1
    1313
    1414  test.fields PS1_DEV_0 PS1_V2
     
    1717  test.fields PS1_V2    PS1_V2
    1818  test.fields PS1_V3    PS1_V2
    19   test.fields PS1_V4    PS1_V4
     19  test.fields PS1_V5    PS1_V2
    2020
    2121  test.fields PS1_DEV_0 PS1_V3
     
    2424  test.fields PS1_V2    PS1_V3
    2525  test.fields PS1_V3    PS1_V3
    26   test.fields PS1_V4    PS1_V4
     26  test.fields PS1_V5    PS1_V3
    2727
    2828  test.fields PS1_DEV_0 PS1_V4
     
    3131  test.fields PS1_V2    PS1_V4
    3232  test.fields PS1_V3    PS1_V4
    33   test.fields PS1_V4    PS1_V4
     33  test.fields PS1_V5    PS1_V4
    3434end 
    3535
     
    5454
    5555  mkinput
    56   echo mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
    57   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
    58   if ($TAP_VERBOSE)
    59     echo exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    60     exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    61   else
    62     echo addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    63     exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass >& tmp.log
    64   end
     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
    6558
    6659  list testfields -copy testfields_$1
     
    7972    if ("$name:0" == "SKIP") continue
    8073    if ("$name:2" == "SKIP") continue
     74 
    8175    read -fits Chip.psf $name:0
    8276    mextract $name:2
     
    9286  set d = $name:0 - $name:2
    9387  vstat -q d
    94   tapOK {abs($MEAN)  < 0.001} "$name:0 vs $name:2 (MEAN)"
    95   tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA)"
     88  tapOK {abs($MEAN)  < 0.001} "$name:0 vs $name:2 (MEAN = $MEAN)"
     89  tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA = $SIGMA)"
    9690
    9791  # detection ID must be first for this to work:
     
    142136    if ("$name:0" == "PSF_THETA")
    143137      # echo $MEAN
    144       tapOK {abs($MEAN)  < 0.006} "$name:0 vs $name:2 (MEAN)"
    145       tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA)"
     138      tapOK {abs($MEAN)  < 0.006} "$name:0 vs $name:2 (MEAN = $MEAN)"
     139      tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA = $SIGMA)"
    146140      continue
    147141    end
    148142
    149     tapOK {abs($MEAN)  < 0.001} "$name:0 vs $name:2 (MEAN)"
    150     tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA)"
     143    tapOK {abs($MEAN)  < 0.001} "$name:0 vs $name:2 (MEAN = $MEAN)"
     144    tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA = $MEAN)"
    151145  end   
    152146
     
    231225  PSF_INST_MAG      : mag:inst 
    232226  PSF_INST_MAG_SIG  : mag:err   
    233   AP_MAG_STANDARD   : mag:ap # FAIL
     227# AP_MAG_STANDARD   : mag:ap # FAIL
    234228  AP_MAG_RADIUS     : SKIP # no accessor
    235229  PEAK_FLUX_AS_MAG  : SKIP # no accessor
     
    237231  CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
    238232  SKY               : sky       
    239   SKY_SIG           : sky_err   
     233  SKY_SIGMA         : sky_err   
    240234  PSF_CHISQ         : psf_chisq
    241235  CR_NSIGMA         : cr_nsigma
     
    267261  PSF_INST_MAG      : mag:inst 
    268262  PSF_INST_MAG_SIG  : mag:err   
    269   AP_MAG_STANDARD   : mag:ap # FAIL
     263# AP_MAG_STANDARD   : mag:ap # FAIL
    270264  AP_MAG_RADIUS     : SKIP # no accessor
    271265  PEAK_FLUX_AS_MAG  : SKIP # no accessor
     
    273267  CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
    274268  SKY               : sky       
    275   SKY_SIG           : sky_err   
     269  SKY_SIGMA         : sky_err   
    276270  PSF_CHISQ         : psf_chisq
    277271  CR_NSIGMA         : cr_nsigma
     
    303297  PSF_INST_FLUX     : SKIP # not ingested into DVO
    304298  PSF_INST_FLUX_SIG : SKIP # not ingested into DVO
    305   AP_MAG_STANDARD   : mag:aperinst # FAIL
     299# AP_MAG_STANDARD   : mag:aperinst # FAIL
    306300  AP_MAG_RAW        : SKIP # not ingested into DVO
    307301  AP_MAG_RADIUS     : SKIP # not ingested into DVO
     
    312306  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO
    313307  SKY               : sky       
    314   SKY_SIG           : sky_err   
     308  SKY_SIGMA         : sky_err   
    315309  PSF_CHISQ         : psf_chisq
    316310  CR_NSIGMA         : cr_nsigma
     
    332326  MOMENTS_R1        : SKIP # not ingested into DVO
    333327  MOMENTS_RH        : SKIP # not ingested into DVO
    334   KRON_FLUX         : mag:kroninst
    335   KRON_FLUX_ERR     : mag:kronerr
     328  KRON_FLUX         : mag:kron:inst
     329  KRON_FLUX_ERR     : mag:kron:err
    336330  KRON_FLUX_INNER   : SKIP # not ingested into DVO
    337331  KRON_FLUX_OUTER   : SKIP # not ingested into DVO
  • trunk/Ohana/src/addstar/test/tap.dvo

    r34405 r38441  
    33if (not($?TAP_BREAK)) set TAP_BREAK = 0
    44if (not($?TAP_VERBOSE)) set TAP_VERBOSE = 0
     5
     6macro tapEXEC
     7  if ($0 < 3)
     8    echo "USAGE: tapEXEC (command)"
     9    break
     10  end
     11
     12  local i cmd result
     13
     14  $cmd = ""
     15  for i 1 $0
     16    $cmd = $cmd $$i
     17  end
     18
     19  if ($TAP_VERBOSE >= 2) echo $cmd
     20
     21  break -auto off
     22  exec $cmd >& tap.log
     23  $result = $STATUS
     24  break -auto on
     25
     26  if (not($result))
     27    exec cat tap.log
     28    echo "not ok : $cmd"
     29    $TAP_NFAIL ++
     30    $TAP_LAST = 0
     31    if ($TAP_BREAK)
     32     break
     33    end
     34  else
     35    if ($TAP_VERBOSE >= 1) echo "ok : $cmd"
     36    $TAP_LAST = 1
     37  end
     38  $TAP_NDONE ++
     39end
    540
    641macro tapOK
     
    1146
    1247  if ($1)
    13     if ($TAP_VERBOSE)
     48    if ($TAP_VERBOSE >= 1)
    1449      echo "ok : $2"
    1550    end
  • trunk/Ohana/src/checkastro/src/bcatalog.c

    r37807 r38441  
    408408  subcatalog[0].Nmeasure = Nmeasure;
    409409  subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt;
    410   subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt;
     410  subcatalog[0].Nsecfilt_mem = Naverage * oldcatalog[0].Nsecfilt;
    411411
    412412  return (TRUE);
     
    515515  subcatalog[0].Nmeasure = Nmeasure;
    516516  subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt;
    517   subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt;
     517  subcatalog[0].Nsecfilt_mem = Naverage * oldcatalog[0].Nsecfilt;
    518518
    519519  return (TRUE);
     
    609609  subcatalog[0].Nmeasure = Nmeasure;
    610610  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
    611   subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     611  subcatalog[0].Nsecfilt_mem = Naverage * catalog[0].Nsecfilt;
    612612
    613613  return (TRUE);
  • trunk/Ohana/src/checkastro/src/checkastro_images.c

    r36833 r38441  
    1111  /* register database handle with shutdown procedure */
    1212  set_db (&db);
     13  gfits_db_init (&db);
    1314
    1415  /* lock and load the image db table */
  • trunk/Ohana/src/checkastro/src/load_catalogs.c

    r36833 r38441  
    3535    pcatalog->catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    3636    pcatalog->catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    37     pcatalog->catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF; // don't need to load all data at this point
     37    pcatalog->catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT; // don't need to load all data at this point
    3838    pcatalog->Nsecfilt  = GetPhotcodeNsecfilt ();
    3939
     
    4343      exit (1);
    4444    }
    45     if (!pcatalog[0].Naves_disk) {
     45    if (!pcatalog[0].Naverage_disk) {
    4646      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename);
    4747      dvo_catalog_unlock (pcatalog);
  • trunk/Ohana/src/checkastro/src/load_images.c

    r37807 r38441  
    1010
    1111  // convert database table to internal structure
    12   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     12  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1313  if (!image) {
    1414      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/delstar/src/delete_duplicate_images.c

    r36833 r38441  
    1616  Image *image, *outimage;
    1717
    18   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     18  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1919  if (!image) {
    2020    fprintf (stderr, "ERROR: failed to read images\n");
     
    6161 
    6262  fprintf (stderr, "removing "OFF_T_FMT" images (leaving "OFF_T_FMT" of "OFF_T_FMT")\n",  Nimage - Noutimage, Noutimage, Nimage);
    63   // gfits_table_set_Image (&db[0].ftable, outimage, Noutimage);
     63  // gfits_table_set_Image (&db[0].ftable, outimage, Noutimage, TRUE);
    6464
    6565  gfits_modify (&db[0].theader, "NAXIS2", OFF_T_FMT, 1,  Noutimage);
     
    110110    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
    111111    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    112     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     112    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    113113
    114114    if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
     
    119119      exit (2);
    120120    }
    121     if (!catalog.Naves_disk) {
     121    if (!catalog.Naverage_disk) {
    122122      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    123123      dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/delstar/src/delete_duplicate_measures.c

    r37807 r38441  
    4545    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
    4646    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    47     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     47    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4848
    4949    if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
     
    5454      exit (2);
    5555    }
    56     if (!catalog.Naves_disk) {
     56    if (!catalog.Naverage_disk) {
    5757      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5858      dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/delstar/src/delete_fix_LAP.c

    r35807 r38441  
    4343    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
    4444    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    45     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     45    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4646
    4747    if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
     
    5252      exit (2);
    5353    }
    54     if (!catalog.Naves_disk) {
     54    if (!catalog.Naverage_disk) {
    5555      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5656      dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/delstar/src/delete_fix_LAP_edges.c

    r37040 r38441  
    5151    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
    5252    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    53     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     53    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    5454
    5555    if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
     
    6060      exit (2);
    6161    }
    62     if (!catalog.Naves_disk) {
     62    if (!catalog.Naverage_disk) {
    6363      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    6464      dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/delstar/src/delete_fix_LAP_edges_delete.c

    r35805 r38441  
    9191    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
    9292    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    93     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     93    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    9494
    9595    if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
     
    100100      exit (2);
    101101    }
    102     if (!catalog.Naves_disk) {
     102    if (!catalog.Naverage_disk) {
    103103      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    104104      dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/delstar/src/delete_image_photcodes.c

    r34749 r38441  
    1212  PhotCode **photcodes = ParsePhotcodeList (PHOTCODE_LIST, &Nphotcodes, FALSE);
    1313
    14   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     14  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1515  if (!image) {
    1616    fprintf (stderr, "ERROR: failed to read images\n");
     
    3333 
    3434  if (VERBOSE) fprintf (stderr, "removing "OFF_T_FMT" images (leaving "OFF_T_FMT" of "OFF_T_FMT")\n",  Nimage - Noutimage, Noutimage, Nimage);
    35   // gfits_table_set_Image (&db[0].ftable, outimage, Noutimage);
     35  // gfits_table_set_Image (&db[0].ftable, outimage, Noutimage, TRUE);
    3636
    3737  gfits_modify (&db[0].theader, "NAXIS2", OFF_T_FMT, 1,  Noutimage);
  • trunk/Ohana/src/delstar/src/delete_imagefile.c

    r34749 r38441  
    2626    catalog.filename = sky[0].filename[i];  /* don't free region before catalog! */
    2727    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    28     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     28    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    2929
    3030    // an error exit status here is a significant error
     
    3333      exit (2);
    3434    }
    35     if (!catalog.Naves_disk) {
     35    if (!catalog.Naverage_disk) {
    3636      dvo_catalog_unlock (&catalog);
    3737      dvo_catalog_free (&catalog);
  • trunk/Ohana/src/delstar/src/delete_imagename.c

    r37807 r38441  
    1818  SkyTableSetFilenames (sky, CATDIR, "cpt");
    1919
    20   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     20  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    2121  if (!image) {
    2222    fprintf (stderr, "ERROR: failed to read images\n");
     
    4141      catalog.filename = skylist[0].filename[i];  /* don't free region before catalog! */
    4242      catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    43       catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     43      catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4444
    4545      // an error exit status here is a significant error
     
    4848        exit (2);
    4949      }
    50       if (!catalog.Naves_disk) {
     50      if (!catalog.Naverage_disk) {
    5151        dvo_catalog_unlock (&catalog);
    5252        dvo_catalog_free (&catalog);
     
    8282 
    8383  if (VERBOSE) fprintf (stderr, "removing "OFF_T_FMT" images (leaving "OFF_T_FMT" of "OFF_T_FMT")\n",  Nimlist,  Noutimage,  Nimage);
    84   // gfits_table_set_Image (&db[0].ftable, outimage, Noutimage);
     84  // gfits_table_set_Image (&db[0].ftable, outimage, Noutimage, TRUE);
    8585
    8686  gfits_modify (&db[0].theader, "NAXIS2", OFF_T_FMT, 1,  Noutimage);
  • trunk/Ohana/src/delstar/src/delete_orphans.c

    r27435 r38441  
    252252  catalog.Nmeasure = Nmeas;
    253253  catalog.Nmissing = Nmiss;
    254   catalog.Nsecf_mem = Nave*Nsecfilt;
     254  catalog.Nsecfilt_mem = Nave*Nsecfilt;
    255255
    256256  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: %d %d %d\n", Nave, Nmeas, Nmiss);
  • trunk/Ohana/src/delstar/src/delete_photcodes.c

    r35758 r38441  
    4141    catalog.filename  = HOST_ID ? hostfile : skylist[0].filename[i];
    4242    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    43     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     43    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4444
    4545    if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
     
    5050      exit (2);
    5151    }
    52     if (!catalog.Naves_disk) {
     52    if (!catalog.Naverage_disk) {
    5353      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5454      dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/delstar/src/delete_photcodes_single.c

    r35107 r38441  
    1010  catalog.filename  = cptname;
    1111  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    12   catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     12  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    1313
    1414  if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
     
    1919    return FALSE;
    2020  }
    21   if (!catalog.Naves_disk) {
     21  if (!catalog.Naverage_disk) {
    2222    if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    2323    dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/delstar/src/delete_times.c

    r37807 r38441  
    2525  skylist[0].ownElements = FALSE; // free these elements when freeing the list
    2626
    27   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     27  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    2828  if (!image) {
    2929    fprintf (stderr, "ERROR: failed to read images\n");
     
    6262    catalog.filename = skylist[0].filename[i];  /* don't free region before catalog! */
    6363    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    64     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     64    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    6565
    6666    // an error exit status here is a significant error
     
    6969      exit (2);
    7070    }
    71     if (!catalog.Naves_disk) {
     71    if (!catalog.Naverage_disk) {
    7272      dvo_catalog_unlock (&catalog);
    7373      dvo_catalog_free (&catalog);
  • trunk/Ohana/src/delstar/src/delstar.c

    r35837 r38441  
    1212  if (!SKIP_IMAGES) {
    1313    set_db (&db);
     14    gfits_db_init (&db);
    1415    status = dvo_image_lock (&db, ImageCat, 60.0, LCK_XCLD); /* XCLD */
    1516    if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
     
    3031    case MODE_FIX_LAP: {
    3132        off_t Nimage;
    32         Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     33        Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    3334        if (!image) {
    3435          fprintf (stderr, "ERROR: failed to read images\n");
     
    6768    case MODE_FIX_LAP_STATS: {
    6869        off_t Nimage;
    69         Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     70        Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    7071        if (!image) {
    7172          fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/delstar/src/find_image_db.c

    r29001 r38441  
    1616  }
    1717
    18   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     18  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1919  if (!image) {
    2020    fprintf (stderr, "ERROR: failed to read images\n");
     
    4646  int code;
    4747
    48   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     48  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    4949
    5050  start = timage[0].tzero - MAX(0.01*timage[0].trate*timage[0].NY, 1);
     
    7676  Image *image;
    7777
    78   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     78  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    7979
    8080  Nlist = 0;
  • trunk/Ohana/src/delstar/src/find_matches.c

    r34088 r38441  
    245245  catalog[0].Nmeasure = Nmeas;
    246246  catalog[0].Nmissing = Nmiss;
    247   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     247  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    248248
    249249  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT"\n",  Nave,  Nmeas,  Nmiss);
  • trunk/Ohana/src/dvolens/src/update_objects.c

    r37358 r38441  
    6161    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    6262    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    63     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING | LOAD_LENSOBJ;
     63    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ;
    6464    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
    6565
     
    6868      exit (1);
    6969    }
    70     if (VERBOSE && (catalog.Naves_disk == 0)) {
     70    if (VERBOSE && (catalog.Naverage_disk == 0)) {
    7171        fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    7272        dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/dvomerge/Makefile

    r37807 r38441  
    164164$(BIN)/dvoutils.$(ARCH) : $(DVOUTILS)
    165165
    166 INSTALL = dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client dvoverify
     166INSTALL = dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client dvoverify dvoutils
    167167
    168168# dependancy rules for binary code #########################
  • trunk/Ohana/src/dvomerge/include/dvomerge.h

    r37807 r38441  
    4141int    REPLACE_BY_PHOTCODE;
    4242int    FORCE_MERGE;
     43int    MAX_CLIENTS;
    4344char  *UPDATE_CATFORMAT;
     45char  *UPDATE_CATCOMPRESS;
    4446
    4547int    MATCHED_TABLES;
  • trunk/Ohana/src/dvomerge/src/LoadCatalog.c

    r37807 r38441  
    88
    99    // always load all of the data (if any exists)
    10     catalog[0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING | LOAD_LENSOBJ | LOAD_STARPAR;
     10    catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;
    1111
    1212    catalog[0].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
  • trunk/Ohana/src/dvomerge/src/LoadImages.c

    r29938 r38441  
    3434  }
    3535
    36   image = gfits_table_get_Image (&db->ftable, Nimage, &db->swapped);
     36  image = gfits_table_get_Image (&db->ftable, Nimage, &db->scaledValue, &db->nativeOrder);
    3737  if (!image) {
    3838    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/dvomerge/src/args.c

    r38062 r38441  
    4444  }
    4545
     46  /* limit the impact of a dvomerge -parallel */
     47  MAX_CLIENTS = 10;
     48  if ((N = get_argument (*argc, argv, "-max-clients"))) {
     49    remove_argument (N, argc, argv);
     50    MAX_CLIENTS = atoi(argv[N]);
     51    remove_argument (N, argc, argv);
     52  }
     53
    4654  /* use a different photcode file to define mean values */
    4755  if ((N = get_argument (*argc, argv, "-photcode-file"))) {
     
    6270    remove_argument (N, argc, argv);
    6371    UPDATE_CATFORMAT = strcreate (argv[N]);
     72    remove_argument (N, argc, argv);
     73  }
     74  UPDATE_CATCOMPRESS = NULL;
     75  if ((N = get_argument (*argc, argv, "-update-catcompress"))) {
     76    remove_argument (N, argc, argv);
     77    UPDATE_CATCOMPRESS = strcreate (argv[N]);
    6478    remove_argument (N, argc, argv);
    6579  }
     
    212226    remove_argument (N, argc, argv);
    213227  }
     228  UPDATE_CATCOMPRESS = NULL;
     229  if ((N = get_argument (*argc, argv, "-update-catcompress"))) {
     230    remove_argument (N, argc, argv);
     231    UPDATE_CATCOMPRESS = strcreate (argv[N]);
     232    remove_argument (N, argc, argv);
     233  }
    214234
    215235  /* replace measurement, don't duplicate */
  • trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r37807 r38441  
    1616  short  *TgtCodes;
    1717 
    18   imagesSrc = gfits_table_get_Image (&src[0].ftable, &NimagesSrc, &src[0].swapped);
     18  imagesSrc = gfits_table_get_Image (&src[0].ftable, &NimagesSrc, &src[0].scaledValue, &src[0].nativeOrder);
    1919  if (!imagesSrc) {
    2020    fprintf (stderr, "ERROR: failed to read images from src\n");
     
    2222  }
    2323
    24   imagesTgt = gfits_table_get_Image (&tgt[0].ftable, &NimagesTgt, &tgt[0].swapped);
     24  imagesTgt = gfits_table_get_Image (&tgt[0].ftable, &NimagesTgt, &tgt[0].scaledValue, &tgt[0].nativeOrder);
    2525  if (!imagesTgt) {
    2626    fprintf (stderr, "ERROR: failed to read images from tgt\n");
     
    8383  }
    8484
    85   images = gfits_table_get_Image (&in[0].ftable, &Nimages, &in[0].swapped);
     85  images = gfits_table_get_Image (&in[0].ftable, &Nimages, &in[0].scaledValue, &in[0].nativeOrder);
    8686  if (!images) {
    8787    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/dvomerge/src/dvoconvert.c

    r33657 r38441  
    8282
    8383      // skip empty input catalogs
    84       if (!incatalog.Naves_disk) {
     84      if (!incatalog.Naverage_disk) {
    8585        dvo_catalog_unlock (&incatalog);
    8686        dvo_catalog_free (&incatalog);
     
    9393    SkyListFree (inlist);
    9494
    95     outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     95    outcatalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    9696    dvo_catalog_save (&outcatalog, VERBOSE);
    9797    dvo_catalog_unlock (&outcatalog);
     
    122122  /*** load output/Images.dat ***/
    123123  sprintf (ImageCat, "%s/Images.dat", output);
     124  gfits_db_init (&outDB);
    124125  outDB.mode   = dvo_catalog_catmode (CATMODE);
    125126  outDB.format = dvo_catalog_catformat (CATFORMAT);
     
    135136  /*** load input/Images.dat ***/
    136137  sprintf (ImageCat, "%s/Images.dat", input);
     138  gfits_db_init (&inDB);
    137139  // inDB.mode   = dvo_catalog_catmode (CATMODE);
    138140  // inDB.format = dvo_catalog_catformat (CATFORMAT);
     
    149151
    150152  // convert the raw image table to Image type (byteswap if needed)
    151   images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.swapped);
     153  images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.scaledValue, &inDB.nativeOrder);
    152154  if (!images) {
    153155    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/dvomerge/src/dvomergeContinue.c

    r37116 r38441  
    109109    LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r", NsecfiltInput);
    110110    // skip empty input catalogs
    111     if (!incatalog.Naves_disk) {
     111    if (!incatalog.Naverage_disk) {
    112112        dvo_catalog_unlock (&incatalog);
    113113        dvo_catalog_free (&incatalog);
  • trunk/Ohana/src/dvomerge/src/dvomergeContinue_threaded.c

    r37116 r38441  
    4747    LoadCatalog (&incatalog, threadData->region, threadData->filename, "r", threadData->NsecfiltInput);
    4848    // skip empty input catalogs
    49     if (!incatalog.Naves_disk) {
     49    if (!incatalog.Naverage_disk) {
    5050      dvo_catalog_unlock (&incatalog);
    5151      dvo_catalog_free (&incatalog);
  • trunk/Ohana/src/dvomerge/src/dvomergeCreate.c

    r37116 r38441  
    145145
    146146      // skip empty input catalogs
    147       if (!incatalog.Naves_disk) {
     147      if (!incatalog.Naverage_disk) {
    148148        dvo_catalog_unlock (&incatalog);
    149149        dvo_catalog_free (&incatalog);
     
    166166
    167167      // skip empty input catalogs
    168       if (!incatalog.Naves_disk) {
     168      if (!incatalog.Naverage_disk) {
    169169        dvo_catalog_unlock (&incatalog);
    170170        dvo_catalog_free (&incatalog);
     
    204204    /*** load output/Images.dat ***/
    205205    sprintf (ImageCat, "%s/Images.dat", output);
     206    gfits_db_init (&outDB);
    206207    outDB.mode   = dvo_catalog_catmode (CATMODE);
    207208    outDB.format = dvo_catalog_catformat (CATFORMAT);
     
    218219    /*** load input1/Images.dat ***/
    219220    sprintf (ImageCat, "%s/Images.dat", input1);
     221    gfits_db_init (&in1DB);
    220222    in1DB.mode   = dvo_catalog_catmode (CATMODE);
    221223    in1DB.format = dvo_catalog_catformat (CATFORMAT);
     
    237239    /*** load input2/Images.dat ***/
    238240    sprintf (ImageCat, "%s/Images.dat", input2);
     241    gfits_db_init (&in2DB);
    239242    in2DB.mode   = dvo_catalog_catmode (CATMODE);
    240243    in2DB.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/dvomerge/src/dvomergeFromList.c

    r37116 r38441  
    113113
    114114    // skip empty input catalogs
    115     if (!incatalog.Naves_disk) {
     115    if (!incatalog.Naverage_disk) {
    116116        dvo_catalog_unlock (&incatalog);
    117117        dvo_catalog_free (&incatalog);
  • trunk/Ohana/src/dvomerge/src/dvomergeImageIDs.c

    r36833 r38441  
    1010  /*** load input1/Images.dat ***/
    1111  sprintf (ImageCat, "%s/Images.dat", input);
     12  gfits_db_init (&inDB);
    1213  inDB.mode   = dvo_catalog_catmode (CATMODE);
    1314  inDB.format = dvo_catalog_catformat (CATFORMAT);
    14   status       = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_SOFT);  // shorter timeout?
     15  status      = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_SOFT);  // shorter timeout?
    1516  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", inDB.filename);
    1617
     
    3738  /*** load output/Images.dat ***/
    3839  sprintf (ImageCat, "%s/Images.dat", output);
     40  gfits_db_init (&outDB);
    3941  outDB.mode   = dvo_catalog_catmode (CATMODE);
    4042  outDB.format = dvo_catalog_catformat (CATFORMAT);
     
    9395  /*** load input1/Images.dat ***/
    9496  sprintf (ImageCat, "%s/Images.dat", input);
     97  gfits_db_init (&inDB);
    9598  inDB.mode   = dvo_catalog_catmode (CATMODE);
    9699  inDB.format = dvo_catalog_catformat (CATFORMAT);
    97   status       = dvo_image_lock (&inDB, ImageCat, 5400.0, LCK_XCLD);  // shorter timeout?
     100  status      = dvo_image_lock (&inDB, ImageCat, 5400.0, LCK_XCLD);  // shorter timeout?
    98101  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", inDB.filename);
    99102
     
    115118  /*** load output/Images.dat ***/
    116119  sprintf (ImageCat, "%s/Images.dat", output);
     120  gfits_db_init (&outDB);
    117121  outDB.mode   = dvo_catalog_catmode (CATMODE);
    118122  outDB.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r38062 r38441  
    142142
    143143    // skip empty input catalogs
    144     if (!incatalog.Naves_disk) {
     144    if (!incatalog.Naverage_disk) {
    145145        dvo_catalog_unlock (&incatalog);
    146146        dvo_catalog_free (&incatalog);
     
    176176
    177177      // if no catalog already exists, use the input catalog to define the format or the specified format
    178       if (outcatalog.Naves_disk == 0) {
    179         if (UPDATE_CATFORMAT) {
    180           outcatalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT);
    181         } else {
    182           outcatalog.catformat = incatalog.catformat;
    183         }
     178      if (UPDATE_CATFORMAT) {
     179        outcatalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT);
     180      } else {
     181        outcatalog.catformat = incatalog.catformat;
     182      }
     183      if (UPDATE_CATCOMPRESS) {
     184        outcatalog.catcompress = dvo_catalog_catcompress (UPDATE_CATCOMPRESS);
     185      } else {
     186        outcatalog.catcompress = incatalog.catcompress;
    184187      }
    185188
     
    227230  return TRUE;
    228231}
     232
     233int dvomergeUpdate_parallel_group (HostTableGroup *group, char *absinput, char *absoutput);
    229234
    230235// launch the dvomergeUpdate_client jobs to the parallel hosts
     
    254259  }   
    255260
     261  int Ngroups;
     262  HostTableGroup *groups = HostTableGroupsMaxNumber (table, &Ngroups, MAX_CLIENTS);
     263  // split the table into Ngroups, each with a unique set of machines (this avoids overloading the remote host machines)
     264
    256265  int i;
    257   for (i = 0; i < table->Nhosts; i++) {
     266  for (i = 0; i < Ngroups; i++) {
     267    // update only a max of MaxClient machines at a time
     268    dvomergeUpdate_parallel_group (&groups[i], absinput, absoutput);
     269  }
     270  return TRUE;
     271}
     272
     273int dvomergeUpdate_parallel_group (HostTableGroup *group, char *absinput, char *absoutput) {
     274
     275  int i;
     276  for (i = 0; i < group->Nhosts; i++) {
    258277
    259278    // ensure that the paths are absolute path names
    260     char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
    261     free (table->hosts[i].pathname);
    262     table->hosts[i].pathname = tmppath;
     279    char *tmppath = abspath (group->hosts[i][0].pathname, DVO_MAX_PATH);
     280    free (group->hosts[i][0].pathname);
     281    group->hosts[i][0].pathname = tmppath;
    263282
    264283    // options / arguments that can affect relastro_client -update-objects:
    265284    char command[DVO_MAX_PATH];
    266285    snprintf (command, DVO_MAX_PATH, "dvomerge_client %s into %s -hostID %d -hostdir %s -region %f %f %f %f -D ADDSTAR_RADIUS %f",
    267               absinput, absoutput, table->hosts[i].hostID, table->hosts[i].pathname,
     286              absinput, absoutput, group->hosts[i][0].hostID, group->hosts[i][0].pathname,
    268287              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, RADIUS
    269288      );
     
    291310      int status = system (command);
    292311      if (status) {
    293         fprintf (stderr, "ERROR running photdbc_client\n");
     312        fprintf (stderr, "ERROR running dvomerge_client\n");
    294313        exit (2);
    295314      }
     
    297316      // launch the job on the remote machine (no handshake)
    298317      int errorInfo = 0;
    299       int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
     318      int pid = rconnect ("ssh", group->hosts[i][0].hostname, command, group->hosts[i][0].stdio, &errorInfo, FALSE);
    300319      if (!pid) {
    301         if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
     320        if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", group->hosts[i][0].hostname, errorInfo);
    302321        exit (1);
    303322      }
    304       table->hosts[i].pid = pid; // save for future reference
     323      group->hosts[i][0].pid = pid; // save for future reference
    305324    }
    306325  }
    307326
    308327  if (PARALLEL_MANUAL) {
    309     fprintf (stderr, "run the photdbc_client commands above.  when these are done, hit return\n");
     328    fprintf (stderr, "run the dvomerge_client commands above.  when these are done, hit return\n");
    310329    getchar();
    311330  }
    312331  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
    313     int status = HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
     332    int status = HostTableGroupWaitJobsGetIO (group, __FILE__, __LINE__, VERBOSE);
    314333    if (!status) {
    315334      fprintf (stderr, "error running one of the remote clients\n");
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c

    r37116 r38441  
    4444    LoadCatalog (&incatalog, threadData->region, threadData->filename, "r", threadData->NsecfiltInput);
    4545    // skip empty input catalogs
    46     if (!incatalog.Naves_disk) {
     46    if (!incatalog.Naverage_disk) {
    4747      dvo_catalog_unlock (&incatalog);
    4848      dvo_catalog_free (&incatalog);
  • trunk/Ohana/src/dvomerge/src/dvorepairCPT.c

    r37807 r38441  
    7676  }
    7777
    78   measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
     78  measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    7979  myAssert(measure, "failed to convert ftable to measure data");
    8080
     
    156156  gfits_modify_alt (&cptHeaderPHU, "SORTED", "%t",      1,  FALSE);
    157157
     158  myAbort ("test for compression");
     159
    158160  /* convert internal to external format */
    159   if (!AverageToFtable (&cptFtable, average, Naverage, catformat, NULL)) {
     161  if (!AverageToFtable (&cptFtable, average, Naverage, catformat, NULL, TRUE)) {
    160162    myAbort("trouble converting format");
    161163  }
  • trunk/Ohana/src/dvomerge/src/dvorepairDeleteImageList.c

    r37807 r38441  
    4646  FILE *cpmFile = NULL;
    4747
    48   char catformat;
     48  DVOCatFormat catformat;
    4949
    5050  N = get_argument (argc, argv, "-delete-image-list");
     
    246246        gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    247247
    248         measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
     248        measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    249249        myAssert(measure, "failed to convert ftable to measure data");
    250250   
     
    284284
    285285        // convert internal to external format
    286         if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat)) {
     286        if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat, TRUE)) {
    287287          myAbort("trouble converting format");
    288288        }
     
    467467  gfits_scan (&cptHeaderPHU, "NSECFILT",     "%d",      1,  &Nsecfilt);
    468468
     469  myAbort ("test for compression");
     470
    469471  /* convert internal to external format */
    470   if (!AverageToFtable (&cptFtable, averageOut, NaverageOut, catformat, NULL)) {
     472  if (!AverageToFtable (&cptFtable, averageOut, NaverageOut, catformat, NULL, TRUE)) {
    471473    myAbort("trouble converting format");
    472474  }
     
    529531
    530532    /* convert internal to external format */
    531     if (!SecFiltToFtable (&cpsFtable, secfilt, Nrows, catformat)) {
     533    if (!SecFiltToFtable (&cpsFtable, secfilt, Nrows, catformat, TRUE)) {
    532534      myAbort("trouble converting format");
    533535    }
  • trunk/Ohana/src/dvomerge/src/dvorepairDeleteImagesByExternID.c

    r37807 r38441  
    3838  char *imageFilename = NULL;
    3939
    40   char catformat;
     40  DVOCatFormat catformat;
    4141
    4242  N = get_argument (argc, argv, "-delete-images-by-extern-id");
     
    279279        gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    280280
     281        myAbort ("fix compression");
     282
    281283        // this function can only handle PS1_V5 and later formats
    282284        // NOTE: FtableToMeasure (and equivalent) free the data associated with cpmFtable.
    283285        // We are left with the data in measure.
    284         measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
     286        measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    285287        myAssert(measure, "failed to convert ftable to measure data");
    286288   
     
    331333
    332334        // convert internal to external format
    333         if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat)) {
     335        if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat, TRUE)) {
    334336          myAbort("trouble converting format");
    335337        }
     
    493495
    494496  /* setup image table format and lock */
     497  gfits_db_init (&db);
    495498  db.mode    = dvo_catalog_catmode ("SPLIT");
    496499  db.format  = dvo_catalog_catformat ("PS1_V5");
     
    658661  gfits_scan (&cptHeaderPHU, "NSECFILT",     "%d",      1,  &Nsecfilt);
    659662
     663  myAbort ("test for compression");
     664
    660665  /* convert internal to external format */
    661   if (!AverageToFtable (&cptFtable, averageOut, NaverageOut, catformat, NULL)) {
     666  if (!AverageToFtable (&cptFtable, averageOut, NaverageOut, catformat, NULL, TRUE)) {
    662667    myAbort("trouble converting format");
    663668  }
     
    727732
    728733    /* convert internal to external format */
    729     if (!SecFiltToFtable (&cpsFtable, secfilt, Nrows, catformat)) {
     734    if (!SecFiltToFtable (&cpsFtable, secfilt, Nrows, catformat, TRUE)) {
    730735      myAbort("trouble converting format");
    731736    }
  • trunk/Ohana/src/dvomerge/src/dvorepairFixCPT.c

    r37046 r38441  
    8686  Matrix matrix;
    8787
    88   char catformat;
     88  DVOCatFormat catformat;
    8989
    9090  cpmFtable.header = &cpmHeaderTBL;
     
    120120  }
    121121
    122   measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
     122  myAbort ("fix cpts");
     123  measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    123124  myAssert(measure, "failed to convert ftable to measure data");
    124125
     
    127128
    128129  // convert internal to external format
    129   if (!MeasureToFtable (&cpmFtable, NULL, measure, Nmeasure, catformat)) {
     130  if (!MeasureToFtable (&cpmFtable, NULL, measure, Nmeasure, catformat, TRUE)) {
    130131    myAbort("trouble converting format");
    131132  }
  • trunk/Ohana/src/dvomerge/src/dvorepairFixImages.c

    r37807 r38441  
    255255
    256256  /* setup image table format and lock */
     257  gfits_db_init (oldDB);
    257258  db.mode   = oldDB->mode;
    258259  db.format = oldDB->format;
     
    280281  memset (&db.ftable.buffer[Nx*Nout], ' ', nbytes - Nx*Nout);
    281282
    282   db.swapped = TRUE; // internal representation
     283  db.nativeOrder = TRUE; // internal representation
     284  db.scaledValue = TRUE; // internal representation
    283285
    284286  gfits_modify (&db.header, "NIMAGES", OFF_T_FMT, 1,  Nout);
  • trunk/Ohana/src/dvomerge/src/dvorepairFixTables.c

    r37807 r38441  
    103103
    104104      // convert internal to external format
    105       if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat)) {
     105      if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat, TRUE)) {
    106106        myAbort("trouble converting format");
    107107      }
     
    183183  gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows);
    184184
    185   measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
     185  measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    186186  myAssert(measure, "failed to convert ftable to measure data");
    187187   
     
    326326  gfits_scan (&cptHeaderPHU, "NSECFILT",     "%d",      1,  &Nsecfilt);
    327327
     328  myAbort ("test for compression");
     329
    328330  /* convert internal to external format */
    329   if (!AverageToFtable (&cptFtable, averageOut, NaverageOut, catformat, NULL)) {
     331  if (!AverageToFtable (&cptFtable, averageOut, NaverageOut, catformat, NULL, TRUE)) {
    330332    myAbort("trouble converting format");
    331333  }
     
    388390
    389391    /* convert internal to external format */
    390     if (!SecFiltToFtable (&cpsFtable, secfilt, Nrows, catformat)) {
     392    if (!SecFiltToFtable (&cpsFtable, secfilt, Nrows, catformat, TRUE)) {
    391393      myAbort("trouble converting format");
    392394    }
  • trunk/Ohana/src/dvomerge/src/dvorepairImageVsMeasure.c

    r37046 r38441  
    128128      gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    129129
    130       measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
     130      measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    131131      myAssert(measure, "failed to convert ftable to measure data");
    132132   
  • trunk/Ohana/src/dvomerge/src/dvorepairImagesVsMeasures.c

    r37046 r38441  
    3232  FILE *cpmFile = NULL;
    3333
    34   char catformat;
     34  DVOCatFormat catformat;
    3535
    3636  N = get_argument (argc, argv, "-images-vs-measures");
     
    134134      gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    135135
    136       measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat);
     136      measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    137137      myAssert(measure, "failed to convert ftable to measure data");
    138138   
  • trunk/Ohana/src/dvomerge/src/dvosecfilt_catalogs.c

    r35416 r38441  
    3939    // always load all of the data (if any exists)
    4040    catalog.Nsecfilt  = 0;
    41     catalog.catflags  = LOAD_SECF;  // XXX this will fail for MEF version
     41    catalog.catflags  = DVO_LOAD_SECFILT;  // XXX this will fail for MEF version
    4242    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    4343    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     
    4848    }
    4949
    50     if (catalog.Naves_disk == 0) {
     50    if (catalog.Naverage_disk == 0) {
    5151      dvo_catalog_unlock (&catalog);
    5252      dvo_catalog_free (&catalog);
     
    6464
    6565    insec = catalog.secfilt;
    66     ALLOCATE (outsec, SecFilt, catalog.Naves_disk * Nsecfilt);
     66    ALLOCATE (outsec, SecFilt, catalog.Naverage_disk * Nsecfilt);
    6767
    68     for (k = 0; k < catalog.Naves_disk; k++) {
     68    for (k = 0; k < catalog.Naverage_disk; k++) {
    6969      for (j = 0; (j < catalog.Nsecfilt) && (j < Nsecfilt); j++) {
    7070        outsec[k*Nsecfilt + j] = insec[k*NsecInput + j];
     
    7777    catalog.secfilt = outsec;
    7878    catalog.Nsecfilt = Nsecfilt;
    79     catalog.Nsecf_mem = Nsecfilt * catalog.Naves_disk;
    80     catalog.Nsecf_disk = Nsecfilt * catalog.Naves_disk;
     79    catalog.Nsecfilt_mem = Nsecfilt * catalog.Naverage_disk;
     80    catalog.Nsecfilt_disk = Nsecfilt * catalog.Naverage_disk;
    8181
    8282    dvo_catalog_save (&catalog, VERBOSE);
  • trunk/Ohana/src/dvomerge/src/dvoutils_load_image_index.c

    r37807 r38441  
    8787
    8888  off_t Nimage;
    89   Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     89  Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    9090  if (!image) {
    9191    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/dvomerge/src/dvoutils_uniq_images.c

    r37807 r38441  
    132132      }
    133133      IDlist[n] ++;
     134      if (VERBOSE && (IDlist[n] > 1)) {
     135        fprintf (stderr, "duplicate ext_id %d in file %s\n", extern_id[i], imFile);
     136      }
    134137    }
    135138
  • trunk/Ohana/src/dvomerge/src/dvoverify_utils.c

    r37807 r38441  
    178178  catalog.catformat = DVO_FORMAT_UNDEF; // read-only,do not set the catformat
    179179  catalog.catmode   = DVO_MODE_UNDEF; // read-only, do not set the catmode
    180   catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_LENSING | LOAD_LENSOBJ;
     180  catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ;
    181181  catalog.Nsecfilt  = 0;
    182182 
     
    187187  }
    188188
    189   // Naves_disk == 0 implies an empty catalog file, skip empty catalogs
    190   if (catalog.Naves_disk == 0) {
     189  // Naverage_disk == 0 implies an empty catalog file, skip empty catalogs
     190  if (catalog.Naverage_disk == 0) {
    191191    dvo_catalog_unlock (&catalog);
    192192    dvo_catalog_free (&catalog);
     
    467467
    468468  // load the iage database table
     469  gfits_db_init (&inDB);
    469470  status = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_SOFT);  // shorter timeout?
    470471  if (!status) {
     
    484485  }
    485486
    486   images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.swapped);
     487  images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.scaledValue, &inDB.nativeOrder);
    487488  if (!images) {
    488489    fprintf (stderr, "ERROR: failed to read images from src\n");
  • trunk/Ohana/src/dvomerge/src/merge_catalogs.c

    r27435 r38441  
    5757  output[0].Naverage = Naverage;
    5858  output[0].Nmeasure = Nmeasure;
    59   output[0].Nsecf_mem = Naverage * Nsecfilt;
     59  output[0].Nsecfilt_mem = Naverage * Nsecfilt;
    6060 
    6161  if (VERBOSE) {
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_new.c

    r37814 r38441  
    115115  output[0].Nlensing = Nlensing;
    116116  output[0].Nstarpar = Nstarpar;
    117   output[0].Nsecf_mem = Naverage * NsecfiltOut;
     117  output[0].Nsecfilt_mem = Naverage * NsecfiltOut;
    118118
    119119  // If we are using dvomergeCreate to split an existing catalog, then the max objID in
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r37807 r38441  
    112112
    113113  /* set up pointers for linked list of measure */
    114   if (output[0].sorted && (output[0].Nmeasure >= output[0].Nmeas_disk)) {
     114  if (output[0].sorted && (output[0].Nmeasure >= output[0].Nmeasure_disk)) {
    115115    // this version is only valid if we have done a full catalog load, and if the catalog
    116116    // is sorted while processed
     
    504504  output[0].Nlensing = Nlens;
    505505  output[0].Nstarpar = Nstar;
    506   output[0].Nsecf_mem = Nave*NsecfiltOut;
     506  output[0].Nsecfilt_mem = Nave*NsecfiltOut;
    507507  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);
    508508
  • trunk/Ohana/src/dvopsps/src/insert_FWobjects_dvopsps.c

    r37672 r38441  
    5353    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    5454    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    55     catalog.catflags  = LOAD_AVES | LOAD_SECF | LOAD_LENSOBJ;
     55    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_LENSOBJ;
    5656    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5757
     
    6060      exit (1);
    6161    }
    62     if (!catalog.Naves_disk) {
     62    if (!catalog.Naverage_disk) {
    6363      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    6464      dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps.c

    r37361 r38441  
    6565    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    6666    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    67     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     67    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    6868    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    6969
     
    7272      exit (1);
    7373    }
    74     if (!catalog.Naves_disk) {
     74    if (!catalog.Naverage_disk) {
    7575      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    7676      dvo_catalog_unlock (&catalog);
     
    138138    }
    139139
    140     char command[1024];
    141     snprintf (command, 1024, "dvopsps_client detections -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     140    char *command = NULL;
     141    strextend (&command, "dvopsps_client detections -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    142142              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    143143              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    144144
    145     char tmpline[1024];
    146     snprintf (tmpline, 1024, "%s -dbhost %s", command, DATABASE_HOST); strcpy (command, tmpline);
    147     snprintf (tmpline, 1024, "%s -dbuser %s", command, DATABASE_USER); strcpy (command, tmpline);
    148     snprintf (tmpline, 1024, "%s -dbpass %s", command, DATABASE_PASS); strcpy (command, tmpline);
    149     snprintf (tmpline, 1024, "%s -dbname %s", command, DATABASE_NAME); strcpy (command, tmpline);
    150 
    151     if (VERBOSE)     { snprintf (tmpline, 1024, "%s -v",       command);                          strcpy (command, tmpline); }
    152     if (SAVE_REMOTE) { snprintf (tmpline, 1024, "%s -save %s", command, table->hosts[i].results); strcpy (command, tmpline); }
     145    strextend (&command, "-dbhost %s", DATABASE_HOST);
     146    strextend (&command, "-dbuser %s", DATABASE_USER);
     147    strextend (&command, "-dbpass %s", DATABASE_PASS);
     148    strextend (&command, "-dbname %s", DATABASE_NAME);
     149
     150    if (VERBOSE)     { strextend (&command, "-v");}
     151    if (SAVE_REMOTE) { strextend (&command, "-save %s", table->hosts[i].results);}
    153152
    154153    // some filters -- these are the detections we skip
    155     if (TIME_START) { snprintf (tmpline, 1024, "%s -time-start %s", command, TIME_START); strcpy (command, tmpline); }
    156     if (TIME_END)   { snprintf (tmpline, 1024, "%s -time-end %s",   command, TIME_END);   strcpy (command, tmpline); }
     154    if (TIME_START) { strextend (&command, "-time-start %s", TIME_START);}
     155    if (TIME_END)   { strextend (&command, "-time-end %s", TIME_END);}
    157156   
    158     if (PHOTCODE_START > 0)      { snprintf (tmpline, 1024, "%s -photcode-start %d", command, PHOTCODE_START); strcpy (command, tmpline); }
    159     if (PHOTCODE_END <= INT_MAX) { snprintf (tmpline, 1024, "%s -photcode-end %d",   command, PHOTCODE_END);   strcpy (command, tmpline); }
     157    if (PHOTCODE_START > 0)      { strextend (&command, "-photcode-start %d", PHOTCODE_START);}
     158    if (PHOTCODE_END <= INT_MAX) { strextend (&command, "-photcode-end %d", PHOTCODE_END);}
    160159
    161160    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r38264 r38441  
    11# include "dvopsps.h"
    2 # define DEBUG 1
     2# define DEBUG 0
    33
    44int Ndetections = 0;
  • trunk/Ohana/src/dvopsps/src/insert_diffobj_dvopsps.c

    r37923 r38441  
    5353    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    5454    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    55     catalog.catflags  = LOAD_AVES | LOAD_SECF;
     55    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    5656    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5757
     
    6060      exit (1);
    6161    }
    62     if (!catalog.Naves_disk) {
     62    if (!catalog.Naverage_disk) {
    6363      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    6464      dvo_catalog_unlock (&catalog);
     
    126126    table->hosts[i].pathname = tmppath;
    127127
    128     char command[1024];
    129     snprintf (command, 1024, "dvopsps_client diffobj -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     128    char *command = NULL;
     129    strextend (&command, "dvopsps_client diffobj -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    130130              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    131131              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    132132
    133     char tmpline[1024];
    134     snprintf (tmpline, 1024, "%s -dbhost %s", command, DATABASE_HOST); strcpy (command, tmpline);
    135     snprintf (tmpline, 1024, "%s -dbuser %s", command, DATABASE_USER); strcpy (command, tmpline);
    136     snprintf (tmpline, 1024, "%s -dbpass %s", command, DATABASE_PASS); strcpy (command, tmpline);
    137     snprintf (tmpline, 1024, "%s -dbname %s", command, DATABASE_NAME); strcpy (command, tmpline);
     133    strextend (&command, "-dbhost %s", DATABASE_HOST);
     134    strextend (&command, "-dbuser %s", DATABASE_USER);
     135    strextend (&command, "-dbpass %s", DATABASE_PASS);
     136    strextend (&command, "-dbname %s", DATABASE_NAME);
    138137
    139     if (VERBOSE)    { snprintf (tmpline, 1024, "%s -v",      command);             strcpy (command, tmpline); }
    140     if (SINGLE_CPT) { snprintf (tmpline, 1024, "%s -cpt %s", command, SINGLE_CPT); strcpy (command, tmpline); }
     138    if (VERBOSE)    { strextend (&command, "-v"); }
     139    if (SINGLE_CPT) { strextend (&command, "-cpt %s", SINGLE_CPT); }
    141140
    142141    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/dvopsps/src/insert_objects_dvopsps.c

    r37361 r38441  
    5353    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    5454    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    55     catalog.catflags  = LOAD_AVES | LOAD_SECF;
     55    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    5656    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5757
     
    6060      exit (1);
    6161    }
    62     if (!catalog.Naves_disk) {
     62    if (!catalog.Naverage_disk) {
    6363      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    6464      dvo_catalog_unlock (&catalog);
     
    126126    table->hosts[i].pathname = tmppath;
    127127
    128     char command[1024];
    129     snprintf (command, 1024, "dvopsps_client objects -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     128    char *command = NULL;
     129    strextend (&command, "dvopsps_client objects -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    130130              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    131131              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    132132
    133     char tmpline[1024];
    134     snprintf (tmpline, 1024, "%s -dbhost %s", command, DATABASE_HOST); strcpy (command, tmpline);
    135     snprintf (tmpline, 1024, "%s -dbuser %s", command, DATABASE_USER); strcpy (command, tmpline);
    136     snprintf (tmpline, 1024, "%s -dbpass %s", command, DATABASE_PASS); strcpy (command, tmpline);
    137     snprintf (tmpline, 1024, "%s -dbname %s", command, DATABASE_NAME); strcpy (command, tmpline);
     133    strextend (&command, "-dbhost %s", DATABASE_HOST);
     134    strextend (&command, "-dbuser %s", DATABASE_USER);
     135    strextend (&command, "-dbpass %s", DATABASE_PASS);
     136    strextend (&command, "-dbname %s", DATABASE_NAME);
    138137
    139     if (VERBOSE)    { snprintf (tmpline, 1024, "%s -v",      command);             strcpy (command, tmpline); }
    140     if (SINGLE_CPT) { snprintf (tmpline, 1024, "%s -cpt %s", command, SINGLE_CPT); strcpy (command, tmpline); }
     138    if (VERBOSE)    { strextend (&command, "-v"); }
     139    if (SINGLE_CPT) { strextend (&command, "-cpt %s", SINGLE_CPT); }
    141140
    142141    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/dvosplit/src/dvosplit.c

    r37043 r38441  
    8080    incatalog.filename = skylist[0].filename[i];
    8181    incatalog.Nsecfilt = GetPhotcodeNsecfilt ();
    82     incatalog.catflags = LOAD_NONE;
     82    incatalog.catflags = DVO_LOAD_NONE;
    8383
    8484    // an error exit status here is a significant error
     
    8989
    9090    // skip empty input catalogs
    91     if (!incatalog.Naves_disk) {
     91    if (!incatalog.Naverage_disk) {
    9292      dvo_catalog_unlock (&incatalog);
    9393      dvo_catalog_free (&incatalog);
  • trunk/Ohana/src/dvosplit/src/open_output_catalogs.c

    r33656 r38441  
    1414    outcatalogs[i].filename  = outlist[0].filename[i];
    1515    outcatalogs[i].Nsecfilt  = GetPhotcodeNsecfilt ();
    16     outcatalogs[i].catflags  = LOAD_NONE;
     16    outcatalogs[i].catflags  = DVO_LOAD_NONE;
    1717    outcatalogs[i].catformat = CATFORMAT ? dvo_catalog_catformat (CATFORMAT) : catformat;  // set the default catformat from config data
    1818    outcatalogs[i].catmode   = CATMODE   ? dvo_catalog_catmode (CATMODE)     : catmode;    // set the default catmode from config data
  • trunk/Ohana/src/dvosplit/src/split_averages.c

    r37807 r38441  
    1010  AveLinks *avelinks;
    1111
    12   ALLOCATE (outref, int, incatalog[0].Naves_disk);
    13   ALLOCATE (outcat, int, incatalog[0].Naves_disk);
     12  ALLOCATE (outref, int, incatalog[0].Naverage_disk);
     13  ALLOCATE (outcat, int, incatalog[0].Naverage_disk);
    1414  ALLOCATE (outmem, int, outlist[0].Nregions);
    1515
     
    2525
    2626  // split out the average & secfilt entries:
    27   incatalog[0].catflags = LOAD_AVES | LOAD_SECF;
     27  incatalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    2828
    2929  if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    30     Nblocks = incatalog[0].Naves_disk / NROWS;
    31     if (incatalog[0].Naves_disk % NROWS) Nblocks ++;
     30    Nblocks = incatalog[0].Naverage_disk / NROWS;
     31    if (incatalog[0].Naverage_disk % NROWS) Nblocks ++;
    3232  } else {
    3333    Nblocks = 1;
     
    4040      dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
    4141      fprintf (stderr, "splitting %s (averages) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
    42       assert (block*NROWS == incatalog[0].Naves_off);
     42      assert (block*NROWS == incatalog[0].Naverage_off);
    4343    } else {
    4444      dvo_catalog_load (incatalog, VERBOSE);
     
    4848    // distribute data to the output catalogs
    4949    for (ave = 0; ave < incatalog[0].Naverage; ave++) {
    50       averef = ave + incatalog[0].Naves_off;
     50      averef = ave + incatalog[0].Naverage_off;
    5151       
    5252      inR = incatalog[0].average[ave].R;
     
    7575
    7676      Nout = outcatalogs[Ncat].Naverage;
    77       outref[averef] = Nout + outcatalogs[Ncat].Naves_off;
     77      outref[averef] = Nout + outcatalogs[Ncat].Naverage_off;
    7878      outcat[averef] = Ncat;
    7979
     
    8585      for (n = 0; n < Nsecfilt; n++) {
    8686        outcatalogs[Ncat].secfilt[Nout*Nsecfilt + n] = incatalog[0].secfilt[ave*Nsecfilt + n];
    87         outcatalogs[Ncat].Nsecf_mem++;
     87        outcatalogs[Ncat].Nsecfilt_mem++;
    8888      }
    8989
     
    9696    dvo_catalog_free_data (incatalog);
    9797
    98     // double check the values of Naverage, Nsecf_mem?
     98    // double check the values of Naverage, Nsecfilt_mem?
    9999
    100100    // XXX for output.catformat == MEF, we probably need to skip this stuff and the free below
     
    103103    if (!FULL_TABLE) {
    104104      for (cat = 0; cat < outlist[0].Nregions; cat++) {
    105         outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF;
     105        outcatalogs[cat].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    106106
    107107        dvo_catalog_save (&outcatalogs[cat], VERBOSE);
    108         // fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
     108        // fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecfilt_mem, outcatalogs[cat].Nsecfilt_disk, outcatalogs[cat].Nsecfilt_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
    109109
    110110        // advance the pointers and free the current data
    111111        // XXX these should be done within save segment:
    112         outcatalogs[cat].Naves_disk += outcatalogs[cat].Naverage;
    113         outcatalogs[cat].Naves_off  += outcatalogs[cat].Naverage;
    114         outcatalogs[cat].Nsecf_disk += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
    115         outcatalogs[cat].Nsecf_off  += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
     112        outcatalogs[cat].Naverage_disk += outcatalogs[cat].Naverage;
     113        outcatalogs[cat].Naverage_off  += outcatalogs[cat].Naverage;
     114        outcatalogs[cat].Nsecfilt_disk += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
     115        outcatalogs[cat].Nsecfilt_off  += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
    116116        outcatalogs[cat].Nsecfilt    = Nsecfilt;
    117117
    118118        outcatalogs[cat].Naverage    = 0;
    119         outcatalogs[cat].Nsecf_mem   = 0;
     119        outcatalogs[cat].Nsecfilt_mem   = 0;
    120120      }
    121121    }
  • trunk/Ohana/src/dvosplit/src/split_measures.c

    r37807 r38441  
    1919
    2020  // split out the measure entries:
    21   incatalog[0].catflags = LOAD_MEAS | LOAD_AVES | LOAD_SECF;
     21  incatalog[0].catflags = DVO_LOAD_MEASURE | DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    2222
    2323  // if ((incatalog[0].catformat == DVO_FORMAT_ELIXIR) || (incatalog[0].catformat == DVO_FORMAT_LONEOS)) {
    2424  //   // for these two formats, we need the average and secfilt values around until we do the measures...
    2525  //   // XXX I am loading these 2x -- perhaps I can make the API smarter about reloading?
    26   //   incatalog[0].catflags |= LOAD_AVES | LOAD_SECF;
     26  //   incatalog[0].catflags |= DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    2727  // }
    2828
    2929  if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    30     Nblocks = incatalog[0].Nmeas_disk / NROWS;
    31     if (incatalog[0].Nmeas_disk % NROWS) Nblocks ++;
     30    Nblocks = incatalog[0].Nmeasure_disk / NROWS;
     31    if (incatalog[0].Nmeasure_disk % NROWS) Nblocks ++;
    3232  } else {
    3333    Nblocks = 1;
     
    4040      dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
    4141      fprintf (stderr, "splitting %s (measures) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
    42       assert (block*NROWS == incatalog[0].Nmeas_off);
     42      assert (block*NROWS == incatalog[0].Nmeasure_off);
    4343    } else {
    4444      dvo_catalog_load (incatalog, VERBOSE);
     
    7272    if (!FULL_TABLE) {
    7373      for (cat = 0; cat < outlist[0].Nregions; cat++) {
    74         outcatalogs[cat].catflags = LOAD_MEAS;
     74        outcatalogs[cat].catflags = DVO_LOAD_MEASURE;
    7575        dvo_catalog_save (&outcatalogs[cat], VERBOSE);
    7676
    77         outcatalogs[cat].Nmeas_disk += outcatalogs[cat].Nmeasure;
    78         outcatalogs[cat].Nmeas_off  += outcatalogs[cat].Nmeasure;
     77        outcatalogs[cat].Nmeasure_disk += outcatalogs[cat].Nmeasure;
     78        outcatalogs[cat].Nmeasure_off  += outcatalogs[cat].Nmeasure;
    7979        outcatalogs[cat].Nmeasure    = 0;
    8080      }
     
    8484  if (FULL_TABLE) {
    8585    for (cat = 0; cat < outlist[0].Nregions; cat++) {
    86       outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
     86      outcatalogs[cat].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_MEASURE;
    8787      dvo_catalog_save (&outcatalogs[cat], VERBOSE);
    8888    }
  • trunk/Ohana/src/dvosplit/src/split_missings.c

    r15743 r38441  
    1515
    1616  // split out the missing entries:
    17   incatalog[0].catflags = LOAD_MISS;
    18   Nblocks = incatalog[0].Nmiss_disk / NROWS;
    19   if (incatalog[0].Nmiss_disk % NROWS) Nblocks ++;
     17  incatalog[0].catflags = DVO_LOAD_MISSING;
     18  Nblocks = incatalog[0].Nmissing_disk / NROWS;
     19  if (incatalog[0].Nmissing_disk % NROWS) Nblocks ++;
    2020  for (block = 0; block < Nblocks; block++) {
    2121
     
    3535
    3636    for (cat = 0; cat < outlist[0].Nregions; cat++) {
    37       outcatalogs[cat].catflags = LOAD_MISS;
     37      outcatalogs[cat].catflags = DVO_LOAD_MISSING;
    3838      dvo_catalog_save_segment (&outcatalog[cat], VERBOSE);
    3939
    40       outcatalog[cat].Nmiss_disk += outcatalog[cat].Nmissing;
    41       outcatalog[cat].Nmiss_off  += outcatalog[cat].Nmissing;
     40      outcatalog[cat].Nmissing_disk += outcatalog[cat].Nmissing;
     41      outcatalog[cat].Nmissing_off  += outcatalog[cat].Nmissing;
    4242      outcatalog[cat].Nmissing    = 0;
    4343
  • trunk/Ohana/src/fakeastro/include/fakeastro.h

    r37807 r38441  
    149149double int_gauss (int i);
    150150
    151 int strextend (char *input, char *format,...);
    152 
    153151int fakeastro_images ();
    154152Image *load_template_images (int *nimage);
  • trunk/Ohana/src/fakeastro/src/fakeastro_2mass.c

    r37807 r38441  
    2121    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    2222    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    23     catalog.catflags  = LOAD_AVES | LOAD_SECF | LOAD_MEAS | LOAD_STARPAR;
     23    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_MEASURE | DVO_LOAD_STARPAR;
    2424    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    2525    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     
    2727      exit (1);
    2828    }
    29     if (!catalog.Naves_disk) {
     29    if (!catalog.Naverage_disk) {
    3030        if (VERBOSE2) { fprintf (stderr, "no data in %s, skipping\n", catalog.filename); }
    3131        dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/fakeastro/src/fakeastro_images.c

    r37807 r38441  
    6767
    6868  /* setup image table format and lock */
     69  gfits_db_init (db);
    6970  db->mode    = dvo_catalog_catmode (CATMODE);
    7071  db->format  = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/fakeastro/src/fakestar_catalog.c

    r37807 r38441  
    99  catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    1010  catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    11   catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_STARPAR;
     11  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_STARPAR;
    1212  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    1313   
  • trunk/Ohana/src/fakeastro/src/insert_fakestar.c

    r37814 r38441  
    118118  catalog[0].Naverage  = Nave;
    119119  catalog[0].Nstarpar  = Nstarpar;
    120   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     120  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    121121  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nstarpar: %d "OFF_T_FMT" "OFF_T_FMT" ("OFF_T_FMT" matches)\n",  Nstars, Nave, Nstarpar, Nmatch);
    122122
  • trunk/Ohana/src/fakeastro/src/load_fake_stars.c

    r37807 r38441  
    1515    catalog[i].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    1616    catalog[i].catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    17     catalog[i].catflags  = LOAD_AVES | LOAD_SECF | LOAD_STARPAR;
     17    catalog[i].catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_STARPAR;
    1818    catalog[i].Nsecfilt  = GetPhotcodeNsecfilt ();
    1919    if (!dvo_catalog_open (&catalog[i], skylist[0].regions[i], VERBOSE, "r")) {
     
    2323    dvo_catalog_unlock (&catalog[i]);
    2424
    25     if (!catalog[i].Naves_disk) {
     25    if (!catalog[i].Naverage_disk) {
    2626        if (VERBOSE2) { fprintf (stderr, "no data in %s, skipping\n", catalog[i].filename); }
    2727        dvo_catalog_free (&catalog[i]);
  • trunk/Ohana/src/fakeastro/src/load_template_images.c

    r37807 r38441  
    55  FITS_DB db;
    66
     7  gfits_db_init (&db);
    78  db.mode    = dvo_catalog_catmode (CATMODE);
    89  db.format  = dvo_catalog_catformat (CATFORMAT);
     
    2425
    2526  off_t Nimage;
    26   Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     27  Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    2728  if (!image) {
    2829    fprintf (stderr, "ERROR: no template images in %s (though db exists)\n", IMAGES_INPUT);
  • trunk/Ohana/src/fakeastro/src/match_fake_stars.c

    r37807 r38441  
    282282  catalog[0].Nmeasure = Nmeas;
    283283  catalog[0].Nstarpar = Nstarpar;
    284   catalog[0].Nsecf_mem = Nave*Nsecfilt;
     284  catalog[0].Nsecfilt_mem = Nave*Nsecfilt;
    285285  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);
    286286
  • trunk/Ohana/src/fakeastro/src/save_fake_stars.c

    r37807 r38441  
    2323    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    2424    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    25     // catalog.catflags  = LOAD_AVES | LOAD_SECF | LOAD_MEAS | LOAD_STARPAR; // use this for non-update mode
    26     catalog.catflags  = LOAD_AVES | LOAD_SECF | LOAD_STARPAR;
     25    // catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_MEASURE | DVO_LOAD_STARPAR; // use this for non-update mode
     26    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_STARPAR;
    2727    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    2828
  • trunk/Ohana/src/fakeastro/src/save_fakestars.c

    r37807 r38441  
    4848
    4949    // need to generate the remote command
    50     char command[1024];
    51     snprintf (command, 1024, "fakestar_client");
    52     strextend (command, "-galaxy");
    53     strextend (command, "-hostID %d", host->hostID);
    54     strextend (command, "-D CATDIR %s", CATDIR);
    55     strextend (command, "-hostdir %s", host->pathname);
    56     strextend (command, "-cpt %s", region->name);
    57     strextend (command, "-input %s", filename);
     50    char *command = NULL;
     51    strextend (&command, "fakestar_client");
     52    strextend (&command, "-galaxy");
     53    strextend (&command, "-hostID %d", host->hostID);
     54    strextend (&command, "-D CATDIR %s", CATDIR);
     55    strextend (&command, "-hostdir %s", host->pathname);
     56    strextend (&command, "-cpt %s", region->name);
     57    strextend (&command, "-input %s", filename);
    5858
    5959    // launch the job on the remote machine (no handshake)
     
    7070  return TRUE;
    7171}
    72 
    73 int strextend (char *input, char *format,...) {
    74 
    75   char tmpextra[1024], tmpline[1024];
    76   va_list argp;
    77 
    78   va_start (argp, format);
    79   vsnprintf (tmpextra, 1024, format, argp);
    80   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    81   strcpy (input, tmpline);
    82 
    83   return TRUE;
    84 }
  • trunk/Ohana/src/gastro/src/getptolemy.c

    r25757 r38441  
    2626    // set the parameters which guide catalog open/load/create
    2727    catalog.filename  = skylist[0].filename[i];
    28     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     28    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
    2929    catalog.Nsecfilt  = 0;
    3030
     
    3636    dvo_catalog_unlock (&catalog);
    3737
    38     // Naves_disk == 0 implies an empty catalog file
     38    // Naverage_disk == 0 implies an empty catalog file
    3939    // for only_match, skip empty catalogs
    40     if (!catalog.Naves_disk) {
     40    if (!catalog.Naverage_disk) {
    4141      dvo_catalog_free (&catalog);
    4242      continue;
  • trunk/Ohana/src/gastro2/src/getptolemy.c

    r25757 r38441  
    2828    // set the parameters which guide catalog open/load/create
    2929    catalog.filename  = skylist[0].filename[i];
    30     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     30    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
    3131    catalog.Nsecfilt  = 0;
    3232
     
    3838    dvo_catalog_unlock (&catalog);
    3939
    40     // Naves_disk == 0 implies an empty catalog file
     40    // Naverage_disk == 0 implies an empty catalog file
    4141    // for only_match, skip empty catalogs
    42     if (!catalog.Naves_disk) {
     42    if (!catalog.Naverage_disk) {
    4343      dvo_catalog_free (&catalog);
    4444      continue;
  • trunk/Ohana/src/gastro2/src/rfits.c

    r29001 r38441  
    1414  if (!gfits_fread_ftable (f, &table, "SMPFILE")) goto escape;
    1515
    16   stars = gfits_table_get_SMPData (&table, &Nstars, NULL);
     16  stars = gfits_table_get_SMPData (&table, &Nstars, NULL, NULL);
    1717  if (!stars) {
    1818    fprintf (stderr, "ERROR: failed to read stars\n");
  • trunk/Ohana/src/getstar/src/WriteImageFITS.c

    r14590 r38441  
    3636
    3737  table.header = &theader;
    38   gfits_table_set_SMPData (&table, NULL, Nstars);
     38  gfits_table_set_SMPData (&table, NULL, Nstars, TRUE);
    3939  gfits_fwrite_Theader (f, &theader);
    4040  gfits_fwrite_table   (f, &table);
  • trunk/Ohana/src/getstar/src/dvoImageExtract.c

    r29001 r38441  
    1414  /*** update the image table ***/
    1515  /* setup image table format and lock */
     16  gfits_db_init (&db);
    1617  db.mode   = dvo_catalog_catmode (CATMODE);
    1718  db.format = dvo_catalog_catformat (CATFORMAT);
     
    3132
    3233  // convert database table to internal structure
    33   images = gfits_table_get_Image (&db.ftable, &Nimages, &db.swapped);
     34  images = gfits_table_get_Image (&db.ftable, &Nimages, &db.scaledValue, &db.nativeOrder);
    3435  if (!images) {
    3536    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/getstar/src/dvoImageOverlaps.c

    r29001 r38441  
    1717  /*** update the image table ***/
    1818  /* setup image table format and lock */
     19  gfits_db_init (&db);
    1920  db.mode   = dvo_catalog_catmode (CATMODE);
    2021  db.format = dvo_catalog_catformat (CATFORMAT);
     
    3435
    3536  // convert database table to internal structure
    36   dbImages = gfits_table_get_Image (&db.ftable, &NdbImages, &db.swapped);
     37  dbImages = gfits_table_get_Image (&db.ftable, &NdbImages, &db.scaledValue, &db.nativeOrder);
    3738  if (!dbImages) {
    3839    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c

    r36131 r38441  
    4343    /*** update the image table ***/
    4444    /* setup image table format and lock */
     45    gfits_db_init (&db);
    4546    db.mode   = dvo_catalog_catmode (CATMODE);
    4647    db.format = dvo_catalog_catformat (CATFORMAT);
     
    6061
    6162    // convert database table to internal structure
    62     dbImages = gfits_table_get_Image (&db.ftable, &NdbImages, &db.swapped);
     63    dbImages = gfits_table_get_Image (&db.ftable, &NdbImages, &db.scaledValue, &db.nativeOrder);
    6364    if (!dbImages) {
    6465      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/getstar/src/getstar.c

    r37359 r38441  
    2828  output.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    2929  output.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    30   output.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     30  output.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    3131  output.Nsecfilt  = GetPhotcodeNsecfilt ();
    3232
     
    6363        catalog.filename = skylist[0].filename[i];
    6464        catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    65         catalog.catflags = LOAD_AVES | LOAD_SECF;
    66         catalog.catflags |= needMeas ? LOAD_MEAS : SKIP_MEAS;
     65        catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     66        catalog.catflags |= needMeas ? DVO_LOAD_MEASURE : DVO_SKIP_MEASURE;
    6767
    6868        // an error exit status here is a significant error
     
    7171          exit (2);
    7272        }
    73         if (!catalog.Naves_disk) {
     73        if (!catalog.Naverage_disk) {
    7474          dvo_catalog_unlock (&catalog);
    7575          dvo_catalog_free (&catalog);
     
    9595        catalog.filename = skylist[0].filename[i];
    9696        catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    97         catalog.catflags = LOAD_AVES | LOAD_SECF;
    98         catalog.catflags |= needMeas ? LOAD_MEAS : SKIP_MEAS;
     97        catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     98        catalog.catflags |= needMeas ? DVO_LOAD_MEASURE : DVO_SKIP_MEASURE;
    9999
    100100        // an error exit status here is a significant error
     
    104104        }
    105105        /* skip empty catalogs */
    106         if (!catalog.Naves_disk) continue;
     106        if (!catalog.Naverage_disk) continue;
    107107        stars = select_by_image (&catalog, &image, 0, 0, stars, &Nstars);
    108108      }
  • trunk/Ohana/src/getstar/src/select_by_region.c

    r37044 r38441  
    162162  output[0].Naverage = Nave;
    163163  output[0].Nmeasure = Nmeas;
    164   output[0].Nsecf_mem = Nave*Nsecfilt;
     164  output[0].Nsecfilt_mem = Nave*Nsecfilt;
    165165
    166166  fprintf (stderr, "output catalog has "OFF_T_FMT" stars ("OFF_T_FMT" measures, %d secfilt)\n",
  • trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c

    r37044 r38441  
    111111
    112112  ftable.header = &theader;
    113   gfits_table_set_Getstar_PS1_DEV_0 (&ftable, output, Noutput);
     113  gfits_table_set_Getstar_PS1_DEV_0 (&ftable, output, Noutput, TRUE);
    114114
    115115  gfits_fwrite_header  (f, &header);
  • trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c

    r37044 r38441  
    114114
    115115  ftable.header = &theader;
    116   gfits_table_set_Getstar_PS1_DEV_1 (&ftable, output, Noutput);
     116  gfits_table_set_Getstar_PS1_DEV_1 (&ftable, output, Noutput, TRUE);
    117117
    118118  gfits_fwrite_header  (f, &header);
  • trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c

    r37044 r38441  
    120120
    121121  ftable.header = &theader;
    122   gfits_table_set_Getstar_PS1_DEV_2 (&ftable, output, Noutput);
     122  gfits_table_set_Getstar_PS1_DEV_2 (&ftable, output, Noutput, TRUE);
    123123
    124124  gfits_fwrite_header  (f, &header);
  • trunk/Ohana/src/imclean/src/wfits.c

    r27435 r38441  
    1919   
    2020  table.header = &theader;
    21   gfits_table_set_SMPData (&table, stars, Nstars);
     21  gfits_table_set_SMPData (&table, stars, Nstars, TRUE);
    2222
    2323  gfits_write_header  (filename, header);
  • trunk/Ohana/src/imregister/detrend/delete.c

    r28241 r38441  
    4141  /** we may later want to pull this out and put it elsewhere **/
    4242  /** free db[0].theader, db[0].table.buffer? **/
    43   gfits_table_set_DetReg (&db[0].ftable, subset, Nsubset);
     43  gfits_table_set_DetReg (&db[0].ftable, subset, Nsubset, TRUE);
    4444  gfits_db_save (db);
    4545  gfits_db_close (db);
  • trunk/Ohana/src/imregister/detrend/output.c

    r27435 r38441  
    5050
    5151  ftable.header = &theader;
    52   gfits_table_set_DetReg (&ftable, subset, Nmatch);
     52  gfits_table_set_DetReg (&ftable, subset, Nmatch, TRUE);
    5353
    5454  gfits_fwrite_header  (f, &header);
  • trunk/Ohana/src/imregister/imphot/dumpfits.c

    r37807 r38441  
    3434
    3535  ftable.header = &theader;
    36   // gfits_table_set_Image (&ftable, subset, Nmatch);
     36  // gfits_table_set_Image (&ftable, subset, Nmatch, TRUE);
    3737
    3838  gfits_fwrite_header  (f, &header);
  • trunk/Ohana/src/imregister/imreg/delete.c

    r28241 r38441  
    4141  /** we may later want to pull this out and put it elsewhere **/
    4242  /** free db[0].theader, db[0].table.buffer? **/
    43   gfits_table_set_RegImage (&db[0].ftable, subset, Nsubset);
     43  gfits_table_set_RegImage (&db[0].ftable, subset, Nsubset, TRUE);
    4444  gfits_db_save (db);
    4545  gfits_db_close (db);
  • trunk/Ohana/src/imregister/imreg/imregclient.c

    r34088 r38441  
    6666  if (NoReg) dump_data (image, Nentry);
    6767
     68  gfits_db_init (&db);
    6869  db.lockstate = LCK_HARD;
    6970  db.timeout   = 300.0;
    70   gfits_db_init (&db);
    7171
    7272  if (!gfits_db_lock (&db, TempDB)) {
     
    7777  if (db.dbstate == LCK_EMPTY) {
    7878    gfits_db_create (&db);
    79     gfits_table_set_RegImage (&db.ftable, NULL, 0);
     79    gfits_table_set_RegImage (&db.ftable, NULL, 0, TRUE);
    8080  } else { 
    8181    if (!gfits_db_load (&db)) {
  • trunk/Ohana/src/imregister/imreg/output.c

    r27435 r38441  
    7777
    7878  ftable.header = &theader;
    79   gfits_table_set_RegImage (&ftable, subset, Nmatch);
     79  gfits_table_set_RegImage (&ftable, subset, Nmatch, TRUE);
    8080
    8181  gfits_fwrite_header  (f, &header);
  • trunk/Ohana/src/imregister/photreg/delete.c

    r28241 r38441  
    3838  }
    3939
    40   gfits_table_set_PhotPars (&db[0].ftable, subset, Nsubset);
     40  gfits_table_set_PhotPars (&db[0].ftable, subset, Nsubset, TRUE);
    4141  gfits_db_save (db);
    4242  gfits_db_close (db);
  • trunk/Ohana/src/imregister/photreg/output.c

    r27435 r38441  
    5555
    5656  ftable.header = &theader;
    57   gfits_table_set_PhotPars (&ftable, subset, Nmatch);
     57  gfits_table_set_PhotPars (&ftable, subset, Nmatch, TRUE);
    5858
    5959  /* EXTNAME is set to ZERO_POINTS_3.0 by default */
  • trunk/Ohana/src/imregister/spreg/delete.c

    r28241 r38441  
    3939  /** we may later want to pull this out and put it elsewhere **/
    4040  /** free db[0].theader, db[0].table.buffer? **/
    41   gfits_table_set_Spectrum (&db[0].ftable, subset, Nsubset);
     41  gfits_table_set_Spectrum (&db[0].ftable, subset, Nsubset, TRUE);
    4242  gfits_db_save (db);
    4343  gfits_db_close (db);
  • trunk/Ohana/src/imregister/spreg/output.c

    r27435 r38441  
    6161
    6262  ftable.header = &theader;
    63   gfits_table_set_Spectrum (&ftable, subset, Nmatch);
     63  gfits_table_set_Spectrum (&ftable, subset, Nmatch, TRUE);
    6464
    6565  gfits_fwrite_header   (f, &header);
     
    9696  /* create an empty table which we will fill in by hand */
    9797  ftable.header = &theader;
    98   gfits_table_set_SpectrumASCII (&ftable, NULL, 0);
     98  gfits_table_set_SpectrumASCII (&ftable, NULL, 0, TRUE);
    9999 
    100100  /* add data to table */
  • trunk/Ohana/src/imregister/src/detregister.c

    r7080 r38441  
    1717  SaveEntry (argv[1], &newdata, descriptor.imageID);
    1818
     19  gfits_db_init (&db);
    1920  db.lockstate = LCK_HARD;
    2021  db.timeout   = 300.0;
    21   gfits_db_init (&db);
    2222
    2323  dBFile = set_dBFile ();
     
    2929  if (db.dbstate == LCK_EMPTY) {
    3030    gfits_db_create (&db);   
    31     gfits_table_set_DetReg (&db.ftable, NULL, 0);
     31    gfits_table_set_DetReg (&db.ftable, NULL, 0, TRUE);
    3232  } else { 
    3333    if (!gfits_db_load (&db)) {
  • trunk/Ohana/src/imregister/src/detsearch.c

    r29001 r38441  
    1717  if (output.Criteria) PrintCriteria ();
    1818       
     19  gfits_db_init (&db);
    1920  db.lockstate = (output.Modify || output.Delete) ? LCK_HARD : LCK_SOFT;
    2021  db.timeout   = 300.0;
    21   gfits_db_init (&db);
    2222
    2323  dBFile = set_dBFile ();
     
    3535
    3636  if (!output.Modify && !output.Delete && !output.Altpath) gfits_db_close (&db);
    37   detrend = gfits_table_get_DetReg (&db.ftable, &Ndetrend, &db.swapped);
     37  detrend = gfits_table_get_DetReg (&db.ftable, &Ndetrend, &db.scaledValue, &db.nativeOrder);
    3838  if (!detrend) {
    3939    fprintf (stderr, "ERROR: failed to read detrend info\n");
  • trunk/Ohana/src/imregister/src/imphotsearch.c

    r29001 r38441  
    1414  args (argc, argv);
    1515 
     16  gfits_db_init (&db);
    1617  db.lockstate = (options.modify) ? LCK_HARD : LCK_SOFT;
    1718  db.timeout   = 300.0;
    18   gfits_db_init (&db);
    1919
    2020  /* don't create a new image table if not available */
     
    3232  if (!options.modify) gfits_db_close (&db);
    3333
    34   image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     34  image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    3535  if (!image) {
    3636    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/imregister/src/imregister.c

    r27435 r38441  
    1717  if (NoReg) goto skip_reg;
    1818
     19  gfits_db_init (&db);
    1920  db.lockstate = LCK_HARD;
    2021  db.timeout   = 300.0;
    21   gfits_db_init (&db);
    2222
    2323  if (!gfits_db_lock (&db, ImageDB)) {
     
    2828  if (db.dbstate == LCK_EMPTY) {
    2929    gfits_db_create (&db);
    30     gfits_table_set_RegImage (&db.ftable, NULL, 0);
     30    gfits_table_set_RegImage (&db.ftable, NULL, 0, TRUE);
    3131  } else { 
    3232    if (!gfits_db_load (&db)) {
  • trunk/Ohana/src/imregister/src/imregtable.c

    r29001 r38441  
    3333  gfits_read_ftable  (infile, &ftable, "IMAGE_DATABASE");
    3434
    35   image = gfits_table_get_RegImage (&ftable, &Nimage, NULL);
     35  image = gfits_table_get_RegImage (&ftable, &Nimage, NULL, NULL);
    3636  if (!image) {
    3737    fprintf (stderr, "ERROR: failed to read images\n");
     
    4040
    4141  /* load database table */
     42  gfits_db_init (&db);
    4243  db.lockstate = LCK_HARD;
    4344  db.timeout   = 300.0;
    44   gfits_db_init (&db);
    4545
    4646  if (!gfits_db_lock (&db, ImageDB)) {
     
    5151  if (db.dbstate == LCK_EMPTY) {
    5252    gfits_db_create (&db);
    53     gfits_table_set_RegImage (&db.ftable, NULL, 0);
     53    gfits_table_set_RegImage (&db.ftable, NULL, 0, TRUE);
    5454  } else { 
    5555    if (!gfits_db_load (&db)) {
  • trunk/Ohana/src/imregister/src/imsearch.c

    r29001 r38441  
    1212  args (argc, argv);
    1313
     14  gfits_db_init (&db);
    1415  db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
    1516  db.timeout   = 300.0;
    16   gfits_db_init (&db);
    1717
    1818  if (!gfits_db_lock (&db, ImageDB)) {
     
    2929  if (!output.modify && !output.delete) gfits_db_close (&db);
    3030
    31   image = gfits_table_get_RegImage (&db.ftable, &Nimage, &db.swapped);
     31  image = gfits_table_get_RegImage (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    3232  if (!image) {
    3333    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/imregister/src/imstatreg.c

    r29001 r38441  
    4040  }
    4141
     42  gfits_db_init (&image_db);
    4243  image_db.lockstate = LCK_HARD;
    4344  image_db.timeout   = 300.0;
    44   gfits_db_init (&image_db);
    4545
    4646  temp_db.lockstate = LCK_HARD;
     
    6666      exit (1);
    6767    }
    68     subset = gfits_table_get_RegImage (&temp_db.ftable, &Nsubset, &temp_db.swapped);
     68    subset = gfits_table_get_RegImage (&temp_db.ftable, &Nsubset, &temp_db.scaledValue, &temp_db.nativeOrder);
    6969    if (!subset) {
    7070      fprintf (stderr, "ERROR: failed to read images\n");
     
    9696         we will just drop the temp db data */
    9797    }
    98     image = gfits_table_get_RegImage (&image_db.ftable, &Nimage, &image_db.swapped);
     98    image = gfits_table_get_RegImage (&image_db.ftable, &Nimage, &image_db.scaledValue, &image_db.nativeOrder);
    9999    if (!image) {
    100100      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/imregister/src/photreg.c

    r7080 r38441  
    1212  regargs (argc, argv, &newdata);
    1313
     14  gfits_db_init (&db);
    1415  db.lockstate = LCK_HARD;
    1516  db.timeout   = 300.0;
    16   gfits_db_init (&db);
    1717
    1818  filename = PhotDB;
     
    2626  if (db.dbstate == LCK_EMPTY) {
    2727    gfits_db_create (&db);
    28     gfits_table_set_PhotPars (&db.ftable, NULL, 0);
     28    gfits_table_set_PhotPars (&db.ftable, NULL, 0, TRUE);
    2929    /* EXTNAME is set to ZERO_POINTS_3.0 by default */
    3030    if (!strcmp (output.db, "trans")) {
  • trunk/Ohana/src/imregister/src/photsearch.c

    r29001 r38441  
    1515  args (argc, argv);
    1616
     17  gfits_db_init (&db);
    1718  db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
    1819  db.timeout   = 300.0;
    19   gfits_db_init (&db);
    2020
    2121  if (!strcmp (output.db, "phot")) {
     
    4141  /* add test to EXTNAME? */
    4242  if (output.convert) {
    43     photpars_old = gfits_table_get_PhotParsOld (&db.ftable, &Nphotpars, &db.swapped);
     43    photpars_old = gfits_table_get_PhotParsOld (&db.ftable, &Nphotpars, &db.scaledValue, &db.nativeOrder);
    4444    if (!photpars_old) {
    4545      fprintf (stderr, "ERROR: failed to read photometry parameters\n");
     
    4848    photpars = PhotParsOld_to_PhotPars (photpars_old, Nphotpars);
    4949  } else {
    50     photpars = gfits_table_get_PhotPars (&db.ftable, &Nphotpars, &db.swapped);
     50    photpars = gfits_table_get_PhotPars (&db.ftable, &Nphotpars, &db.scaledValue, &db.nativeOrder);
    5151    if (!photpars) {
    5252      fprintf (stderr, "ERROR: failed to read photometry parameters\n");
  • trunk/Ohana/src/imregister/src/spregister.c

    r7080 r38441  
    1717  if (NoReg) exit (0);
    1818
     19  gfits_db_init (&db);
    1920  db.lockstate = LCK_HARD;
    2021  db.timeout   = 300.0;
    21   gfits_db_init (&db);
    2222
    2323  if (!gfits_db_lock (&db, SpectrumDB)) {
     
    2828  if (db.dbstate == LCK_EMPTY) {
    2929    gfits_db_create (&db);
    30     gfits_table_set_Spectrum (&db.ftable, NULL, 0);
     30    gfits_table_set_Spectrum (&db.ftable, NULL, 0, TRUE);
    3131  } else { 
    3232    if (!gfits_db_load (&db)) {
  • trunk/Ohana/src/imregister/src/spsearch.c

    r29001 r38441  
    1212  args (argc, argv);
    1313
     14  gfits_db_init (&db);
    1415  db.lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
    1516  db.timeout   = 300.0;
    16   gfits_db_init (&db);
    1717
    1818  if (!gfits_db_lock (&db, SpectrumDB)) {
     
    2929  if (!output.modify && !output.delete) gfits_db_close (&db);
    3030
    31   spectrum = gfits_table_get_Spectrum (&db.ftable, &Nspectrum, &db.swapped);
     31  spectrum = gfits_table_get_Spectrum (&db.ftable, &Nspectrum, &db.scaledValue, &db.nativeOrder);
    3232  if (!spectrum) {
    3333    fprintf (stderr, "ERROR: failed to read spectrum\n");
  • trunk/Ohana/src/libautocode/Makefile.Targets

    r38153 r38441  
    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 \
    5759$(ASRC)/missing.$(ARCH).o \
    5860$(ASRC)/photcode.$(ARCH).o \
     
    165167$(AINC)/starpar-ps1-v5.h \
    166168$(AINC)/starpar-ps1-sim.h \
     169$(AINC)/galshape.h \
     170$(AINC)/galshape-ps1-v5.h \
    167171$(AINC)/missing.h \
    168172$(AINC)/photcode.h \
  • trunk/Ohana/src/libautocode/def/autocode.c

    r29537 r38441  
    2727/*** add test of EXTNAME and header-defined columns? ***/
    2828/* return internal structure representation */
    29 $STRUCT *gfits_table_get_$STRUCT (FTable *ftable, off_t *Ndata, char *swapped) {
     29/* scaledData & nativeBytes describe the current state of the ftable.buffer */
     30$STRUCT *gfits_table_get_$STRUCT (FTable *ftable, off_t *Ndata, char *scaledValue, char *nativeOrder) {
    3031
    3132  int Ncols;
     
    4041  *Ndata = ftable[0].header[0].Naxis[1];
    4142  data = ($STRUCT *) ftable[0].buffer;
    42   if ((swapped == NULL) || (*swapped == FALSE)) {
     43
     44  // if the pointer is not passed, we need to swap
     45  if (!nativeOrder || !*nativeOrder) {
    4346    if (!gfits_convert_$STRUCT (data, sizeof ($STRUCT), *Ndata)) {
    4447      return NULL;
    4548    }
     49    if (nativeOrder) *nativeOrder = TRUE;
     50  }
     51  // if the pointer is not passed, we need to scale
     52  if (!scaledValue || !*scaledValue) {
    4653    gfits_table_scale_data (ftable);
    47     if (swapped != NULL) *swapped = TRUE;
     54    if (scaledValue) *scaledValue = TRUE;
    4855  }
    4956  return (data);
    5057}
    5158
    52 int gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, off_t Ndata) {
     59int gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, off_t Ndata, int swapFromNative) {
    5360
    5461  Header *header;
     
    6774  /* add data values */
    6875  if (!gfits_table_scale_data (ftable)) return (FALSE);
    69   if (!gfits_convert_$STRUCT (data, sizeof ($STRUCT), Ndata)) return (FALSE);
     76  if (swapFromNative) {
     77    if (!gfits_convert_$STRUCT (data, sizeof ($STRUCT), Ndata)) return (FALSE);
     78  }
    7079  if (!gfits_add_rows (ftable, (char *) data, Ndata, sizeof ($STRUCT))) return (FALSE);
    7180
  • trunk/Ohana/src/libautocode/def/autocode.h

    r27435 r38441  
    22/** STRUCT DEFINITION **/
    33
    4 $STRUCT *gfits_table_get_$STRUCT (FTable *table, off_t *Ndata, char *swapped);
    5 int      gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, off_t Ndata);
     4$STRUCT *gfits_table_get_$STRUCT (FTable *table, off_t *Ndata, char *scaledValue, char *nativeOrder);
     5int      gfits_table_set_$STRUCT (FTable *ftable, $STRUCT *data, off_t Ndata, int swapFromNative);
    66int      gfits_table_mkheader_$STRUCT (Header *header);
    77int      gfits_convert_$STRUCT ($STRUCT *data, off_t size, off_t nitems);
  • trunk/Ohana/src/libautocode/def/average-ps1-v1.d

    r36833 r38441  
    2626FIELD Nmeasure,       NMEASURE,    unsigned short,  number of psf measurements
    2727FIELD Nmissing,       NMISSING,    unsigned short,  number of missings
    28 FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
     28FIELD Ngalphot,      NGALPHOT,   unsigned short,  number of galphot measurements
    2929
    3030FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
  • trunk/Ohana/src/libautocode/def/average-ps1-v2.d

    r36833 r38441  
    3131FIELD Nmeasure,       NMEASURE,    unsigned short,  number of psf measurements
    3232FIELD Nmissing,       NMISSING,    unsigned short,  number of missings
    33 FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
     33FIELD Ngalphot,      NGALPHOT,   unsigned short,  number of galphot measurements
    3434
    3535FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
  • trunk/Ohana/src/libautocode/def/average-ps1-v3.d

    r36833 r38441  
    3131FIELD Nmeasure,       NMEASURE,    unsigned short,  number of psf measurements
    3232FIELD Nmissing,       NMISSING,    unsigned short,  number of missings
    33 FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
     33FIELD Ngalphot,      NGALPHOT,   unsigned short,  number of galphot measurements
    3434
    3535FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
  • trunk/Ohana/src/libautocode/def/average-ps1-v4.d

    r36833 r38441  
    3434FIELD Nmeasure,       NMEASURE,    unsigned short,  number of psf measurements
    3535FIELD Nmissing,       NMISSING,    unsigned short,  number of missings
    36 FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
     36FIELD Ngalphot,      NGALPHOT,   unsigned short,  number of galphotd measurements
    3737
    3838FIELD measureOffset,  OFF_MEASURE, uint32_t,        offset to first psf measurement
  • trunk/Ohana/src/libautocode/def/average-ps1-v5.d

    r37807 r38441  
    4141FIELD Nlensing,       NLENSING,    unsigned short,  number of lensing measurements
    4242FIELD Nlensobj,       NLENSOBJ,    unsigned short,  number of lensing measurements
    43 FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
     43FIELD Ngalphot,      NGALPHOT,   unsigned short,  number of galphot measurements
    4444
    45 FIELD measureOffset,  OFF_MEASURE, int,             offset to first psf measurement
    46 FIELD missingOffset,  OFF_MISSING, int,             offset to first missing obs
    47 FIELD lensingOffset,  OFF_LENSING, int,             offset to first lensing obs
    48 FIELD lensobjOffset,  OFF_LENSOBJ, int,             offset to mean lensing data
    49 FIELD starparOffset,  OFF_STARPAR, int,             offset to stellar parameter data
    50 FIELD extendOffset,   OFF_EXTEND,  int,             offset to extended object entry
     45FIELD measureOffset,  OFF_MEASURE,  int,            offset to first psf measurement
     46FIELD missingOffset,  OFF_MISSING,  int,            offset to first missing obs
     47FIELD lensingOffset,  OFF_LENSING,  int,            offset to first lensing obs
     48FIELD lensobjOffset,  OFF_LENSOBJ,  int,            offset to mean lensing data
     49FIELD starparOffset,  OFF_STARPAR,  int,            offset to stellar parameter data
     50FIELD galphotOffset, OFF_GALPHOT, int,              offset to galphot object entry
    5151
    5252FIELD refColorBlue,   REF_COLOR_BLUE, float,        color of astrometry ref stars
  • trunk/Ohana/src/libautocode/def/average.d

    r37807 r38441  
    4141FIELD Nlensing,       NLENSING,    unsigned short,  number of lensing measurements
    4242FIELD Nlensobj,       NLENSOBJ,    unsigned short,  number of lensing measurements
    43 FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
     43FIELD Ngalphot,      NGALPHOT,   unsigned short,  number of galphot measurements
    4444
    45 FIELD measureOffset,  OFF_MEASURE, int,             offset to first psf measurement
    46 FIELD missingOffset,  OFF_MISSING, int,             offset to first missing obs
    47 FIELD lensingOffset,  OFF_LENSING, int,             offset to first lensing obs
    48 FIELD lensobjOffset,  OFF_LENSOBJ, int,             offset to mean lensing data
    49 FIELD starparOffset,  OFF_STARPAR, int,             offset to stellar parameter data
    50 FIELD extendOffset,   OFF_EXTEND, int,             offset to extended object entry
     45FIELD measureOffset,  OFF_MEASURE,  int,             offset to first psf measurement
     46FIELD missingOffset,  OFF_MISSING,  int,             offset to first missing obs
     47FIELD lensingOffset,  OFF_LENSING,  int,            offset to first lensing obs
     48FIELD lensobjOffset,  OFF_LENSOBJ,  int,            offset to mean lensing data
     49FIELD starparOffset,  OFF_STARPAR,  int,            offset to stellar parameter data
     50FIELD galphotOffset, OFF_GALPHOT, int,              offset to extended object entry
    5151
    5252FIELD refColorBlue,   REF_COLOR_BLUE, float,        color of astrometry ref stars
  • trunk/Ohana/src/libdvo/Makefile

    r37992 r38441  
    1010MAN     =       $(HOME)/doc
    1111INC     =       $(HOME)/include
     12TEST    =       $(HOME)/test
     13TESTBIN =       $(HOME)/test
    1214ASRC    =       $(AUTO)/src
    1315AINC    =       $(AUTO)/include
     
    153155        rm -f $@
    154156        cp $< $@
     157        echo "done making autocode.h"
    155158
    156159$(AINC)/autocode.h: $(AINCS) $(ADEF)/autocode.h $(ADEF)/common.h
  • trunk/Ohana/src/libdvo/include/dvo.h

    r38154 r38441  
    1010
    1111/* DVO table modes */
    12 typedef enum {DVO_MODE_UNDEF, DVO_MODE_RAW, DVO_MODE_MEF, DVO_MODE_SPLIT, DVO_MODE_MYSQL} DVOTableMode;
     12typedef enum {DVO_MODE_UNDEF = 0, DVO_MODE_RAW, DVO_MODE_MEF, DVO_MODE_SPLIT, DVO_MODE_MYSQL} DVOCatMode;
     13
     14/* DVO table modes */
     15typedef enum {DVO_COMPRESS_NONE = 0, DVO_COMPRESS_NONE_1, DVO_COMPRESS_NONE_2, DVO_COMPRESS_AUTO, DVO_COMPRESS_GZIP_1, DVO_COMPRESS_GZIP_2, DVO_COMPRESS_RICE_1} DVOCatCompress; //
    1316
    1417/* DVO table formats */
    1518typedef enum {
    16   DVO_FORMAT_UNDEF,
     19  DVO_FORMAT_UNDEF = 0,
    1720  DVO_FORMAT_INTERNAL,
    1821  DVO_FORMAT_ELIXIR,
     
    3033  DVO_FORMAT_PS1_V4,
    3134  DVO_FORMAT_PS1_V5,
    32 } DVOTableFormat;
     35} DVOCatFormat;
     36
     37typedef enum {DVO_CAT_OPEN_FAIL, DVO_CAT_OPEN_OK, DVO_CAT_OPEN_EMPTY} DVOCatalogOpenModes;
     38
     39/* catalog values to be loaded */
     40typedef enum {
     41  DVO_LOAD_NONE     = 0x0000,
     42  DVO_LOAD_AVERAGE  = 0x0001,
     43  DVO_LOAD_MEASURE  = 0x0002,
     44  DVO_LOAD_MISSING  = 0x0004,
     45  DVO_LOAD_SECFILT  = 0x0008,
     46  DVO_SKIP_AVERAGE  = 0x0010,
     47  DVO_SKIP_MEASURE  = 0x0020,
     48  DVO_SKIP_MISSING  = 0x0040,
     49  DVO_SKIP_SECFILT  = 0x0080,
     50  DVO_LOAD_LENSING  = 0x0100,
     51  DVO_LOAD_LENSOBJ  = 0x0200,
     52  DVO_SKIP_LENSING  = 0x0400,
     53  DVO_SKIP_LENSOBJ  = 0x0800,
     54  DVO_LOAD_STARPAR  = 0x1000,
     55  DVO_SKIP_STARPAR  = 0x2000,
     56  DVO_LOAD_GALPHOT = 0x4000,
     57  DVO_SKIP_GALPHOT = 0x8000,
     58} DVOCatFlags;
    3359
    3460/* image data modes in RegImage */
    3561typedef enum {T_UNDEF = -1, T_NONE, T_OBJECT, T_DARK, T_BIAS, T_FLAT, T_MASK, T_FRINGE, T_SCATTER, T_MODES, T_FRINGEPTS, T_ANY, N_TYPE} ElixirDetrendTypes;
    3662typedef enum {M_UNDEF = -1, M_NONE, M_MEF, M_SPLIT, M_SINGLE, M_CUBE, M_SLICE, M_MODES, N_MODE} ElixirDetrendModes;
    37 
    38 typedef enum {DVO_CAT_OPEN_FAIL, DVO_CAT_OPEN_OK, DVO_CAT_OPEN_EMPTY} DVOCatalogOpenModes;
    3963
    4064// these are used as NAN for types of int values
     
    5478# define IMREG_DIST  0x01 /* image distributed, only imregister-3.0 */
    5579
    56 /* catalog values to be loaded */
    57 # define LOAD_NONE      0x0000
    58 # define LOAD_AVES      0x0001
    59 # define LOAD_MEAS      0x0002
    60 # define LOAD_MISS      0x0004
    61 # define LOAD_SECF      0x0008
    62 # define SKIP_AVES      0x0010
    63 # define SKIP_MEAS      0x0020
    64 # define SKIP_MISS      0x0040
    65 # define SKIP_SECF      0x0080
    66 # define LOAD_LENSING   0x0100
    67 # define LOAD_LENSOBJ   0x0200
    68 # define SKIP_LENSING   0x0400
    69 # define SKIP_LENSOBJ   0x0800
    70 # define LOAD_STARPAR   0x1000
    71 # define SKIP_STARPAR   0x2000
    72 
    7380/* photometry code types */
    7481// # define PHOT_PRI 0x01
    75 # define PHOT_SEC 0x02
    76 # define PHOT_DEP 0x03
    77 # define PHOT_REF 0x04
    78 # define PHOT_ALT 0x05  /* never stored, only for look-ups */
    79 # define PHOT_MAG 0x06  /* generic magnitude; never stored */
     82typedef enum {
     83  PHOT_SEC  = 0x02,
     84  PHOT_DEP  = 0x03,
     85  PHOT_REF  = 0x04,
     86  PHOT_ALT  = 0x05,  /* never stored, only for look-ups */
     87  PHOT_MAG  = 0x06,  /* generic magnitude; never stored */
     88} DVOPhotCodeTypes;
    8089
    8190/* Image.code values -- these values are 32 bit (as of PS1_V1) */
     
    222231  char   lockstate;
    223232  char   mode;          /* what data storage mode is used for disk file? */
    224   char   format;        /* what data format is used for disk file? */
     233  DVOCatFormat format;  /* what data format is used for disk file? */
    225234  char   virtual;       /* is table in ftable or vtable? */
    226   char   swapped;       /* is table in internal byte-order? */
     235  char   nativeOrder;   /* is table in internal byte-order? */
     236  char   scaledValue;   /* is table in internal byte-order? */
    227237} FITS_DB;
    228238
     
    484494  unsigned short   Nmeasure;             // number of psf measurements
    485495  unsigned short   Nmissing;             // number of missings
    486   unsigned short   Nextend;              // number of extended measurements
     496  unsigned short   Ngalphot;            // number of extended measurements
    487497  uint32_t         measureOffset;        // offset to first psf measurement
    488498  uint32_t         missingOffset;        // offset to first missing obs
     
    704714  unsigned short   Nlensing;             // number of lensing measurements
    705715  unsigned short   Nlensobj;             // number of lensing measurements
    706   unsigned short   Nextend;              // number of extended measurements
     716  unsigned short   Ngalphot;            // number of galphot measurements
    707717  int              measureOffset;        // offset to first psf measurement
    708718  int              missingOffset;        // offset to first missing obs
    709719  int              lensingOffset;        // offset to first lensing obs
    710720  int              lensobjOffset;        // offset to mean lensing data
    711   int              extendOffset;         // offset to extended object entry
     721  int              galphotOffset;       // offset to extended object entry
    712722  int              starparOffset;        // offset to stellar parameter data
    713723  float            refColorBlue;         // color of astrometry ref stars
     
    742752
    743753  // lensing data (optional?)
    744   Lensing *lensing;
    745   Lensobj *lensobj;
    746   StarPar *starpar;
     754  Lensing  *lensing;
     755  Lensobj  *lensobj;
     756  StarPar  *starpar;
     757  GalPhot *galphot;
    747758
    748759  int Nsecfilt;  /* number of secfilt entries for each average entry */
    749   off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nstarpar,      Nsecf_mem;  /* current number of each component in memory */
    750   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nstarpar_disk, Nsecf_disk; /* current number of each component on disk */
    751   off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nstarpar_off,  Nsecf_off;  /* index of first loaded data value */
     760  off_t Naverage,      Nmeasure,      Nmissing,      Nlensing,      Nlensobj,      Nstarpar,      Ngalphot,      Nsecfilt_mem;  /* current number of each component in memory */
     761  off_t Naverage_disk, Nmeasure_disk, Nmissing_disk, Nlensing_disk, Nlensobj_disk, Nstarpar_disk, Ngalphot_disk, Nsecfilt_disk; /* current number of each component on disk */
     762  off_t Naverage_off,  Nmeasure_off,  Nmissing_off,  Nlensing_off,  Nlensobj_off,  Nstarpar_off,  Ngalphot_off,  Nsecfilt_off;  /* index of first loaded data value */
    752763
    753764  // note that we use these for the full-sky relphot analysis
     
    765776
    766777  /* pointers to split data files */
    767   struct Catalog *measure_catalog;              /* measure catalog data (split) */
    768   struct Catalog *missing_catalog;              /* missing catalog data (split) */
    769   struct Catalog *secfilt_catalog;              /* secfilt catalog data (split) */
    770   struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
    771   struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
    772   struct Catalog *starpar_catalog;              /* starpar catalog data (split) */
     778  struct Catalog *measure_catalog;              /* measure  catalog data (split) */
     779  struct Catalog *missing_catalog;              /* missing  catalog data (split) */
     780  struct Catalog *secfilt_catalog;              /* secfilt  catalog data (split) */
     781  struct Catalog *lensing_catalog;              /* lensing  catalog data (split) */
     782  struct Catalog *lensobj_catalog;              /* lensobj  catalog data (split) */
     783  struct Catalog *starpar_catalog;              /* starpar  catalog data (split) */
     784  struct Catalog *galphot_catalog;              /* galphot catalog data (split) */
    773785
    774786  unsigned int objID;
     
    777789  /* extra catalog information */
    778790  char lockmode;
    779   char catmode;                         /* storage mode (raw, mef, split, mysql) */
    780   char catformat;                       /* storage format (elixir, panstarrs, etc) */
     791  DVOCatMode     catmode;     /* storage mode (raw, mef, split, mysql) */
     792  DVOCatFormat   catformat;                     /* storage format (elixir, panstarrs, etc) */
     793  DVOCatCompress catcompress;                   // output compress mode
     794  DVOCatFlags    catflags;                      /* choices to be loaded */
     795 
    781796  int sorted;                           /* is measure table average-sorted? (NOTE this is an int only because gfits_scan %t requires it) */
    782  
    783   short catflags; /* choices to be loaded */
     797
    784798
    785799  /* pointers for data manipulation */
     
    928942int dvo_catalog_save_complete (Catalog *catalog, char VERBOSE);
    929943int dvo_catalog_update (Catalog *catalog, char VERBOSE);
    930 int dvo_catalog_catformat (char *catformat);
    931 int dvo_catalog_catmode (char *catmode);
     944DVOCatFormat dvo_catalog_catformat (char *catformat);
     945DVOCatMode dvo_catalog_catmode (char *catmode);
     946DVOCatCompress dvo_catalog_catcompress (char *catcompress);
     947char *dvo_catalog_compress_string (DVOCatCompress catcompress);
    932948void dvo_catalog_test (Catalog *catalog, int halt);
    933949
     
    956972int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format);
    957973
    958 DVOTableFormat FtableGetFormat (FTable *ftable);
    959 
    960 Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary);
    961 Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format);
    962 SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format);
    963 Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
    964 Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
    965 StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format);
    966 int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    967 
    968 int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, char format, SecFilt *primary);
    969 int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format);
    970 int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format);
    971 int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
    972 int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
    973 int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format);
    974 int ImageToFtable (FTable *ftable, Header *theader, char format);
    975 int ImageToVtable (VTable *vtable, Header *theader, char format);
     974DVOCatFormat FtableGetFormat (FTable *ftable);
     975
     976Average *FtableToAverage   (FTable *ftable, off_t *Naverage,  DVOCatFormat *format, SecFilt **primary, char nativeOrder);
     977
     978Measure *FtableToMeasure   (FTable *ftable, Average *average, off_t *Nmeasure,  DVOCatFormat *format, char nativeOrder);
     979Missing *FtableToMissing   (FTable *ftable, Average *average, off_t *Nmissing,  DVOCatFormat *format, char nativeBytes);
     980SecFilt *FtableToSecFilt   (FTable *ftable, Average *average, off_t *Nsecfilt,  DVOCatFormat *format, char nativeOrder);
     981Lensing *FtableToLensing   (FTable *ftable, Average *average, off_t *Nlensing,  DVOCatFormat *format, char nativeOrder);
     982Lensobj *FtableToLensobj   (FTable *ftable, Average *average, off_t *Nlensobj,  DVOCatFormat *format, char nativeOrder);
     983StarPar *FtableToStarPar   (FTable *ftable, Average *average, off_t *Nstarpar,  DVOCatFormat *format, char nativeOrder);
     984GalPhot *FtableToGalPhot (FTable *ftable, Average *average, off_t *Ngalphot, DVOCatFormat *format, char nativeOrder);
     985
     986int      FtableToImage   (FTable *ftable, Header *theader, DVOCatFormat *format);
     987
     988int MeasureToFtable  (FTable *ftable, Average  *average,  Measure *measure, off_t Nmeasure, DVOCatFormat format, int swapFromNative);
     989int AverageToFtable  (FTable *ftable, Average  *average,  off_t Naverage,  DVOCatFormat format, SecFilt *primary, int swapFromNative);
     990int SecFiltToFtable  (FTable *ftable, SecFilt  *secfilt,  off_t Nsecfilt,  DVOCatFormat format, int swapFromNative);
     991int LensingToFtable  (FTable *ftable, Lensing  *lensing,  off_t Nlensing,  DVOCatFormat format, int swapFromNative);
     992int LensobjToFtable  (FTable *ftable, Lensobj  *lensobj,  off_t Nlensobj,  DVOCatFormat format, int swapFromNative);
     993int StarParToFtable  (FTable *ftable, StarPar  *starpar,  off_t Nstarpar,  DVOCatFormat format, int swapFromNative);
     994int GalPhotToFtable (FTable *ftable, GalPhot *galphot, off_t Ngalphot, DVOCatFormat format, int swapFromNative);
     995
     996int ImageToFtable (FTable *ftable, Header *theader, DVOCatFormat format);
     997int ImageToVtable (VTable *vtable, Header *theader, DVOCatFormat format);
    976998
    977999# include "loneos_defs.h"
     
    10051027int gfits_table_set_Image (FTable *ftable);
    10061028int gfits_table_mkheader_Image (Header *header);
    1007 Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped);
     1029Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *scaledValue, char *nativeOrder);
    10081030
    10091031/* flatcorr APIs */
     
    10691091void InitHost (HostInfo *host);
    10701092
    1071 HostTableGroup *HostTableGroups (HostTable *table, int *ngroups);
     1093HostTableGroup *HostTableGroupsUniqueMachines (HostTable *table, int *ngroups);
     1094HostTableGroup *HostTableGroupsMaxNumber (HostTable *table, int *ngroups, int Nmax);
     1095
    10721096int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE);
    10731097
     
    11061130void dvo_lensobj_init (Lensobj *lensobj, int toZero);
    11071131void dvo_starpar_init (StarPar *starpar);
     1132void dvo_galphot_init (GalPhot *galphot);
    11081133
    11091134void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
  • trunk/Ohana/src/libdvo/include/ps1_v5_defs.h

    r38153 r38441  
    2323StarPar_PS1_V5          *StarParInternalTo_PS1_V5 (StarPar *in, off_t Nvalues);
    2424
     25GalPhot                 *GalPhot_PS1_V5_ToInternal (GalPhot_PS1_V5 *in, off_t Nvalues);
     26GalPhot_PS1_V5         *GalPhotInternalTo_PS1_V5 (GalPhot *in, off_t Nvalues);
     27
    2528PhotCode                *PhotCode_PS1_V5_To_Internal (PhotCode_PS1_V5 *in, off_t Nvalues);
    2629PhotCode_PS1_V5         *PhotCode_Internal_To_PS1_V5 (PhotCode *in, off_t Nvalues);
  • trunk/Ohana/src/libdvo/src/AstromOffsetMapIO.c

    r37807 r38441  
    3939    return (NULL);
    4040  }
    41   AstromOffsetMap_Disk_6x6 *map_disk = gfits_table_get_AstromOffsetMap_Disk_6x6 (&ftable, &Nmap, NULL);
     41  AstromOffsetMap_Disk_6x6 *map_disk = gfits_table_get_AstromOffsetMap_Disk_6x6 (&ftable, &Nmap, NULL, NULL);
    4242  if (!map_disk) {
    4343    fprintf (stderr, "ERROR: failed to read Astrom Offset Map\n");
     
    7878
    7979  ftable.header = &theader;
    80   gfits_table_set_AstromOffsetMap_Disk_6x6 (&ftable, map_disk, Nmap);
     80  gfits_table_set_AstromOffsetMap_Disk_6x6 (&ftable, map_disk, Nmap, TRUE);
    8181
    8282  f = fopen (filename, "w");
  • trunk/Ohana/src/libdvo/src/HostTable.c

    r37807 r38441  
    155155
    156156// split a host table into Ngroups, each with a unique set of hosts
    157 HostTableGroup *HostTableGroups (HostTable *table, int *ngroups) {
     157HostTableGroup *HostTableGroupsUniqueMachines (HostTable *table, int *ngroups) {
    158158
    159159  // identify the unique host names and the number of times they each exist
     
    210210        foundHost[k] = TRUE;
    211211      }
     212    }
     213  }
     214  *ngroups = Ngroups;
     215  return groups;
     216}
     217
     218// split a host table into Ngroups, each with a unique set of hosts
     219HostTableGroup *HostTableGroupsMaxNumber (HostTable *table, int *ngroups, int Nmax) {
     220
     221  int i, j;
     222
     223  int Ngroups = (table->Nhosts % Nmax) ? (int)(table->Nhosts / Nmax + 1) : table->Nhosts / Nmax;
     224
     225  HostTableGroup *groups = NULL;
     226  ALLOCATE (groups, HostTableGroup, Ngroups);
     227
     228  // in each group, attempt to add one of each unique host
     229  int k = 0;
     230  for (i = 0; i < Ngroups; i++) {
     231    groups[i].Nhosts = 0;
     232    ALLOCATE (groups[i].hosts, HostInfo *, Nmax);
     233    for (j = 0; j < Nmax; j++) {
     234      groups[i].hosts[groups[i].Nhosts] = &table->hosts[k];
     235      groups[i].Nhosts ++;
     236      k++;
    212237    }
    213238  }
  • trunk/Ohana/src/libdvo/src/LoadImages.c

    r37807 r38441  
    6565  }
    6666
    67   image = gfits_table_get_Image (&db.ftable, Nimage, &db.swapped);
     67  image = gfits_table_get_Image (&db.ftable, Nimage, &db.scaledValue, &db.nativeOrder);
    6868  if (!image) {
    6969    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r37035 r38441  
    1515
    1616  /* XXX choose more sensible lock timeouts! */
     17  gfits_db_init (&db);
    1718  db.timeout   = 60.0;
    1819  db.lockstate = LCK_SOFT;
    19   gfits_db_init (&db);
    2020
    2121  /* does this mean the db is empty, non-existent, or has access errors? */
     
    4343# define CONVERT_FORMAT(NAME, FORMAT)                                   \
    4444  if (!strcmp (extname, NAME)) {                                        \
    45     PhotCode_##FORMAT *photcode_input = gfits_table_get_PhotCode_##FORMAT (&db.ftable, &Ncode, &db.swapped); \
     45    PhotCode_##FORMAT *photcode_input = gfits_table_get_PhotCode_##FORMAT (&db.ftable, &Ncode, &db.scaledValue, &db.nativeOrder); \
    4646    if (!photcode_input) {                                                      \
    4747      fprintf (stderr, "ERROR: failed to read photcodes in LoadPhotcodesFITS.c\n");             \
  • trunk/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r37035 r38441  
    1717
    1818  /* XXX choose more sensible lock timeouts! */
     19  gfits_db_init (&db);
    1920  db.lockstate = LCK_XCLD;
    2021  db.timeout   = 10.0;
    21   gfits_db_init (&db);
    2222
    2323  /* does this mean the db is empty, non-existent, or has access errors? */
     
    3434  /* convert FITS format data to internal format (byteswaps & EXTNAME) */
    3535  if (!gfits_db_create (&db)) return (FALSE);
    36   if (!gfits_table_set_PhotCode_PS1_V5 (&db.ftable, photcode_output, table[0].Ncode)) return (FALSE);
     36  if (!gfits_table_set_PhotCode_PS1_V5 (&db.ftable, photcode_output, table[0].Ncode, TRUE)) return (FALSE);
    3737  if (!gfits_db_save (&db)) return (FALSE);
    3838  if (!gfits_db_close (&db)) return (FALSE);
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r38062 r38441  
    4242}
    4343
    44 int dvo_catalog_catformat (char *catformat) {
     44DVOCatFormat dvo_catalog_catformat (char *catformat) {
    4545 
    4646  /* set the specified CATFORMAT */
     
    6262}
    6363
    64 int dvo_catalog_catmode (char *catmode) {
     64DVOCatMode dvo_catalog_catmode (char *catmode) {
    6565
    6666  /* set the specified CATMODE */
     
    6969  if (!strcasecmp (catmode, "SPLIT")) return (DVO_MODE_SPLIT);
    7070  return (DVO_MODE_UNDEF);
     71}
     72
     73DVOCatCompress dvo_catalog_catcompress (char *catcompress) {
     74
     75  /* set the specified CATMODE */
     76  if (!strcasecmp (catcompress, "NONE"))   return (DVO_COMPRESS_NONE);
     77  if (!strcasecmp (catcompress, "AUTO"))   return (DVO_COMPRESS_AUTO);
     78  if (!strcasecmp (catcompress, "NONE_1")) return (DVO_COMPRESS_NONE_1);
     79  if (!strcasecmp (catcompress, "NONE_2")) return (DVO_COMPRESS_NONE_2);
     80  if (!strcasecmp (catcompress, "GZIP_1")) return (DVO_COMPRESS_GZIP_1);
     81  if (!strcasecmp (catcompress, "GZIP_2")) return (DVO_COMPRESS_GZIP_2);
     82  if (!strcasecmp (catcompress, "RICE_1")) return (DVO_COMPRESS_RICE_1);
     83  return (DVO_COMPRESS_NONE);
     84}
     85
     86// we can return a static string here unless we run multiple outputs threads at once
     87static char compress_string[16];
     88char *dvo_catalog_compress_string (DVOCatCompress catcompress) {
     89
     90  switch (catcompress) {
     91    case DVO_COMPRESS_NONE:
     92      strcpy (compress_string, "NONE");
     93      break;
     94    case DVO_COMPRESS_AUTO:
     95      strcpy (compress_string, "AUTO");
     96      break;
     97    case DVO_COMPRESS_GZIP_1:
     98      strcpy (compress_string, "GZIP_1");
     99      break;
     100    case DVO_COMPRESS_GZIP_2:
     101      strcpy (compress_string, "GZIP_2");
     102      break;
     103    case DVO_COMPRESS_NONE_1:
     104      strcpy (compress_string, "NONE_1");
     105      break;
     106    case DVO_COMPRESS_NONE_2:
     107      strcpy (compress_string, "NONE_2");
     108      break;
     109    case DVO_COMPRESS_RICE_1:
     110      strcpy (compress_string, "RICE_1");
     111      break;
     112    default:
     113      myAbort ("error in compress option");
     114  }
     115  return compress_string;
    71116}
    72117
     
    131176  average->Nlensobj        = 0;
    132177  average->Nstarpar        = 0;
    133   average->Nextend         = 0;
     178  average->Ngalphot       = 0;
    134179
    135180  average->measureOffset   = -1;
     
    138183  average->lensobjOffset   = -1;
    139184  average->starparOffset   = -1;
    140   average->extendOffset    = -1;
     185  average->galphotOffset  = -1;
    141186
    142187  average->refColorBlue    = NAN;
     
    466511
    467512// init all data, or just catalog data
     513void dvo_galphot_init (GalPhot *galphot) {
     514  galphot->Xfit         = NAN;
     515  galphot->Yfit         = NAN;
     516  galphot->mag          = NAN;
     517  galphot->magErr       = NAN;
     518  galphot->majorAxis    = NAN;
     519  galphot->minorAxis    = NAN;
     520  galphot->majorAxisErr = NAN;
     521  galphot->minorAxisErr = NAN;
     522  galphot->theta        = NAN;
     523  galphot->theta_err    = NAN;
     524  galphot->index        = NAN;
     525  galphot->chisq        = NAN;
     526  galphot->Npix         = 0;
     527
     528  galphot->detID   = -1;
     529  galphot->objID   = -1;
     530  galphot->catID   = -1;
     531  galphot->imageID = -1;
     532
     533  galphot->photcode = 0;
     534  galphot->modelType = 0;
     535}
     536
     537# define INIT_TABLE(TABLE)                      \
     538  catalog[0].TABLE = NULL;                      \
     539  catalog[0].N##TABLE = 0;                      \
     540  catalog[0].N##TABLE##_disk = 0;               \
     541  catalog[0].N##TABLE##_off  = 0;               \
     542  catalog[0].TABLE##_catalog  = NULL;
     543
     544// init all data, or just catalog data
    468545void dvo_catalog_init (Catalog *catalog, int complete) {
    469546
     
    473550    catalog[0].filename = NULL;
    474551
    475     catalog[0].lockmode = 0;
    476     catalog[0].catmode  = 0;
    477     catalog[0].catformat = 0;
    478     catalog[0].catflags = 0;
    479     catalog[0].Nsecfilt = 0;
     552    catalog[0].lockmode    = 0;
     553    catalog[0].catmode     = DVO_MODE_UNDEF;
     554    catalog[0].catformat   = DVO_FORMAT_UNDEF;
     555    catalog[0].catcompress = DVO_COMPRESS_NONE;
     556    catalog[0].catflags    = DVO_LOAD_NONE;
     557    catalog[0].Nsecfilt    = 0;
    480558  }
    481559
    482560  gfits_init_header (&catalog[0].header);
    483 
     561 
    484562  // the following describe the catalog files on disk
    485563  catalog[0].average = NULL;
    486   catalog[0].measure = NULL;
    487   catalog[0].missing = NULL;
     564  catalog[0].Naverage = 0;
     565  catalog[0].Naverage_disk = 0;
     566  catalog[0].Naverage_off  = 0;
     567  // average lacks average_catalog
     568
    488569  catalog[0].secfilt = NULL;
    489  
    490   catalog[0].lensing = NULL;
    491   catalog[0].lensobj = NULL;
    492 
    493   catalog[0].starpar = NULL;
     570  catalog[0].Nsecfilt_mem = 0;
     571  catalog[0].Nsecfilt_disk = 0;
     572  catalog[0].Nsecfilt_off  = 0;
     573  catalog[0].secfilt_catalog = NULL;
     574  // secfilt uses Nsecfilt_mem not Nsecfilt
    494575
    495576  catalog[0].averageT = NULL;
    496577  catalog[0].measureT = NULL;
     578
     579  INIT_TABLE(measure);
     580  INIT_TABLE(missing);
     581  INIT_TABLE(lensing);
     582  INIT_TABLE(lensobj);
     583  INIT_TABLE(starpar);
     584  INIT_TABLE(galphot);
    497585
    498586  catalog[0].objID = 0;
    499587  catalog[0].catID = 0;
    500588  catalog[0].sorted = 0;
    501 
    502   catalog[0].Naverage = 0;
    503   catalog[0].Nmeasure = 0;
    504   catalog[0].Nmissing = 0;
    505   catalog[0].Nsecf_mem = 0;
    506 
    507   catalog[0].Nlensing = 0;
    508   catalog[0].Nlensobj = 0;
    509 
    510   catalog[0].Nstarpar = 0;
    511 
    512   catalog[0].Naves_disk = 0;
    513   catalog[0].Nmeas_disk = 0;
    514   catalog[0].Nmiss_disk = 0;
    515   catalog[0].Nsecf_disk = 0;
    516 
    517   catalog[0].Nlensing_disk = 0;
    518   catalog[0].Nlensobj_disk = 0;
    519 
    520   catalog[0].Nstarpar_disk = 0;
    521 
    522   catalog[0].Naves_off  = 0;
    523   catalog[0].Nmeas_off  = 0;
    524   catalog[0].Nmiss_off  = 0;
    525   catalog[0].Nsecf_off  = 0;
    526 
    527   catalog[0].Nlensing_off  = 0;
    528   catalog[0].Nlensobj_off  = 0;
    529 
    530   catalog[0].Nstarpar_off  = 0;
    531 
    532   /* pointers to SPLIT data files */
    533   catalog[0].measure_catalog = NULL;
    534   catalog[0].missing_catalog = NULL;
    535   catalog[0].secfilt_catalog = NULL;
    536   catalog[0].lensing_catalog = NULL;
    537   catalog[0].lensobj_catalog = NULL;
    538   catalog[0].starpar_catalog = NULL;
    539589
    540590  /* pointers for data manipulation */
     
    568618  if (catalog[0].f == NULL)   return (DVO_CAT_OPEN_FAIL);
    569619
    570   fseeko (catalog[0].f, 0, SEEK_SET);
     620  if (fseeko (catalog[0].f, 0, SEEK_SET)) {
     621    perror ("fseeko: ");
     622    exit (1);
     623  }
    571624  return (DVO_CAT_OPEN_OK);
    572625}
     
    580633
    581634  if (fflush (catalog[0].f)) {
    582     fprintf (stderr, "failed to flush file\n");
     635    perror ("fflush: ");
     636    fprintf (stderr, "failed to flush file %s\n", catalog[0].filename);
    583637    return FALSE;
    584638  }
     
    607661    if (catalog[0].lensobj_catalog) { if (!dvo_catalog_unlock (catalog[0].lensobj_catalog)) { fprintf (stderr, "failed to unlock lensobj\n"); return (0); }}
    608662    if (catalog[0].starpar_catalog) { if (!dvo_catalog_unlock (catalog[0].starpar_catalog)) { fprintf (stderr, "failed to unlock starpar\n"); return (0); }}
     663    if (catalog[0].galphot_catalog) { if (!dvo_catalog_unlock (catalog[0].galphot_catalog)) { fprintf (stderr, "failed to unlock galphot\n"); return (0); }}
    609664  }
    610665  return (1);
     
    849904    catalog[0].secfilt = outsec;
    850905    catalog[0].Nsecfilt = Nsecfilt;
    851     catalog[0].Nsecf_mem = Nsecfilt * catalog[0].Naverage;
     906    catalog[0].Nsecfilt_mem = Nsecfilt * catalog[0].Naverage;
    852907  }
    853908  return (TRUE);
     
    887942      dvo_catalog_free (catalog[0].starpar_catalog);
    888943      free (catalog[0].starpar_catalog);
     944    }
     945    if (catalog[0].galphot_catalog) {
     946      free (catalog[0].galphot_catalog[0].filename);
     947      dvo_catalog_free (catalog[0].galphot_catalog);
     948      free (catalog[0].galphot_catalog);
    889949    }
    890950  }
     
    914974  if (catalog[0].secfilt) {
    915975    free (catalog[0].secfilt);
    916     catalog[0].Nsecf_mem = 0;
     976    catalog[0].Nsecfilt_mem = 0;
    917977    catalog[0].secfilt = NULL;
    918978  }
     
    932992    catalog[0].starpar = NULL;
    933993  }
     994  if (catalog[0].galphot) {
     995    free (catalog[0].galphot);
     996    catalog[0].Ngalphot = 0;
     997    catalog[0].galphot = NULL;
     998  }
    934999  if (catalog[0].nOwn_t)      { free (catalog[0].nOwn_t); catalog[0].nOwn_t = NULL; }
    9351000  if (catalog[0].found_t)     { free (catalog[0].found_t); catalog[0].found_t = NULL; }
     
    9381003
    9391004/*
    940   mode   : items to read (LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF)
     1005  mode   : items to read (DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT)
    9411006  format : what table structure on disk (INTERNAL, LONEOS, etc, )
    9421007  style  : raw, mef, split, mysql
     
    9711036
    9721037  // skip empty cpt files
    973   if (primary && !catalog->Naves_disk) {
     1038  if (primary && !catalog->Naverage_disk) {
    9741039    return TRUE;
    9751040  }
     
    10531118      }
    10541119    }
     1120    if (catalog[0].galphot_catalog != NULL) {
     1121      if (catalog[0].Ngalphot_disk == 0) {
     1122        // need to relock (and re-open) file for close elsewhere
     1123        status = dvo_catalog_lock (catalog[0].galphot_catalog, lockmode);
     1124      } else {
     1125        if (!dvo_catalog_backup (catalog[0].galphot_catalog, FALSE)) {
     1126          return FALSE;
     1127        }
     1128      }
     1129    }
    10551130  }
    10561131  return TRUE;
     
    10601135int dvo_catalog_unlink_backup (Catalog *catalog, int primary) {
    10611136
    1062   if (primary && !catalog->Naves_disk) {
     1137  if (primary && !catalog->Naverage_disk) {
    10631138    // skip empty files (empty when read, but output may not be empty)
    10641139    return TRUE;
     
    11091184      }
    11101185    }
     1186    if ((catalog[0].galphot_catalog != NULL) && (catalog[0].Ngalphot_disk > 0)) {
     1187      if (!dvo_catalog_unlink_backup (catalog[0].galphot_catalog, FALSE)) {
     1188        return FALSE;
     1189      }
     1190    }
    11111191  }
    11121192  return TRUE;
  • trunk/Ohana/src/libdvo/src/dvo_catalog_create.c

    r37807 r38441  
    11# include <dvo.h>
    22# define DEBUG 0
     3
     4Catalog *dvo_catalog_create_subcat (Catalog *catalog, char *ext, char *tablename);
    35
    46// create a new dvo catalog file (if split, lock extra files as well?)
     
    911// catalog[0].lockmode
    1012void dvo_catalog_create (SkyRegion *region, Catalog *catalog) {
    11 
    12   int length;
    13   char *path, *root, *file, *line;
    14   time_t now;
    1513
    1614  if (DEBUG) fprintf (stderr, "new catalog file: %s\n", catalog[0].filename);
     
    2927
    3028  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    31     path = pathname (catalog[0].filename);
    32     root = filerootname (catalog[0].filename);
    33     length = strlen(path) + strlen(root) + 6;
    34 
    35     /* define measure catalog file */
    36     ALLOCATE (catalog[0].measure_catalog, Catalog, 1);
    37     dvo_catalog_init (catalog[0].measure_catalog, TRUE);
    38 
    39     /* create basic data for measure catalog file */
    40     gfits_create_header (&catalog[0].measure_catalog[0].header);
    41 
    42     ALLOCATE (catalog[0].measure_catalog[0].filename, char, length);
    43 
    44     sprintf (catalog[0].measure_catalog[0].filename, "%s/%s.cpm", path, root);
    45     file = filebasename (catalog[0].measure_catalog[0].filename);
    46     gfits_modify (&catalog[0].header, "MEASURE", "%s", 1, file);
    47     free (file);
    48 
    49     /* define missing catalog file */
    50     ALLOCATE (catalog[0].missing_catalog, Catalog, 1);
    51     dvo_catalog_init (catalog[0].missing_catalog, TRUE);
    52 
    53     /* create basic data for missing catalog file */
    54     gfits_create_header (&catalog[0].missing_catalog[0].header);
    55     ALLOCATE (catalog[0].missing_catalog[0].filename, char, length);
    56     sprintf (catalog[0].missing_catalog[0].filename, "%s/%s.cpn", path, root);
    57     file = filebasename (catalog[0].missing_catalog[0].filename);
    58     gfits_modify (&catalog[0].header, "MISSING", "%s", 1, file);
    59     free (file);
    60 
    61     /* define secfilt catalog file */
    62     ALLOCATE (catalog[0].secfilt_catalog, Catalog, 1);
    63     dvo_catalog_init (catalog[0].secfilt_catalog, TRUE);
    64 
    65     /* create basic data for secfilt catalog file */
    66     gfits_create_header (&catalog[0].secfilt_catalog[0].header);
    67     ALLOCATE (catalog[0].secfilt_catalog[0].filename, char, length);
    68     sprintf (catalog[0].secfilt_catalog[0].filename, "%s/%s.cps", path, root);
    69     file = filebasename (catalog[0].secfilt_catalog[0].filename);
    70     gfits_modify (&catalog[0].header, "SECFILT", "%s", 1, file);
    71     free (file);
    72 
    73     /* define lensing catalog file */
    74     ALLOCATE (catalog[0].lensing_catalog, Catalog, 1);
    75     dvo_catalog_init (catalog[0].lensing_catalog, TRUE);
    76 
    77     /* create basic data for lensing catalog file */
    78     gfits_create_header (&catalog[0].lensing_catalog[0].header);
    79     ALLOCATE (catalog[0].lensing_catalog[0].filename, char, length);
    80     sprintf (catalog[0].lensing_catalog[0].filename, "%s/%s.cpx", path, root);
    81     file = filebasename (catalog[0].lensing_catalog[0].filename);
    82     gfits_modify (&catalog[0].header, "LENSING", "%s", 1, file);
    83     free (file);
    84 
    85     /* define lensobj catalog file */
    86     ALLOCATE (catalog[0].lensobj_catalog, Catalog, 1);
    87     dvo_catalog_init (catalog[0].lensobj_catalog, TRUE);
    88 
    89     /* create basic data for lensobj catalog file */
    90     gfits_create_header (&catalog[0].lensobj_catalog[0].header);
    91     ALLOCATE (catalog[0].lensobj_catalog[0].filename, char, length);
    92     sprintf (catalog[0].lensobj_catalog[0].filename, "%s/%s.cpy", path, root);
    93     file = filebasename (catalog[0].lensobj_catalog[0].filename);
    94     gfits_modify (&catalog[0].header, "LENSOBJ", "%s", 1, file);
    95     free (file);
    96 
    97     /* define starpar catalog file */
    98     ALLOCATE (catalog[0].starpar_catalog, Catalog, 1);
    99     dvo_catalog_init (catalog[0].starpar_catalog, TRUE);
    100 
    101     /* create basic data for starpar catalog file */
    102     gfits_create_header (&catalog[0].starpar_catalog[0].header);
    103     ALLOCATE (catalog[0].starpar_catalog[0].filename, char, length);
    104     sprintf (catalog[0].starpar_catalog[0].filename, "%s/%s.cpz", path, root);
    105     file = filebasename (catalog[0].starpar_catalog[0].filename);
    106     gfits_modify (&catalog[0].header, "STARPAR", "%s", 1, file);
    107     free (file);
    108 
    109     free (path);
    110     free (root);
     29    catalog[0].measure_catalog  = dvo_catalog_create_subcat (catalog, "cpm", "MEASURE");
     30    catalog[0].missing_catalog  = dvo_catalog_create_subcat (catalog, "cpn", "MISSING");
     31    catalog[0].secfilt_catalog  = dvo_catalog_create_subcat (catalog, "cps", "SECFILT");
     32    catalog[0].lensing_catalog  = dvo_catalog_create_subcat (catalog, "cpx", "LENSING");
     33    catalog[0].lensobj_catalog  = dvo_catalog_create_subcat (catalog, "cpy", "LENSOBJ");
     34    catalog[0].starpar_catalog  = dvo_catalog_create_subcat (catalog, "cpz", "STARPAR");
     35    catalog[0].galphot_catalog = dvo_catalog_create_subcat (catalog, "cpq", "GALPHOT");
    11136
    11237    // lock the additional split files
     
    13661      exit (2);
    13762    }
     63    if (dvo_catalog_lock (catalog[0].galphot_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
     64      fprintf (stderr, "error with file lock\n");
     65      exit (2);
     66    }
    13867  }   
    13968
     
    15079
    15180  /* write creation date in header */
     81  time_t now;
    15282  ohana_str_to_time ("now", &now);
    153   line = ohana_sec_to_date (now);
     83  char *line = ohana_sec_to_date (now);
    15484  gfits_modify (&catalog[0].header, "DATE", "%s", 1, line);
    15585  free (line);
     
    16393  ALLOCATE (catalog[0].lensobj, Lensobj, 1);
    16494  ALLOCATE (catalog[0].starpar, StarPar, 1);
     95  ALLOCATE (catalog[0].galphot, GalPhot, 1);
    16596
    16697  /* setup secondary filters to match photcodes:
     
    170101}
    171102 
     103Catalog *dvo_catalog_create_subcat (Catalog *catalog, char *ext, char *tablename) {
     104 
     105  char *path = pathname (catalog[0].filename);
     106  char *root = filerootname (catalog[0].filename);
     107  int length = strlen(path) + strlen(root) + 6;
     108   
     109  Catalog *subcat;
     110 
     111  /* define subcat catalog file */
     112  ALLOCATE (subcat, Catalog, 1);
     113  dvo_catalog_init (subcat, TRUE);
     114 
     115  /* create basic data for measure catalog file */
     116  gfits_create_header (&subcat->header);
     117
     118  subcat->catcompress = catalog->catcompress;
     119
     120  ALLOCATE (subcat->filename, char, length);
     121
     122  sprintf (subcat->filename, "%s/%s.%s", path, root, ext);
     123
     124  char *file = filebasename (subcat->filename);
     125  gfits_modify (&catalog[0].header, tablename, "%s", 1, file);
     126
     127  free (file);
     128  free (path);
     129  free (root);
     130
     131  return subcat;
     132}
     133
    172134int dvo_catalog_set_range (Catalog *catalog) {
    173135
  • trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r37807 r38441  
    2626  }
    2727
    28   // NSTARS, average, Naves_disk
     28  // NSTARS, average, Naverage_disk
    2929
    3030# define GET_TABLE_SIZES(HFIELD, CFIELD, DFIELD, REQUIRED)              \
     
    4141 
    4242  /* get the components and sizes from the header */
    43   GET_TABLE_SIZES ("NSTARS",   average, Naves_disk,    TRUE);
    44   GET_TABLE_SIZES ("NMEAS",    measure, Nmeas_disk,    TRUE);
    45   GET_TABLE_SIZES ("NMISS",    missing, Nmiss_disk,    FALSE);
    46   GET_TABLE_SIZES ("NLENSING", lensing, Nlensing_disk, FALSE);
    47   GET_TABLE_SIZES ("NLENSOBJ", lensobj, Nlensobj_disk, FALSE);
    48   GET_TABLE_SIZES ("NSTARPAR", starpar, Nstarpar_disk, FALSE);
     43  GET_TABLE_SIZES ("NSTARS",    average,  Naverage_disk,     TRUE);
     44  GET_TABLE_SIZES ("NMEAS",     measure,  Nmeasure_disk,     TRUE);
     45  GET_TABLE_SIZES ("NMISS",     missing,  Nmissing_disk,     FALSE);
     46  GET_TABLE_SIZES ("NLENSING",  lensing,  Nlensing_disk,  FALSE);
     47  GET_TABLE_SIZES ("NLENSOBJ",  lensobj,  Nlensobj_disk,  FALSE);
     48  GET_TABLE_SIZES ("NSTARPAR",  starpar,  Nstarpar_disk,  FALSE);
     49  GET_TABLE_SIZES ("NGALPHOT", galphot, Ngalphot_disk, FALSE);
    4950
    5051  /**  Nsecfilt is unusual: it does not list the number of data items in the table
     
    5354  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
    5455  catalog[0].Nsecfilt = Nsecfilt;
    55   catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     56  catalog[0].Nsecfilt_disk = Naverage * Nsecfilt;
    5657  catalog[0].secfilt = NULL;
    5758
     
    7071
    7172  /* read Average table data (or skip) */
    72   if (catalog[0].catflags & LOAD_AVES) {
     73  if (catalog[0].catflags & DVO_LOAD_AVERAGE) {
    7374    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    7475      if (VERBOSE) fprintf (stderr, "can't read table average data");
     
    7677    }
    7778    /* old versions of DVO stored one of the average magnitudes in Average. we save this if needed */
    78     catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
    79     if (Naverage != catalog[0].Naves_disk) {
    80       fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Naverage,  catalog[0].Naves_disk);
    81     }
    82     catalog[0].Naverage = catalog[0].Naves_disk;
    83     catalog[0].Naves_off = 0;
     79    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary, FALSE);
     80    if (Naverage != catalog[0].Naverage_disk) {
     81      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Naverage,  catalog[0].Naverage_disk);
     82    }
     83    catalog[0].Naverage = catalog[0].Naverage_disk;
     84    catalog[0].Naverage_off = 0;
    8485  } else {
    8586    catalog[0].catformat = FtableGetFormat (&ftable);
     
    8889    ALLOCATE (catalog[0].average, Average, 1);
    8990    catalog[0].Naverage = 0;
    90     catalog[0].Naves_off = catalog[0].Naves_disk;
     91    catalog[0].Naverage_off = catalog[0].Naverage_disk;
    9192  }
    9293  gfits_free_header (&header);
     
    99100  }
    100101  /* read Measure table data */
    101   if (catalog[0].catflags & LOAD_MEAS) {
     102  if (catalog[0].catflags & DVO_LOAD_MEASURE) {
    102103    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    103104      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    104105      return (FALSE);
    105106    }
    106     catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &catalog[0].Nmeasure, &catalog[0].catformat);
    107     if (Nmeasure != catalog[0].Nmeas_disk) {
    108       fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmeasure,  catalog[0].Nmeas_disk);
    109     }
    110     catalog[0].Nmeasure = catalog[0].Nmeas_disk;
    111     catalog[0].Nmeas_off = 0;
     107    catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &catalog[0].Nmeasure, &catalog[0].catformat, FALSE);
     108    if (Nmeasure != catalog[0].Nmeasure_disk) {
     109      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmeasure,  catalog[0].Nmeasure_disk);
     110    }
     111    catalog[0].Nmeasure = catalog[0].Nmeasure_disk;
     112    catalog[0].Nmeasure_off = 0;
    112113  } else {
    113114    Nbytes = gfits_data_size (&header);
     
    115116    ALLOCATE (catalog[0].measure, Measure, 1);
    116117    catalog[0].Nmeasure = 0;
    117     catalog[0].Nmeas_off = catalog[0].Nmeas_disk;
     118    catalog[0].Nmeasure_off = catalog[0].Nmeasure_disk;
    118119  }
    119120
     
    124125  }
    125126  /* read Missing table data */
    126   if (catalog[0].catflags & LOAD_MISS) {
     127  if (catalog[0].catflags & DVO_LOAD_MISSING) {
    127128    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    128129      if (VERBOSE) fprintf (stderr, "can't read table missing data");
     
    130131    }
    131132    /* no conversions currently defined */
    132     catalog[0].missing = gfits_table_get_Missing (&ftable, &catalog[0].Nmissing, NULL);
     133    catalog[0].missing = gfits_table_get_Missing (&ftable, &catalog[0].Nmissing, NULL, NULL);
    133134    if (!catalog[0].missing) {
    134135      fprintf (stderr, "ERROR: failed to read missing\n");
    135136      exit (2);
    136137    }
    137     if (Nmissing != catalog[0].Nmiss_disk) {
    138       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmissing,  catalog[0].Nmiss_disk);
    139     }
    140     catalog[0].Nmissing = catalog[0].Nmiss_disk;
    141     catalog[0].Nmiss_off = 0;
     138    if (Nmissing != catalog[0].Nmissing_disk) {
     139      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmissing,  catalog[0].Nmissing_disk);
     140    }
     141    catalog[0].Nmissing = catalog[0].Nmissing_disk;
     142    catalog[0].Nmissing_off = 0;
    142143  } else {
    143144    Nbytes = gfits_data_size (&header);
     
    145146    ALLOCATE (catalog[0].missing, Missing, 1);
    146147    catalog[0].Nmissing = 0;
    147     catalog[0].Nmiss_off = catalog[0].Nmiss_disk;
     148    catalog[0].Nmissing_off = catalog[0].Nmissing_disk;
    148149  }
    149150
     
    154155  }
    155156  /* read secfilt table data */
    156   if (catalog[0].catflags & LOAD_SECF) {
     157  if (catalog[0].catflags & DVO_LOAD_SECFILT) {
    157158    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    158159      if (VERBOSE) fprintf (stderr, "can't read table secfilt data");
     
    162163    /* how many entries do we expect from the secfilt table? */
    163164    Nexpect = catalog[0].Nsecfilt * catalog[0].Naverage;
    164     catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
     165    catalog[0].secfilt = FtableToSecFilt (&ftable, catalog[0].average, &Nitems, &catalog[0].catformat, FALSE);
    165166    if (Nexpect != Nitems) {
    166167      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nexpect,  Nitems);
     
    175176      Ntmpfilt = catalog[0].Nsecfilt;
    176177      Nsecfilt = catalog[0].Nsecfilt + 1;
    177       Ntotal = Nsecfilt * catalog[0].Naves_disk;
     178      Ntotal = Nsecfilt * catalog[0].Naverage_disk;
    178179      ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
    179       for (i = 0; i < catalog[0].Naves_disk; i++) {
     180      for (i = 0; i < catalog[0].Naverage_disk; i++) {
    180181        catalog[0].secfilt[i*Nsecfilt + 0] = primary[i];
    181182        for (j = 0; j < Ntmpfilt; j++) {
     
    184185      }         
    185186      catalog[0].Nsecfilt = Nsecfilt;
    186       catalog[0].Nsecf_disk = Ntotal;
     187      catalog[0].Nsecfilt_disk = Ntotal;
    187188      free (tmpfilt);
    188189      free (primary);
    189190    }
    190     catalog[0].Nsecf_mem = catalog[0].Nsecf_disk;
    191     catalog[0].Nsecf_off = 0;
     191    catalog[0].Nsecfilt_mem = catalog[0].Nsecfilt_disk;
     192    catalog[0].Nsecfilt_off = 0;
    192193  } else {
    193194    /* no real need to skip the data array here... */
     
    197198      free (primary);
    198199      catalog[0].Nsecfilt ++;
    199       catalog[0].Nsecf_disk =  catalog[0].Nsecfilt * catalog[0].Naves_disk;
     200      catalog[0].Nsecfilt_disk =  catalog[0].Nsecfilt * catalog[0].Naverage_disk;
    200201    }
    201202    ALLOCATE (catalog[0].secfilt, SecFilt, 1);
    202     catalog[0].Nsecf_mem = 0;
    203     catalog[0].Nsecf_off = catalog[0].Nsecf_disk;
     203    catalog[0].Nsecfilt_mem = 0;
     204    catalog[0].Nsecfilt_off = catalog[0].Nsecfilt_disk;
    204205  }
    205206
     
    210211  }
    211212  /* read Lensing table data */
    212   if (catalog[0].catflags & LOAD_LENSING) {
     213  if (catalog[0].catflags & DVO_LOAD_LENSING) {
    213214    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    214215      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
    215216      return (FALSE);
    216217    }
    217     catalog[0].lensing = FtableToLensing (&ftable, &catalog[0].Nlensing, &catalog[0].catformat);
     218    catalog[0].lensing = FtableToLensing (&ftable, catalog[0].average, &catalog[0].Nlensing, &catalog[0].catformat, FALSE);
    218219    if (Nlensing != catalog[0].Nlensing_disk) {
    219220      fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  catalog[0].Nlensing_disk);
     
    235236  }
    236237  /* read Lensobj table data */
    237   if (catalog[0].catflags & LOAD_LENSOBJ) {
     238  if (catalog[0].catflags & DVO_LOAD_LENSOBJ) {
    238239    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    239240      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
    240241      return (FALSE);
    241242    }
    242     catalog[0].lensobj = FtableToLensobj (&ftable, &catalog[0].Nlensobj, &catalog[0].catformat);
     243    catalog[0].lensobj = FtableToLensobj (&ftable, catalog[0].average, &catalog[0].Nlensobj, &catalog[0].catformat, FALSE);
    243244    if (Nlensobj != catalog[0].Nlensobj_disk) {
    244245      fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  catalog[0].Nlensobj_disk);
     
    260261  }
    261262  /* read StarPar table data */
    262   if (catalog[0].catflags & LOAD_STARPAR) {
     263  if (catalog[0].catflags & DVO_LOAD_STARPAR) {
    263264    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    264265      if (VERBOSE) fprintf (stderr, "can't read table starpar data");
    265266      return (FALSE);
    266267    }
    267     catalog[0].starpar = FtableToStarPar (&ftable, &catalog[0].Nstarpar, &catalog[0].catformat);
     268    catalog[0].starpar = FtableToStarPar (&ftable, catalog[0].average, &catalog[0].Nstarpar, &catalog[0].catformat, FALSE);
    268269    if (Nstarpar != catalog[0].Nstarpar_disk) {
    269270      fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  catalog[0].Nstarpar_disk);
     
    277278    catalog[0].Nstarpar = 0;
    278279    catalog[0].Nstarpar_off = catalog[0].Nstarpar_disk;
     280  }
     281
     282  /* read GalPhot table header */
     283  if (!gfits_fread_header (catalog[0].f, &header)) {
     284    if (VERBOSE) fprintf (stderr, "can't read table galphot header");
     285    return (FALSE);
     286  }
     287  /* read GalPhot table data */
     288  if (catalog[0].catflags & DVO_LOAD_GALPHOT) {
     289    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
     290      if (VERBOSE) fprintf (stderr, "can't read table galphot data");
     291      return (FALSE);
     292    }
     293    catalog[0].galphot = FtableToGalPhot (&ftable, catalog[0].average, &catalog[0].Ngalphot, &catalog[0].catformat, FALSE);
     294    if (Ngalphot != catalog[0].Ngalphot_disk) {
     295      fprintf (stderr, "Warning: mismatch between Ngalphot in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Ngalphot,  catalog[0].Ngalphot_disk);
     296    }
     297    catalog[0].Ngalphot = catalog[0].Ngalphot_disk;
     298    catalog[0].Ngalphot_off = 0;
     299  } else {
     300    Nbytes = gfits_data_size (&header);
     301    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     302    ALLOCATE (catalog[0].galphot, GalPhot, 1);
     303    catalog[0].Ngalphot = 0;
     304    catalog[0].Ngalphot_off = catalog[0].Ngalphot_disk;
    279305  }
    280306
     
    330356  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  catalog[0].Nlensobj);
    331357  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  catalog[0].Nstarpar);
     358  gfits_modify (&catalog[0].header, "NGALPHOT", OFF_T_FMT, 1,  catalog[0].Ngalphot);
     359
    332360  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    333361  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    357385
    358386  /* write out Average table (convert to FITS table format) */
    359   AverageToFtable (&ftable, catalog[0].average, catalog[0].Naverage, catalog[0].catformat, primary);
     387  AverageToFtable (&ftable, catalog[0].average, catalog[0].Naverage, catalog[0].catformat, primary, TRUE);
    360388  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    361389    fprintf (stderr, "can't write table header");
     
    370398
    371399  /* write out Measure table (convert to FITS table format) */
    372   MeasureToFtable (&ftable, catalog[0].average, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat);
     400  MeasureToFtable (&ftable, catalog[0].average, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat, TRUE);
    373401  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    374402    fprintf (stderr, "can't write table header");
     
    383411
    384412  /* write out Missing table (convert to FITS table format) */
    385   gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing);
     413  gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing, TRUE);
    386414  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    387415    fprintf (stderr, "can't write table header");
     
    397425  /* write out SecFilt table (convert to FITS table format) */
    398426  Nitems = catalog[0].Naverage * Nsecfilt;
    399   SecFiltToFtable (&ftable, secfilt, Nitems, catalog[0].catformat);
     427  SecFiltToFtable (&ftable, secfilt, Nitems, catalog[0].catformat, TRUE);
    400428  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    401429    fprintf (stderr, "can't write table header");
     
    410438
    411439  /* write out Lensing table (convert to FITS table format) */
    412   LensingToFtable (&ftable, catalog[0].lensing, catalog[0].Nlensing, catalog[0].catformat);
     440  LensingToFtable (&ftable, catalog[0].lensing, catalog[0].Nlensing, catalog[0].catformat, TRUE);
    413441  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    414442    fprintf (stderr, "can't write table header");
     
    423451
    424452  /* write out Lensobj table (convert to FITS table format) */
    425   LensobjToFtable (&ftable, catalog[0].lensobj, catalog[0].Nlensobj, catalog[0].catformat);
    426   if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    427     fprintf (stderr, "can't write table header");
    428     goto failure;
    429   }
    430   if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
    431     fprintf (stderr, "can't write table data");
    432     goto failure;
    433   }
    434   gfits_free_table (&ftable);
    435   gfits_free_header (&header);
    436 
    437   /* free temp storage */
    438   if (primary != NULL) {
    439     free (primary);
    440     free (secfilt);
    441   }
    442   return (TRUE);
     453  LensobjToFtable (&ftable, catalog[0].lensobj, catalog[0].Nlensobj, catalog[0].catformat, TRUE);
     454  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     455    fprintf (stderr, "can't write table header");
     456    goto failure;
     457  }
     458  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     459    fprintf (stderr, "can't write table data");
     460    goto failure;
     461  }
     462  gfits_free_table (&ftable);
     463  gfits_free_header (&header);
    443464
    444465  /* write out StarPar table (convert to FITS table format) */
    445   StarParToFtable (&ftable, catalog[0].starpar, catalog[0].Nstarpar, catalog[0].catformat);
     466  StarParToFtable (&ftable, catalog[0].starpar, catalog[0].Nstarpar, catalog[0].catformat, TRUE);
     467  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     468    fprintf (stderr, "can't write table header");
     469    goto failure;
     470  }
     471  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     472    fprintf (stderr, "can't write table data");
     473    goto failure;
     474  }
     475  gfits_free_table (&ftable);
     476  gfits_free_header (&header);
     477
     478  /* write out GalPhot table (convert to FITS table format) */
     479  GalPhotToFtable (&ftable, catalog[0].galphot, catalog[0].Ngalphot, catalog[0].catformat, TRUE);
    446480  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    447481    fprintf (stderr, "can't write table header");
  • trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r37807 r38441  
    136136  /* read and convert the averages (use a macro to clean this up?) */
    137137  /* old versions of DVO stored one of the average magnitudes in Average. we save this if needed */
    138   if (catalog[0].catflags & LOAD_AVES) {
     138  if (catalog[0].catflags & DVO_LOAD_AVERAGE) {
    139139    catalog[0].average = ReadRawAverage (catalog[0].f, catalog[0].Naverage, catalog[0].catformat, &primary);
    140140  } else {
     
    145145 
    146146  /* read and convert the measures (use a macro to clean this up?) */
    147   if (catalog[0].catflags & LOAD_MEAS) {
     147  if (catalog[0].catflags & DVO_LOAD_MEASURE) {
    148148    catalog[0].measure = ReadRawMeasure (catalog[0].f, catalog[0].average, catalog[0].Nmeasure, catalog[0].catformat);
    149149  } else {
     
    154154
    155155  /* read and convert missing */
    156   if (catalog[0].catflags & LOAD_MISS) {
     156  if (catalog[0].catflags & DVO_LOAD_MISSING) {
    157157    ALLOCATE (catalog[0].missing, Missing, MAX (catalog[0].Nmissing, 1));
    158158    Nitems = catalog[0].Nmissing;
     
    170170 
    171171  /* read and convert secfilt */
    172   if (catalog[0].catflags & LOAD_SECF) {
     172  if (catalog[0].catflags & DVO_LOAD_SECFILT) {
    173173    Nitems = catalog[0].Naverage * catalog[0].Nsecfilt;
    174174    catalog[0].secfilt = ReadRawSecFilt (catalog[0].f, Nitems, catalog[0].catformat);
     
    191191      }         
    192192      catalog[0].Nsecfilt = Nsecfilt;
    193       catalog[0].Nsecf_mem = Ntotal;
     193      catalog[0].Nsecfilt_mem = Ntotal;
    194194      free (primary);
    195195    }
     
    210210
    211211  /* check data integrity */
    212   if (catalog[0].catflags & LOAD_AVES) {
     212  if (catalog[0].catflags & DVO_LOAD_AVERAGE) {
    213213    for (i = Nmeas = Nmiss = 0; i < catalog[0].Naverage; i++) {
    214214      Nmeas += catalog[0].average[i].Nmeasure;
     
    226226
    227227  /* save the current number so we can do partial updates */
    228   catalog[0].Naves_disk = catalog[0].Naverage;
    229   catalog[0].Nmeas_disk = catalog[0].Nmeasure;
    230   catalog[0].Nmiss_disk = catalog[0].Nmissing;
     228  catalog[0].Naverage_disk = catalog[0].Naverage;
     229  catalog[0].Nmeasure_disk = catalog[0].Nmeasure;
     230  catalog[0].Nmissing_disk = catalog[0].Nmissing;
    231231
    232232  return (TRUE);
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r38153 r38441  
    11# include <dvo.h>
     2# define OHANA_MEMCHECK 0
    23
    34// return options:
     
    67// * ok
    78
     9// utility function to see if we should compress this table)
     10int output_is_compressed (int start, int Nrows, int Ntotal, DVOCatCompress catcompress) {
     11  int fullWrite = (start == 0) && (Nrows == Ntotal);
     12  if (fullWrite && catcompress) return TRUE;  // we want to compress, so do not swap
     13  return FALSE;
     14}
     15
     16int byteswap_varlength_ftable (Header *header, FTable *table) {
     17  int i, Nfields;
     18  if (!gfits_scan (header, "TFIELDS", "%d", 1, &Nfields)) return FALSE;
     19  for (i = 0; i < Nfields; i++) {
     20    if (!gfits_byteswap_varlength_column (table, i+1)) return FALSE;
     21  }
     22  return TRUE;
     23}
     24
    825int dvo_catalog_secfilt_to_primary (Catalog *catalog, SecFilt **myPrimary, SecFilt **mySecfilt, int *myNsecfilt) {
    926
     
    2037
    2138  // XXX this translation only works if we have loaded / created a matched average/secfilt set
    22   assert (catalog[0].Nsecf_mem == catalog[0].Nsecfilt*catalog[0].Naverage);
     39  assert (catalog[0].Nsecfilt_mem == catalog[0].Nsecfilt*catalog[0].Naverage);
    2340
    2441  Nallfilt = catalog[0].Nsecfilt;
     
    3552  }             
    3653  catalog[0].Nsecfilt --;
    37   catalog[0].Nsecf_mem = catalog[0].Naverage*catalog[0].Nsecfilt;
     54  catalog[0].Nsecfilt_mem = catalog[0].Naverage*catalog[0].Nsecfilt;
    3855
    3956  *myPrimary = primary;
     
    5168  Ntmpfilt = catalog[0].Nsecfilt;
    5269
    53   // we do NOT modify Nsecf_disk; this operation only modifies in in-memory values
     70  // we do NOT modify Nsecfilt_disk; this operation only modifies in in-memory values
    5471
    5572  catalog[0].Nsecfilt ++;
     
    5774  Ntotal = Nsecfilt * Naves;
    5875
    59   catalog[0].Nsecf_mem = Ntotal;
     76  catalog[0].Nsecfilt_mem = Ntotal;
    6077
    6178  ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
     
    7491
    7592  Matrix matrix;
    76 
    77   // ohana_memcheck_func (TRUE);
    7893 
    79 
    80   if (0) {
    81     // XXX a TEST : is the data corrupted or the file?
    82     char name[1024];
    83     snprintf (name, 1024, "%s.phu.v2", catalog->filename);
    84     FILE *f = fopen (name, "w");
    85     fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
    86     // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
    87     // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
    88     //       catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
    89     //       catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
    90     fclose (f);
    91   }
    92   if (0) {
    93     // XXX a TEST : is the data corrupted or the file?
    94     char name[1024];
    95     snprintf (name, 1024, "%s.phu", catalog->filename);
    96     FILE *f = fopen (name, "w");
    97     fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
    98     // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
    99     // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
    100     //       catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
    101     //       catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
    102     fclose (f);
    103   }
    104 # if (0)
    105   {
    106     // XXX a TEST : is the data corrupted or the file?
    107     char name[1024];
    108     snprintf (name, 1024, "%s.phu.v2", catalog->filename);
    109     FILE *f = fopen (name, "w");
    110     fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
    111     fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
    112     fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
    113              catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
    114              catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
    115     fclose (f);
    116   }
    117   {
    118     // XXX a TEST : is the data corrupted or the file?
    119     char name[1024];
    120     snprintf (name, 1024, "%s.phu.v3", catalog->filename);
    121     FILE *f = fopen (name, "w");
    122     fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
    123     fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
    124     fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
    125              catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
    126              catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
    127     fclose (f);
    128   }
    129 # endif
     94  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     95 
    13096  /* rewind file pointers and truncate (file is still open) */
    13197  if (fseeko (catalog->f, 0LL, SEEK_SET)) {
    13298    perror ("dvo_catalog_save_subset: ");
    13399    fprintf (stderr, "failed to seek to beginning\n");
     100    return FALSE;
    134101  }
    135102
     
    151118  gfits_free_matrix (&matrix);
    152119
     120  FTable *outtable = ftable;
     121  FTable cmptable;
     122  Header cmpheader;
     123  gfits_init_header (&cmpheader);
     124  gfits_init_table (&cmptable);
     125  cmptable.header = &cmpheader;
     126 
     127  int fullWrite = (start == 0) && (Nrows == Ntotal);
     128  int isCompressed = output_is_compressed (start, Nrows, Ntotal, catalog->catcompress);
     129
     130  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     131
     132  if (isCompressed) {
     133    // fprintf (stderr, "compress %s\n", catalog->filename);
     134    char *compressMode = dvo_catalog_compress_string (catalog->catcompress);
     135    // I should test how Ntile affects fpack/funpack and speed
     136    if (!gfits_compress_table (ftable, &cmptable, 1000, compressMode)) {
     137      fprintf (stderr, "compression failure\n");
     138      return (FALSE);
     139    }
     140    if (!byteswap_varlength_ftable (&cmpheader, &cmptable)) {
     141      fprintf (stderr, "failed to swap varlength column\n");
     142      return FALSE;
     143    }
     144    if (!gfits_modify (cmptable.header, "DVO_CMP", "%s", 1, compressMode)) {
     145      fprintf (stderr, "can't save compression mode\n");
     146      return (FALSE);
     147    }
     148    outtable = &cmptable;
     149  }
     150
     151  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     152
    153153  // write the table data
    154   if (!gfits_fwrite_ftable_range (catalog->f, ftable, start, Nrows, Ndisk, Ntotal)) {
    155     fprintf (stderr, "can't write table data\n");
    156     return (FALSE);
    157   }
    158   fullsize += ftable->datasize + ftable->header->datasize;
     154  if (fullWrite) {
     155    if (!gfits_fwrite_Theader (catalog->f, outtable->header)) {
     156      fprintf (stderr, "can't write table header\n");
     157      return (FALSE);
     158    }
     159    if (!gfits_fwrite_table (catalog->f, outtable)) {
     160      fprintf (stderr, "can't write table data\n");
     161      return (FALSE);
     162    }
     163  } else {
     164    if (!gfits_fwrite_ftable_range (catalog->f, outtable, start, Nrows, Ndisk, Ntotal)) {
     165      fprintf (stderr, "can't write table data (range)\n");
     166      return (FALSE);
     167    }
     168  }
     169  fullsize += outtable->datasize + outtable->header->datasize;
     170
     171  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     172
     173  // since we init'ed the structures above, these operations are safe whether or not we compressed the table
     174  gfits_free_header (&cmpheader);
     175  gfits_free_table (&cmptable);
    159176
    160177  // if the output file will be completely re-written, truncate to total datasize
    161   if ((start == 0) && (Nrows == Ntotal)) {
     178  if (fullWrite) {
    162179    int fd = fileno (catalog->f);
    163180    if (ftruncate (fd, fullsize)) {
     
    192209    // databases created prior to ~2014.07.01 did not have the LENSING, LENSOBJ, STARPAR paths in their headers.
    193210    // in these cases, we do not try to lock or open the relevant file
    194     if (!strcmp (name, "LENSING")) return (DVO_CAT_OPEN_EMPTY);
    195     if (!strcmp (name, "LENSOBJ")) return (DVO_CAT_OPEN_EMPTY);
    196     if (!strcmp (name, "STARPAR")) return (DVO_CAT_OPEN_EMPTY);
     211    if (!strcmp (name, "LENSING"))  return (DVO_CAT_OPEN_EMPTY);
     212    if (!strcmp (name, "LENSOBJ"))  return (DVO_CAT_OPEN_EMPTY);
     213    if (!strcmp (name, "STARPAR"))  return (DVO_CAT_OPEN_EMPTY);
     214    if (!strcmp (name, "GALPHOT")) return (DVO_CAT_OPEN_EMPTY);
    197215    return (DVO_CAT_OPEN_FAIL);
    198216  }
     
    200218  sprintf (subcat[0].filename, "%s/%s", path, string);
    201219  free (path);
     220
     221  // inherit compression mode for this subcat;
     222  subcat->catcompress = catalog->catcompress;
    202223
    203224  /* lock & open catalog file */
     
    220241  }
    221242  Nskip = gfits_data_size (&subcat[0].header);
    222   fseeko (subcat[0].f, Nskip, SEEK_CUR);
     243  if (fseeko (subcat[0].f, Nskip, SEEK_CUR)) { perror ("fseeko: "); exit (1); }
    223244
    224245  /* read table header */
     
    230251  return (DVO_CAT_OPEN_OK);
    231252}
     253
     254// ftable must already exist and have a valid, loaded header
     255int gfits_fread_uncompressed (Catalog *catalog, FTable *ftable, char *nativeOrder, char VERBOSE) {
     256
     257  // fread_ftable_data requires the header
     258
     259  *nativeOrder = FALSE;
     260  if (!gfits_fread_ftable_data (catalog->f, ftable, FALSE)) {
     261    if (VERBOSE) fprintf (stderr, "can't read table data\n");
     262    return FALSE;
     263  }
     264  // NOTE: fread_ftable returns an unswapped table; uncompress swaps the bytes into native order
     265   
     266  if (gfits_extension_is_compressed_table (ftable->header)) {
     267    FTable rawtable;
     268    Header rawheader;
     269    gfits_init_table (&rawtable);
     270    gfits_init_header (&rawheader);
     271    rawtable.header = &rawheader;
     272
     273    // NOTE: uncompress swaps the data bytes into native order, but needs the varlength columns native
     274    if (!byteswap_varlength_ftable (ftable->header, ftable)) {
     275      fprintf (stderr, "failed to swap varlength column\n");
     276      return FALSE;
     277    }
     278    if (!gfits_uncompress_table (ftable, &rawtable)) {
     279      if (VERBOSE) fprintf (stderr, "failed to uncompress table\n");
     280      gfits_free_table (ftable);
     281      return FALSE;
     282    }
     283
     284    char compressMode[80];
     285    if (!gfits_scan (ftable->header, "DVO_CMP", "%s", 1, compressMode)) {
     286      strcpy (compressMode, "AUTO");
     287    }
     288    catalog->catcompress = dvo_catalog_catcompress (compressMode); // if any table is compressed, set all to a compress state?
     289
     290    // free the buffers
     291    gfits_free_header (ftable->header);
     292    gfits_free_table (ftable);
     293   
     294    // copies values but does not allocate new memory
     295    Header *outheader = ftable->header;
     296    gfits_copy_header_ptr (&rawheader, outheader);
     297    gfits_copy_ftable_ptr (&rawtable, ftable); // this replaces ftable->header
     298    ftable->header = outheader;
     299    *nativeOrder = TRUE;
     300  }
     301  return TRUE;
     302}
     303
     304// LOAD_SUBCAT(measure,MEASURE,Measure)
     305
     306# define LOAD_SUBCAT(FIELD, NAME, STRUCT)                               \
     307  {                                                                     \
     308    Header header;                                                      \
     309    FTable ftable;                                                      \
     310    off_t Nitems;                                                       \
     311    gfits_init_table  (&ftable);                                        \
     312    gfits_init_header (&header);                                        \
     313    ftable.header = &header;                                            \
     314    int status = DVO_CAT_OPEN_EMPTY;                                    \
     315    if (!(catalog[0].catflags & DVO_SKIP_##NAME)) {                     \
     316      status = dvo_catalog_open_subcat (catalog, &catalog[0].FIELD##_catalog, ftable.header, #NAME, VERBOSE); \
     317      if (status == DVO_CAT_OPEN_FAIL) {                                \
     318        return (FALSE);                                                 \
     319      }                                                                 \
     320      if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].N##FIELD##_disk > 0)) { \
     321        return (FALSE);                                                 \
     322      }                                                                 \
     323    }                                                                   \
     324    if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & DVO_LOAD_##NAME)) { \
     325      char nativeOrder = FALSE;                                         \
     326      /* read table data */                                             \
     327      if (!gfits_fread_uncompressed (catalog[0].FIELD##_catalog, &ftable, &nativeOrder, VERBOSE)) { \
     328        if (VERBOSE) fprintf (stderr, "can't read table %s data\n", #FIELD); \
     329        gfits_free_header (&header);                                    \
     330        return (FALSE);                                                 \
     331      }                                                                 \
     332      /* convert data format to internal : returns number of row read in Nvalues */ \
     333      catalog[0].FIELD = FtableTo##STRUCT (&ftable, catalog[0].average, &Nitems, &catalog[0].catformat, nativeOrder); \
     334        if (Nitems != catalog[0].N##FIELD##_disk) {                     \
     335          fprintf (stderr, "Warning: mismatch between N%s in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n", #FIELD, Nitems, catalog[0].N##FIELD##_disk); \
     336        }                                                               \
     337        catalog[0].N##FIELD = catalog[0].N##FIELD##_disk;               \
     338          catalog[0].N##FIELD##_off = 0;                                \
     339    } else {                                                            \
     340      if (catalog[0].FIELD##_catalog) {                                 \
     341        gfits_free_header (&catalog[0].FIELD##_catalog[0].header);      \
     342      } else {                                                          \
     343        ALLOCATE (catalog[0].FIELD##_catalog, Catalog, 1);              \
     344        dvo_catalog_init (catalog[0].FIELD##_catalog, TRUE);            \
     345      }                                                                 \
     346      gfits_create_header (&catalog[0].FIELD##_catalog[0].header);      \
     347      ALLOCATE (catalog[0].FIELD, STRUCT, 1);                           \
     348      catalog[0].N##FIELD = 0;                                          \
     349        catalog[0].N##FIELD##_off = catalog[0].N##FIELD##_disk;         \
     350    }                                                                   \
     351    gfits_free_header (&header);                                        \
     352  }
    232353
    233354int dvo_catalog_load_split (Catalog *catalog, int VERBOSE) {
     
    240361  off_t Nlensobj;
    241362  off_t Nstarpar;
    242   off_t Nitems;
    243   int status, Nsecfilt;
    244   Header header;
    245   FTable ftable;
     363  off_t Ngalphot;
     364  int Nsecfilt;
    246365  SecFilt *primary;
    247366
    248   /* ftable header storage for below */
    249   ftable.header = &header;
    250   ftable.buffer = NULL;
    251   header.buffer = NULL;
    252367  primary = NULL;
    253   status = FALSE;
    254368
    255369  /* get the components from the header - these duplicate information in the split files (NAXIS2) */
    256   // NSTARS, NMEAS, NMISS are required; NLENSING, NLENSOBJ, NSTARPAR are not (0 if not found)
    257   if (!gfits_scan (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  &Naverage)) return (FALSE);
    258   if (!gfits_scan (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  &Nmeasure)) return (FALSE);
    259   if (!gfits_scan (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  &Nmissing)) return (FALSE);
    260   if (!gfits_scan (&catalog[0].header, "NSECFILT",      "%d", 1,  &Nsecfilt)) Nsecfilt = 0;
    261   if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) Nlensing = 0;
    262   if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) Nlensobj = 0;
    263   if (!gfits_scan (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  &Nstarpar)) Nstarpar = 0;
     370  // NSTARS, NMEAS, NMISS are required; NLENSING, NLENSOBJ, NSTARPAR, NGALPHOT are not (0 if not found)
     371  if (!gfits_scan (&catalog[0].header, "NSTARS",    OFF_T_FMT, 1,  &Naverage))  return (FALSE);
     372  if (!gfits_scan (&catalog[0].header, "NMEAS",     OFF_T_FMT, 1,  &Nmeasure))  return (FALSE);
     373  if (!gfits_scan (&catalog[0].header, "NMISS",     OFF_T_FMT, 1,  &Nmissing))  return (FALSE);
     374  if (!gfits_scan (&catalog[0].header, "NSECFILT",       "%d", 1,  &Nsecfilt))  Nsecfilt  = 0;
     375  if (!gfits_scan (&catalog[0].header, "NLENSING",  OFF_T_FMT, 1,  &Nlensing))  Nlensing  = 0;
     376  if (!gfits_scan (&catalog[0].header, "NLENSOBJ",  OFF_T_FMT, 1,  &Nlensobj))  Nlensobj  = 0;
     377  if (!gfits_scan (&catalog[0].header, "NSTARPAR",  OFF_T_FMT, 1,  &Nstarpar))  Nstarpar  = 0;
     378  if (!gfits_scan (&catalog[0].header, "NGALPHOT", OFF_T_FMT, 1,  &Ngalphot)) Ngalphot = 0;
    264379
    265380  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    276391
    277392  /* save the current number so we can do partial updates */
    278   catalog[0].Naves_disk = Naverage;
    279   catalog[0].Nmeas_disk = Nmeasure;
    280   catalog[0].Nmiss_disk = Nmissing;
    281   catalog[0].Nsecf_disk = Naverage * Nsecfilt;
    282   catalog[0].Nlensing_disk = Nlensing;
    283   catalog[0].Nlensobj_disk = Nlensobj;
    284   catalog[0].Nstarpar_disk = Nstarpar;
    285 
    286   /**  Nsecfilt is unusual: it does not list the number of data items in the table
    287        instead, the number of items is Nsecfilt * Naverage.  **/
    288   catalog[0].Nsecfilt  = Nsecfilt;
     393  catalog[0].Naverage_disk = Naverage;
     394  catalog[0].Nmeasure_disk = Nmeasure;
     395  catalog[0].Nmissing_disk = Nmissing;
     396  catalog[0].Nsecfilt_disk = Naverage * Nsecfilt;
     397  catalog[0].Nlensing_disk  = Nlensing;
     398  catalog[0].Nlensobj_disk  = Nlensobj;
     399  catalog[0].Nstarpar_disk  = Nstarpar;
     400  catalog[0].Ngalphot_disk = Ngalphot;
    289401
    290402  /* default values, but we will assign these a valid value before we exit (even if empty) */
    291   catalog[0].average = NULL;
    292   catalog[0].measure = NULL;
    293   catalog[0].missing = NULL;
    294   catalog[0].secfilt = NULL;
    295   catalog[0].lensing = NULL;
    296   catalog[0].lensobj = NULL;
    297   catalog[0].starpar = NULL;
     403  catalog[0].average  = NULL;
     404  catalog[0].measure  = NULL;
     405  catalog[0].missing  = NULL;
     406  catalog[0].secfilt  = NULL;
     407  catalog[0].lensing  = NULL;
     408  catalog[0].lensobj  = NULL;
     409  catalog[0].starpar  = NULL;
     410  catalog[0].galphot = NULL;
    298411
    299412  /*** Average Table ***/
     
    302415  /* move pointer past PHU header -- must be already read (load_catalog) */
    303416  Nbytes = catalog[0].header.datasize + gfits_data_size (&catalog[0].header);
    304   fseeko (catalog[0].f, Nbytes, SEEK_SET);
     417  if (fseeko (catalog[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
     418
     419  /* ftable header storage for below */
     420  char nativeOrder;
     421  Header header;
     422  FTable ftable;
     423  gfits_init_table  (&ftable);
     424  gfits_init_header (&header);
     425  ftable.header = &header;
    305426
    306427  /* read Average table header */
    307428  if (!gfits_fread_header (catalog[0].f, &header)) {
    308     if (VERBOSE) fprintf (stderr, "can't read table average header");
     429    if (VERBOSE) fprintf (stderr, "can't read table average header\n");
    309430    return (FALSE);
    310431  }
    311   if (catalog[0].catflags & LOAD_AVES) {
    312     /* read Average table data : format is irrelevant here */
    313     if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    314       if (VERBOSE) fprintf (stderr, "can't read table average data");
    315       return (FALSE);
    316     }
    317     /* convert the saved version of the table to the internal version.  Old versions of DVO stored
     432  if (catalog[0].catflags & DVO_LOAD_AVERAGE) {
     433    if (!gfits_fread_uncompressed (catalog, &ftable, &nativeOrder, VERBOSE)) {
     434      if (VERBOSE) fprintf (stderr, "can't read Average table\n");
     435      gfits_free_header (&header);
     436      return FALSE;
     437    }
     438
     439    /* convert the disk version of the table to the internal version.  Old versions of DVO stored
    318440     * one of the average magnitudes in Average.  We save this in case it is needed below.  NOTE:
    319441     * primary is only used if we read in the secfilt table, otherwise it should be freed */
    320     catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
    321     if (Naverage != catalog[0].Naves_disk) {
    322       fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Naverage,  catalog[0].Naves_disk);
    323     }
    324     gfits_free_header (&header);
    325     catalog[0].Naverage = catalog[0].Naves_disk;
    326     catalog[0].Naves_off = 0;
     442    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary, nativeOrder);
     443    if (Naverage != catalog[0].Naverage_disk) {
     444      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Naverage,  catalog[0].Naverage_disk);
     445    }
     446    catalog[0].Naverage = catalog[0].Naverage_disk;
     447    catalog[0].Naverage_off = 0;
    327448  } else {
    328449    catalog[0].catformat = FtableGetFormat (&ftable);
    329450    ALLOCATE (catalog[0].average, Average, 1);
    330451    catalog[0].Naverage = 0;
    331     catalog[0].Naves_off = catalog[0].Naves_disk;
    332   }
     452    catalog[0].Naverage_off = catalog[0].Naverage_disk;
     453  }
     454  gfits_free_header (&header);
    333455
    334456  /*** Measure Table ***/
    335   if (!(catalog[0].catflags & SKIP_MEAS)) {
    336     // unless we specify 'skip', we still need to load the
    337     status = dvo_catalog_open_subcat (catalog, &catalog[0].measure_catalog, ftable.header, "MEASURE", VERBOSE);
    338     if (status == DVO_CAT_OPEN_FAIL) {
    339       return (FALSE);
    340     }
    341     if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nmeas_disk > 0)) {
    342       return (FALSE);
    343     }
    344   }
    345   if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MEAS)) {
    346     // XXX this allows an empty Measure catalog with non-empty Average catalog : is that OK?
    347     /* read Measure table data */
    348     if (!gfits_fread_ftable_data (catalog[0].measure_catalog[0].f, &ftable, FALSE)) {
    349       if (VERBOSE) fprintf (stderr, "can't read table measure data\n");
    350       return (FALSE);
    351     }
    352     /* convert data format to internal : returns number of row read in Nmeasure */
    353     catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &Nmeasure, &catalog[0].catformat);
    354     if (Nmeasure != catalog[0].Nmeas_disk) {
    355       fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmeasure,  catalog[0].Nmeas_disk);
    356     }
    357     catalog[0].Nmeasure = catalog[0].Nmeas_disk;
    358     catalog[0].Nmeas_off = 0;
    359   } else {
    360     // XXX is it necessary to generate a template header here?
    361     // XXX this is a memory leak, right?
    362     if (catalog[0].measure_catalog) {
    363       gfits_free_header (&catalog[0].measure_catalog[0].header);
     457 
     458  LOAD_SUBCAT(measure,MEASURE,Measure);
     459  LOAD_SUBCAT(missing,MISSING,Missing);
     460  LOAD_SUBCAT(secfilt,SECFILT,SecFilt);
     461  LOAD_SUBCAT(lensing,LENSING,Lensing);
     462  LOAD_SUBCAT(lensobj,LENSOBJ,Lensobj);
     463  LOAD_SUBCAT(starpar,STARPAR,StarPar);
     464  LOAD_SUBCAT(galphot,GALPHOT,GalPhot);
     465
     466  /**  catalog->Nsecfilt is unusual: it does not list the number of data items in the
     467       table instead, the number of items is Nsecfilt * Naverage, and is stored in
     468       Nsecfilt_mem. fix these below **/
     469
     470  catalog[0].Nsecfilt_mem = catalog[0].Nsecfilt;
     471  catalog[0].Nsecfilt  = Nsecfilt;
     472
     473  /** some old formats stored one of the secfilt values in the average table.
     474      repair this below **/
     475
     476  if (primary) {
     477    if (catalog[0].Nsecfilt_mem) {
     478      dvo_catalog_primary_to_secfilt (catalog, primary, catalog[0].Naverage_disk);
    364479    } else {
    365       ALLOCATE (catalog[0].measure_catalog, Catalog, 1);
    366       dvo_catalog_init (catalog[0].measure_catalog, TRUE);
    367     }
    368     gfits_create_header (&catalog[0].measure_catalog[0].header);
    369     ALLOCATE (catalog[0].measure, Measure, 1);
    370     catalog[0].Nmeasure = 0;
    371     catalog[0].Nmeas_off = catalog[0].Nmeas_disk;
    372   }
    373   gfits_free_header (&header);
    374 
    375   /*** Missing Table ***/
    376   status = dvo_catalog_open_subcat (catalog, &catalog[0].missing_catalog, ftable.header, "MISSING", VERBOSE);
    377   if (status == DVO_CAT_OPEN_FAIL) {
    378     return (FALSE);
    379   }
    380   if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nmiss_disk > 0)) {
    381     return (FALSE);
    382   }
    383   if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MISS)) {
    384     /* read Missing table data */
    385     if (!gfits_fread_ftable_data (catalog[0].missing_catalog[0].f, &ftable, FALSE)) {
    386       if (VERBOSE) fprintf (stderr, "can't read table missing data\n");
    387       return (FALSE);
    388     }
    389     /* no conversions currently defined : this just does the byte swap */
    390     catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
    391     if (!catalog[0].missing) {
    392       fprintf (stderr, "ERROR: failed to read missing\n");
    393       exit (2);
    394     }
    395     if (Nmissing != catalog[0].Nmiss_disk) {
    396       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmissing,  catalog[0].Nmiss_disk);
    397     }
    398     catalog[0].Nmissing = catalog[0].Nmiss_disk;
    399     catalog[0].Nmiss_off = 0;
    400   } else {
    401     // XXX is it necessary to generate a template header here?
    402     gfits_create_header (&catalog[0].missing_catalog[0].header);
    403     ALLOCATE (catalog[0].missing, Missing, 1);
    404     catalog[0].Nmissing = 0;
    405     catalog[0].Nmiss_off = catalog[0].Nmiss_disk;
    406   }
    407   gfits_free_header (ftable.header);
    408 
    409   /*** Secfilt Table ***/
    410   status = dvo_catalog_open_subcat (catalog, &catalog[0].secfilt_catalog, ftable.header, "SECFILT", VERBOSE);
    411   // fprintf (stderr, "secfilt header %s : %zx\n", catalog[0].secfilt_catalog[0].filename, (size_t) catalog[0].secfilt_catalog[0].header.buffer);
    412   if (status == DVO_CAT_OPEN_FAIL) {
    413     return (FALSE);
    414   }
    415   if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nsecf_disk > 0)) {
    416     return (FALSE);
    417   }
    418   if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_SECF)) {
    419     /* read secfilt table data */
    420     if (!gfits_fread_ftable_data (catalog[0].secfilt_catalog[0].f, &ftable, FALSE)) {
    421       if (VERBOSE) fprintf (stderr, "can't read table secfilt data\n");
    422       return (FALSE);
    423     }
    424     catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
    425     if (Nitems != catalog[0].Nsecf_disk) {
    426       fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nitems,  catalog[0].Nsecf_disk);
    427     }
    428     catalog[0].Nsecf_mem = catalog[0].Nsecf_disk;
    429     catalog[0].Nsecf_off = 0;
    430 
    431     /* if primary is defined, we were supplied with one additional average magnitude from Average
    432        we need to interleave these magnitudes with the secfilt entries just loaded */
    433     if (primary != NULL) {
    434       // this modifies catalog.Nsecf_mem,Nsecfilt
    435       dvo_catalog_primary_to_secfilt (catalog, primary, catalog[0].Naves_disk);
    436     }
    437   } else {
    438     if (primary != NULL) {
    439480      free (primary);
    440481      catalog[0].Nsecfilt ++;
    441482    }
    442     gfits_create_header (&catalog[0].secfilt_catalog[0].header);
    443     ALLOCATE (catalog[0].secfilt, SecFilt, 1);
    444     catalog[0].Nsecf_mem = 0;
    445     catalog[0].Nsecf_off = catalog[0].Nsecf_disk;
    446   }
    447   gfits_free_header (ftable.header);
    448 
    449   /*** Lensing Table ***/
    450   if (!(catalog[0].catflags & SKIP_LENSING)) {
    451     // unless we specify 'skip', we still need to load the Lensing table
    452     status = dvo_catalog_open_subcat (catalog, &catalog[0].lensing_catalog, ftable.header, "LENSING", VERBOSE);
    453     if (status == DVO_CAT_OPEN_FAIL) {
    454       return (FALSE);
    455     }
    456     // the Lensing file need not exist, unless we expect data to exist
    457     if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nlensing_disk > 0)) {
    458       return (FALSE);
    459     }
    460   }
    461   if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_LENSING)) {
    462     // only read the Lensing table if the file actually exists
    463     /* read Lensing table data */
    464     if (!gfits_fread_ftable_data (catalog[0].lensing_catalog[0].f, &ftable, FALSE)) {
    465       if (VERBOSE) fprintf (stderr, "can't read table lensing data\n");
    466       return (FALSE);
    467     }
    468     /* convert data format to internal : returns number of row read in Nlensing */
    469     catalog[0].lensing = FtableToLensing (&ftable, &Nlensing, &catalog[0].catformat);
    470     if (Nlensing != catalog[0].Nlensing_disk) {
    471       fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  catalog[0].Nlensing_disk);
    472     }
    473     catalog[0].Nlensing = catalog[0].Nlensing_disk;
    474     catalog[0].Nlensing_off = 0;
    475   } else {
    476     if (catalog[0].lensing_catalog) {
    477       gfits_free_header (&catalog[0].lensing_catalog[0].header);
    478     } else {
    479       ALLOCATE (catalog[0].lensing_catalog, Catalog, 1);
    480       dvo_catalog_init (catalog[0].lensing_catalog, TRUE);
    481     }
    482     gfits_create_header (&catalog[0].lensing_catalog[0].header);
    483     ALLOCATE (catalog[0].lensing, Lensing, 1);
    484     catalog[0].Nlensing = 0;
    485     catalog[0].Nlensing_off = catalog[0].Nlensing_disk;
    486   }
    487   gfits_free_header (&header);
    488 
    489   /*** Lensobj Table ***/
    490   if (!(catalog[0].catflags & SKIP_LENSOBJ)) {
    491     // unless we specify 'skip', we still need to load the
    492     status = dvo_catalog_open_subcat (catalog, &catalog[0].lensobj_catalog, ftable.header, "LENSOBJ", VERBOSE);
    493     if (status == DVO_CAT_OPEN_FAIL) {
    494       return (FALSE);
    495     }
    496     // the Lensobj file need not exist, unless we expect data to exist
    497     if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nlensobj_disk > 0)) {
    498       return (FALSE);
    499     }
    500   }
    501   if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_LENSOBJ)) {
    502     // only read the Lensobj table if the file actually exists
    503     /* read Lensobj table data */
    504     if (!gfits_fread_ftable_data (catalog[0].lensobj_catalog[0].f, &ftable, FALSE)) {
    505       if (VERBOSE) fprintf (stderr, "can't read table lensobj data\n");
    506       return (FALSE);
    507     }
    508     /* convert data format to internal : returns number of row read in Nlensobj */
    509     catalog[0].lensobj = FtableToLensobj (&ftable, &Nlensobj, &catalog[0].catformat);
    510     if (Nlensobj != catalog[0].Nlensobj_disk) {
    511       fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  catalog[0].Nlensobj_disk);
    512     }
    513     catalog[0].Nlensobj = catalog[0].Nlensobj_disk;
    514     catalog[0].Nlensobj_off = 0;
    515   } else {
    516     if (catalog[0].lensobj_catalog) {
    517       gfits_free_header (&catalog[0].lensobj_catalog[0].header);
    518     } else {
    519       ALLOCATE (catalog[0].lensobj_catalog, Catalog, 1);
    520       dvo_catalog_init (catalog[0].lensobj_catalog, TRUE);
    521     }
    522     gfits_create_header (&catalog[0].lensobj_catalog[0].header);
    523     ALLOCATE (catalog[0].lensobj, Lensobj, 1);
    524     catalog[0].Nlensobj = 0;
    525     catalog[0].Nlensobj_off = catalog[0].Nlensobj_disk;
    526   }
    527   gfits_free_header (&header);
    528 
    529   /*** StarPar Table ***/
    530   if (!(catalog[0].catflags & SKIP_STARPAR)) {
    531     // unless we specify 'skip', we still need to load the
    532     status = dvo_catalog_open_subcat (catalog, &catalog[0].starpar_catalog, ftable.header, "STARPAR", VERBOSE);
    533     if (status == DVO_CAT_OPEN_FAIL) {
    534       return (FALSE);
    535     }
    536     // the StarPar file need not exist, unless we expect data to exist
    537     if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nstarpar_disk > 0)) {
    538       return (FALSE);
    539     }
    540   }
    541   if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_STARPAR)) {
    542     // only read the StarPar table if the file actually exists
    543     /* read StarPar table data */
    544     if (!gfits_fread_ftable_data (catalog[0].starpar_catalog[0].f, &ftable, FALSE)) {
    545       if (VERBOSE) fprintf (stderr, "can't read table starpar data\n");
    546       return (FALSE);
    547     }
    548     /* convert data format to internal : returns number of row read in Nstarpar */
    549     catalog[0].starpar = FtableToStarPar (&ftable, &Nstarpar, &catalog[0].catformat);
    550     if (Nstarpar != catalog[0].Nstarpar_disk) {
    551       fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  catalog[0].Nstarpar_disk);
    552     }
    553     catalog[0].Nstarpar = catalog[0].Nstarpar_disk;
    554     catalog[0].Nstarpar_off = 0;
    555   } else {
    556     if (catalog[0].starpar_catalog) {
    557       gfits_free_header (&catalog[0].starpar_catalog[0].header);
    558     } else {
    559       ALLOCATE (catalog[0].starpar_catalog, Catalog, 1);
    560       dvo_catalog_init (catalog[0].starpar_catalog, TRUE);
    561     }
    562     gfits_create_header (&catalog[0].starpar_catalog[0].header);
    563     ALLOCATE (catalog[0].starpar, StarPar, 1);
    564     catalog[0].Nstarpar = 0;
    565     catalog[0].Nstarpar_off = catalog[0].Nstarpar_disk;
    566   }
    567   gfits_free_header (&header);
     483  }
    568484
    569485  return (TRUE);
     
    575491
    576492  off_t Nbytes;
    577   off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj, Nstarpar;
     493  off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj, Nstarpar, Ngalphot;
    578494  Header header;
    579495  FTable ftable;
     
    587503
    588504  /*** Average (& SecFilt) Table ***/
    589   if (catalog[0].catflags & LOAD_AVES) {
     505  if (catalog[0].catflags & DVO_LOAD_AVERAGE) {
    590506
    591507    /*** load the Average data ***/
    592508    /* move pointer past header and matrix -- must be already read (load_catalog) */
    593509    Nbytes = catalog[0].header.datasize + gfits_data_size (&catalog[0].header);
    594     fseeko (catalog[0].f, Nbytes, SEEK_SET);
     510    if (fseeko (catalog[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
     511
    595512    /* read Average table header */
    596513    if (!gfits_fread_header (catalog[0].f, &header)) {
     
    607524     * one of the average magnitudes in Average.  We save this in case it is needed below.  NOTE:
    608525     * primary is only used if we read in the secfilt table, otherwise it should be freed */
    609     catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
     526    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary, FALSE);
    610527    if (Naverage != Nrows) {
    611528      // XXX this condition denotes the eof has been reached; not an error or a warning
     
    614531    gfits_free_header (&header);
    615532    catalog[0].Naverage = Naverage;
    616     catalog[0].Naves_off = start;
     533    catalog[0].Naverage_off = start;
    617534
    618535    /*** load the secfilt data ***/
     
    621538    /* move pointer past header -- must be already read (load_catalog) */
    622539    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
    623     fseeko (subcat[0].f, Nbytes, SEEK_SET);
     540    if (fseeko (subcat[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    624541
    625542    /* read Secfilt table header */
     
    635552
    636553    Nexpect = catalog[0].Naverage * catalog[0].Nsecfilt;
    637     catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
     554    catalog[0].secfilt = FtableToSecFilt (&ftable, catalog[0].average, &Nitems, &catalog[0].catformat, FALSE);
    638555    if (Nitems != Nexpect) {
    639556      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nitems,  Nexpect);
    640557    }
    641     catalog[0].Nsecf_mem = catalog[0].Naverage * catalog[0].Nsecfilt;
    642     catalog[0].Nsecf_off = start               * catalog[0].Nsecfilt;
     558    catalog[0].Nsecfilt_mem = catalog[0].Naverage * catalog[0].Nsecfilt;
     559    catalog[0].Nsecfilt_off = start               * catalog[0].Nsecfilt;
    643560
    644561    /* if primary is defined, we were supplied with one additional average magnitude from Average
     
    651568
    652569  // XXX check the open status of the catalog
    653   if (catalog[0].catflags & LOAD_MEAS) {
     570  if (catalog[0].catflags & DVO_LOAD_MEASURE) {
    654571
    655572    Catalog *subcat = catalog[0].measure_catalog;
     
    657574    /* move pointer past header -- must be already read (load_catalog) */
    658575    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
    659     fseeko (subcat[0].f, Nbytes, SEEK_SET);
     576    if (fseeko (subcat[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    660577
    661578    /* read Measure table header */
     
    671588
    672589    /* convert data format to internal : returns number of row read in Nmeasure */
    673     catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &Nmeasure, &catalog[0].catformat);
     590    catalog[0].measure = FtableToMeasure (&ftable, catalog[0].average, &Nmeasure, &catalog[0].catformat, FALSE);
    674591    if (Nmeasure != Nrows) {
    675592      // XXX this condition denotes the eof has been reached; not an error or a warning
     
    678595    gfits_free_header (&header);
    679596    catalog[0].Nmeasure = Nmeasure;
    680     catalog[0].Nmeas_off = start;
     597    catalog[0].Nmeasure_off = start;
    681598  }
    682599
    683600  // XXX check the open status of the catalog?
    684   if (catalog[0].catflags & LOAD_MISS) {
     601  if (catalog[0].catflags & DVO_LOAD_MISSING) {
    685602
    686603    Catalog *subcat = catalog[0].missing_catalog;
     
    688605    /* move pointer past header -- must be already read (load_catalog) */
    689606    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
    690     fseeko (subcat[0].f, Nbytes, SEEK_SET);
     607    if (fseeko (subcat[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    691608
    692609    /* read Missing table header */
     
    702619
    703620    /* no conversions currently defined : this just does the byte swap */
    704     catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
     621    catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL, NULL);
    705622    if (!catalog[0].missing) {
    706623      fprintf (stderr, "ERROR: failed to read missing\n");
     
    712629    gfits_free_header (&header);
    713630    catalog[0].Nmissing = Nmissing;
    714     catalog[0].Nmiss_off = start;
     631    catalog[0].Nmissing_off = start;
    715632  }
    716633
    717634  // XXX check the open status of the catalog
    718   if (catalog[0].catflags & LOAD_LENSING) {
     635  if (catalog[0].catflags & DVO_LOAD_LENSING) {
    719636
    720637    Catalog *subcat = catalog[0].lensing_catalog;
     
    722639    /* move pointer past header -- must be already read (load_catalog) */
    723640    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
    724     fseeko (subcat[0].f, Nbytes, SEEK_SET);
     641    if (fseeko (subcat[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    725642
    726643    /* read Lensing table header */
     
    736653
    737654    /* convert data format to internal : returns number of row read in Nlensing */
    738     catalog[0].lensing = FtableToLensing (&ftable, &Nlensing, &catalog[0].catformat);
     655    catalog[0].lensing = FtableToLensing (&ftable, catalog[0].average, &Nlensing, &catalog[0].catformat, FALSE);
    739656    if (Nlensing != Nrows) {
    740657      // XXX this condition denotes the eof has been reached; not an error or a warning
     
    747664
    748665  // XXX check the open status of the catalog
    749   if (catalog[0].catflags & LOAD_LENSOBJ) {
     666  if (catalog[0].catflags & DVO_LOAD_LENSOBJ) {
    750667
    751668    Catalog *subcat = catalog[0].lensobj_catalog;
     
    753670    /* move pointer past header -- must be already read (load_catalog) */
    754671    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
    755     fseeko (subcat[0].f, Nbytes, SEEK_SET);
     672    if (fseeko (subcat[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    756673
    757674    /* read Lensobj table header */
     
    767684
    768685    /* convert data format to internal : returns number of row read in Nlensobj */
    769     catalog[0].lensobj = FtableToLensobj (&ftable, &Nlensobj, &catalog[0].catformat);
     686    catalog[0].lensobj = FtableToLensobj (&ftable, catalog[0].average, &Nlensobj, &catalog[0].catformat, FALSE);
    770687    if (Nlensobj != Nrows) {
    771688      // XXX this condition denotes the eof has been reached; not an error or a warning
     
    778695
    779696  // XXX check the open status of the catalog
    780   if (catalog[0].catflags & LOAD_STARPAR) {
     697  if (catalog[0].catflags & DVO_LOAD_STARPAR) {
    781698
    782699    Catalog *subcat = catalog[0].starpar_catalog;
     
    784701    /* move pointer past header -- must be already read (load_catalog) */
    785702    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
    786     fseeko (subcat[0].f, Nbytes, SEEK_SET);
     703    if (fseeko (subcat[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    787704
    788705    /* read StarPar table header */
     
    798715
    799716    /* convert data format to internal : returns number of row read in Nstarpar */
    800     catalog[0].starpar = FtableToStarPar (&ftable, &Nstarpar, &catalog[0].catformat);
     717    catalog[0].starpar = FtableToStarPar (&ftable, catalog[0].average, &Nstarpar, &catalog[0].catformat, FALSE);
    801718    if (Nstarpar != Nrows) {
    802719      // XXX this condition denotes the eof has been reached; not an error or a warning
     
    808725  }
    809726
     727  // XXX check the open status of the catalog
     728  if (catalog[0].catflags & DVO_LOAD_GALPHOT) {
     729
     730    Catalog *subcat = catalog[0].galphot_catalog;
     731
     732    /* move pointer past header -- must be already read (load_catalog) */
     733    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
     734    if (fseeko (subcat[0].f, Nbytes, SEEK_SET)) { perror ("fseeko: "); exit (1); }
     735
     736    /* read GalPhot table header */
     737    if (!gfits_fread_header (subcat[0].f, &header)) {
     738      if (VERBOSE) fprintf (stderr, "can't read table galphot header");
     739      return (FALSE);
     740    }
     741    /* read GalPhot table data : format is irrelevant here */
     742    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     743      if (VERBOSE) fprintf (stderr, "can't read table galphot data");
     744      return (FALSE);
     745    }
     746
     747    /* convert data format to internal : returns number of row read in Ngalphot */
     748    catalog[0].galphot = FtableToGalPhot (&ftable, catalog[0].average, &Ngalphot, &catalog[0].catformat, FALSE);
     749    if (Ngalphot != Nrows) {
     750      // XXX this condition denotes the eof has been reached; not an error or a warning
     751      // fprintf (stderr, "Warning: mismatch between Ngalphot in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Ngalphot,  Nrows);
     752    }
     753    gfits_free_header (&header);
     754    catalog[0].Ngalphot = Ngalphot;
     755    catalog[0].Ngalphot_off = start;
     756  }
     757
    810758  return (TRUE);
    811759}
     
    814762int dvo_catalog_save_split (Catalog *catalog, char VERBOSE) {
    815763
    816   off_t Nitems;
    817764  Header header;
    818765  FTable ftable;
    819766  SecFilt *primary, *secfilt;
    820767  int Nsecfilt;
    821   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    822   off_t first, start, Nrows;
     768  off_t Naverage_disk_new, Nmeasure_disk_new, Nmissing_disk_new, Nsecfilt_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new, Ngalphot_disk_new;
    823769
    824770  ftable.header = &header;
     
    828774 
    829775  // skip empty catalogs: it is illegal to have Measures without corresponding Averages
    830   Naves_disk_new = MAX (catalog[0].Naves_disk, catalog[0].Naverage + catalog[0].Naves_off);
    831   if (Naves_disk_new == 0) {
     776  Naverage_disk_new = MAX (catalog[0].Naverage_disk, catalog[0].Naverage + catalog[0].Naverage_off);
     777  if (Naverage_disk_new == 0) {
    832778    if (VERBOSE) fprintf (stderr, "no stars in catalog, skipping\n");
    833779    return (TRUE);
     
    847793  }
    848794
    849   Nmeas_disk_new = MAX (catalog[0].Nmeas_disk, catalog[0].Nmeasure + catalog[0].Nmeas_off);
    850   Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
    851   Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
     795  Nmeasure_disk_new = MAX (catalog[0].Nmeasure_disk, catalog[0].Nmeasure + catalog[0].Nmeasure_off);
     796  Nmissing_disk_new = MAX (catalog[0].Nmissing_disk, catalog[0].Nmissing + catalog[0].Nmissing_off);
     797  Nsecfilt_disk_new = MAX (catalog[0].Nsecfilt_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecfilt_off);
    852798  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
    853799  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
    854800  Nstarpar_disk_new = MAX (catalog[0].Nstarpar_disk, catalog[0].Nstarpar + catalog[0].Nstarpar_off);
     801  Ngalphot_disk_new = MAX (catalog[0].Ngalphot_disk, catalog[0].Ngalphot + catalog[0].Ngalphot_off);
    855802
    856803  /* make sure header is consistent with data */
    857   gfits_modify (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  Naves_disk_new);
    858   gfits_modify (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  Nmeas_disk_new);
    859   gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    860   gfits_modify (&catalog[0].header, "NSECFILT", "%d",   1, Nsecfilt);
    861   gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    862   gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    863   gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
     804  gfits_modify (&catalog[0].header, "NSTARS",    OFF_T_FMT, 1,  Naverage_disk_new);
     805  gfits_modify (&catalog[0].header, "NMEAS",     OFF_T_FMT, 1,  Nmeasure_disk_new);
     806  gfits_modify (&catalog[0].header, "NMISS",     OFF_T_FMT, 1,  Nmissing_disk_new);
     807  gfits_modify (&catalog[0].header, "NSECFILT",  "%d",      1,  Nsecfilt);
     808  gfits_modify (&catalog[0].header, "NLENSING",  OFF_T_FMT, 1,  Nlensing_disk_new);
     809  gfits_modify (&catalog[0].header, "NLENSOBJ",  OFF_T_FMT, 1,  Nlensobj_disk_new);
     810  gfits_modify (&catalog[0].header, "NSTARPAR",  OFF_T_FMT, 1,  Nstarpar_disk_new);
     811  gfits_modify (&catalog[0].header, "NGALPHOT", OFF_T_FMT, 1,  Ngalphot_disk_new);
     812
    864813  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    865814  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    868817
    869818  /*** Average Table ***/
    870   if ((catalog[0].catflags & LOAD_AVES) && (catalog[0].average != NULL)) {
    871 
    872     first  = 0;                    // first row in memory to write
    873     start  = catalog[0].Naves_off; // first disk row to write
    874     Nrows  = catalog[0].Naverage - first;
     819  if ((catalog[0].catflags & DVO_LOAD_AVERAGE) && (catalog[0].average != NULL)) {
     820
     821    off_t first  = 0;                    // first row in memory to write
     822    off_t start  = catalog[0].Naverage_off; // first disk row to write
     823    off_t Nrows  = catalog[0].Naverage - first;
    875824
    876825    assert (Nrows >= 0);
    877826    assert (first >= 0);
    878827    assert (first <= catalog[0].Naverage);
    879     assert (catalog[0].Naves_disk >= catalog[0].Naves_off);
    880 
    881     /* convert internal to external format */
    882     if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary)) {
    883       fprintf (stderr, "trouble converting format\n");
    884       goto failure;
    885     }
    886 
    887     if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naves_disk, Naves_disk_new)) {
     828    assert (catalog[0].Naverage_disk >= catalog[0].Naverage_off);
     829
     830    /* convert internal to external format : also results in a byte-swapped, scaled output
     831       table.  Note that ftable is newly allocated.
     832    */
     833   
     834    // if we are going to compress, we need to receive unswapped data --
     835    int swapFromNative = !output_is_compressed (start, Nrows, Naverage_disk_new, catalog->catcompress);
     836
     837    // convert to external table format
     838    if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary, swapFromNative)) {
     839      fprintf (stderr, "trouble converting format\n");
     840      goto failure;
     841    }
     842
     843    if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naverage_disk, Naverage_disk_new)) {
    888844      fprintf (stderr, "failure writing Average table\n");
    889845      goto failure;
     
    894850    // even if we do not save the average table, we need to keep the header in sync
    895851    /* rewind file pointers and truncate (file is still open) */
    896     fseeko (catalog[0].f, 0, SEEK_SET);
     852    if (fseeko (catalog[0].f, 0, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    897853
    898854    /* write table PHU header - always write this out */
     
    905861
    906862  /*** Measure Table ***/
    907   if ((catalog[0].catflags & LOAD_MEAS) && (catalog[0].measure != NULL)) {
     863  if ((catalog[0].catflags & DVO_LOAD_MEASURE) && (catalog[0].measure != NULL)) {
     864
     865    off_t first  = 0;                    // first row in memory to write
     866    off_t start  = catalog[0].Nmeasure_off; // first disk row to write
     867    off_t Nrows  = catalog[0].Nmeasure - first;
     868
     869    assert (Nrows >= 0);
     870    assert (first >= 0);
     871    assert (first <= catalog[0].Nmeasure);
     872    assert (catalog[0].Nmeasure_disk >= catalog[0].Nmeasure_off);
     873
     874    // if we are going to compress, we need to receive unswapped data --
     875    int swapFromNative = !output_is_compressed (start, Nrows, Nmeasure_disk_new, catalog->catcompress);
     876
     877    // convert to external table format
     878    if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat, swapFromNative)) {
     879      fprintf (stderr, "trouble converting format\n");
     880      goto failure;
     881    }
     882
     883    // write out Measure table
     884    catalog->measure_catalog->catcompress = catalog->catcompress; // XXX this is a bit of a hack, should be done in an api
     885    if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeasure_disk, Nmeasure_disk_new)) {
     886      fprintf (stderr, "trouble writing Measure table\n");
     887      goto failure;
     888    }
     889    gfits_free_header (&header);
     890    gfits_free_table (&ftable);
     891  }
     892
     893  /*** Missing Table ***/
     894  if ((catalog[0].catflags & DVO_LOAD_MISSING) && (catalog[0].missing != NULL)) {
     895
     896    if (catalog[0].Nmissing_off != 0) {
     897      fprintf (stderr, "inconsistency: Missing table cannot be written in segments\n");
     898      goto failure;
     899    }
     900
     901    // if we are going to compress, we need to receive unswapped data --
     902    int swapFromNative = !output_is_compressed (catalog[0].Nmissing_off, catalog[0].Nmissing, Nmissing_disk_new, catalog->catcompress);
     903
     904    // convert to external table format
     905    if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing, swapFromNative)) {
     906      fprintf (stderr, "trouble converting format\n");
     907      goto failure;
     908    }
     909
     910    // write out Missing table (must write out entire table)
     911    catalog->missing_catalog->catcompress = catalog->catcompress; // XXX this is a bit of a hack, should be done in an api
     912    if (!dvo_catalog_save_subcat (catalog[0].missing_catalog, &ftable, 0, catalog[0].Nmissing, catalog[0].Nmissing, catalog[0].Nmissing)) {
     913      fprintf (stderr, "trouble writing Missing Table\n");
     914      goto failure;
     915    }
     916    gfits_free_header (&header);
     917    gfits_free_table (&ftable);
     918  }
     919
     920  /*** Secfilt Table ***/
     921  if ((catalog[0].catflags & DVO_LOAD_SECFILT) && (catalog[0].secfilt != NULL)) {
     922
     923    off_t first  = 0;                    // first row in memory to write
     924    off_t start  = catalog[0].Nsecfilt_off; // first disk row to write
     925    off_t Nitems = catalog[0].Naverage*Nsecfilt;
     926    off_t Nrows  = Nitems - first;
     927
     928    assert (Nrows >= 0);
     929    assert (first >= 0);
     930    assert (first <= Nitems);
     931    assert (catalog[0].Nsecfilt_disk >= catalog[0].Nsecfilt_off);
     932    // XXX check these for consistency...
     933
     934    // if we are going to compress, we need to receive unswapped data --
     935    int swapFromNative = !output_is_compressed (start, Nrows, Nsecfilt_disk_new, catalog->catcompress);
     936
     937    // convert to external table format
     938    if (!SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat, swapFromNative)) {
     939      fprintf (stderr, "trouble converting format\n");
     940      goto failure;
     941    }
     942
     943    // write out SecFilt table
     944    catalog->secfilt_catalog->catcompress = catalog->catcompress; // XXX this is a bit of a hack, should be done in an api
     945    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecfilt_disk, Nsecfilt_disk_new)) {
     946      fprintf (stderr, "failure writing SecFilt table\n");
     947      goto failure;
     948    }
     949    gfits_free_header (&header);
     950    gfits_free_table (&ftable);
     951  }
     952
     953  /*** Lensing Table ***/
     954  if ((catalog[0].catflags & DVO_LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     955
     956    off_t first  = 0;                    // first row in memory to write
     957    off_t start  = catalog[0].Nlensing_off; // first disk row to write
     958    off_t Nrows  = catalog[0].Nlensing - first;
     959
     960    assert (Nrows >= 0);
     961    assert (first >= 0);
     962    assert (first <= catalog[0].Nlensing);
     963    assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
     964
     965    // if we are going to compress, we need to receive unswapped data --
     966    int swapFromNative = !output_is_compressed (start, Nrows, Nlensing_disk_new, catalog->catcompress);
     967
     968    // convert to external table format
     969    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat, swapFromNative)) {
     970      fprintf (stderr, "trouble converting format\n");
     971      goto failure;
     972    }
     973
     974    // write out Lensing table
     975    catalog->lensing_catalog->catcompress = catalog->catcompress; // XXX this is a bit of a hack, should be done in an api
     976    if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
     977      fprintf (stderr, "trouble writing Lensing table\n");
     978      goto failure;
     979    }
     980    gfits_free_header (&header);
     981    gfits_free_table (&ftable);
     982  }
     983
     984  /*** Lensobj Table ***/
     985  if ((catalog[0].catflags & DVO_LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     986
     987    off_t first  = 0;                    // first row in memory to write
     988    off_t start  = catalog[0].Nlensobj_off; // first disk row to write
     989    off_t Nrows  = catalog[0].Nlensobj - first;
     990
     991    assert (Nrows >= 0);
     992    assert (first >= 0);
     993    assert (first <= catalog[0].Nlensobj);
     994    assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
     995
     996    // if we are going to compress, we need to receive unswapped data --
     997    int swapFromNative = !output_is_compressed (start, Nrows, Nlensobj_disk_new, catalog->catcompress);
     998
     999    // convert to external table format
     1000    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat, swapFromNative)) {
     1001      fprintf (stderr, "trouble converting format\n");
     1002      goto failure;
     1003    }
     1004
     1005    // write out Lensobj table
     1006    catalog->lensobj_catalog->catcompress = catalog->catcompress; // XXX this is a bit of a hack, should be done in an api
     1007    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
     1008      fprintf (stderr, "trouble writing Lensobj table\n");
     1009      goto failure;
     1010    }
     1011    gfits_free_header (&header);
     1012    gfits_free_table (&ftable);
     1013  }
     1014
     1015  /*** StarPar Table ***/
     1016  if ((catalog[0].catflags & DVO_LOAD_STARPAR) && (catalog[0].starpar != NULL)) {
     1017
     1018    off_t first  = 0;                    // first row in memory to write
     1019    off_t start  = catalog[0].Nstarpar_off; // first disk row to write
     1020    off_t Nrows  = catalog[0].Nstarpar - first;
     1021
     1022    assert (Nrows >= 0);
     1023    assert (first >= 0);
     1024    assert (first <= catalog[0].Nstarpar);
     1025    assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
     1026
     1027    // if we are going to compress, we need to receive unswapped data --
     1028    int swapFromNative = !output_is_compressed (start, Nrows, Nstarpar_disk_new, catalog->catcompress);
     1029
     1030    // convert to external table format
     1031    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat, swapFromNative)) {
     1032      fprintf (stderr, "trouble converting format\n");
     1033      goto failure;
     1034    }
     1035
     1036    // write out StarPar table
     1037    catalog->starpar_catalog->catcompress = catalog->catcompress; // XXX this is a bit of a hack, should be done in an api
     1038    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
     1039      fprintf (stderr, "trouble writing StarPar table\n");
     1040      goto failure;
     1041    }
     1042    gfits_free_header (&header);
     1043    gfits_free_table (&ftable);
     1044  }
     1045
     1046  /*** GalPhot Table ***/
     1047  if ((catalog[0].catflags & DVO_LOAD_GALPHOT) && (catalog[0].galphot != NULL)) {
     1048
     1049    off_t first  = 0;                    // first row in memory to write
     1050    off_t start  = catalog[0].Ngalphot_off; // first disk row to write
     1051    off_t Nrows  = catalog[0].Ngalphot - first;
     1052
     1053    assert (Nrows >= 0);
     1054    assert (first >= 0);
     1055    assert (first <= catalog[0].Ngalphot);
     1056    assert (catalog[0].Ngalphot_disk >= catalog[0].Ngalphot_off);
     1057
     1058    // if we are going to compress, we need to receive unswapped data --
     1059    int swapFromNative = !output_is_compressed (start, Nrows, Ngalphot_disk_new, catalog->catcompress);
     1060
     1061    // convert to external table format
     1062    if (!GalPhotToFtable (&ftable, &catalog[0].galphot[first], Nrows, catalog[0].catformat, swapFromNative)) {
     1063      fprintf (stderr, "trouble converting format\n");
     1064      goto failure;
     1065    }
     1066
     1067    // write out GalPhot table
     1068    catalog->galphot_catalog->catcompress = catalog->catcompress; // XXX this is a bit of a hack, should be done in an api
     1069    if (!dvo_catalog_save_subcat (catalog[0].galphot_catalog, &ftable, start, Nrows, catalog[0].Ngalphot_disk, Ngalphot_disk_new)) {
     1070      fprintf (stderr, "trouble writing GalPhot table\n");
     1071      goto failure;
     1072    }
     1073    gfits_free_header (&header);
     1074    gfits_free_table (&ftable);
     1075  }
     1076
     1077  /* free temp storage */
     1078  if (primary != NULL) {
     1079    free (primary);
     1080    free (secfilt);
     1081  }
     1082  return (TRUE);
     1083
     1084 failure:
     1085  /* free temp storage */
     1086  gfits_free_header (&header);
     1087  gfits_free_table (&ftable);
     1088  if (primary != NULL) {
     1089    free (primary);
     1090    free (secfilt);
     1091  }
     1092  return (FALSE);
     1093}
     1094
     1095/* update_catalog_split only writes new lines to file. */
     1096int dvo_catalog_update_split (Catalog *catalog, char VERBOSE) {
     1097
     1098  off_t Nitems;
     1099  Header header;
     1100  FTable ftable;
     1101  SecFilt *primary, *secfilt;
     1102  int Nsecfilt;
     1103  off_t Naverage_disk_new, Nmeasure_disk_new, Nmissing_disk_new, Nsecfilt_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new, Ngalphot_disk_new;
     1104  off_t first, start, Nrows;
     1105
     1106  ftable.header = &header;
     1107  ftable.buffer = NULL;
     1108  header.buffer = NULL;
     1109
     1110  // skip empty catalogs: it is illegal to have Measures without corresponding Averages
     1111  Naverage_disk_new = MAX (catalog[0].Naverage_disk, catalog[0].Naverage + catalog[0].Naverage_off);
     1112  if (Naverage_disk_new == 0) {
     1113    if (VERBOSE) fprintf (stderr, "no stars in catalog, skipping\n");
     1114    return (TRUE);
     1115  }
     1116
     1117  // for the appropriate types, pull out the first secfilt and pass to AverageToFtable as primary
     1118  switch (catalog[0].catformat) {
     1119    case DVO_FORMAT_ELIXIR: // special case for ELIXIR
     1120    case DVO_FORMAT_LONEOS: // special case for LONEOS
     1121      dvo_catalog_secfilt_to_primary (catalog, &primary, &secfilt, &Nsecfilt);
     1122      break;
     1123    default:
     1124      primary = NULL;
     1125      secfilt = catalog[0].secfilt;
     1126      Nsecfilt = catalog[0].Nsecfilt;
     1127      break;
     1128  }
     1129
     1130  Nmeasure_disk_new = MAX (catalog[0].Nmeasure_disk, catalog[0].Nmeasure + catalog[0].Nmeasure_off);
     1131  Nmissing_disk_new = MAX (catalog[0].Nmissing_disk, catalog[0].Nmissing + catalog[0].Nmissing_off);
     1132  Nsecfilt_disk_new = MAX (catalog[0].Nsecfilt_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecfilt_off);
     1133  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
     1134  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
     1135  Nstarpar_disk_new = MAX (catalog[0].Nstarpar_disk, catalog[0].Nstarpar + catalog[0].Nstarpar_off);
     1136  Ngalphot_disk_new = MAX (catalog[0].Ngalphot_disk, catalog[0].Ngalphot + catalog[0].Ngalphot_off);
     1137
     1138  /* make sure header is consistent with data */
     1139  gfits_modify (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  Naverage_disk_new);
     1140  gfits_modify (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  Nmeasure_disk_new);
     1141  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmissing_disk_new);
     1142  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
     1143  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
     1144  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
     1145  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
     1146  gfits_modify (&catalog[0].header, "NGALPHOT", OFF_T_FMT, 1,  Ngalphot_disk_new);
     1147
     1148  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
     1149  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     1150
     1151  /* in split mode, we can save only part of the data */
     1152
     1153  /*** Average Table ***/
     1154  if (catalog[0].average != NULL) {
     1155
     1156    first  = catalog[0].Naverage_disk - catalog[0].Naverage_off; // first row to write (memory)
     1157    start  = catalog[0].Naverage_disk;                        // first row to write (disk)
     1158    Nrows  = catalog[0].Naverage - first;
     1159
     1160    assert (Nrows >= 0);
     1161    assert (first >= 0);
     1162    assert (first <= catalog[0].Naverage);
     1163    assert (catalog[0].Naverage_disk >= catalog[0].Naverage_off);
     1164
     1165    /* convert internal to external format */
     1166    if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary, TRUE)) {
     1167      fprintf (stderr, "trouble converting format\n");
     1168      goto failure;
     1169    }
     1170
     1171    if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naverage_disk, Naverage_disk_new)) {
     1172      fprintf (stderr, "failure writing Average table\n");
     1173      goto failure;
     1174    }
     1175    gfits_free_header (&header);
     1176    gfits_free_table (&ftable);
     1177  } else {
     1178    // even if we do not save the average table, we need to keep the header in sync
     1179    /* rewind file pointers and truncate (file is still open) */
     1180    if (fseeko (catalog[0].f, 0, SEEK_SET)) { perror ("fseeko: "); exit (1); }
     1181
     1182    /* write table PHU header - always write this out */
     1183    /* XXX EAM : check if disk file size has changed */
     1184    if (!gfits_fwrite_header  (catalog[0].f, &catalog[0].header)) {
     1185      fprintf (stderr, "can't write primary header");
     1186      goto failure;
     1187    }
     1188  }
     1189
     1190  /*** Measure Table ***/
     1191  if ((catalog[0].catflags & DVO_LOAD_MEASURE) && (catalog[0].measure != NULL)) {
    9081192
    9091193    first  = 0;                    // first row in memory to write
    910     start  = catalog[0].Nmeas_off; // first disk row to write
     1194    start  = catalog[0].Nmeasure_off; // first disk row to write
    9111195    Nrows  = catalog[0].Nmeasure - first;
    9121196
     
    9141198    assert (first >= 0);
    9151199    assert (first <= catalog[0].Nmeasure);
    916     assert (catalog[0].Nmeas_disk >= catalog[0].Nmeas_off);
     1200    assert (catalog[0].Nmeasure_disk >= catalog[0].Nmeasure_off);
    9171201
    9181202    // convert to external table format (note that the block above does not damage or free catalog.average)
    919     if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
     1203    if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat, TRUE)) {
    9201204      fprintf (stderr, "trouble converting format\n");
    9211205      goto failure;
     
    9231207
    9241208    // write out Measure table
    925     if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeas_disk, Nmeas_disk_new)) {
     1209    if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeasure_disk, Nmeasure_disk_new)) {
    9261210      fprintf (stderr, "trouble writing Measure table\n");
    9271211      goto failure;
     
    9321216
    9331217  /*** Missing Table ***/
    934   if ((catalog[0].catflags & LOAD_MISS) && (catalog[0].missing != NULL)) {
    935 
    936     if (catalog[0].Nmiss_off != 0) {
     1218  if ((catalog[0].catflags & DVO_LOAD_MISSING) && (catalog[0].missing != NULL)) {
     1219
     1220    if (catalog[0].Nmissing_off != 0) {
    9371221      fprintf (stderr, "inconsistency: Missing table cannot be written in segments\n");
    9381222      goto failure;
     
    9401224
    9411225    // convert to external table format
    942     if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing)) {
     1226    if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing, TRUE)) {
    9431227      fprintf (stderr, "trouble converting format\n");
    9441228      goto failure;
     
    9551239
    9561240  /*** Secfilt Table ***/
    957   if ((catalog[0].catflags & LOAD_SECF) && (catalog[0].secfilt != NULL)) {
     1241  if ((catalog[0].catflags & DVO_LOAD_SECFILT) && (catalog[0].secfilt != NULL)) {
    9581242
    9591243    first  = 0;                    // first row in memory to write
    960     start  = catalog[0].Nsecf_off; // first disk row to write
    961     Nitems = catalog[0].Nsecf_mem;
     1244    start  = catalog[0].Nsecfilt_off; // first disk row to write
     1245    Nitems = catalog[0].Nsecfilt_mem;
    9621246    Nrows  = Nitems - first;
    9631247
     
    9651249    assert (first >= 0);
    9661250    assert (first <= Nitems);
    967     assert (catalog[0].Nsecf_disk >= catalog[0].Nsecf_off);
     1251    assert (catalog[0].Nsecfilt_disk >= catalog[0].Nsecfilt_off);
    9681252    // XXX check these for consistency...
    9691253
    9701254    // convert to external table format
    971     SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat);
     1255    if (!SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat, TRUE)) {
     1256      fprintf (stderr, "trouble converting format\n");
     1257      goto failure;
     1258    }
    9721259
    9731260    // write out SecFilt table
    974     if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
     1261    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecfilt_disk, Nsecfilt_disk_new)) {
    9751262      fprintf (stderr, "failure writing SecFilt table\n");
    9761263      goto failure;
     
    9811268
    9821269  /*** Lensing Table (optional, do not save if not loaded) ***/
    983   if ((catalog[0].catflags & LOAD_LENSING) && catalog[0].lensing_catalog->f && catalog[0].lensing) {
     1270  if ((catalog[0].catflags & DVO_LOAD_LENSING) && catalog[0].lensing_catalog->f && catalog[0].lensing) {
    9841271
    9851272    first  = 0;                    // first row in memory to write
     
    9941281    if (catalog[0].Nlensing) {
    9951282      // convert to external table format (note that the block above does not damage or free catalog.average)
    996       if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     1283      if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat, TRUE)) {
    9971284        fprintf (stderr, "trouble converting format\n");
    9981285        goto failure;
     
    10101297
    10111298  /*** Lensobj Table (optional, do not save if not loaded) ***/
    1012   if ((catalog[0].catflags & LOAD_LENSOBJ) && catalog[0].lensobj_catalog->f && catalog[0].lensobj) {
     1299  if ((catalog[0].catflags & DVO_LOAD_LENSOBJ) && catalog[0].lensobj_catalog->f && catalog[0].lensobj) {
    10131300
    10141301    first  = 0;                    // first row in memory to write
     
    10231310    if (catalog[0].Nlensobj) {
    10241311      // convert to external table format (note that the block above does not damage or free catalog.average)
    1025       if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     1312      if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat, TRUE)) {
    10261313        fprintf (stderr, "trouble converting format\n");
    10271314        goto failure;
     
    10391326
    10401327  /*** StarPar Table (optional, do not save if not loaded) ***/
    1041     if ((catalog[0].catflags & LOAD_STARPAR) && catalog[0].starpar_catalog->f && catalog[0].starpar) {
     1328  if ((catalog[0].catflags & DVO_LOAD_STARPAR) && catalog[0].starpar_catalog->f && catalog[0].starpar) {
    10421329
    10431330    first  = 0;                    // first row in memory to write
     
    10521339    if (catalog[0].Nstarpar) {
    10531340      // convert to external table format (note that the block above does not damage or free catalog.average)
    1054       if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1341      if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat, TRUE)) {
    10551342        fprintf (stderr, "trouble converting format\n");
    10561343        goto failure;
     
    10671354  }
    10681355
     1356  /*** GalPhot Table (optional, do not save if not loaded) ***/
     1357  if ((catalog[0].catflags & DVO_LOAD_GALPHOT) && catalog[0].galphot_catalog->f && catalog[0].galphot) {
     1358
     1359    first  = 0;                    // first row in memory to write
     1360    start  = catalog[0].Ngalphot_off; // first disk row to write
     1361    Nrows  = catalog[0].Ngalphot - first;
     1362
     1363    assert (Nrows >= 0);
     1364    assert (first >= 0);
     1365    assert (first <= catalog[0].Ngalphot);
     1366    assert (catalog[0].Ngalphot_disk >= catalog[0].Ngalphot_off);
     1367
     1368    if (catalog[0].Ngalphot) {
     1369      // convert to external table format (note that the block above does not damage or free catalog.average)
     1370      if (!GalPhotToFtable (&ftable, &catalog[0].galphot[first], Nrows, catalog[0].catformat, TRUE)) {
     1371        fprintf (stderr, "trouble converting format\n");
     1372        goto failure;
     1373      }
     1374
     1375      // write out GalPhot table
     1376      if (!dvo_catalog_save_subcat (catalog[0].galphot_catalog, &ftable, start, Nrows, catalog[0].Ngalphot_disk, Ngalphot_disk_new)) {
     1377        fprintf (stderr, "trouble writing GalPhot table\n");
     1378        goto failure;
     1379      }
     1380      gfits_free_header (&header);
     1381      gfits_free_table (&ftable);
     1382    }
     1383  }
     1384
    10691385  /* free temp storage */
    10701386  if (primary != NULL) {
     
    10741390  return (TRUE);
    10751391
    1076 failure:
     1392 failure:
    10771393  /* free temp storage */
    10781394  gfits_free_header (&header);
     
    10881404int dvo_catalog_save_split_complete (Catalog *catalog, char VERBOSE) {
    10891405
    1090   off_t Nitems;
    10911406  Header header;
    10921407  FTable ftable;
    10931408  SecFilt *primary, *secfilt;
    10941409  int Nsecfilt;
    1095   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
     1410  off_t Naverage_disk_new, Nmeasure_disk_new, Nmissing_disk_new, Nsecfilt_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new, Ngalphot_disk_new;
    10961411  off_t first, start, Nrows;
    10971412
     
    11021417 
    11031418  // skip empty catalogs: it is illegal to have Measures without corresponding Averages
    1104   if (catalog[0].Naves_off > 0) {
     1419  if (catalog[0].Naverage_off > 0) {
    11051420    fprintf (stderr, "ERROR: only partial catalog (Average) was loaded\n");
    11061421    goto failure;
    11071422  }
    1108   if (catalog[0].Nmeas_off > 0) {
     1423  if (catalog[0].Nmeasure_off > 0) {
    11091424    fprintf (stderr, "ERROR: only partial catalog (Measure) was loaded\n");
    11101425    goto failure;
    11111426  }
    1112   if (catalog[0].Nmiss_off > 0) {
     1427  if (catalog[0].Nmissing_off > 0) {
    11131428    fprintf (stderr, "ERROR: only partial catalog (Missing) was loaded\n");
    11141429    goto failure;
    11151430  }
    1116   if (catalog[0].Nsecf_off > 0) {
     1431  if (catalog[0].Nsecfilt_off > 0) {
    11171432    fprintf (stderr, "ERROR: only partial catalog (Secfilt) was loaded\n");
    11181433    goto failure;
     
    11301445    goto failure;
    11311446  }
    1132 
    1133   Naves_disk_new = catalog[0].Naverage;
    1134   if (Naves_disk_new == 0) {
     1447  if (catalog[0].Ngalphot_off > 0) {
     1448    fprintf (stderr, "ERROR: only partial catalog (GalPhot) was loaded\n");
     1449    goto failure;
     1450  }
     1451
     1452  Naverage_disk_new = catalog[0].Naverage;
     1453  if (Naverage_disk_new == 0) {
    11351454    if (VERBOSE) fprintf (stderr, "resulting catalog is empty; delete it\n");
    11361455    // unlink ();
     
    11511470  }
    11521471
    1153   Nmeas_disk_new = catalog[0].Nmeasure;
    1154   Nmiss_disk_new = catalog[0].Nmissing;
    1155   Nsecf_disk_new = catalog[0].Naverage*Nsecfilt;
     1472  Nmeasure_disk_new = catalog[0].Nmeasure;
     1473  Nmissing_disk_new = catalog[0].Nmissing;
     1474  Nsecfilt_disk_new = catalog[0].Naverage*Nsecfilt;
    11561475  Nlensing_disk_new = catalog[0].Nlensing;
    11571476  Nlensobj_disk_new = catalog[0].Nlensobj;
    11581477  Nstarpar_disk_new = catalog[0].Nstarpar;
     1478  Ngalphot_disk_new = catalog[0].Ngalphot;
    11591479
    11601480  /* make sure header is consistent with data */
    1161   gfits_modify (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  Naves_disk_new);
    1162   gfits_modify (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  Nmeas_disk_new);
    1163   gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
     1481  gfits_modify (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  Naverage_disk_new);
     1482  gfits_modify (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  Nmeasure_disk_new);
     1483  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmissing_disk_new);
    11641484  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
    11651485  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    11661486  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    11671487  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
     1488  gfits_modify (&catalog[0].header, "NGALPHOT", OFF_T_FMT, 1, Ngalphot_disk_new);
    11681489  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    11691490  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    11721493
    11731494  /*** Average Table ***/
    1174   if ((catalog[0].catflags & LOAD_AVES) && (catalog[0].average != NULL)) {
     1495  if ((catalog[0].catflags & DVO_LOAD_AVERAGE) && (catalog[0].average != NULL)) {
    11751496
    11761497    first  = 0;                    // first row in memory to write
    1177     start  = catalog[0].Naves_off; // first disk row to write
     1498    start  = catalog[0].Naverage_off; // first disk row to write
    11781499    Nrows  = catalog[0].Naverage - first;
    11791500
     
    11811502    assert (first >= 0);
    11821503    assert (first <= catalog[0].Naverage);
    1183     assert (catalog[0].Naves_disk >= catalog[0].Naves_off);
     1504    assert (catalog[0].Naverage_disk >= catalog[0].Naverage_off);
    11841505
    11851506    /* convert internal to external format */
    1186     if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary)) {
    1187       fprintf (stderr, "trouble converting format\n");
    1188       goto failure;
    1189     }
    1190 
    1191     if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naves_disk, Naves_disk_new)) {
     1507    if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary, TRUE)) {
     1508      fprintf (stderr, "trouble converting format\n");
     1509      goto failure;
     1510    }
     1511
     1512    if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naverage_disk, Naverage_disk_new)) {
    11921513      fprintf (stderr, "failure writing Average table\n");
    11931514      goto failure;
     
    11981519    // even if we do not save the average table, we need to keep the header in sync
    11991520    /* rewind file pointers and truncate (file is still open) */
    1200     fseeko (catalog[0].f, 0, SEEK_SET);
     1521    if (fseeko (catalog[0].f, 0, SEEK_SET)) { perror ("fseeko: "); exit (1); }
    12011522
    12021523    /* write table PHU header - always write this out */
     
    12091530
    12101531  /*** Measure Table ***/
    1211   if ((catalog[0].catflags & LOAD_MEAS) && (catalog[0].measure != NULL)) {
    1212 
    1213     first  = 0;                    // first row in memory to write
    1214     start  = catalog[0].Nmeas_off; // first disk row to write
     1532  if (catalog[0].measure != NULL) {
     1533
     1534    first  = catalog[0].Nmeasure_disk - catalog[0].Nmeasure_off;  // first row in memory to write
     1535    start  = catalog[0].Nmeasure_disk; // first disk row to write
    12151536    Nrows  = catalog[0].Nmeasure - first;
    12161537
     
    12181539    assert (first >= 0);
    12191540    assert (first <= catalog[0].Nmeasure);
    1220     assert (catalog[0].Nmeas_disk >= catalog[0].Nmeas_off);
     1541    assert (catalog[0].Nmeasure_disk >= catalog[0].Nmeasure_off);
    12211542
    12221543    // convert to external table format
    1223     if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
     1544    // XXX does catalog.measure have averef correctly set up?
     1545    if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat, TRUE)) {
    12241546      fprintf (stderr, "trouble converting format\n");
    12251547      goto failure;
     
    12271549
    12281550    // write out Measure table
    1229     if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeas_disk, Nmeas_disk_new)) {
     1551    if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeasure_disk, Nmeasure_disk_new)) {
    12301552      fprintf (stderr, "trouble writing Measure table\n");
    12311553      goto failure;
     
    12351557  }
    12361558
     1559  /* missing table CANNOT be written unsorted, thus it is always written
     1560     out in full */
     1561
    12371562  /*** Missing Table ***/
    1238   if ((catalog[0].catflags & LOAD_MISS) && (catalog[0].missing != NULL)) {
    1239 
    1240     if (catalog[0].Nmiss_off != 0) {
     1563
     1564  if (catalog[0].missing != NULL) {
     1565
     1566    if (catalog[0].Nmissing_off != 0) {
    12411567      fprintf (stderr, "inconsistency: Missing table cannot be written in segments\n");
    12421568      goto failure;
     
    12441570
    12451571    // convert to external table format
    1246     if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing)) {
     1572    if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing, TRUE)) {
    12471573      fprintf (stderr, "trouble converting format\n");
    12481574      goto failure;
     
    12591585
    12601586  /*** Secfilt Table ***/
    1261   if ((catalog[0].catflags & LOAD_SECF) && (catalog[0].secfilt != NULL)) {
    1262 
    1263     first  = 0;                    // first row in memory to write
    1264     start  = catalog[0].Nsecf_off; // first disk row to write
    1265     Nitems = catalog[0].Naverage*Nsecfilt;
    1266     Nrows  = Nitems - first;
    1267 
    1268     assert (Nrows >= 0);
    1269     assert (first >= 0);
    1270     assert (first <= Nitems);
    1271     assert (catalog[0].Nsecf_disk >= catalog[0].Nsecf_off);
    1272     // XXX check these for consistency...
     1587  if (catalog[0].secfilt != NULL) {
     1588
     1589    first  = catalog[0].Nsecfilt_disk - catalog[0].Nsecfilt_off;  // first row in memory to write
     1590    start  = catalog[0].Nsecfilt_disk; // first disk row to write
     1591    Nrows  = catalog[0].Nsecfilt_mem - first;
     1592
     1593    assert (Nrows >= 0);
     1594    assert (first >= 0);
     1595    assert (catalog[0].Nsecfilt_disk >= catalog[0].Nsecfilt_off);
    12731596
    12741597    // convert to external table format
    1275     SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat);
     1598    if (!SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat, TRUE)) {
     1599      fprintf (stderr, "trouble converting format\n");
     1600      goto failure;
     1601    }
    12761602
    12771603    // write out SecFilt table
    1278     if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
     1604    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecfilt_disk, Nsecfilt_disk_new)) {
    12791605      fprintf (stderr, "failure writing SecFilt table\n");
    12801606      goto failure;
     
    12851611
    12861612  /*** Lensing Table ***/
    1287   if ((catalog[0].catflags & LOAD_LENSING) && (catalog[0].lensing != NULL)) {
    1288 
    1289     first  = 0;                    // first row in memory to write
    1290     start  = catalog[0].Nlensing_off; // first disk row to write
     1613  if (catalog[0].lensing != NULL) {
     1614
     1615    first  = catalog[0].Nlensing_disk - catalog[0].Nlensing_off;  // first row in memory to write
     1616    start  = catalog[0].Nlensing_disk; // first disk row to write
    12911617    Nrows  = catalog[0].Nlensing - first;
    12921618
     
    12971623
    12981624    // convert to external table format
    1299     if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     1625    // XXX does catalog.lensing have averef correctly set up?
     1626    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat, TRUE)) {
    13001627      fprintf (stderr, "trouble converting format\n");
    13011628      goto failure;
     
    13121639
    13131640  /*** Lensobj Table ***/
    1314   if ((catalog[0].catflags & LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
    1315 
    1316     first  = 0;                    // first row in memory to write
    1317     start  = catalog[0].Nlensobj_off; // first disk row to write
     1641  if (catalog[0].lensobj != NULL) {
     1642
     1643    first  = catalog[0].Nlensobj_disk - catalog[0].Nlensobj_off;  // first row in memory to write
     1644    start  = catalog[0].Nlensobj_disk; // first disk row to write
    13181645    Nrows  = catalog[0].Nlensobj - first;
    13191646
     
    13241651
    13251652    // convert to external table format
    1326     if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     1653    // XXX does catalog.lensobj have averef correctly set up?
     1654    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat, TRUE)) {
    13271655      fprintf (stderr, "trouble converting format\n");
    13281656      goto failure;
     
    13391667
    13401668  /*** StarPar Table ***/
    1341   if ((catalog[0].catflags & LOAD_STARPAR) && (catalog[0].starpar != NULL)) {
    1342 
    1343     first  = 0;                    // first row in memory to write
    1344     start  = catalog[0].Nstarpar_off; // first disk row to write
     1669  if (catalog[0].starpar != NULL) {
     1670
     1671    first  = catalog[0].Nstarpar_disk - catalog[0].Nstarpar_off;  // first row in memory to write
     1672    start  = catalog[0].Nstarpar_disk; // first disk row to write
    13451673    Nrows  = catalog[0].Nstarpar - first;
    13461674
     
    13511679
    13521680    // convert to external table format
    1353     if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1681    // XXX does catalog.starpar have averef correctly set up?
     1682    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat, TRUE)) {
    13541683      fprintf (stderr, "trouble converting format\n");
    13551684      goto failure;
     
    13591688    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
    13601689      fprintf (stderr, "trouble writing StarPar table\n");
     1690      goto failure;
     1691    }
     1692    gfits_free_header (&header);
     1693    gfits_free_table (&ftable);
     1694  }
     1695
     1696  /*** GalPhot Table ***/
     1697  if (catalog[0].galphot != NULL) {
     1698
     1699    first  = catalog[0].Ngalphot_disk - catalog[0].Ngalphot_off;  // first row in memory to write
     1700    start  = catalog[0].Ngalphot_disk; // first disk row to write
     1701    Nrows  = catalog[0].Ngalphot - first;
     1702
     1703    assert (Nrows >= 0);
     1704    assert (first >= 0);
     1705    assert (first <= catalog[0].Ngalphot);
     1706    assert (catalog[0].Ngalphot_disk >= catalog[0].Ngalphot_off);
     1707
     1708    // convert to external table format
     1709    // XXX does catalog.galphot have averef correctly set up?
     1710    if (!GalPhotToFtable (&ftable, &catalog[0].galphot[first], Nrows, catalog[0].catformat, TRUE)) {
     1711      fprintf (stderr, "trouble converting format\n");
     1712      goto failure;
     1713    }
     1714
     1715    // write out GalPhot table
     1716    if (!dvo_catalog_save_subcat (catalog[0].galphot_catalog, &ftable, start, Nrows, catalog[0].Ngalphot_disk, Ngalphot_disk_new)) {
     1717      fprintf (stderr, "trouble writing GalPhot table\n");
    13611718      goto failure;
    13621719    }
     
    13701727    free (secfilt);
    13711728  }
     1729
    13721730  return (TRUE);
    13731731
    1374 failure:
    1375   /* free temp storage */
    1376   gfits_free_header (&header);
    1377   gfits_free_table (&ftable);
    1378   if (primary != NULL) {
    1379     free (primary);
    1380     free (secfilt);
    1381   }
    1382   return (FALSE);
    1383 }
    1384 
    1385 /* update_catalog_split only writes new lines to file. */
    1386 int dvo_catalog_update_split (Catalog *catalog, char VERBOSE) {
    1387 
    1388   Header header;
    1389   FTable ftable;
    1390   SecFilt *primary, *secfilt;
    1391   int Nsecfilt;
    1392   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    1393   off_t first, start, Nrows;
    1394 
    1395   ftable.header = &header;
    1396   ftable.buffer = NULL;
    1397   header.buffer = NULL;
    1398 
    1399   // skip empty catalogs: it is illegal to have Measures without corresponding Averages
    1400   Naves_disk_new = MAX (catalog[0].Naves_disk, catalog[0].Naverage + catalog[0].Naves_off);
    1401   if (Naves_disk_new == 0) {
    1402     if (VERBOSE) fprintf (stderr, "no stars in catalog, skipping\n");
    1403     return (TRUE);
    1404   }
    1405 
    1406   // for the appropriate types, pull out the first secfilt and pass to AverageToFtable as primary
    1407   switch (catalog[0].catformat) {
    1408     case DVO_FORMAT_ELIXIR: // special case for ELIXIR
    1409     case DVO_FORMAT_LONEOS: // special case for LONEOS
    1410       dvo_catalog_secfilt_to_primary (catalog, &primary, &secfilt, &Nsecfilt);
    1411       break;
    1412     default:
    1413       primary = NULL;
    1414       secfilt = catalog[0].secfilt;
    1415       Nsecfilt = catalog[0].Nsecfilt;
    1416       break;
    1417   }
    1418 
    1419   Nmeas_disk_new = MAX (catalog[0].Nmeas_disk, catalog[0].Nmeasure + catalog[0].Nmeas_off);
    1420   Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
    1421   Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
    1422   Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
    1423   Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
    1424   Nstarpar_disk_new = MAX (catalog[0].Nstarpar_disk, catalog[0].Nstarpar + catalog[0].Nstarpar_off);
    1425 
    1426   /* make sure header is consistent with data */
    1427   gfits_modify (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  Naves_disk_new);
    1428   gfits_modify (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  Nmeas_disk_new);
    1429   gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    1430   gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
    1431   gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    1432   gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    1433   gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
    1434   gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    1435   gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
    1436 
    1437   /* in split mode, we can save only part of the data */
    1438 
    1439   /*** Average Table ***/
    1440   if (catalog[0].average != NULL) {
    1441 
    1442     first  = catalog[0].Naves_disk - catalog[0].Naves_off; // first row to write (memory)
    1443     start  = catalog[0].Naves_disk;                        // first row to write (disk)
    1444     Nrows  = catalog[0].Naverage - first;
    1445 
    1446     assert (Nrows >= 0);
    1447     assert (first >= 0);
    1448     assert (first <= catalog[0].Naverage);
    1449     assert (catalog[0].Naves_disk >= catalog[0].Naves_off);
    1450 
    1451     /* convert internal to external format */
    1452     if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary)) {
    1453       fprintf (stderr, "trouble converting format\n");
    1454       goto failure;
    1455     }
    1456 
    1457     if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naves_disk, Naves_disk_new)) {
    1458       fprintf (stderr, "failure writing Average table\n");
    1459       goto failure;
    1460     }
    1461     gfits_free_header (&header);
    1462     gfits_free_table (&ftable);
    1463   } else {
    1464     // even if we do not save the average table, we need to keep the header in sync
    1465     /* rewind file pointers and truncate (file is still open) */
    1466     fseeko (catalog[0].f, 0, SEEK_SET);
    1467 
    1468     /* write table PHU header - always write this out */
    1469     /* XXX EAM : check if disk file size has changed */
    1470     if (!gfits_fwrite_header  (catalog[0].f, &catalog[0].header)) {
    1471       fprintf (stderr, "can't write primary header");
    1472       goto failure;
    1473     }
    1474   }
    1475 
    1476   /*** Measure Table ***/
    1477   if (catalog[0].measure != NULL) {
    1478 
    1479     first  = catalog[0].Nmeas_disk - catalog[0].Nmeas_off;  // first row in memory to write
    1480     start  = catalog[0].Nmeas_disk; // first disk row to write
    1481     Nrows  = catalog[0].Nmeasure - first;
    1482 
    1483     assert (Nrows >= 0);
    1484     assert (first >= 0);
    1485     assert (first <= catalog[0].Nmeasure);
    1486     assert (catalog[0].Nmeas_disk >= catalog[0].Nmeas_off);
    1487 
    1488     // convert to external table format
    1489     // XXX does catalog.measure have averef correctly set up?
    1490     if (!MeasureToFtable (&ftable, catalog[0].average, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
    1491       fprintf (stderr, "trouble converting format\n");
    1492       goto failure;
    1493     }
    1494 
    1495     // write out Measure table
    1496     if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeas_disk, Nmeas_disk_new)) {
    1497       fprintf (stderr, "trouble writing Measure table\n");
    1498       goto failure;
    1499     }
    1500     gfits_free_header (&header);
    1501     gfits_free_table (&ftable);
    1502   }
    1503 
    1504   /* missing table CANNOT be written unsorted, thus it is always written
    1505      out in full */
    1506 
    1507   /*** Missing Table ***/
    1508 
    1509   if (catalog[0].missing != NULL) {
    1510 
    1511     if (catalog[0].Nmiss_off != 0) {
    1512       fprintf (stderr, "inconsistency: Missing table cannot be written in segments\n");
    1513       goto failure;
    1514     }
    1515 
    1516     // convert to external table format
    1517     if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing)) {
    1518       fprintf (stderr, "trouble converting format\n");
    1519       goto failure;
    1520     }
    1521 
    1522     // write out Missing table (must write out entire table)
    1523     if (!dvo_catalog_save_subcat (catalog[0].missing_catalog, &ftable, 0, catalog[0].Nmissing, catalog[0].Nmissing, catalog[0].Nmissing)) {
    1524       fprintf (stderr, "trouble writing Missing Table\n");
    1525       goto failure;
    1526     }
    1527     gfits_free_header (&header);
    1528     gfits_free_table (&ftable);
    1529   }
    1530 
    1531   /*** Secfilt Table ***/
    1532   if (catalog[0].secfilt != NULL) {
    1533 
    1534     first  = catalog[0].Nsecf_disk - catalog[0].Nsecf_off;  // first row in memory to write
    1535     start  = catalog[0].Nsecf_disk; // first disk row to write
    1536     Nrows  = catalog[0].Nsecf_mem - first;
    1537 
    1538     assert (Nrows >= 0);
    1539     assert (first >= 0);
    1540     assert (catalog[0].Nsecf_disk >= catalog[0].Nsecf_off);
    1541 
    1542     // convert to external table format
    1543     SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat);
    1544 
    1545     // write out SecFilt table
    1546     if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
    1547       fprintf (stderr, "failure writing SecFilt table\n");
    1548       goto failure;
    1549     }
    1550     gfits_free_header (&header);
    1551     gfits_free_table (&ftable);
    1552   }
    1553 
    1554   /*** Lensing Table ***/
    1555   if (catalog[0].lensing != NULL) {
    1556 
    1557     first  = catalog[0].Nlensing_disk - catalog[0].Nlensing_off;  // first row in memory to write
    1558     start  = catalog[0].Nlensing_disk; // first disk row to write
    1559     Nrows  = catalog[0].Nlensing - first;
    1560 
    1561     assert (Nrows >= 0);
    1562     assert (first >= 0);
    1563     assert (first <= catalog[0].Nlensing);
    1564     assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
    1565 
    1566     // convert to external table format
    1567     // XXX does catalog.lensing have averef correctly set up?
    1568     if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
    1569       fprintf (stderr, "trouble converting format\n");
    1570       goto failure;
    1571     }
    1572 
    1573     // write out Lensing table
    1574     if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
    1575       fprintf (stderr, "trouble writing Lensing table\n");
    1576       goto failure;
    1577     }
    1578     gfits_free_header (&header);
    1579     gfits_free_table (&ftable);
    1580   }
    1581 
    1582   /*** Lensobj Table ***/
    1583   if (catalog[0].lensobj != NULL) {
    1584 
    1585     first  = catalog[0].Nlensobj_disk - catalog[0].Nlensobj_off;  // first row in memory to write
    1586     start  = catalog[0].Nlensobj_disk; // first disk row to write
    1587     Nrows  = catalog[0].Nlensobj - first;
    1588 
    1589     assert (Nrows >= 0);
    1590     assert (first >= 0);
    1591     assert (first <= catalog[0].Nlensobj);
    1592     assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
    1593 
    1594     // convert to external table format
    1595     // XXX does catalog.lensobj have averef correctly set up?
    1596     if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
    1597       fprintf (stderr, "trouble converting format\n");
    1598       goto failure;
    1599     }
    1600 
    1601     // write out Lensobj table
    1602     if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
    1603       fprintf (stderr, "trouble writing Lensobj table\n");
    1604       goto failure;
    1605     }
    1606     gfits_free_header (&header);
    1607     gfits_free_table (&ftable);
    1608   }
    1609 
    1610   /*** StarPar Table ***/
    1611   if (catalog[0].starpar != NULL) {
    1612 
    1613     first  = catalog[0].Nstarpar_disk - catalog[0].Nstarpar_off;  // first row in memory to write
    1614     start  = catalog[0].Nstarpar_disk; // first disk row to write
    1615     Nrows  = catalog[0].Nstarpar - first;
    1616 
    1617     assert (Nrows >= 0);
    1618     assert (first >= 0);
    1619     assert (first <= catalog[0].Nstarpar);
    1620     assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
    1621 
    1622     // convert to external table format
    1623     // XXX does catalog.starpar have averef correctly set up?
    1624     if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
    1625       fprintf (stderr, "trouble converting format\n");
    1626       goto failure;
    1627     }
    1628 
    1629     // write out StarPar table
    1630     if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
    1631       fprintf (stderr, "trouble writing StarPar table\n");
    1632       goto failure;
    1633     }
    1634     gfits_free_header (&header);
    1635     gfits_free_table (&ftable);
    1636   }
    1637 
    1638   /* free temp storage */
    1639   if (primary != NULL) {
    1640     free (primary);
    1641     free (secfilt);
    1642   }
    1643 
    1644   return (TRUE);
    1645 
    1646 failure:
     1732 failure:
    16471733  /* free temp storage */
    16481734  if (primary != NULL) {
     
    16621748
    16631749/* XXX EAM : update is not efficient.  MeasureToFtable should only
    1664    convert the new rows (Nmeas_disk to Nmeasure). the resulting
     1750   convert the new rows (Nmeasure_disk to Nmeasure). the resulting
    16651751   table represents the end rows of the ftable.  we need to define
    16661752   the vtable based on the ftable, but with Ny = Nmeasure */ 
     
    16681754
    16691755
    1670     // * convert to an ftable
    1671     // * optionally write the PHU header/matrix
    1672     // * advance to the start of the output data block:
    1673     // ** Nx * catalog[0].Nmeas_off
    1674     // * write out the ftable data block
    1675     // * if Nmeas_off + Nmeasure >= Nmeas_disk, update padding
    1676     // ** start = Nmeas_off
    1677     // ** Nrows = Nmeasure
    1678 
     1756// * convert to an ftable
     1757// * optionally write the PHU header/matrix
     1758// * advance to the start of the output data block:
     1759// ** Nx * catalog[0].Nmeasure_off
     1760// * write out the ftable data block
     1761// * if Nmeasure_off + Nmeasure >= Nmeasure_disk, update padding
     1762// ** start = Nmeasure_off
     1763// ** Nrows = Nmeasure
     1764
  • trunk/Ohana/src/libdvo/src/dvo_convert.c

    r38153 r38441  
    1111    constructions below **/
    1212
    13 DVOTableFormat FtableGetFormat (FTable *ftable) {
    14 
    15   DVOTableFormat format;
     13DVOCatFormat FtableGetFormat (FTable *ftable) {
     14
     15  DVOCatFormat format;
    1616  char extname[80];
    1717
     
    5252/*** Average / FTable conversion functions ***/
    5353
    54 Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary) {
     54Average *FtableToAverage (FTable *ftable, off_t *Naverage, DVOCatFormat *format, SecFilt **primary, char nativeBytes) {
    5555
    5656  Average *average;
     
    9898  if (!strcmp (extname, NAME)) { \
    9999    Average_##TYPE *tmpAverage; \
    100     tmpAverage = gfits_table_get_Average_##TYPE (ftable, Naverage, NULL); \
     100      tmpAverage = gfits_table_get_Average_##TYPE (ftable, Naverage, NULL, &nativeBytes); \
    101101    if (!tmpAverage) { \
    102102      fprintf (stderr, "ERROR: failed to read averages\n"); \
     
    109109
    110110  if (!strcmp (extname, "DVO_AVERAGE")) {
    111     average = gfits_table_get_Average (ftable, Naverage, NULL);
     111    average = gfits_table_get_Average (ftable, Naverage, NULL, &nativeBytes);
    112112    if (!average) {
    113113      fprintf (stderr, "ERROR: failed to read averages\n");
     
    139139}
    140140
    141 int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, char format, SecFilt *primary) {
    142 
    143 # define FORMAT_CASE(FORMAT, TYPE) \
    144     case DVO_FORMAT_##FORMAT: { \
    145       Average_##TYPE *tmpAverage; \
     141int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, DVOCatFormat format, SecFilt *primary, int swapFromNative) {
     142 
     143# define FORMAT_CASE(FORMAT, TYPE)              \
     144  case DVO_FORMAT_##FORMAT: {                                           \
     145    Average_##TYPE *tmpAverage;                                         \
    146146      tmpAverage = AverageInternalTo_##TYPE (average, Naverage, primary); \
    147       gfits_table_set_Average_##TYPE (ftable, tmpAverage, Naverage); \
    148       free (tmpAverage); \
    149       break; }
    150 
     147        gfits_table_set_Average_##TYPE (ftable, tmpAverage, Naverage, swapFromNative); \
     148          free (tmpAverage);                                            \
     149          break; }
     150 
    151151  /* convert from the internal format */
    152152  switch (format) {
    153153    case DVO_FORMAT_INTERNAL: {
    154       gfits_table_set_Average (ftable, average, Naverage);
     154      gfits_table_set_Average (ftable, average, Naverage, swapFromNative);
    155155      break; }
    156156
     
    180180
    181181// FtableToMeasure needs the Average since old formats stored measure.dR,dD only
    182 Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format) {
     182// other FtableToFOO conversions accept the average argument for macro construction
     183Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, DVOCatFormat *format, char nativeBytes) {
    183184
    184185  Measure *measure;
     
    226227  if (!strcmp (extname, NAME)) {                                        \
    227228    Measure_##TYPE *tmpMeasure;                                         \
    228     tmpMeasure = gfits_table_get_Measure_##TYPE (ftable, Nmeasure, NULL); \
    229     if (!tmpMeasure) {                                                  \
    230       fprintf (stderr, "ERROR: failed to read measures\n");             \
    231       exit (2);                                                         \
    232     }                                                                   \
    233     myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     229      tmpMeasure = gfits_table_get_Measure_##TYPE (ftable, Nmeasure, NULL, &nativeBytes); \
     230        if (!tmpMeasure) {                                              \
     231          fprintf (stderr, "ERROR: failed to read measures\n");         \
     232          exit (2);                                                     \
     233        }                                                               \
     234        myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
    234235    measure = Measure_##TYPE##_ToInternal (average, tmpMeasure, *Nmeasure); \
    235236    free (tmpMeasure);                                                  \
     
    238239
    239240  if (!strcmp (extname, "DVO_MEASURE")) {
    240     measure = gfits_table_get_Measure (ftable, Nmeasure, NULL);
     241    measure = gfits_table_get_Measure (ftable, Nmeasure, NULL, &nativeBytes);
    241242    if (!measure) {
    242243      fprintf (stderr, "ERROR: failed to read measures\n");
     
    269270
    270271// MeasureToFtable needs the Average since old formats stored measure.dR,dD only
    271 int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format) {
     272int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, DVOCatFormat format, int swapFromNative) {
    272273
    273274# define FORMAT_CASE(FORMAT, TYPE, ABS_COORDS)          \
     
    276277      myAssert (ABS_COORDS || average, "conversion from internal needs average table"); \
    277278      tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
    278       gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure); \
     279        gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure, swapFromNative); \
    279280      free (tmpMeasure); \
    280281      break; }
     
    283284  switch (format) {
    284285    case DVO_FORMAT_INTERNAL: {
    285       gfits_table_set_Measure (ftable, measure, Nmeasure);
     286      gfits_table_set_Measure (ftable, measure, Nmeasure, swapFromNative);
    286287      break; }
    287288
     
    308309}
    309310
     311/*** Missing / FTable conversion functions ***/
     312
     313Missing *FtableToMissing (FTable *ftable, Average *average, off_t *Nmissing, DVOCatFormat *format, char nativeBytes) {
     314
     315  Missing *missing;
     316  char extname[80];
     317
     318  /* convert to the internal format */
     319  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     320    fprintf (stderr, "EXTNAME missing for missing table\n");
     321    return (FALSE);
     322  }
     323
     324# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     325  if (!strcmp (extname, NAME)) {                                        \
     326    fprintf (stderr, "ERROR: format %s not defined for missing, skipping\n", NAME); \
     327    *Nmissing = 0; \
     328    return NULL; \
     329  }
     330
     331# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     332  if (!strcmp (extname, NAME)) {                                        \
     333    Missing_##TYPE *tmpMissing;                                         \
     334    tmpMissing = gfits_table_get_Missing_##TYPE (ftable, Nmissing, NULL, &nativeBytes); \
     335    if (!tmpMissing) {                                                  \
     336      fprintf (stderr, "ERROR: failed to read missing\n");              \
     337      exit (2);                                                         \
     338    }                                                                   \
     339    missing = Missing_##TYPE##_ToInternal (tmpMissing, *Nmissing); \
     340    free (tmpMissing);                                                  \
     341    *format = DVO_FORMAT_##FORMAT;                                      \
     342    return (missing); }
     343
     344  // XXX the structure is here for future expansion, but no transformations are currently defined
     345  if (TRUE) {
     346    missing = gfits_table_get_Missing (ftable, Nmissing, NULL, &nativeBytes);
     347    if (!missing) {
     348      fprintf (stderr, "ERROR: failed to read missing\n");
     349      exit (2);
     350    }
     351    *format = DVO_FORMAT_INTERNAL;
     352    return (missing);
     353  }
     354
     355  if (!strcmp (extname, "DVO_MISSING")) {
     356    missing = gfits_table_get_Missing (ftable, Nmissing, NULL, &nativeBytes);
     357    if (!missing) {
     358      fprintf (stderr, "ERROR: failed to read missing\n");
     359      exit (2);
     360    }
     361    *format = DVO_FORMAT_INTERNAL;
     362    return (missing);
     363  }
     364
     365  SKIPPING_FORMAT ("DVO_MISSING_PS1_SIM",         PS1_SIM,         PS1_SIM);
     366  SKIPPING_FORMAT ("DVO_MISSING_PS1_REF",         PS1_REF,         PS1_REF);
     367  SKIPPING_FORMAT ("DVO_MISSING_ELIXIR",          ELIXIR,          Elixir);
     368  SKIPPING_FORMAT ("DVO_MISSING_LONEOS",          LONEOS,          Loneos);
     369  SKIPPING_FORMAT ("DVO_MISSING_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     370  SKIPPING_FORMAT ("DVO_MISSING_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     371  SKIPPING_FORMAT ("DVO_MISSING_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     372  SKIPPING_FORMAT ("DVO_MISSING_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     373  SKIPPING_FORMAT ("DVO_MISSING_PS1_V1",          PS1_V1,          PS1_V1);
     374  SKIPPING_FORMAT ("DVO_MISSING_PS1_V2",          PS1_V2,          PS1_V2);
     375  SKIPPING_FORMAT ("DVO_MISSING_PS1_V3",          PS1_V3,          PS1_V3);
     376  SKIPPING_FORMAT ("DVO_MISSING_PS1_V4",          PS1_V4,          PS1_V4);
     377  SKIPPING_FORMAT ("DVO_MISSING_PS1_V5",          PS1_V5,          PS1_V5);
     378# undef CONVERT_FORMAT
     379# undef SKIPPING_FORMAT
     380
     381  fprintf (stderr, "table format unknown: %s\n", extname);
     382
     383  *Nmissing = 0;
     384  return (NULL);
     385}
     386
    310387/*** SecFilt / FTable conversion functions ***/
    311388
    312 SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format) {
     389SecFilt *FtableToSecFilt (FTable *ftable, Average *average, off_t *Nsecfilt, DVOCatFormat *format, char nativeBytes) {
    313390
    314391  SecFilt *secfilt;
     
    339416  if (!strcmp (extname, NAME)) { \
    340417    SecFilt_##TYPE *tmpSecFilt; \
    341     tmpSecFilt = gfits_table_get_SecFilt_##TYPE (ftable, Nsecfilt, NULL); \
     418    tmpSecFilt = gfits_table_get_SecFilt_##TYPE (ftable, Nsecfilt, NULL, &nativeBytes); \
    342419    if (!tmpSecFilt) { \
    343420      fprintf (stderr, "ERROR: failed to read secfilts\n"); \
     
    350427
    351428  if (!strcmp (extname, "DVO_SECFILT")) {
    352     secfilt = gfits_table_get_SecFilt (ftable, Nsecfilt, NULL);
     429    secfilt = gfits_table_get_SecFilt (ftable, Nsecfilt, NULL, &nativeBytes);
    353430    if (!secfilt) {
    354431      fprintf (stderr, "ERROR: failed to read secfilts\n");
     
    380457}
    381458
    382 int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format) {
     459int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, DVOCatFormat format, int swapFromNative) {
    383460
    384461# define FORMAT_CASE(FORMAT, TYPE) \
     
    386463      SecFilt_##TYPE *tmpSecFilt; \
    387464      tmpSecFilt = SecFiltInternalTo_##TYPE (secfilt, Nsecfilt); \
    388       gfits_table_set_SecFilt_##TYPE (ftable, tmpSecFilt, Nsecfilt); \
     465        gfits_table_set_SecFilt_##TYPE (ftable, tmpSecFilt, Nsecfilt, swapFromNative); \
    389466      free (tmpSecFilt); \
    390467      break; }
     
    393470  switch (format) {
    394471    case DVO_FORMAT_INTERNAL: {
    395       gfits_table_set_SecFilt (ftable, secfilt, Nsecfilt);
     472      gfits_table_set_SecFilt (ftable, secfilt, Nsecfilt, swapFromNative);
    396473      break; }
    397474
     
    420497/*** Lensing / FTable conversion functions ***/
    421498
    422 Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format) {
     499Lensing *FtableToLensing (FTable *ftable, Average *average, off_t *Nlensing, DVOCatFormat *format, char nativeBytes) {
    423500
    424501  Lensing *lensing;
     
    433510  if (!strcmp (extname, "DVO_LENSING_PS1_V5") && (ftable[0].header[0].Naxis[0] == 128)) {
    434511    Lensing_PS1_V5_R0 *tmpLensing;                                             
    435     tmpLensing = gfits_table_get_Lensing_PS1_V5_R0 (ftable, Nlensing, NULL);
     512    tmpLensing = gfits_table_get_Lensing_PS1_V5_R0 (ftable, Nlensing, NULL, &nativeBytes);
    436513    if (!tmpLensing) {                                                 
    437514      fprintf (stderr, "ERROR: failed to read lensings\n");             
     
    445522  if (!strcmp (extname, "DVO_LENSING_PS1_V5") && (ftable[0].header[0].Naxis[0] == 136)) {
    446523    Lensing_PS1_V5_R1 *tmpLensing;                                             
    447     tmpLensing = gfits_table_get_Lensing_PS1_V5_R1 (ftable, Nlensing, NULL);
     524    tmpLensing = gfits_table_get_Lensing_PS1_V5_R1 (ftable, Nlensing, NULL, &nativeBytes);
    448525    if (!tmpLensing) {                                                 
    449526      fprintf (stderr, "ERROR: failed to read lensings\n");             
     
    457534  if (!strcmp (extname, "DVO_LENSING_PS1_V5") && (ftable[0].header[0].Naxis[0] == 144)) {
    458535    Lensing_PS1_V5_R2 *tmpLensing;                                             
    459     tmpLensing = gfits_table_get_Lensing_PS1_V5_R2 (ftable, Nlensing, NULL);
     536    tmpLensing = gfits_table_get_Lensing_PS1_V5_R2 (ftable, Nlensing, NULL, &nativeBytes);
    460537    if (!tmpLensing) {                                                 
    461538      fprintf (stderr, "ERROR: failed to read lensings\n");             
     
    477554  if (!strcmp (extname, NAME)) {                                        \
    478555    Lensing_##TYPE *tmpLensing;                                         \
    479     tmpLensing = gfits_table_get_Lensing_##TYPE (ftable, Nlensing, NULL); \
     556    tmpLensing = gfits_table_get_Lensing_##TYPE (ftable, Nlensing, NULL, &nativeBytes); \
    480557    if (!tmpLensing) {                                                  \
    481558      fprintf (stderr, "ERROR: failed to read lensings\n");             \
     
    488565
    489566  if (!strcmp (extname, "DVO_LENSING")) {
    490     lensing = gfits_table_get_Lensing (ftable, Nlensing, NULL);
     567    lensing = gfits_table_get_Lensing (ftable, Nlensing, NULL, &nativeBytes);
    491568    if (!lensing) {
    492569      fprintf (stderr, "ERROR: failed to read lensings\n");
     
    520597
    521598// LensingToFtable needs the Average since old formats stored lensing.dR,dD only
    522 int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format) {
     599int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, DVOCatFormat format, int swapFromNative) {
    523600
    524601# define FORMAT_CASE(FORMAT, TYPE)              \
     
    526603      Lensing_##TYPE *tmpLensing; \
    527604      tmpLensing = LensingInternalTo_##TYPE (lensing, Nlensing); \
    528       gfits_table_set_Lensing_##TYPE (ftable, tmpLensing, Nlensing); \
     605        gfits_table_set_Lensing_##TYPE (ftable, tmpLensing, Nlensing, swapFromNative); \
    529606      free (tmpLensing); \
    530607      break; }
     
    533610  switch (format) {
    534611    case DVO_FORMAT_INTERNAL: {
    535       gfits_table_set_Lensing (ftable, lensing, Nlensing);
     612      gfits_table_set_Lensing (ftable, lensing, Nlensing, swapFromNative);
    536613      break; }
    537614
     
    559636/*** Lensobj / FTable conversion functions ***/
    560637
    561 Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format) {
     638Lensobj *FtableToLensobj (FTable *ftable, Average *average, off_t *Nlensobj, DVOCatFormat *format, char nativeBytes) {
    562639
    563640  Lensobj *lensobj;
     
    572649  if (!strcmp (extname, "DVO_LENSOBJ_PS1_V5") && (ftable[0].header[0].Naxis[0] == 136)) {
    573650    Lensobj_PS1_V5_R0 *tmpLensobj;                                             
    574     tmpLensobj = gfits_table_get_Lensobj_PS1_V5_R0 (ftable, Nlensobj, NULL);
     651    tmpLensobj = gfits_table_get_Lensobj_PS1_V5_R0 (ftable, Nlensobj, NULL, &nativeBytes);
    575652    if (!tmpLensobj) {                                                 
    576653      fprintf (stderr, "ERROR: failed to read lensobjs\n");             
     
    592669  if (!strcmp (extname, NAME)) {                                        \
    593670    Lensobj_##TYPE *tmpLensobj;                                         \
    594     tmpLensobj = gfits_table_get_Lensobj_##TYPE (ftable, Nlensobj, NULL); \
     671    tmpLensobj = gfits_table_get_Lensobj_##TYPE (ftable, Nlensobj, NULL, &nativeBytes); \
    595672    if (!tmpLensobj) {                                                  \
    596673      fprintf (stderr, "ERROR: failed to read lensobjs\n");             \
     
    603680
    604681  if (!strcmp (extname, "DVO_LENSOBJ")) {
    605     lensobj = gfits_table_get_Lensobj (ftable, Nlensobj, NULL);
     682    lensobj = gfits_table_get_Lensobj (ftable, Nlensobj, NULL, &nativeBytes);
    606683    if (!lensobj) {
    607684      fprintf (stderr, "ERROR: failed to read lensobjs\n");
     
    635712
    636713// LensobjToFtable needs the Average since old formats stored lensobj.dR,dD only
    637 int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format) {
     714int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, DVOCatFormat format, int swapFromNative) {
    638715
    639716# define FORMAT_CASE(FORMAT, TYPE)              \
     
    641718      Lensobj_##TYPE *tmpLensobj; \
    642719      tmpLensobj = LensobjInternalTo_##TYPE (lensobj, Nlensobj); \
    643       gfits_table_set_Lensobj_##TYPE (ftable, tmpLensobj, Nlensobj); \
     720        gfits_table_set_Lensobj_##TYPE (ftable, tmpLensobj, Nlensobj, swapFromNative); \
    644721      free (tmpLensobj); \
    645722      break; }
     
    648725  switch (format) {
    649726    case DVO_FORMAT_INTERNAL: {
    650       gfits_table_set_Lensobj (ftable, lensobj, Nlensobj);
     727      gfits_table_set_Lensobj (ftable, lensobj, Nlensobj, swapFromNative);
    651728      break; }
    652729
     
    674751/*** StarPar / FTable conversion functions ***/
    675752
    676 StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format) {
     753StarPar *FtableToStarPar (FTable *ftable, Average *average, off_t *Nstarpar, DVOCatFormat *format, char nativeBytes) {
    677754
    678755  StarPar *starpar;
     
    695772  if (!strcmp (extname, NAME)) {                                        \
    696773    StarPar_##TYPE *tmpStarPar;                                         \
    697     tmpStarPar = gfits_table_get_StarPar_##TYPE (ftable, Nstarpar, NULL); \
     774    tmpStarPar = gfits_table_get_StarPar_##TYPE (ftable, Nstarpar, NULL, &nativeBytes); \
    698775    if (!tmpStarPar) {                                                  \
    699776      fprintf (stderr, "ERROR: failed to read starpar\n");              \
     
    706783
    707784  if (!strcmp (extname, "DVO_STARPAR")) {
    708     starpar = gfits_table_get_StarPar (ftable, Nstarpar, NULL);
     785    starpar = gfits_table_get_StarPar (ftable, Nstarpar, NULL, &nativeBytes);
    709786    if (!starpar) {
    710787      fprintf (stderr, "ERROR: failed to read starpar\n");
     
    738815
    739816// StarParToFtable needs the Average since old formats stored starpar.dR,dD only
    740 int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format) {
     817int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, DVOCatFormat format, int swapFromNative) {
    741818
    742819# define FORMAT_CASE(FORMAT, TYPE)              \
     
    744821      StarPar_##TYPE *tmpStarPar; \
    745822      tmpStarPar = StarParInternalTo_##TYPE (starpar, Nstarpar); \
    746       gfits_table_set_StarPar_##TYPE (ftable, tmpStarPar, Nstarpar); \
     823        gfits_table_set_StarPar_##TYPE (ftable, tmpStarPar, Nstarpar, swapFromNative); \
    747824      free (tmpStarPar); \
    748825      break; }
     
    751828  switch (format) {
    752829    case DVO_FORMAT_INTERNAL: {
    753       gfits_table_set_StarPar (ftable, starpar, Nstarpar);
     830      gfits_table_set_StarPar (ftable, starpar, Nstarpar, swapFromNative);
    754831      break; }
    755832
     
    776853}
    777854
     855/*** GalPhot / FTable conversion functions ***/
     856
     857GalPhot *FtableToGalPhot (FTable *ftable, Average *average, off_t *Ngalphot, DVOCatFormat *format, char nativeBytes) {
     858
     859  GalPhot *galphot;
     860  char extname[80];
     861
     862  /* convert to the internal format */
     863  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     864    fprintf (stderr, "EXTNAME missing for galphot table\n");
     865    return (FALSE);
     866  }
     867
     868# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     869  if (!strcmp (extname, NAME)) {                                        \
     870    fprintf (stderr, "ERROR: format %s not defined for galphot, skipping\n", NAME); \
     871    *Ngalphot = 0; \
     872    return NULL; \
     873  }
     874
     875# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     876  if (!strcmp (extname, NAME)) {                                        \
     877    GalPhot_##TYPE *tmpGalPhot;                                         \
     878    tmpGalPhot = gfits_table_get_GalPhot_##TYPE (ftable, Ngalphot, NULL, &nativeBytes); \
     879    if (!tmpGalPhot) {                                                  \
     880      fprintf (stderr, "ERROR: failed to read galphots\n");             \
     881      exit (2);                                                         \
     882    }                                                                   \
     883    galphot = GalPhot_##TYPE##_ToInternal (tmpGalPhot, *Ngalphot); \
     884    free (tmpGalPhot);                                                  \
     885    *format = DVO_FORMAT_##FORMAT;                                      \
     886    return (galphot); }
     887
     888  if (!strcmp (extname, "DVO_GALPHOT")) {
     889    galphot = gfits_table_get_GalPhot (ftable, Ngalphot, NULL, &nativeBytes);
     890    if (!galphot) {
     891      fprintf (stderr, "ERROR: failed to read galphots\n");
     892      exit (2);
     893    }
     894    *format = DVO_FORMAT_INTERNAL;
     895    return (galphot);
     896  }
     897
     898  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_REF",         PS1_REF,         PS1_REF);
     899  SKIPPING_FORMAT ("DVO_GALPHOT_ELIXIR",          ELIXIR,          Elixir);
     900  SKIPPING_FORMAT ("DVO_GALPHOT_LONEOS",          LONEOS,          Loneos);
     901  SKIPPING_FORMAT ("DVO_GALPHOT_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     902  SKIPPING_FORMAT ("DVO_GALPHOT_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     903  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     904  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     905  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_V1",          PS1_V1,          PS1_V1);
     906  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_V2",          PS1_V2,          PS1_V2);
     907  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_V3",          PS1_V3,          PS1_V3);
     908  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_V4",          PS1_V4,          PS1_V4);
     909  CONVERT_FORMAT  ("DVO_GALPHOT_PS1_V5",          PS1_V5,          PS1_V5);
     910  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_SIM",         PS1_SIM,         PS1_SIM);
     911# undef CONVERT_FORMAT
     912# undef SKIPPING_FORMAT
     913
     914  fprintf (stderr, "table format unknown: %s\n", extname);
     915
     916  *Ngalphot = 0;
     917  return (NULL);
     918}
     919
     920// GalPhotToFtable needs the Average since old formats stored galphot.dR,dD only
     921int GalPhotToFtable (FTable *ftable, GalPhot *galphot, off_t Ngalphot, DVOCatFormat format, int swapFromNative) {
     922
     923# define FORMAT_CASE(FORMAT, TYPE)              \
     924    case DVO_FORMAT_##FORMAT: { \
     925      GalPhot_##TYPE *tmpGalPhot; \
     926      tmpGalPhot = GalPhotInternalTo_##TYPE (galphot, Ngalphot); \
     927        gfits_table_set_GalPhot_##TYPE (ftable, tmpGalPhot, Ngalphot, swapFromNative); \
     928      free (tmpGalPhot); \
     929      break; }
     930
     931  /* convert from the internal format */
     932  switch (format) {
     933    case DVO_FORMAT_INTERNAL: {
     934      gfits_table_set_GalPhot (ftable, galphot, Ngalphot, swapFromNative);
     935      break; }
     936
     937//    FORMAT_CASE (PS1_REF,         PS1_REF);
     938//    FORMAT_CASE (ELIXIR,          Elixir);
     939//    FORMAT_CASE (LONEOS,          Loneos);
     940//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     941//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     942//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     943//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     944//    FORMAT_CASE (PS1_V1,          PS1_V1);
     945//    FORMAT_CASE (PS1_V2,          PS1_V2);
     946//    FORMAT_CASE (PS1_V3,          PS1_V3);
     947//    FORMAT_CASE (PS1_V4,          PS1_V4);
     948      FORMAT_CASE (PS1_V5,          PS1_V5);
     949# undef FORMAT_CASE
     950
     951    default:
     952      fprintf (stderr, "table format unknown (galphot)\n");
     953      return (FALSE);
     954  }
     955  return (TRUE);
     956}
     957
    778958/*** Image Conversions ***/
    779959
    780960// I have loaded the disk db table and now I want to convert to the internal format
    781961// (Image structure), but I onyl
    782 int FtableToImage (FTable *ftable, Header *theader, char *format) {
     962int FtableToImage (FTable *ftable, Header *theader, DVOCatFormat *format) {
    783963
    784964  off_t Nimage;
     
    788968  if (*format == DVO_FORMAT_ELIXIR) {             // special case for ELIXIR
    789969    Image_Elixir *tmpimage;
    790     tmpimage = gfits_table_get_Image_Elixir (ftable, &Nimage, NULL);
     970    tmpimage = gfits_table_get_Image_Elixir (ftable, &Nimage, NULL, NULL);
    791971    if (!tmpimage) {
    792972      fprintf (stderr, "ERROR: failed to read images\n");
     
    814994    Image_##TYPE *tmpimage; \
    815995    *format = DVO_FORMAT_##FORMAT; \
    816     tmpimage = gfits_table_get_Image_##TYPE (ftable, &Nimage, NULL); \
     996    tmpimage = gfits_table_get_Image_##TYPE (ftable, &Nimage, NULL, NULL); \
    817997    if (!tmpimage) { \
    818998      fprintf (stderr, "ERROR: failed to read images\n"); \
     
    8491029}
    8501030
    851 int ImageToFtable (FTable *ftable, Header *theader, char format) {
     1031int ImageToFtable (FTable *ftable, Header *theader, DVOCatFormat format) {
    8521032
    8531033  off_t Nimage;
     
    8601040      tmpImage = ImageInternalTo_##TYPE ((Image *) ftable[0].buffer, Nimage); \
    8611041      free (ftable[0].buffer); \
    862       gfits_table_set_Image_##TYPE (ftable, tmpImage, Nimage); \
     1042      gfits_table_set_Image_##TYPE (ftable, tmpImage, Nimage, TRUE); \
    8631043      free (tmpImage); \
    8641044      break; }
     
    8891069}
    8901070
    891 int ImageToVtable (VTable *vtable, Header *theader, char format) {
     1071int ImageToVtable (VTable *vtable, Header *theader, DVOCatFormat format) {
    8921072
    8931073  off_t i, Nrow, Nimage;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r37807 r38441  
    118118    out[i].Nmeasure      = in[i].Nmeasure;     
    119119    out[i].Nmissing      = in[i].Nmissing;     
    120     out[i].Nextend       = in[i].Nextend;     
     120    out[i].Ngalphot     = in[i].Nextend;     
    121121    out[i].measureOffset = in[i].measureOffset;
    122122    out[i].missingOffset = in[i].missingOffset;
     
    152152    out[i].Nmeasure      = in[i].Nmeasure;     
    153153    out[i].Nmissing      = in[i].Nmissing;     
    154     out[i].Nextend       = in[i].Nextend;     
     154    out[i].Nextend       = in[i].Ngalphot;     
    155155    out[i].measureOffset = in[i].measureOffset;
    156156    out[i].missingOffset = in[i].missingOffset;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r37807 r38441  
    138138    out[i].Nmeasure      = in[i].Nmeasure;     
    139139    out[i].Nmissing      = in[i].Nmissing;     
    140     out[i].Nextend       = in[i].Nextend;     
     140    out[i].Ngalphot     = in[i].Ngalphot;     
    141141    out[i].measureOffset = in[i].measureOffset;
    142142    out[i].missingOffset = in[i].missingOffset;
     
    173173    out[i].Nmeasure      = in[i].Nmeasure;     
    174174    out[i].Nmissing      = in[i].Nmissing;     
    175     out[i].Nextend       = in[i].Nextend;     
     175    out[i].Ngalphot     = in[i].Ngalphot;     
    176176    out[i].measureOffset = in[i].measureOffset;
    177177    out[i].missingOffset = in[i].missingOffset;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r37807 r38441  
    143143    out[i].Nmeasure      = in[i].Nmeasure;     
    144144    out[i].Nmissing      = in[i].Nmissing;     
    145     out[i].Nextend       = in[i].Nextend;     
     145    out[i].Ngalphot     = in[i].Ngalphot;     
    146146    out[i].measureOffset = in[i].measureOffset;
    147147    out[i].missingOffset = in[i].missingOffset;
     
    182182    out[i].Nmeasure      = in[i].Nmeasure;     
    183183    out[i].Nmissing      = in[i].Nmissing;     
    184     out[i].Nextend       = in[i].Nextend;     
     184    out[i].Ngalphot     = in[i].Ngalphot;     
    185185    out[i].measureOffset = in[i].measureOffset;
    186186    out[i].missingOffset = in[i].missingOffset;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r37807 r38441  
    143143    out[i].Nmeasure      = in[i].Nmeasure;     
    144144    out[i].Nmissing      = in[i].Nmissing;     
    145     out[i].Nextend       = in[i].Nextend;     
     145    out[i].Ngalphot     = in[i].Ngalphot;     
    146146    out[i].measureOffset = in[i].measureOffset;
    147147    out[i].missingOffset = in[i].missingOffset;
     
    184184    out[i].Nmeasure      = in[i].Nmeasure;     
    185185    out[i].Nmissing      = in[i].Nmissing;     
    186     out[i].Nextend       = in[i].Nextend;     
     186    out[i].Ngalphot     = in[i].Ngalphot;     
    187187    out[i].measureOffset = in[i].measureOffset;
    188188    out[i].missingOffset = in[i].missingOffset;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r37807 r38441  
    164164    out[i].Nmeasure      = in[i].Nmeasure;     
    165165    out[i].Nmissing      = in[i].Nmissing;     
    166     out[i].Nextend       = in[i].Nextend;     
     166    out[i].Ngalphot     = in[i].Ngalphot;     
    167167    out[i].measureOffset = in[i].measureOffset;
    168168    out[i].missingOffset = in[i].missingOffset;
     
    208208    out[i].Nmeasure      = in[i].Nmeasure;     
    209209    out[i].Nmissing      = in[i].Nmissing;     
    210     out[i].Nextend       = in[i].Nextend;     
     210    out[i].Ngalphot     = in[i].Ngalphot;     
    211211    out[i].measureOffset = in[i].measureOffset;
    212212    out[i].missingOffset = in[i].missingOffset;
     
    690690    out[i].Nmeasure      = in[i].Nmeasure;     
    691691    out[i].Nmissing      = in[i].Nmissing;     
    692     out[i].Nextend       = in[i].Nextend;     
     692    out[i].Ngalphot     = in[i].Ngalphot;     
    693693    out[i].measureOffset = in[i].measureOffset;
    694694    out[i].missingOffset = in[i].missingOffset;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r38153 r38441  
    196196    out[i].Nlensobj      = in[i].Nlensobj;     
    197197    out[i].Nstarpar      = in[i].Nstarpar;     
    198     out[i].Nextend       = in[i].Nextend;     
     198    out[i].Ngalphot     = in[i].Ngalphot;     
    199199
    200200    out[i].measureOffset = in[i].measureOffset;
     
    203203    out[i].lensobjOffset = in[i].lensobjOffset;
    204204    out[i].starparOffset = in[i].starparOffset;
    205     out[i].extendOffset  = in[i].extendOffset;
     205    out[i].galphotOffset  = in[i].galphotOffset;
    206206
    207207    out[i].refColorBlue  = in[i].refColorBlue;
     
    264264    out[i].Nlensobj       = in[i].Nlensobj;     
    265265    out[i].Nstarpar       = in[i].Nstarpar;     
    266     out[i].Nextend        = in[i].Nextend;     
     266    out[i].Ngalphot        = in[i].Ngalphot;     
    267267                         
    268268    out[i].measureOffset  = in[i].measureOffset;
     
    271271    out[i].lensobjOffset  = in[i].lensobjOffset;
    272272    out[i].starparOffset  = in[i].starparOffset;
    273     out[i].extendOffset   = in[i].extendOffset;
     273    out[i].galphotOffset   = in[i].galphotOffset;
    274274                         
    275275    out[i].refColorBlue   = in[i].refColorBlue;
     
    975975    out[i].objID   = in[i].objID ;
    976976    out[i].catID   = in[i].catID ;
     977  }
     978  return (out);
     979}
     980
     981GalPhot *GalPhot_PS1_V5_ToInternal (GalPhot_PS1_V5 *in, off_t Nvalues) {
     982
     983  off_t i;
     984  GalPhot *out;
     985
     986  ALLOCATE_ZERO (out, GalPhot, Nvalues);
     987
     988  for (i = 0; i < Nvalues; i++) {
     989    dvo_galphot_init (&out[i]);
     990
     991    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;
     1010  }
     1011  return (out);
     1012}
     1013
     1014GalPhot_PS1_V5 *GalPhotInternalTo_PS1_V5 (GalPhot *in, off_t Nvalues) {
     1015
     1016  off_t i;
     1017  GalPhot_PS1_V5 *out;
     1018
     1019  ALLOCATE_ZERO (out, GalPhot_PS1_V5, Nvalues);
     1020
     1021  for (i = 0; i < Nvalues; i++) {
     1022    out[i].Xfit          = in[i].Xfit;
     1023    out[i].Yfit          = in[i].Yfit;
     1024    out[i].mag           = in[i].mag;
     1025    out[i].magErr        = in[i].magErr;
     1026    out[i].majorAxis     = in[i].majorAxis;
     1027    out[i].minorAxis     = in[i].minorAxis;
     1028    out[i].majorAxisErr  = in[i].majorAxisErr;
     1029    out[i].minorAxisErr  = in[i].minorAxisErr;
     1030    out[i].theta         = in[i].theta;
     1031    out[i].theta_err     = in[i].theta_err;
     1032    out[i].index         = in[i].index;
     1033    out[i].chisq         = in[i].chisq;
     1034    out[i].Npix          = in[i].Npix;
     1035    out[i].objID         = in[i].objID;
     1036    out[i].catID         = in[i].catID;
     1037    out[i].detID         = in[i].detID;
     1038    out[i].imageID       = in[i].imageID;
     1039    out[i].photcode      = in[i].photcode;
     1040    out[i].modelType     = in[i].modelType;
    9771041  }
    9781042  return (out);
     
    12341298    out[i].Nlensing       = in[i].Nlensing;     
    12351299    out[i].Nlensobj       = in[i].Nlensobj;     
    1236     out[i].Nextend        = in[i].Nextend;     
     1300    out[i].Ngalphot        = in[i].Ngalphot;     
    12371301                         
    12381302    out[i].measureOffset  = in[i].measureOffset;
     
    12411305    out[i].lensobjOffset  = in[i].lensobjOffset;
    12421306    out[i].starparOffset  = in[i].starparOffset;
    1243     out[i].extendOffset   = in[i].extendOffset;
     1307    out[i].galphotOffset   = in[i].galphotOffset;
    12441308                         
    12451309    out[i].refColorBlue   = in[i].refColorBlue;
     
    13021366    SWAP_BYTE (110); // NLENSING
    13031367    SWAP_BYTE (112); // NLENSOBJ
    1304     SWAP_BYTE (114); // NEXTEND
     1368    SWAP_BYTE (114); // NGALPHOT
    13051369    SWAP_WORD (116); // OFF_MEASURE
    13061370    SWAP_WORD (120); // OFF_MISSING
    13071371    SWAP_WORD (124); // OFF_LENSING
    13081372    SWAP_WORD (128); // OFF_LENSOBJ
    1309     SWAP_WORD (132); // OFF_EXTEND
     1373    SWAP_WORD (132); // OFF_GALPHOT
    13101374    SWAP_WORD (136); // OFF_PARAMS
    13111375    SWAP_WORD (140); // REF_COLOR_BLUE
  • trunk/Ohana/src/libdvo/src/dvo_image.c

    r37807 r38441  
    1919  db[0].lockstate = lockstate;
    2020  db[0].timeout   = timeout;
    21   gfits_db_init (db);
    2221
    2322  if (!gfits_db_lock (db, filename)) {
     
    8988  // so when we later do a gfits_copy_ftable, we stomp on bad memory
    9089  FtableToImage (&db[0].ftable, &db[0].theader, &db[0].format);
    91   db[0].swapped = TRUE;  /* table has internal byte-order */
     90  db[0].nativeOrder = TRUE;  /* table has internal byte-order */
     91  db[0].scaledValue = TRUE;  /* table has internal byte-order */
    9292  return (TRUE);
    9393}
     
    100100  /* convert from internal to requested external format */
    101101  ImageToFtable (&db[0].ftable, &db[0].theader, db[0].format);
    102   db[0].swapped = FALSE;
     102  db[0].nativeOrder = FALSE;
     103  db[0].scaledValue = FALSE;
    103104
    104105  /* write data in appropriate mode */
     
    149150  /* theader is modified to match output format */
    150151  ImageToVtable (&db[0].vtable, &db[0].theader, db[0].format);
    151   db[0].swapped = FALSE;
     152  db[0].scaledValue = FALSE;
     153  db[0].nativeOrder = FALSE;
    152154
    153155  /* write data in appropriate mode */
     
    363365
    364366/* return internal structure representation */
    365 Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped) {
     367Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *scaledValue, char *nativeOrder) {
    366368
    367369  int Ncols;
     
    377379  data = (Image *) ftable[0].buffer;
    378380
    379   if (!swapped) {
    380     myAbort ("invalid to call this without suppying 'swapped'");
    381   }
    382   if (*swapped == FALSE) {
    383     myAbort ("invalid for table to be swapped");
     381  if (!scaledValue) {
     382    myAbort ("invalid to call this without suppying 'scaledValue'");
     383  }
     384  if (*scaledValue == FALSE) {
     385    myAbort ("invalid for table NOT to be scaledValue");
     386  }
     387  if (!nativeOrder) {
     388    myAbort ("invalid to call this without suppying 'nativeOrder'");
     389  }
     390  if (*nativeOrder == FALSE) {
     391    myAbort ("invalid for table NOT to be nativeOrder");
    384392  }
    385393   
  • trunk/Ohana/src/libdvo/src/dvo_image_raw.c

    r37807 r38441  
    107107  db[0].theader.Naxis[1] = Nimage;
    108108  db[0].ftable.datasize = gfits_data_size (&db[0].theader);
    109   db[0].swapped = FALSE;  /* table does not have internal byte-order */
     109
     110  db[0].nativeOrder = FALSE;  /* table does not have internal byte-order */
     111  db[0].scaledValue = FALSE;  /* table does not have internal byte-order */
    110112  return (TRUE);
    111113}
  • trunk/Ohana/src/libdvo/src/dvo_util.c

    r37807 r38441  
    127127    }
    128128
    129     dvoConfig->images = gfits_table_get_Image (&dvoConfig->imageDB.ftable, &dvoConfig->nImages, &dvoConfig->imageDB.swapped);
     129    dvoConfig->images = gfits_table_get_Image (&dvoConfig->imageDB.ftable, &dvoConfig->nImages, &dvoConfig->imageDB.scaledValue, &dvoConfig->imageDB.nativeOrder);
    130130    if (!dvoConfig->images) {
    131131        fprintf (stderr, "problem loading images\n");
     
    207207      Catalog catalog;
    208208      catalog.filename = skylist->filename[reg];
    209       catalog.catflags = GetMeasures ? LOAD_AVES | LOAD_MEAS | LOAD_SECF : LOAD_AVES | LOAD_SECF;
     209      catalog.catflags = GetMeasures ? DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT : DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    210210      catalog.Nsecfilt = 0;
    211211
  • trunk/Ohana/src/libdvo/src/fits_db.c

    r35755 r38441  
    66  db[0].f             = NULL;
    77  db[0].filename      = NULL;
     8  db[0].dbstate       = 0;
     9  db[0].lockstate     = 0;
     10  db[0].mode          = 0;
     11  db[0].format        = 0;
     12  db[0].virtual       = 0;
     13  db[0].nativeOrder   = 0;
     14  db[0].scaledValue   = 0;
    815 
    9 # if (1)
    1016  gfits_init_header (&db->header);
    1117  gfits_init_matrix (&db->matrix);
    1218  gfits_init_header (&db->theader);
    13   gfits_init_table (&db->ftable);
     19  gfits_init_table  (&db->ftable);
    1420  db->ftable.header = &db->theader;
    1521  gfits_init_vtable (&db->vtable);
    16 # else 
    17   db[0].header.buffer = NULL;
    18   db[0].matrix.buffer = NULL;
    19   db[0].theader.buffer = NULL;
    20   db[0].ftable.buffer = NULL;
    21   db[0].ftable.header = &db[0].theader;
    22   db[0].vtable.header = NULL;
    23   db[0].vtable.buffer = NULL;
    24   db[0].vtable.row    = NULL;
    25 # endif
    2622  return (TRUE);
    2723}
     
    9793    return (FALSE);
    9894  }
    99   db[0].swapped = FALSE;  /* table does not have internal byte-order */
     95  db[0].nativeOrder = FALSE;  /* table does not have internal byte-order */
     96  db[0].scaledValue = FALSE;  /* table has not been scaled by BZERO,BSCALE */
    10097  return (TRUE);
    10198}
  • trunk/Ohana/src/libdvo/src/flatcorr_io.c

    r37807 r38441  
    4949    return (NULL);
    5050  }
    51   flatcorrTable->image = gfits_table_get_FlatCorrectionImage (&ftable, &flatcorrTable->Nimage, NULL);
     51  flatcorrTable->image = gfits_table_get_FlatCorrectionImage (&ftable, &flatcorrTable->Nimage, NULL, NULL);
    5252  if (!flatcorrTable->image) {
    5353    fprintf (stderr, "ERROR: failed to read Flat Correction Images\n");
     
    6464    return (NULL);
    6565  }
    66   flatcorrTable->corr = gfits_table_get_FlatCorrection (&ftable, &flatcorrTable->Ncorr, NULL);
     66  flatcorrTable->corr = gfits_table_get_FlatCorrection (&ftable, &flatcorrTable->Ncorr, NULL, NULL);
    6767  if (!flatcorrTable->corr) {
    6868    fprintf (stderr, "ERROR: failed to read Flat Corrections\n");
     
    9393    for (j = 0; j < flatcorrTable->image[i].Nx; j++) {
    9494      ALLOCATE (flatcorrTable->offset[i][j], float, flatcorrTable->image[i].Ny);
    95       memset (flatcorrTable->offset[i][j], 0.0, flatcorrTable->image[i].Ny*sizeof(float));
     95      memset (flatcorrTable->offset[i][j], 0, flatcorrTable->image[i].Ny*sizeof(float));
    9696    }
    9797  }
     
    161161
    162162  ftableImage.header = &theaderImage;
    163   gfits_table_set_FlatCorrectionImage (&ftableImage, image, flatcorrTable->Nimage);
     163  gfits_table_set_FlatCorrectionImage (&ftableImage, image, flatcorrTable->Nimage, TRUE);
    164164
    165165  ftableCorr.header = &theaderCorr;
    166   gfits_table_set_FlatCorrection (&ftableCorr, corr, flatcorrTable->Ncorr);
     166  gfits_table_set_FlatCorrection (&ftableCorr, corr, flatcorrTable->Ncorr, TRUE);
    167167
    168168  f = fopen (filename, "w");
  • trunk/Ohana/src/libdvo/src/skyregion_io.c

    r36833 r38441  
    4040  ALLOCATE (skytable, SkyTable, 1);
    4141  memset (skytable->hosts, 0, 80);
    42   skytable[0].regions = gfits_table_get_SkyRegion (&ftable, &skytable[0].Nregions, NULL);
     42  skytable[0].regions = gfits_table_get_SkyRegion (&ftable, &skytable[0].Nregions, NULL, NULL);
    4343  if (!skytable[0].regions) {
    4444    fprintf (stderr, "ERROR: failed to read sky regions\n");
     
    9999  gfits_print (&header, "HOSTS", "%s", 1, skytable->hosts);
    100100
    101   gfits_table_set_SkyRegion (&ftable, skytable[0].regions, skytable[0].Nregions);
     101  gfits_table_set_SkyRegion (&ftable, skytable[0].regions, skytable[0].Nregions, TRUE);
    102102
    103103  f = fopen (filename, "w");
  • trunk/Ohana/src/libfits/Makefile

    r38255 r38441  
    11default: install
    22help:
    3         @echo "make options: install libfits man clean dist"
     3        @echo "make options: install libfits man clean dist test test.verbose test.clean"
    44
    55include ../../Makefile.System
     
    1313INC     =       $(HOME)/include
    1414MAN     =       $(HOME)/doc
     15TESTDIR =       $(HOME)/test
     16TESTBIN =       $(HOME)/test
    1517include ../../Makefile.Common
    1618
     
    1921FULL_CPPFLAGS = $(BASE_CPPFLAGS) -I$(EXT)
    2022FULL_LDFLAGS  = $(BASE_LDFLAGS) -lohana
     23
     24TEST_CFLAGS   = $(BASE_CFLAGS)
     25TEST_CPPFLAGS = $(BASE_CPPFLAGS)
     26TEST_LDFLAGS  = $(BASE_LDFLAGS) -lFITS -lohana -ltap_ohana
     27
     28
     29TESTXTRA = tcomptiming
     30TESTPROG = zlib ricetest imagecomp tablecomp
     31$(TESTPROG) : % : $(TESTBIN)/%
     32$(TESTXTRA) : % : $(TESTBIN)/%
     33test: $(TESTPROG)
     34        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS); done
     35test.verbose: $(TESTPROG)
     36        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS) -v; done
    2137
    2238install: $(DESTLIB)/libFITS.a $(DESTLIB)/libFITS.$(DLLTYPE) $(DESTMAN)/fits.1
     
    3753
    3854MATRIX_OBJ = \
    39 $(MATR)/F_add_M_value.$(ARCH).o                 $(MATR)/F_add_M.$(ARCH).o        \
    40 $(MATR)/F_create_M.$(ARCH).o                    $(MATR)/F_divide_M.$(ARCH).o     \
    41 $(MATR)/F_free_M.$(ARCH).o                      $(MATR)/F_copy_M.$(ARCH).o       \
    42 $(MATR)/F_write_M.$(ARCH).o                     $(MATR)/F_get_M_value.$(ARCH).o  \
    43 $(MATR)/F_multiply_M.$(ARCH).o                  $(MATR)/F_read_M.$(ARCH).o       \
    44 $(MATR)/F_insert_M.$(ARCH).o                    $(MATR)/F_set_M_value.$(ARCH).o  \
    45 $(MATR)/F_convert_format.$(ARCH).o              $(MATR)/F_read_segment.$(ARCH).o \
    46 $(MATR)/F_read_portion.$(ARCH).o                $(MATR)/F_load_M.$(ARCH).o       \
    47 $(MATR)/F_matrix.$(ARCH).o                      $(MATR)/F_compress_M.$(ARCH).o   \
    48 $(MATR)/F_uncompress_data.$(ARCH).o             $(MATR)/F_swap_raw.$(ARCH).o
     55$(MATR)/F_add_M_value.$(ARCH).o                 $(MATR)/F_add_M.$(ARCH).o          \
     56$(MATR)/F_create_M.$(ARCH).o                    $(MATR)/F_divide_M.$(ARCH).o       \
     57$(MATR)/F_free_M.$(ARCH).o                      $(MATR)/F_copy_M.$(ARCH).o         \
     58$(MATR)/F_write_M.$(ARCH).o                     $(MATR)/F_get_M_value.$(ARCH).o    \
     59$(MATR)/F_multiply_M.$(ARCH).o                  $(MATR)/F_read_M.$(ARCH).o         \
     60$(MATR)/F_insert_M.$(ARCH).o                    $(MATR)/F_set_M_value.$(ARCH).o    \
     61$(MATR)/F_convert_format.$(ARCH).o              $(MATR)/F_read_segment.$(ARCH).o   \
     62$(MATR)/F_read_portion.$(ARCH).o                $(MATR)/F_load_M.$(ARCH).o         \
     63$(MATR)/F_matrix.$(ARCH).o                      $(MATR)/F_compress_utils.$(ARCH).o \
     64$(MATR)/F_compress_M.$(ARCH).o                  $(MATR)/F_compress_data.$(ARCH).o  \
     65$(MATR)/F_uncompress_M.$(ARCH).o                $(MATR)/F_uncompress_data.$(ARCH).o \
     66$(MATR)/F_swap_raw.$(ARCH).o
    4967
    5068TABLE_OBJ = \
     
    5573$(TABL)/F_set_column.$(ARCH).o                  $(TABL)/F_get_column.$(ARCH).o   \
    5674$(TABL)/F_table_row.$(ARCH).o                   $(TABL)/F_free_T.$(ARCH).o       \
    57 $(TABL)/F_table_varlength.$(ARCH).o             $(TABL)/F_copy_T.$(ARCH).o
     75$(TABL)/F_table_varlength.$(ARCH).o             $(TABL)/F_copy_T.$(ARCH).o       \
     76$(TABL)/F_compress_T.$(ARCH).o                  $(TABL)/F_uncompress_T.$(ARCH).o
    5877
    5978EXTERN_OBJ = \
  • trunk/Ohana/src/libfits/doc/notes-compress.txt

    r15487 r38441  
     1
     220150525 :
     3
     4uncompression steps:
     5
     6 * read in a table: gfits_fread_ftable_data (f, &ftable, FALSE); (no byte swap)
     7 * uncompress the image: gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable);
     8   * get ZIMAGE from heaer & delete
     9   * get ZCMPTYPE
     10   * get ZBITPIX, ZNAXIS, ZNAXISnn
     11   * get ZTILEn (if missing ZTILE1 = Nx, others 1)
     12   * get ZNAME, ZVAL
     13   * ZSIMPLE, ZTENSION, ZEXTEND, ZBLOCKED, ZPCOUNT, ZGCOUNT, etc
     14   * ZSCALE, ZBLANK, OBLANK, ZZERO
     15
     16   * data is stored in fits table COMPRESSED_DATA (1PB, 1PI, 1PJ)
     17
     18------------------------------------------------
    119
    220TFORMn : rPt(e_max)
  • trunk/Ohana/src/libfits/extern/gzip.c

    r23816 r38441  
    22# include <gfitsio.h>
    33# include <zlib.h>
     4# define EXTRA_VERBOSE 0
    45
    56/** the two functions in this file re-implement the uncompress function of zlib. 
     
    1011
    1112/* zlib.h -- interface of the 'zlib' general purpose compression library
    12   version 1.2.3, July 18th, 2005
    13 
    14   Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
    15 
    16   This software is provided 'as-is', without any express or implied
    17   warranty.  In no event will the authors be held liable for any damages
    18   arising from the use of this software.
    19 
    20   Permission is granted to anyone to use this software for any purpose,
    21   including commercial applications, and to alter it and redistribute it
    22   freely, subject to the following restrictions:
    23 
    24   1. The origin of this software must not be misrepresented; you must not
    25      claim that you wrote the original software. If you use this software
    26      in a product, an acknowledgment in the product documentation would be
    27      appreciated but is not required.
    28   2. Altered source versions must be plainly marked as such, and must not be
    29      misrepresented as being the original software.
    30   3. This notice may not be removed or altered from any source distribution.
    31 
    32   Jean-loup Gailly        Mark Adler
    33   jloup@gzip.org          madler@alumni.caltech.edu
    34 
    35 
    36   The data format used by the zlib library is described by RFCs (Request for
    37   Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
    38   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
     13   version 1.2.3, July 18th, 2005
     14
     15   Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
     16
     17   This software is provided 'as-is', without any express or implied
     18   warranty.  In no event will the authors be held liable for any damages
     19   arising from the use of this software.
     20
     21   Permission is granted to anyone to use this software for any purpose,
     22   including commercial applications, and to alter it and redistribute it
     23   freely, subject to the following restrictions:
     24
     25   1. The origin of this software must not be misrepresented; you must not
     26   claim that you wrote the original software. If you use this software
     27   in a product, an acknowledgment in the product documentation would be
     28   appreciated but is not required.
     29   2. Altered source versions must be plainly marked as such, and must not be
     30   misrepresented as being the original software.
     31   3. This notice may not be removed or altered from any source distribution.
     32
     33   Jean-loup Gailly        Mark Adler
     34   jloup@gzip.org          madler@alumni.caltech.edu
     35
     36
     37   The data format used by the zlib library is described by RFCs (Request for
     38   Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
     39   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
    3940*/
    4041
    4142/*
    42      The 'zlib' compression library provides in-memory compression and
     43  The 'zlib' compression library provides in-memory compression and
    4344  decompression functions, including integrity checks of the uncompressed
    4445  data.  This version of the library supports only one compression method
     
    4647  stream interface.
    4748
    48      Compression can be done in a single step if the buffers are large
     49  Compression can be done in a single step if the buffers are large
    4950  enough (for example if an input file is mmap'ed), or can be done by
    5051  repeated calls of the compression function.  In the latter case, the
     
    5253  (providing more output space) before each call.
    5354
    54      The compressed data format used by default by the in-memory functions is
     55  The compressed data format used by default by the in-memory functions is
    5556  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
    5657  around a deflate stream, which is itself documented in RFC 1951.
    5758
    58      The library also supports reading and writing files in gzip (.gz) format
     59  The library also supports reading and writing files in gzip (.gz) format
    5960  with an interface similar to that of stdio using the functions that start
    6061  with "gz".  The gzip format is different from the zlib format.  gzip is a
    6162  gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
    6263
    63      This library can optionally read and write gzip streams in memory as well.
    64 
    65      The zlib format was designed to be compact and fast for use in memory
     64  This library can optionally read and write gzip streams in memory as well.
     65
     66  The zlib format was designed to be compact and fast for use in memory
    6667  and on communications channels.  The gzip format was designed for single-
    6768  file compression on file systems, has a larger header than zlib to maintain
    6869  directory information, and uses a different, slower check method than zlib.
    6970
    70      The library does not install any signal handler. The decoder checks
     71  The library does not install any signal handler. The decoder checks
    7172  the consistency of the compressed data, so the library should never
    7273  crash even in case of corrupted input.
     
    116117}
    117118
    118 // XXX ??? is cfitsio writing data which is incompatible with zlib ???
    119 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
    120 {
    121     z_stream stream;
    122     int err;
    123 
    124     stream.next_in = (Bytef*)source;
    125     stream.avail_in = (uInt)sourceLen;
    126     /* Check for source > 64K on 16-bit machine: */
    127     if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
    128 
    129     stream.next_out = dest;
    130     stream.avail_out = (uInt)*destLen;
    131     if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
    132 
    133     stream.zalloc = (alloc_func)0;
    134     stream.zfree = (free_func)0;
    135 
    136     // MAX_WBITS = 15
    137     err = inflateInit2(&stream, -15);
    138     if (err != Z_OK) return err;
    139 
    140     err = inflate(&stream, Z_FINISH);
    141     if (err != Z_STREAM_END) {
    142         inflateEnd(&stream);
    143         if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
    144             return Z_DATA_ERROR;
    145         return err;
    146     }
    147     assert (stream.total_out <= *destLen);
    148     *destLen = stream.total_out;
    149 
    150     err = inflateEnd(&stream);
    151     return err;
     119# define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
     120
     121int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) {
     122
     123  z_stream stream;
     124  int i, err;
     125 
     126  stream.next_in = (Bytef*)source;
     127  stream.avail_in = (uInt)sourceLen;
     128
     129  /* Check for source > 64K on 16-bit machine: */
     130  if ((uLong)stream.avail_in != sourceLen) ESCAPE (Z_BUF_ERROR);
     131
     132  stream.next_out = dest;
     133  stream.avail_out = (uInt)*destLen; // allocated space
     134  if ((uLong)stream.avail_out != *destLen) ESCAPE (Z_BUF_ERROR);
     135
     136  stream.zalloc = Z_NULL;
     137  stream.zfree  = Z_NULL;
     138  stream.opaque = Z_NULL;
     139
     140  if (EXTRA_VERBOSE) {
     141    fprintf (stderr, "inp cmp: ");
     142    for (i = 0; i < sourceLen; i++) {
     143      fprintf (stderr, "0x%02hhx ", source[i]);
     144    }
     145    fprintf (stderr, "\n");
     146  }
     147
     148  // the '1' is the compression level: make this a user argument
     149  // NOTE: cfitsio uses a fixed value of 1
     150  // I am using deflateInit2 because cfitsio expects gzip, not just zlib
     151  // windowBits = 31 = (15 + 16) = (2^15 window bits) + (create a gzip stream)
     152  err = deflateInit2(&stream, 1, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY);
     153  if (0) fprintf (stderr, "inp buffers cmp 0: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);
     154
     155  if (err != Z_OK) ESCAPE(err);
     156
     157  // XXX this is written to do the compression in a single pass.  it could be re-done to have
     158  // the compression occur in a series of steps
     159  err = deflate(&stream, Z_FINISH);
     160  if (err != Z_STREAM_END) {
     161    err = deflateEnd(&stream);
     162    ESCAPE (Z_BUF_ERROR);
     163  }
     164
     165  if (EXTRA_VERBOSE) {
     166    fprintf (stderr, "out cmp: ");
     167    for (i = 0; i < stream.total_out; i++) {
     168      fprintf (stderr, "0x%02hhx ", dest[i]);
     169    }
     170    fprintf (stderr, "\n");
     171  }
     172
     173  assert (stream.total_out <= *destLen);
     174  *destLen = stream.total_out;
     175 
     176  err = deflateEnd(&stream);
     177  return err;
    152178}
     179
     180// NOTE: CFITSIO uses gzip format, not just zlib
     181int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) {
     182
     183  z_stream stream;
     184  int i, err;
     185 
     186  stream.next_in = (Bytef*)source;
     187  stream.avail_in = (uInt)sourceLen;
     188
     189  /* Check for source > 64K on 16-bit machine: */
     190  if ((uLong)stream.avail_in != sourceLen) ESCAPE (Z_BUF_ERROR);
     191 
     192  stream.next_out = dest;
     193  stream.avail_out = (uInt)*destLen;
     194  if ((uLong)stream.avail_out != *destLen) ESCAPE (Z_BUF_ERROR);
     195 
     196  stream.zalloc = Z_NULL;
     197  stream.zfree  = Z_NULL;
     198  stream.opaque = Z_NULL;
     199 
     200  if (EXTRA_VERBOSE) {
     201    fprintf (stderr, "inp unc: ");
     202    for (i = 0; i < sourceLen; i++) {
     203      fprintf (stderr, "0x%02hhx ", source[i]);
     204    }
     205    fprintf (stderr, "\n");
     206  }
     207 
     208  // windowBits = 47 = (15 + 32) = (2^15 window bits) + (test for either gzip or zlib
     209  // streams).  NOTE: modern versions of zlib (version > 1.2.3.4) allow for windowBits = 0
     210  // (or 16 or 32) to use the compressed stream windowBits value.  IPP cluster still has
     211  // zlib version = 1.2.3, so we cannot use this feature.
     212  err = inflateInit2(&stream, 47);
     213  if (err != Z_OK) ESCAPE (err);
     214 
     215  err = inflate(&stream, Z_FINISH);
     216  if (err != Z_STREAM_END) {
     217    inflateEnd(&stream);
     218    if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) ESCAPE (Z_DATA_ERROR);
     219    ESCAPE(err);
     220  }
     221 
     222  if (EXTRA_VERBOSE) {
     223    fprintf (stderr, "out unc: ");
     224    for (i = 0; i < stream.total_out; i++) {
     225      fprintf (stderr, "0x%02hhx ", dest[i]);
     226    }
     227    fprintf (stderr, "\n");
     228  }
     229
     230  assert (stream.total_out <= *destLen);
     231  *destLen = stream.total_out;
     232
     233  err = inflateEnd(&stream);
     234  return err;
     235}
     236
  • trunk/Ohana/src/libfits/header/F_copy_H.c

    r27435 r38441  
    3030  return (TRUE);
    3131}       
     32
     33int gfits_copy_header_ptr (Header *in, Header *out) {
     34
     35  int i;
     36
     37  if (!in)  return FALSE;
     38  if (!out) return FALSE;
     39
     40  out[0].simple = in[0].simple;
     41  out[0].unsign = in[0].unsign;
     42  out[0].extend = in[0].extend;
     43  out[0].bitpix = in[0].bitpix;
     44
     45  out[0].Naxes  = in[0].Naxes;
     46  for (i = 0; i < FT_MAX_NAXES; i++)
     47    out[0].Naxis[i] = in[0].Naxis[i];
     48
     49  out[0].datasize = in[0].datasize;
     50
     51  out[0].pcount = in[0].pcount;
     52  out[0].gcount = in[0].gcount;
     53  out[0].bzero  = in[0].bzero;
     54  out[0].bscale = in[0].bscale;
     55
     56  out[0].buffer = in[0].buffer;
     57
     58  return (TRUE);
     59}       
  • trunk/Ohana/src/libfits/header/F_modify.c

    r34577 r38441  
    4848    strncpy (comment, qe, p + 80 - qe);
    4949  }
    50   gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
     50  gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
    5151
    5252  /* write the numeric modes */
     
    134134    strncpy (comment, qe, p + 80 - qe);
    135135  }
    136   gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
     136  gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
    137137
    138138  /* write the boolean mode */
     
    166166    if (!ptr) goto invalid;
    167167    strncpy (comment, ptr, 80);
    168     gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
     168    gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
    169169    snprintf (string, 81, "%-8s= %s / %-s", field, data, comment);
    170170    /* this will keep the original line, but truncate the comment */
     
    296296 */
    297297
     298// XXX this is an absurd patch on a gcc bug: memset has a problem is value != 0 and N is constant
     299void myMemset (char *ptr, int value, size_t N) {
     300
     301  char *p = ptr;
     302 
     303  size_t i = 0;
     304  for (i = 0; i < N; i++, p++) {
     305    *p = value;
     306  }
     307}
     308
    298309/* fill 'line' with Nbyte space from first NULL to last byte with value */
    299310void gfits_pad_ending (char *line, char value, int Nbyte) {
    300  
    301   char *p;
    302   int N;
    303311
    304312  line[Nbyte-1] = 0;
    305313 
    306   p = line + strlen (line);
    307   N = MAX (Nbyte - strlen (line) - 1, 0);
    308   memset (p, value, N);
     314  char *p = line + strlen (line);
     315  size_t N = MAX (Nbyte - strlen (line) - 1, 0);
     316  myMemset (p, value, N);
    309317}
    310318
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r38255 r38441  
    7373  off_t                   datasize; // size of the buffer (including block padding at the end)
    7474  off_t                   validsize;  // size of the valid portion of the table (< validsize if file is short)
     75  off_t                   heap_start; // byte offset to start of HEAP
    7576} FTable;
    7677
     
    8586} VTable;
    8687
    87 typedef struct {
    88   int   maxlen;               // max size of all table rows
    89   int   nbytes;               // number of bytes per column element
    90   int   Nstart;               // byte offset of this column relative to first column
    91   off_t heap_start;           // byte offset to start of HEAP
    92   char  format;               // data format character (one of: XLABIJEDCM)
    93   char  mode;                 // access data pointer type (one of P or Q)
     88// description / metadata needed for a single varlength column.  A varlength column has a
     89// 2-element array giving the (length,offset) of data in the heap.  Below, 'real data' are
     90// the values in the heap; 'metadata' are the values in the main table.
     91typedef struct {
     92  int   column;               // field number (of the metadata)
     93  char  format;               // format character for real data (one of: XLABIJKEDCM)
     94  char  mode;                 // format character for metadata (one of P [float] or Q [double])
     95  int   maxlen;               // max size of all table rows for this column
     96  int   nbytes;               // number of bytes per real data column element
     97  int   offset;               // byte offset of the metadata column relative to first column
    9498} VarLengthColumn;
     99
     100typedef 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
     108  VarLengthColumn zdef;       // description of the output variable length column
     109
     110  char datatype[80];          // named data type associated with ttype (eg, 18J -> int, 18D -> double)
     111  int Nvalues;                // number of values per row (eg 18J -> 18 int values)
     112  int pixsize;                // number of bytes per value of this row (eg, 18J -> 4 bytes)
     113  int rowsize;                // number of bytes for a full row (Nvalues * pixsize)
     114  int offset;                 // byte offset of the real data column relative to first column
     115} TableField;
    95116
    96117# ifndef PROTO
     
    106127char   *gfits_keyword_end              PROTO((char *line));
    107128int     gfits_copy_header              PROTO((Header *in, Header *out));
     129int     gfits_copy_header_ptr          PROTO((Header *in, Header *out));
    108130int     gfits_create_header            PROTO((Header *header));
    109131int     gfits_delete                   PROTO((Header *header, char *field, int N));
     
    117139int     gfits_modify                   PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5);
    118140int     gfits_print                    PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5);
    119 int     gfits_modify_alt               PROTO((Header *header, char *field, char *mode, int N,...));
    120 int     gfits_print_alt                PROTO((Header *header, char *field, char *mode, int N,...));
     141int     gfits_modify_alt               PROTO((Header *header, char *field, char *mode, int N,...)); // do not use a FORMAT: non-standard fmt chars
     142int     gfits_print_alt                PROTO((Header *header, char *field, char *mode, int N,...)); // do not use a FORMAT: non-standard fmt chars
    121143int     gfits_find_Xheader             PROTO((FILE *f, Header *header, char *extname));
    122144int     gfits_read_Xheader             PROTO((char *filename, Header *header, int N));
     
    124146int     gfits_save_header              PROTO((FILE *f, Header *header));
    125147int     gfits_scan                     PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(scanf, 3, 5);
    126 int     gfits_scan_alt                 PROTO((Header *header, char *field, char *mode, int N,...));
     148int     gfits_scan_alt                 PROTO((Header *header, char *field, char *mode, int N,...)); // do not use a FORMAT: non-standard fmt chars
    127149int     gfits_set_unsign_mode          PROTO((int mode));
    128150int     gfits_stripwhite               PROTO((char *string));
     
    133155off_t   gfits_data_min_size            PROTO((Header *header));
    134156off_t   gfits_data_pad_size            PROTO((off_t rawsize));
     157off_t   gfits_heap_start               PROTO((Header *header));
    135158int     gfits_extended_to_primary      PROTO((Header *header, int simple, char *comment));
    136159int     gfits_primary_to_extended      PROTO((Header *header, char *exttype, char *comment));
     
    166189void    gfits_set_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y, double value));
    167190int     gfits_write_matrix             PROTO((char *filename, Matrix *matrix));
     191
    168192int     gfits_uncompress_image         PROTO((Header *header, Matrix *matrix, FTable *ftable));
    169 int     gfits_uncompress_data          PROTO((char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize));
    170 int     gfits_distribute_data          PROTO((Matrix *matrix, int bitpix, char *data, int Ndata, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero));
    171 int     gfits_byteswap_zdata           PROTO((char *zdata, int Nzdata, int bitpix));
     193int     gfits_uncompress_data          PROTO((char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int Nout_alloc, int out_pixsize));
     194int     gfits_distribute_data          PROTO((Matrix *matrix, char *data, int Ndata, int bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero));
     195
     196int     gfits_compress_data            PROTO((char *zdata, int *Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *rawdata, int Nraw, int raw_pixsize, int Nx, int Ny));
     197int     gfits_compress_image           PROTO((Header *header, Matrix *matrix, FTable *ftable, int *Ztile, char *zcmptype));
     198int     gfits_collect_data             PROTO((Matrix *matrix, char *raw, int Nraw, int raw_pixsize, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero));
     199
     200int     gfits_copy_keywords_compress   PROTO((Header *srchead, Header *tgthead));
    172201int     gfits_swap_raw                 PROTO((Matrix *matrix));
    173 int     gfits_extension_is_compressed  PROTO((Header *header));
     202
    174203off_t   gfits_tile_size                PROTO((Matrix *matrix, int *otile, int *ztile));
     204int     gfits_imtile_maxsize           PROTO((Matrix *matrix, int *ztile));
     205int     gfits_imtile_count             PROTO((Matrix *matrix, int *ztile, int *ntile));
     206int     gfits_imtile_start             PROTO((Matrix *matrix, int *otile));
     207int     gfits_imtile_next              PROTO((Matrix *matrix, int *ztile, int *ntile, int *otile));
     208
     209int     gfits_extension_is_compressed_image  PROTO((Header *header));
     210int     gfits_extension_is_compressed_table  PROTO((Header *header));
     211int     gfits_byteswap_zdata            PROTO((char *zdata, int Nzdata, int pixsize));
     212int     gfits_compressed_data_pixsize   PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
    175213int     gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
    176 int     gfits_vartable_heap_pixsize    PROTO((char format));
     214int     gfits_uncompressed_data_bitpix  PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
     215int     gfits_vartable_heap_pixsize     PROTO((char format));
     216int     gfits_cmptype_valid             PROTO((char *cmptype));
     217
     218int     gfits_varlength_column_add_data PROTO((FTable *table, char *data, off_t Ndata, int row, VarLengthColumn *column));
     219void   *gfits_varlength_column_pointer  PROTO((FTable *ftable, VarLengthColumn *column, off_t row, off_t *length));
     220int     gfits_varlength_column_define   PROTO((FTable *ftable, VarLengthColumn *def, int column));
     221int     gfits_varlength_column_finish   PROTO((FTable *ftable, VarLengthColumn *def));
     222int     gfits_byteswap_varlength_column PROTO((FTable *ftable, int column));
    177223
    178224/******************************* Table functions *************/
     
    183229char   *gfits_table_print              PROTO((FTable *ftable,...));
    184230int     gfits_add_rows                 PROTO((FTable *ftable, char *data, off_t Nrow, off_t Nbytes));
     231int     gfits_set_table_rows           PROTO((Header *header, FTable *table, off_t Nrows));
    185232int     gfits_bintable_format          PROTO((char *format, char *type, int *Nval, int *Nbytes));
    186233int     gfits_create_table             PROTO((Header *header, FTable *ftable));
     
    199246int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal));
    200247int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
     248int     gfits_get_bintable_column_raw  PROTO((Header *header, FTable *table, char *label, void **data, char nativeOrder));
    201249int     gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval));
     250void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));
    202251int     gfits_get_bintable_column_type_by_N  PROTO((Header *header, int N, char *type, int *Nval));
    203 void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));
     252void   *gfits_get_bintable_column_data_raw   PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol, char nativeOrder));
    204253int     gfits_get_table_column         PROTO((Header *header, FTable *table, char *label, void **data));
    205254int     gfits_get_table_column_type    PROTO((Header *header, char *label, char *type));
     
    207256int     gfits_read_table               PROTO((char *filename, FTable *ftable));
    208257int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    209 int     gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow));
     258int     gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder));
    210259int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    211260int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4);
     
    219268int     gfits_copy_ftable              PROTO((FTable *in, FTable *out));
    220269int     gfits_copy_vtable              PROTO((VTable *in, VTable *out));
     270int     gfits_copy_ftable_ptr          PROTO((FTable *in, FTable *out));
    221271
    222272int     gfits_create_Theader           PROTO((Header *header, char *type));
     
    227277int     gfits_write_Theader            PROTO((char *filename, Header *header));
    228278
    229 int     gfits_varlength_column_define  PROTO((FTable *ftable, VarLengthColumn *def, int column));
    230 void   *gfits_varlength_column_pointer PROTO((FTable *ftable, VarLengthColumn *column, off_t row, off_t *length));
     279int     gfits_compress_table           PROTO((FTable *srctable, FTable *tgttable, int ztilelen, char *zcmptype));
     280int     gfits_uncompress_table         PROTO((FTable *srctable, FTable *tgttable));
     281
     282// XXX EAM for testing
     283int gfits_dump_raw_table (FTable *table, char *message);
     284int gfits_dump_cmp_table (FTable *table, char *message);
     285
    231286
    232287#endif /* FITSIO */
  • trunk/Ohana/src/libfits/matrix/F_matrix.c

    r35164 r38441  
    22# include <gfitsio.h>
    33
    4 off_t gfits_data_size (Header *header) {
    5  
    6   int i;
    7   off_t Nrec, size;
    8 
    9   if (header[0].Naxes == 0) return (0);
    10 
    11   size = abs(header[0].bitpix / 8);
    12 
    13   for (i = 0; i < header[0].Naxes; i++)
    14     size *= header[0].Naxis[i];
    15 
    16   // XXX do I multiply this times gcount?
    17   size += header[0].pcount;
    18 
    19   /* round up to next complete block */
    20   if (size % FT_RECORD_SIZE) {
    21     Nrec = 1 + (int) (size / FT_RECORD_SIZE);
    22     size = FT_RECORD_SIZE * Nrec;
    23   }
    24 
    25   return (size);
    26 }
    27 
    28 off_t gfits_data_min_size (Header *header) {
     4off_t gfits_heap_start (Header *header) {
    295 
    306  int i;
     
    3814    size *= header[0].Naxis[i];
    3915
    40   // XXX do I multiply this times gcount?
     16  return (size);
     17}
     18
     19off_t gfits_data_min_size (Header *header) {
     20 
     21  off_t size = gfits_heap_start (header);
    4122  size += header[0].pcount;
     23
     24  // XXX what do I do with gcount?
    4225
    4326  return (size);
     
    4629off_t gfits_data_pad_size (off_t rawsize) {
    4730 
    48   off_t Nrec, size;
    49 
    50   size = rawsize;
     31  off_t size = rawsize;
    5132
    5233  /* round up to next complete block */
    5334  if (rawsize % FT_RECORD_SIZE) {
    54     Nrec = 1 + (int) (rawsize / FT_RECORD_SIZE);
     35    off_t Nrec = 1 + (int) (rawsize / FT_RECORD_SIZE);
    5536    size = FT_RECORD_SIZE * Nrec;
    5637  }
     
    5839  return (size);
    5940}
     41
     42off_t gfits_data_size (Header *header) {
     43  off_t rawsize = gfits_data_min_size(header);
     44  off_t size = gfits_data_pad_size (rawsize);
     45
     46  return (size);
     47}
     48
  • trunk/Ohana/src/libfits/matrix/F_uncompress_data.c

    r23815 r38441  
    2626int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
    2727
    28 int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize) {
     28# define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
     29
     30int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int Nout_alloc, int out_pixsize) {
    2931
    3032  int status;
    31   static int Ninsum = 0;
    32   static int Noutsum = 0;
    3333
    34   if (!strcasecmp(cmptype, "GZIP_1")) {
    35     unsigned long tNout = *Nout * out_pixsize;
     34  // do not actually uncompress : this is used for testing
     35  if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1") || !strcasecmp(cmptype, "NONE_2")) {
     36    memcpy (outdata, zdata, Nzdata);
     37    myAssert (*Nout == Nzdata, "invalid size");
     38    *Nout = Nzdata / out_pixsize;
     39    return (TRUE);
     40  }
     41
     42  if (!strcasecmp(cmptype, "GZIP_1") || !strcasecmp(cmptype, "GZIP_2")) {
     43    // unsigned long tNout = *Nout * out_pixsize;
     44    // input value of *Nout is number of BYTES
     45    unsigned long tNout = Nout_alloc;
    3646
    3747    // for GZIP data, I need to check for and remove the header on the first block:
    38     gfits_gz_stripheader ((unsigned char *)zdata, &Nzdata);
     48    // XXX maybe not anymore
     49    // gfits_gz_stripheader ((unsigned char *)zdata, &Nzdata);
    3950
    4051    // uncompress does not require us to know the expected number of pixel; it tells us the number
     52    // XXX shouldn't we validate the result : we think we know the size
    4153    status = gfits_uncompress ((Bytef *) outdata, &tNout, (Bytef *) zdata, Nzdata);
    42     if (status != Z_OK) {
    43       fprintf (stderr, "error in uncompress (GZIP)\n");
    44       return (FALSE);
    45     }
     54    if (status != Z_OK) ESCAPE(FALSE);
     55    myAssert (*Nout == tNout, "uncompressed size mismatch");
    4656    *Nout = tNout / out_pixsize;
     57    // output value of *Nout is number of PIXELS
    4758
    4859    // the resulting uncompressed data is byteswapped
    49     if (!gfits_byteswap_zdata (outdata, *Nout, out_pixsize)) return (FALSE);
     60    // if (!gfits_byteswap_zdata (outdata, *Nout, out_pixsize)) return (FALSE);
    5061
    5162    return (TRUE);
    5263  }
    5364
    54   if (!strcasecmp(cmptype, "RICE_1")) {
     65  if (!strcasecmp(cmptype, "RICE_1") || !strcasecmp(cmptype, "RICE_ONE")) {
    5566    int i, blocksize;
    5667    // look for the BLOCKSIZE
     
    6677    }
    6778
    68     int Npix;
    69     // Npix = *Nout * (out_pixsize / 4.0);
    70     Npix = *Nout;
    71 
    72     Ninsum += Nzdata;
    73     Noutsum += *Nout;
    74     // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum);
     79    int status = FALSE;
     80    int Npix = *Nout / out_pixsize;
     81    int k;
    7582
    7683    switch (out_pixsize) {
    7784      case 4:
    7885        // rice decompression from the CFITSIO source tree : we need to tell it the expected number of pixels
    79         // is also REQUIRES 4byte output, which is fairly stupid.
    80         if (fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize)) {
    81           fprintf (stderr, "error in rice decompression\n");
    82           return (FALSE);
     86        status = fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize);
     87        break;
     88      case 2:
     89        if (0) {
     90          fprintf (stderr, "Nout: %d, Nrawpix: %d\n", Nzdata, Npix);
     91          fprintf (stderr, "cmp out: ");
     92          for (k = 0; k < Nzdata; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     93          fprintf (stderr, "\n");
    8394        }
    84         return (TRUE);
    85 
    86       case 2:
    87         if (fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize)) {
    88           fprintf (stderr, "error in rice decompression\n");
    89           return (FALSE);
    90         }
    91         return (TRUE);
    92 
     95        status = fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize);
     96        break;
    9397      case 1:
    94         if (fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize)) {
    95           fprintf (stderr, "error in rice decompression\n");
    96           return (FALSE);
    97         }
    98         return (TRUE);
    99        
     98        status = fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize);
     99        break;
    100100      default:
    101101        fprintf (stderr, "invalid output pixel size %d\n", out_pixsize);
    102         return (FALSE);
     102        status = FALSE;
     103        break;
    103104    }
    104    
     105    if (status) {
     106      *Nout = 0;
     107      return FALSE;
     108    }
     109    *Nout = Npix;
     110    return TRUE;
    105111  }
    106112 
  • trunk/Ohana/src/libfits/table/F_copy_T.c

    r34088 r38441  
    66
    77  /* find buffer size */
    8   out[0].validsize = in[0].validsize;
    9   out[0].datasize  = in[0].datasize;
     8  out[0].validsize  = in[0].validsize;
     9  out[0].datasize   = in[0].datasize;
     10  out[0].heap_start = in[0].heap_start;
    1011
    1112  ALLOCATE (out[0].buffer, char, out[0].datasize);
    1213  memcpy (out[0].buffer, in[0].buffer, out[0].datasize);
     14  return (TRUE);
     15}       
     16
     17/*********************** copy ftable pointers (does not copy memory) ***********************************/
     18int gfits_copy_ftable_ptr (FTable *in, FTable *out) {
     19
     20  if (!in)  return FALSE;
     21  if (!out) return FALSE;
     22
     23  /* find buffer size */
     24  out[0].validsize  = in[0].validsize;
     25  out[0].datasize   = in[0].datasize;
     26  out[0].heap_start = in[0].heap_start;
     27  out[0].header     = in[0].header;
     28  out[0].buffer     = in[0].buffer;
    1329  return (TRUE);
    1430}       
     
    2844
    2945  /* find buffer size */
    30   out[0].datasize = in[0].datasize;
    31   out[0].pad      = in[0].pad;
    32   out[0].Nrow     = in[0].Nrow;
     46  out[0].datasize   = in[0].datasize;
     47  // out[0].heap_start = in[0].heap_start;
     48  out[0].pad        = in[0].pad;
     49  out[0].Nrow       = in[0].Nrow;
    3350
    3451  off_t Nrows = out[0].Nrow;
  • trunk/Ohana/src/libfits/table/F_create_T.c

    r35756 r38441  
    44/*********************** fits init table *******************************/
    55int gfits_init_table (FTable *table) {
    6   table[0].header = NULL;
    7   table[0].buffer = NULL;
    8   table[0].datasize = 0;
    9   table[0].validsize = 0;
     6  table[0].header     = NULL;
     7  table[0].buffer     = NULL;
     8  table[0].datasize   = 0;
     9  table[0].heap_start = 0;
     10  table[0].validsize  = 0;
    1011  return (TRUE);
    1112
     
    4243  }
    4344  table[0].datasize = Nbytes;
     45  table[0].heap_start = gfits_heap_start (header);
    4446  return (TRUE);
    4547
     48}
     49
     50/*********************** fits create table *******************************/
     51int gfits_set_table_rows (Header *header, FTable *table, off_t Nrows) {
     52
     53    header[0].Naxis[1] = Nrows;
     54    gfits_modify (header, "NAXIS2", OFF_T_FMT, 1,  Nrows);
     55
     56    off_t Nbytes = gfits_data_size (header);
     57    REALLOCATE (table[0].buffer, char, Nbytes);
     58    bzero (table[0].buffer, Nbytes);
     59    table[0].datasize = Nbytes;
     60    table[0].heap_start = gfits_heap_start (header);
     61  return (TRUE);
    4662}
    4763
     
    6076  Ny = table[0].header[0].Naxis[0];
    6177  table[0].datasize = gfits_data_size (header);
     78  // table[0].heap_start = gfits_heap_start (header);
    6279  table[0].pad = table[0].datasize - Nx*Ny;
    6380 
  • trunk/Ohana/src/libfits/table/F_define_column.c

    r35756 r38441  
    6666  sprintf (field, "TTYPE%d", Nfields);
    6767  gfits_modify (header, field, "%s", 1, label);
    68   gfits_modify_alt (header, field, "%C", 1, comment);
    69   sprintf (field, "TUNIT%d", Nfields);
    70   gfits_modify (header, field, "%s", 1, unit);
     68  if (comment) {
     69    gfits_modify_alt (header, field, "%C", 1, comment);
     70  }
     71  if (unit) {
     72    sprintf (field, "TUNIT%d", Nfields);
     73    gfits_modify (header, field, "%s", 1, unit);
     74  }
    7175  sprintf (field, "TFORM%d", Nfields);
    7276  gfits_modify (header, field, "%s", 1, format);
  • trunk/Ohana/src/libfits/table/F_get_column.c

    r37039 r38441  
    1717
    1818void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol) {
     19  void *data = gfits_get_bintable_column_data_raw (header, table, label, type, Nrow, Ncol, FALSE);
     20  return data;
     21}
     22
     23void *gfits_get_bintable_column_data_raw (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol, char nativeOrder) {
    1924
    2025  off_t Nx, Ny;
     
    7176  }
    7277
    73   /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
     78  // NOTE: we have already copied the data to 'array', so the blocks below
     79  // only need to swap if this is a direct copy
    7480  Pin  = array;
    7581  Pout = array;
     82  int directCopy = (Bzero == 0.0) && (Bscale == 1.0);
     83
     84  /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
    7685  if (!strcmp (type, "char")) {
    7786    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    78       *(char *)Pout = *(char *)Pin*Bscale + Bzero;
     87      if (!directCopy) { *(char *)Pout = *(char *)Pin*Bscale + Bzero; }
    7988    }
    8089  }
    8190  if (!strcmp (type, "byte")) {
    8291    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    83       *(char *)Pout = *(char *)Pin*Bscale + Bzero;
     92      if (!directCopy) { *(char *)Pout = *(char *)Pin*Bscale + Bzero; }
    8493    }
    8594  }
     
    8796    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    8897# ifdef BYTE_SWAP
    89       SWAP_BYTE;
    90 # endif
    91       *(short *)Pout = *(short *)Pin*Bscale + Bzero;
     98      if (!nativeOrder) { SWAP_BYTE; }
     99# endif
     100      if (!directCopy) { *(short *)Pout = *(short *)Pin*Bscale + Bzero; }
    92101    } 
    93102  }
     
    95104    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    96105# ifdef BYTE_SWAP
    97       SWAP_WORD;
    98 # endif
    99       *(int *)Pout = *(int *)Pin*Bscale + Bzero;
     106      if (!nativeOrder) { SWAP_WORD; }
     107# endif
     108      if (!directCopy) { *(int *)Pout = *(int *)Pin*Bscale + Bzero; }
    100109    }
    101110  }
    102111  if (!strcmp (type, "int64_t")) {
    103     if ((Bzero == 0.0) && (Bscale == 1.0)) {
    104       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    105 # ifdef BYTE_SWAP
    106         SWAP_DBLE;
    107 # endif
    108         *(int64_t *)Pout = *(int64_t *)Pin;
    109       }
    110     } else {
    111       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    112 # ifdef BYTE_SWAP
    113         SWAP_DBLE;
    114 # endif
    115         *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
    116       }
     112    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     113# ifdef BYTE_SWAP
     114      if (!nativeOrder) { SWAP_DBLE; }
     115# endif
     116      if (!directCopy) { *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero; }
    117117    }
    118118  }
     
    120120    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    121121# ifdef BYTE_SWAP
    122       SWAP_WORD;
    123 # endif
    124       *(float *)Pout = *(float *)Pin*Bscale + Bzero;
     122      if (!nativeOrder) { SWAP_WORD; }
     123# endif
     124      if (!directCopy) { *(float *)Pout = *(float *)Pin*Bscale + Bzero; }
    125125    }
    126126  }
     
    128128    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    129129# ifdef BYTE_SWAP
    130       SWAP_DBLE;
    131 # endif
    132       *(double *)Pout = *(double *)Pin*Bscale + Bzero;
    133     }
    134   }
     130      if (!nativeOrder) { SWAP_DBLE; }
     131# endif
     132      if (!directCopy) { *(double *)Pout = *(double *)Pin*Bscale + Bzero; }
     133    }
     134  }
     135
     136  // check that we supplied a valid type
    135137
    136138  *Ncol = Nval;
     
    174176  if (!gfits_get_bintable_column_type_by_N (header, N, type, Nval)) return FALSE;
    175177  return (TRUE);
     178}
     179
     180/***********************/
     181int gfits_get_bintable_column_raw (Header *header, FTable *table, char *label, void **data, char nativeOrder) {
     182
     183  char type[16];
     184  off_t Nrow;
     185  int Ncol;
     186
     187  char *array = gfits_get_bintable_column_data_raw (header, table, label, type, &Nrow, &Ncol, nativeOrder);
     188  if (array == NULL) return (FALSE);
     189
     190  *data = array;
     191  return TRUE;
    176192}
    177193
  • trunk/Ohana/src/libfits/table/F_read_T.c

    r37807 r38441  
    4545    if (Nread < gfits_data_min_size (table[0].header)) {
    4646      fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  gfits_data_min_size (table[0].header));
    47       if (padIfShort) {
    48         memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
    49         fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
    50         table[0].validsize = Nread;
    51         table[0].datasize = Nbytes;
    52         return (TRUE);
    53       } else {
    54         gfits_free_table  (table);
     47      if (!padIfShort) {
     48        gfits_free_table (table);
    5549        return (FALSE);
    5650      }
    57     }
    58     fprintf (stderr, "warning: file missing pad\n");
     51      memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
     52      fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
     53    } else {
     54      fprintf (stderr, "warning: file missing pad\n");
     55    }
    5956  }
    6057  table[0].validsize = Nread;
    6158  table[0].datasize = Nbytes;
     59  table[0].heap_start = gfits_heap_start (table->header);
    6260  return (TRUE);
    6361}       
     
    9391    }
    9492    fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  Nbytes);
    95     if (padIfShort) {
    96       memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
    97       fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
    98       table[0].validsize = Nread;
    99       table[0].datasize = Nbytes;
    100     } else {
     93    if (!padIfShort) {
    10194      free (table[0].buffer);
    10295      return (FALSE);
    10396    }
     97    memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
     98    fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
    10499  }
    105100
     
    107102  table[0].header[0].Naxis[1] = Nrows;
    108103  gfits_modify (table[0].header, "NAXIS2",  OFF_T_FMT, 1,  Nrows);
    109   table[0].datasize = gfits_data_size (table[0].header);
     104  table[0].validsize = Nread;
     105  table[0].datasize = Nbytes;
     106  table[0].heap_start = gfits_heap_start (table->header);
    110107
    111108  return (TRUE);
     
    122119  Ny = table[0].header[0].Naxis[1];
    123120  table[0].datasize = gfits_data_size (table[0].header);
     121  // table[0].heap_start = gfits_heap_start (table[0].header);
    124122  table[0].pad = table[0].datasize - Nx*Ny;
    125123
     
    206204    for (i = 0; i < Nrow; i++) table[0].row[i] = row[i];
    207205    table[0].datasize = gfits_data_size (table[0].header);
     206    // table[0].heap_start = gfits_heap_start (table[0].header);
    208207    table[0].pad      = table[0].datasize - Nx*Ny;
    209208    return (TRUE);
  • trunk/Ohana/src/libfits/table/F_set_column.c

    r37039 r38441  
    11# include <ohana.h>
    22# include <gfitsio.h>
     3
     4# define SWAP_NONE
     5
     6# ifdef BYTE_SWAP
    37# define SWAP_BYTE { \
    48  char tmp; \
     
    1418  tmp = Pout[2]; Pout[2] = Pout[5]; Pout[5] = tmp; \
    1519  tmp = Pout[3]; Pout[3] = Pout[4]; Pout[4] = tmp; }
     20# else
     21# define SWAP_BYTE
     22# define SWAP_WORD
     23# define SWAP_DBLE
     24# endif
    1625
    1726/***********************/
    1827int gfits_set_bintable_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) {
    1928
    20   off_t Nx, Ny, nbytes;
     29  off_t Nx, Ny;
    2130  int i, N, Nfields;
    2231  int Nval, Nbytes, Nstart, Nv, Nb;
     
    5564  gfits_scan (header, "NAXIS1", OFF_T_FMT, 1,  &Nx);
    5665  gfits_scan (header, "NAXIS2", OFF_T_FMT, 1,  &Ny);
     66
     67  // if no rows have yet been assigned, we need to allocate the full data buffer
    5768  if (Ny == 0) {
    5869    Ny = Nrow;
    59     header[0].Naxis[1] = Ny;
    60     gfits_modify (header, "NAXIS2", OFF_T_FMT, 1,  Ny);
    61 
    62     nbytes = gfits_data_size (header);
    63     REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
    64     bzero (table[0].buffer, nbytes);
    65     table[0].datasize = nbytes;
     70    gfits_set_table_rows (header, table, Ny);
    6671  }
    6772  if (Ny != Nrow) return (FALSE);
     
    143148  }
    144149
     150  if (!strcmp (type, "var")) {
     151    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     152      *(int *)Pout = *(int *)Pin;
     153# ifdef BYTE_SWAP
     154      SWAP_WORD;
     155# endif
     156    }
     157  }
     158
     159  if (!strcmp (type, "var64")) {
     160    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     161      *(int *)Pout = *(int *)Pin;
     162# ifdef BYTE_SWAP
     163      SWAP_DBLE;
     164# endif
     165    }
     166  }
     167
    145168  /* check array space */
    146169  if (Nx*Ny < Nx*(Nrow - 1) + Nstart + Nval*Nbytes) {
     
    161184
    162185/***********************/
    163 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow) {
    164 
    165   off_t Nx, Ny, nbytes;
     186// convert the input data array (of the specified intype) to the desired table data type. swap unless nativeOrder is requested
     187int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder) {
     188
     189  off_t Nx, Ny;
    166190  int i, N, Nfields;
    167191  int Nval, NbytesOut, Nstart, Nv, Nb;
     
    202226  if (Ny == 0) {
    203227    Ny = Nrow;
    204     header[0].Naxis[1] = Ny;
    205     gfits_modify (header, "NAXIS2", OFF_T_FMT, 1,  Ny);
    206 
    207     nbytes = gfits_data_size (header);
    208     REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
    209     bzero (table[0].buffer, nbytes);
    210     table[0].datasize = nbytes;
     228    gfits_set_table_rows (header, table, Ny);
    211229  }
    212230  if (Ny != Nrow) return (FALSE);
     
    230248  // if (!strcmp (intype, #ITYPE)) {
    231249
     250  int directCopy = (Bzero == 0.0) && (Bscale == 1.0);
     251
     252# define SET_VALUES(OUTNAME, OUTTYPE, INNAME, INTYPE, SWAP_OP, NBYTES_IN) \
     253  if (!strcmp (outtype, OUTNAME) && !strcmp (intype, INNAME)) {         \
     254    int NbytesIn = NBYTES_IN;                                           \
     255    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { \
     256      if (directCopy) {                                                 \
     257        *(OUTTYPE *)Pout = *(INTYPE *)Pin;                              \
     258      } else {                                                          \
     259        *(OUTTYPE *)Pout = (*(INTYPE *)Pin - Bzero) / Bscale;           \
     260      }                                                                 \
     261      if (!nativeOrder) { SWAP_OP; }}}                                 
     262
     263  SET_VALUES("char",       char, "char", char, SWAP_NONE, 1);
     264  SET_VALUES("byte",       char, "char", char, SWAP_NONE, 1);
     265  SET_VALUES("short",     short, "char", char, SWAP_BYTE, 1);
     266  SET_VALUES("int",         int, "char", char, SWAP_WORD, 1);
     267  SET_VALUES("int64_t", int64_t, "char", char, SWAP_DBLE, 1);
     268  SET_VALUES("float",     float, "char", char, SWAP_WORD, 1);
     269  SET_VALUES("double",   double, "char", char, SWAP_DBLE, 1);
     270
     271  SET_VALUES("char",       char, "byte", char, SWAP_NONE, 1);
     272  SET_VALUES("byte",       char, "byte", char, SWAP_NONE, 1);
     273  SET_VALUES("short",     short, "byte", char, SWAP_BYTE, 1);
     274  SET_VALUES("int",         int, "byte", char, SWAP_WORD, 1);
     275  SET_VALUES("int64_t", int64_t, "byte", char, SWAP_DBLE, 1);
     276  SET_VALUES("float",     float, "byte", char, SWAP_WORD, 1);
     277  SET_VALUES("double",   double, "byte", char, SWAP_DBLE, 1);
     278
     279  SET_VALUES("char",       char, "short", short, SWAP_NONE, 2);
     280  SET_VALUES("byte",       char, "short", short, SWAP_NONE, 2);
     281  SET_VALUES("short",     short, "short", short, SWAP_BYTE, 2);
     282  SET_VALUES("int",         int, "short", short, SWAP_WORD, 2);
     283  SET_VALUES("int64_t", int64_t, "short", short, SWAP_DBLE, 2);
     284  SET_VALUES("float",     float, "short", short, SWAP_WORD, 2);
     285  SET_VALUES("double",   double, "short", short, SWAP_DBLE, 2);
     286
     287  SET_VALUES("char",       char, "int", int, SWAP_NONE, 4);
     288  SET_VALUES("byte",       char, "int", int, SWAP_NONE, 4);
     289  SET_VALUES("short",     short, "int", int, SWAP_BYTE, 4);
     290  SET_VALUES("int",         int, "int", int, SWAP_WORD, 4);
     291  SET_VALUES("int64_t", int64_t, "int", int, SWAP_DBLE, 4);
     292  SET_VALUES("float",     float, "int", int, SWAP_WORD, 4);
     293  SET_VALUES("double",   double, "int", int, SWAP_DBLE, 4);
     294
     295  SET_VALUES("char",       char, "int64_t", int64_t, SWAP_NONE, 8);
     296  SET_VALUES("byte",       char, "int64_t", int64_t, SWAP_NONE, 8);
     297  SET_VALUES("short",     short, "int64_t", int64_t, SWAP_BYTE, 8);
     298  SET_VALUES("int",         int, "int64_t", int64_t, SWAP_WORD, 8);
     299  SET_VALUES("int64_t", int64_t, "int64_t", int64_t, SWAP_DBLE, 8);
     300  SET_VALUES("float",     float, "int64_t", int64_t, SWAP_WORD, 8);
     301  SET_VALUES("double",   double, "int64_t", int64_t, SWAP_DBLE, 8);
     302
     303  SET_VALUES("char",       char, "float", float, SWAP_NONE, 4);
     304  SET_VALUES("byte",       char, "float", float, SWAP_NONE, 4);
     305  SET_VALUES("short",     short, "float", float, SWAP_BYTE, 4);
     306  SET_VALUES("int",         int, "float", float, SWAP_WORD, 4);
     307  SET_VALUES("int64_t", int64_t, "float", float, SWAP_DBLE, 4);
     308  SET_VALUES("float",     float, "float", float, SWAP_WORD, 4);
     309  SET_VALUES("double",   double, "float", float, SWAP_DBLE, 4);
     310
     311  SET_VALUES("char",       char, "double", double, SWAP_NONE, 8);
     312  SET_VALUES("byte",       char, "double", double, SWAP_NONE, 8);
     313  SET_VALUES("short",     short, "double", double, SWAP_BYTE, 8);
     314  SET_VALUES("int",         int, "double", double, SWAP_WORD, 8);
     315  SET_VALUES("int64_t", int64_t, "double", double, SWAP_DBLE, 8);
     316  SET_VALUES("float",     float, "double", double, SWAP_WORD, 8);
     317  SET_VALUES("double",   double, "double", double, SWAP_DBLE, 8);
     318
     319# if (0)
    232320  /** input == char **/
    233321  if (!strcmp (outtype, "char") && !strcmp (intype, "char")) {
    234322    int NbytesIn = 1;
    235323    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
    236       *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     324      if (directCopy) { *(char *)Pout = *(char *)Pin; } else {
     325        *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     326      }
    237327    }
    238328  }
    239329  if (!strcmp (outtype, "byte") && !strcmp (intype, "char")) {
     330    int NbytesIn = 1;
     331    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     332      if (directCopy) { *(char *)Pout = *(char *)Pin; } else {
     333        *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     334      }
     335    }
     336  }
     337  if (!strcmp (outtype, "short") && !strcmp (intype, "char")) {
     338    int NbytesIn = 1;
     339    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     340      if (directCopy) { *(short *)Pout = *(char *)Pin; } else {
     341        *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
     342      }
     343# ifdef BYTE_SWAP
     344      if (!nativeOrder) { SWAP_BYTE; }
     345# endif
     346    } 
     347  }
     348  if (!strcmp (outtype, "int") && !strcmp (intype, "char")) {
     349    int NbytesIn = 1;
     350    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     351      *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
     352# ifdef BYTE_SWAP
     353      if (!nativeOrder) { SWAP_WORD; }
     354# endif
     355    }
     356  }
     357  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "char")) {
     358    int NbytesIn = 1;
     359    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     360      *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
     361# ifdef BYTE_SWAP
     362      if (!nativeOrder) { SWAP_DBLE; }
     363# endif
     364    }
     365  }
     366  if (!strcmp (outtype, "float") && !strcmp (intype, "char")) {
     367    int NbytesIn = 1;
     368    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     369      *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
     370# ifdef BYTE_SWAP
     371      if (!nativeOrder) { SWAP_WORD; }
     372# endif
     373    }
     374  }
     375  if (!strcmp (outtype, "double") && !strcmp (intype, "char")) {
     376    int NbytesIn = 1;
     377    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     378      *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
     379# ifdef BYTE_SWAP
     380      if (!nativeOrder) { SWAP_DBLE; }
     381# endif
     382    }
     383  }
     384
     385  /** input == byte **/
     386  if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) {
    240387    int NbytesIn = 1;
    241388    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     
    243390    }
    244391  }
    245   if (!strcmp (outtype, "short") && !strcmp (intype, "char")) {
    246     int NbytesIn = 1;
    247     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    248       *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
    249 # ifdef BYTE_SWAP
    250       SWAP_BYTE;
    251 # endif
    252     } 
    253   }
    254   if (!strcmp (outtype, "int") && !strcmp (intype, "char")) {
    255     int NbytesIn = 1;
    256     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    257       *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
    258 # ifdef BYTE_SWAP
    259       SWAP_WORD;
    260 # endif
    261     }
    262   }
    263   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "char")) {
    264     int NbytesIn = 1;
    265     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    266       *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
    267 # ifdef BYTE_SWAP
    268       SWAP_DBLE;
    269 # endif
    270     }
    271   }
    272   if (!strcmp (outtype, "float") && !strcmp (intype, "char")) {
    273     int NbytesIn = 1;
    274     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    275       *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
    276 # ifdef BYTE_SWAP
    277       SWAP_WORD;
    278 # endif
    279     }
    280   }
    281   if (!strcmp (outtype, "double") && !strcmp (intype, "char")) {
    282     int NbytesIn = 1;
    283     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    284       *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
    285 # ifdef BYTE_SWAP
    286       SWAP_DBLE;
    287 # endif
    288     }
    289   }
    290 
    291   /** input == byte **/
    292   if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) {
     392  if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) {
    293393    int NbytesIn = 1;
    294394    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     
    296396    }
    297397  }
    298   if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) {
    299     int NbytesIn = 1;
    300     for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
    301       *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
    302     }
    303   }
    304398  if (!strcmp (outtype, "short") && !strcmp (intype, "byte")) {
    305399    int NbytesIn = 1;
     
    307401      *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
    308402# ifdef BYTE_SWAP
    309       SWAP_BYTE;
     403      if (!nativeOrder) { SWAP_BYTE; }
    310404# endif
    311405    } 
     
    316410      *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
    317411# ifdef BYTE_SWAP
    318       SWAP_WORD;
     412      if (!nativeOrder) { SWAP_WORD; }
    319413# endif
    320414    }
     
    325419      *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
    326420# ifdef BYTE_SWAP
    327       SWAP_DBLE;
     421      if (!nativeOrder) { SWAP_DBLE; }
    328422# endif
    329423    }
     
    334428      *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
    335429# ifdef BYTE_SWAP
    336       SWAP_WORD;
     430      if (!nativeOrder) { SWAP_WORD; }
    337431# endif
    338432    }
     
    343437      *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
    344438# ifdef BYTE_SWAP
    345       SWAP_DBLE;
     439      if (!nativeOrder) { SWAP_DBLE; }
    346440# endif
    347441    }
     
    366460      *(short *)Pout = (*(short *)Pin - Bzero) / Bscale;
    367461# ifdef BYTE_SWAP
    368       SWAP_BYTE;
     462      if (!nativeOrder) { SWAP_BYTE; }
    369463# endif
    370464    } 
     
    375469      *(int *)Pout = (*(short *)Pin - Bzero) / Bscale;
    376470# ifdef BYTE_SWAP
    377       SWAP_WORD;
     471      if (!nativeOrder) { SWAP_WORD; }
    378472# endif
    379473    }
     
    384478      *(int64_t *)Pout = (*(short *)Pin - Bzero) / Bscale;
    385479# ifdef BYTE_SWAP
    386       SWAP_DBLE;
     480      if (!nativeOrder) { SWAP_DBLE; }
    387481# endif
    388482    }
     
    393487      *(float *)Pout = (*(short *)Pin - Bzero) / Bscale;
    394488# ifdef BYTE_SWAP
    395       SWAP_WORD;
     489      if (!nativeOrder) { SWAP_WORD; }
    396490# endif
    397491    }
     
    402496      *(double *)Pout = (*(short *)Pin - Bzero) / Bscale;
    403497# ifdef BYTE_SWAP
    404       SWAP_DBLE;
     498      if (!nativeOrder) { SWAP_DBLE; }
    405499# endif
    406500    }
     
    425519      *(short *)Pout = (*(int *)Pin - Bzero) / Bscale;
    426520# ifdef BYTE_SWAP
    427       SWAP_BYTE;
     521      if (!nativeOrder) { SWAP_BYTE; }
    428522# endif
    429523    } 
     
    434528      *(int *)Pout = (*(int *)Pin - Bzero) / Bscale;
    435529# ifdef BYTE_SWAP
    436       SWAP_WORD;
     530      if (!nativeOrder) { SWAP_WORD; }
    437531# endif
    438532    }
     
    443537      *(int64_t *)Pout = (*(int *)Pin - Bzero) / Bscale;
    444538# ifdef BYTE_SWAP
    445       SWAP_DBLE;
     539      if (!nativeOrder) { SWAP_DBLE; }
    446540# endif
    447541    }
     
    452546      *(float *)Pout = (*(int *)Pin - Bzero) / Bscale;
    453547# ifdef BYTE_SWAP
    454       SWAP_WORD;
     548      if (!nativeOrder) { SWAP_WORD; }
    455549# endif
    456550    }
     
    461555      *(double *)Pout = (*(int *)Pin - Bzero) / Bscale;
    462556# ifdef BYTE_SWAP
    463       SWAP_DBLE;
     557      if (!nativeOrder) { SWAP_DBLE; }
    464558# endif
    465559    }
     
    484578      *(short *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    485579# ifdef BYTE_SWAP
    486       SWAP_BYTE;
     580      if (!nativeOrder) { SWAP_BYTE; }
    487581# endif
    488582    } 
     
    493587      *(int *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    494588# ifdef BYTE_SWAP
    495       SWAP_WORD;
     589      if (!nativeOrder) { SWAP_WORD; }
    496590# endif
    497591    }
     
    502596      *(int64_t *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    503597# ifdef BYTE_SWAP
    504       SWAP_DBLE;
     598      if (!nativeOrder) { SWAP_DBLE; }
    505599# endif
    506600    }
     
    511605      *(float *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    512606# ifdef BYTE_SWAP
    513       SWAP_WORD;
     607      if (!nativeOrder) { SWAP_WORD; }
    514608# endif
    515609    }
     
    520614      *(double *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    521615# ifdef BYTE_SWAP
    522       SWAP_DBLE;
     616      if (!nativeOrder) { SWAP_DBLE; }
    523617# endif
    524618    }
     
    543637      *(short *)Pout = (*(float *)Pin - Bzero) / Bscale;
    544638# ifdef BYTE_SWAP
    545       SWAP_BYTE;
     639      if (!nativeOrder) { SWAP_BYTE; }
    546640# endif
    547641    } 
     
    552646      *(int *)Pout = (*(float *)Pin - Bzero) / Bscale;
    553647# ifdef BYTE_SWAP
    554       SWAP_WORD;
     648      if (!nativeOrder) { SWAP_WORD; }
    555649# endif
    556650    }
     
    561655      *(int64_t *)Pout = (*(float *)Pin - Bzero) / Bscale;
    562656# ifdef BYTE_SWAP
    563       SWAP_DBLE;
     657      if (!nativeOrder) { SWAP_DBLE; }
    564658# endif
    565659    }
     
    570664      *(float *)Pout = (*(float *)Pin - Bzero) / Bscale;
    571665# ifdef BYTE_SWAP
    572       SWAP_WORD;
     666      if (!nativeOrder) { SWAP_WORD; }
    573667# endif
    574668    }
     
    579673      *(double *)Pout = (*(float *)Pin - Bzero) / Bscale;
    580674# ifdef BYTE_SWAP
    581       SWAP_DBLE;
     675      if (!nativeOrder) { SWAP_DBLE; }
    582676# endif
    583677    }
     
    602696      *(short *)Pout = (*(double *)Pin - Bzero) / Bscale;
    603697# ifdef BYTE_SWAP
    604       SWAP_BYTE;
     698      if (!nativeOrder) { SWAP_BYTE; }
    605699# endif
    606700    } 
     
    611705      *(int *)Pout = (*(double *)Pin - Bzero) / Bscale;
    612706# ifdef BYTE_SWAP
    613       SWAP_WORD;
     707      if (!nativeOrder) { SWAP_WORD; }
    614708# endif
    615709    }
     
    620714      *(int64_t *)Pout = (*(double *)Pin - Bzero) / Bscale;
    621715# ifdef BYTE_SWAP
    622       SWAP_DBLE;
     716      if (!nativeOrder) { SWAP_DBLE; }
    623717# endif
    624718    }
     
    629723      *(float *)Pout = (*(double *)Pin - Bzero) / Bscale;
    630724# ifdef BYTE_SWAP
    631       SWAP_WORD;
     725      if (!nativeOrder) { SWAP_WORD; }
    632726# endif
    633727    }
     
    638732      *(double *)Pout = (*(double *)Pin - Bzero) / Bscale;
    639733# ifdef BYTE_SWAP
    640       SWAP_DBLE;
    641 # endif
    642     }
    643   }
     734      if (!nativeOrder) { SWAP_DBLE; }
     735# endif
     736    }
     737  }
     738# endif
    644739
    645740  /* check array space */
     
    683778int gfits_set_table_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) {
    684779
    685   off_t Nx, Ny, nbytes;
     780  off_t Nx, Ny;
    686781  int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
    687782  char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16];
     
    713808  if (Ny == 0) {
    714809    Ny = Nrow;
    715     header[0].Naxis[1] = Ny;
    716     gfits_modify (header, "NAXIS2", OFF_T_FMT, 1,  Ny);
    717 
    718     nbytes = gfits_data_size (header);
    719     REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
    720     bzero (table[0].buffer, nbytes);
    721     table[0].datasize = nbytes;
     810    gfits_set_table_rows (header, table, Ny);
    722811  }
    723812  if (Ny != Nrow) return (FALSE);
  • trunk/Ohana/src/libfits/table/F_table_format.c

    r37039 r38441  
    88int gfits_bintable_format (char *format, char *type, int *Nval, int *Nbytes) {
    99
    10   char *Lchar, *Fchar;
    11   int Nv;
    12 
    13   if (format == (char *) NULL) return (FALSE);
    14   if (format[0] == 0) return (FALSE);
    15   Lchar = &format[strlen(format) - 1];
    16 
    17   Nv = strtol (format, &Fchar, 10);
    18   if (Fchar != Lchar) return (FALSE);
     10  char *Fchar;
     11
     12  if (format == (char *) NULL) return (FALSE); // format must be defined
     13  if (format[0] == 0) return (FALSE);          // format must not be empty string
     14  // char *Lchar = &format[strlen(format) - 1];        // last-char pointer
     15
     16  int Nv = strtol (format, &Fchar, 10);            // Fchar points at end of leading number
     17  // if (Fchar != Lchar) return (FALSE);       -- this test is invalid for eg 1PB(nn)
    1918  if ((Nv == 0) && (Fchar == format)) Nv = 1;
    2019
     
    5150    { *Nbytes = 8;  strcpy (type, "double"); *Nval = Nv;               }
    5251    break;
    53   case  'P':
    54     { *Nbytes = 8;  strcpy (type, "var");    *Nval = 2*Nv;             }
    55     break;
    5652  case  'C':
    5753    { *Nbytes = 8;  strcpy (type, "float");  *Nval = 2*Nv;             }
     
    5955  case  'M':
    6056    { *Nbytes = 16; strcpy (type, "double"); *Nval = 2*Nv;             }
     57    break;
     58  case  'P':
     59    { *Nbytes = 4;  strcpy (type, "var");    *Nval = 2*Nv;             }
     60    break;
     61  case  'Q':
     62    { *Nbytes = 8;  strcpy (type, "var64"); *Nval = 2*Nv;             }
    6163    break;
    6264  default:
     
    8082   C - complex float
    8183   M - complex double
    82    P - var length array descrpt (64 bit)
     84   P - var length array descrpt (32 bit pointer)
     85   Q - var length array descrpt (64 bit pointer)
    8386   
    8487   all can be preceeded by integer N which specified number
    8588   of entries in array
    86    
    8789*/
    8890
  • trunk/Ohana/src/libfits/table/F_table_row.c

    r28241 r38441  
    2828  REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
    2929  table[0].datasize = nbytes;
     30  table[0].heap_start = gfits_heap_start (header);
    3031 
    3132  memcpy (&table[0].buffer[Nstart], data, Nbytes*Nrow);
     
    6768
    6869  table[0].datasize = gfits_data_size (table[0].header);
     70  // table[0].heap_start = gfits_heap_start (header);
    6971  table[0].pad      = table[0].datasize - Nx*Ny;
    7072
     
    102104  REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
    103105  table[0].datasize = nbytes;
     106  table[0].heap_start = gfits_heap_start (header);
    104107  return (TRUE);
    105108}
  • trunk/Ohana/src/libfits/table/F_table_varlength.c

    r28241 r38441  
    22# include <gfitsio.h>
    33
     4// fills the column definition structure for a specific column based on a given table.
    45int gfits_varlength_column_define (FTable *ftable, VarLengthColumn *def, int column) {
    56
     
    1415  snprintf (field, 80, "TFORM%d", column);
    1516  if (!gfits_scan (ftable->header, field, "%s", 1, format)) return (FALSE);
     17
     18  def->column = column;
    1619
    1720  // find and remove the max field length element
     
    4851  if (*p1 == 'I') { def->nbytes = 2;  def->format = *p1; }
    4952  if (*p1 == 'J') { def->nbytes = 4;  def->format = *p1; }
     53  if (*p1 == 'K') { def->nbytes = 8;  def->format = *p1; }
    5054  if (*p1 == 'E') { def->nbytes = 4;  def->format = *p1; }
    5155  if (*p1 == 'D') { def->nbytes = 8;  def->format = *p1; }
     
    5458  if (!def->nbytes) { return (FALSE); }
    5559 
    56   /* scan columns to find column offset */
    57   def->Nstart = 0;
     60  /* scan columns to find column offset for metadata column*/
     61  def->offset = 0;
    5862  for (i = 1; i < column; i++) {
    5963    sprintf (field, "TFORM%d", i);
    6064    gfits_scan (ftable->header, field, "%s", 1, format);
    6165    gfits_bintable_format (format, tmpline, &Nv, &Nb);
    62     def->Nstart += Nv*Nb;
     66    def->offset += Nv*Nb;
    6367  }
    6468
    6569  // heap_start must be long long so file may be very large
    66   if (!gfits_scan (ftable->header, "THEAP", OFF_T_FMT, 1,  &def->heap_start)) {
    67     def->heap_start = ftable->header->Naxis[0]*ftable->header->Naxis[1];
    68   }
    69 
     70  // confirm that ftable->heap_start is correctly set?
     71
     72  return TRUE;
     73}
     74
     75# define SWAP_WORD \
     76  tmp = pchar[0]; pchar[0] = pchar[3]; pchar[3] = tmp; \
     77  tmp = pchar[1]; pchar[1] = pchar[2]; pchar[2] = tmp;
     78
     79# define SWAP_DBLE \
     80  tmp = pchar[0]; pchar[0] = pchar[7]; pchar[7] = tmp; \
     81  tmp = pchar[1]; pchar[1] = pchar[6]; pchar[6] = tmp; \
     82  tmp = pchar[2]; pchar[2] = pchar[5]; pchar[5] = tmp; \
     83  tmp = pchar[3]; pchar[3] = pchar[4]; pchar[4] = tmp;
     84
     85int gfits_byteswap_varlength_column (FTable *ftable, int column) {
     86
     87# ifdef BYTE_SWAP 
     88  VarLengthColumn zdef;
     89  if (!gfits_varlength_column_define (ftable, &zdef, column)) return FALSE;
     90
     91  char *bufstart = &ftable->buffer[zdef.offset];
     92
     93  int i;
     94  char *pchar, tmp;
     95
     96  off_t Nx = ftable->header->Naxis[0];
     97
     98  for (i = 0; i < ftable->header->Naxis[1]; i++) {
     99    if (zdef.mode == 'P') {
     100      pchar = &bufstart[i*Nx];
     101      SWAP_WORD;
     102      pchar = &bufstart[i*Nx + 4];
     103      SWAP_WORD;
     104    }     
     105    if (zdef.mode == 'Q') {
     106      char *pchar, tmp;
     107      pchar = &bufstart[i*Nx];
     108      SWAP_DBLE;
     109      pchar = &bufstart[i*Nx + 8];
     110      SWAP_DBLE;
     111    }
     112  }
     113# endif
    70114  return TRUE;
    71115}
     
    75119void *gfits_varlength_column_pointer (FTable *ftable, VarLengthColumn *column, off_t row, off_t *length) {
    76120
    77   void *result;
    78   off_t offset, Nx;
    79 
    80121  if ((column->mode != 'P') && (column->mode != 'Q')) abort();
    81122
    82123  // find the values for the specified row
    83124  // the values in the main table for this row and varlength column:
    84   Nx = ftable->header->Naxis[0];
    85 
    86 # define SWAP_WORD \
    87   tmp = pchar[0]; pchar[0] = pchar[3]; pchar[3] = tmp; \
    88   tmp = pchar[1]; pchar[1] = pchar[2]; pchar[2] = tmp;
    89 
    90 # ifdef BYTE_SWAP
    91   char *pchar, tmp;
    92   pchar = &ftable->buffer[row*Nx + column->Nstart];
    93   SWAP_WORD;
    94   pchar = &ftable->buffer[row*Nx + column->Nstart + 4];
    95   SWAP_WORD;
    96 # endif
     125  off_t Nx = ftable->header->Naxis[0];
     126  off_t offset = 0;
    97127
    98128  if (column->mode == 'P') {
    99129    int *ptr;
    100     ptr = (int *) &ftable->buffer[row*Nx + column->Nstart];
     130    ptr = (int *) &ftable->buffer[row*Nx + column->offset];
    101131    *length = ptr[0];
    102132    offset = ptr[1];
    103   } else if (column->mode == 'Q') {
     133  }
     134  if (column->mode == 'Q') {
    104135    off_t *ptr;
    105     ptr = (off_t *) &ftable->buffer[row*Nx + column->Nstart];
     136    ptr = (off_t *) &ftable->buffer[row*Nx + column->offset];
    106137    *length = ptr[0];
    107138    offset = ptr[1];
    108   } else {
    109         // this was actually trapped above
    110         abort();
    111   }
    112 
    113   result = (void *) (ftable->buffer + column->heap_start + offset);
     139  }
     140
     141  // fprintf (stderr, "length: %d, offset: %d\n", (int) *length, (int) offset);
     142
     143  void *result = (void *) (ftable->buffer + ftable->heap_start + offset);
    114144  return result;
    115145}
     146
     147// to generate a compressed image or a compressed table, we need to be able to add data
     148// for varlength columns to the heap.  To start, assume we have defined the cartesian
     149// portion of the table correctly, and are only extending the heap.
     150
     151int gfits_varlength_column_add_data (FTable *table, char *data, off_t Ndata, int row, VarLengthColumn *column) {
     152
     153  // find the current starting point for new data (end of current buffer main data + current heap
     154  off_t heap_offset = gfits_data_min_size (table->header);
     155
     156  // extend the buffer size to add the new data
     157  off_t Nbytes = gfits_data_pad_size (heap_offset + Ndata);
     158  REALLOCATE (table->buffer, char, Nbytes);
     159
     160  char *heap_ptr = table->buffer + heap_offset;
     161
     162  // add the new data to the table buffer
     163  memcpy (heap_ptr, data, Ndata);
     164
     165  // *** now we add the data description to the table ***
     166
     167  if ((column->mode != 'P') && (column->mode != 'Q')) abort();
     168
     169  // find the cell for the specified row & column
     170  // the values in the main table for this row and varlength column:
     171  int Nx = table->header->Naxis[0];
     172
     173  // set the cell values
     174  if (column->mode == 'P') {
     175    int *ptr;
     176    ptr = (int *) &table->buffer[row*Nx + column->offset];
     177    ptr[0] = Ndata;
     178    ptr[1] = heap_offset - table->heap_start;
     179  }
     180  if (column->mode == 'Q') {
     181    off_t *ptr;
     182    ptr = (off_t *) &table->buffer[row*Nx + column->offset];
     183    ptr[0] = Ndata;
     184    ptr[1] = heap_offset - table->heap_start;
     185  }
     186
     187  // update maxlen
     188  // fprintf (stderr, "row: %d, Ndata: %d, maxlen: %d\n", (int) row, (int) Ndata, (int) column->maxlen);
     189  column->maxlen = MAX (column->maxlen, Ndata);
     190
     191  off_t pcount;
     192  gfits_scan (table->header, "PCOUNT", OFF_T_FMT, 1, &pcount);
     193
     194  pcount += Ndata;
     195  gfits_modify (table->header, "PCOUNT", OFF_T_FMT, 1, pcount);
     196  table->header->pcount = pcount;
     197  table->datasize = gfits_data_size (table->header);
     198  myAssert (table->datasize == Nbytes, "inconsistent header and data");
     199
     200  return TRUE;
     201}
     202
     203// update the header TFORM value for this entry
     204int gfits_varlength_column_finish (FTable *ftable, VarLengthColumn *def) {
     205
     206  char field[81];
     207  char format[81];
     208
     209  // grab the value of TFORMn for this column
     210  snprintf (field, 80, "TFORM%d", def->column);
     211  if (!gfits_scan (ftable->header, field, "%s", 1, format)) return FALSE;
     212
     213  // find and update the max field length element
     214  char *p1 = strchr (format, '(');
     215  if (!p1) return (FALSE); // not a valid varlength column -- missing (e_max)
     216 
     217  p1 ++;
     218  *p1 = 0;
     219
     220  snprintf (p1, 80 - (p1 - format), "%d)", def->maxlen);
     221  if (!gfits_modify (ftable->header, field, "%s", 1, format)) return FALSE;
     222
     223  return TRUE;
     224}
  • trunk/Ohana/src/libfits/table/F_write_T.c

    r37807 r38441  
    1414 
    1515  status = fseeko (f, 0LL, SEEK_END);  /* write table to end of file! */
     16  if (status) { perror ("fseeko: "); return (FALSE);  }
    1617  status = gfits_fwrite_table (f, table);
    1718
     
    2627 
    2728  Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].datasize, f);
    28  
    29   if (Nbytes != table[0].datasize) return (FALSE);
     29  if (Nbytes != table[0].datasize) { perror ("fwrite: "); return (FALSE);  }
    3030  return (TRUE);
    3131}       
     
    4545  /* file pointer is at beginning of desired table data */
    4646  start = ftello (f);
     47  if (start < 0) { perror ("ftello: "); return FALSE; }
    4748 
    4849  for (i = 0; i < Nrow; i++) {
     
    5051    fseeko (f, offset, SEEK_SET);
    5152    Nbytes = fwrite (table[0].buffer[i], sizeof (char), Nx, f);
    52     if (Nbytes != Nx) { return (FALSE); }
     53    if (Nbytes != Nx) { perror ("fwrite: "); return (FALSE); }
    5354  }
    5455 
     
    5859
    5960  offset = start + Nx*Ny;
    60   fseeko (f, offset, SEEK_SET);
     61  int status = fseeko (f, offset, SEEK_SET);
     62  if (status) { perror ("fseeko: "); return FALSE; }
     63
    6164  Nbytes = fwrite (pad, sizeof (char), Npad, f);
    62   if (Nbytes != Npad) { return (FALSE); }
     65  if (Nbytes != Npad) { perror ("fwrite: "); return (FALSE); }
    6366  free (pad);
    6467
     
    8487  Nx = ftable[0].header[0].Naxis[0]; // final output table size on disk
    8588  ftable[0].datasize = gfits_data_size (ftable[0].header);
     89  ftable[0].heap_start = gfits_heap_start (ftable[0].header);
    8690
    8791  Nskip = start * Nx;
     
    96100  // cursor must be at start of the table (after table header)
    97101  if (fseeko (f, Nskip, SEEK_CUR)) {
     102    perror ("fseeko: ");
    98103    fprintf (stderr, "can't seek table start\n");
    99104    return (FALSE);
     
    101106
    102107  Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
    103   if (Nwrite != Nbytes) {
    104     return (FALSE);
    105   }
     108  if (Nwrite != Nbytes) { perror ("fwrite: "); return (FALSE); }
    106109
    107110  if (Ntotal >= Ndisk) {
     
    112115    free (pad);
    113116
    114     if (Nbytes != Npad) return (FALSE);
     117    if (Nbytes != Npad) { perror ("fwrite: "); return (FALSE);  }
    115118  }
    116119
  • trunk/Ohana/src/libfits/table/F_write_TH.c

    r27435 r38441  
    1414 
    1515  status = fseeko (f, 0LL, SEEK_END);  /* write header to end of file! */
     16  if (status) { perror ("fseeko: "); return (FALSE);  }
    1617  status = gfits_fwrite_Theader (f, header);
    1718
     
    2627 
    2728  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
     29  if (Nbytes != header[0].datasize) { perror ("fwrite: "); return (FALSE);  }
    2830
    29   if (Nbytes != header[0].datasize) return (FALSE);
    3031  return (TRUE);
    3132}       
  • trunk/Ohana/src/libohana/Makefile

    r37807 r38441  
    11default: install
    22help:
    3         @echo "make options: install libohana clean dist test typetest"
     3        @echo "make options: install libohana clean dist test test.clean"
    44
    55include ../../Makefile.System
     
    1010MAN     =       $(HOME)/doc
    1111INC     =       $(HOME)/include
    12 TESTDIR =       $(HOME)/test
     12TESTDIR =       $(HOME)/test
     13TESTBIN =       $(HOME)/test
    1314include ../../Makefile.Common
    1415
     
    1718FULL_CPPFLAGS = $(BASE_CPPFLAGS)
    1819FULL_LDFLAGS  = $(BASE_LDFLAGS)
    19 TFLAGS        = $(FULL_CFLAGS) $(FULL_CPPFLAGS) $(FULL_LDFLAGS) -lohana -ltap_ohana
    2020
    21 install: $(DESTLIB)/libohana.a $(DESTLIB)/libohana.$(DLLTYPE) typetest
     21TEST_CFLAGS   = $(BASE_CFLAGS)
     22TEST_CPPFLAGS = $(BASE_CPPFLAGS)
     23TEST_LDFLAGS  = $(BASE_LDFLAGS) -lohana -ltap_ohana
     24
     25install: $(DESTLIB)/libohana.a $(DESTLIB)/libohana.$(DLLTYPE)
    2226libohana: $(LIB)/libohana.$(ARCH).a $(LIB)/libohana.$(ARCH).$(DLLTYPE)
    2327
     
    5155# $(SRC)/gsl_utils.$(ARCH).o     \
    5256
    53 TYPETEST = \
    54 $(TESTDIR)/typetest.$(ARCH)
    55 
    56 $(TYPETEST) : $(LIB)/libohana.$(ARCH).a
    57 
    58 typetest: $(TYPETEST)
    59         for i in $(TYPETEST); do $$i || exit 1; done
    60 
    61 TEST = \
    62 $(TESTDIR)/memtest.$(ARCH)
    63 # $(TESTDIR)/string.$(ARCH)
    64 
    65 testcode: install $(TEST)
    66 test:
    67         $(MAKE) testcode
    68         for i in $(TEST); do $$i; done
    69 
    70 quicktest:
    71         for i in $(TEST); do $$i; done
    72 
    7357$(OBJS): $(INCS)
    7458
     
    7963$(DESTLIB)/libohana.$(DLLTYPE): $(LIB)/libohana.$(ARCH).$(DLLTYPE)
    8064
    81 $(TESTDIR)/%.$(ARCH) : $(TESTDIR)/%.c
    82         $(CC) $^ -o $@ $(TFLAGS)
    83 
    84 .PHONY: test
    85 
     65TESTPROG = memtest typetest string
     66$(TESTPROG) : % : $(TESTBIN)/% $(OBJS)
     67test: $(TESTPROG)
     68        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS); done
     69test.verbose: $(TESTPROG)
     70        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 |& $(TESTHARNESS) -v; done
  • trunk/Ohana/src/libohana/include/ohana.h

    r37807 r38441  
    286286char   *strcreate              PROTO((char *string));
    287287char   *strncreate             PROTO((char *string, int n));
     288int     strextend              PROTO((char **input, char *format,...)) OHANA_FORMAT(printf, 2, 3);
    288289int     scan_line              PROTO((FILE *f, char *line));
    289290int     scan_line_maxlen       PROTO((FILE *f, char *line, int maxlen));
     
    393394
    394395char   *memstr                 PROTO((char *m1, char *m2, int n));
    395 int     write_fmt              PROTO((int fd, char *format, ...));
     396int     write_fmt              PROTO((int fd, char *format, ...)) OHANA_FORMAT(printf, 2, 3);
    396397
    397398char   **isolate_elements      PROTO((int argc, char **argv, int *nstack));
     
    403404
    404405// gprint gets a stub implementation in libohana. opihi implements the real one.
    405 int    gprint (gpDest dest, char *format, ...);
     406int    gprint                  PROTO((gpDest dest, char *format, ...) OHANA_FORMAT(printf, 2, 3));
    406407
    407408// rconnect is used to run remote programs with a pipe for communication
  • trunk/Ohana/src/libohana/include/ohana_allocate.h

    r33646 r38441  
    2626void  ohana_free (const char *file, int line, const char *func, void *in);
    2727void  ohana_memdump_func (int mode);
    28 void  ohana_memcheck_func (int mode);
     28int   ohana_memcheck_func (int mode);
    2929void  real_free (void *in);
    3030
     
    5656# else  /* below: not OHANA_MEMORY */
    5757
    58 # define ohana_memcheck(X) /* NOP */
     58# define ohana_memcheck(X) TRUE
    5959# define ohana_memdump(X) /* NOP */
    6060void  real_free (void *in);
  • trunk/Ohana/src/libohana/src/ohana_allocate.c

    r37807 r38441  
    207207}
    208208
    209 void ohana_memcheck_func (int allmemory) {
     209int ohana_memcheck_func (int allmemory) {
    210210
    211211  if (!lastBlock) {
    212212    fprintf (stderr, "no memory allocated\n");
    213     return;
     213    return TRUE;
    214214  }
    215215
     
    253253  fprintf (stderr, "%zd memory blocks allocated (%zd bytes total), %zd good, %zd bad\n", Ntotal, Nbytes, Ngood, Nbad);
    254254
    255   return;
     255  if (Nbad) return FALSE;
     256  return TRUE;
    256257}
    257258
  • trunk/Ohana/src/libohana/src/string.c

    r37033 r38441  
    6565}
    6666
     67// extend input as needed to add the formatted pieces
     68// if input is NULL, allocate a new line
     69// the result of the format must be < 1024 bytes
     70int strextend (char **input, char *format,...) {
     71
     72  int Nchar;
     73  char tmpextra[1024], tmpline, *output;
     74  va_list argp;
     75
     76  va_start (argp, format);
     77  Nchar = vsnprintf (tmpextra, 1024, format, argp);
     78  if (Nchar > 1024 - 1) return FALSE;
     79
     80  if (*input) {
     81    Nchar = snprintf (&tmpline, 0, "%s %s", *input, tmpextra);
     82    ALLOCATE (output, char, Nchar + 1);
     83    snprintf (output, Nchar + 1, "%s %s", *input, tmpextra);
     84    free (*input);
     85  } else {
     86    Nchar = strlen(tmpextra) + 1;
     87    ALLOCATE (output, char, Nchar);
     88    strcpy (output, tmpextra);
     89  }
     90  *input = output;
     91
     92  return TRUE;
     93}
     94
    6795// replace a single entry of 'match' in the string with 'with'
    6896// (quick-and-dirty regex for a common case...)
  • trunk/Ohana/src/libohana/test

    • Property svn:ignore
      •  

        old new  
        44*.darwin_x86
        55*.dSYM
         6memtest
         7string
         8typetest
  • trunk/Ohana/src/libohana/test/string.c

    r10313 r38441  
    44int main (void) {
    55
    6   plan_tests (16);
     6  plan_tests (20);
    77
    88  diag ("libohana string.c tests");
     
    6767    skip_end();
    6868  }
     69
     70  /*** strextend ***/
     71  {
     72    int status;
     73    char *string = NULL;
     74
     75    status = strextend(&string, "hello %s", "there");
     76    ok (status, "strextend for NULL input");
     77    ok (!strcmp(string, "hello there"), "strextend format");
     78   
     79    status = strextend(&string, "more words %d", 2);
     80    ok (status, "strextend for non-NULL input");
     81    ok (!strcmp(string, "hello there more words 2"), "strextend format");
     82  }
    6983  return exit_status();
    7084}
  • trunk/Ohana/src/libohana/test/typetest.c

    r31663 r38441  
    11# include "ohana.h"
     2# include "tap_ohana.h"
    23
    34enum
    4 {
     5  {
    56    OHANA_LITTLE_ENDIAN = 0x03020100ul,
    67    OHANA_BIG_ENDIAN    = 0x00010203ul,
    7 };
     8  };
    89
    910static const union {
    10     unsigned char bytes[4];
    11     int value;
     11  unsigned char bytes[4];
     12  int value;
    1213} ohana_host_order = { { 0, 1, 2, 3 } };
    1314
     
    1516
    1617// we need to verify some type-related issues:
    17 int main (int argc, char **argv) {
     18int main (void) {
    1819
    19     int status;
     20  plan_tests (4);
    2021
    21     status = 0;
     22  diag ("libohana typetest.c tests");
    2223
    23     // 1) have we defined BYTE_SWAP correctly?
     24  int status = 0;
     25
     26  // 1) have we defined BYTE_SWAP correctly?
    2427
    2528# ifdef BYTE_SWAP
    26     if (OHANA_HOST_ORDER == OHANA_BIG_ENDIAN) {
    27         fprintf (stderr, "ERROR: BYTE_SWAP is defined on a big endian machine\n");
    28         fprintf (stderr, "(see libohana/include/ohana.h)\n");
    29         status = 1;
    30     } else {
    31         fprintf (stderr, "BYTE_SWAP is small endian\n");
    32     }   
     29  ok (OHANA_HOST_ORDER == OHANA_LITTLE_ENDIAN, "BYTE_SWAP defined on small endian hardware (see libohana/include/ohana.h)");
    3330# else
    34     if (OHANA_HOST_ORDER == OHANA_BIG_ENDIAN) {
    35         fprintf (stderr, "NOT_BYTE_SWAP is big endian\n");
    36     } else {
    37         fprintf (stderr, "ERROR: BYTE_SWAP not defined on a small endian machine\n");
    38         fprintf (stderr, "(see libohana/include/ohana.h)\n");
    39         status = 1;
    40     }   
     31  ok (OHANA_HOST_ORDER == OHANA_BIG_ENDIAN, "BYTE_SWAP NOT defined on big endian hardware (see libohana/include/ohana.h)");
    4132# endif
    4233
    43     // 2) have we defined NAN correctly?
    44     {
    45         float fvalue;
    46         double dvalue;
     34  // 2) have we defined NAN correctly?
     35  {
     36    float fvalue;
     37    double dvalue;
    4738   
    48         fvalue = NAN;
    49         dvalue = NAN;
     39    fvalue = NAN;
     40    dvalue = NAN;
    5041
    51         if (isfinite(fvalue)) {
    52             fprintf (stderr, "ERROR: NAN definition fails for float\n");
    53             fprintf (stderr, "fvalue: %e\n", fvalue);
    54             status = 1;
    55         }
    56         if (isfinite(dvalue)) {
    57             fprintf (stderr, "ERROR: NAN definition fails for double\n");
    58             fprintf (stderr, "dvalue: %e\n", dvalue);
    59             status = 1;
    60         }
    61 
    62         fprintf (stderr, "fvalue: %e (isfinite: %d)\n", fvalue, isfinite(fvalue));
    63         fprintf (stderr, "dvalue: %e (isfinite: %d)\n", dvalue, isfinite(dvalue));
     42    ok (isnan(fvalue), "float  NAN correctly defined");
     43    ok (isnan(dvalue), "double NAN correctly defined");
    6444
    6545# ifdef __STDC_VERSION__
    66         fprintf (stderr, "STDC_VERSION: %ld\n", __STDC_VERSION__);
     46    diag ("STDC_VERSION: %ld\n", __STDC_VERSION__);
    6747# else
    68         fprintf (stderr, "STDC_VERSION is not set\n");
     48    diag ("STDC_VERSION is not set");
    6949# endif
    70     }
     50  }
    7151
    72     // 3) have we defined OFF_T_FMT correctly?
    73     off_t big_value;
     52  // 3) have we defined OFF_T_FMT correctly?  this test should actually raise a compile-time error
     53  off_t big_value = 10;
    7454
    75     big_value = 10;
    76     fprintf (stderr, "this is a big int: "OFF_T_FMT" n'est pas?\n", big_value);
     55  char line[80];
     56  status = snprintf (line, 80, "this is a big int: "OFF_T_FMT" n'est pas?", big_value);
     57  //                            1234567890123456789         0123456789012
     58  ok (status == 32, "correctly formatted an off_t int with %d chars", status);
    7759
    78     // we could move the % out of the FMT and allow constructions like this:
    79     // # define OFF_T_FMT "jd"
    80     // fprintf (stderr, "this is a big int: %06"OFF_T_FMT_ALT" n'est pas?\n", big_value);
    81     // still kind of ugly...
     60  // we could move the % out of the FMT and allow constructions like this:
     61  // # define OFF_T_FMT "jd"
     62  // fprintf (stderr, "this is a big int: %06"OFF_T_FMT_ALT" n'est pas?\n", big_value);
     63  // still kind of ugly...
    8264
    83     exit (status);
     65  fprintf (stderr, "max float:  %e\n", FLT_MAX);
     66  fprintf (stderr, "max double: %e\n", DBL_MAX);
     67  fprintf (stderr, "min float:  %e\n", FLT_MIN);
     68  fprintf (stderr, "min double: %e\n", DBL_MIN);
     69
     70  return exit_status();
    8471}
  • trunk/Ohana/src/markrock/src/markrock.c

    r25757 r38441  
    3838  catalog.filename = argv[1];
    3939  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    40   catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     40  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4141
    4242  // an error exit status here is a significant error
     
    4545    exit (2);
    4646  }
    47   if (catalog.Naves_disk) {
     47  if (catalog.Naverage_disk) {
    4848    dvo_catalog_unlock (&catalog);
    4949    dvo_catalog_free (&catalog);
  • trunk/Ohana/src/markstar/src/find_images.c

    r29001 r38441  
    2525  }
    2626
    27   timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
     27  timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].scaledValue, &db[0].nativeOrder);
    2828  if (!timage) {
    2929    fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/markstar/src/markstar.c

    r15743 r38441  
    3737
    3838  set_db (&db);
     39  gfits_db_init (&db);
    3940  dvo_image_lock (&db, ImageCat, 3600.0, LCK_XCLD);
    4041
    4142  catalog.filename = argv[1];
    4243  catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    43   catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     44  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4445
    4546  // an error exit status here is a significant error
     
    4849    exit (2);
    4950  }
    50   if (!catalog.Naves_disk) {
     51  if (!catalog.Naverage_disk) {
    5152    dvo_catalog_unlock (&catalog);
    5253    dvo_catalog_free (&catalog);
  • trunk/Ohana/src/mosastro/src/getptolemy.c

    r25757 r38441  
    2626    // set the parameters which guide catalog open/load/create
    2727    catalog.filename  = skylist[0].filename[i];
    28     catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     28    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
    2929    catalog.Nsecfilt  = 0;
    3030
     
    3636    dvo_catalog_unlock (&catalog);
    3737
    38     // Naves_disk == 0 implies an empty catalog file
     38    // Naverage_disk == 0 implies an empty catalog file
    3939    // for only_match, skip empty catalogs
    40     if (!catalog.Naves_disk) {
     40    if (!catalog.Naverage_disk) {
    4141      dvo_catalog_free (&catalog);
    4242      continue;
  • trunk/Ohana/src/mosastro/src/rfits.c

    r29001 r38441  
    3131
    3232  off_t Nstars;
    33   stars = gfits_table_get_SMPData (&table, &Nstars, NULL);
     33  stars = gfits_table_get_SMPData (&table, &Nstars, NULL, NULL);
    3434  if (!stars) {
    3535    fprintf (stderr, "ERROR: failed to read stars\n");
  • trunk/Ohana/src/mosastro/src/wfits.c

    r27435 r38441  
    1919   
    2020  table.header = &theader;
    21   gfits_table_set_SMPData (&table, stars, Nstars);
     21  gfits_table_set_SMPData (&table, stars, Nstars, TRUE);
    2222
    2323  gfits_write_header  (filename, header);
  • trunk/Ohana/src/opihi/cmd.data

  • trunk/Ohana/src/opihi/cmd.data/cast.c

    r36489 r38441  
    1717  // out type
    1818  char outType = OPIHI_NOTYPE;
    19   if (!strcasecmp(argv[5], "int")) outType = OPIHI_INT;
    20   if (!strcasecmp(argv[5], "float")) outType = OPIHI_FLT;
     19  if (!strcasecmp(argv[5], "int"))    outType = OPIHI_INT;
     20  if (!strcasecmp(argv[5], "float"))  outType = OPIHI_FLT;
     21  if (!strcasecmp(argv[5], "single")) outType = OPIHI_FLT;
     22  if (!strcasecmp(argv[5], "int64"))  outType = OPIHI_FLT;
    2123  if (outType == OPIHI_NOTYPE) goto usage;
     24
     25  int ForceSingle = FALSE;
     26  if (!strcasecmp(argv[5], "single")) ForceSingle = TRUE;
     27
     28  int ForceI64 = FALSE;
     29  if (!strcasecmp(argv[5], "int64")) ForceI64 = TRUE;
    2230
    2331  if ((ovec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto error;
     
    3240    opihi_flt *vo = ovec[0].elements.Flt;
    3341    for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) {
    34       *vo = *vi;
     42      if (ForceSingle) {
     43        float tmp = *vi;
     44        *vo = tmp;
     45      } else if (ForceI64) {
     46        int64_t tmp = *vi;
     47        *vo = tmp;
     48      } else {
     49        *vo = *vi;
     50      }
    3551    }
    3652    return (TRUE);
     
    4864    opihi_flt *vo = ovec[0].elements.Flt;
    4965    for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) {
    50       *vo = *vi;
     66      if (ForceSingle) {
     67        float tmp = *vi;
     68        *vo = tmp;
     69      } else {
     70        *vo = *vi;
     71      }
    5172    }
    5273    return (TRUE);
     
    6687
    6788usage:
    68   gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float)\n");
     89  gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float/single)\n");
     90  gprint (GP_ERR, "  note: (single) forces vector to have single precision\n");
    6991  return (FALSE);
    7092}
  • trunk/Ohana/src/opihi/cmd.data/rd.c

    r38255 r38441  
    99  Buffer *buf;
    1010
     11  int VERBOSE = FALSE;
     12  if ((N = get_argument (argc, argv, "-v"))) {
     13    remove_argument (N, &argc, argv);
     14    VERBOSE = TRUE;
     15  }
     16
    1117  int JustHead = FALSE;
    1218  if ((N = get_argument (argc, argv, "-head"))) {
     
    9197      return (FALSE);
    9298    }
    93     if (gfits_extension_is_compressed (&buf[0].header)) {
     99    if (gfits_extension_is_compressed_image (&buf[0].header)) {
    94100        IsCompressed = TRUE;
    95101    }
     
    124130      Nword = 1;
    125131      IsCompressed = FALSE;
    126       if (gfits_extension_is_compressed (&buf[0].header)) {
     132      if (gfits_extension_is_compressed_image (&buf[0].header)) {
    127133        if (!strcmp (CCDKeyword, "EXTNAME")) Nword = 1;
    128134        IsCompressed = TRUE;
     
    198204    ftable.header[0].buffer = NULL;
    199205    gfits_copy_header (&buf[0].header, ftable.header);
    200     status = gfits_fread_ftable_data (f, &ftable, FALSE);  // this just reads the bytes (not even a SWAP)
    201     status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable);
     206
     207    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { gprint (GP_ERR, "problem reading compressed image table data\n"); fclose (f); return FALSE; }
     208    if (!gfits_byteswap_varlength_column (&ftable, 1)) { gprint (GP_ERR, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
     209    if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { gprint (GP_ERR, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }
     210
    202211    // uncompressing the image leaves the format as an extension
    203212    gfits_extended_to_primary (&buf[0].header, TRUE, "Standard FITS");
    204213    gfits_free_table (&ftable);
     214
     215    status = TRUE;
    205216    // XXX this currently does not work for a cube (we get a cube back, not a specific plane)
    206217  } else {
     
    239250  buf[0].unsign = buf[0].header.unsign;
    240251
    241   gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n",
    242            buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
     252  if (VERBOSE) gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
    243253
    244254  blank = 0xffff;
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r38062 r38441  
    11# include "data.h"
     2int dump_raw_table (FTable *table, char *message);
     3int dump_cmp_table (FTable *table, char *message);
    24
    35FILE *f = (FILE *) NULL;
     
    412414  table.header = &header;
    413415
    414   /* load appropriate extension (if extname is a number, use count) */
     416  /**** find the appropriate extension and read header (if extname is a number, use count) ****/
    415417  if (Nextend > -1) {
    416418    // first extension is PHU, cannot be a table.
     
    429431    }
    430432    if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend);
    431 
    432     if (getSizes) {
    433       read_table_sizes (&header);
    434       if (CCDKeyword != NULL) free (CCDKeyword);
    435       gfits_free_header (&header);
    436       return TRUE;
    437     }
    438 
    439     if (Nrows == -1) {
    440       Nrows = header.Naxis[1] - start;
    441     }
    442     if (start < 0) ESCAPE ("invalid range: start < 0\n");
    443     if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
    444     if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
    445 
    446     // just a warning:
    447     if (start + Nrows > header.Naxis[1]) {
    448       if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start);
    449     }
    450 
    451     // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
    452     // Ny = 100, start = 10, Nrows = 90
    453 
    454     if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    455433  } else {
    456434    if (CCDKeyword == NULL) {
     
    460438      CCDKeyword = strcreate ("EXTNAME");
    461439    }
    462 
    463440    while (1) {
    464441      if (!gfits_load_header (f, &header)) {
     
    469446        return (TRUE); 
    470447      }
    471 
    472448      Nbytes = gfits_data_size (&header);
    473449
     
    482458        continue;
    483459      }
    484 
    485       if (getSizes) {
    486         read_table_sizes (&header);
    487         if (CCDKeyword != NULL) free (CCDKeyword);
    488         gfits_free_header (&header);
    489         return TRUE;
    490       }
    491 
    492       if (Nrows == -1) {
    493         Nrows = header.Naxis[1] - start;
    494       }
    495       if (start < 0) ESCAPE ("invalid range: start < 0\n");
    496       if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
    497       if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
    498 
    499       // just a warning:
    500       if (start + Nrows > header.Naxis[1]) {
    501         if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start);
    502       }
    503 
    504       if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    505 
    506       // if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
    507 
    508460      break;
    509461    }
     462  }
     463
     464  int IsCompressed = gfits_extension_is_compressed_table (&header);
     465
     466  if (getSizes && !IsCompressed) {
     467    read_table_sizes (&header);
     468    if (CCDKeyword != NULL) free (CCDKeyword);
     469    gfits_free_header (&header);
     470    return TRUE;
     471  }
     472  if (IsCompressed) {
     473    if (getSizes) {
     474      gprint (GP_ERR, "%s[%s] is compressed: -sizes is invalid\n", filename, extname);
     475      gfits_free_header (&header);
     476      return FALSE;
     477    }
     478    if ((start > 0) || (Nrows > -1)) {
     479      gprint (GP_ERR, "%s[%s] is compressed: must read entire table\n", filename, extname);
     480      gfits_free_header (&header);
     481      return FALSE;
     482    }
     483  }
     484
     485  if (Nrows == -1) {
     486    Nrows = header.Naxis[1] - start;
     487  }
     488  if (start < 0) ESCAPE ("invalid range: start < 0\n");
     489  if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny ("OFF_T_FMT")\n", header.Naxis[1]);
     490  if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
     491
     492  // just a warning:
     493  if (start + Nrows > header.Naxis[1]) {
     494    if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only "OFF_T_FMT" rows\n", header.Naxis[1] - start);
     495  }
     496
     497  // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
     498  // Ny = 100, start = 10, Nrows = 90
     499
     500  if (IsCompressed) {
     501    if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension %d\n", Nextend);
     502  } else {
     503    if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    510504  }
    511505
     
    518512  Binary = !strcmp (type, "BINTABLE");
    519513  Ny = header.Naxis[1];
     514
     515  Header *outheader = &header;
     516  FTable *outtable  = &table;
     517
     518  Header rawheader;
     519  FTable rawtable;
     520  if (IsCompressed) {
     521    rawtable.header = &rawheader;
     522
     523    dump_cmp_table (&table, "rd cmp");
     524
     525    int Nfields;
     526    if (!gfits_scan (&header, "TFIELDS", "%d", 1, &Nfields)) ESCAPE ("cannot find TFIELDS in header\n");
     527    for (i = 0; i < Nfields; i++) {
     528      gfits_byteswap_varlength_column (&table, i+1);
     529    }
     530    if (!gfits_uncompress_table (&table, &rawtable)) ESCAPE ("failed to uncompress table\n");
     531    dump_raw_table (&rawtable, "rd raw");
     532
     533    outheader = &rawheader;
     534    outtable  = &rawtable;
     535    gfits_free_header (&header);
     536    gfits_free_table (&table);
     537    Ny = rawheader.Naxis[1];
     538  }
    520539
    521540  /* find columns which match requested vectors */
     
    527546    Nval = 0;
    528547    if (Binary) {
    529       if (!gfits_get_bintable_column_type (&header, argv[i], type, &Nval)) ESCAPE ("requested field not found");
    530       if (!gfits_get_bintable_column (&header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");
     548      if (!gfits_get_bintable_column_type (outheader, argv[i], type, &Nval)) ESCAPE ("requested field not found\n");
     549      if (!gfits_get_bintable_column_raw (outheader, outtable, argv[i], &data, IsCompressed)) ESCAPE ("error reading data from specified field\n");
    531550    } else {
    532       if (!gfits_get_table_column_type (&header, argv[i], type)) ESCAPE ("requested field not found");
    533       if (!gfits_get_table_column (&header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");
    534     }
    535     if (Nval == 0) ESCAPE ("no data for field in table");
     551      if (!gfits_get_table_column_type (outheader, argv[i], type)) ESCAPE ("requested field not found\n");
     552      if (!gfits_get_table_column (outheader, outtable, argv[i], &data)) ESCAPE ("error reading data from specified field\n");
     553    }
     554    if (Nval == 0) ESCAPE ("no data for field in table\n");
    536555   
    537556    vecType = OPIHI_INT;
    538     if (!strcmp (type, "double") || !strcmp (type, "float")) {
     557    if (!strcmp (type, "double") || !strcmp (type, "float") || !strcmp (type, "int64_t")) {
    539558      vecType = OPIHI_FLT;
    540559    }
     
    570589        else
    571590          sprintf (name, "%s:%d", argv[i], j);
    572         if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     591        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n");
    573592        ResetVector (vec[j], vecType, Ny);
    574593      }
    575594
    576       if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
     595      if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type);
    577596
    578597    } else {
     
    584603        else
    585604          sprintf (name, "%s:%d", argv[i], j);
    586         if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     605        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n");
    587606        ResetVector (vec[j], vecType, Nval);
    588607      }
    589608
    590       if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
     609      if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type);
    591610    }
    592611    free (data);
     
    594613  }
    595614  if (CCDKeyword != NULL) free (CCDKeyword);
    596   gfits_free_table (&table);
    597   gfits_free_header (&header);
     615  gfits_free_table (outtable);
     616  gfits_free_header (outheader);
    598617  return (TRUE);
    599618}
  • trunk/Ohana/src/opihi/cmd.data/tv.c

    r38062 r38441  
    7171  int tooBig = buf[0].matrix.Naxis[2] ? (plane >= buf[0].matrix.Naxis[2]) : plane > 0;
    7272  if (tooBig) {
    73     gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs %d)\n", plane, buf[0].matrix.Naxis[2]);
     73    gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs "OFF_T_FMT")\n", plane, buf[0].matrix.Naxis[2]);
    7474    return (FALSE);
    7575  }
  • trunk/Ohana/src/opihi/cmd.data/vstats.c

    r35109 r38441  
    121121      goto skip;
    122122    }
     123    // we can hit inf if pmax and pmin are close to the max range
     124    if (isinf(dx)) dx = DBL_MAX / Nbin;
    123125
    124126    ALLOCATE (Nval, int, Nbin + 2);
  • trunk/Ohana/src/opihi/cmd.data/wd.c

    r38062 r38441  
    1818  }
    1919
     20  char *CompressMode = NULL;
     21  if ((N = get_argument (argc, argv, "-compress-mode"))) {
     22    remove_argument (N, &argc, argv);
     23    CompressMode = strcreate(argv[N]);
     24    remove_argument (N, &argc, argv);
     25  } else if ((N = get_argument (argc, argv, "-compress"))) {
     26    remove_argument (N, &argc, argv);
     27    CompressMode = strcreate("GZIP_1");
     28  }
     29
    2030  outZero = 0;
    2131  newZero = FALSE;
     
    5464    if (outUnsign == -1) {
    5565      gprint (GP_ERR, "-unsign options: t, f, true, false\n");
     66      FREE (CompressMode);
    5667      return (FALSE);
    5768    }
     
    6273  if (argc != 3) {
    6374    gprint (GP_ERR, "USAGE: wd <buffer> <filename> [-bitpix N] [-bscale X] [-bzero X] [-extend] [-newplane]\n");
     75    FREE (CompressMode);
    6476    return (FALSE);
    6577  }
    6678
    67   if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
     79  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) { FREE (CompressMode); return (FALSE); }
    6880
    6981  if (!newBitpix) outBitpix = buf[0].bitpix;
     
    159171    gfits_free_header (&temp_header);
    160172    gfits_free_matrix (&temp_matrix);
     173    FREE (CompressMode);
    161174    return (status);
    162175  }
    163176 
     177  // not compatible with extend
     178  if (CompressMode) {
     179    Header myHeader;
     180    Matrix myMatrix;
     181
     182    FILE *f = fopen (argv[2], "w");
     183    if (!f) {
     184      fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", argv[2]);
     185      FREE (CompressMode);
     186      return FALSE;
     187    }
     188   
     189    gfits_init_header (&myHeader);
     190    myHeader.extend = TRUE;
     191    gfits_create_header (&myHeader);
     192    gfits_create_matrix (&myHeader, &myMatrix);
     193    gfits_fwrite_header  (f, &myHeader);
     194    gfits_fwrite_matrix  (f, &myMatrix);
     195    gfits_free_header (&myHeader);
     196    gfits_free_matrix (&myMatrix);
     197
     198    FTable ftable;
     199    Header theader;
     200
     201    ftable.header = &theader;
     202
     203    gfits_compress_image (&temp_header, &temp_matrix, &ftable, NULL, CompressMode);
     204    gfits_byteswap_varlength_column (&ftable, 1);
     205    gfits_fwrite_Theader (f, &theader);
     206    gfits_fwrite_table  (f, &ftable);
     207    fclose (f);
     208
     209    gfits_free_header (&theader);
     210    gfits_free_table (&ftable);
     211    FREE (CompressMode);
     212    return (TRUE);
     213  }
     214
    164215  /* the actual write-to-disk goes here */
    165216  if (!gfits_write_header (argv[2], &temp_header)) {
     
    167218    gfits_free_header (&temp_header);
    168219    gfits_free_matrix (&temp_matrix);
     220    FREE (CompressMode);
    169221    return (FALSE);
    170222  }
     
    174226    gfits_free_header (&temp_header);
    175227    gfits_free_matrix (&temp_matrix);
     228    FREE (CompressMode);
    176229    return (FALSE);
    177230  }
     
    180233  gfits_free_matrix (&temp_matrix);
    181234 
     235  FREE (CompressMode);
    182236  return (TRUE);
    183237}
  • trunk/Ohana/src/opihi/cmd.data/write_vectors.c

    r35109 r38441  
    33int write_vectors (int argc, char **argv) {
    44 
    5   int append;
    65  int i, j, Nvec, Ne, N;
    76  FILE *f;
    87  char **fmtlist, *fmttype;
    9   char *p0, *p1, *p2, *format, *FITS;
     8  char *p0, *p1, *p2, *format;
    109  Vector **vec;
    1110
     
    3433
    3534  /* option generate a FITS output table */
    36   FITS = NULL;
     35  char *FITS = NULL;
    3736  if ((N = get_argument (argc, argv, "-fits"))) {
    3837    remove_argument (N, &argc, argv);
     
    5857  }
    5958
    60   append = FALSE;
     59  int append = FALSE;
    6160  if ((N = get_argument (argc, argv, "-append"))) {
    6261    remove_argument (N, &argc, argv);
    6362    append = TRUE;
     63  }
     64
     65  char *compress = NULL;
     66  if ((N = get_argument (argc, argv, "-compress-mode"))) {
     67    remove_argument (N, &argc, argv);
     68    compress = strcreate(argv[N]);
     69    remove_argument (N, &argc, argv);
     70  } else if ((N = get_argument (argc, argv, "-compress"))) {
     71    remove_argument (N, &argc, argv);
     72    compress = strcreate("GZIP_1");
     73    if (!FITS) {
     74      fprintf (stderr, "NOTE: write_vectors -compress has no effect on non-FITS\n");
     75    }
    6476  }
    6577
     
    105117
    106118  if (FITS) {
    107     int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, format);
     119    int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format);
    108120    free (vec);
    109121    return status;
     
    243255    gprint (GP_ERR, "  -csv : write a comma-separated values file (eg, to read in excel)\n");
    244256    gprint (GP_ERR, "  -f \"format\" : provide formatting codes for output:\n");
    245     gprint (GP_ERR, "    ascii / csv : format consists of c-style format codes in form %NN.Md\n");
     257    gprint (GP_ERR, "    ascii / csv : format consists of c-style format codes in form %%NN.Md\n");
    246258    gprint (GP_ERR, ",     the following codes are allowed\n");
    247     gprint (GP_ERR, "        %e -- double, %f -- float\n");
    248     gprint (GP_ERR, "        %d -- int, %c -- char, %x -- hex int\n");
     259    gprint (GP_ERR, "        %%e -- double, %%f -- float\n");
     260    gprint (GP_ERR, "        %%d -- int, %%c -- char, %%x -- hex int\n");
    249261    gprint (GP_ERR, "    FITS : format consists of the following FITS binary table format codes:\n");
    250262    gprint (GP_ERR, "      B : 1 byte int\n");   
  • trunk/Ohana/src/opihi/dvo/avextract.c

    r38062 r38441  
    185185    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
    186186    catalog.filename = (HOST_ID || PARALLEL_LOCAL) ? hostfile : skylist[0].filename[i];
    187     catalog.catflags = LOAD_AVES | LOAD_SECF;
    188     catalog.catflags |= needMeasure ? LOAD_MEAS : SKIP_MEAS;
    189     catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
    190     catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
     187    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     188    catalog.catflags |= needMeasure ? DVO_LOAD_MEASURE : DVO_SKIP_MEASURE;
     189    catalog.catflags |= needLensobj ? DVO_LOAD_LENSOBJ : DVO_SKIP_LENSOBJ;
     190    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
    191191    catalog.Nsecfilt = 0;
    192192
     
    256256  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
    257257  if (RESULT_FILE && !SKIP_RESULTS) {
    258     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, NULL);
     258    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL);
    259259    if (!status) {
    260260      goto escape;
  • trunk/Ohana/src/opihi/dvo/avmatch.c

    r37807 r38441  
    115115
    116116      CoordsFile = abspath("coords.fits", 1024);
    117       int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     117      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL);
    118118      if (!status) goto escape;
    119119    }
     
    190190    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
    191191    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    192     catalog.catflags = LOAD_AVES | LOAD_SECF;
    193     catalog.catflags |= needMeasure ? LOAD_MEAS    : SKIP_MEAS;
    194     catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
    195     catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
     192    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     193    catalog.catflags |= needMeasure ? DVO_LOAD_MEASURE    : DVO_SKIP_MEASURE;
     194    catalog.catflags |= needLensobj ? DVO_LOAD_LENSOBJ : DVO_SKIP_LENSOBJ;
     195    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
    196196    catalog.Nsecfilt = 0;
    197197
     
    302302      vec[i][0].Nelements = Nfound;
    303303    }
    304     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, NULL);
     304    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, FALSE, NULL);
    305305    free (vec[Nfields]->elements.Int);
    306306    free (vec[Nfields]);
  • trunk/Ohana/src/opihi/dvo/calextract.c

    r34088 r38441  
    6161    /* lock, load, unlock catalog */
    6262    catalog.filename = skylist[0].filename[Nr];
    63     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     63    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    6464    catalog.Nsecfilt = 0;
    6565
  • trunk/Ohana/src/opihi/dvo/calmextract.c

    r34088 r38441  
    7474    /* lock, load, unlock catalog */
    7575    catalog.filename = skylist[0].filename[Nr];
    76     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     76    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    7777    catalog.Nsecfilt = 0;
    7878
  • trunk/Ohana/src/opihi/dvo/catalog.c

    r19823 r38441  
    315315      /* lock, load, unlock catalog */
    316316      catalog.filename = filename;
    317       catalog.catflags = LOAD_AVES;
     317      catalog.catflags = DVO_LOAD_AVERAGE;
    318318
    319319      // an error exit status here is a significant error
  • trunk/Ohana/src/opihi/dvo/ccd.c

    r34088 r38441  
    6969    /* lock, load, unlock catalog */
    7070    catalog.filename = skylist[0].filename[k];
    71     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     71    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    7272    catalog.Nsecfilt = 0;
    7373
  • trunk/Ohana/src/opihi/dvo/cmatch.c

    r28241 r38441  
    2929  /* load data from the photometry database file */
    3030  catalog1.filename = filename;
    31   catalog1.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     31  catalog1.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    3232
    3333  // an error exit status here is a significant error
  • trunk/Ohana/src/opihi/dvo/cmd.c

    r34088 r38441  
    6868    /* lock, load, unlock catalog */
    6969    catalog.filename = skylist[0].filename[j];
    70     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     70    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    7171    catalog.Nsecfilt = 0;
    7272
  • trunk/Ohana/src/opihi/dvo/cmpReadFile.c

    r29001 r38441  
    1919  if (!gfits_fread_ftable (f, &table, "SMPFILE")) goto escape;
    2020
    21   smpdata = gfits_table_get_SMPData (&table, &Nstars, NULL);
     21  smpdata = gfits_table_get_SMPData (&table, &Nstars, NULL, NULL);
    2222  if (!smpdata) {
    2323    fprintf (stderr, "ERROR: failed to read stars\n");
  • trunk/Ohana/src/opihi/dvo/ddmags.c

    r15509 r38441  
    6666    /* lock, load, unlock catalog */
    6767    catalog.filename = skylist[0].filename[k];
    68     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     68    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    6969    catalog.Nsecfilt = 0;
    7070
  • trunk/Ohana/src/opihi/dvo/dmagaves.c

    r14401 r38441  
    5858    /* lock, load, unlock catalog */
    5959    catalog.filename = skylist[0].filename[j];
    60     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     60    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    6161    catalog.Nsecfilt = 0;
    6262
  • trunk/Ohana/src/opihi/dvo/dmagmeas.c

    r15509 r38441  
    6666    /* lock, load, unlock catalog */
    6767    catalog.filename = skylist[0].filename[j];
    68     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     68    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    6969    catalog.Nsecfilt = 0;
    7070
  • trunk/Ohana/src/opihi/dvo/dmags.c

    r15509 r38441  
    6464    /* lock, load, unlock catalog */
    6565    catalog.filename = skylist[0].filename[j];
    66     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     66    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    6767    catalog.Nsecfilt = 0;
    6868
  • trunk/Ohana/src/opihi/dvo/dmt.c

    r31635 r38441  
    7777    /* lock, load, unlock catalog */
    7878    catalog.filename = skylist[0].filename[k];
    79     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     79    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    8080    catalog.Nsecfilt = 0;
    8181
  • trunk/Ohana/src/opihi/dvo/dvo_host_utils.c

    r37807 r38441  
    230230  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
    231231  if (ResultFile) {
    232     int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL);
     232    int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, FALSE, NULL);
    233233    if (!status) {
    234234      gprint (GP_ERR, "failed to write result file %s\n", ResultFile);
  • trunk/Ohana/src/opihi/dvo/extract.c

    r31635 r38441  
    252252      catalog.measure = (Measure *) NULL;
    253253      catalog.secfilt = (SecFilt *) NULL;
    254       loadmode = LOAD_AVES | LOAD_SECF;
     254      loadmode = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    255255      if ((mode == REF) || (mode == TYPE) || (mode == NPHOT) || (mode == NCODE))
    256         loadmode = loadmode | LOAD_MEAS;
     256        loadmode = loadmode | DVO_LOAD_MEASURE;
    257257
    258258      /* lock, load, unlock catalog */
  • trunk/Ohana/src/opihi/dvo/fitcolors.c

    r34584 r38441  
    162162    /* lock, load, unlock catalog */
    163163    catalog[k].filename = skylist[0].filename[k];
    164     catalog[k].catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     164    catalog[k].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    165165    catalog[k].Nsecfilt = 0;
    166166
  • trunk/Ohana/src/opihi/dvo/fitsed.c

    r37049 r38441  
    188188    /* lock, load, unlock catalog */
    189189    catalog.filename = skylist[0].filename[k];
    190     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     190    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    191191    catalog.Nsecfilt = 0;
    192192
  • trunk/Ohana/src/opihi/dvo/gstar.c

    r37246 r38441  
    235235
    236236  /* lock, load, unlock catalog */
    237   catalog.catflags = LOAD_AVES | LOAD_SECF;
    238   catalog.catflags |= GetMeasures ? LOAD_MEAS : SKIP_MEAS;
     237  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     238  catalog.catflags |= GetMeasures ? DVO_LOAD_MEASURE : DVO_SKIP_MEASURE;
    239239  catalog.Nsecfilt = 0;
    240240
  • trunk/Ohana/src/opihi/dvo/imdata.c

    r37807 r38441  
    136136    /* get file name and open */
    137137    catalog.filename = skylist[0].filename[j];
    138     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     138    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    139139    catalog.Nsecfilt = 0;
    140140
  • trunk/Ohana/src/opihi/dvo/lcurve.c

    r37049 r38441  
    7676  /* set filename, read in header */
    7777  catalog.filename = skylist[0].filename[0];
    78   catalog.catflags = LOAD_AVES | LOAD_MEAS;
     78  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
    7979  catalog.Nsecfilt = 0;
    8080
  • trunk/Ohana/src/opihi/dvo/lightcurve.c

    r37049 r38441  
    5959  /* set filename, read in header */
    6060  catalog.filename = skylist[0].filename[0];
    61   catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     61  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    6262  catalog.Nsecfilt = 0;
    6363
  • trunk/Ohana/src/opihi/dvo/mextract.c

    r37807 r38441  
    1919    return FALSE;
    2020}
     21
     22void gfits_uncompress_timing ();
    2123
    2224int mextract (int argc, char **argv) {
     
    229231    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
    230232    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    231     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
    232     // catalog.catflags |= needLensing ? LOAD_LENSING : SKIP_LENSING;
    233     catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
     233    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     234    // catalog.catflags |= needLensing ? DVO_LOAD_LENSING : DVO_SKIP_LENSING;
     235    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
    234236    catalog.Nsecfilt = Nsecfilt;
    235237
     
    317319  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
    318320  if (RESULT_FILE && !SKIP_RESULTS) {
    319     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, NULL);
     321    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL);
    320322    if (!status) goto escape;
    321323  }
     
    330332  SkyListFree (skylist);
    331333  FreeSkyRegionSelection (selection);
     334
     335  gfits_uncompress_timing();
    332336
    333337  // fprintf (stderr, "done extr...\n");
  • trunk/Ohana/src/opihi/dvo/mmatch.c

    r37807 r38441  
    150150      // XXX this is now set for both cases...
    151151      CoordsFile = abspath("coords.fits", 1024);
    152       int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     152      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL);
    153153      if (!status) goto escape;
    154154    }
     
    248248    snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name);
    249249    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    250     catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
    251     catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
     250    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT | DVO_LOAD_MEASURE;
     251    catalog.catflags |= needStarpar ? DVO_LOAD_STARPAR : DVO_SKIP_STARPAR;
    252252    catalog.Nsecfilt = Nsecfilt;
    253253
     
    349349      vec[Nfields-1] = IDXvec;
    350350    }
    351     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, NULL);
     351    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, FALSE, NULL);
    352352    if (!status) goto escape;
    353353  }
  • trunk/Ohana/src/opihi/dvo/mmextract.c

    r37807 r38441  
    183183    /* lock, load, unlock catalog */
    184184    catalog.filename = skylist[0].filename[i];
    185     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     185    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    186186    catalog.Nsecfilt = Nsecfilt;
    187187
  • trunk/Ohana/src/opihi/dvo/objectcoverage.c

    r37807 r38441  
    184184    /* lock, load, unlock catalog */
    185185    catalog.filename = skylist[0].filename[k];
    186     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     186    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    187187    catalog.Nsecfilt = 0;
    188188
  • trunk/Ohana/src/opihi/dvo/paverage.c

    r34088 r38441  
    105105  for (j = 0; (j < skylist[0].Nregions) && !interrupt; j++) {
    106106    catalog.filename = skylist[0].filename[j];
    107     catalog.catflags = LOAD_AVES | LOAD_SECF;
     107    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
    108108    catalog.Nsecfilt = Nsecfilt;
    109109
  • trunk/Ohana/src/opihi/dvo/pmeasure.c

    r37049 r38441  
    178178  for (j = 0; (j < skylist[0].Nregions) && !interrupt; j++) {
    179179    catalog.filename = skylist[0].filename[j];
    180     catalog.catflags = LOAD_AVES | LOAD_MEAS;
     180    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
    181181    catalog.Nsecfilt = 0;
    182182
  • trunk/Ohana/src/opihi/dvo/subpix.c

    r37807 r38441  
    4040  /* lock, load, unlock catalog */
    4141  catalog.filename = skylist[0].filename[0];
    42   catalog.catflags = LOAD_AVES | LOAD_MEAS;
     42  catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
    4343  catalog.Nsecfilt = 0;
    4444
  • trunk/Ohana/src/opihi/include/dvomath.h

    r38062 r38441  
    167167
    168168/* vector IO functions */
    169 int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *format));
     169int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format));
    170170Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
    171171
  • trunk/Ohana/src/opihi/lib.data/SplineOps.c

    r34584 r38441  
    178178  gfits_create_table (&theader, &ftable);
    179179
    180   gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots);
    181   gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots);
    182   gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots);
     180  // NOTE: if we want to compress the output table, use native byte order here (last element)
     181  gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots, FALSE);
     182  gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots, FALSE);
     183  gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots, FALSE);
    183184
    184185  if (!append) {
  • trunk/Ohana/src/opihi/lib.shell/VectorIO.c

    r37049 r38441  
    11# include "opihi.h"
    22 
    3 // write a set of vectors to a FITS file (vectors names become fits column names)
    4 int WriteVectorTable (Header *theader, FTable *ftable, char *extname, Vector **vec, int Nvec, char *format) {
     3// write a set of vectors to a FITS FTable structure (vectors names become fits column names)
     4static int WriteVectorTable (FTable *ftable, char *extname, Vector **vec, int Nvec, char *format, char nativeOrder) {
    55 
    66  int j;
     
    88  char *tformat = NULL;
    99
     10  Header *theader = ftable->header;
    1011  gfits_create_table_header (theader, "BINTABLE", extname);
    1112
     
    5859  for (j = 0; j < Nvec; j++) {
    5960    if (vec[j][0].type == OPIHI_FLT) {
    60       gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements);
     61      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements, nativeOrder);
    6162    } else {
    62       gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements);
     63      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder);
    6364    }
    6465  }
     
    7071}
    7172 
     73# define VERBOSE 0
     74int dump_raw_table (FTable *table, char *message) {
     75# if (VERBOSE)
     76  int i;
     77  fprintf (stderr, "%s data: ", message);
     78  for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {
     79    fprintf (stderr, "0x%02hhx ", table->buffer[i]);
     80  }
     81  fprintf (stderr, "\n");
     82# endif
     83  return TRUE;
     84}
     85
     86int dump_cmp_table (FTable *table, char *message) {
     87# if (VERBOSE)
     88  int i;
     89  fprintf (stderr, "%s pntr: ", message);
     90  for (i = 0; i < table->header->Naxis[0]*table->header->Naxis[1]; i++) {
     91    fprintf (stderr, "0x%02hhx ", table->buffer[i]);
     92  }
     93  fprintf (stderr, "\n");
     94
     95  fprintf (stderr, "%s data: ", message);
     96  for (i = 0; i < table->header->pcount; i++) {
     97    fprintf (stderr, "0x%02hhx ", table->buffer[table->heap_start + i]);
     98  }
     99  fprintf (stderr, "\n");
     100# endif
     101  return TRUE;
     102}
     103
    72104// write a set of vectors to a FITS file (vectors names become fits column names)
    73 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *format) {
    74  
    75   Header header;
    76   Matrix matrix;
    77   Header theader;
    78   FTable ftable;
     105int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format) {
     106 
     107  Header rawheader;
     108  Header cmpheader;
     109  FTable rawtable;
     110  FTable cmptable;
    79111
    80112  FILE *f = NULL;
     
    91123  }
    92124
    93   if (!WriteVectorTable (&theader, &ftable, extname, vec, Nvec, format)) goto escape;
     125  // init so free below does not fail if table is not created
     126  gfits_init_header (&rawheader);
     127  gfits_init_header (&cmpheader);
     128  gfits_init_table (&rawtable);
     129  gfits_init_table (&cmptable);
     130
     131  rawtable.header = &rawheader;
     132  if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format, (compress != NULL))) goto escape;
     133  // NOTE : for compression, the table is constructed in native by order
     134
     135  FTable *outtable = &rawtable;
     136  Header *outheader = &rawheader;
     137
     138  if (compress) {
     139    cmptable.header = &cmpheader;
     140
     141    dump_raw_table (&rawtable, "wd raw");
     142    if (!gfits_compress_table (&rawtable, &cmptable, 0, compress)) goto escape;
     143
     144    int i, Nfields;
     145    if (!gfits_scan (&cmpheader, "TFIELDS", "%d", 1, &Nfields)) goto escape;
     146    for (i = 0; i < Nfields; i++) {
     147      gfits_byteswap_varlength_column (&cmptable, i+1);
     148    }
     149    dump_cmp_table (&cmptable, "wd cmp");
     150
     151    outtable = &cmptable;
     152    outheader = &cmpheader;
     153  }
    94154
    95155  if (!append) {
     156    Header header;
     157    Matrix matrix;
    96158    gfits_init_header (&header);
     159    gfits_init_matrix (&matrix);
    97160    header.extend = TRUE;
    98161    gfits_create_header (&header);
     
    103166    gfits_free_matrix (&matrix);
    104167  }
    105   gfits_fwrite_Theader (f, &theader);
    106   gfits_fwrite_table  (f, &ftable);
    107 
    108   gfits_free_header (&theader);
    109   gfits_free_table (&ftable);
     168
     169  // write the actual table data
     170  gfits_fwrite_Theader (f, outheader);
     171  gfits_fwrite_table  (f, outtable);
     172
     173  gfits_free_header (&rawheader);
     174  gfits_free_table (&rawtable);
     175
     176  if (compress) {
     177    gfits_free_header (&cmpheader);
     178    gfits_free_table (&cmptable);
     179  }
    110180
    111181  fclose (f);
     
    114184
    115185 escape:
    116   if (!append) {
    117     gfits_free_header (&header);
    118     gfits_free_matrix (&matrix);
    119   }
    120   gfits_free_header (&theader);
    121   gfits_free_table (&ftable);
     186  gfits_free_header (&rawheader);
     187  gfits_free_table (&rawtable);
     188
     189  if (compress) {
     190    gfits_free_header (&cmpheader);
     191    gfits_free_table (&cmptable);
     192  }
    122193
    123194  fclose (f);
     
    249320  ASSIGN_DATA(short,   short,   Int);
    250321  ASSIGN_DATA(int,     int,     Int);
    251   ASSIGN_DATA(int64_t, int64_t, Int);
     322  ASSIGN_DATA(int64_t, int64_t, Flt); // int64_t has a problem: Int is too small, Flt is wrong precision
    252323  ASSIGN_DATA(float,   float,   Flt);
    253324  ASSIGN_DATA(double,  double,  Flt);
     
    274345  ASSIGN_DATA_TRANSPOSE(short,   short,   Int);
    275346  ASSIGN_DATA_TRANSPOSE(int,     int,     Int);
    276   ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Int);
     347  ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Flt);
    277348  ASSIGN_DATA_TRANSPOSE(float,   float,   Flt);
    278349  ASSIGN_DATA_TRANSPOSE(double,  double,  Flt);
  • trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r38062 r38441  
    5858    if (!strcmp (argv[i], "lgamma")) { type = ST_UNARY; goto gotit; }
    5959    if (!strcmp (argv[i], "rnd"))    { type = ST_UNARY; goto gotit; }
     60    if (!strcmp (argv[i], "drnd"))   { type = ST_UNARY; goto gotit; }
     61    if (!strcmp (argv[i], "lrnd"))   { type = ST_UNARY; goto gotit; }
     62    if (!strcmp (argv[i], "mrnd"))   { type = ST_UNARY; goto gotit; }
    6063    if (!strcmp (argv[i], "xramp"))  { type = ST_UNARY; goto gotit; }
    6164    if (!strcmp (argv[i], "yramp"))  { type = ST_UNARY; goto gotit; }
  • trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r38062 r38441  
    115115
    116116        /* there are no valid unary string operators */
    117         push_error ("invalid operands for trinary operator (mismatch types?)");
     117        snprintf (line, 512, "invalid operands for trinary operator %s (mismatch types?)", stack[i].name);
     118        push_error (line);
    118119        clear_stack (&tmp_stack);
    119120        return (FALSE);
     
    210211
    211212        /* there are no valid unary string operators */
    212         push_error ("syntax error: no valid string unary ops");
     213        snprintf (line, 512, "invalid operand for unary operator %s (undefined value?)", stack[i].name);
     214        push_error (line);
    213215        clear_stack (&tmp_stack);
    214216        return (FALSE);
  • trunk/Ohana/src/opihi/lib.shell/stack_math.c

    r38062 r38441  
    1212  // set up the possible operations : int OP int -> int, all else yield float
    1313  // OP is the operation performed on *M1 and *M2
    14 # define SSS_FUNC(OP) {                                         \
     14# define SSS_FUNC(OP) {                                                 \
    1515    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT) && (V3->type == ST_SCALAR_FLT)) { \
    16       opihi_flt M1  =  V1[0].FltValue;                  \
    17       opihi_flt M2  =  V2[0].FltValue;                  \
    18       opihi_flt M3  =  V3[0].FltValue;                  \
    19       OUT[0].type = ST_SCALAR_FLT;                      \
    20       OUT[0].FltValue = OP;                                                     \
     16      opihi_flt M1  =  V1[0].FltValue;                                  \
     17      opihi_flt M2  =  V2[0].FltValue;                                  \
     18      opihi_flt M3  =  V3[0].FltValue;                                  \
     19      OUT[0].type = ST_SCALAR_FLT;                                      \
     20      OUT[0].FltValue = OP;                                             \
    2121      break;                                                            \
    2222    }                                                                   \
    2323    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT) && (V3->type == ST_SCALAR_INT)) { \
    24       opihi_int M1  =  V1[0].IntValue;                  \
    25       opihi_int M2  =  V2[0].IntValue;                  \
    26       opihi_int M3  =  V3[0].IntValue;                  \
    27       OUT[0].type = ST_SCALAR_INT;                      \
    28       OUT[0].IntValue = OP;                                                     \
     24      opihi_int M1  =  V1[0].IntValue;                                  \
     25      opihi_int M2  =  V2[0].IntValue;                                  \
     26      opihi_int M3  =  V3[0].IntValue;                                  \
     27      OUT[0].type = ST_SCALAR_INT;                                      \
     28      OUT[0].IntValue = OP;                                             \
    2929      break;                                                            \
    3030    }                                                                   \
     
    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
     
    6868  // set up the possible operations : int OP int -> int, all else yield float
    6969  // OP is the operation performed on *M1 and *M2
    70 # define VVV_FUNC(OP) {                                         \
     70# define VVV_FUNC(OP) {                                                 \
    7171    if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \
    7272      CopyVector (OUT[0].vector, V1[0].vector);                         \
     
    394394  // OP is the operation performed on *M1 and *M2
    395395# define SV_FUNC(FTYPE,OP) {                                            \
    396     if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) {               \
     396    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) { \
    397397      CopyVector (OUT[0].vector, V2[0].vector);                         \
    398398      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    404404      break;                                                            \
    405405    }                                                                   \
    406     if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) {               \
     406    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) { \
    407407      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    408408      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    414414      break;                                                            \
    415415    }                                                                   \
    416     if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) {               \
     416    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) { \
    417417      CopyVector (OUT[0].vector, V2[0].vector);                         \
    418418      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    434434      break;                                                            \
    435435    }                                                                   \
    436     if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) {               \
     436    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \
    437437      CopyVector (OUT[0].vector, V2[0].vector);                         \
    438438      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    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);
     
    501501  // OP is the operation performed on *M1 and *M2
    502502# define VS_FUNC(FTYPE,OP) {                                            \
    503     if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) {               \
     503    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) { \
    504504      CopyVector (OUT[0].vector, V1[0].vector);                         \
    505505      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    511511      break;                                                            \
    512512    }                                                                   \
    513     if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) {               \
     513    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) { \
    514514      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    515515      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    521521      break;                                                            \
    522522    }                                                                   \
    523     if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) {               \
     523    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) { \
    524524      CopyVector (OUT[0].vector, V1[0].vector);                         \
    525525      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    541541      break;                                                            \
    542542    }                                                                   \
    543     if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) {               \
     543    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \
    544544      CopyVector (OUT[0].vector, V1[0].vector);                         \
    545545      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    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);
     
    885885  float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
    886886
    887 # define MS_FUNC(OP) {                                  \
    888     if (V2->type == ST_SCALAR_FLT)  {                           \
    889       opihi_flt M2 = V2[0].FltValue;                    \
     887# define MS_FUNC(OP) {                          \
     888    if (V2->type == ST_SCALAR_FLT)  {           \
     889      opihi_flt M2 = V2[0].FltValue;            \
    890890      for (i = 0; i < Npix; i++, out++, M1++) { \
    891         *out = OP;                                      \
    892       }                                                 \
    893       break;                                            \
    894     }                                                   \
    895     if (V2->type == ST_SCALAR_INT)  {                           \
    896       opihi_int M2 = V2[0].IntValue;                    \
     891        *out = OP;                              \
     892      }                                         \
     893      break;                                    \
     894    }                                           \
     895    if (V2->type == ST_SCALAR_INT)  {           \
     896      opihi_int M2 = V2[0].IntValue;            \
    897897      for (i = 0; i < Npix; i++, out++, M1++) { \
    898         *out = OP;                                      \
    899       }                                                 \
    900       break;                                            \
    901     }                                                   \
     898        *out = OP;                              \
     899      }                                         \
     900      break;                                    \
     901    }                                           \
    902902  }
    903903
     
    961961  float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
    962962
    963 # define SM_FUNC(OP) {                                  \
    964     if (V1->type == ST_SCALAR_FLT)  {                           \
    965       opihi_flt M1 = V1[0].FltValue;                    \
     963# define SM_FUNC(OP) {                          \
     964    if (V1->type == ST_SCALAR_FLT)  {           \
     965      opihi_flt M1 = V1[0].FltValue;            \
    966966      for (i = 0; i < Npix; i++, out++, M2++) { \
    967         *out = OP;                                      \
    968       }                                                 \
    969       break;                                            \
    970     }                                                   \
    971     if (V1->type == ST_SCALAR_INT)  {                           \
    972       opihi_int M1 = V1[0].IntValue;                    \
     967        *out = OP;                              \
     968      }                                         \
     969      break;                                    \
     970    }                                           \
     971    if (V1->type == ST_SCALAR_INT)  {           \
     972      opihi_int M1 = V1[0].IntValue;            \
    973973      for (i = 0; i < Npix; i++, out++, M2++) { \
    974         *out = OP;                                      \
    975       }                                                 \
    976       break;                                            \
    977     }                                                   \
     974        *out = OP;                              \
     975      }                                         \
     976      break;                                    \
     977    }                                           \
    978978  }
    979979
     
    10231023
    10241024# define SS_FUNC(FTYPE,OP) {                                            \
    1025     if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {                   \
     1025    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {   \
    10261026      opihi_flt M1 = V1[0].FltValue;                                    \
    10271027      opihi_flt M2 = V2[0].FltValue;                                    \
    1028       OUT[0].type = ST_SCALAR_FLT;                                              \
     1028      OUT[0].type = ST_SCALAR_FLT;                                      \
    10291029      OUT[0].FltValue = OP;                                             \
    10301030      break;                                                            \
    10311031    }                                                                   \
    1032     if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {                   \
     1032    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {   \
    10331033      opihi_flt M1 = V1[0].FltValue;                                    \
    10341034      opihi_int M2 = V2[0].IntValue;                                    \
    1035       OUT[0].type = ST_SCALAR_FLT;                                              \
     1035      OUT[0].type = ST_SCALAR_FLT;                                      \
    10361036      OUT[0].FltValue = OP;                                             \
    10371037      break;                                                            \
    10381038    }                                                                   \
    1039     if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {                   \
     1039    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {   \
    10401040      opihi_int M1 = V1[0].IntValue;                                    \
    10411041      opihi_flt M2 = V2[0].FltValue;                                    \
    1042       OUT[0].type = ST_SCALAR_FLT;                                              \
     1042      OUT[0].type = ST_SCALAR_FLT;                                      \
    10431043      OUT[0].FltValue = OP;                                             \
    10441044      break;                                                            \
    10451045    }                                                                   \
    1046     if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {       \
     1046    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \
    10471047      opihi_int M1 = V1[0].IntValue;                                    \
    10481048      opihi_int M2 = V2[0].IntValue;                                    \
    1049       OUT[0].type = ST_SCALAR_FLT;                                              \
     1049      OUT[0].type = ST_SCALAR_FLT;                                      \
    10501050      OUT[0].FltValue = OP;                                             \
    10511051      break;                                                            \
    10521052    }                                                                   \
    1053     if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {                   \
     1053    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {   \
    10541054      opihi_int M1 = V1[0].IntValue;                                    \
    10551055      opihi_int M2 = V2[0].IntValue;                                    \
    1056       OUT[0].type = ST_SCALAR_INT;                                              \
     1056      OUT[0].type = ST_SCALAR_INT;                                      \
    10571057      OUT[0].IntValue = OP;                                             \
    10581058      break;                                                            \
     
    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
     
    11531153}
    11541154
    1155 
    11561155int S_unary (StackVar *OUT, StackVar *V1, char *op) {
    11571156
    11581157  char line[512]; // this is only used to report an error
    11591158 
    1160 # define S_FUNC(OP,FTYPE) {                     \
    1161     if (V1->type == ST_SCALAR_FLT) {                    \
    1162       opihi_flt M1  = V1[0].FltValue;           \
    1163       OUT[0].type = ST_SCALAR_FLT;                      \
    1164       OUT[0].FltValue = OP;                     \
    1165       clear_stack (V1);                         \
    1166       return (TRUE);                            \
    1167     }                                           \
     1159# define S_FUNC(OP,FTYPE) {                                             \
     1160    if (V1->type == ST_SCALAR_FLT) {                                    \
     1161      opihi_flt M1  = V1[0].FltValue;                                   \
     1162      OUT[0].type = ST_SCALAR_FLT;                                      \
     1163      OUT[0].FltValue = OP;                                             \
     1164      clear_stack (V1);                                                 \
     1165      return (TRUE);                                                    \
     1166    }                                                                   \
    11681167    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) {      \
    1169       opihi_int M1  = V1[0].IntValue;           \
    1170       OUT[0].type = ST_SCALAR_FLT;                      \
    1171       OUT[0].FltValue = OP;                     \
    1172       clear_stack (V1);                         \
    1173       return (TRUE);                            \
    1174     }                                           \
     1168      opihi_int M1  = V1[0].IntValue;                                   \
     1169      OUT[0].type = ST_SCALAR_FLT;                                      \
     1170      OUT[0].FltValue = OP;                                             \
     1171      clear_stack (V1);                                                 \
     1172      return (TRUE);                                                    \
     1173    }                                                                   \
    11751174    if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {      \
    1176       opihi_int M1  = V1[0].IntValue;           \
    1177       OUT[0].type = ST_SCALAR_INT;                      \
    1178       OUT[0].IntValue = OP;                     \
    1179       clear_stack (V1);                         \
    1180       return (TRUE);                            \
    1181     }                                           \
     1175      opihi_int M1  = V1[0].IntValue;                                   \
     1176      OUT[0].type = ST_SCALAR_INT;                                      \
     1177      OUT[0].IntValue = OP;                                             \
     1178      clear_stack (V1);                                                 \
     1179      return (TRUE);                                                    \
     1180    }                                                                   \
    11821181  }
    11831182
     
    12111210  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT);
    12121211  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT);
    1213   if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT);
     1212  if (!strcmp (op, "rnd"))    S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
     1213  if (!strcmp (op, "drnd"))   S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
     1214  if (!strcmp (op, "lrnd"))   S_FUNC(0*M1 + lrand48(), ST_SCALAR_INT);
     1215  if (!strcmp (op, "mrnd"))   S_FUNC(0*M1 + mrand48(), ST_SCALAR_INT);
    12141216  if (!strcmp (op, "not"))    S_FUNC(!(M1), ST_SCALAR_INT);
    12151217  if (!strcmp (op, "--"))     S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed,
     
    12351237  OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/
    12361238
    1237 # define V_FUNC(OP,FTYPE) {                                     \
    1238     if (V1->vector->type == OPIHI_FLT) {                        \
    1239       CopyVector (OUT[0].vector, V1[0].vector);                 \
    1240       opihi_flt *M1  = V1[0].vector[0].elements.Flt;            \
    1241       opihi_flt *out = OUT[0].vector[0].elements.Flt;           \
    1242       for (i = 0; i < Nx; i++, out++, M1++) {                   \
    1243         *out = OP;                                              \
    1244       }                                                         \
    1245       goto escape;                                              \
    1246     }                                                           \
     1239# define V_FUNC(OP,FTYPE) {                                             \
     1240    if (V1->vector->type == OPIHI_FLT) {                                \
     1241      CopyVector (OUT[0].vector, V1[0].vector);                         \
     1242      opihi_flt *M1  = V1[0].vector[0].elements.Flt;                    \
     1243      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     1244      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     1245        *out = OP;                                                      \
     1246      }                                                                 \
     1247      goto escape;                                                      \
     1248    }                                                                   \
    12471249    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) {  \
    1248       MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);     \
    1249       opihi_int *M1  = V1[0].vector[0].elements.Int;            \
    1250       opihi_flt *out = OUT[0].vector[0].elements.Flt;           \
    1251       for (i = 0; i < Nx; i++, out++, M1++) {                   \
    1252         *out = OP;                                              \
    1253       }                                                         \
    1254       goto escape;                                              \
    1255     }                                                           \
     1250      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
     1251      opihi_int *M1  = V1[0].vector[0].elements.Int;                    \
     1252      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     1253      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     1254        *out = OP;                                                      \
     1255      }                                                                 \
     1256      goto escape;                                                      \
     1257    }                                                                   \
    12561258    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) {  \
    1257       CopyVector (OUT[0].vector, V1[0].vector);                 \
    1258       opihi_int *M1  = V1[0].vector[0].elements.Int;            \
    1259       opihi_int *out = OUT[0].vector[0].elements.Int;           \
    1260       for (i = 0; i < Nx; i++, out++, M1++) {                   \
    1261         *out = OP;                                              \
    1262       }                                                         \
    1263       goto escape;                                              \
     1259      CopyVector (OUT[0].vector, V1[0].vector);                         \
     1260      opihi_int *M1  = V1[0].vector[0].elements.Int;                    \
     1261      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     1262      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     1263        *out = OP;                                                      \
     1264      }                                                                 \
     1265      goto escape;                                                      \
    12641266    } }                                                 
    12651267
     
    12941296  if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT);
    12951297  if (!strcmp (op, "rnd"))    V_FUNC(drand48(), ST_SCALAR_FLT);
     1298  if (!strcmp (op, "drnd"))   V_FUNC(drand48(), ST_SCALAR_FLT);
     1299  if (!strcmp (op, "lrnd"))   V_FUNC(lrand48(), ST_SCALAR_INT);
     1300  if (!strcmp (op, "mrnd"))   V_FUNC(mrand48(), ST_SCALAR_INT);
    12961301  if (!strcmp (op, "ramp"))   V_FUNC(i, ST_SCALAR_INT);
    12971302  if (!strcmp (op, "zero"))   V_FUNC(0, ST_SCALAR_INT);
     
    13201325}
    13211326
     1327# define M_FUNC(OP) { for (i = 0; i < Npix; i++, out++, M1++) { *out = (OP); }}
     1328
    13221329int M_unary (StackVar *OUT, StackVar *V1, char *op) {
    13231330
     
    13371344  M1  = (float *) V1[0].buffer[0].matrix.buffer;
    13381345  out = (float *)OUT[0].buffer[0].matrix.buffer;
    1339 
     1346 
     1347// if (!strcmp (op, "rint"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }}
     1348 
    13401349  if (!strcmp (op, "="))     { }
    1341   if (!strcmp (op, "abs"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = fabs(*M1);         }}
    1342   if (!strcmp (op, "int"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = (opihi_flt)(long long)(*M1); }}
    1343 
    1344   if (!strcmp (op, "floor")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = floor (*M1); }}
    1345   if (!strcmp (op, "ceil"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = ceil (*M1); }}
    1346   // if (!strcmp (op, "rint"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }}
    1347 
    1348   if (!strcmp (op, "exp"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = exp(*M1);          }}
    1349   if (!strcmp (op, "ten"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = pow(10.0,*M1);     }}
    1350   if (!strcmp (op, "log"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = log10(*M1);        }}
    1351   if (!strcmp (op, "ln"))    { for (i = 0; i < Npix; i++, out++, M1++) { *out = log(*M1);          }}
    1352   if (!strcmp (op, "sqrt"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sqrt(*M1);         }}
    1353   if (!strcmp (op, "erf"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = erf(*M1);          }}
    1354 
    1355   if (!strcmp (op, "sinh"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sinh(*M1);         }}
    1356   if (!strcmp (op, "cosh"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = cosh(*M1);         }}
    1357   if (!strcmp (op, "asinh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asinh(*M1);        }}
    1358   if (!strcmp (op, "acosh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acosh(*M1);        }}
    1359   if (!strcmp (op, "lgamma")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = lgamma(*M1);      }}
    1360 
    1361   if (!strcmp (op, "sin"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1);          }}
    1362   if (!strcmp (op, "cos"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1);          }}
    1363   if (!strcmp (op, "tan"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1);          }}
    1364   if (!strcmp (op, "dsin"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1*RAD_DEG);  }}
    1365   if (!strcmp (op, "dcos"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1*RAD_DEG);  }}
    1366   if (!strcmp (op, "dtan"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1*RAD_DEG);  }}
    1367   if (!strcmp (op, "asin"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1);         }}
    1368   if (!strcmp (op, "acos"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1);         }}
    1369   if (!strcmp (op, "atan"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1);         }}
    1370   if (!strcmp (op, "dasin")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1)*DEG_RAD; }}
    1371   if (!strcmp (op, "dacos")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1)*DEG_RAD; }}
    1372   if (!strcmp (op, "datan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1)*DEG_RAD; }}
    1373   if (!strcmp (op, "not"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = !(*M1);            }}
    1374   if (!strcmp (op, "--"))    { for (i = 0; i < Npix; i++, out++, M1++) { *out = -(*M1);            }}
    1375   if (!strcmp (op, "rnd"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = drand48();         }}
    1376   if (!strcmp (op, "ramp"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = i;                 }}
    1377   if (!strcmp (op, "zero"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = 0;                 }}
    1378   if (!strcmp (op, "isinf")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = !finite(*M1);      }}
    1379   if (!strcmp (op, "isnan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = isnan(*M1);        }}
     1350  if (!strcmp (op, "abs"))    M_FUNC(fabs(*M1));
     1351  if (!strcmp (op, "int"))    M_FUNC((opihi_flt)(long long)(*M1));
     1352  if (!strcmp (op, "floor"))  M_FUNC(floor (*M1));
     1353  if (!strcmp (op, "ceil"))   M_FUNC(ceil (*M1));
     1354  if (!strcmp (op, "exp"))    M_FUNC(exp(*M1));
     1355  if (!strcmp (op, "ten"))    M_FUNC(pow(10.0,*M1));
     1356  if (!strcmp (op, "log"))    M_FUNC(log10(*M1));
     1357  if (!strcmp (op, "ln"))     M_FUNC(log(*M1));
     1358  if (!strcmp (op, "sqrt"))   M_FUNC(sqrt(*M1));
     1359  if (!strcmp (op, "erf"))    M_FUNC(erf(*M1));
     1360  if (!strcmp (op, "sinh"))   M_FUNC(sinh(*M1));
     1361  if (!strcmp (op, "cosh"))   M_FUNC(cosh(*M1));
     1362  if (!strcmp (op, "asinh"))  M_FUNC(asinh(*M1));
     1363  if (!strcmp (op, "acosh"))  M_FUNC(acosh(*M1));
     1364  if (!strcmp (op, "lgamma")) M_FUNC(lgamma(*M1));
     1365  if (!strcmp (op, "sin"))    M_FUNC(sin(*M1));
     1366  if (!strcmp (op, "cos"))    M_FUNC(cos(*M1));
     1367  if (!strcmp (op, "tan"))    M_FUNC(tan(*M1));
     1368  if (!strcmp (op, "dsin"))   M_FUNC(sin(*M1*RAD_DEG));
     1369  if (!strcmp (op, "dcos"))   M_FUNC(cos(*M1*RAD_DEG));
     1370  if (!strcmp (op, "dtan"))   M_FUNC(tan(*M1*RAD_DEG));
     1371  if (!strcmp (op, "asin"))   M_FUNC(asin(*M1));
     1372  if (!strcmp (op, "acos"))   M_FUNC(acos(*M1));
     1373  if (!strcmp (op, "atan"))   M_FUNC(atan(*M1));
     1374  if (!strcmp (op, "dasin"))  M_FUNC(asin(*M1)*DEG_RAD);
     1375  if (!strcmp (op, "dacos"))  M_FUNC(acos(*M1)*DEG_RAD);
     1376  if (!strcmp (op, "datan"))  M_FUNC(atan(*M1)*DEG_RAD);
     1377  if (!strcmp (op, "not"))    M_FUNC(!(*M1));
     1378  if (!strcmp (op, "--"))     M_FUNC(-(*M1));
     1379  if (!strcmp (op, "rnd"))    M_FUNC(drand48());
     1380  if (!strcmp (op, "drnd"))   M_FUNC(drand48());
     1381  if (!strcmp (op, "lrnd"))   M_FUNC(lrand48());
     1382  if (!strcmp (op, "mrnd"))   M_FUNC(mrand48());
     1383  if (!strcmp (op, "ramp"))   M_FUNC(i);
     1384  if (!strcmp (op, "zero"))   M_FUNC(0);
     1385  if (!strcmp (op, "isinf"))  M_FUNC(!finite(*M1));
     1386  if (!strcmp (op, "isnan"))  M_FUNC(isnan(*M1));
    13801387
    13811388  /* xrm and yrm only make sense for 2D matrices. see special meaning for vectors */
  • trunk/Ohana/src/photdbc/include/photdbc.h

    r37807 r38441  
    5454char  *CATMODE;    /* raw, mef, split, mysql */
    5555char  *CATFORMAT;  /* internal, elixir, loneos, panstarrs */
     56char  *CATCOMPRESS;  /* ?? */
    5657char   PhotCodeFile[DVO_MAX_PATH];
    5758
  • trunk/Ohana/src/photdbc/src/ConfigInit.c

    r34749 r38441  
    6363  WarnConfig (config, "ZERO_PT",                "%lf", 0, &ZERO_POINT);
    6464
     65  // NOTE: in this program, CATFORMAT, CATMODE, CATCOMPRESS may only be set
     66  // as command-line options, eg: -set-format PS1_V5
     67
    6568  if (!success) {
    6669    fprintf (stderr, "missing config parameter\n");
  • trunk/Ohana/src/photdbc/src/Shutdown_dvodist.c

    r33655 r38441  
    1111
    1212  // lock the image db table
     13  gfits_db_init (&db);
    1314  int status = dvo_image_lock (&db, ImageCat, 60.0, LCK_XCLD);
    1415  if (!status) {
  • trunk/Ohana/src/photdbc/src/args.c

    r37807 r38441  
    7171    remove_argument (N, &argc, argv);
    7272    CATMODE = strcreate (argv[N]);
     73    remove_argument (N, &argc, argv);
     74  }
     75
     76  // override input catalog format (PS1_V1, PS1_REF, etc)
     77  CATCOMPRESS = NULL;
     78  if ((N = get_argument (argc, argv, "-set-compress"))) {
     79    remove_argument (N, &argc, argv);
     80    CATCOMPRESS = strcreate (argv[N]);
    7381    remove_argument (N, &argc, argv);
    7482  }
     
    257265  }
    258266
     267  // override input catalog format (PS1_V1, PS1_REF, etc)
     268  CATCOMPRESS = NULL;
     269  if ((N = get_argument (argc, argv, "-set-compress"))) {
     270    remove_argument (N, &argc, argv);
     271    CATCOMPRESS = strcreate (argv[N]);
     272    remove_argument (N, &argc, argv);
     273  }
     274
    259275  /* specify portion of the sky */
    260276  REGION.Rmin = 0;
     
    344360  fprintf (stderr, " -skip-images\n");
    345361  fprintf (stderr, " -only-images\n");
    346   fprintf (stderr, " -set-format (catformat)\n");
     362  fprintf (stderr, " -set-compress (catcompress) : NONE, GZIP_1, GZIP_2, RICE_1, AUTO\n");
     363  fprintf (stderr, " -set-format (catmode)\n");
    347364  fprintf (stderr, " -set-mode (catmode)\n");
    348365
  • trunk/Ohana/src/photdbc/src/copy_images.c

    r37807 r38441  
    1919  if (status == -1) Shutdown ("ERROR: CATDIR %s does not exist, no data in database", path);
    2020
     21  gfits_db_init (&in);
    2122  status = dvo_image_lock (&in, ImageCat, 60.0, LCK_SOFT);
    2223  if (!status) {
     
    3839
    3940  // lock the output catalog
     41  gfits_db_init (&out);
    4042  status = dvo_image_lock (&out, ImageOut, 60.0, LCK_XCLD);
    4143  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", ImageOut);
     
    4648  dvo_image_create (&out, ZERO_POINT);
    4749   
    48   image = gfits_table_get_Image (&in.ftable, &Nimage, &in.swapped);
     50  image = gfits_table_get_Image (&in.ftable, &Nimage, &in.scaledValue, &in.nativeOrder);
    4951  if (!image) {
    5052      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/photdbc/src/find_images.c

    r37807 r38441  
    2424  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    2525
    26   timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
     26  timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].scaledValue, &db[0].nativeOrder);
    2727  if (!timage) {
    2828      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/photdbc/src/flag_measures.c

    r29001 r38441  
    1515  if (VERBOSE) fprintf (stderr, "flagging bad measurements\n");
    1616
    17   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     17  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1818  if (!image) {
    1919      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/photdbc/src/join_stars.c

    r37807 r38441  
    224224  catalog[0].Naverage = Naves;
    225225  catalog[0].Nmeasure = Nmeas;
    226   catalog[0].Nsecf_mem = Naves*catalog[0].Nsecfilt;
     226  catalog[0].Nsecfilt_mem = Naves*catalog[0].Nsecfilt;
    227227 
    228228  return;
  • trunk/Ohana/src/photdbc/src/make_subcatalog.c

    r37045 r38441  
    190190  subcatalog[0].Nmeasure = Nmeasure;
    191191  subcatalog[0].Nsecfilt = Nsecfilt;
    192   subcatalog[0].Nsecf_mem = Naverage * Nsecfilt;
     192  subcatalog[0].Nsecfilt_mem = Naverage * Nsecfilt;
    193193
    194194  // XXX for now, don't copy the missing entries (these should be re-computed)
  • trunk/Ohana/src/photdbc/src/photdbc_catalogs.c

    r37807 r38441  
    2424    incatalog.filename  = hostID ? hostfile : skylist[0].filename[i];
    2525    incatalog.Nsecfilt = GetPhotcodeNsecfilt ();
    26     incatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     26    incatalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
    2727
    2828    // an error exit status here is a significant error
     
    3232    }
    3333    // skip empty input catalogs
    34     if (!incatalog.Naves_disk) {
     34    if (!incatalog.Naverage_disk) {
    3535      dvo_catalog_unlock (&incatalog);
    3636      dvo_catalog_free (&incatalog);
     
    5151
    5252    // define outcatalog open parameters
    53     outcatalog.catformat = CATFORMAT ? dvo_catalog_catformat (CATFORMAT) : incatalog.catformat;
    54     outcatalog.catmode   = CATMODE   ? dvo_catalog_catmode (CATMODE)     : incatalog.catmode;
    55     outcatalog.Nsecfilt  = incatalog.Nsecfilt;                 // inherit from the incatalog
    56     outcatalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     53    outcatalog.catformat   = CATFORMAT   ? dvo_catalog_catformat   (CATFORMAT)   : incatalog.catformat;
     54    outcatalog.catmode     = CATMODE     ? dvo_catalog_catmode     (CATMODE)     : incatalog.catmode;
     55    outcatalog.catcompress = CATCOMPRESS ? dvo_catalog_catcompress (CATCOMPRESS) : incatalog.catcompress; // set the default catcompress from config data
     56    outcatalog.Nsecfilt    = incatalog.Nsecfilt;                 // inherit from the incatalog
     57    outcatalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    5758
    5859    // output catalogs always represent the same skyregions as the input catalogs
     
    121122
    122123    // options / arguments that can affect relastro_client -update-objects:
    123     char command[DVO_MAX_PATH];
    124     snprintf (command, DVO_MAX_PATH, "photdbc_client %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -D NMEAS_MIN %d -D NMEAS_MIN_FILTERED %d -D AVE_SIGMA_LIM %f -D SIGMA_MAX %f",
     124    char *command = NULL;
     125    strextend (&command, "photdbc_client %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -D NMEAS_MIN %d -D NMEAS_MIN_FILTERED %d -D AVE_SIGMA_LIM %f -D SIGMA_MAX %f",
    125126              tmproot, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    126127              REGION.Rmin, REGION.Rmax, REGION.Dmin, REGION.Dmax,
     
    128129      );
    129130
    130     char tmpline[DVO_MAX_PATH];
    131     if (VERBOSE)            { snprintf (tmpline, DVO_MAX_PATH, "%s -v",                command);                             strcpy (command, tmpline); }
    132     if (ExcludeByInstMag)   { snprintf (tmpline, DVO_MAX_PATH, "%s -instmag %f %f",    command, INST_MAG_MIN, INST_MAG_MAX); strcpy (command, tmpline); }
    133     if (ExcludeByMinSigma)  { snprintf (tmpline, DVO_MAX_PATH, "%s -min-sigma %f",     command, SIGMA_MIN_KEEP);                strcpy (command, tmpline); }
    134     if (ExcludeByMaxMinMag) { snprintf (tmpline, DVO_MAX_PATH, "%s -maxminmag %f",     command, MAX_MIN_MAG);                   strcpy (command, tmpline); }
    135     if (PHOTCODE_DROP_LIST) { snprintf (tmpline, DVO_MAX_PATH, "%s -photcode-drop %s", command, PHOTCODE_DROP_LIST);    strcpy (command, tmpline); }
    136     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, DVO_MAX_PATH, "%s -photcode-keep %s", command, PHOTCODE_KEEP_LIST);    strcpy (command, tmpline); }
    137     if (CATFORMAT)          { snprintf (tmpline, DVO_MAX_PATH, "%s -set-format %s",    command, CATFORMAT);                     strcpy (command, tmpline); }
    138     if (CATMODE)            { snprintf (tmpline, DVO_MAX_PATH, "%s -set-mode %s",      command, CATMODE);                       strcpy (command, tmpline); }
     131    if (VERBOSE)            { strextend (&command, "-v"); }
     132    if (ExcludeByInstMag)   { strextend (&command, "-instmag %f %f", INST_MAG_MIN, INST_MAG_MAX); }
     133    if (ExcludeByMinSigma)  { strextend (&command, "-min-sigma %f", SIGMA_MIN_KEEP); }
     134    if (ExcludeByMaxMinMag) { strextend (&command, "-maxminmag %f", MAX_MIN_MAG); }
     135    if (PHOTCODE_DROP_LIST) { strextend (&command, "-photcode-drop %s", PHOTCODE_DROP_LIST); }
     136    if (PHOTCODE_KEEP_LIST) { strextend (&command, "-photcode-keep %s", PHOTCODE_KEEP_LIST); }
     137    if (CATCOMPRESS)        { strextend (&command, "-set-compress %s", CATCOMPRESS); }
     138    if (CATFORMAT)          { strextend (&command, "-set-format %s", CATFORMAT); }
     139    if (CATMODE)            { strextend (&command, "-set-mode %s", CATMODE); }
    139140
    140141    if (PARALLEL_OUTHOSTS) {
     
    142143      free  (table_output->hosts[i].pathname);
    143144      table_output->hosts[i].pathname = tmppath;
    144       snprintf (tmpline, DVO_MAX_PATH, "%s -hostdir-output %s", command, table_output->hosts[i].pathname); strcpy (command, tmpline);
     145      strextend (&command, "-hostdir-output %s", table_output->hosts[i].pathname);
    145146    }
    146147
  • trunk/Ohana/src/relastro/include/relastro.h

    r38062 r38441  
    539539int hpm_objects (SkyRegion *region, Catalog *catalog);
    540540
    541 int strextend (char *input, char *format,...);
    542541int launch_region_hosts (RegionHostTable *regionHosts);
    543542
     
    591590float getColorBlue (off_t meas, int cat);
    592591float getColorRed (off_t meas, int cat);
    593 
    594 int strextend (char *input, char *format,...);
    595592
    596593int areImagesLoaded ();
  • trunk/Ohana/src/relastro/src/BrightCatalog.c

    r38062 r38441  
    172172    GET_COLUMN(Nmeasure,       "NMEASURE",       short);
    173173    GET_COLUMN(Nmissing,       "NMISSING",       short);
    174     GET_COLUMN(Nextend,        "NEXTEND",        short);
     174    GET_COLUMN(Ngalphot,      "NGALPHOT",      short);
    175175    GET_COLUMN(measureOffset,  "OFF_MEASURE",    int);
    176176    GET_COLUMN(missingOffset,  "OFF_MISSING",    int);
     
    208208      average[i].Nmeasure        = Nmeasure[i]        ;
    209209      average[i].Nmissing        = Nmissing[i]        ;
    210       average[i].Nextend         = Nextend[i]         ;
     210      average[i].Ngalphot       = Ngalphot[i]         ;
    211211      average[i].measureOffset   = measureOffset[i]   ;
    212212      average[i].missingOffset   = missingOffset[i]   ;
     
    241241    free (Nmeasure);
    242242    free (Nmissing);
    243     free (Nextend);
     243    free (Ngalphot);
    244244    free (measureOffset);
    245245    free (missingOffset);
     
    502502    gfits_define_bintable_column (&theader, "I", "NMEASURE",       "number of psf measurements",                          "", 1.0, 0.0);
    503503    gfits_define_bintable_column (&theader, "I", "NMISSING",       "number of missings",                                  "", 1.0, 0.0);
    504     gfits_define_bintable_column (&theader, "I", "NEXTEND",        "number of extended measurements",                     "", 1.0, 0.0);
     504    gfits_define_bintable_column (&theader, "I", "NGALPHOT",      "number of galaxy shape measurements",                 "", 1.0, 0.0);
    505505    gfits_define_bintable_column (&theader, "J", "OFF_MEASURE",    "offset to first psf measurement",                     "", 1.0, 0.0);
    506506    gfits_define_bintable_column (&theader, "J", "OFF_MISSING",    "offset to first missing obs",                         "", 1.0, 0.0);
     
    537537    short    *Nmeasure      ; ALLOCATE (Nmeasure      , short   , catalog->Naverage);
    538538    short    *Nmissing      ; ALLOCATE (Nmissing      , short   , catalog->Naverage);
    539     short    *Nextend       ; ALLOCATE (Nextend       , short   , catalog->Naverage);
     539    short    *Ngalphot     ; ALLOCATE (Ngalphot     , short   , catalog->Naverage);
    540540    int      *measureOffset ; ALLOCATE (measureOffset , int     , catalog->Naverage);
    541541    int      *missingOffset ; ALLOCATE (missingOffset , int     , catalog->Naverage);
     
    571571      Nmeasure[i]        = average[i].Nmeasure        ;
    572572      Nmissing[i]        = average[i].Nmissing        ;
    573       Nextend[i]         = average[i].Nextend         ;
     573      Ngalphot[i]       = average[i].Ngalphot       ;
    574574      measureOffset[i]   = average[i].measureOffset   ;
    575575      missingOffset[i]   = average[i].missingOffset   ;
     
    604604    gfits_set_bintable_column (&theader, &ftable, "NMEASURE",       Nmeasure,        catalog->Naverage);
    605605    gfits_set_bintable_column (&theader, &ftable, "NMISSING",       Nmissing,        catalog->Naverage);
    606     gfits_set_bintable_column (&theader, &ftable, "NEXTEND",        Nextend,         catalog->Naverage);
     606    gfits_set_bintable_column (&theader, &ftable, "NGALPHOT",      Ngalphot,       catalog->Naverage);
    607607    gfits_set_bintable_column (&theader, &ftable, "OFF_MEASURE",    measureOffset,   catalog->Naverage);
    608608    gfits_set_bintable_column (&theader, &ftable, "OFF_MISSING",    missingOffset,   catalog->Naverage);
     
    635635    free (Nmeasure);
    636636    free (Nmissing);
    637     free (Nextend);
     637    free (Ngalphot);
    638638    free (measureOffset);
    639639    free (missingOffset);
  • trunk/Ohana/src/relastro/src/ImageTable.c

    r36630 r38441  
    77  FITS_DB db;
    88
     9  gfits_db_init (&db);
    910  db.mode   = dvo_catalog_catmode (CATMODE);
    1011  db.format = dvo_catalog_catformat (CATFORMAT);
     
    2728  // convert database table to internal structure (binary to Image)
    2829  // 'image' points to the same memory as db->ftable->buffer
    29   Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     30  Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    3031  if (!image) {
    3132    Shutdown ("ERROR: failed to read images");
     
    4243
    4344  // setup image table format and lock
     45  gfits_db_init (&db);
    4446  db.mode   = dvo_catalog_catmode (CATMODE);
    4547  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r37807 r38441  
    3434    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    3535    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    36     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     36    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    3737    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3838
     
    4141      exit (1);
    4242    }
    43     if (!catalog.Naves_disk) {
     43    if (!catalog.Naverage_disk) {
    4444      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    4545      dvo_catalog_unlock (&catalog);
     
    102102
    103103  int Ngroups;
    104   HostTableGroup *groups = HostTableGroups (table, &Ngroups);
     104  HostTableGroup *groups = HostTableGroupsUniqueMachines (table, &Ngroups);
    105105  // split the table into Ngroups, each with a unique set of machines (this avoids overloading the remote host machines)
    106106
     
    152152    // MaxDensityUse, MaxDensityValue
    153153
    154     char command[1024];
    155     snprintf (command, 1024, "relastro_client -update-offsets -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f",
     154    char *command = NULL;
     155    strextend (&command, "relastro_client -update-offsets -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f",
    156156              group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR);
    157157
    158     if (FIT_MODE == FIT_PM_ONLY)         strextend (command, "-pm");
    159     if (FIT_MODE == FIT_PAR_ONLY)        strextend (command, "-par");
    160     if (FIT_MODE == FIT_PM_AND_PAR)      strextend (command, "-pmpar");
    161 
    162     if (VERBOSE)       strextend (command, "-v");
    163     if (VERBOSE2)      strextend (command, "-vv");
    164     if (RESET)         strextend (command, "-reset");
    165     if (UPDATE)        strextend (command, "-update");
    166 
    167     if (RESET_BAD_IMAGES) strextend (command, "-reset-bad-images");
    168 
    169     if (ImagSelect)    strextend (command, "-instmag %f %f", ImagMin, ImagMax);
    170     if (MaxDensityUse) strextend (command, "-max-density %f", MaxDensityValue);
    171    
    172     if (USE_BASIC_CHECK) strextend (command, "-basic-image-search");
    173     if (FlagOutlier)     strextend (command, "-clip %d", CLIP_THRESH);
    174     if (ExcludeBogus)    strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
    175    
    176     if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
    177 
    178     if (PHOTCODE_KEEP_LIST) strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
    179     if (PHOTCODE_SKIP_LIST) strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
    180     if (PhotFlagSelect)     strextend (command, "+photflags");
    181     if (PhotFlagBad)        strextend (command, "+photflagbad %d", PhotFlagBad);
    182     if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
     158    if (FIT_MODE == FIT_PM_ONLY)         strextend (&command, "-pm");
     159    if (FIT_MODE == FIT_PAR_ONLY)        strextend (&command, "-par");
     160    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (&command, "-pmpar");
     161
     162    if (VERBOSE)       strextend (&command, "-v");
     163    if (VERBOSE2)      strextend (&command, "-vv");
     164    if (RESET)         strextend (&command, "-reset");
     165    if (UPDATE)        strextend (&command, "-update");
     166
     167    if (RESET_BAD_IMAGES) strextend (&command, "-reset-bad-images");
     168
     169    if (ImagSelect)    strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     170    if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue);
     171   
     172    if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");
     173    if (FlagOutlier)     strextend (&command, "-clip %d", CLIP_THRESH);
     174    if (ExcludeBogus)    strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
     175   
     176    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
     177
     178    if (PHOTCODE_KEEP_LIST) strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
     179    if (PHOTCODE_SKIP_LIST) strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
     180    if (PhotFlagSelect)     strextend (&command, "+photflags");
     181    if (PhotFlagBad)        strextend (&command, "+photflagbad %d", PhotFlagBad);
     182    if (PhotFlagPoor)       strextend (&command, "+photflagpoor %d", PhotFlagPoor);
    183183    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    184184
    185185    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    186       strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     186      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    187187    }
    188188    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
    189       strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    190     }
    191 
    192     if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
    193     if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     189      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     190    }
     191
     192    if (MinBadQF > 0.0)        strextend (&command, "-min-bad-psfqf %f", MinBadQF);
     193    if (MaxMeanOffset != 10.0) strextend (&command, "-max-mean-offset  %f", MaxMeanOffset);
    194194
    195195    if (TimeSelect) {
    196196      char *tstart = ohana_sec_to_date (TSTART);
    197197      char *tstop  = ohana_sec_to_date (TSTOP);
    198       strextend (command, "-time %s %s", tstart, tstop);
     198      strextend (&command, "-time %s %s", tstart, tstop);
    199199      free (tstart);
    200200      free (tstop);
     
    270270    // MaxDensityUse, MaxDensityValue
    271271
    272     char command[1024];
    273     snprintf (command, 1024, "relastro_client -update-offsets -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f",
     272    char *command = NULL;
     273    strextend (&command, "relastro_client -update-offsets -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f",
    274274              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR);
    275275
    276     if (FIT_MODE == FIT_PM_ONLY)         strextend (command, "-pm");
    277     if (FIT_MODE == FIT_PAR_ONLY)        strextend (command, "-par");
    278     if (FIT_MODE == FIT_PM_AND_PAR)      strextend (command, "-pmpar");
    279 
    280     if (VERBOSE)       strextend (command, "-v");
    281     if (VERBOSE2)      strextend (command, "-vv");
    282     if (RESET)         strextend (command, "-reset");
    283     if (UPDATE)        strextend (command, "-update");
    284 
    285     if (RESET_BAD_IMAGES) strextend (command, "-reset-bad-images");
    286 
    287     if (ImagSelect)    strextend (command, "-instmag %f %f", ImagMin, ImagMax);
    288     if (MaxDensityUse) strextend (command, "-max-density %f", MaxDensityValue);
    289    
    290     if (USE_BASIC_CHECK) strextend (command, "-basic-image-search");
    291     if (FlagOutlier)     strextend (command, "-clip %d", CLIP_THRESH);
    292     if (ExcludeBogus)    strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
    293    
    294     if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
    295 
    296     if (PHOTCODE_KEEP_LIST) strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
    297     if (PHOTCODE_SKIP_LIST) strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
    298     if (PhotFlagSelect)     strextend (command, "+photflags");
    299     if (PhotFlagBad)        strextend (command, "+photflagbad %d", PhotFlagBad);
    300     if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
     276    if (FIT_MODE == FIT_PM_ONLY)         strextend (&command, "-pm");
     277    if (FIT_MODE == FIT_PAR_ONLY)        strextend (&command, "-par");
     278    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (&command, "-pmpar");
     279
     280    if (VERBOSE)       strextend (&command, "-v");
     281    if (VERBOSE2)      strextend (&command, "-vv");
     282    if (RESET)         strextend (&command, "-reset");
     283    if (UPDATE)        strextend (&command, "-update");
     284
     285    if (RESET_BAD_IMAGES) strextend (&command, "-reset-bad-images");
     286
     287    if (ImagSelect)    strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     288    if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue);
     289   
     290    if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");
     291    if (FlagOutlier)     strextend (&command, "-clip %d", CLIP_THRESH);
     292    if (ExcludeBogus)    strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
     293   
     294    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
     295
     296    if (PHOTCODE_KEEP_LIST) strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
     297    if (PHOTCODE_SKIP_LIST) strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
     298    if (PhotFlagSelect)     strextend (&command, "+photflags");
     299    if (PhotFlagBad)        strextend (&command, "+photflagbad %d", PhotFlagBad);
     300    if (PhotFlagPoor)       strextend (&command, "+photflagpoor %d", PhotFlagPoor);
    301301    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    302302
    303303    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    304       strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     304      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    305305    }
    306306    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
    307       strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    308     }
    309 
    310     if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
    311     if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     307      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     308    }
     309
     310    if (MinBadQF > 0.0)        strextend (&command, "-min-bad-psfqf %f", MinBadQF);
     311    if (MaxMeanOffset != 10.0) strextend (&command, "-max-mean-offset  %f", MaxMeanOffset);
    312312
    313313    if (TimeSelect) {
    314314      char *tstart = ohana_sec_to_date (TSTART);
    315315      char *tstop  = ohana_sec_to_date (TSTOP);
    316       strextend (command, "-time %s %s", tstart, tstop);
     316      strextend (&command, "-time %s %s", tstart, tstop);
    317317      free (tstart);
    318318      free (tstop);
  • trunk/Ohana/src/relastro/src/args.c

    r37807 r38441  
    959959}
    960960
    961 int strextend (char *input, char *format,...) {
    962 
    963   char tmpextra[1024], tmpline[1024];
    964   va_list argp;
    965 
    966   va_start (argp, format);
    967   vsnprintf (tmpextra, 1024, format, argp);
    968   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    969   strcpy (input, tmpline);
    970 
    971   return TRUE;
    972 }
  • trunk/Ohana/src/relastro/src/assign_images.c

    r37807 r38441  
    1111  // convert database table to internal structure (binary to Image)
    1212  // 'image' points to the same memory as db->ftable->buffer
    13   Image *image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     13  Image *image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1414  if (!image) {
    1515      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r37807 r38441  
    521521  subcatalog[0].Nmeasure = Nmeasure;
    522522  subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt;
    523   subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt;
     523  subcatalog[0].Nsecfilt_mem = Naverage * oldcatalog[0].Nsecfilt;
    524524
    525525  return (TRUE);
     
    628628  subcatalog[0].Nmeasure = Nmeasure;
    629629  subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt;
    630   subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt;
     630  subcatalog[0].Nsecfilt_mem = Naverage * oldcatalog[0].Nsecfilt;
    631631
    632632  return (TRUE);
     
    722722  subcatalog[0].Nmeasure = Nmeasure;
    723723  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
    724   subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     724  subcatalog[0].Nsecfilt_mem = Naverage * catalog[0].Nsecfilt;
    725725
    726726  return (TRUE);
  • trunk/Ohana/src/relastro/src/high_speed_catalogs.c

    r35763 r38441  
    3131    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    3232    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    33     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     33    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    3434    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3535
     
    3838      exit (1);
    3939    }
    40     if (!catalog.Naves_disk) {
     40    if (!catalog.Naverage_disk) {
    4141      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    4242      dvo_catalog_unlock (&catalog);
     
    147147    }
    148148
    149     char command[1024];
    150     snprintf (command, 1024, "relastro_client -high-speed %s %s %f %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f",
     149    char *command = NULL;
     150    strextend (&command, "relastro_client -high-speed %s %s %f %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f",
    151151              PHOTCODE_A_LIST, PHOTCODE_B_LIST, RADIUS, outputDir, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    152152
     
    154154
    155155    // options / arguments that can affect relastro_client -high-speed
    156     char tmpline[1024];
    157     if (FIT_MODE == FIT_PM_ONLY)         { snprintf (tmpline, 1024, "%s -pm",    command);              strcpy (command, tmpline); }
    158     if (FIT_MODE == FIT_PAR_ONLY)        { snprintf (tmpline, 1024, "%s -par",   command);              strcpy (command, tmpline); }
    159     if (FIT_MODE == FIT_PM_AND_PAR)      { snprintf (tmpline, 1024, "%s -pmpar", command);              strcpy (command, tmpline); }
    160 
    161     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                       strcpy (command, tmpline); }
    162     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                       strcpy (command, tmpline); }
    163     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                       strcpy (command, tmpline); }
    164     if (ImagSelect)    { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax);     strcpy (command, tmpline); }
    165     if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue);      strcpy (command, tmpline); }
     156    if (FIT_MODE == FIT_PM_ONLY)         { strextend (&command, "-pm"); }
     157    if (FIT_MODE == FIT_PAR_ONLY)        { strextend (&command, "-par"); }
     158    if (FIT_MODE == FIT_PM_AND_PAR)      { strextend (&command, "-pmpar"); }
     159
     160    if (VERBOSE)       { strextend (&command, "-v"); }
     161    if (VERBOSE2)      { strextend (&command, "-vv"); }
     162    if (RESET)         { strextend (&command, "-reset"); }
     163    if (ImagSelect)    { strextend (&command, "-instmag %f %f", ImagMin, ImagMax); }
     164    if (MaxDensityUse) { strextend (&command, "-max-density %f", MaxDensityValue); }
    166165   
    167     if (USE_BASIC_CHECK) { snprintf (tmpline, 1024, "%s -basic-image-search", command);                 strcpy (command, tmpline); }
    168 
    169     if (FlagOutlier)   { snprintf (tmpline, 1024, "%s -clip %d",        command, CLIP_THRESH);          strcpy (command, tmpline); }
    170    
    171     if (USE_FIXED_PIXCOORDS) { snprintf (tmpline, 1024, "%s -D USE_FIXED_PIXCOORDS 1", command);     strcpy (command, tmpline); }
    172 
    173     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
    174     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
    175     if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                      strcpy (command, tmpline); }
    176     if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);      strcpy (command, tmpline); }
    177     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);    strcpy (command, tmpline); }
     166    if (USE_BASIC_CHECK)     { strextend (&command, "-basic-image-search"); }
     167    if (FlagOutlier)         { strextend (&command, "-clip %d", CLIP_THRESH); }
     168    if (USE_FIXED_PIXCOORDS) { strextend (&command, "-D USE_FIXED_PIXCOORDS 1"); }
     169    if (PHOTCODE_KEEP_LIST)  { strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST); }
     170    if (PHOTCODE_SKIP_LIST)  { strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST); }
     171    if (PhotFlagSelect)      { strextend (&command, "+photflags"); }
     172    if (PhotFlagBad)         { strextend (&command, "+photflagbad %d", PhotFlagBad); }
     173    if (PhotFlagPoor)        { strextend (&command, "+photflagpoor %d", PhotFlagPoor); }
    178174    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    179175
    180     if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
    181     if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
    182 
    183     if (WHERE_A[0]) { snprintf (tmpline, 1024, "%s -D WHERE_A \"%s\"", command, WHERE_A);               strcpy (command, tmpline); }
    184     if (WHERE_B[0]) { snprintf (tmpline, 1024, "%s -D WHERE_B \"%s\"", command, WHERE_B);               strcpy (command, tmpline); }
     176    if (MinBadQF > 0.0)        { strextend (&command, "-min-bad-psfqf %f", MinBadQF); }
     177    if (MaxMeanOffset != 10.0) { strextend (&command, "-max-mean-offset  %f", MaxMeanOffset); }
     178
     179    if (WHERE_A[0]) { strextend (&command, "-D WHERE_A \"%s\"", WHERE_A); }
     180    if (WHERE_B[0]) { strextend (&command, "-D WHERE_B \"%s\"", WHERE_B); }
    185181
    186182    if (TimeSelect) {
    187183      char *tstart = ohana_sec_to_date (TSTART);
    188184      char *tstop  = ohana_sec_to_date (TSTOP);
    189       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     185      strextend (&command, "-time %s %s", tstart, tstop);
    190186      free (tstart);
    191187      free (tstop);
    192       strcpy (command, tmpline);
    193188    }
    194189
  • trunk/Ohana/src/relastro/src/high_speed_objects.c

    r37807 r38441  
    3232  catalogOut.filename = filename; // based on the input name, need to keep everything below the catdir portion
    3333  catalogOut.Nsecfilt = Nsecfilt;
    34   catalogOut.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF; // load all data
     34  catalogOut.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT; // load all data
    3535 
    3636  catalogOut.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     
    263263  catalogOut.Nmeasure=Nmatchmeas;
    264264  catalogOut.Nsecfilt=Nsecfilt;
    265   catalogOut.Nsecf_mem=Nmatch*Nsecfilt;
     265  catalogOut.Nsecfilt_mem=Nmatch*Nsecfilt;
    266266
    267267  populate_tiny_values (&catalogOut, DVO_TV_MEASURE);
  • trunk/Ohana/src/relastro/src/hpm_catalogs.c

    r35763 r38441  
    2929    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    3030    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    31     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     31    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    3232    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3333
     
    3636      exit (1);
    3737    }
    38     if (!catalog.Naves_disk) {
     38    if (!catalog.Naverage_disk) {
    3939      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    4040      dvo_catalog_unlock (&catalog);
     
    145145    }
    146146
    147     char command[1024];
    148     snprintf (command, 1024, "relastro_client -hpm %f %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f",
     147    char *command = NULL;
     148    strextend (&command, "relastro_client -hpm %f %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f",
    149149              RADIUS, outputDir, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    150150
     
    152152
    153153    // options / arguments that can affect relastro_client -high-speed
    154     char tmpline[1024];
    155     if (FIT_MODE == FIT_PM_ONLY)         { snprintf (tmpline, 1024, "%s -pm",    command);              strcpy (command, tmpline); }
    156     if (FIT_MODE == FIT_PAR_ONLY)        { snprintf (tmpline, 1024, "%s -par",   command);              strcpy (command, tmpline); }
    157     if (FIT_MODE == FIT_PM_AND_PAR)      { snprintf (tmpline, 1024, "%s -pmpar", command);              strcpy (command, tmpline); }
    158 
    159     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                       strcpy (command, tmpline); }
    160     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                       strcpy (command, tmpline); }
    161     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                       strcpy (command, tmpline); }
    162     if (ImagSelect)    { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax);     strcpy (command, tmpline); }
    163     if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue);      strcpy (command, tmpline); }
     154    if (FIT_MODE == FIT_PM_ONLY)         { strextend (&command, "-pm"); }
     155    if (FIT_MODE == FIT_PAR_ONLY)        { strextend (&command, "-par"); }
     156    if (FIT_MODE == FIT_PM_AND_PAR)      { strextend (&command, "-pmpar"); }
     157
     158    if (VERBOSE)       { strextend (&command, "-v"); }
     159    if (VERBOSE2)      { strextend (&command, "-vv"); }
     160    if (RESET)         { strextend (&command, "-reset"); }
     161    if (ImagSelect)    { strextend (&command, "-instmag %f %f", ImagMin, ImagMax); }
     162    if (MaxDensityUse) { strextend (&command, "-max-density %f", MaxDensityValue); }
    164163   
    165     if (USE_BASIC_CHECK) { snprintf (tmpline, 1024, "%s -basic-image-search", command);                 strcpy (command, tmpline); }
    166 
    167     if (FlagOutlier)   { snprintf (tmpline, 1024, "%s -clip %d",        command, CLIP_THRESH);          strcpy (command, tmpline); }
    168    
    169     if (USE_FIXED_PIXCOORDS) { snprintf (tmpline, 1024, "%s -D USE_FIXED_PIXCOORDS 1", command);     strcpy (command, tmpline); }
    170 
    171     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
    172     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
    173     if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                      strcpy (command, tmpline); }
    174     if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);      strcpy (command, tmpline); }
    175     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);    strcpy (command, tmpline); }
     164    if (USE_BASIC_CHECK)     { strextend (&command, "-basic-image-search"); }
     165    if (FlagOutlier)         { strextend (&command, "-clip %d", CLIP_THRESH); }
     166    if (USE_FIXED_PIXCOORDS) { strextend (&command, "-D USE_FIXED_PIXCOORDS 1"); }
     167    if (PHOTCODE_KEEP_LIST)  { strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST); }
     168    if (PHOTCODE_SKIP_LIST)  { strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST); }
     169    if (PhotFlagSelect)      { strextend (&command, "+photflags"); }
     170    if (PhotFlagBad)         { strextend (&command, "+photflagbad %d", PhotFlagBad); }
     171    if (PhotFlagPoor)        { strextend (&command, "+photflagpoor %d", PhotFlagPoor); }
    176172    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    177173
    178     if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
    179     if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
     174    if (MinBadQF > 0.0)        { strextend (&command, "-min-bad-psfqf %f", MinBadQF); }
     175    if (MaxMeanOffset != 10.0) { strextend (&command, "-max-mean-offset  %f", MaxMeanOffset); }
    180176
    181177    if (TimeSelect) {
    182178      char *tstart = ohana_sec_to_date (TSTART);
    183179      char *tstop  = ohana_sec_to_date (TSTOP);
    184       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     180      strextend (&command, "-time %s %s", tstart, tstop);
    185181      free (tstart);
    186182      free (tstop);
    187       strcpy (command, tmpline);
    188183    }
    189184
  • trunk/Ohana/src/relastro/src/hpm_objects.c

    r37807 r38441  
    3333  catalogOut.filename = filename;
    3434  catalogOut.Nsecfilt = Nsecfilt;
    35   catalogOut.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF; // load all data
     35  catalogOut.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT; // load all data
    3636 
    3737  catalogOut.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     
    279279  }
    280280  catalogOut.Nsecfilt = Nsecfilt;
    281   catalogOut.Nsecf_mem = Nsecfilt * catalogOut.Naverage;
     281  catalogOut.Nsecfilt_mem = Nsecfilt * catalogOut.Naverage;
    282282
    283283  populate_tiny_values (&catalogOut, DVO_TV_MEASURE);
  • trunk/Ohana/src/relastro/src/launch_region_hosts.c

    r37807 r38441  
    7777    }
    7878
    79     char command[1024];
    80     snprintf (command, 1024, "relastro -parallel-images %s", filename);
    81     strextend (command, "-region-hosts %s", REGION_FILE);
    82     strextend (command, "-region-hostID %d", host->hostID);
    83     strextend (command, "-D CATDIR %s", CATDIR);
    84     strextend (command, "-region %f %f %f %f", host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat);
    85     strextend (command, "-statmode %s", STATMODE);
    86     strextend (command, "-minerror %f", MIN_ERROR);
    87     strextend (command, "-nloop %d", NLOOP);
    88     strextend (command, "-threads %d", NTHREADS);
     79    char *command = NULL;
     80    strextend (&command, "relastro -parallel-images %s", filename);
     81    strextend (&command, "-region-hosts %s", REGION_FILE);
     82    strextend (&command, "-region-hostID %d", host->hostID);
     83    strextend (&command, "-D CATDIR %s", CATDIR);
     84    strextend (&command, "-region %f %f %f %f", host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat);
     85    strextend (&command, "-statmode %s", STATMODE);
     86    strextend (&command, "-minerror %f", MIN_ERROR);
     87    strextend (&command, "-nloop %d", NLOOP);
     88    strextend (&command, "-threads %d", NTHREADS);
    8989
    9090    switch (FIT_TARGET) {
    9191      case TARGET_SIMPLE:
    92         strextend (command, "-update-simple");
     92        strextend (&command, "-update-simple");
    9393        break;
    9494      case TARGET_CHIPS:
    95         strextend (command, "-update-chips");
     95        strextend (&command, "-update-chips");
    9696        break;
    9797      case TARGET_MOSAICS:
    98         strextend (command, "-update-mosaics");
     98        strextend (&command, "-update-mosaics");
    9999        break;
    100100      case TARGET_NONE:
     
    102102    }
    103103
    104     if (VERBOSE)            strextend (command, "-v");
    105     if (VERBOSE2)           strextend (command, "-vv");
    106     if (RESET)              strextend (command, "-reset");
    107     if (UPDATE)             strextend (command, "-update");
    108     if (PARALLEL)           strextend (command, "-parallel");
    109     if (PARALLEL_MANUAL)    strextend (command, "-parallel-manual");
    110     if (PARALLEL_SERIAL)    strextend (command, "-parallel-serial");
    111     if (PHOTCODE_KEEP_LIST) strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
    112     if (PHOTCODE_SKIP_LIST) strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
    113     if (PHOTCODE_RESET_LIST) strextend (command, "-reset-to-photcode %s", PHOTCODE_RESET_LIST);
     104    if (VERBOSE)            strextend (&command, "-v");
     105    if (VERBOSE2)           strextend (&command, "-vv");
     106    if (RESET)              strextend (&command, "-reset");
     107    if (UPDATE)             strextend (&command, "-update");
     108    if (PARALLEL)           strextend (&command, "-parallel");
     109    if (PARALLEL_MANUAL)    strextend (&command, "-parallel-manual");
     110    if (PARALLEL_SERIAL)    strextend (&command, "-parallel-serial");
     111    if (PHOTCODE_KEEP_LIST) strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
     112    if (PHOTCODE_SKIP_LIST) strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
     113    if (PHOTCODE_RESET_LIST) strextend (&command, "-reset-to-photcode %s", PHOTCODE_RESET_LIST);
    114114
    115     if (MaxDensityUse)      strextend (command, "-max-density %f", MaxDensityValue);
    116     if (ImagSelect)         strextend (command, "-instmag %f %f", ImagMin, ImagMax);
    117     if (ExcludeBogus)       strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
     115    if (MaxDensityUse)      strextend (&command, "-max-density %f", MaxDensityValue);
     116    if (ImagSelect)         strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     117    if (ExcludeBogus)       strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
    118118
    119119    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    120       strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     120      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    121121    }
    122122    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
    123       strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     123      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    124124    }
    125125
    126     if (PhotFlagSelect)     strextend (command, "+photflags");
    127     if (PhotFlagBad)        strextend (command, "+photflagbad %d", PhotFlagBad);
    128     if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
     126    if (PhotFlagSelect)     strextend (&command, "+photflags");
     127    if (PhotFlagBad)        strextend (&command, "+photflagbad %d", PhotFlagBad);
     128    if (PhotFlagPoor)       strextend (&command, "+photflagpoor %d", PhotFlagPoor);
    129129
    130     if (CHIPMAP)            strextend (command, "-chipmap %d", CHIPMAP);
    131     if (RESET_IMAGES)       strextend (command, "-reset-images");
     130    if (CHIPMAP)            strextend (&command, "-chipmap %d", CHIPMAP);
     131    if (RESET_IMAGES)       strextend (&command, "-reset-images");
    132132
    133     if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
    134     if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     133    if (MinBadQF > 0.0)        strextend (&command, "-min-bad-psfqf %f", MinBadQF);
     134    if (MaxMeanOffset != 10.0) strextend (&command, "-max-mean-offset  %f", MaxMeanOffset);
    135135
    136     strextend (command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
    137     strextend (command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
    138     strextend (command, "-D RELASTRO_DPOS_MAX %f", DPOS_MAX);
    139     strextend (command, "-D ADDSTAR_RADIUS %f", ADDSTAR_RADIUS);
     136    strextend (&command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
     137    strextend (&command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
     138    strextend (&command, "-D RELASTRO_DPOS_MAX %f", DPOS_MAX);
     139    strextend (&command, "-D ADDSTAR_RADIUS %f", ADDSTAR_RADIUS);
    140140
    141     strextend (command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
     141    strextend (&command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
    142142
    143     strextend (command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
    144     strextend (command, "-D USE_ICRF_LOCAL %d",   USE_ICRF_LOCAL);
    145     strextend (command, "-D USE_ICRF_SHFIT %d",   USE_ICRF_SHFIT);
    146     strextend (command, "-D USE_ICRF_POLE %d",    USE_ICRF_POLE);
     143    strextend (&command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     144    strextend (&command, "-D USE_ICRF_LOCAL %d",   USE_ICRF_LOCAL);
     145    strextend (&command, "-D USE_ICRF_SHFIT %d",   USE_ICRF_SHFIT);
     146    strextend (&command, "-D USE_ICRF_POLE %d",    USE_ICRF_POLE);
    147147
    148     if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
     148    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
    149149
    150150    if (TimeSelect) {
    151151      char *tstart = ohana_sec_to_date (TSTART);
    152152      char *tstop  = ohana_sec_to_date (TSTOP);
    153       strextend (command, "-time %s %s", tstart, tstop);
     153      strextend (&command, "-time %s %s", tstart, tstop);
    154154      free (tstart);
    155155      free (tstop);
  • trunk/Ohana/src/relastro/src/load_catalogs.c

    r38062 r38441  
    4040    pcatalog->catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    4141    pcatalog->catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    42     pcatalog->catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF; // don't need to load all data at this point
     42    pcatalog->catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT; // don't need to load all data at this point
    4343    pcatalog->Nsecfilt  = GetPhotcodeNsecfilt ();
    4444
     
    4848      exit (1);
    4949    }
    50     if (!pcatalog[0].Naves_disk) {
     50    if (!pcatalog[0].Naverage_disk) {
    5151      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename);
    5252      dvo_catalog_unlock (pcatalog);
     
    160160    // MaxDensityUse, MaxDensityValue
    161161
    162     char command[1024];
    163     snprintf (command, 1024, "relastro_client -load-objects %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f -D RELASTRO_SIGMA_LIM %f",
     162    char *command = NULL;
     163    strextend (&command, "relastro_client -load-objects %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f -D RELASTRO_SIGMA_LIM %f",
    164164              table->hosts[i].results, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR, SIGMA_LIM);
    165165
    166     if (FIT_MODE == FIT_PM_ONLY)         strextend (command, "-pm");
    167     if (FIT_MODE == FIT_PAR_ONLY)        strextend (command, "-par");
    168     if (FIT_MODE == FIT_PM_AND_PAR)      strextend (command, "-pmpar");
    169 
    170     if (VERBOSE)       strextend (command, "-v");
    171     if (VERBOSE2)      strextend (command, "-vv");
    172     if (RESET)         strextend (command, "-reset");
    173     if (ImagSelect)    strextend (command, "-instmag %f %f", ImagMin, ImagMax);
    174     if (MaxDensityUse) strextend (command, "-max-density %f", MaxDensityValue);
    175     if (FlagOutlier)   strextend (command, "-clip %d", CLIP_THRESH);
    176     if (ExcludeBogus)  strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
    177 
    178     if (USE_ICRF_CORRECT) strextend (command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
    179     if (USE_GALAXY_MODEL) strextend (command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
     166    if (FIT_MODE == FIT_PM_ONLY)         strextend (&command, "-pm");
     167    if (FIT_MODE == FIT_PAR_ONLY)        strextend (&command, "-par");
     168    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (&command, "-pmpar");
     169
     170    if (VERBOSE)       strextend (&command, "-v");
     171    if (VERBOSE2)      strextend (&command, "-vv");
     172    if (RESET)         strextend (&command, "-reset");
     173    if (ImagSelect)    strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     174    if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue);
     175    if (FlagOutlier)   strextend (&command, "-clip %d", CLIP_THRESH);
     176    if (ExcludeBogus)  strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
     177
     178    if (USE_ICRF_CORRECT) strextend (&command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     179    if (USE_GALAXY_MODEL) strextend (&command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
    180180   
    181181    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    182       strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     182      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    183183    }
    184184    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
    185       strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    186     }
    187 
    188     if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
    189     if (PHOTCODE_KEEP_LIST)  strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
    190     if (PHOTCODE_SKIP_LIST)  strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
    191     if (PhotFlagSelect)      strextend (command, "+photflags");
    192     if (PhotFlagBad)         strextend (command, "+photflagbad %d", PhotFlagBad);
    193     if (PhotFlagPoor)        strextend (command, "+photflagpoor %d", PhotFlagPoor);
     185      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     186    }
     187
     188    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
     189    if (PHOTCODE_KEEP_LIST)  strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
     190    if (PHOTCODE_SKIP_LIST)  strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
     191    if (PhotFlagSelect)      strextend (&command, "+photflags");
     192    if (PhotFlagBad)         strextend (&command, "+photflagbad %d", PhotFlagBad);
     193    if (PhotFlagPoor)        strextend (&command, "+photflagpoor %d", PhotFlagPoor);
    194194    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    195195
     
    197197      char *tstart = ohana_sec_to_date (TSTART);
    198198      char *tstop  = ohana_sec_to_date (TSTOP);
    199       strextend (command, "-time %s %s", tstart, tstop);
     199      strextend (&command, "-time %s %s", tstart, tstop);
    200200      free (tstart);
    201201      free (tstop);
  • trunk/Ohana/src/relastro/src/load_images.c

    r37807 r38441  
    1616
    1717  // convert database table to internal structure
    18   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     18  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1919  if (!image) {
    2020      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/relastro/src/relastro_client.c

    r37807 r38441  
    6969     
    7070      set_db (&db);
     71      gfits_db_init (&db);
    7172
    7273      /* lock and load the image db table */
  • trunk/Ohana/src/relastro/src/relastro_images.c

    r37807 r38441  
    1111  /* register database handle with shutdown procedure */
    1212  set_db (&db);
     13  gfits_db_init (&db);
    1314
    1415  /* lock and load the image db table */
  • trunk/Ohana/src/relastro/src/relastro_merge_source.c

    r37038 r38441  
    4545  catalog_src.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    4646  catalog_src.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    47   catalog_src.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     47  catalog_src.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4848  catalog_src.Nsecfilt  = GetPhotcodeNsecfilt ();
    4949
     
    5252    exit (1);
    5353  }
    54   if (!catalog_src.Naves_disk) {
     54  if (!catalog_src.Naverage_disk) {
    5555    fprintf (stderr, "no data in %s, error in cat ID?\n", catalog_src.filename);
    5656    exit (1);
  • trunk/Ohana/src/relastro/src/relastro_objects.c

    r37807 r38441  
    4444    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    4545    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    46     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     46    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4747    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4848
     
    5252      exit (1);
    5353    }
    54     if (!catalog.Naves_disk) {
     54    if (!catalog.Naverage_disk) {
    5555      if (VERBOSE2) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5656      dvo_catalog_unlock (&catalog);
     
    147147    // SRC_MEAS_TOOFEW
    148148
    149     char command[1024];
    150     snprintf (command, 1024, "relastro_client -update-objects -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s",
     149    char *command = NULL;
     150    strextend (&command, "relastro_client -update-objects -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s",
    151151              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE);
    152152
    153     char tmpline[1024];
    154     if (FIT_MODE == FIT_PM_ONLY)         { snprintf (tmpline, 1024, "%s -pm",    command);           strcpy (command, tmpline); }
    155     if (FIT_MODE == FIT_PAR_ONLY)        { snprintf (tmpline, 1024, "%s -par",   command);           strcpy (command, tmpline); }
    156     if (FIT_MODE == FIT_PM_AND_PAR)      { snprintf (tmpline, 1024, "%s -pmpar", command);           strcpy (command, tmpline); }
    157 
    158     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    159     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                    strcpy (command, tmpline); }
    160     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                    strcpy (command, tmpline); }
    161     if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command);                    strcpy (command, tmpline); }
    162 
    163     if (ImagSelect)    { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax);  strcpy (command, tmpline); }
    164     if (MaxDensityUse) { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue);   strcpy (command, tmpline); }
    165    
    166     if (FlagOutlier)   { snprintf (tmpline, 1024, "%s -clip %d",        command, CLIP_THRESH);       strcpy (command, tmpline); }
    167    
    168     if (USE_FIXED_PIXCOORDS) { snprintf (tmpline, 1024, "%s -D USE_FIXED_PIXCOORDS 1", command);     strcpy (command, tmpline); }
    169 
    170     if (PHOTCODE_KEEP_LIST) { snprintf (tmpline, 1024, "%s +photcode %s", command, PHOTCODE_KEEP_LIST); strcpy (command, tmpline); }
    171     if (PHOTCODE_SKIP_LIST) { snprintf (tmpline, 1024, "%s -photcode %s", command, PHOTCODE_SKIP_LIST); strcpy (command, tmpline); }
    172     if (PhotFlagSelect)    { snprintf (tmpline, 1024, "%s +photflags",   command);                      strcpy (command, tmpline); }
    173     if (PhotFlagBad)       { snprintf (tmpline, 1024, "%s +photflagbad %d", command, PhotFlagBad);      strcpy (command, tmpline); }
    174     if (PhotFlagPoor)      { snprintf (tmpline, 1024, "%s +photflagpoor %d", command, PhotFlagPoor);    strcpy (command, tmpline); }
     153    if (FIT_MODE == FIT_PM_ONLY)         { strextend (&command, "-pm"); }
     154    if (FIT_MODE == FIT_PAR_ONLY)        { strextend (&command, "-par"); }
     155    if (FIT_MODE == FIT_PM_AND_PAR)      { strextend (&command, "-pmpar"); }
     156
     157    if (VERBOSE)       { strextend (&command, "-v"); }
     158    if (VERBOSE2)      { strextend (&command, "-vv"); }
     159    if (RESET)         { strextend (&command, "-reset"); }
     160    if (UPDATE)        { strextend (&command, "-update"); }
     161    if (ImagSelect)    { strextend (&command, "-instmag %f %f", ImagMin, ImagMax); }
     162    if (MaxDensityUse) { strextend (&command, "-max-density %f", MaxDensityValue); }
     163    if (FlagOutlier)   { strextend (&command, "-clip %d", CLIP_THRESH); }
     164    if (USE_FIXED_PIXCOORDS) { strextend (&command, "-D USE_FIXED_PIXCOORDS 1"); }
     165    if (PHOTCODE_KEEP_LIST)  { strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST); }
     166    if (PHOTCODE_SKIP_LIST)  { strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST); }
     167    if (PhotFlagSelect)      { strextend (&command, "+photflags"); }
     168    if (PhotFlagBad)         { strextend (&command, "+photflagbad %d", PhotFlagBad); }
     169    if (PhotFlagPoor)        { strextend (&command, "+photflagpoor %d", PhotFlagPoor); }
    175170    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    176171
    177     if (MinBadQF > 0.0)    { snprintf (tmpline, 1024, "%s -min-bad-psfqf %f",        command, MinBadQF);      strcpy (command, tmpline); }
    178     if (MaxMeanOffset != 10.0) { snprintf (tmpline, 1024, "%s -max-mean-offset  %f", command, MaxMeanOffset); strcpy (command, tmpline); }
     172    if (MinBadQF > 0.0)        { strextend (&command, "-min-bad-psfqf %f", MinBadQF); }
     173    if (MaxMeanOffset != 10.0) { strextend (&command, "-max-mean-offset  %f", MaxMeanOffset); }
    179174
    180175    if (TimeSelect) {
    181176      char *tstart = ohana_sec_to_date (TSTART);
    182177      char *tstop  = ohana_sec_to_date (TSTOP);
    183       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     178      strextend (&command, "-time %s %s", tstart, tstop);
    184179      free (tstart);
    185180      free (tstop);
    186       strcpy (command, tmpline);
    187181    }
    188182
  • trunk/Ohana/src/relastro/src/relastro_parallel_regions.c

    r37807 r38441  
    1717  // register database handle with shutdown procedure
    1818  set_db (&db);
     19  gfits_db_init (&db);
    1920  db.mode   = dvo_catalog_catmode (CATMODE);
    2021  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/relphot/include/relphot.h

    r38062 r38441  
    213213char        *BOUNDARY_TREE;
    214214
    215 int SET_MREL_VERSION;
     215// XXX deprecate int SET_MREL_VERSION;
    216216int IS_DIFF_DB;
    217217
     
    494494
    495495int launch_region_hosts (RegionHostTable *regionHosts);
    496 int strextend (char *input, char *format,...);
    497496
    498497Image *ImageTableLoad(char *filename, off_t *nimage);
  • trunk/Ohana/src/relphot/src/ImageTable.c

    r37807 r38441  
    77  FITS_DB db;
    88
     9  gfits_db_init (&db);
    910  db.mode   = dvo_catalog_catmode (CATMODE);
    1011  db.format = dvo_catalog_catformat (CATFORMAT);
     
    2728  // convert database table to internal structure (binary to Image)
    2829  // 'image' points to the same memory as db->ftable->buffer
    29   Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     30  Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    3031  if (!image) {
    3132    Shutdown ("ERROR: failed to read images");
     
    4546
    4647  // setup image table format and lock
     48  gfits_db_init (&db);
    4749  db.mode   = dvo_catalog_catmode (CATMODE);
    4850  db.format = dvo_catalog_catformat (CATFORMAT);
     51
    4952  status    = dvo_image_lock (&db, filename, 60.0, LCK_XCLD);  // shorter timeout?
    5053  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  • trunk/Ohana/src/relphot/src/StarOps.c

    r37116 r38441  
    128128
    129129  for (i = 0; i < Ncatalog; i++) {
    130     // pass == -1 for anything other than the final pass
    131     switch (SET_MREL_VERSION) {
    132       case 0:
    133         setMrel_catalog (catalog, i, -1, flatcorr, &results, Nsecfilt);
    134         break;
    135       case 1:
    136         setMrel_catalog_alt (catalog, i, -1, flatcorr, &results, Nsecfilt);
    137         break;
    138       default:
    139         fprintf (stderr, "invalid setMrel version %d (use 0 or 1)\n", SET_MREL_VERSION);
    140         exit (2);
    141     }
     130    setMrel_catalog_alt (catalog, i, -1, flatcorr, &results, Nsecfilt);
    142131    SetMrelInfoAccum (&summary, &results);
    143132  }
     
    175164
    176165  for (i = 0; i < Ncatalog; i++) {
    177     switch (SET_MREL_VERSION) {
    178       // case 0:
    179       // setMrel_catalog (catalog, i, pass, flatcorr, &results, Nsecfilt);
    180       // break;
    181       case 1:
    182         setMrel_catalog_alt (catalog, i, pass, flatcorr, &results, Nsecfilt);
    183         break;
    184       default:
    185         fprintf (stderr, "invalid setMrel version %d (use 1)\n", SET_MREL_VERSION);
    186         exit (2);
    187     }
     166    setMrel_catalog_alt (catalog, i, pass, flatcorr, &results, Nsecfilt);
    188167    SetMrelInfoAccum (&summary, &results);
    189168  }
     
    293272
    294273    // pass == -1 for anything other than the final pass
    295     switch (SET_MREL_VERSION) {
    296       case 0:
    297         setMrel_catalog (catalog, i, -1, flatcorr, &results, Nsecfilt);
    298         break;
    299       case 1:
    300         setMrel_catalog_alt (catalog, i, -1, flatcorr, &results, Nsecfilt);
    301         break;
    302       default:
    303         fprintf (stderr, "invalid setMrel version %d (use 0 or 1)\n", SET_MREL_VERSION);
    304         exit (2);
    305     }
     274    setMrel_catalog_alt (catalog, i, -1, flatcorr, &results, Nsecfilt);
    306275    SetMrelInfoAccum (&threadinfo->summary, &results);
    307276  }
  • trunk/Ohana/src/relphot/src/args.c

    r38062 r38441  
    7676  }
    7777
    78   SET_MREL_VERSION = 1;
    79   if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
    80     remove_argument (N, &argc, argv);
    81     SET_MREL_VERSION = atof(argv[N]);
    82     remove_argument (N, &argc, argv);
    83   }
    84 
    8578  VERBOSE = VERBOSE2 = FALSE;
    8679  if ((N = get_argument (argc, argv, "-v"))) {
     
    529522  }
    530523
    531   SET_MREL_VERSION = 1;
    532   if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
    533     remove_argument (N, &argc, argv);
    534     SET_MREL_VERSION = atof(argv[N]);
    535     remove_argument (N, &argc, argv);
    536   }
    537 
    538524  VERBOSE = VERBOSE2 = FALSE;
    539525  if ((N = get_argument (argc, argv, "-v"))) {
  • trunk/Ohana/src/relphot/src/assign_images.c

    r37807 r38441  
    1111  // convert database table to internal structure (binary to Image)
    1212  // 'image' points to the same memory as db->ftable->buffer
    13   Image *image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     13  Image *image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1414  if (!image) {
    1515      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/relphot/src/bcatalog.c

    r37116 r38441  
    245245  subcatalog[0].Nmeasure = Nmeasure;
    246246  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
    247   subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     247  subcatalog[0].Nsecfilt_mem = Naverage * catalog[0].Nsecfilt;
    248248
    249249  if (VERBOSE) {
     
    368368  subcatalog[0].Nmeasure = Nmeasure;
    369369  subcatalog[0].Nsecfilt = oldcatalog[0].Nsecfilt;
    370   subcatalog[0].Nsecf_mem = Naverage * oldcatalog[0].Nsecfilt;
     370  subcatalog[0].Nsecfilt_mem = Naverage * oldcatalog[0].Nsecfilt;
    371371
    372372  return (TRUE);
     
    461461  subcatalog[0].Nmeasure = Nmeasure;
    462462  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
    463   subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     463  subcatalog[0].Nsecfilt_mem = Naverage * catalog[0].Nsecfilt;
    464464
    465465  return (TRUE);
  • trunk/Ohana/src/relphot/src/launch_region_hosts.c

    r37037 r38441  
    11# include "relphot.h"
    22# define DEBUG 0
    3 
    4 int strextend (char *input, char *format,...) {
    5 
    6   char tmpextra[1024], tmpline[1024];
    7   va_list argp;
    8 
    9   va_start (argp, format);
    10   vsnprintf (tmpextra, 1024, format, argp);
    11   snprintf (tmpline, 1024, "%s %s", input, tmpextra);
    12   strcpy (input, tmpline);
    13 
    14   return TRUE;
    15 }
    163
    174int launch_region_hosts (RegionHostTable *regionHosts) {
     
    5441    ImageTableSave (filename, host->image, host->Nimage);
    5542
    56     char command[1024];
    57     snprintf (command, 1024, "relphot %s", PhotcodeList);
    58     strextend (command, "-parallel-images %s", filename);
    59     strextend (command, "-region-hosts %s", REGION_FILE);
    60     strextend (command, "-region-hostID %d", host->hostID);
    61     strextend (command, "-D CATDIR %s", CATDIR);
    62     strextend (command, "-region %f %f %f %f", host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat);
    63     strextend (command, "-statmode %s", STATMODE);
    64     strextend (command, "-D CAMERA %s", CAMERA);
    65     strextend (command, "-D STAR_TOOFEW %d", STAR_TOOFEW);
    66     strextend (command, "-minerror %f", MIN_ERROR);
    67     strextend (command, "-cloud-limit %f", CLOUD_TOLERANCE);
     43    char *command = NULL;
     44    strextend (&command, "relphot %s", PhotcodeList);
     45    strextend (&command, "-parallel-images %s", filename);
     46    strextend (&command, "-region-hosts %s", REGION_FILE);
     47    strextend (&command, "-region-hostID %d", host->hostID);
     48    strextend (&command, "-D CATDIR %s", CATDIR);
     49    strextend (&command, "-region %f %f %f %f", host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat);
     50    strextend (&command, "-statmode %s", STATMODE);
     51    strextend (&command, "-D CAMERA %s", CAMERA);
     52    strextend (&command, "-D STAR_TOOFEW %d", STAR_TOOFEW);
     53    strextend (&command, "-minerror %f", MIN_ERROR);
     54    strextend (&command, "-cloud-limit %f", CLOUD_TOLERANCE);
    6855
    69     if (VERBOSE)             strextend (command, "-v");
    70     if (VERBOSE2)            strextend (command, "-vv");
    71     if (RESET)               strextend (command, "-reset");
    72     if (RESET_ZEROPTS)       strextend (command, "-reset-zpts");
    73     if (!KEEP_UBERCAL)       strextend (command, "-reset-ubercal");
    74     if (DophotSelect)        strextend (command, "-dophot %d", DophotValue);
    75     if (ImagSelect)          strextend (command, "-instmag %f %f", ImagMin, ImagMax);
    76     if (MaxDensityUse)       strextend (command, "-max-density %f", MaxDensityValue);
    77     if (SyntheticPhotometry) strextend (command, "-synthphot");
     56    if (VERBOSE)             strextend (&command, "-v");
     57    if (VERBOSE2)            strextend (&command, "-vv");
     58    if (RESET)               strextend (&command, "-reset");
     59    if (RESET_ZEROPTS)       strextend (&command, "-reset-zpts");
     60    if (!KEEP_UBERCAL)       strextend (&command, "-reset-ubercal");
     61    if (DophotSelect)        strextend (&command, "-dophot %d", DophotValue);
     62    if (ImagSelect)          strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     63    if (MaxDensityUse)       strextend (&command, "-max-density %f", MaxDensityValue);
     64    if (SyntheticPhotometry) strextend (&command, "-synthphot");
    7865
    79     if (UPDATE)              strextend (command, "-update");
    80     if (MOSAIC_ZEROPT)       strextend (command, "-mosaic");
    81     if (FREEZE_IMAGES)       strextend (command, "-imfreeze");
    82     if (FREEZE_MOSAICS)      strextend (command, "-mosfreeze");
    83     if (PARALLEL)            strextend (command, "-parallel");
    84     if (PARALLEL_MANUAL)     strextend (command, "-parallel-manual");
    85     if (PARALLEL_SERIAL)     strextend (command, "-parallel-serial");
     66    if (UPDATE)              strextend (&command, "-update");
     67    if (MOSAIC_ZEROPT)       strextend (&command, "-mosaic");
     68    if (FREEZE_IMAGES)       strextend (&command, "-imfreeze");
     69    if (FREEZE_MOSAICS)      strextend (&command, "-mosfreeze");
     70    if (PARALLEL)            strextend (&command, "-parallel");
     71    if (PARALLEL_MANUAL)     strextend (&command, "-parallel-manual");
     72    if (PARALLEL_SERIAL)     strextend (&command, "-parallel-serial");
    8673
    8774    // XXX deprecate this if we are happy with the new version
    88     if (SET_MREL_VERSION != 1) strextend (command, "-set-mrel-version %d", SET_MREL_VERSION);
     75    // if (SET_MREL_VERSION != 1) strextend (command, "-set-mrel-version %d", SET_MREL_VERSION);
    8976
    9077    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/relphot/src/load_catalogs.c

    r37037 r38441  
    3434    // XXX keep in mind that not all catalogs are loaded
    3535    dvo_catalog_init (&catalog[i], TRUE);
     36    dvo_catalog_init (&tcatalog, TRUE);
    3637
    3738    // does this host ID match the desired location for the table?
     
    4142    char hostfile[1024];
    4243    snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
    43     tcatalog.filename = hostID ? hostfile : skylist[0].filename[i];
    44 
    45     tcatalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    46     tcatalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    47     tcatalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF;    // don't need to load all data at this point
    48     tcatalog.Nsecfilt  = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
     44    tcatalog.filename    = hostID ? hostfile : skylist[0].filename[i];
     45    tcatalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;    // don't need to load all data at this point
     46    tcatalog.Nsecfilt    = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
     47
     48    // tcatalog.catformat   = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
     49    // tcatalog.catmode     = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     50    // tcatalog.catcompress = dvo_catalog_catcompress (CATCOMPRESS); // set the default catcompress from config data
    4951
    5052    if (!dvo_catalog_open (&tcatalog, skylist[0].regions[i], VERBOSE2, "r")) {
     
    5254      exit (1);
    5355    }
    54     if (!tcatalog.Naves_disk) {
     56    if (!tcatalog.Naverage_disk) {
    5557        if (VERBOSE2) { fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename); }
    5658        dvo_catalog_unlock (&tcatalog);
     
    153155    // MaxDensityUse, MaxDensityValue
    154156
    155     char command[1024];
    156     snprintf (command, 1024, "relphot_client %s -load %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -D CAMERA %s -D MAG_LIM %f -D SIGMA_LIM %f",
     157    char *command = NULL;
     158    strextend (&command, "relphot_client %s -load %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -D CAMERA %s -D MAG_LIM %f -D SIGMA_LIM %f",
    157159              PhotcodeList, table->hosts[i].results, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, CAMERA, MAG_LIM, SIGMA_LIM);
    158160
    159     char tmpline[1024];
    160     if (VERBOSE)             { snprintf (tmpline, 1024, "%s -v",              command);                   strcpy (command, tmpline); }
    161     if (VERBOSE2)            { snprintf (tmpline, 1024, "%s -vv",             command);                   strcpy (command, tmpline); }
    162     if (RESET)               { snprintf (tmpline, 1024, "%s -reset",          command);                   strcpy (command, tmpline); }
    163     if (RESET_ZEROPTS)       { snprintf (tmpline, 1024, "%s -reset-zpts",     command);                   strcpy (command, tmpline); }
    164     if (!KEEP_UBERCAL)       { snprintf (tmpline, 1024, "%s -reset-ubercal",  command);                   strcpy (command, tmpline); }
    165     if (DophotSelect)        { snprintf (tmpline, 1024, "%s -dophot %d",      command, DophotValue);      strcpy (command, tmpline); }
    166     if (ImagSelect)          { snprintf (tmpline, 1024, "%s -instmag %f %f",  command, ImagMin, ImagMax); strcpy (command, tmpline); }
    167     if (MaxDensityUse)       { snprintf (tmpline, 1024, "%s -max-density %f", command, MaxDensityValue);  strcpy (command, tmpline); }
    168     if (SyntheticPhotometry) { snprintf (tmpline, 1024, "%s -synthphot",      command);                   strcpy (command, tmpline); }
     161    if (VERBOSE)             { strextend (&command, "-v"); }
     162    if (VERBOSE2)            { strextend (&command, "-vv"); }
     163    if (RESET)               { strextend (&command, "-reset"); }
     164    if (RESET_ZEROPTS)       { strextend (&command, "-reset-zpts"); }
     165    if (!KEEP_UBERCAL)       { strextend (&command, "-reset-ubercal"); }
     166    if (DophotSelect)        { strextend (&command, "-dophot %d", DophotValue); }
     167    if (ImagSelect)          { strextend (&command, "-instmag %f %f", ImagMin, ImagMax); }
     168    if (MaxDensityUse)       { strextend (&command, "-max-density %f", MaxDensityValue); }
     169    if (SyntheticPhotometry) { strextend (&command, "-synthphot"); }
    169170
    170171    if (TimeSelect) {
    171172      char *tstart = ohana_sec_to_date (TSTART);
    172173      char *tstop  = ohana_sec_to_date (TSTOP);
    173       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     174      strextend (&command, "-time %s %s", tstart, tstop);
    174175      free (tstart);
    175176      free (tstop);
    176       strcpy (command, tmpline);
    177177    }
    178178
  • trunk/Ohana/src/relphot/src/load_images.c

    r37807 r38441  
    2121  // convert database table to internal structure (binary to Image)
    2222  // 'image' points to the same memory as db->ftable->buffer
    23   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     23  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    2424  if (!image) {
    2525      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/relphot/src/reload_catalogs.c

    r37907 r38441  
    5656    TIMESTAMP(time1);
    5757
    58     catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    59     catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    60     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    61     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
     58    // catalog.catformat   = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
     59    // catalog.catmode     = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     60    // catalog.catcompress = dvo_catalog_catcompress (CATCOMPRESS); // set the default catcompress from config data
     61    catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     62    catalog.Nsecfilt    = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
    6263
    6364    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     
    6566      exit (1);
    6667    }
    67     if (VERBOSE && (catalog.Naves_disk == 0)) {
     68    if (VERBOSE && (catalog.Naverage_disk == 0)) {
    6869        fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    6970        dvo_catalog_unlock (&catalog);
     
    170171
    171172  int Ngroups;
    172   HostTableGroup *groups = HostTableGroups (table, &Ngroups);
     173  HostTableGroup *groups = HostTableGroupsUniqueMachines (table, &Ngroups);
    173174  // split the table into Ngroups, each with a unique set of machines (this avoids overloading the remote host machines)
    174175
     
    206207    group->hosts[i][0].pathname = tmppath;
    207208
    208     char command[1024];
    209     snprintf (command, 1024, "relphot_client %s -update-catalogs %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f",
    210               PhotcodeList, imageFile, group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
     209    char *command = NULL;
     210    strextend (&command, "relphot_client %s -update-catalogs %s", PhotcodeList, imageFile);
     211    strextend (&command, "-hostID %d -D CATDIR %s -hostdir %s", group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname);
     212    strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
     213    strextend (&command, "-statmode %s", STATMODE);
     214    strextend (&command, "-D CAMERA %s", CAMERA);
     215    strextend (&command, "-D STAR_TOOFEW %d -minerror %f", STAR_TOOFEW, MIN_ERROR);
    211216
    212217    // options & configs which affect relphot_client -update-catalogs
     
    220225    // MIN_ERROR
    221226   
    222     char tmpline[1024];
    223     if (VERBOSE)          { snprintf (tmpline, 1024, "%s -v",                   command);                                         strcpy (command, tmpline); }
    224     if (VERBOSE2)         { snprintf (tmpline, 1024, "%s -vv",                  command);                                         strcpy (command, tmpline); }
    225     if (RESET)            { snprintf (tmpline, 1024, "%s -reset",               command);                                         strcpy (command, tmpline); }
    226     if (RESET_ZEROPTS)    { snprintf (tmpline, 1024, "%s -reset-zpts",          command);                                         strcpy (command, tmpline); }
    227     if (UPDATE)           { snprintf (tmpline, 1024, "%s -update",              command);                                         strcpy (command, tmpline); }
    228     if (IS_DIFF_DB)       { snprintf (tmpline, 1024, "%s -is-diff-db",          command);                                         strcpy (command, tmpline); }
    229     if (!KEEP_UBERCAL)    { snprintf (tmpline, 1024, "%s -reset-ubercal",       command);                                         strcpy (command, tmpline); }
    230     if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT);                       strcpy (command, tmpline); }
    231     if (BOUNDARY_TREE)    { snprintf (tmpline, 1024, "%s -boundary-tree %s",    command, BOUNDARY_TREE);                          strcpy (command, tmpline); }
    232     if (SET_MREL_VERSION != 1) { snprintf (tmpline, 1024, "%s -set-mrel-version %d", command, SET_MREL_VERSION);                  strcpy (command, tmpline); }
    233     if (AreaSelect)       { snprintf (tmpline, 1024, "%s -area %f %f %f %f",    command, AreaXmin, AreaXmax, AreaYmin, AreaYmax); strcpy (command, tmpline); }
     227    if (VERBOSE)          { strextend (&command, "-v"); }
     228    if (VERBOSE2)         { strextend (&command, "-vv"); }
     229    if (RESET)            { strextend (&command, "-reset"); }
     230    if (RESET_ZEROPTS)    { strextend (&command, "-reset-zpts"); }
     231    if (UPDATE)           { strextend (&command, "-update"); }
     232    if (IS_DIFF_DB)       { strextend (&command, "-is-diff-db"); }
     233    if (!KEEP_UBERCAL)    { strextend (&command, "-reset-ubercal"); }
     234    if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
     235    if (BOUNDARY_TREE)    { strextend (&command, "-boundary-tree %s", BOUNDARY_TREE); }
     236
     237    // deprecate
     238    // if (SET_MREL_VERSION != 1) { snprintf (tmpline, 1024, "%s -set-mrel-version %d", SET_MREL_VERSION); } // XXXX deprecate this...
     239
     240    if (AreaSelect)       { strextend (&command, "-area %f %f %f %f", AreaXmin, AreaXmax, AreaYmin, AreaYmax); }
    234241    if (TimeSelect) {
    235242      char *tstart = ohana_sec_to_date (TSTART);
    236243      char *tstop  = ohana_sec_to_date (TSTOP);
    237       snprintf (tmpline, 1024, "%s -time %s %s", command, tstart, tstop);
     244      strextend (&command, "-time %s %s", tstart, tstop);
    238245      free (tstart);
    239246      free (tstop);
    240       strcpy (command, tmpline);
    241247    }
    242248
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r37037 r38441  
    1818  /* register database handle with shutdown procedure */
    1919  set_db (&db);
     20  gfits_db_init (&db);
    2021  db.mode   = dvo_catalog_catmode (CATMODE);
    2122  db.format = dvo_catalog_catformat (CATFORMAT);
     
    185186      // convert database table to internal structure (binary to Image)
    186187      // 'image' points to the same memory as db->ftable->buffer
    187       image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     188      image = gfits_table_get_Image (&db.ftable, &Nimage, &db.scaledValue, &db.nativeOrder);
    188189      if (!image) {
    189190        fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/relphot/src/relphot_objects.c

    r37807 r38441  
    3939    char hostfile[1024];
    4040    snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
    41     catalog.filename  = hostID ? hostfile : skylist[0].filename[i];
    42     catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    43     catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    44     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    45     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     41    catalog.filename    = hostID ? hostfile : skylist[0].filename[i];
     42    // catalog.catformat   = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
     43    // catalog.catmode     = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     44    // catalog.catcompress = dvo_catalog_catcompress (CATCOMPRESS); // set the default catcompress from config data
     45    catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     46    catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
    4647
    4748    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     
    4950      exit (1);
    5051    }
    51     if (!catalog.Naves_disk) {
     52    if (!catalog.Naverage_disk) {
    5253      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5354      dvo_catalog_unlock (&catalog);
     
    153154    // MaxDensityUse, MaxDensityValue
    154155
    155     char command[1024];
    156     snprintf (command, 1024, "relphot_client -update-objects -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f",
     156    char *command = NULL;
     157    strextend (&command, "relphot_client -update-objects -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f",
    157158              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
    158159
    159     char tmpline[1024];
    160     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    161     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                    strcpy (command, tmpline); }
    162     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                    strcpy (command, tmpline); }
    163     if (RESET_ZEROPTS) { snprintf (tmpline, 1024, "%s -reset-zpts",     command);                    strcpy (command, tmpline); }
    164     if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command);                    strcpy (command, tmpline); }
    165     if (!KEEP_UBERCAL) { snprintf (tmpline, 1024, "%s -reset-ubercal",  command);                    strcpy (command, tmpline); }
    166     if (SET_MREL_VERSION != 1) { snprintf (tmpline, 1024, "%s -set-mrel-version %d", command, SET_MREL_VERSION); strcpy (command, tmpline); }
     160    if (VERBOSE)       { strextend (&command, "-v"); }
     161    if (VERBOSE2)      { strextend (&command, "-vv"); }
     162    if (RESET)         { strextend (&command, "-reset"); }
     163    if (RESET_ZEROPTS) { strextend (&command, "-reset-zpts"); }
     164    if (UPDATE)        { strextend (&command, "-update"); }
     165    if (!KEEP_UBERCAL) { strextend (&command, "-reset-ubercal"); }
     166
     167    // if (SET_MREL_VERSION != 1) { strextend (&command, "-set-mrel-version %d", SET_MREL_VERSION); }
    167168
    168169    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/relphot/src/relphot_parallel_regions.c

    r37807 r38441  
    2323  // register database handle with shutdown procedure
    2424  set_db (&db);
     25  gfits_db_init (&db);
    2526  db.mode   = dvo_catalog_catmode (CATMODE);
    2627  db.format = dvo_catalog_catformat (CATFORMAT);
  • trunk/Ohana/src/relphot/src/relphot_synthphot.c

    r38062 r38441  
    4040    char hostfile[1024];
    4141    snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
    42     catalog.filename  = hostID ? hostfile : skylist[0].filename[i];
    43     catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
    44     catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
    45     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
    46     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     42    catalog.filename    = hostID ? hostfile : skylist[0].filename[i];
     43    // catalog.catformat   = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
     44    // catalog.catmode     = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
     45    // catalog.catcompress = dvo_catalog_catcompress (CATCOMPRESS); // set the default catcompress from config data
     46    catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     47    catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
    4748
    4849    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     
    5051      exit (1);
    5152    }
    52     if (!catalog.Naves_disk) {
     53    if (!catalog.Naverage_disk) {
    5354      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5455      dvo_catalog_unlock (&catalog);
     
    109110    // VERBOSE, VERBOSE2
    110111
    111     char command[1024];
    112     snprintf (command, 1024, "relphot_client -synthphot_means %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f",
    113               SYNTH_ZERO_POINTS, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
     112    char *command = NULL;
     113    strextend (&command, "relphot_client -synthphot_means %s", SYNTH_ZERO_POINTS);
     114    strextend (&command, "-hostID %d -D CATDIR %s -hostdir %s", table->hosts[i].hostID, CATDIR, table->hosts[i].pathname);
     115    strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    114116
    115     char tmpline[1024];
    116     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    117     if (VERBOSE2)      { snprintf (tmpline, 1024, "%s -vv",             command);                    strcpy (command, tmpline); }
    118     if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command);                    strcpy (command, tmpline); }
     117    if (VERBOSE)       { strextend (&command, "-v");      }
     118    if (VERBOSE2)      { strextend (&command, "-vv");     }
     119    if (UPDATE)        { strextend (&command, "-update"); }
    119120
    120121    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/tools/src/fields.c

    r27491 r38441  
    6666      GotFile = TRUE;
    6767      GotField &= print_fields (filename, NULL, &header, argc, argv);
     68      GotExtension = TRUE;
    6869      continue;
    6970    }
     
    7273      GotFile = TRUE;
    7374      GotField &= print_fields (filename, NULL, &header, argc, argv);
     75      GotExtension = TRUE;
    7476      continue;
    7577    }
  • trunk/Ohana/src/uniphot/src/find_image_sgroups.c

    r37807 r38441  
    1212
    1313  imlink = *Imlink;
    14   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     14  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1515  if (!image) {
    1616      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/find_image_tgroups.c

    r31160 r38441  
    1111  ImageLink *imlink;
    1212
    13   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     13  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1414  if (!image) {
    1515      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/fiximids.c

    r35764 r38441  
    1111
    1212  set_db (&db);
     13  gfits_db_init (&db);
    1314  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
    1415  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  • trunk/Ohana/src/uniphot/src/fixstkids.c

    r35764 r38441  
    1111
    1212  set_db (&db);
     13  gfits_db_init (&db);
    1314  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
    1415  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  • trunk/Ohana/src/uniphot/src/load_images.c

    r33654 r38441  
    2121
    2222  /* use a vtable to keep the images to be calibrated */
    23   image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].swapped);
     23  image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    2424  if (!image) {
    2525      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/load_images_fiximids.c

    r37043 r38441  
    2020
    2121  /* use a vtable to keep the images to be calibrated */
    22   image = gfits_table_get_Image (&db[0].ftable, Nimage_load, &db[0].swapped);
     22  image = gfits_table_get_Image (&db[0].ftable, Nimage_load, &db[0].scaledValue, &db[0].nativeOrder);
    2323  if (!image) {
    2424      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/load_images_fixstkids.c

    r37043 r38441  
    1919
    2020  /* use a vtable to keep the images to be calibrated */
    21   image = gfits_table_get_Image (&db[0].ftable, Nimage_load, &db[0].swapped);
     21  image = gfits_table_get_Image (&db[0].ftable, Nimage_load, &db[0].scaledValue, &db[0].nativeOrder);
    2222  if (!image) {
    2323      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/load_images_setphot.c

    r33654 r38441  
    1111
    1212  /* use a vtable to keep the images to be calibrated */
    13   image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].swapped);
     13  image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1414  if (!image) {
    1515      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/load_images_setposangle.c

    r34749 r38441  
    1919
    2020  /* use a vtable to keep the images to be calibrated */
    21   image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].swapped);
     21  image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    2222  if (!image) {
    2323      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/setfwhm.c

    r33654 r38441  
    1313
    1414  set_db (&db);
     15  gfits_db_init (&db);
    1516  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
    1617  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  • trunk/Ohana/src/uniphot/src/setphot.c

    r33963 r38441  
    1414
    1515  set_db (&db);
     16  gfits_db_init (&db);
    1617  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
    1718  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  • trunk/Ohana/src/uniphot/src/setposangle.c

    r34749 r38441  
    1111
    1212  set_db (&db);
     13  gfits_db_init (&db);
    1314  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
    1415  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  • trunk/Ohana/src/uniphot/src/subset_images.c

    r31160 r38441  
    88
    99  // convert from the binary I/O format to the internal structure (Image)
    10   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     10  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1111  if (!image) {
    1212      fprintf (stderr, "ERROR: failed to read images\n");
  • trunk/Ohana/src/uniphot/src/uniphot.c

    r33654 r38441  
    1919
    2020  set_db (&db);
     21  gfits_db_init (&db);
    2122  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
    2223  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  • trunk/Ohana/src/uniphot/src/update_dvo_ckids.c

    r35764 r38441  
    4646    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    4747    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    48     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     48    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4949    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5050
     
    5353      exit (1);
    5454    }
    55     if (!catalog.Naves_disk) {
     55    if (!catalog.Naverage_disk) {
    5656      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5757      dvo_catalog_unlock (&catalog);
     
    111111    table->hosts[i].pathname = tmppath;
    112112
    113     char command[1024];
    114     snprintf (command, 1024, "ckids_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     113    char *command = NULL;
     114    strextend (&command, "ckids_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    115115              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    116116              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    117117
    118     char tmpline[1024];
    119     if (VERBOSE)     { snprintf (tmpline, 1024, "%s -v",          command);                          strcpy (command, tmpline); }
    120     if (SINGLE_CPT)  { snprintf (tmpline, 1024, "%s -cpt %s",     command, SINGLE_CPT);              strcpy (command, tmpline); }
    121     if (UPDATE)      { snprintf (tmpline, 1024, "%s -update",     command);                          strcpy (command, tmpline); }
     118    if (VERBOSE)     { strextend (&command, "-v"); }
     119    if (SINGLE_CPT)  { strextend (&command, "-cpt %s", SINGLE_CPT); }
     120    if (UPDATE)      { strextend (&command, "-update"); }
    122121
    123122    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/uniphot/src/update_dvo_fiximids.c

    r35764 r38441  
    4141    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    4242    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    43     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     43    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4444    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4545
     
    4848      exit (1);
    4949    }
    50     if (!catalog.Naves_disk) {
     50    if (!catalog.Naverage_disk) {
    5151      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5252      dvo_catalog_unlock (&catalog);
     
    112112    snprintf (table->hosts[i].results, 1024, "%s/fiximids.results.%s.dat", table->hosts[i].pathname, uniquer);
    113113
    114     char command[1024];
    115     snprintf (command, 1024, "fiximids_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
     114    char *command = NULL;
     115    strextend (&command, "fiximids_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
    116116              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile,
    117117              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
     
    119119    int saveImstats = VERBOSE_IMSTATS || SUMMARY_IMSTATS;
    120120
    121     char tmpline[1024];
    122     if (VERBOSE)     { snprintf (tmpline, 1024, "%s -v",          command);                          strcpy (command, tmpline); }
    123     if (saveImstats) { snprintf (tmpline, 1024, "%s -imstats %s", command, table->hosts[i].results); strcpy (command, tmpline); }
    124     if (SINGLE_CPT)  { snprintf (tmpline, 1024, "%s -cpt %s",     command, SINGLE_CPT);              strcpy (command, tmpline); }
    125     if (UPDATE)      { snprintf (tmpline, 1024, "%s -update",     command);                          strcpy (command, tmpline); }
     121    if (VERBOSE)     { strextend (&command, "-v"); }
     122    if (saveImstats) { strextend (&command, "-imstats %s", table->hosts[i].results); }
     123    if (SINGLE_CPT)  { strextend (&command, "-cpt %s", SINGLE_CPT); }
     124    if (UPDATE)      { strextend (&command, "-update"); }
    126125
    127126    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/uniphot/src/update_dvo_fixstkids.c

    r35764 r38441  
    4141    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    4242    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    43     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     43    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4444    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4545
     
    4848      exit (1);
    4949    }
    50     if (!catalog.Naves_disk) {
     50    if (!catalog.Naverage_disk) {
    5151      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5252      dvo_catalog_unlock (&catalog);
     
    127127    snprintf (table->hosts[i].results, 1024, "%s/fixstkids.results.%s.dat", table->hosts[i].pathname, uniquer);
    128128
    129     char command[1024];
    130     snprintf (command, 1024, "fixstkids_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
     129    char *command = NULL;
     130    strextend (&command, "fixstkids_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
    131131              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile,
    132132              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
     
    134134    int saveImstats = VERBOSE_IMSTATS || SUMMARY_IMSTATS;
    135135
    136     char tmpline[1024];
    137     if (VERBOSE)     { snprintf (tmpline, 1024, "%s -v",          command);                          strcpy (command, tmpline); }
    138     if (saveImstats) { snprintf (tmpline, 1024, "%s -imstats %s", command, table->hosts[i].results); strcpy (command, tmpline); }
    139     if (SINGLE_CPT)  { snprintf (tmpline, 1024, "%s -cpt %s",     command, SINGLE_CPT);              strcpy (command, tmpline); }
    140     if (UPDATE)      { snprintf (tmpline, 1024, "%s -update",     command);                          strcpy (command, tmpline); }
     136    if (VERBOSE)     { strextend (&command, "-v"); }
     137    if (saveImstats) { strextend (&command, "-imstats %s", table->hosts[i].results); }
     138    if (SINGLE_CPT)  { strextend (&command, "-cpt %s", SINGLE_CPT); }
     139    if (UPDATE)      { strextend (&command, "-update"); }
    141140
    142141    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/uniphot/src/update_dvo_setastrom.c

    r38062 r38441  
    4242    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    4343    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    44     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     44    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    4545    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4646
     
    4949      exit (1);
    5050    }
    51     if (!catalog.Naves_disk) {
     51    if (!catalog.Naverage_disk) {
    5252      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5353      dvo_catalog_unlock (&catalog);
     
    9595    table->hosts[i].pathname = tmppath;
    9696
    97     char command[1024];
    98     snprintf (command, 1024, "setastrom_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     97    char *command = NULL;
     98    strextend (&command, "setastrom_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    9999              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    100100              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    101101
    102     char tmpline[1024];
    103     if (VERBOSE)          { snprintf (tmpline, 1024, "%s -v",                   command);                   strcpy (command, tmpline); }
    104     if (UPDATE)           { snprintf (tmpline, 1024, "%s -update",              command);                   strcpy (command, tmpline); }
    105     if (KH_FILE)          { snprintf (tmpline, 1024, "%s -KH %s",               command, KH_FILE);          strcpy (command, tmpline); }
    106     if (DCR_FILE)         { snprintf (tmpline, 1024, "%s -DCR %s",              command, DCR_FILE);         strcpy (command, tmpline); }
    107     if (CAM_FILE)         { snprintf (tmpline, 1024, "%s -CAM %s",              command, CAM_FILE);         strcpy (command, tmpline); }
    108     if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); }
    109 
    110     if (KH_RESET)         { snprintf (tmpline, 1024, "%s -KH-reset",            command);                   strcpy (command, tmpline); }
    111     if (DCR_RESET)        { snprintf (tmpline, 1024, "%s -DCR-reset",           command);                   strcpy (command, tmpline); }
    112     if (CAM_RESET)        { snprintf (tmpline, 1024, "%s -CAM-reset",           command);                   strcpy (command, tmpline); }
     102    if (VERBOSE)          { strextend (&command, "-v"); }
     103    if (UPDATE)           { strextend (&command, "-update"); }
     104    if (KH_FILE)          { strextend (&command, "-KH %s", KH_FILE); }
     105    if (DCR_FILE)         { strextend (&command, "-DCR %s", DCR_FILE); }
     106    if (CAM_FILE)         { strextend (&command, "-CAM %s", CAM_FILE); }
     107    if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
     108    if (KH_RESET)         { strextend (&command, "-KH-reset"); }
     109    if (DCR_RESET)        { strextend (&command, "-DCR-reset"); }
     110    if (CAM_RESET)        { strextend (&command, "-CAM-reset"); }
    113111
    114112    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/uniphot/src/update_dvo_setgalmodel.c

    r37807 r38441  
    3838    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    3939    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    40     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_STARPAR;
     40    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_STARPAR;
    4141    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4242
     
    4545      exit (1);
    4646    }
    47     if (!catalog.Naves_disk) {
     47    if (!catalog.Naverage_disk) {
    4848      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    4949      dvo_catalog_unlock (&catalog);
     
    9191    table->hosts[i].pathname = tmppath;
    9292
    93     char command[1024];
    94     snprintf (command, 1024, "setgalmodel_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     93    char *command = NULL;
     94    strextend (&command, "setgalmodel_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    9595              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    9696              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    9797
     98    if (VERBOSE)          { strextend (&command, "-v"); }
     99    if (TESTING)          { strextend (&command, "-testing"); }
     100    if (UPDATE)           { strextend (&command, "-update"); }
     101    if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
     102
    98103    fprintf (stderr, "command: %s\n", command);
    99 
    100     char tmpline[1024];
    101     if (VERBOSE)          { snprintf (tmpline, 1024, "%s -v",                   command);                   strcpy (command, tmpline); }
    102     if (TESTING)          { snprintf (tmpline, 1024, "%s -testing",             command);                   strcpy (command, tmpline); }
    103     if (UPDATE)           { snprintf (tmpline, 1024, "%s -update",              command);                   strcpy (command, tmpline); }
    104     if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); }
    105104
    106105    if (PARALLEL_MANUAL) continue;
  • trunk/Ohana/src/uniphot/src/update_dvo_setphot.c

    r38263 r38441  
    5454    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    5555    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    56     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     56    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    5757    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5858
     
    6161      exit (1);
    6262    }
    63     if (!catalog.Naves_disk) {
     63    if (!catalog.Naverage_disk) {
    6464      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    6565      dvo_catalog_unlock (&catalog);
     
    110110    table->hosts[i].pathname = tmppath;
    111111
    112     char command[1024];
    113     snprintf (command, 1024, "setphot_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
     112    char *command = NULL;
     113    strextend (&command, "setphot_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
    114114              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile,
    115115              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    116116
    117     char tmpline[1024];
    118     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    119     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                    strcpy (command, tmpline); }
    120     if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command);                    strcpy (command, tmpline); }
    121     if (UBERCAL)       { snprintf (tmpline, 1024, "%s -ubercal",        command);                    strcpy (command, tmpline); }
     117    if (VERBOSE)       { strextend (&command, "-v"); }
     118    if (RESET)         { strextend (&command, "-reset"); }
     119    if (UPDATE)        { strextend (&command, "-update"); }
     120    if (UBERCAL)       { strextend (&command, "-ubercal"); }
    122121
    123122    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/uniphot/src/update_dvo_setposangle.c

    r35103 r38441  
    5555    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    5656    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    57     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     57    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    5858    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5959
     
    6262      exit (1);
    6363    }
    64     if (!catalog.Naves_disk) {
     64    if (!catalog.Naverage_disk) {
    6565      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    6666      dvo_catalog_unlock (&catalog);
     
    112112    table->hosts[i].pathname = tmppath;
    113113
    114     char command[1024];
    115     snprintf (command, 1024, "setposangle_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
     114    char *command = NULL;
     115    strextend (&command, "setposangle_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f",
    116116              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile,
    117117              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    118118
     119    if (VERBOSE)       { strextend (&command, "-v"); }
     120    if (UPDATE)        { strextend (&command, "-update"); }
     121
    119122    fprintf (stderr, "command: %s\n", command);
    120 
    121     char tmpline[1024];
    122     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    123     if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command);                    strcpy (command, tmpline); }
    124123
    125124    if (PARALLEL_MANUAL) continue;
  • trunk/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r37807 r38441  
    1414  Coords coords;
    1515
    16   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     16  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].scaledValue, &db[0].nativeOrder);
    1717  if (!image) {
    1818      fprintf (stderr, "ERROR: failed to read images\n");
     
    6161  for (i = 0; i < pglob.gl_pathc; i++) {
    6262    catalog.filename = pglob.gl_pathv[i];
    63     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     63    catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    6464    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    6565
     
    6969      exit (2);
    7070    }
    71     if (!catalog.Naves_disk) {
     71    if (!catalog.Naverage_disk) {
    7272      dvo_catalog_unlock (&catalog);
    7373      dvo_catalog_free (&catalog);
Note: See TracChangeset for help on using the changeset viewer.