IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38447


Ignore:
Timestamp:
Jun 12, 2015, 9:44:51 PM (11 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20150419/Ohana/src
Files:
195 edited
11 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150419/Ohana/src

  • branches/eam_branches/ipp-20150419/Ohana/src/checkastro/src/bcatalog.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/checkastro/src/checkastro_images.c

    r36833 r38447  
    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 */
  • branches/eam_branches/ipp-20150419/Ohana/src/checkastro/src/load_catalogs.c

    r36833 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/checkastro/src/load_images.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_duplicate_images.c

    r36833 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_duplicate_measures.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_fix_LAP.c

    r35807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_fix_LAP_edges.c

    r37040 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_fix_LAP_edges_delete.c

    r35805 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_image_photcodes.c

    r34749 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_imagefile.c

    r34749 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_imagename.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_orphans.c

    r27435 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_photcodes.c

    r35758 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_photcodes_single.c

    r35107 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delete_times.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/delstar.c

    r35837 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/find_image_db.c

    r29001 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/delstar/src/find_matches.c

    r34088 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/dvolens/src/update_objects.c

    r37358 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/dvopsps/src/insert_FWobjects_dvopsps.c

    r37672 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/dvopsps/src/insert_detections_dvopsps.c

    r37361 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r37807 r38447  
    215215      fprintf (stderr, "%s\n", mysql_error(mysql));
    216216      fprintf (stderr, "Nbuffer: %d\n", buffer->Nbuffer);
    217       if (DEBUG) fprintf (stderr, "%s\n", buffer->buffer);
     217      if (DEBUG) {
     218        FILE *f = fopen ("dvopsps.dump.sql", "w");
     219        fprintf (f, "%s\n", buffer->buffer);
     220        fclose (f);
     221      }
    218222      status = FALSE;
    219223    }
  • branches/eam_branches/ipp-20150419/Ohana/src/dvopsps/src/insert_diffobj_dvopsps.c

    r37923 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/dvopsps/src/insert_objects_dvopsps.c

    r37361 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/dvosplit/src/dvosplit.c

    r37043 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/dvosplit/src/open_output_catalogs.c

    r33656 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/dvosplit/src/split_averages.c

    r37807 r38447  
    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    }
  • branches/eam_branches/ipp-20150419/Ohana/src/dvosplit/src/split_measures.c

    r37807 r38447  
    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    }
  • branches/eam_branches/ipp-20150419/Ohana/src/dvosplit/src/split_missings.c

    r15743 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/include/fakeastro.h

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

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/fakeastro_images.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/fakestar_catalog.c

    r37807 r38447  
    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   
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/insert_fakestar.c

    r38319 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/load_fake_stars.c

    r37807 r38447  
    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]);
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/load_template_images.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/match_fake_stars.c

    r38319 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/save_fake_stars.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/fakeastro/src/save_fakestars.c

    r37807 r38447  
    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 }
  • branches/eam_branches/ipp-20150419/Ohana/src/gastro/src/getptolemy.c

    r25757 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/gastro2/src/getptolemy.c

    r25757 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/gastro2/src/rfits.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/WriteImageFITS.c

    r14590 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/dvoImageExtract.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/dvoImageOverlaps.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/dvoImagesAtCoords.c

    r36131 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/getstar.c

    r37359 r38447  
    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      }
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/select_by_region.c

    r37044 r38447  
    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",
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c

    r37044 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c

    r37044 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c

    r37044 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imclean/src/wfits.c

    r27435 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/detrend/delete.c

    r28241 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/detrend/output.c

    r27435 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/imphot/dumpfits.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/imreg/delete.c

    r28241 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/imreg/imregclient.c

    r34088 r38447  
    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)) {
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/imreg/output.c

    r27435 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/photreg/delete.c

    r28241 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/photreg/output.c

    r27435 r38447  
    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 */
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/spreg/delete.c

    r28241 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/spreg/output.c

    r27435 r38447  
    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 */
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/detregister.c

    r7080 r38447  
    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)) {
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/detsearch.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/imphotsearch.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/imregister.c

    r27435 r38447  
    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)) {
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/imregtable.c

    r29001 r38447  
    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)) {
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/imsearch.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/imstatreg.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/photreg.c

    r7080 r38447  
    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")) {
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/photsearch.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/spregister.c

    r7080 r38447  
    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)) {
  • branches/eam_branches/ipp-20150419/Ohana/src/imregister/src/spsearch.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/Makefile.Targets

    r38153 r38447  
    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 \
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/autocode.c

    r29537 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/autocode.h

    r27435 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/average-ps1-v1.d

    r36833 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/average-ps1-v2.d

    r36833 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/average-ps1-v3.d

    r36833 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/average-ps1-v4.d

    r36833 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/average-ps1-v5.d

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libautocode/def/average.d

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/Makefile

    r37992 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/include/dvo.h

    r38318 r38447  
    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
     
    6286# define IMREG_DIST  0x01 /* image distributed, only imregister-3.0 */
    6387
    64 /* catalog values to be loaded */
    65 # define LOAD_NONE      0x0000
    66 # define LOAD_AVES      0x0001
    67 # define LOAD_MEAS      0x0002
    68 # define LOAD_MISS      0x0004
    69 # define LOAD_SECF      0x0008
    70 # define SKIP_AVES      0x0010
    71 # define SKIP_MEAS      0x0020
    72 # define SKIP_MISS      0x0040
    73 # define SKIP_SECF      0x0080
    74 # define LOAD_LENSING   0x0100
    75 # define LOAD_LENSOBJ   0x0200
    76 # define SKIP_LENSING   0x0400
    77 # define SKIP_LENSOBJ   0x0800
    78 # define LOAD_STARPAR   0x1000
    79 # define SKIP_STARPAR   0x2000
    80 
    8188/* photometry code types */
    8289// # define PHOT_PRI 0x01
    83 # define PHOT_SEC 0x02
    84 # define PHOT_DEP 0x03
    85 # define PHOT_REF 0x04
    86 # define PHOT_ALT 0x05  /* never stored, only for look-ups */
    87 # define PHOT_MAG 0x06  /* generic magnitude; never stored */
     90typedef enum {
     91  PHOT_SEC  = 0x02,
     92  PHOT_DEP  = 0x03,
     93  PHOT_REF  = 0x04,
     94  PHOT_ALT  = 0x05,  /* never stored, only for look-ups */
     95  PHOT_MAG  = 0x06,  /* generic magnitude; never stored */
     96} DVOPhotCodeTypes;
    8897
    8998/* Image.code values -- these values are 32 bit (as of PS1_V1) */
     
    238247  char   lockstate;
    239248  char   mode;          /* what data storage mode is used for disk file? */
    240   char   format;        /* what data format is used for disk file? */
     249  DVOCatFormat format;  /* what data format is used for disk file? */
    241250  char   virtual;       /* is table in ftable or vtable? */
    242   char   swapped;       /* is table in internal byte-order? */
     251  char   nativeOrder;   /* is table in internal byte-order? */
     252  char   scaledValue;   /* is table in internal byte-order? */
    243253} FITS_DB;
    244254
     
    500510  unsigned short   Nmeasure;             // number of psf measurements
    501511  unsigned short   Nmissing;             // number of missings
    502   unsigned short   Nextend;              // number of extended measurements
     512  unsigned short   Ngalphot;            // number of extended measurements
    503513  uint32_t         measureOffset;        // offset to first psf measurement
    504514  uint32_t         missingOffset;        // offset to first missing obs
     
    720730  unsigned short   Nlensing;             // number of lensing measurements
    721731  unsigned short   Nlensobj;             // number of lensing measurements
    722   unsigned short   Nextend;              // number of extended measurements
     732  unsigned short   Ngalphot;            // number of galphot measurements
    723733  int              measureOffset;        // offset to first psf measurement
    724734  int              missingOffset;        // offset to first missing obs
    725735  int              lensingOffset;        // offset to first lensing obs
    726736  int              lensobjOffset;        // offset to mean lensing data
    727   int              extendOffset;         // offset to extended object entry
     737  int              galphotOffset;       // offset to extended object entry
    728738  int              starparOffset;        // offset to stellar parameter data
    729739  float            refColorBlue;         // color of astrometry ref stars
     
    758768
    759769  // lensing data (optional?)
    760   Lensing *lensing;
    761   Lensobj *lensobj;
    762   StarPar *starpar;
     770  Lensing  *lensing;
     771  Lensobj  *lensobj;
     772  StarPar  *starpar;
     773  GalPhot *galphot;
    763774
    764775  int Nsecfilt;  /* number of secfilt entries for each average entry */
    765   off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nstarpar,      Nsecf_mem;  /* current number of each component in memory */
    766   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nstarpar_disk, Nsecf_disk; /* current number of each component on disk */
    767   off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nstarpar_off,  Nsecf_off;  /* index of first loaded data value */
     776  off_t Naverage,      Nmeasure,      Nmissing,      Nlensing,      Nlensobj,      Nstarpar,      Ngalphot,      Nsecfilt_mem;  /* current number of each component in memory */
     777  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 */
     778  off_t Naverage_off,  Nmeasure_off,  Nmissing_off,  Nlensing_off,  Nlensobj_off,  Nstarpar_off,  Ngalphot_off,  Nsecfilt_off;  /* index of first loaded data value */
    768779
    769780  // note that we use these for the full-sky relphot analysis
     
    781792
    782793  /* pointers to split data files */
    783   struct Catalog *measure_catalog;              /* measure catalog data (split) */
    784   struct Catalog *missing_catalog;              /* missing catalog data (split) */
    785   struct Catalog *secfilt_catalog;              /* secfilt catalog data (split) */
    786   struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
    787   struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
    788   struct Catalog *starpar_catalog;              /* starpar catalog data (split) */
     794  struct Catalog *measure_catalog;              /* measure  catalog data (split) */
     795  struct Catalog *missing_catalog;              /* missing  catalog data (split) */
     796  struct Catalog *secfilt_catalog;              /* secfilt  catalog data (split) */
     797  struct Catalog *lensing_catalog;              /* lensing  catalog data (split) */
     798  struct Catalog *lensobj_catalog;              /* lensobj  catalog data (split) */
     799  struct Catalog *starpar_catalog;              /* starpar  catalog data (split) */
     800  struct Catalog *galphot_catalog;              /* galphot catalog data (split) */
    789801
    790802  unsigned int objID;
     
    793805  /* extra catalog information */
    794806  char lockmode;
    795   char catmode;                         /* storage mode (raw, mef, split, mysql) */
    796   char catformat;                       /* storage format (elixir, panstarrs, etc) */
     807  DVOCatMode     catmode;     /* storage mode (raw, mef, split, mysql) */
     808  DVOCatFormat   catformat;                     /* storage format (elixir, panstarrs, etc) */
     809  DVOCatCompress catcompress;                   // output compress mode
     810  DVOCatFlags    catflags;                      /* choices to be loaded */
     811 
    797812  int sorted;                           /* is measure table average-sorted? (NOTE this is an int only because gfits_scan %t requires it) */
    798  
    799   short catflags; /* choices to be loaded */
     813
    800814
    801815  /* pointers for data manipulation */
     
    946960int dvo_catalog_save_complete (Catalog *catalog, char VERBOSE);
    947961int dvo_catalog_update (Catalog *catalog, char VERBOSE);
    948 int dvo_catalog_catformat (char *catformat);
    949 int dvo_catalog_catmode (char *catmode);
     962DVOCatFormat dvo_catalog_catformat (char *catformat);
     963DVOCatMode dvo_catalog_catmode (char *catmode);
     964DVOCatCompress dvo_catalog_catcompress (char *catcompress);
     965char *dvo_catalog_compress_string (DVOCatCompress catcompress);
    950966void dvo_catalog_test (Catalog *catalog, int halt);
    951967
     
    974990int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format);
    975991
    976 DVOTableFormat FtableGetFormat (FTable *ftable);
    977 
    978 Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary);
    979 Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format);
    980 SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format);
    981 Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
    982 Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
    983 StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format);
    984 int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    985 
    986 int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, char format, SecFilt *primary);
    987 int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format);
    988 int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format);
    989 int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
    990 int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
    991 int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format);
    992 int ImageToFtable (FTable *ftable, Header *theader, char format);
    993 int ImageToVtable (VTable *vtable, Header *theader, char format);
     992DVOCatFormat FtableGetFormat (FTable *ftable);
     993
     994Average *FtableToAverage   (FTable *ftable, off_t *Naverage,  DVOCatFormat *format, SecFilt **primary, char nativeOrder);
     995
     996Measure *FtableToMeasure   (FTable *ftable, Average *average, off_t *Nmeasure,  DVOCatFormat *format, char nativeOrder);
     997Missing *FtableToMissing   (FTable *ftable, Average *average, off_t *Nmissing,  DVOCatFormat *format, char nativeBytes);
     998SecFilt *FtableToSecFilt   (FTable *ftable, Average *average, off_t *Nsecfilt,  DVOCatFormat *format, char nativeOrder);
     999Lensing *FtableToLensing   (FTable *ftable, Average *average, off_t *Nlensing,  DVOCatFormat *format, char nativeOrder);
     1000Lensobj *FtableToLensobj   (FTable *ftable, Average *average, off_t *Nlensobj,  DVOCatFormat *format, char nativeOrder);
     1001StarPar *FtableToStarPar   (FTable *ftable, Average *average, off_t *Nstarpar,  DVOCatFormat *format, char nativeOrder);
     1002GalPhot *FtableToGalPhot (FTable *ftable, Average *average, off_t *Ngalphot, DVOCatFormat *format, char nativeOrder);
     1003
     1004int      FtableToImage   (FTable *ftable, Header *theader, DVOCatFormat *format);
     1005
     1006int MeasureToFtable  (FTable *ftable, Average  *average,  Measure *measure, off_t Nmeasure, DVOCatFormat format, int swapFromNative);
     1007int AverageToFtable  (FTable *ftable, Average  *average,  off_t Naverage,  DVOCatFormat format, SecFilt *primary, int swapFromNative);
     1008int SecFiltToFtable  (FTable *ftable, SecFilt  *secfilt,  off_t Nsecfilt,  DVOCatFormat format, int swapFromNative);
     1009int LensingToFtable  (FTable *ftable, Lensing  *lensing,  off_t Nlensing,  DVOCatFormat format, int swapFromNative);
     1010int LensobjToFtable  (FTable *ftable, Lensobj  *lensobj,  off_t Nlensobj,  DVOCatFormat format, int swapFromNative);
     1011int StarParToFtable  (FTable *ftable, StarPar  *starpar,  off_t Nstarpar,  DVOCatFormat format, int swapFromNative);
     1012int GalPhotToFtable (FTable *ftable, GalPhot *galphot, off_t Ngalphot, DVOCatFormat format, int swapFromNative);
     1013
     1014int ImageToFtable (FTable *ftable, Header *theader, DVOCatFormat format);
     1015int ImageToVtable (VTable *vtable, Header *theader, DVOCatFormat format);
    9941016
    9951017# include "loneos_defs.h"
     
    10231045int gfits_table_set_Image (FTable *ftable);
    10241046int gfits_table_mkheader_Image (Header *header);
    1025 Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped);
     1047Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *scaledValue, char *nativeOrder);
    10261048
    10271049/* flatcorr APIs */
     
    10871109void InitHost (HostInfo *host);
    10881110
    1089 HostTableGroup *HostTableGroups (HostTable *table, int *ngroups);
     1111HostTableGroup *HostTableGroupsUniqueMachines (HostTable *table, int *ngroups);
     1112HostTableGroup *HostTableGroupsMaxNumber (HostTable *table, int *ngroups, int Nmax);
     1113
    10901114int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE);
    10911115
     
    11241148void dvo_lensobj_init (Lensobj *lensobj, int toZero);
    11251149void dvo_starpar_init (StarPar *starpar);
     1150void dvo_galphot_init (GalPhot *galphot);
    11261151
    11271152void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/include/ps1_v5_defs.h

    r38153 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/AstromOffsetMapIO.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/HostTable.c

    r37807 r38447  
    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  }
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/LoadImages.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r37035 r38447  
    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");             \
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r37035 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_catalog.c

    r38318 r38447  
    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;
     
    477522
    478523// init all data, or just catalog data
     524void dvo_galphot_init (GalPhot *galphot) {
     525  galphot->Xfit         = NAN;
     526  galphot->Yfit         = NAN;
     527  galphot->mag          = NAN;
     528  galphot->magErr       = NAN;
     529  galphot->majorAxis    = NAN;
     530  galphot->minorAxis    = NAN;
     531  galphot->majorAxisErr = NAN;
     532  galphot->minorAxisErr = NAN;
     533  galphot->theta        = NAN;
     534  galphot->theta_err    = NAN;
     535  galphot->index        = NAN;
     536  galphot->chisq        = NAN;
     537  galphot->Npix         = 0;
     538
     539  galphot->detID   = -1;
     540  galphot->objID   = -1;
     541  galphot->catID   = -1;
     542  galphot->imageID = -1;
     543
     544  galphot->photcode = 0;
     545  galphot->modelType = 0;
     546}
     547
     548# define INIT_TABLE(TABLE)                      \
     549  catalog[0].TABLE = NULL;                      \
     550  catalog[0].N##TABLE = 0;                      \
     551  catalog[0].N##TABLE##_disk = 0;               \
     552  catalog[0].N##TABLE##_off  = 0;               \
     553  catalog[0].TABLE##_catalog  = NULL;
     554
     555// init all data, or just catalog data
    479556void dvo_catalog_init (Catalog *catalog, int complete) {
    480557
     
    484561    catalog[0].filename = NULL;
    485562
    486     catalog[0].lockmode = 0;
    487     catalog[0].catmode  = 0;
    488     catalog[0].catformat = 0;
    489     catalog[0].catflags = 0;
    490     catalog[0].Nsecfilt = 0;
     563    catalog[0].lockmode    = 0;
     564    catalog[0].catmode     = DVO_MODE_UNDEF;
     565    catalog[0].catformat   = DVO_FORMAT_UNDEF;
     566    catalog[0].catcompress = DVO_COMPRESS_NONE;
     567    catalog[0].catflags    = DVO_LOAD_NONE;
     568    catalog[0].Nsecfilt    = 0;
    491569  }
    492570
    493571  gfits_init_header (&catalog[0].header);
    494 
     572 
    495573  // the following describe the catalog files on disk
    496574  catalog[0].average = NULL;
    497   catalog[0].measure = NULL;
    498   catalog[0].missing = NULL;
     575  catalog[0].Naverage = 0;
     576  catalog[0].Naverage_disk = 0;
     577  catalog[0].Naverage_off  = 0;
     578  // average lacks average_catalog
     579
    499580  catalog[0].secfilt = NULL;
    500  
    501   catalog[0].lensing = NULL;
    502   catalog[0].lensobj = NULL;
    503 
    504   catalog[0].starpar = NULL;
     581  catalog[0].Nsecfilt_mem = 0;
     582  catalog[0].Nsecfilt_disk = 0;
     583  catalog[0].Nsecfilt_off  = 0;
     584  catalog[0].secfilt_catalog = NULL;
     585  // secfilt uses Nsecfilt_mem not Nsecfilt
    505586
    506587  catalog[0].averageT = NULL;
    507588  catalog[0].measureT = NULL;
     589
     590  INIT_TABLE(measure);
     591  INIT_TABLE(missing);
     592  INIT_TABLE(lensing);
     593  INIT_TABLE(lensobj);
     594  INIT_TABLE(starpar);
     595  INIT_TABLE(galphot);
    508596
    509597  catalog[0].objID = 0;
    510598  catalog[0].catID = 0;
    511599  catalog[0].sorted = 0;
    512 
    513   catalog[0].Naverage = 0;
    514   catalog[0].Nmeasure = 0;
    515   catalog[0].Nmissing = 0;
    516   catalog[0].Nsecf_mem = 0;
    517 
    518   catalog[0].Nlensing = 0;
    519   catalog[0].Nlensobj = 0;
    520 
    521   catalog[0].Nstarpar = 0;
    522 
    523   catalog[0].Naves_disk = 0;
    524   catalog[0].Nmeas_disk = 0;
    525   catalog[0].Nmiss_disk = 0;
    526   catalog[0].Nsecf_disk = 0;
    527 
    528   catalog[0].Nlensing_disk = 0;
    529   catalog[0].Nlensobj_disk = 0;
    530 
    531   catalog[0].Nstarpar_disk = 0;
    532 
    533   catalog[0].Naves_off  = 0;
    534   catalog[0].Nmeas_off  = 0;
    535   catalog[0].Nmiss_off  = 0;
    536   catalog[0].Nsecf_off  = 0;
    537 
    538   catalog[0].Nlensing_off  = 0;
    539   catalog[0].Nlensobj_off  = 0;
    540 
    541   catalog[0].Nstarpar_off  = 0;
    542 
    543   /* pointers to SPLIT data files */
    544   catalog[0].measure_catalog = NULL;
    545   catalog[0].missing_catalog = NULL;
    546   catalog[0].secfilt_catalog = NULL;
    547   catalog[0].lensing_catalog = NULL;
    548   catalog[0].lensobj_catalog = NULL;
    549   catalog[0].starpar_catalog = NULL;
    550600
    551601  /* pointers for data manipulation */
     
    579629  if (catalog[0].f == NULL)   return (DVO_CAT_OPEN_FAIL);
    580630
    581   fseeko (catalog[0].f, 0, SEEK_SET);
     631  if (fseeko (catalog[0].f, 0, SEEK_SET)) {
     632    perror ("fseeko: ");
     633    exit (1);
     634  }
    582635  return (DVO_CAT_OPEN_OK);
    583636}
     
    591644
    592645  if (fflush (catalog[0].f)) {
    593     fprintf (stderr, "failed to flush file\n");
     646    perror ("fflush: ");
     647    fprintf (stderr, "failed to flush file %s\n", catalog[0].filename);
    594648    return FALSE;
    595649  }
     
    618672    if (catalog[0].lensobj_catalog) { if (!dvo_catalog_unlock (catalog[0].lensobj_catalog)) { fprintf (stderr, "failed to unlock lensobj\n"); return (0); }}
    619673    if (catalog[0].starpar_catalog) { if (!dvo_catalog_unlock (catalog[0].starpar_catalog)) { fprintf (stderr, "failed to unlock starpar\n"); return (0); }}
     674    if (catalog[0].galphot_catalog) { if (!dvo_catalog_unlock (catalog[0].galphot_catalog)) { fprintf (stderr, "failed to unlock galphot\n"); return (0); }}
    620675  }
    621676  return (1);
     
    860915    catalog[0].secfilt = outsec;
    861916    catalog[0].Nsecfilt = Nsecfilt;
    862     catalog[0].Nsecf_mem = Nsecfilt * catalog[0].Naverage;
     917    catalog[0].Nsecfilt_mem = Nsecfilt * catalog[0].Naverage;
    863918  }
    864919  return (TRUE);
     
    898953      dvo_catalog_free (catalog[0].starpar_catalog);
    899954      free (catalog[0].starpar_catalog);
     955    }
     956    if (catalog[0].galphot_catalog) {
     957      free (catalog[0].galphot_catalog[0].filename);
     958      dvo_catalog_free (catalog[0].galphot_catalog);
     959      free (catalog[0].galphot_catalog);
    900960    }
    901961  }
     
    925985  if (catalog[0].secfilt) {
    926986    free (catalog[0].secfilt);
    927     catalog[0].Nsecf_mem = 0;
     987    catalog[0].Nsecfilt_mem = 0;
    928988    catalog[0].secfilt = NULL;
    929989  }
     
    9431003    catalog[0].starpar = NULL;
    9441004  }
     1005  if (catalog[0].galphot) {
     1006    free (catalog[0].galphot);
     1007    catalog[0].Ngalphot = 0;
     1008    catalog[0].galphot = NULL;
     1009  }
    9451010  if (catalog[0].nOwn_t)      { free (catalog[0].nOwn_t); catalog[0].nOwn_t = NULL; }
    9461011  if (catalog[0].found_t)     { free (catalog[0].found_t); catalog[0].found_t = NULL; }
     
    9491014
    9501015/*
    951   mode   : items to read (LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF)
     1016  mode   : items to read (DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT)
    9521017  format : what table structure on disk (INTERNAL, LONEOS, etc, )
    9531018  style  : raw, mef, split, mysql
     
    9821047
    9831048  // skip empty cpt files
    984   if (primary && !catalog->Naves_disk) {
     1049  if (primary && !catalog->Naverage_disk) {
    9851050    return TRUE;
    9861051  }
     
    10641129      }
    10651130    }
     1131    if (catalog[0].galphot_catalog != NULL) {
     1132      if (catalog[0].Ngalphot_disk == 0) {
     1133        // need to relock (and re-open) file for close elsewhere
     1134        status = dvo_catalog_lock (catalog[0].galphot_catalog, lockmode);
     1135      } else {
     1136        if (!dvo_catalog_backup (catalog[0].galphot_catalog, FALSE)) {
     1137          return FALSE;
     1138        }
     1139      }
     1140    }
    10661141  }
    10671142  return TRUE;
     
    10711146int dvo_catalog_unlink_backup (Catalog *catalog, int primary) {
    10721147
    1073   if (primary && !catalog->Naves_disk) {
     1148  if (primary && !catalog->Naverage_disk) {
    10741149    // skip empty files (empty when read, but output may not be empty)
    10751150    return TRUE;
     
    11201195      }
    11211196    }
     1197    if ((catalog[0].galphot_catalog != NULL) && (catalog[0].Ngalphot_disk > 0)) {
     1198      if (!dvo_catalog_unlink_backup (catalog[0].galphot_catalog, FALSE)) {
     1199        return FALSE;
     1200      }
     1201    }
    11221202  }
    11231203  return TRUE;
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_catalog_create.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_catalog_split.c

    r38153 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_convert.c

    r38153 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r38318 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r38318 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r38318 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r38318 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r38318 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r38318 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_image.c

    r37807 r38447  
    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   
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_image_raw.c

    r37807 r38447  
    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}
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/dvo_util.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/fits_db.c

    r35755 r38447  
    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}
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/flatcorr_io.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/libdvo/src/skyregion_io.c

    r36833 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/Makefile

    r37807 r38447  
    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
     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 = \
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/doc/notes-compress.txt

    r15487 r38447  
     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)
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/extern/gzip.c

    r23816 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/header/F_copy_H.c

    r27435 r38447  
    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}       
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/header/F_modify.c

    r34577 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/include/gfitsio.h

    r38062 r38447  
    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));
    172 int     gfits_extension_is_compressed  PROTO((Header *header));
     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));
     201int     gfits_swap_raw                 PROTO((Matrix *matrix));
     202
    173203off_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));
    174213int     gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions));
    175 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));
    176223
    177224/******************************* Table functions *************/
     
    182229char   *gfits_table_print              PROTO((FTable *ftable,...));
    183230int     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));
    184232int     gfits_bintable_format          PROTO((char *format, char *type, int *Nval, int *Nbytes));
    185233int     gfits_create_table             PROTO((Header *header, FTable *ftable));
     
    198246int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal));
    199247int     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));
    200249int     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));
    201251int     gfits_get_bintable_column_type_by_N  PROTO((Header *header, int N, char *type, int *Nval));
    202 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));
    203253int     gfits_get_table_column         PROTO((Header *header, FTable *table, char *label, void **data));
    204254int     gfits_get_table_column_type    PROTO((Header *header, char *label, char *type));
     
    206256int     gfits_read_table               PROTO((char *filename, FTable *ftable));
    207257int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    208 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));
    209259int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    210260int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4);
     
    218268int     gfits_copy_ftable              PROTO((FTable *in, FTable *out));
    219269int     gfits_copy_vtable              PROTO((VTable *in, VTable *out));
     270int     gfits_copy_ftable_ptr          PROTO((FTable *in, FTable *out));
    220271
    221272int     gfits_create_Theader           PROTO((Header *header, char *type));
     
    226277int     gfits_write_Theader            PROTO((char *filename, Header *header));
    227278
    228 int     gfits_varlength_column_define  PROTO((FTable *ftable, VarLengthColumn *def, int column));
    229 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
    230286
    231287#endif /* FITSIO */
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/matrix/F_matrix.c

    r35164 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/matrix/F_uncompress_data.c

    r23815 r38447  
    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 
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_copy_T.c

    r34088 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_create_T.c

    r35756 r38447  
    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 
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_define_column.c

    r35756 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_get_column.c

    r37039 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_read_T.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_set_column.c

    r37039 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_table_format.c

    r37039 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_table_row.c

    r28241 r38447  
    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}
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_table_varlength.c

    r28241 r38447  
    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}
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_write_T.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libfits/table/F_write_TH.c

    r27435 r38447  
    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}       
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/Makefile

    r38286 r38447  
    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
     
    5256# $(SRC)/gsl_utils.$(ARCH).o     \
    5357
    54 TYPETEST = \
    55 $(TESTDIR)/typetest.$(ARCH)
    56 
    57 $(TYPETEST) : $(LIB)/libohana.$(ARCH).a
    58 
    59 typetest: $(TYPETEST)
    60         for i in $(TYPETEST); do $$i || exit 1; done
    61 
    62 TEST = \
    63 $(TESTDIR)/memtest.$(ARCH)
    64 # $(TESTDIR)/string.$(ARCH)
    65 
    66 testcode: install $(TEST)
    67 test:
    68         $(MAKE) testcode
    69         for i in $(TEST); do $$i; done
    70 
    71 quicktest:
    72         for i in $(TEST); do $$i; done
    73 
    7458$(OBJS): $(INCS)
    7559
     
    8064$(DESTLIB)/libohana.$(DLLTYPE): $(LIB)/libohana.$(ARCH).$(DLLTYPE)
    8165
    82 $(TESTDIR)/%.$(ARCH) : $(TESTDIR)/%.c
    83         $(CC) $^ -o $@ $(TFLAGS)
    84 
    85 .PHONY: test
    86 
     66TESTPROG = memtest typetest string
     67$(TESTPROG) : % : $(TESTBIN)/% $(OBJS)
     68test: $(TESTPROG)
     69        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS); done
     70test.verbose: $(TESTPROG)
     71        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 |& $(TESTHARNESS) -v; done
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/include/ohana.h

    r38282 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/include/ohana_allocate.h

    r33646 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/src/ohana_allocate.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/src/string.c

    r37033 r38447  
    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...)
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/test

    • Property svn:ignore
      •  

        old new  
        44*.darwin_x86
        55*.dSYM
         6memtest
         7string
         8typetest
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/test/string.c

    r10313 r38447  
    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}
  • branches/eam_branches/ipp-20150419/Ohana/src/libohana/test/typetest.c

    r31663 r38447  
    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}
  • branches/eam_branches/ipp-20150419/Ohana/src/markrock/src/markrock.c

    r25757 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/markstar/src/find_images.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/markstar/src/markstar.c

    r15743 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/mosastro/src/getptolemy.c

    r25757 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/mosastro/src/rfits.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/mosastro/src/wfits.c

    r27435 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/include/photdbc.h

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

    r34749 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/Shutdown_dvodist.c

    r33655 r38447  
    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) {
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/args.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/copy_images.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/find_images.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/flag_measures.c

    r29001 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/join_stars.c

    r37807 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/make_subcatalog.c

    r37045 r38447  
    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)
  • branches/eam_branches/ipp-20150419/Ohana/src/photdbc/src/photdbc_catalogs.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/include/relastro.h

    r38062 r38447  
    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 ();
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/BrightCatalog.c

    r38062 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/ImageTable.c

    r36630 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/args.c

    r37807 r38447  
    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 }
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/assign_images.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/bcatalog.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/high_speed_catalogs.c

    r35763 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/high_speed_objects.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/hpm_catalogs.c

    r35763 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/hpm_objects.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/launch_region_hosts.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/load_catalogs.c

    r38062 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/load_images.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/relastro_client.c

    r37807 r38447  
    6969     
    7070      set_db (&db);
     71      gfits_db_init (&db);
    7172
    7273      /* lock and load the image db table */
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/relastro_images.c

    r37807 r38447  
    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 */
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/relastro_merge_source.c

    r37038 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/relastro_objects.c

    r37807 r38447  
    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
  • branches/eam_branches/ipp-20150419/Ohana/src/relastro/src/relastro_parallel_regions.c

    r37807 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/tools/src/fields.c

    r27491 r38447  
    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    }
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/find_image_sgroups.c

    r37807 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/find_image_tgroups.c

    r31160 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/fiximids.c

    r35764 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/fixstkids.c

    r35764 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/load_images.c

    r33654 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/load_images_fiximids.c

    r37043 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/load_images_fixstkids.c

    r37043 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/load_images_setphot.c

    r33654 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/load_images_setposangle.c

    r34749 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/setfwhm.c

    r33654 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/setphot.c

    r38299 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/setposangle.c

    r34749 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/subset_images.c

    r31160 r38447  
    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");
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/uniphot.c

    r33654 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_ckids.c

    r35764 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_fiximids.c

    r35764 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_fixstkids.c

    r35764 r38447  
    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);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_setastrom.c

    r38282 r38447  
    4343    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
    4444    catalog.catmode   = DVO_MODE_UNDEF;   // not needed since we skip empty catalogs
    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    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    4747
     
    5050      exit (1);
    5151    }
    52     if (!catalog.Naves_disk) {
     52    if (!catalog.Naverage_disk) {
    5353      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    5454      dvo_catalog_unlock (&catalog);
     
    9999    table->hosts[i].pathname = tmppath;
    100100
    101     char command[1024];
    102     snprintf (command, 1024, "setastrom_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     101    char *command = NULL;
     102    strextend (&command, "setastrom_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    103103              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    104104              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    105105
    106     char tmpline[1024];
    107     if (VERBOSE)          { snprintf (tmpline, 1024, "%s -v",                   command);                   strcpy (command, tmpline); }
    108     if (UPDATE)           { snprintf (tmpline, 1024, "%s -update",              command);                   strcpy (command, tmpline); }
    109     if (KH_FILE)          { snprintf (tmpline, 1024, "%s -KH %s",               command, KH_FILE);          strcpy (command, tmpline); }
    110     if (DCR_FILE)         { snprintf (tmpline, 1024, "%s -DCR %s",              command, DCR_FILE);         strcpy (command, tmpline); }
    111     if (CAM_FILE)         { snprintf (tmpline, 1024, "%s -CAM %s",              command, CAM_FILE);         strcpy (command, tmpline); }
    112     if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); }
    113 
    114     if (KH_RESET)         { snprintf (tmpline, 1024, "%s -KH-reset",            command);                   strcpy (command, tmpline); }
    115     if (DCR_RESET)        { snprintf (tmpline, 1024, "%s -DCR-reset",           command);                   strcpy (command, tmpline); }
    116     if (CAM_RESET)        { snprintf (tmpline, 1024, "%s -CAM-reset",           command);                   strcpy (command, tmpline); }
     106    if (VERBOSE)          { strextend (&command, "-v"); }
     107    if (UPDATE)           { strextend (&command, "-update"); }
     108    if (KH_FILE)          { strextend (&command, "-KH %s", KH_FILE); }
     109    if (DCR_FILE)         { strextend (&command, "-DCR %s", DCR_FILE); }
     110    if (CAM_FILE)         { strextend (&command, "-CAM %s", CAM_FILE); }
     111    if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
     112    if (KH_RESET)         { strextend (&command, "-KH-reset"); }
     113    if (DCR_RESET)        { strextend (&command, "-DCR-reset"); }
     114    if (CAM_RESET)        { strextend (&command, "-CAM-reset"); }
    117115
    118116    fprintf (stderr, "command: %s\n", command);
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_setgalmodel.c

    r37807 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_setphot.c

    r36630 r38447  
    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    if (VERBOSE)       { strextend (&command, "-v"); }
     118    if (RESET)         { strextend (&command, "-reset"); }
     119    if (UPDATE)        { strextend (&command, "-update"); }
     120    if (UBERCAL)       { strextend (&command, "-ubercal"); }
     121
    117122    fprintf (stderr, "command: %s\n", command);
    118 
    119     char tmpline[1024];
    120     if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
    121     if (RESET)         { snprintf (tmpline, 1024, "%s -reset",          command);                    strcpy (command, tmpline); }
    122     if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command);                    strcpy (command, tmpline); }
    123     if (UBERCAL)       { snprintf (tmpline, 1024, "%s -ubercal",        command);                    strcpy (command, tmpline); }
    124123
    125124    if (PARALLEL_MANUAL) continue;
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_setposangle.c

    r35103 r38447  
    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;
  • branches/eam_branches/ipp-20150419/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r37807 r38447  
    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.