IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15743


Ignore:
Timestamp:
Dec 5, 2007, 3:29:29 PM (18 years ago)
Author:
eugene
Message:

importing updates from eam_branch_20071130

Location:
trunk/Ohana
Files:
11 added
49 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/Makefile.in

    r15129 r15743  
    3030addstar     \
    3131delstar     \
     32dvosplit    \
    3233elixir      \
    3334gastro      \
  • trunk/Ohana/src/addstar/src/SEDfit.c

    r15509 r15743  
    210210    }
    211211  }
    212   outcat[0].Naverage = Nave;
    213   outcat[0].Nmeasure = Nmeas;
     212  outcat[0].Naverage  = Nave;
     213  outcat[0].Nmeasure  = Nmeas;
     214  outcat[0].Nsecf_mem = Nave*Nsec;
    214215 
    215216  free (sourceValue.mags);
  • trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c

    r15036 r15743  
    1313
    1414  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    15   if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
     15  if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
    1616 
    1717  // XXX this is probably not needed anymore
     
    4949    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    5050    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    51     if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
     51    if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
    5252
    5353    // an error exit status here is a significant error
     
    5757    }
    5858
    59     // Nave_disk == 0 implies an empty catalog file
     59    // Naves_disk == 0 implies an empty catalog file
    6060    // for only_match, skip empty catalogs
    61     if ((catalog.Nave_disk == 0) && options[0].only_match) {
     61    if ((catalog.Naves_disk == 0) && options[0].only_match) {
    6262      dvo_catalog_unlock (&catalog);
    6363      dvo_catalog_free (&catalog);
     
    7373    if (!options[0].only_images) {
    7474      SetProtect (TRUE);
    75       dvo_catalog_save (&catalog, VERBOSE);
     75      if (options[0].update) {
     76        catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     77        dvo_catalog_update (&catalog, VERBOSE);
     78      } else {
     79        dvo_catalog_save (&catalog, VERBOSE);
     80      }
    7681      SetProtect (FALSE);
    7782    }
  • trunk/Ohana/src/addstar/src/UpdateDatabase_Refcat.c

    r14401 r15743  
    3737    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    3838    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    39     if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
     39    if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
    4040 
    4141    // an error exit status here is a significant error
     
    4545    }
    4646
    47     // Nave_disk == 0 implies an empty catalog file
     47    // Naves_disk == 0 implies an empty catalog file
    4848    // for only_match, skip empty catalogs
    49     if ((catalog.Nave_disk == 0) && options[0].only_match) {
     49    if ((catalog.Naves_disk == 0) && options[0].only_match) {
    5050      dvo_catalog_unlock (&catalog);
    5151      dvo_catalog_free (&catalog);
     
    6262    if (!options[0].only_images) {
    6363      SetProtect (TRUE);
    64       dvo_catalog_save (&catalog, VERBOSE);
     64      if (options[0].update) {
     65        catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     66        dvo_catalog_update (&catalog, VERBOSE);
     67      } else {
     68        dvo_catalog_save (&catalog, VERBOSE);
     69      }
    6570      SetProtect (FALSE);
    6671    }
  • trunk/Ohana/src/addstar/src/UpdateDatabase_Reflist.c

    r14401 r15743  
    3737    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    3838    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    39     if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
     39    if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
    4040
    4141    // an error exit status here is a significant error
     
    4646
    4747    /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
    48     if ((catalog.Nave_disk == 0) && options[0].only_match) {
     48    if ((catalog.Naves_disk == 0) && options[0].only_match) {
    4949      dvo_catalog_unlock (&catalog);
    5050      dvo_catalog_free (&catalog);
     
    5858    if (!options[0].only_images) {
    5959      SetProtect (TRUE);
    60       dvo_catalog_save (&catalog, VERBOSE);
     60      if (options[0].update) {
     61        catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     62        dvo_catalog_update (&catalog, VERBOSE);
     63      } else {
     64        dvo_catalog_save (&catalog, VERBOSE);
     65      }
    6166      SetProtect (FALSE);
    6267    }
  • trunk/Ohana/src/addstar/src/addstar.c

    r15209 r15743  
    9090    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    9191    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    92     if (options.update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
     92    if (options.update) catalog.catflags = LOAD_AVES | LOAD_MISS | LOAD_SECF;
    9393
    9494    // open as read or write, depending on desire
     
    105105    }
    106106
    107     // Nave_disk == 0 implies an empty catalog file
     107    // Naves_disk == 0 implies an empty catalog file
    108108    // for only_match, skip empty catalogs
    109     if ((catalog.Nave_disk == 0) && options.only_match) {
     109    if ((catalog.Naves_disk == 0) && options.only_match) {
    110110      dvo_catalog_unlock (&catalog);
    111111      dvo_catalog_free (&catalog);
     
    142142    if (Nsubset && !options.only_images) {
    143143      SetProtect (TRUE);
    144       dvo_catalog_save (&catalog, VERBOSE);
     144      if (options.update) {
     145        catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     146        dvo_catalog_update (&catalog, VERBOSE);
     147      } else {
     148        dvo_catalog_save (&catalog, VERBOSE);
     149      }
    145150      SetProtect (FALSE);
    146151    }
  • trunk/Ohana/src/addstar/src/find_matches.c

    r15509 r15743  
    361361  catalog[0].Naverage = Nave;
    362362  catalog[0].Nmeasure = Nmeas;
     363  catalog[0].Nsecf_mem = Nave*Nsecfilt;
    363364  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
    364365
  • trunk/Ohana/src/addstar/src/find_matches_closest.c

    r15509 r15743  
    362362  catalog[0].Naverage = Nave;
    363363  catalog[0].Nmeasure = Nmeas;
     364  catalog[0].Nsecf_mem = Nave*Nsecfilt;
    364365  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
    365366
  • trunk/Ohana/src/addstar/src/find_matches_refstars.c

    r15509 r15743  
    372372  catalog[0].Nmeasure = Nmeas;
    373373  catalog[0].Nmissing = Nmiss;
     374  catalog[0].Nsecf_mem = Nave*Nsecfilt;
    374375  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmiss, Nmatch);
    375376  return (Nmatch);
  • trunk/Ohana/src/addstar/src/load2mass_catalog.c

    r15509 r15743  
    7979  catalog[0].Naverage = Nave;
    8080  catalog[0].Nmeasure = Nmeas;
     81  catalog[0].Nsecf_mem = Nave*Nsec;
    8182  return (TRUE);
    8283}
  • trunk/Ohana/src/addstar/src/sedstar.c

    r8361 r15743  
    3434    }
    3535
    36     // Nave_disk == 0 implies an empty catalog file
    37     if ((incatalog.Nave_disk == 0) && options.only_match) {
     36    // Naves_disk == 0 implies an empty catalog file
     37    if ((incatalog.Naves_disk == 0) && options.only_match) {
    3838      if (VERBOSE) fprintf (stderr, "skipping empty region\n");
    3939      dvo_catalog_unlock (&incatalog);
  • trunk/Ohana/src/delstar/src/delete_imagefile.c

    r12332 r15743  
    3333      exit (2);
    3434    }
    35     if (!catalog.Nave_disk) {
     35    if (!catalog.Naves_disk) {
    3636      dvo_catalog_unlock (&catalog);
    3737      dvo_catalog_free (&catalog);
  • trunk/Ohana/src/delstar/src/delete_imagename.c

    r14590 r15743  
    4444        exit (2);
    4545      }
    46       if (!catalog.Nave_disk) {
     46      if (!catalog.Naves_disk) {
    4747        dvo_catalog_unlock (&catalog);
    4848        dvo_catalog_free (&catalog);
  • trunk/Ohana/src/delstar/src/delete_orphans.c

    r8386 r15743  
    252252  catalog.Nmeasure = Nmeas;
    253253  catalog.Nmissing = Nmiss;
     254  catalog.Nsecf_mem = Nave*Nsecfilt;
     255
    254256  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: %d %d %d\n", Nave, Nmeas, Nmiss);
    255257
  • trunk/Ohana/src/delstar/src/delete_times.c

    r14401 r15743  
    6464      exit (2);
    6565    }
    66     if (!catalog.Nave_disk) {
     66    if (!catalog.Naves_disk) {
    6767      dvo_catalog_unlock (&catalog);
    6868      dvo_catalog_free (&catalog);
  • trunk/Ohana/src/delstar/src/find_matches.c

    r12332 r15743  
    234234  catalog[0].Nmeasure = Nmeas;
    235235  catalog[0].Nmissing = Nmiss;
     236  catalog[0].Nsecf_mem = Nave*Nsecfilt;
     237
    236238  if (VERBOSE) fprintf (stderr, "  ending with Nave, Nmeas, Nmiss: %d %d %d\n", Nave, Nmeas, Nmiss);
    237239
  • trunk/Ohana/src/dvosplit/src/dvosplit.c

    r15722 r15743  
    11# include "dvosplit.h"
    2 # define NROWS 100000 /* ~10MB per row for measures */
    32
     3// dvosplit (outlevel) [-region Rmin Rmax Dmin Dmax]
    44int main (int argc, char **argv) {
    55
    6   // USAGE: dvosplit (outlevel) [-region RA RA DEC DEC]
     6  int i, j, OUT_DEPTH;
     7  SkyTable *sky;
     8  SkyList *skylist, *outlist;
     9  Catalog incatalog, *outcatalogs;
     10  AveLinks *avelinks;
     11  char filename[256];
    712
    8   // the output catalog needs to inherit the SKY_DEPTH of the input catalog.
    9   // if the CATDIR/SkyTable.fits is not found, assume the HST layout (old default)
     13  SetSignals ();
     14  ConfigInit (&argc, argv);
     15  args (argc, argv);
     16
     17  OUT_DEPTH = atoi (argv[1]);
    1018
    1119  // load the sky table for the existing database
     
    1321  SkyTableSetFilenames (sky, CATDIR, "cpt");
    1422
    15   // XXX I should just be copying the input sky and setting the output names on that
    16   // load the sky table for the existing database, generate output names
    17   outsky = SkyTableLoadOptimal (CATDIR, NULL, NULL, SKY_DEPTH_HST, VERBOSE);
    18   SkyTableSetFilenames (outsky, OUTDIR, "cpt");
    19 
    2023  // get the list of populated regions
    21   skylist  = SkyListByPatch (sky, -1, &REGION);
     24  skylist  = SkyListByPatch (sky, -1, &UserPatch);
    2225 
    2326  for (i = 0; i < skylist[0].Nregions; i++) {
     
    2730    // if (current level == out level) skip: no action is needed
    2831    if (skylist[0].regions[i][0].depth >= OUT_DEPTH) continue;
    29 
    30     outlist = SkyListByPatch (outsky, OUT_DEPTH, skylist[0].regions[i]);
    3132
    3233    // set the parameters which guide catalog open/load/create
     
    4243
    4344    // skip empty input catalogs
    44     if (!incatalog.Nave_disk) {
     45    if (!incatalog.Naves_disk) {
    4546      dvo_catalog_unlock (&incatalog);
    4647      dvo_catalog_free (&incatalog);
     
    4849    }
    4950
    50     outcatalog = SkyTableSubdivide (&incatalog, &Noutcatalog);
     51    // change sky.regions[i].depth for these regions
     52    outlist = SkyListByPatch (sky, OUT_DEPTH, skylist[0].regions[i]);
    5153
    52     // split out the average entries:
    53     incatalog.catflags = LOAD_AVES;
    54     Nblocks = incatalog.Nave_disk / NROWS;
    55     for (j = 0; j < Nblocks; j++) {
     54    outcatalogs = open_output_catalogs (outlist);
    5655
    57       // read up to NROWS at a time
    58       dvo_catalog_load_segment (&incatalog, VERBOSE, j*NROWS, NROWS);
     56    avelinks = split_averages (&incatalog, outlist, outcatalogs);
    5957
    60       for (k = 0; k < incatalog.Naverage; k++) {
    61         averef = j*NROWS + k;
    62        
    63         inR  = incatalog.average[k].R;
    64         inD = incatalog.average[k].D;
     58    split_measures (&incatalog, outlist, outcatalogs, avelinks);
    6559
    66         // which of the outcatalogs contains this coordinate?
     60    // XXX missing entries have to be reconstructed if they are desired
     61    // split_missings (&incatalog, outlist, outcatalogs, avelinks);
    6762
    68         N = -1;
    69         for (n = 0; n < Noutcatalog; n++) {
    70           if (inR < outregions[n].Rmin) continue;
    71           if (inR > outregions[n].Rmax) continue;
    72           if (inD < outregions[n].Dmin) continue;
    73           if (inD > outregions[n].Dmax) continue;
    74           Ncat = n;
    75           break;
    76         }
    77         if (Ncat == -1) continue;
     63    dvo_catalog_unlock (&incatalog);
    7864
    79         // XXX this probably needs to be Nave_disk so we can have partial saves
    80         Nout = outcatalog[Ncat].Naverage;
    81         outref[averef] = Nout;
    82         outcat[averef] = Ncat;
    83 
    84         outcatalog[Ncat].average[Nout] = incatalog.average[k];
    85         outcatalog[Ncat].Naverage++;
    86       }
    87 
    88       for (n = 0; n < Noutcatalog; n++) {
    89         dvo_catalog_save_segment (&outcatalog[Ncat], VERBOSE, outcatalog[Ncat].Nave_disk, outcatalog[Ncat].Naverage);
    90       }
     65    for (j = 0; j < outlist[0].Nregions; j++) {
     66      dvo_catalog_unlock (&outcatalogs[j]);
    9167    }
    9268
    93     // split out the measure entries:
    94     incatalog.catflags = LOAD_MEAS;
    95     Nblocks = incatalog.Nmeas_disk / NROWS;
    96     for (j = 0; j < Nblocks; j++) {
    97 
    98       // read up to NROWS at a time
    99       dvo_catalog_load_segment (&incatalog, VERBOSE, j*NROWS, NROWS);
    100 
    101       for (k = 0; k < incatalog.Nmeasure; k++) {
    102 
    103         averef = incatalog.measure[k].averef;
    104         Ncat = outcat[averef];
    105 
    106         Nout = outcatalog[Ncat].Nmeasure;
    107         outcatalog[Ncat].measure[Nout] = incatalog.measure[k];
    108         outcatalog[Ncat].measure[Nout].averef = outref[averef];
    109         outcatalog[Ncat].Nmeasure++;
    110       }
    111 
    112       for (n = 0; n < Noutcatalog; n++) {
    113         dvo_catalog_save_segment (&outcatalog[N], VERBOSE, outcatalog[N].Nmeas_disk, outcatalog[N].Nmeasure);
    114       }
     69    // adjust depth
     70    skylist[0].regions[i][0].table = FALSE;
     71    for (j = 0; j < outlist[0].Nregions; j++) {
     72      outlist[0].regions[j][0].table = TRUE;
    11573    }
    11674
    117     // split out the secfilt entries:
    118     incatalog.catflags = LOAD_SECF;
    119     Nblocks = incatalog.Nsecfilt_disk / NROWS;
    120     for (j = 0; j < Nblocks; j++) {
     75  }
    12176
    122       // read up to NROWS at a time
    123       dvo_catalog_load_segment (&incatalog, VERBOSE, j*NROWS, NROWS);
     77  // save sky table copy
     78  sprintf (filename, "%s/SkyTable.fits", CATDIR);
     79  check_file_access (filename, FALSE, VERBOSE);
     80  if (!SkyTableSave (sky, filename)) {
     81    fprintf (stderr, "ERROR: failed to save sky table for %s\n", CATDIR);
     82    exit (1);
     83  }
    12484
    125       for (k = 0; k < incatalog.Naverage; k++) {
    126 
    127         averef = j*NROWS + k;
    128         Ncat = outcat[averef];
    129         Nout = outref[averef] * Nsecfilt;
    130 
    131         for (n = 0; n < Nsecfilt; n++) {
    132           outcatalog[Ncat].secfilt[Nout + n] = incatalog.measure[k*Nsecfilt + n];
    133         }
    134       }
    135 
    136       for (n = 0; n < Noutcatalog; n++) {
    137         dvo_catalog_save_segment (&outcatalog[N], VERBOSE, outcatalog[N].Nmeas_disk, outcatalog[N].Nmeasure);
    138       }
    139     }
    140 
     85  exit (0);
     86}
  • trunk/Ohana/src/gastro/src/getptolemy.c

    r12332 r15743  
    3636    dvo_catalog_unlock (&catalog);
    3737
    38     // Nave_disk == 0 implies an empty catalog file
     38    // Naves_disk == 0 implies an empty catalog file
    3939    // for only_match, skip empty catalogs
    40     if (!catalog.Nave_disk) {
     40    if (!catalog.Naves_disk) {
    4141      dvo_catalog_free (&catalog);
    4242      continue;
  • trunk/Ohana/src/gastro2/src/getptolemy.c

    r12332 r15743  
    3838    dvo_catalog_unlock (&catalog);
    3939
    40     // Nave_disk == 0 implies an empty catalog file
     40    // Naves_disk == 0 implies an empty catalog file
    4141    // for only_match, skip empty catalogs
    42     if (!catalog.Nave_disk) {
     42    if (!catalog.Naves_disk) {
    4343      dvo_catalog_free (&catalog);
    4444      continue;
  • trunk/Ohana/src/getstar/src/getstar.c

    r15540 r15743  
    2121  output.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    2222  output.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     23  output.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
    2324  output.Nsecfilt  = GetPhotcodeNsecfilt ();
    2425
     
    4748          exit (2);
    4849        }
    49         if (!catalog.Nave_disk) {
     50        if (!catalog.Naves_disk) {
    5051          dvo_catalog_unlock (&catalog);
    5152          dvo_catalog_free (&catalog);
     
    7879        }
    7980        /* skip empty catalogs */
    80         if (!catalog.Nave_disk) continue;
     81        if (!catalog.Naves_disk) continue;
    8182        stars = select_by_image (&catalog, &image, 0, 0, stars, &Nstars);
    8283      }
  • trunk/Ohana/src/getstar/src/select_by_region.c

    r15543 r15743  
    9191  output[0].Naverage = Nave;
    9292  output[0].Nmeasure = Nmeas;
     93  output[0].Nsecf_mem = Nave*Nsecfilt;
     94
    9395  fprintf (stderr, "output catalog has %d stars (%d measures, %d secfilt)\n",
    9496           output[0].Naverage, output[0].Nmeasure, output[0].Nsecfilt);
  • trunk/Ohana/src/libdvo/doc/dvo-catalogs.txt

    r8328 r15743  
    22// APIs related to the DVO catalogs:
    33
    4 // XXX change name
    5 // XXX add SORTED test to load
    6 // XXX add Nsecfilt test? or add an API?
    74load_catalog (Catalog *catalog, int VERBOSE);
    8 // returns
    9 //   0: failure to lock catalog
    10 //   1: success: file is locked and opened
    11 //   2: success: file is locked but empty
    125
    136dvo_catalog_lock (Catalog *catalog, int lockmode);
     
    2013// layout: RAW, MEF, SPLIT
    2114// mode:   READ, WRITE
     15
     16// returns
     17//   DVO_CAT_OPEN_FAIL:  failure to lock catalog
     18//   DVO_CAT_OPEN_OK:    success: file is locked and opened
     19//   DVO_CAT_OPEN_EMPTY: success: file is locked but empty
     20
     21 the catalog is opened and the data for each of the elements (average,
     22 measure, etc) is loaded if requested.  Whether or not the data is
     23 loaded, the values of catalog.Naves_disk,Naves_off,Naverage are set
     24 to match the segment of data loaded.  this API always loads either
     25 the entire data set, or none.  If none, the offset value is set to
     26 point at the end of the table.
    2227
    2328dvo_catalog_save (Catalog *catalog, int VERBOSE);
     
    4348- open and read an existing catalog / error if missing (can be ignored)
    4449
     50dvo_catalog_open (Catalog *catalog, int mode);
    4551
    46 dvo_catalog_open (Catalog *catalog, int mode);
     52dvo_catalog_load_segment_average (Catalog *catalog, int start, int Nrows)
     53
     54 this function reads in the requested number of rows from the catalog
     55 for the Average and SecFilt tables only.  It is possible within the
     56 DVO framework to examine the average values in slices. 
     57
     58dvo_catalog_load_segment_measure (Catalog *catalog, int start, int Nrows)
     59
     60 this function reads in the requested number of rows from the catalog
     61 for the Measure table only.  It is not guaranteed to be possible to
     62 examine the measure values in slices if reference is needed to their
     63 average values.
     64
     65dvo_catalog_load_segment_missing (Catalog *catalog, int start, int Nrows)
     66
     67 this function reads in the requested number of rows from the catalog
     68 for the Missing table only.  It is not guaranteed to be possible to
     69 examine the missing values in slices if reference is needed to their
     70 average values.
  • trunk/Ohana/src/libdvo/include/dvo.h

    r15722 r15743  
    2222typedef 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;
    2323typedef enum {M_UNDEF = -1, M_NONE, M_MEF, M_SPLIT, M_SINGLE, M_CUBE, M_SLICE, M_MODES, N_MODE} ElixirDetrendModes;
     24
     25typedef enum {DVO_CAT_OPEN_FAIL, DVO_CAT_OPEN_OK, DVO_CAT_OPEN_EMPTY} DVOCatalogOpenModes;
    2426
    2527typedef enum {
     
    195197  Missing *missing;
    196198  SecFilt *secfilt;
    197   int Naverage, Nmeasure, Nmissing, Nsecfilt;   /* current number of each component */
    198   int Nave_disk, Nmeas_disk, Nmiss_disk;        /* number of component on disk */
    199   int Nmeas_off;                                /* dist seq of first loaded data value */
    200   /* note the different counting for Nsecfilt */
     199
     200  int Nsecfilt;  /* number of secfilt entries for each average entry */
     201  int Naverage,   Nmeasure,   Nmissing,   Nsecf_mem;  /* current number of each component in memory */
     202  int Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */
     203  int Naves_off,  Nmeas_off,  Nmiss_off,  Nsecf_off;  /* index of first loaded data value */
     204
     205  /* note the different counting for Nsecfilt:
     206     number of secfilt rows on disk is: Nave_disk * Nsecfilt
     207     number of secfilt rows in mem  is: Naverage * Nsecfilt
     208     *** that is just silly, and bad: convert to using Nsec_mem, Nsec_disk, Nsec_off.
     209     *** unless we always require the secfilt and average entries to be loaded sychronously.
     210   */
    201211
    202212  /* pointers to split data files */
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r15509 r15743  
    9090  catalog[0].Nmeasure = 0;
    9191  catalog[0].Nmissing = 0;
    92 
    93   catalog[0].Nave_disk  = 0;
     92  catalog[0].Nsecf_mem = 0;
     93
     94  catalog[0].Naves_disk = 0;
    9495  catalog[0].Nmeas_disk = 0;
    9596  catalog[0].Nmiss_disk = 0;
     97  catalog[0].Nsecf_disk = 0;
     98
     99  catalog[0].Naves_off  = 0;
    96100  catalog[0].Nmeas_off  = 0;
     101  catalog[0].Nmiss_off  = 0;
     102  catalog[0].Nsecf_off  = 0;
    97103
    98104  /* pointers to SPLIT data files */
     
    110116
    111117/* possible exit status for lock_catalog:
    112    0 - failure (including lock failure)
    113    1 - success
    114    2 - empty file (file may be open or closed!)
     118   DVO_CAT_OPEN_FAIL - failure (including lock failure)
     119   DVO_CAT_OPEN_OK - success
     120   DVO_CAT_OPEN_EMPTY - empty file (file may be open or closed!)
    115121*/
    116122int dvo_catalog_lock (Catalog *catalog, int lockmode) {
     
    125131  catalog[0].f = fsetlockfile (catalog[0].filename, 3600.0, catalog[0].lockmode, &dbstate);
    126132
    127   if (dbstate == LCK_MISSING) return (2);
    128   if (dbstate == LCK_EMPTY)   return (2);
    129   if (catalog[0].f == NULL)   return (0);
     133  if (dbstate == LCK_MISSING) return (DVO_CAT_OPEN_EMPTY);
     134  if (dbstate == LCK_EMPTY)   return (DVO_CAT_OPEN_EMPTY);
     135  if (catalog[0].f == NULL)   return (DVO_CAT_OPEN_FAIL);
    130136
    131137  fseek (catalog[0].f, 0, SEEK_SET);
    132   return (1);
     138  return (DVO_CAT_OPEN_OK);
    133139}
    134140
     
    192198 
    193199  switch (dvo_catalog_lock (catalog, catalog[0].lockmode)) {
    194   case 0:
     200  case DVO_CAT_OPEN_FAIL:
    195201    if (VERBOSE) fprintf (stderr, "can't lock file %s\n", catalog[0].filename);
    196202    return (FALSE);
    197   case 1:
     203  case DVO_CAT_OPEN_OK:
    198204    if (!dvo_catalog_load (catalog, VERBOSE)) {
    199205      if (VERBOSE) fprintf (stderr, "failure loading catalog\n");
     
    206212    if (VERBOSE) fprintf (stderr, "loaded existing file %s\n", catalog[0].filename);
    207213    break;
    208   case 2:
     214  case DVO_CAT_OPEN_EMPTY:
    209215    if ((mode == DVO_OPEN_READ) || (mode == DVO_OPEN_UPDATE)) return (TRUE);
    210216    catalog[0].Nsecfilt = Nsecfilt;
     
    235241  if (!status) catalog[0].sorted = TRUE;
    236242
    237   // even if the data is sorted on disk, if we only load the MEAS_META, we are
    238   // treating it as unsorted (eg, append only)
    239   if (catalog[0].catflags & LOAD_MEAS_META) {
    240       catalog[0].sorted = FALSE;
    241   }
    242 
    243243  // determine catmode
    244244  if (!gfits_scan (&catalog[0].header, "NAXIS", "%d", 1, &Naxis)) {
     
    275275}
    276276
    277 // write out the data, unlink if empty?
     277// write out the data, unlink if empty?  'save' means: write out all data currently in
     278// memory.  NOTE: this is currently not always possible: for non-SPLIT moe files, this
     279// operation may require expanding the file size, which does not automatically happen
    278280int dvo_catalog_save (Catalog *catalog, char VERBOSE) {
    279281
     
    281283  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
    282284
    283   if (catalog[0].Nmeas_off != 0) {
    284     if (!dvo_catalog_update (catalog, VERBOSE)) {
    285       return (FALSE);
    286     }
    287     return (TRUE);
    288   }
    289 
     285  // XXX handle return status
    290286  switch (catalog[0].catmode) {
    291287    case DVO_MODE_RAW:
     
    305301}
    306302
     303// write out the in-memory data which extends beyond the data on disk.  NOTE: this is
     304// currently only possible for the SPLIT mode.
    307305int dvo_catalog_update (Catalog *catalog, char VERBOSE) {
     306
     307  // set the 'sorted' header keyword
     308  catalog[0].sorted = FALSE;
     309  gfits_modify (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
    308310
    309311  /* update is only valid for catmode SPLIT */
    310312  switch (catalog[0].catmode) {
    311313    case DVO_MODE_RAW:
    312       dvo_catalog_save_raw (catalog, VERBOSE);
     314      fprintf (stderr, "not allowed for RAW mode\n");
    313315      break;
    314316    case DVO_MODE_MEF:
    315       dvo_catalog_save_mef (catalog, VERBOSE);
     317      fprintf (stderr, "not allowed for MEF mode\n");
    316318      break;
    317319    case DVO_MODE_SPLIT:
    318       /* new file needs to use save_catalog_split */
    319       if (catalog[0].Nave_disk == 0) {
    320         dvo_catalog_save_split (catalog, VERBOSE);
    321       } else {
    322         dvo_catalog_update_split (catalog, VERBOSE);
    323       }
     320      dvo_catalog_update_split (catalog, VERBOSE);
    324321      break;
    325322    default:
     
    360357    catalog[0].secfilt = outsec;
    361358    catalog[0].Nsecfilt = Nsecfilt;
     359    catalog[0].Nsecf_mem = Nsecfilt * catalog[0].Naverage;
    362360  }
    363361  return (TRUE);
     
    396394  style  : raw, mef, split, mysql
    397395*/
     396
     397int dvo_catalog_load_segment (Catalog *catalog, int VERBOSE, int start, int Nrows) {
     398 
     399  int Naxis, split, status;
     400  char measure[80];
     401
     402  // catformat determined in dvo_catalog_load_XXX function
     403  catalog[0].catformat = DVO_FORMAT_UNDEF;
     404
     405  switch (catalog[0].catmode) {
     406    case DVO_MODE_RAW:
     407      if (VERBOSE) fprintf (stderr, "reading catalog (mode DVO_MODE_RAW)\n");
     408      fprintf (stderr, "cannot do this in raw mode\n");
     409      // dvo_catalog_load_segment_raw (catalog, VERBOSE, start, Nrows);
     410      break;
     411    case DVO_MODE_MEF:
     412      if (VERBOSE) fprintf (stderr, "reading catalog (mode DVO_MODE_MEF)\n");
     413      fprintf (stderr, "cannot do this in mef mode\n");
     414      // dvo_catalog_load_segment_mef (catalog, VERBOSE, start, Nrows);
     415      break;
     416    case DVO_MODE_SPLIT:
     417      if (VERBOSE) fprintf (stderr, "reading catalog (mode DVO_MODE_SPLIT)\n");
     418      dvo_catalog_load_segment_split (catalog, VERBOSE, start, Nrows);
     419      break;
     420    default:
     421      fprintf (stderr, "error getting catalog mode\n");
     422      exit (2);
     423  }
     424  return (TRUE);
     425}
     426
  • trunk/Ohana/src/libdvo/src/dvo_catalog_create.c

    r14590 r15743  
    7373    // lock the additional split files
    7474    // XXX clear residual locks if we fail
    75     if (dvo_catalog_lock (catalog[0].measure_catalog, catalog[0].lockmode) != 2) {
     75    if (dvo_catalog_lock (catalog[0].measure_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
    7676      fprintf (stderr, "error with file lock\n");
    7777      exit (2);
    7878    }
    79     if (dvo_catalog_lock (catalog[0].missing_catalog, catalog[0].lockmode) != 2) {
     79    if (dvo_catalog_lock (catalog[0].missing_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
    8080      fprintf (stderr, "error with file lock\n");
    8181      exit (2);
    8282    }
    83     if (dvo_catalog_lock (catalog[0].secfilt_catalog, catalog[0].lockmode) != 2) {
     83    if (dvo_catalog_lock (catalog[0].secfilt_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
    8484      fprintf (stderr, "error with file lock\n");
    8585      exit (2);
  • trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r15487 r15743  
    2828  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
    2929
     30  /* save the current number so we can do partial updates */
     31  catalog[0].Naves_disk = Naverage;
     32  catalog[0].Nmeas_disk = Nmeasure;
     33  catalog[0].Nmiss_disk = Nmissing;
     34  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     35
    3036  /**  Nsecfilt is unusual: it does not list the number of data items in the table
    3137       instead, the number of items is Nsecfilt * Naverage.  **/
    3238  catalog[0].Nsecfilt = Nsecfilt;
     39
     40  /* default values, but we will assign these a valid value before we exit (even if empty) */
     41  catalog[0].average = NULL;
     42  catalog[0].measure = NULL;
     43  catalog[0].missing = NULL;
     44  catalog[0].secfilt = NULL;
    3345
    3446  /* validate table mode */
     
    4658    }
    4759    /* old versions of DVO stored one of the average magnitudes in Average. we save this if needed */
    48     catalog[0].average = FtableToAverage (&ftable, &catalog[0].Naverage, &catalog[0].catformat, &primary);
    49     if (Naverage != catalog[0].Naverage) {
    50       fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naverage);
    51     }
     60    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
     61    if (Naverage != catalog[0].Naves_disk) {
     62      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naves_disk);
     63    }
     64    catalog[0].Naverage = catalog[0].Naves_disk;
     65    catalog[0].Naves_off = 0;
    5266  } else {
    5367    Nbytes = gfits_data_size (&header);
    5468    fseek (f, Nbytes, SEEK_CUR);
     69    ALLOCATE (catalog[0].average, Average, 1);
     70    catalog[0].Naverage = 0;
     71    catalog[0].Naves_off = catalog[0].Naves_disk;
    5572  }
    5673  gfits_free_header (&header);
     
    6986    }
    7087    catalog[0].measure = FtableToMeasure (&ftable, &catalog[0].Nmeasure, &catalog[0].catformat);
    71     if (Nmeasure != catalog[0].Nmeasure) {
    72       fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeasure);
    73     }
     88    if (Nmeasure != catalog[0].Nmeas_disk) {
     89      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeas_disk);
     90    }
     91    catalog[0].Nmeasure = catalog[0].Nmeas_disk;
     92    catalog[0].Nmeas_off = 0;
    7493  } else {
    7594    Nbytes = gfits_data_size (&header);
    7695    fseek (f, Nbytes, SEEK_CUR);
     96    ALLOCATE (catalog[0].measure, Measure, 1);
     97    catalog[0].Nmeasure = 0;
     98    catalog[0].Nmeas_off = catalog[0].Nmeas_disk;
    7799  }
    78100
     
    90112    /* no conversions currently defined */
    91113    catalog[0].missing = gfits_table_get_Missing (&ftable, &catalog[0].Nmissing, NULL);
    92     if (Nmissing != catalog[0].Nmissing) {
    93       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmissing);
    94     }
     114    if (Nmissing != catalog[0].Nmiss_disk) {
     115      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmiss_disk);
     116    }
     117    catalog[0].Nmissing = catalog[0].Nmiss_disk;
     118    catalog[0].Nmiss_off = 0;
    95119  } else {
    96120    Nbytes = gfits_data_size (&header);
    97121    fseek (f, Nbytes, SEEK_CUR);
     122    ALLOCATE (catalog[0].missing, Missing, 1);
     123    catalog[0].Nmissing = 0;
     124    catalog[0].Nmiss_off = catalog[0].Nmiss_disk;
    98125  }
    99126
     
    125152      Ntmpfilt = catalog[0].Nsecfilt;
    126153      Nsecfilt = catalog[0].Nsecfilt + 1;
    127       Ntotal = Nsecfilt * catalog[0].Naverage;
     154      Ntotal = Nsecfilt * catalog[0].Naves_disk;
    128155      ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
    129       for (i = 0; i < catalog[0].Naverage; i++) {
     156      for (i = 0; i < catalog[0].Naves_disk; i++) {
    130157        catalog[0].secfilt[i*Nsecfilt + 0] = primary[i];
    131158        for (j = 0; j < Ntmpfilt; j++) {
     
    134161      }         
    135162      catalog[0].Nsecfilt = Nsecfilt;
     163      catalog[0].Nsecf_disk = Ntotal;
    136164      free (primary);
    137165    }
    138 
     166    catalog[0].Nsecf_mem = catalog[0].Nsecf_disk;
     167    catalog[0].Nsecf_off = 0;
    139168  } else {
    140169    /* no real need to skip the data array here... */
    141170    Nbytes = gfits_data_size (&header);
    142171    fseek (f, Nbytes, SEEK_CUR);
    143     if (primary != NULL) free (primary);
    144   }
    145 
    146   /* save the current number so we can do partial updates */
    147   catalog[0].Nave_disk  = catalog[0].Naverage;
    148   catalog[0].Nmeas_disk = catalog[0].Nmeasure;
    149   catalog[0].Nmiss_disk = catalog[0].Nmissing;
     172    if (primary != NULL) {
     173      free (primary);
     174      catalog[0].Nsecfilt ++;
     175      catalog[0].Nsecf_disk =  catalog[0].Nsecfilt * catalog[0].Naves_disk;
     176    }
     177    ALLOCATE (catalog[0].secfilt, SecFilt, 1);
     178    catalog[0].Nsecf_mem = 0;
     179    catalog[0].Nsecf_off = catalog[0].Nsecf_disk;
     180  }
    150181
    151182  return (TRUE);
  • trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r15035 r15743  
    171171      }         
    172172      catalog[0].Nsecfilt = Nsecfilt;
     173      catalog[0].Nsecf_mem = Ntotal;
    173174      free (primary);
    174175    }
     
    201202
    202203  /* save the current number so we can do partial updates */
    203   catalog[0].Nave_disk = catalog[0].Naverage;
     204  catalog[0].Naves_disk = catalog[0].Naverage;
    204205  catalog[0].Nmeas_disk = catalog[0].Nmeasure;
    205206  catalog[0].Nmiss_disk = catalog[0].Nmissing;
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r15487 r15743  
    11# include <dvo.h>
     2
     3// return options:
     4// * error (cannot lock, open, read, etc)
     5// * empty (file is not found)
     6// * ok
     7
     8int dvo_catalog_secfilt_to_primary (Catalog *catalog, SecFilt **myPrimary, SecFilt **mySecfilt, int *myNsecfilt) {
     9
     10  int i, j, Nallfilt, Nsecfilt, Ntotal;
     11
     12  SecFilt *primary;
     13  SecFilt *secfilt;
     14
     15  if (catalog[0].secfilt == NULL) {       
     16    fprintf (stderr, "missing secfilt, cannot build output averages (dvo_catalog_split.c)\n");
     17    exit (1);
     18  }
     19  secfilt = catalog[0].secfilt;
     20
     21  // 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);
     23
     24  Nallfilt = catalog[0].Nsecfilt;
     25  Nsecfilt = catalog[0].Nsecfilt - 1;
     26  Ntotal = Nsecfilt * catalog[0].Naverage;
     27  ALLOCATE (primary, SecFilt, catalog[0].Naverage);
     28  ALLOCATE (secfilt, SecFilt, Ntotal);
     29
     30  for (i = 0; i < catalog[0].Naverage; i++) {
     31    primary[i] = secfilt[i*Nallfilt + 0];
     32    for (j = 0; j < Nsecfilt; j++) {
     33      secfilt[i*Nsecfilt + j] = catalog[0].secfilt[i*Nallfilt + j + 1];
     34    }
     35  }             
     36  catalog[0].Nsecfilt --;
     37  catalog[0].Nsecf_mem = catalog[0].Naverage*catalog[0].Nsecfilt;
     38
     39  *myPrimary = primary;
     40  *mySecfilt = secfilt;
     41  *myNsecfilt = Nsecfilt;
     42}
     43
     44int dvo_catalog_primary_to_secfilt (Catalog *catalog, SecFilt *primary, int Naves) {
     45
     46  int Ntmpfilt, Nsecfilt, Ntotal, i, j;
     47  SecFilt *tmpfilt;
     48
     49  tmpfilt  = catalog[0].secfilt;
     50  Ntmpfilt = catalog[0].Nsecfilt;
     51
     52  // we do NOT modify Nsecf_disk; this operation only modifies in in-memory values
     53
     54  catalog[0].Nsecfilt ++;
     55  Nsecfilt = catalog[0].Nsecfilt;
     56  Ntotal = Nsecfilt * Naves;
     57
     58  catalog[0].Nsecf_mem = Ntotal;
     59
     60  ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
     61  for (i = 0; i < Naves; i++) {
     62    catalog[0].secfilt[i*Nsecfilt + 0] = primary[i];
     63    for (j = 0; j < Ntmpfilt; j++) {
     64      catalog[0].secfilt[i*Nsecfilt + j + 1] = tmpfilt[i*Ntmpfilt + j];
     65    }
     66  }             
     67  free (primary);
     68  return (TRUE);
     69}
     70
     71int dvo_catalog_save_subcat (Catalog *catalog, FTable *ftable, int start, int Nrows, int Ndisk, int Ntotal) {
     72
     73  Matrix matrix;
     74
     75  /* rewind file pointers and truncate (file is still open) */
     76  fseek (catalog->f, 0, SEEK_SET);
     77
     78  // write PHU header
     79  if (!gfits_fwrite_header  (catalog->f, &catalog->header)) {
     80    fprintf (stderr, "can't write primary header");
     81    return (FALSE);
     82  }
     83
     84  // write the PHU matrix; this is probably a NOP, do I have to keep it in?
     85  gfits_create_matrix (&catalog->header, &matrix);
     86  if (!gfits_fwrite_matrix  (catalog->f, &matrix)) {
     87    fprintf (stderr, "can't write primary matrix");
     88    gfits_free_matrix (&matrix);
     89    return (FALSE);
     90  }
     91  gfits_free_matrix (&matrix);
     92
     93  // write the table data
     94  if (!gfits_fwrite_ftable_range (catalog->f, ftable, start, Nrows, Ndisk, Ntotal)) {
     95    fprintf (stderr, "can't write table data");
     96    return (FALSE);
     97  }
     98  return (TRUE);
     99}
     100
     101int dvo_catalog_open_subcat (Catalog *catalog, Catalog **Subcat, Header *header, char *name, int VERBOSE) {
     102
     103  int status;
     104  char *path, string[80];
     105  Catalog *subcat;
     106  Matrix matrix;
     107
     108  /* in split mode, we need to init & open the corresponding measure file (even if we do not read
     109   * any data in at this stage) */
     110  ALLOCATE (subcat, Catalog, 1);
     111  dvo_catalog_init (subcat, TRUE);
     112
     113  /* needed to find the split files below */
     114  path = pathname (catalog[0].filename);
     115
     116  /* get split filename from main header (paths relative to cpt file) */
     117  if (!gfits_scan (&catalog[0].header, name,  "%s", 1, string)) return (DVO_CAT_OPEN_FAIL);
     118  ALLOCATE (subcat[0].filename, char, strlen(path) + strlen(string) + 2);
     119  sprintf (subcat[0].filename, "%s/%s", path, string);
     120
     121  /* lock & open catalog file */
     122  status = dvo_catalog_lock (subcat, catalog[0].lockmode);
     123  if (status != DVO_CAT_OPEN_OK) {
     124    if (VERBOSE) {
     125      if (status == DVO_CAT_OPEN_EMPTY) {
     126        fprintf (stderr, "%s (%s) is empty\n", name, subcat[0].filename);
     127      } else {
     128        fprintf (stderr, "failure to lock %s (%s)\n", name, subcat[0].filename);
     129      }
     130    }
     131    return (status);
     132  }
     133
     134  /* read PHU */
     135  if (!gfits_load_header (subcat[0].f, &subcat[0].header)) {
     136    if (VERBOSE) fprintf (stderr, "error reading %s header: %s\n", name, subcat[0].filename);
     137    return (DVO_CAT_OPEN_FAIL);
     138  }
     139  /* matrix should be empty : XXX skip the matrix data? */
     140  if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     141    if (VERBOSE) fprintf (stderr, "can't read primary matrix for %s\n", name);
     142    return (DVO_CAT_OPEN_FAIL);
     143  }
     144  gfits_free_matrix (&matrix);
     145  /* read Measure table header */
     146  if (!gfits_fread_header (subcat[0].f, header)) {
     147    if (VERBOSE) fprintf (stderr, "can't read %s PHU header\n", name);
     148    return (DVO_CAT_OPEN_FAIL);
     149  }
     150
     151  *Subcat = subcat;
     152  return (DVO_CAT_OPEN_OK);
     153}
    2154
    3155int dvo_catalog_load_split (Catalog *catalog, int VERBOSE) {
     
    9161  FTable ftable;
    10162  SecFilt *primary;
    11   Catalog *measure, *missing, *secfilt;
    12163
    13164  /* ftable header storage for below */
    14165  ftable.header = &header;
     166  ftable.buffer = NULL;
     167  header.buffer = NULL;
     168  primary = NULL;
    15169
    16170  /* needed to find the split files below */
     
    23177  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
    24178
     179  /* save the current number so we can do partial updates */
     180  catalog[0].Naves_disk = Naverage;
     181  catalog[0].Nmeas_disk = Nmeasure;
     182  catalog[0].Nmiss_disk = Nmissing;
     183  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     184
    25185  /**  Nsecfilt is unusual: it does not list the number of data items in the table
    26186       instead, the number of items is Nsecfilt * Naverage.  **/
    27   catalog[0].Nsecfilt = Nsecfilt;
    28 
    29   /* default values */
     187  catalog[0].Nsecfilt  = Nsecfilt;
     188
     189  /* default values, but we will assign these a valid value before we exit (even if empty) */
    30190  catalog[0].average = NULL;
    31191  catalog[0].measure = NULL;
     
    33193  catalog[0].secfilt = NULL;
    34194
    35   /* XXX EAM : validate table mode */
    36 
    37195  /*** Average Table ***/
    38 
    39196  if (catalog[0].catflags & LOAD_AVES) {
    40197    /* move pointer past header -- must be already read (load_catalog) */
    41198    fseek (catalog[0].f, catalog[0].header.size, SEEK_SET);
    42     /* matrix should be empty */
     199    /* matrix should be empty : XXX should we drop this step and skip the data? */
    43200    if (!gfits_fread_matrix (catalog[0].f, &matrix, &catalog[0].header)) {
    44201      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     
    50207      return (FALSE);
    51208    }
    52     /* read Average table data */
     209    /* read Average table data : format is irrelevant here */
    53210    if (!gfits_fread_ftable_data (catalog[0].f, &ftable)) {
    54211      if (VERBOSE) fprintf (stderr, "can't read table average data");
    55212      return (FALSE);
    56213    }
    57     /* old versions of DVO stored one of the average magnitudes in Average. we save this if needed */
    58     catalog[0].average = FtableToAverage (&ftable, &catalog[0].Naverage, &catalog[0].catformat, &primary);
    59     if (Naverage != catalog[0].Naverage) {
    60       fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naverage);
    61     }
    62     gfits_free_header (&header);
    63   }
     214    /* convert the saved version of the table to the internal version.  Old versions of DVO stored
     215     * one of the average magnitudes in Average.  We save this in case it is needed below.  NOTE:
     216     * primary is only used if we read in the secfilt table, otherwise it should be freed */
     217    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
     218    if (Naverage != catalog[0].Naves_disk) {
     219      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naves_disk);
     220    }
     221    gfits_free_header (&header);
     222    catalog[0].Naverage = catalog[0].Naves_disk;
     223    catalog[0].Naves_off = 0;
     224  } else {
     225    ALLOCATE (catalog[0].average, Average, 1);
     226    catalog[0].Naverage = 0;
     227    catalog[0].Naves_off = catalog[0].Naves_disk;
     228  }
    64229
    65230  /*** Measure Table ***/
    66 
    67   measure = NULL;
    68 
    69   /* (Full Load) */
    70   if (catalog[0].catflags & LOAD_MEAS) {
    71     ALLOCATE (measure, Catalog, 1);
    72     dvo_catalog_init (measure, TRUE);
    73 
    74     /* get split filename from main header (paths relative to cpt file) */
    75     if (!gfits_scan (&catalog[0].header, "MEASURE",  "%s", 1, string)) return (FALSE);
    76     ALLOCATE (measure[0].filename, char, strlen(path) + strlen(string) + 2);
    77     sprintf (measure[0].filename, "%s/%s", path, string);
    78 
    79     /* lock & open catalog file */
    80     if (dvo_catalog_lock (measure, catalog[0].lockmode) != 1) {
    81       fprintf (stderr, "cannot access measure file %s\n", measure[0].filename);
    82       exit (2);
    83     }
    84 
    85     /* read PHU */
    86     if (!gfits_load_header (measure[0].f, &measure[0].header)) {
    87       if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", measure[0].filename);
    88       return (FALSE);
    89     }
    90     /* matrix should be empty */
    91     if (!gfits_fread_matrix (measure[0].f, &matrix, &measure[0].header)) {
    92       if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    93       return (FALSE);
    94     }
    95     /* read Measure table header */
    96     if (!gfits_fread_header (measure[0].f, &header)) {
    97       if (VERBOSE) fprintf (stderr, "can't read measure PHU header\n");
    98       return (FALSE);
    99     }
     231  status = dvo_catalog_open_subcat (catalog, &catalog[0].measure_catalog, ftable.header, "MEASURE", VERBOSE);
     232  if (status == DVO_CAT_OPEN_FAIL) {
     233    return (FALSE);
     234  }
     235  if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nmeas_disk > 0)) {
     236    return (FALSE);
     237  }
     238  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MEAS)) {
     239    // XXX this allows an empty Measure catalog with non-empty Average catalog : is that OK?
    100240    /* read Measure table data */
    101     if (!gfits_fread_ftable_data (measure[0].f, &ftable)) {
     241    if (!gfits_fread_ftable_data (catalog[0].measure_catalog[0].f, &ftable)) {
    102242      if (VERBOSE) fprintf (stderr, "can't read table measure data\n");
    103243      return (FALSE);
    104244    }
    105     /* convert data format to internal */
    106     catalog[0].measure = FtableToMeasure (&ftable, &catalog[0].Nmeasure, &catalog[0].catformat);
    107     if (Nmeasure != catalog[0].Nmeasure) {
    108       fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeasure);
    109     }
     245    /* convert data format to internal : returns number of row read in Nmeasure */
     246    catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
     247    if (Nmeasure != catalog[0].Nmeas_disk) {
     248      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeas_disk);
     249    }
     250    catalog[0].Nmeasure = catalog[0].Nmeas_disk;
    110251    catalog[0].Nmeas_off = 0;
    111     gfits_free_header (&header);
    112     gfits_free_matrix (&matrix);
    113   }
    114 
    115   /* (Meta Load) */
    116   if (catalog[0].catflags & LOAD_MEAS_META) {
    117     ALLOCATE (measure, Catalog, 1);
    118     dvo_catalog_init (measure, TRUE);
    119 
    120     /* get split filename from main header (paths relative to cpt file) */
    121     if (!gfits_scan (&catalog[0].header, "MEASURE",  "%s", 1, string)) return (FALSE);
    122     ALLOCATE (measure[0].filename, char, strlen(path) + strlen(string) + 2);
    123     sprintf (measure[0].filename, "%s/%s", path, string);
    124 
    125     /* lock & open catalog file */
    126     if (dvo_catalog_lock (measure, catalog[0].lockmode) != 1) {
    127       fprintf (stderr, "cannot access measure file %s\n", measure[0].filename);
    128       exit (2);
    129     }
    130 
    131     /* read PHU */
    132     if (!gfits_load_header (measure[0].f, &measure[0].header)) {
    133       if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", measure[0].filename);
    134       return (FALSE);
    135     }
    136 
    137     /* allocate dummy data for valid realloc */
     252  } else {
     253    // XXX is it necessary to generate a template header here?
     254    gfits_create_header (&catalog[0].measure_catalog[0].header);
    138255    ALLOCATE (catalog[0].measure, Measure, 1);
    139 
    140     /* set up the table size information */
    141     catalog[0].Nmeasure  = 0;        /* no rows loaded */
    142     catalog[0].Nmeas_off = Nmeasure; /* start of new entries */
    143   }
    144   catalog[0].measure_catalog = measure;
     256    catalog[0].Nmeasure = 0;
     257    catalog[0].Nmeas_off = catalog[0].Nmeas_disk;
     258  }
     259  gfits_free_header (ftable.header);
    145260
    146261  /*** Missing Table ***/
    147 
    148   missing = NULL;
    149   if (catalog[0].catflags & LOAD_MISS) {
    150     ALLOCATE (missing, Catalog, 1);
    151     dvo_catalog_init (missing, TRUE);
    152 
    153     /* get split filename from main header (paths relative to cpt file) */
    154     if (!gfits_scan (&catalog[0].header, "MISSING",  "%s", 1, string)) return (FALSE);
    155     ALLOCATE (missing[0].filename, char, strlen(path) + strlen(string) + 2);
    156     sprintf (missing[0].filename, "%s/%s", path, string);
    157 
    158     /* lock & open catalog file */
    159     status = dvo_catalog_lock (missing, catalog[0].lockmode);
    160     if (!status) {
    161       fprintf (stderr, "ERROR: cannot access missing file %s\n", missing[0].filename);
    162       exit (2);
    163     }
    164     if (status == 2) {
    165         /* MISSING table is empty (this is not an error) */
    166         gfits_create_header (&missing[0].header);
    167         goto missing_empty;
    168     }
    169 
    170     /* read PHU */
    171     if (!gfits_load_header (missing[0].f, &missing[0].header)) {
    172       if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", missing[0].filename);
    173       return (FALSE);
    174     }
    175     /* matrix should be empty */
    176     if (!gfits_fread_matrix (missing[0].f, &matrix, &missing[0].header)) {
    177       if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    178       return (FALSE);
    179     }
    180     /* read Missing table header */
    181     if (!gfits_fread_header (missing[0].f, &header)) {
    182       if (VERBOSE) fprintf (stderr, "can't read table missing header\n");
    183       return (FALSE);
    184     }
     262  status = dvo_catalog_open_subcat (catalog, &catalog[0].missing_catalog, ftable.header, "MISSING", VERBOSE);
     263  if (status == DVO_CAT_OPEN_FAIL) {
     264    return (FALSE);
     265  }
     266  if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nmiss_disk > 0)) {
     267    return (FALSE);
     268  }
     269  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MISS)) {
    185270    /* read Missing table data */
    186     if (!gfits_fread_ftable_data (missing[0].f, &ftable)) {
     271    if (!gfits_fread_ftable_data (catalog[0].missing_catalog[0].f, &ftable)) {
    187272      if (VERBOSE) fprintf (stderr, "can't read table missing data\n");
    188273      return (FALSE);
    189274    }
    190     /* no conversions currently defined */
    191     catalog[0].missing = gfits_table_get_Missing (&ftable, &catalog[0].Nmissing, NULL);
    192     if (Nmissing != catalog[0].Nmissing) {
    193       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmissing);
    194     }
    195     gfits_free_header (&header);
    196     gfits_free_matrix (&matrix);
    197   }
    198 missing_empty:
    199   catalog[0].missing_catalog = missing;
     275    /* no conversions currently defined : this just does the byte swap */
     276    catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
     277    if (Nmissing != catalog[0].Nmiss_disk) {
     278      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmiss_disk);
     279    }
     280    catalog[0].Nmissing = catalog[0].Nmiss_disk;
     281    catalog[0].Nmiss_off = 0;
     282  } else {
     283    // XXX is it necessary to generate a template header here?
     284    gfits_create_header (&catalog[0].missing_catalog[0].header);
     285    ALLOCATE (catalog[0].missing, Missing, 1);
     286    catalog[0].Nmissing = 0;
     287    catalog[0].Nmiss_off = catalog[0].Nmiss_disk;
     288  }
     289  gfits_free_header (ftable.header);
    200290
    201291  /*** Secfilt Table ***/
    202 
    203   secfilt = NULL;
    204   if (catalog[0].catflags & LOAD_SECF) {
    205     ALLOCATE (secfilt, Catalog, 1);
    206     dvo_catalog_init (secfilt, TRUE);
    207 
    208     /* get split filename from main header (paths relative to cpt file) */
    209     if (!gfits_scan (&catalog[0].header, "SECFILT",  "%s", 1, string)) return (FALSE);
    210     ALLOCATE (secfilt[0].filename, char, strlen(path) + strlen(string) + 2);
    211     sprintf (secfilt[0].filename, "%s/%s", path, string);
    212 
    213     /* lock & open catalog file */
    214     if (dvo_catalog_lock (secfilt, catalog[0].lockmode) != 1) {
    215       fprintf (stderr, "cannot access secfilt file %s\n", secfilt[0].filename);
    216       exit (2);
    217     }
    218 
    219     /* read PHU */
    220     if (!gfits_load_header (secfilt[0].f, &secfilt[0].header)) {
    221       if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", secfilt[0].filename);
    222       return (FALSE);
    223     }
    224     /* matrix should be empty */
    225     if (!gfits_fread_matrix (secfilt[0].f, &matrix, &secfilt[0].header)) {
    226       if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    227       return (FALSE);
    228     }
    229     /* read secfilt table header */
    230     if (!gfits_fread_header (secfilt[0].f, &header)) {
    231       if (VERBOSE) fprintf (stderr, "can't read table secfilt header\n");
    232       return (FALSE);
    233     }
     292  status = dvo_catalog_open_subcat (catalog, &catalog[0].secfilt_catalog, ftable.header, "SECFILT", VERBOSE);
     293  if (status == DVO_CAT_OPEN_FAIL) {
     294    return (FALSE);
     295  }
     296  if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nsecf_disk > 0)) {
     297    return (FALSE);
     298  }
     299  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_SECF)) {
    234300    /* read secfilt table data */
    235     if (!gfits_fread_ftable_data (secfilt[0].f, &ftable)) {
     301    if (!gfits_fread_ftable_data (catalog[0].secfilt_catalog[0].f, &ftable)) {
    236302      if (VERBOSE) fprintf (stderr, "can't read table secfilt data\n");
    237303      return (FALSE);
    238304    }
    239     Nexpect = catalog[0].Nsecfilt * catalog[0].Naverage;
    240305    catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
    241     if (Nexpect != Nitems) {
    242       fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nexpect, Nitems);
    243     }
     306    if (Nitems != catalog[0].Nsecf_disk) {
     307      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nitems, catalog[0].Nsecf_disk);
     308    }
     309    catalog[0].Nsecf_mem = catalog[0].Nsecf_disk;
     310    catalog[0].Nsecf_off = 0;
    244311
    245312    /* if primary is defined, we were supplied with one additional average magnitude from Average
    246313       we need to interleave these magnitudes with the secfilt entries just loaded */
    247314    if (primary != NULL) {
    248       int Ntmpfilt, Ntotal, i, j;
    249       SecFilt *tmpfilt;
    250       tmpfilt  = catalog[0].secfilt;
    251       Ntmpfilt = catalog[0].Nsecfilt;
    252       Nsecfilt = catalog[0].Nsecfilt + 1;
    253       Ntotal = Nsecfilt * catalog[0].Naverage;
    254       ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
    255       for (i = 0; i < catalog[0].Naverage; i++) {
    256         catalog[0].secfilt[i*Nsecfilt + 0] = primary[i];
    257         for (j = 0; j < Ntmpfilt; j++) {
    258           catalog[0].secfilt[i*Nsecfilt + j + 1] = tmpfilt[i*Ntmpfilt + j];
    259         }
    260       }         
    261       catalog[0].Nsecfilt = Nsecfilt;
     315      // this modifies catalog.Nsecf_mem,Nsecfilt
     316      dvo_catalog_primary_to_secfilt (catalog, primary, catalog[0].Naves_disk);
     317    }
     318  } else {
     319    if (primary != NULL) {
    262320      free (primary);
    263     }
    264 
    265 
    266     gfits_free_header (&header);
    267     gfits_free_matrix (&matrix);
    268   } else {
    269     if (primary != NULL) free (primary);
    270   }
    271 
    272   catalog[0].secfilt_catalog = secfilt;
    273 
    274   /* save the current number so we can do partial updates */
    275   catalog[0].Nave_disk  = Naverage;
    276   catalog[0].Nmeas_disk = Nmeasure;
    277   catalog[0].Nmiss_disk = Nmissing;
     321      catalog[0].Nsecfilt ++;
     322    }
     323    gfits_create_header (&catalog[0].secfilt_catalog[0].header);
     324    ALLOCATE (catalog[0].secfilt, SecFilt, 1);
     325    catalog[0].Nsecf_mem = 0;
     326    catalog[0].Nsecf_off = catalog[0].Nsecf_disk;
     327  }
     328  gfits_free_header (ftable.header);
    278329
    279330  return (TRUE);
    280331}
    281332
    282 /* save_catalog_split writes complete new files from scratch */
     333// I need to always read both average and secfilt at the same time to correctly manage the
     334// primary secfilt values...
     335int dvo_catalog_load_segment_split (Catalog *catalog, int VERBOSE, int start, int Nrows) {
     336
     337  int Naverage, Nsecfilt, Nexpect, Nitems, Nmeasure, Nmissing;
     338  Header header;
     339  Matrix matrix;
     340  FTable ftable;
     341  SecFilt *primary;
     342
     343  /* ftable header storage for below */
     344  ftable.header = &header;
     345  ftable.buffer = NULL;
     346  header.buffer = NULL;
     347  primary = NULL;
     348
     349  /*** Average (& SecFilt) Table ***/
     350  if (catalog[0].catflags & LOAD_AVES) {
     351
     352    /*** load the Average data ***/
     353    /* move pointer past header -- must be already read (load_catalog) */
     354    fseek (catalog[0].f, catalog[0].header.size, SEEK_SET);
     355    /* matrix should be empty : XXX should we drop this step and skip the data? */
     356    if (!gfits_fread_matrix (catalog[0].f, &matrix, &catalog[0].header)) {
     357      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     358      return (FALSE);
     359    }
     360    /* read Average table header */
     361    if (!gfits_fread_header (catalog[0].f, &header)) {
     362      if (VERBOSE) fprintf (stderr, "can't read table average header");
     363      return (FALSE);
     364    }
     365    /* read Average table data : format is irrelevant here */
     366    if (!gfits_fread_ftable_range (catalog[0].f, &ftable, start, Nrows)) {
     367      if (VERBOSE) fprintf (stderr, "can't read table average data");
     368      return (FALSE);
     369    }
     370
     371    /* convert the saved version of the table to the internal version.  Old versions of DVO stored
     372     * one of the average magnitudes in Average.  We save this in case it is needed below.  NOTE:
     373     * primary is only used if we read in the secfilt table, otherwise it should be freed */
     374    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
     375    if (Naverage != Nrows) {
     376      // XXX this condition denotes the eof has been reached; not an error or a warning
     377      // fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, Nrows);
     378    }
     379    gfits_free_header (&header);
     380    catalog[0].Naverage = Naverage;
     381    catalog[0].Naves_off = start;
     382
     383    /*** load the secfilt data ***/
     384    Catalog *subcat = catalog[0].secfilt_catalog;
     385
     386    /* move pointer past header -- must be already read (load_catalog) */
     387    fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     388    /* matrix should be empty : XXX should we drop this step and skip the data? */
     389    if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     390      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     391      return (FALSE);
     392    }
     393    /* read Secfilt table header */
     394    if (!gfits_fread_header (subcat[0].f, &header)) {
     395      if (VERBOSE) fprintf (stderr, "can't read table measure header");
     396      return (FALSE);
     397    }
     398    /* read Secfilt table data : format is irrelevant here */
     399    if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start*catalog[0].Nsecfilt, catalog[0].Naverage*catalog[0].Nsecfilt)) {
     400      if (VERBOSE) fprintf (stderr, "can't read table measure data");
     401      return (FALSE);
     402    }
     403
     404    Nexpect = catalog[0].Naverage * catalog[0].Nsecfilt;
     405    catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
     406    if (Nitems != Nexpect) {
     407      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nitems, Nexpect);
     408    }
     409    catalog[0].Nsecf_mem = catalog[0].Naverage * catalog[0].Nsecfilt;
     410    catalog[0].Nsecf_off = start               * catalog[0].Nsecfilt;
     411
     412    /* if primary is defined, we were supplied with one additional average magnitude from Average
     413       we need to interleave these magnitudes with the secfilt entries just loaded */
     414    if (primary != NULL) {
     415      dvo_catalog_primary_to_secfilt (catalog, primary, Nrows);
     416    }
     417    gfits_free_header (&header);
     418    gfits_free_matrix (&matrix);
     419  }
     420
     421  // XXX check the open status of the catalog
     422  if (catalog[0].catflags & LOAD_MEAS) {
     423
     424    Catalog *subcat = catalog[0].measure_catalog;
     425
     426    /* move pointer past header -- must be already read (load_catalog) */
     427    fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     428    /* matrix should be empty : XXX should we drop this step and skip the data? */
     429    if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     430      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     431      return (FALSE);
     432    }
     433    /* read Measure table header */
     434    if (!gfits_fread_header (subcat[0].f, &header)) {
     435      if (VERBOSE) fprintf (stderr, "can't read table measure header");
     436      return (FALSE);
     437    }
     438    /* read Measure table data : format is irrelevant here */
     439    if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     440      if (VERBOSE) fprintf (stderr, "can't read table measure data");
     441      return (FALSE);
     442    }
     443
     444    /* convert data format to internal : returns number of row read in Nmeasure */
     445    catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
     446    if (Nmeasure != Nrows) {
     447      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, Nrows);
     448    }
     449    gfits_free_header (&header);
     450    gfits_free_matrix (&matrix);
     451    catalog[0].Nmeasure = Nmeasure;
     452    catalog[0].Nmeas_off = start;
     453  }
     454
     455  // XXX check the open status of the catalog?
     456  if (catalog[0].catflags & LOAD_MISS) {
     457
     458    Catalog *subcat = catalog[0].missing_catalog;
     459
     460    /* move pointer past header -- must be already read (load_catalog) */
     461    fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     462    /* matrix should be empty : XXX should we drop this step and skip the data? */
     463    if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     464      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     465      return (FALSE);
     466    }
     467    /* read Missing table header */
     468    if (!gfits_fread_header (subcat[0].f, &header)) {
     469      if (VERBOSE) fprintf (stderr, "can't read table missing header");
     470      return (FALSE);
     471    }
     472    /* read Missing table data : format is irrelevant here */
     473    if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     474      if (VERBOSE) fprintf (stderr, "can't read table missing data");
     475      return (FALSE);
     476    }
     477
     478    /* no conversions currently defined : this just does the byte swap */
     479    catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
     480    if (Nmissing != Nrows) {
     481      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, Nrows);
     482    }
     483    gfits_free_header (&header);
     484    gfits_free_matrix (&matrix);
     485    catalog[0].Nmissing = Nmissing;
     486    catalog[0].Nmiss_off = start;
     487  }
     488  return (TRUE);
     489}
     490
     491/* save_catalog_split writes all data currently in memory to disk */
    283492int dvo_catalog_save_split (Catalog *catalog, char VERBOSE) {
    284493
     
    290499  SecFilt *primary, *secfilt;
    291500  int i, j, Nsecfilt, Nallfilt, Ntotal;
     501  int Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     502  int first, start, Nrows;
    292503
    293504  ftable.header = &header;
    294 
    295   if (catalog[0].Naverage == 0) {
     505  ftable.buffer = NULL;
     506  header.buffer = NULL;
     507  primary = NULL;
     508 
     509  // skip empty catalogs: it is illegal to have Measures without corresponding Averages
     510  Naves_disk_new = MAX (catalog[0].Naves_disk, catalog[0].Naverage + catalog[0].Naves_off);
     511  if (Naves_disk_new == 0) {
    296512    if (VERBOSE) fprintf (stderr, "no stars in catalog, skipping\n");
    297513    return (TRUE);
    298514  }
    299515
    300   /* for the appropriate types, pull out the first secfilt and pass to AverageToFtable as primary */
    301   if ((catalog[0].catformat == DVO_FORMAT_ELIXIR) || // special case for ELIXIR
    302       (catalog[0].catformat == DVO_FORMAT_LONEOS)) { // special case for LONEOS
    303     if (catalog[0].secfilt == NULL) {       
    304       fprintf (stderr, "missing secfilt, cannot build output averages (dvo_catalog_split.c:544)\n");
    305       exit (1);
    306     }
    307     secfilt = catalog[0].secfilt;
    308 
    309     Nallfilt = catalog[0].Nsecfilt;
    310     Nsecfilt = catalog[0].Nsecfilt - 1;
    311     Ntotal = Nsecfilt * catalog[0].Naverage;
    312     ALLOCATE (primary, SecFilt, catalog[0].Naverage);
    313     ALLOCATE (secfilt, SecFilt, Ntotal);
    314 
    315     for (i = 0; i < catalog[0].Naverage; i++) {
    316       primary[i] = secfilt[i*Nallfilt + 0];
    317       for (j = 0; j < Nsecfilt; j++) {
    318         secfilt[i*Nsecfilt + j] = catalog[0].secfilt[i*Nallfilt + j + 1];
    319       }
    320     }           
    321   } else {
    322     primary = NULL;
    323     secfilt = catalog[0].secfilt;
    324     Nsecfilt = catalog[0].Nsecfilt;
    325   }
     516  // for the appropriate types, pull out the first secfilt and pass to AverageToFtable as primary
     517  switch (catalog[0].catformat) {
     518    case DVO_FORMAT_ELIXIR: // special case for ELIXIR
     519    case DVO_FORMAT_LONEOS: // special case for LONEOS
     520      dvo_catalog_secfilt_to_primary (catalog, &primary, &secfilt, &Nsecfilt);
     521      break;
     522    default:
     523      primary = NULL;
     524      secfilt = catalog[0].secfilt;
     525      Nsecfilt = catalog[0].Nsecfilt;
     526      break;
     527  }
     528
     529  Nmeas_disk_new = MAX (catalog[0].Nmeas_disk, catalog[0].Nmeasure + catalog[0].Nmeas_off);
     530  Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
     531  Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
    326532
    327533  /* make sure header is consistent with data */
    328   gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, catalog[0].Naverage);
    329   gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, catalog[0].Nmeasure);
    330   gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, catalog[0].Nmissing);
     534  gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, Naves_disk_new);
     535  gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, Nmeas_disk_new);
     536  gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, Nmiss_disk_new);
    331537  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
    332538  gfits_modify (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    333539
    334   /* rewind file pointers and truncate (file is still open) */
    335   fseek (catalog[0].f, 0, SEEK_SET);
    336 
    337   /* write table PHU header - always write this out */
    338   /* XXX EAM : check if disk file size has changed */
    339   if (!gfits_fwrite_header  (catalog[0].f, &catalog[0].header)) {
    340     fprintf (stderr, "can't write primary header");
    341     goto failure;
    342   }
    343 
    344540  /* in split mode, we can save only part of the data */
    345541
    346542  /*** Average Table ***/
    347 
     543  if ((catalog[0].catflags & LOAD_AVES) && (catalog[0].average != NULL)) {
     544
     545    first  = 0;                    // first row in memory to write
     546    start  = catalog[0].Naves_off; // first disk row to write
     547    Nrows  = catalog[0].Naverage - first;
     548
     549    assert (Nrows >= 0);
     550    assert (first >= 0);
     551    assert (first < catalog[0].Naverage);
     552    assert (catalog[0].Naves_disk >= catalog[0].Naves_off);
     553
     554    /* convert internal to external format */
     555    if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary)) {
     556      fprintf (stderr, "trouble converting format\n");
     557      goto failure;
     558    }
     559
     560    if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naves_disk, Naves_disk_new)) {
     561      fprintf (stderr, "failure writing Average table\n");
     562      goto failure;
     563    }
     564    gfits_free_header (&header);
     565    gfits_free_table (&ftable);
     566  } else {
     567    // even if we do not save the average table, we need to keep the header in sync
     568    /* rewind file pointers and truncate (file is still open) */
     569    fseek (catalog[0].f, 0, SEEK_SET);
     570
     571    /* write table PHU header - always write this out */
     572    /* XXX EAM : check if disk file size has changed */
     573    if (!gfits_fwrite_header  (catalog[0].f, &catalog[0].header)) {
     574      fprintf (stderr, "can't write primary header");
     575      goto failure;
     576    }
     577  }
     578
     579  /*** Measure Table ***/
     580  if ((catalog[0].catflags & LOAD_MEAS) && (catalog[0].measure != NULL)) {
     581
     582    first  = 0;                    // first row in memory to write
     583    start  = catalog[0].Nmeas_off; // first disk row to write
     584    Nrows  = catalog[0].Nmeasure - first;
     585
     586    assert (Nrows >= 0);
     587    assert (first >= 0);
     588    assert (first < catalog[0].Nmeasure);
     589    assert (catalog[0].Nmeas_disk >= catalog[0].Nmeas_off);
     590
     591    // convert to external table format
     592    if (!MeasureToFtable (&ftable, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
     593      fprintf (stderr, "trouble converting format\n");
     594      goto failure;
     595    }
     596
     597    // write out Measure table
     598    if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeas_disk, Nmeas_disk_new)) {
     599      fprintf (stderr, "trouble writing Measure table\n");
     600      goto failure;
     601    }
     602    gfits_free_header (&header);
     603    gfits_free_table (&ftable);
     604  }
     605
     606  /*** Missing Table ***/
     607  if ((catalog[0].catflags & LOAD_MISS) && (catalog[0].missing != NULL)) {
     608
     609    if (catalog[0].Nmiss_off != 0) {
     610      fprintf (stderr, "inconsistency: Missing table cannot be written in segments\n");
     611      goto failure;
     612    }
     613
     614    // convert to external table format
     615    if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing)) {
     616      fprintf (stderr, "trouble converting format\n");
     617      goto failure;
     618    }
     619
     620    // write out Missing table (must write out entire table)
     621    if (!dvo_catalog_save_subcat (catalog[0].missing_catalog, &ftable, 0, catalog[0].Nmissing, catalog[0].Nmissing, catalog[0].Nmissing)) {
     622      fprintf (stderr, "trouble writing Missing Table\n");
     623      goto failure;
     624    }
     625    gfits_free_header (&header);
     626    gfits_free_table (&ftable);
     627  }
     628
     629  /*** Secfilt Table ***/
     630  if ((catalog[0].catflags & LOAD_SECF) && (catalog[0].secfilt != NULL)) {
     631
     632    first  = 0;                    // first row in memory to write
     633    start  = catalog[0].Nsecf_off; // first disk row to write
     634    Nitems = catalog[0].Nsecf_mem;
     635    Nrows  = Nitems - first;
     636
     637    assert (Nrows >= 0);
     638    assert (first >= 0);
     639    assert (first < Nitems);
     640    assert (catalog[0].Nsecf_disk >= catalog[0].Nsecf_off);
     641    // XXX check these for consistency...
     642
     643    // convert to external table format
     644    SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat);
     645
     646    // write out SecFilt table
     647    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
     648      fprintf (stderr, "failure writing SecFilt table\n");
     649      goto failure;
     650    }
     651    gfits_free_header (&header);
     652    gfits_free_table (&ftable);
     653  }
     654
     655  /* free temp storage */
     656  if (primary != NULL) {
     657    free (primary);
     658    free (secfilt);
     659  }
     660  return (TRUE);
     661
     662failure:
     663  /* free temp storage */
     664  gfits_free_header (&header);
     665  gfits_free_table (&ftable);
     666  if (primary != NULL) {
     667    free (primary);
     668    free (secfilt);
     669  }
     670  return (FALSE);
     671}
     672
     673/* update_catalog_split only writes new lines to file. */
     674int dvo_catalog_update_split (Catalog *catalog, char VERBOSE) {
     675
     676  int i, Nx, Ny, Nlines;
     677  int Nitems, Nskip, Nout, Ndisk, Nstart;
     678  Matrix matrix;
     679  Header header;
     680  FTable ftable;
     681  Catalog *catfile;
     682  SecFilt *primary, *secfilt;
     683  int j, Nsecfilt, Nallfilt, Ntotal;
     684  int Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     685  int first, start, Nrows;
     686
     687  ftable.header = &header;
     688  ftable.buffer = NULL;
     689  header.buffer = NULL;
     690
     691  // skip empty catalogs: it is illegal to have Measures without corresponding Averages
     692  Naves_disk_new = MAX (catalog[0].Naves_disk, catalog[0].Naverage + catalog[0].Naves_off);
     693  if (Naves_disk_new == 0) {
     694    if (VERBOSE) fprintf (stderr, "no stars in catalog, skipping\n");
     695    return (TRUE);
     696  }
     697
     698  // for the appropriate types, pull out the first secfilt and pass to AverageToFtable as primary
     699  switch (catalog[0].catformat) {
     700    case DVO_FORMAT_ELIXIR: // special case for ELIXIR
     701    case DVO_FORMAT_LONEOS: // special case for LONEOS
     702      dvo_catalog_secfilt_to_primary (catalog, &primary, &secfilt, &Nsecfilt);
     703      break;
     704    default:
     705      primary = NULL;
     706      secfilt = catalog[0].secfilt;
     707      Nsecfilt = catalog[0].Nsecfilt;
     708      break;
     709  }
     710
     711  Nmeas_disk_new = MAX (catalog[0].Nmeas_disk, catalog[0].Nmeasure + catalog[0].Nmeas_off);
     712  Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
     713  Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
     714
     715  /* make sure header is consistent with data */
     716  gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, Naves_disk_new);
     717  gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, Nmeas_disk_new);
     718  gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, Nmiss_disk_new);
     719  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
     720  gfits_modify (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
     721
     722  /* in split mode, we can save only part of the data */
     723
     724  /*** Average Table ***/
    348725  if (catalog[0].average != NULL) {
    349     ftruncate (fileno (catalog[0].f), catalog[0].header.size);
    350 
    351     /* this is probably a NOP, do I have to keep it in? */
    352     gfits_create_matrix (&catalog[0].header, &matrix);
    353     if (!gfits_fwrite_matrix  (catalog[0].f, &matrix)) {
    354       fprintf (stderr, "can't write primary matrix");
    355       goto failure;
    356     }
    357     gfits_free_matrix (&matrix);
    358 
    359     /* write out Average table (convert to FITS table format) */
    360     if (!AverageToFtable (&ftable, catalog[0].average, catalog[0].Naverage, catalog[0].catformat, primary)) {
    361         fprintf (stderr, "trouble converting format\n");
    362         goto failure;
    363     }
    364     if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    365       fprintf (stderr, "can't write table header");
    366       goto failure;
    367     }
    368     if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
    369       fprintf (stderr, "can't write table data");
    370       goto failure;
    371     }
     726
     727    first  = catalog[0].Naves_disk - catalog[0].Naves_off; // first row to write (memory)
     728    start  = catalog[0].Naves_disk;                        // first row to write (disk)
     729    Nrows  = catalog[0].Naverage - first;
     730
     731    assert (Nrows >= 0);
     732    assert (first >= 0);
     733    assert (first < catalog[0].Naverage);
     734    assert (catalog[0].Naves_disk >= catalog[0].Naves_off);
     735
     736    /* convert internal to external format */
     737    if (!AverageToFtable (&ftable, &catalog[0].average[first], Nrows, catalog[0].catformat, primary)) {
     738      fprintf (stderr, "trouble converting format\n");
     739      goto failure;
     740    }
     741
     742    if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naves_disk, Naves_disk_new)) {
     743      fprintf (stderr, "failure writing Average table\n");
     744      goto failure;
     745    }
     746    gfits_free_header (&header);
    372747    gfits_free_table (&ftable);
    373     gfits_free_header (&header);
     748  } else {
     749    // even if we do not save the average table, we need to keep the header in sync
     750    /* rewind file pointers and truncate (file is still open) */
     751    fseek (catalog[0].f, 0, SEEK_SET);
     752
     753    /* write table PHU header - always write this out */
     754    /* XXX EAM : check if disk file size has changed */
     755    if (!gfits_fwrite_header  (catalog[0].f, &catalog[0].header)) {
     756      fprintf (stderr, "can't write primary header");
     757      goto failure;
     758    }
    374759  }
    375760
     
    377762  if (catalog[0].measure != NULL) {
    378763
    379     /* catalog file data is stored in separate structure */
    380     catfile = catalog[0].measure_catalog;
    381 
    382     /* XXX EAM : warn about this condition; add code to handle? */
    383     if (catalog[0].Nmeas_off != 0) {
    384       fprintf (stderr, "WARNING: LOAD_MEAS_META mixed with save??\n");
    385       fprintf (stderr, "WARNING: this should not be allowed to happen!\n");
    386     }
    387 
    388     /* rewind file pointers and truncate (file is still open) */
    389     fseek (catfile[0].f, 0, SEEK_SET);
    390     ftruncate (fileno (catfile[0].f), 0);
    391 
    392     /* write table PHU header */
    393     if (!gfits_fwrite_header  (catfile[0].f, &catfile[0].header)) {
    394       fprintf (stderr, "can't write primary header");
    395       goto failure;
    396     }
    397 
    398     /* this is probably a NOP, do I have to keep it in? */
    399     gfits_create_matrix (&catfile[0].header, &matrix);
    400     if (!gfits_fwrite_matrix  (catfile[0].f, &matrix)) {
    401       fprintf (stderr, "can't write primary matrix");
    402       goto failure;
    403     }
    404     gfits_free_matrix (&matrix);
    405 
    406     /* write out Measure table (convert to FITS table format) */
    407     MeasureToFtable (&ftable, catalog[0].measure, catalog[0].Nmeasure, catalog[0].catformat);
    408     if (!gfits_fwrite_Theader (catfile[0].f, &header)) {
    409       fprintf (stderr, "can't write table header");
    410       goto failure;
    411     }
    412     if (!gfits_fwrite_table (catfile[0].f, &ftable)) {
    413       fprintf (stderr, "can't write table data");
    414       goto failure;
    415     }
     764    first  = catalog[0].Nmeas_disk - catalog[0].Nmeas_off;  // first row in memory to write
     765    start  = catalog[0].Nmeas_off; // first disk row to write
     766    Nrows  = catalog[0].Nmeasure - first;
     767
     768    assert (Nrows >= 0);
     769    assert (first >= 0);
     770    assert (first < catalog[0].Nmeasure);
     771    assert (catalog[0].Nmeas_disk >= catalog[0].Nmeas_off);
     772
     773    // convert to external table format
     774    if (!MeasureToFtable (&ftable, &catalog[0].measure[first], Nrows, catalog[0].catformat)) {
     775      fprintf (stderr, "trouble converting format\n");
     776      goto failure;
     777    }
     778
     779    // write out Measure table
     780    if (!dvo_catalog_save_subcat (catalog[0].measure_catalog, &ftable, start, Nrows, catalog[0].Nmeas_disk, Nmeas_disk_new)) {
     781      fprintf (stderr, "trouble writing Measure table\n");
     782      goto failure;
     783    }
     784    gfits_free_header (&header);
    416785    gfits_free_table (&ftable);
    417     gfits_free_header (&header);
    418   }
     786  }
     787
     788  /* missing table CANNOT be written unsorted, thus it is always written
     789     out in full */
    419790
    420791  /*** Missing Table ***/
     792
    421793  if (catalog[0].missing != NULL) {
    422794
    423     /* catalog data is stored in separate catalog */
    424     catfile = catalog[0].missing_catalog;
    425 
    426     /* rewind file pointers and truncate (file is still open) */
    427     fseek (catfile[0].f, 0, SEEK_SET);
    428     ftruncate (fileno (catfile[0].f), 0);
    429 
    430     /* write table PHU header */
    431     if (!gfits_fwrite_header  (catfile[0].f, &catfile[0].header)) {
    432       fprintf (stderr, "can't write primary header");
    433       goto failure;
    434     }
    435 
    436     /* this is probably a NOP, do I have to keep it in? */
    437     gfits_create_matrix (&catfile[0].header, &matrix);
    438     if (!gfits_fwrite_matrix  (catfile[0].f, &matrix)) {
    439       fprintf (stderr, "can't write primary matrix");
    440       goto failure;
    441     }
    442     gfits_free_matrix (&matrix);
    443 
    444     /* write out Missing table (convert to FITS table format) */
    445     gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing);
    446     if (!gfits_fwrite_Theader (catfile[0].f, &header)) {
    447       fprintf (stderr, "can't write table header");
    448       goto failure;
    449     }
    450     if (!gfits_fwrite_table (catfile[0].f, &ftable)) {
    451       fprintf (stderr, "can't write table data");
    452       goto failure;
    453     }
     795    if (catalog[0].Nmiss_off != 0) {
     796      fprintf (stderr, "inconsistency: Missing table cannot be written in segments\n");
     797      goto failure;
     798    }
     799
     800    // convert to external table format
     801    if (!gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing)) {
     802      fprintf (stderr, "trouble converting format\n");
     803      goto failure;
     804    }
     805
     806    // write out Missing table (must write out entire table)
     807    if (!dvo_catalog_save_subcat (catalog[0].missing_catalog, &ftable, 0, catalog[0].Nmissing, catalog[0].Nmissing, catalog[0].Nmissing)) {
     808      fprintf (stderr, "trouble writing Missing Table\n");
     809      goto failure;
     810    }
     811    gfits_free_header (&header);
    454812    gfits_free_table (&ftable);
    455     gfits_free_header (&header);
    456813  }
    457814
     
    459816  if (catalog[0].secfilt != NULL) {
    460817
    461     /* catalog file data is stored in a separate catalog structure */
    462     catfile = catalog[0].secfilt_catalog;
    463 
    464     /* rewind file pointers and truncate (file is still open) */
    465     fseek (catfile[0].f, 0, SEEK_SET);
    466     ftruncate (fileno (catfile[0].f), 0);
    467 
    468     /* write table PHU header */
    469     if (!gfits_fwrite_header  (catfile[0].f, &catfile[0].header)) {
    470       fprintf (stderr, "can't write primary header");
    471       goto failure;
    472     }
    473 
    474     /* this is probably a NOP, do I have to keep it in? */
    475     gfits_create_matrix (&catfile[0].header, &matrix);
    476     if (!gfits_fwrite_matrix  (catfile[0].f, &matrix)) {
    477       fprintf (stderr, "can't write primary matrix");
    478       goto failure;
    479     }
    480     gfits_free_matrix (&matrix);
    481 
    482     /* write out SecFilt table (convert to FITS table format) */
    483     Nitems = catalog[0].Naverage * catalog[0].Nsecfilt;
    484     SecFiltToFtable (&ftable, secfilt, Nitems, catalog[0].catformat);
    485     if (!gfits_fwrite_Theader (catfile[0].f, &header)) {
    486       fprintf (stderr, "can't write table header");
    487       goto failure;
    488     }
    489     if (!gfits_fwrite_table (catfile[0].f, &ftable)) {
    490       fprintf (stderr, "can't write table data");
    491       goto failure;
    492     }
     818    first  = catalog[0].Nsecf_disk - catalog[0].Nsecf_off;  // first row in memory to write
     819    start  = catalog[0].Nsecf_off; // first disk row to write
     820    Nitems = catalog[0].Nsecf_mem;
     821    Nrows  = Nitems - first;
     822
     823    assert (Nrows >= 0);
     824    assert (first >= 0);
     825    assert (first < Nitems);
     826    assert (catalog[0].Nmeas_disk >= catalog[0].Nmeas_off);
     827
     828    // convert to external table format
     829    SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat);
     830
     831    // write out SecFilt table
     832    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
     833      fprintf (stderr, "failure writing SecFilt table\n");
     834      goto failure;
     835    }
     836    gfits_free_header (&header);
    493837    gfits_free_table (&ftable);
    494     gfits_free_header (&header);
    495838  }
    496839
     
    512855}
    513856
    514 /* update_catalog_split only writes new lines to file. 
    515  * if file is empty, call save_catalog_split instead.
    516  * XXX EAM : save_catalog SHOULD do this
    517  */
    518 
    519 int dvo_catalog_update_split (Catalog *catalog, char VERBOSE) {
    520 
    521   int i, Nx, Ny, Nlines;
    522   int Nitems, Nskip, Nout, Ndisk, Nstart;
    523   Matrix matrix;
    524   Header header;
    525   FTable ftable;
    526   VTable vtable;
    527   Catalog *catfile;
    528   SecFilt *primary, *secfilt;
    529   int j, Nsecfilt, Nallfilt, Ntotal;
    530 
    531   ftable.header = &header;
    532   vtable.header = &header;
    533 
    534   if (catalog[0].Naverage == 0) {
    535     if (VERBOSE) fprintf (stderr, "no stars in catalog, skipping\n");
    536     return (TRUE);
    537   }
    538 
    539   /** for the appropriate types, pull out the first secfilt and pass to AverageToFtable as primary **/
    540   if ((catalog[0].catformat == DVO_FORMAT_ELIXIR) || // special case for ELIXIR
    541       (catalog[0].catformat == DVO_FORMAT_LONEOS)) { // special case for LONEOS
    542     if (catalog[0].secfilt == NULL) {
    543       fprintf (stderr, "missing secfilt, cannot build output averages (dvo_catalog_split.c:544)\n");
    544       exit (1);
    545     }
    546     secfilt = catalog[0].secfilt;
    547 
    548     Nallfilt = catalog[0].Nsecfilt;
    549     Nsecfilt = catalog[0].Nsecfilt - 1;
    550     Ntotal = Nsecfilt * catalog[0].Naverage;
    551     ALLOCATE (primary, SecFilt, catalog[0].Naverage);
    552     ALLOCATE (secfilt, SecFilt, Ntotal);
    553 
    554     for (i = 0; i < catalog[0].Naverage; i++) {
    555       primary[i] = secfilt[i*Nallfilt + 0];
    556       for (j = 0; j < Nsecfilt; j++) {
    557         secfilt[i*Nsecfilt + j] = catalog[0].secfilt[i*Nallfilt + j + 1];
    558       }
    559     }           
    560   } else {
    561     primary = NULL;
    562     secfilt = catalog[0].secfilt;
    563     Nsecfilt = catalog[0].Nsecfilt;
    564   }
    565 
    566   /* make sure header is consistent with data */
    567   gfits_modify (&catalog[0].header, "NSTARS",   "%d", 1, catalog[0].Naverage);
    568   gfits_modify (&catalog[0].header, "NMEAS",    "%d", 1, catalog[0].Nmeasure + catalog[0].Nmeas_off);
    569   gfits_modify (&catalog[0].header, "NMISS",    "%d", 1, catalog[0].Nmissing);
    570   gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
    571   gfits_modify (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    572 
    573   /* rewind file pointers and truncate (file is still open) */
    574   fseek (catalog[0].f, 0, SEEK_SET);
    575 
    576   /* write table PHU header - always write this out */
    577   /* XXX EAM : check if disk file size has changed */
    578   if (!gfits_fwrite_header  (catalog[0].f, &catalog[0].header)) {
    579     fprintf (stderr, "can't write primary header");
    580     goto failure;
    581   }
    582 
    583   /*** Average Table ***/
    584   if (catalog[0].average != NULL) {
    585 
    586     /* skip past matrix (already at end of header) */
    587     Nskip = gfits_data_size (&catalog[0].header);
    588     fseek (catalog[0].f, Nskip, SEEK_CUR);
    589 
    590     /* how many lines to write out? */
    591     Nout = catalog[0].Naverage - catalog[0].Nave_disk;
    592 
    593     /* write out Average table (convert to FITS table format) */
    594     AverageToFtable (&ftable, catalog[0].average, catalog[0].Naverage, catalog[0].catformat, primary);
    595     /* convert only output rows to vtable */
    596     gfits_table_to_vtable (&ftable, &vtable, catalog[0].Nave_disk, Nout);
    597 
    598     if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    599       fprintf (stderr, "can't write table header");
    600       goto failure;
    601     }
    602     if (!gfits_fwrite_vtable (catalog[0].f, &vtable)) {
    603       fprintf (stderr, "can't write table data");
    604       goto failure;
    605     }
    606     gfits_free_vtable (&vtable);
    607     gfits_free_table (&ftable);
    608     gfits_free_header (&header);
    609   }
    610 
    611   /*** Measure Table ***/
    612   if (catalog[0].measure != NULL) {
    613 
    614     catfile = catalog[0].measure_catalog;
    615 
    616     /* skip past PHU header and matrix */
    617     Nskip = catfile[0].header.size + gfits_data_size (&catfile[0].header);
    618     fseek (catfile[0].f, Nskip, SEEK_SET);
    619 
    620     Ndisk  = catalog[0].Nmeas_disk;
    621     Nstart = catalog[0].Nmeas_disk - catalog[0].Nmeas_off; /* where is first new line? */
    622     Nout   = catalog[0].Nmeasure - Nstart;                   /* how many lines to write out? */
    623     Nlines = catalog[0].Nmeasure + catalog[0].Nmeas_off;   /* how many lines total in file */
    624 
    625     /* convert to output format FITS table (only rows for output : 0 - Nout) */
    626     MeasureToFtable (&ftable, &catalog[0].measure[Nstart], Nout, catalog[0].catformat);
    627 
    628     gfits_scan (&header, "NAXIS1", "%d", 1, &Nx);
    629     gfits_scan (&header, "NAXIS2", "%d", 1, &Ny);
    630 
    631     /* convert all output rows to vtable */
    632     ALLOCATE (vtable.row, int, MAX (1, Nout));
    633     ALLOCATE (vtable.buffer, char *, MAX (1, Nout));
    634     for (i = 0; i < Nout; i++) {
    635       ALLOCATE (vtable.buffer[i], char, MAX (1, Nx));
    636       memcpy (vtable.buffer[i], &ftable.buffer[i*Nx], Nx);
    637       vtable.row[i] = i + Ndisk;
    638     }
    639 
    640     /* modify vtable to represent full disk table */
    641     gfits_modify (&header, "NAXIS2", "%d", 1, Nlines);
    642     header.Naxis[1] = Nlines;
    643 
    644     vtable.size = gfits_data_size (&header);
    645     vtable.Nrow = Nout;
    646     vtable.pad = vtable.size - Nx*Ny;
    647 
    648     if (!gfits_fwrite_Theader (catfile[0].f, &header)) {
    649       fprintf (stderr, "can't write table header");
    650       goto failure;
    651     }
    652     if (!gfits_fwrite_vtable (catfile[0].f, &vtable)) {
    653       fprintf (stderr, "can't write table data");
    654       goto failure;
    655     }
    656     gfits_free_vtable (&vtable);
    657     gfits_free_table (&ftable);
    658     gfits_free_header (&header);
    659   }
    660 
    661   /*** Missing Table ***/
    662   /* missing table CANNOT be written unsorted, thus it is always written
    663      out in full */
    664 
    665   if (catalog[0].missing != NULL) {
    666 
    667     catfile = catalog[0].missing_catalog;
    668 
    669     /* rewind file pointers and truncate (file is still open) */
    670     fseek (catfile[0].f, 0, SEEK_SET);
    671     ftruncate (fileno (catfile[0].f), 0);
    672 
    673     /* write table PHU header */
    674     if (!gfits_fwrite_header  (catfile[0].f, &catfile[0].header)) {
    675       fprintf (stderr, "can't write primary header");
    676       goto failure;
    677     }
    678 
    679     /* this is probably a NOP, do I have to keep it in? */
    680     gfits_create_matrix (&catfile[0].header, &matrix);
    681     if (!gfits_fwrite_matrix  (catfile[0].f, &matrix)) {
    682       fprintf (stderr, "can't write primary matrix");
    683       goto failure;
    684     }
    685     gfits_free_matrix (&matrix);
    686 
    687     /* write out Missing table (convert to FITS table format) */
    688     gfits_table_set_Missing (&ftable, catalog[0].missing, catalog[0].Nmissing);
    689     if (!gfits_fwrite_Theader (catfile[0].f, &header)) {
    690       fprintf (stderr, "can't write table header");
    691       goto failure;
    692     }
    693     if (!gfits_fwrite_table (catfile[0].f, &ftable)) {
    694       fprintf (stderr, "can't write table data");
    695       goto failure;
    696     }
    697     gfits_free_table (&ftable);
    698     gfits_free_header (&header);
    699   }
    700 
    701   /*** Secfilt Table ***/
    702   if (catalog[0].secfilt != NULL) {
    703 
    704     catfile = catalog[0].secfilt_catalog;
    705 
    706     /* skip past PHU header and matrix */
    707     Nskip = catfile[0].header.size + gfits_data_size (&catfile[0].header);
    708     fseek (catfile[0].f, Nskip, SEEK_SET);
    709 
    710     /* how many lines to write out? */
    711     Nout  = catalog[0].Nsecfilt * (catalog[0].Naverage - catalog[0].Nave_disk);
    712     Ndisk = catalog[0].Nsecfilt * catalog[0].Nave_disk;
    713 
    714     /* convert to output format FITS table */
    715     Nitems = catalog[0].Naverage * catalog[0].Nsecfilt;
    716     SecFiltToFtable (&ftable, secfilt, Nitems, catalog[0].catformat);
    717     /* convert only output rows to vtable */
    718     gfits_table_to_vtable (&ftable, &vtable, Ndisk, Nout);
    719 
    720     if (!gfits_fwrite_Theader (catfile[0].f, &header)) {
    721       fprintf (stderr, "can't write table header");
    722       goto failure;
    723     }
    724     if (!gfits_fwrite_vtable (catfile[0].f, &vtable)) {
    725       fprintf (stderr, "can't write table data");
    726       goto failure;
    727     }
    728     gfits_free_vtable (&vtable);
    729     gfits_free_table (&ftable);
    730     gfits_free_header (&header);
    731   }
    732 
    733   /* free temp storage */
    734   if (primary != NULL) {
    735     free (primary);
    736     free (secfilt);
    737   }
    738 
    739   return (TRUE);
    740 
    741 failure:
    742   /* free temp storage */
    743   if (primary != NULL) {
    744     free (primary);
    745     free (secfilt);
    746   }
    747   return (FALSE);
    748 }
    749 
    750857/* in split mode, extra files are linked to catalog->measure_catalog, etc.  Each
    751858   has a valid filename, f, header.  The primary catalog data pointers are set
     
    758865/* XXX EAM : update is not efficient.  MeasureToFtable should only
    759866   convert the new rows (Nmeas_disk to Nmeasure). the resulting
    760    table represents the end rows of the vtable.  we need to define
     867   table represents the end rows of the ftable.  we need to define
    761868   the vtable based on the ftable, but with Ny = Nmeasure */ 
    762869 
     870
     871
     872    // * convert to an ftable
     873    // * optionally write the PHU header/matrix
     874    // * advance to the start of the output data block:
     875    // ** Nx * catalog[0].Nmeas_off
     876    // * write out the ftable data block
     877    // * if Nmeas_off + Nmeasure >= Nmeas_disk, update padding
     878    // ** start = Nmeas_off
     879    // ** Nrows = Nmeasure
     880
  • trunk/Ohana/src/libfits/header/F_read_H.c

    r15487 r15743  
    3434    Nbytes = fread (&header[0].buffer[i*FT_RECORD_SIZE],
    3535                    sizeof(char), FT_RECORD_SIZE, f);
     36    if (Nbytes != FT_RECORD_SIZE) {
     37      perror ("fits read error");
     38    }
     39   
    3640    header[0].size += Nbytes;
    3741    if (Nbytes != FT_RECORD_SIZE) {
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r15656 r15743  
    22
    33# include <assert.h>
     4# include <errno.h>
    45
    56# ifndef GFITSIO
     
    172173int     gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname));
    173174int     gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable));
     175int     gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, int start, int Nrows));
    174176int     gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, int Nrow, int *row));
    175177int     gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, int start, int Nrows));
     
    178180int     gfits_fwrite_table             PROTO((FILE *f, FTable *table));
    179181int     gfits_fwrite_vtable            PROTO((FILE *f, VTable *table));
     182int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, int start, int Nrows, int Ndisk, int Ntotal));
    180183int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
    181184int     gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval));
  • trunk/Ohana/src/libfits/matrix/F_load_M.c

    r15487 r15743  
    3030
    3131  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
     32  if (nbytes != Nbytes) {
     33    perror ("fits matrix read error");
     34  }
    3235
    3336# ifdef BYTE_SWAP 
  • trunk/Ohana/src/libfits/matrix/F_read_portion.c

    r7054 r15743  
    4747  fseek (f, header.size + Nskip, SEEK_SET);
    4848  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
     49  if (nbytes != Nbytes) {
     50    perror ("fits matrix read error");
     51  }
     52
    4953  fclose (f);
    5054
  • trunk/Ohana/src/libfits/matrix/F_read_segment.c

    r13039 r15743  
    9090  fseek (f, Nskip, SEEK_CUR);
    9191  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
     92  if (nbytes != Nbytes) {
     93    perror ("fits matrix read error");
     94  }
     95
    9296  matrix[0].size = Nbytes;
    9397
  • trunk/Ohana/src/libfits/table/F_read_T.c

    r15487 r15743  
    5959  Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
    6060  if (Nread != Nbytes) {
     61    perror ("fits read error");
    6162    gfits_free_table  (table);
    6263    return (FALSE);
    6364  }
    6465  table[0].size = Nbytes;
     66  return (TRUE);
     67}       
     68
     69/*********************** fits read ftable data ***********************************/
     70int gfits_fread_ftable_range (FILE *f, FTable *table, int start, int Nrows) {
     71
     72  int Nbytes, Nread, Nskip, Nx, Ny;
     73
     74  /* find disk table size */
     75  Nx = table[0].header[0].Naxis[0];
     76  Ny = table[0].header[0].Naxis[1];
     77
     78  // it is an error to ask for data starting out-of-bounds
     79  if (start < 0) return (FALSE);
     80  if (start >= Ny) return (FALSE);
     81 
     82  // if we request more data than is available, we will stop at the table end.
     83  Nrows = MIN (Nrows, Ny - start);
     84
     85  Nskip = start * Nx;
     86  Nbytes = Nrows * Nx;
     87  ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
     88
     89  fseek (f, Nskip, SEEK_CUR);
     90
     91  Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
     92  if (Nread != Nbytes) {
     93    if (ferror (f)) {
     94      perror ("fits read error");
     95    } else {
     96      fprintf (stderr, "unexpected eof\n");
     97    }     
     98    free (table[0].buffer);
     99    return (FALSE);
     100  }
     101
     102  /* modify structure and header to match actual read rows Ny */
     103  table[0].header[0].Naxis[1] = Nrows;
     104  gfits_modify (table[0].header, "NAXIS2",  "%d", 1, Nrows);
     105  table[0].size = gfits_data_size (table[0].header);
     106
    65107  return (TRUE);
    66108}       
     
    88130  Nread = fread (buffer, sizeof (char), Nbytes, f);
    89131  if (Nread != Nbytes) {
     132    perror ("fits read error");
    90133    free (buffer);
    91134    return (FALSE);
     
    146189      fseek (f, offset, SEEK_SET);
    147190      Nread = fread (table[0].buffer[i], sizeof (char), Nx, f);
    148       if (Nread != Nx) { return (FALSE); }
     191      if (Nread != Nx) {
     192        perror ("fits read error");
     193        return (FALSE);
     194      }
    149195    }
    150196
  • trunk/Ohana/src/libfits/table/F_read_TH.c

    r15487 r15743  
    4646    Nbytes = fread (&Theader[0].buffer[i*FT_RECORD_SIZE],
    4747                    sizeof(char), FT_RECORD_SIZE, f);
     48    if (Nbytes != FT_RECORD_SIZE) {
     49      perror ("fits matrix read error");
     50    }
     51
    4852    Theader[0].size += Nbytes;
    4953    if (Nbytes != FT_RECORD_SIZE)
  • trunk/Ohana/src/libfits/table/F_write_T.c

    r7054 r15743  
    6969/* this will add data beyond the end of the table in the file if needed,
    7070   filling intervening gap with 0 */
     71
     72/*********************** fits read ftable data ***********************************/
     73int gfits_fwrite_ftable_range (FILE *f, FTable *ftable, int start, int Nrows, int Ndisk, int Ntotal) {
     74
     75  int Nbytes, Nwrite, Nskip, Nx, Npad;
     76  char *pad;
     77
     78  if (start < 0) return (FALSE);
     79 
     80  /* modify vtable to represent full disk table */
     81  gfits_modify (ftable[0].header, "NAXIS2", "%d", 1, Ntotal);
     82  ftable[0].header[0].Naxis[1] = Ntotal;
     83
     84  Nx = ftable[0].header[0].Naxis[0]; // final output table size on disk
     85  ftable[0].size = gfits_data_size (ftable[0].header);
     86
     87  Nskip = start * Nx;
     88  Nbytes = Nrows * Nx;
     89
     90  // cursor must be at start of the table header
     91  if (!gfits_fwrite_Theader (f, ftable[0].header)) {
     92    fprintf (stderr, "can't write table header");
     93    return (FALSE);
     94  }
     95
     96  // cursor must be at start of the table (after table header)
     97  fseek (f, Nskip, SEEK_CUR);
     98  Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
     99  if (Nwrite != Nbytes) {
     100    return (FALSE);
     101  }
     102
     103  if (Ntotal >= Ndisk) {
     104    Npad = ftable[0].size - Nx*Ntotal;
     105    ALLOCATE (pad, char, Npad);
     106    bzero (pad, Npad);
     107    Nbytes = fwrite (pad, sizeof (char), Npad, f);
     108    free (pad);
     109
     110    if (Nbytes != Npad) return (FALSE);
     111  }
     112
     113  return (TRUE);
     114}       
     115
  • trunk/Ohana/src/markrock/src/markrock.c

    r8386 r15743  
    4545    exit (2);
    4646  }
    47   if (catalog.Nave_disk) {
     47  if (catalog.Naves_disk) {
    4848    dvo_catalog_unlock (&catalog);
    4949    dvo_catalog_free (&catalog);
  • trunk/Ohana/src/markstar/src/markstar.c

    r8386 r15743  
    4848    exit (2);
    4949  }
    50   if (!catalog.Nave_disk) {
     50  if (!catalog.Naves_disk) {
    5151    dvo_catalog_unlock (&catalog);
    5252    dvo_catalog_free (&catalog);
  • trunk/Ohana/src/mosastro/src/getptolemy.c

    r12332 r15743  
    3636    dvo_catalog_unlock (&catalog);
    3737
    38     // Nave_disk == 0 implies an empty catalog file
     38    // Naves_disk == 0 implies an empty catalog file
    3939    // for only_match, skip empty catalogs
    40     if (!catalog.Nave_disk) {
     40    if (!catalog.Naves_disk) {
    4141      dvo_catalog_free (&catalog);
    4242      continue;
  • trunk/Ohana/src/photdbc/src/join_stars.c

    r12332 r15743  
    172172 
    173173  catalog[0].Naverage = Naves;
     174  catalog[0].Nsecf_mem = Naves*catalog[0].Nsecfilt;
    174175}
    175176
     
    181182   generates a new SecFilt table with empty values
    182183   does NOT update magnitudes
     184   output measure table is the same size as the input measure table
     185   (measures are just moved around).  thus, catalog[0].Nmeasure does not change.
    183186*/   
    184187   
  • trunk/Ohana/src/photdbc/src/make_subcatalog.c

    r12332 r15743  
    1010
    1111  Nsecfilt = GetPhotcodeNsecfilt ();
     12  assert (catalog[0].Nsecfilt == Nsecfilt);
    1213
    1314  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
     
    9697  subcatalog[0].Naverage = Naverage;
    9798  subcatalog[0].Nmeasure = Nmeasure;
    98   subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
     99  subcatalog[0].Nsecfilt = Nsecfilt;
     100  subcatalog[0].Nsecf_mem = Naverage * Nsecfilt;
    99101
    100102  // XXX for now, don't copy the missing entries (these should be re-computed)
  • trunk/Ohana/src/photdbc/src/photdbc.c

    r8701 r15743  
    3434    }
    3535    // skip empty input catalogs
    36     if (!incatalog.Nave_disk) {
     36    if (!incatalog.Naves_disk) {
    3737      dvo_catalog_unlock (&incatalog);
    3838      dvo_catalog_free (&incatalog);
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r15130 r15743  
    66  int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
    77  float mag;
     8
     9  // XXX PhotNsec as a global is a bad idea; either get it from catalog
     10  // or get it from:
     11  // Nsecfilt = GetPhotcodeNsecfilt ();
     12  // assert (catalog[0].Nsecfilt == Nsecfilt);
    813
    914  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
     
    104109  subcatalog[0].Nmeasure = Nmeasure;
    105110  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
     111  subcatalog[0].Nsecf_mem = Naverage * PhotNsec;
     112  assert (PhotNsec == catalog[0].Nsecfilt);
    106113
    107114  if (VERBOSE) {
  • trunk/Ohana/src/relastro/src/load_catalogs.c

    r15130 r15743  
    1313  for (i = 0; i < skylist[0].Nregions; i++) {
    1414
     15    // we only allow output if we do not use a subset.  in this case,
     16    // the output parameters are correctly set for catalog[i] via pcatalog
    1517    pcatalog = subselect ? &tcatalog : &catalog[i];
    1618
     
    2628      exit (1);
    2729    }
    28     if (VERBOSE && !pcatalog[0].Nave_disk) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename);
     30    if (VERBOSE && !pcatalog[0].Naves_disk) fprintf (stderr, "no data in %s, skipping\n", pcatalog[0].filename);
    2931
    3032    // select only the brighter stars
  • trunk/Ohana/src/relastro/src/reload_catalogs.c

    r12332 r15743  
    2929      exit (1);
    3030    }
    31     if (VERBOSE && (catalog.Nave_disk == 0)) {
     31    if (VERBOSE && (catalog.Naves_disk == 0)) {
    3232        fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    3333        dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/relphot/src/bcatalog.c

    r15634 r15743  
    66  int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
    77  float mag;
     8
     9  // XXX PhotNsec as a global is a bad idea; either get it from catalog
     10  // or get it from:
     11  // Nsecfilt = GetPhotcodeNsecfilt ();
     12  // assert (catalog[0].Nsecfilt == Nsecfilt);
    813
    914  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
     
    105110  subcatalog[0].Nmeasure = Nmeasure;
    106111  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
     112  subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     113  assert (PhotNsec == catalog[0].Nsecfilt);
    107114
    108115  if (VERBOSE) {
  • trunk/Ohana/src/relphot/src/load_catalogs.c

    r9633 r15743  
    2424      exit (1);
    2525    }
    26     if (VERBOSE && !tcatalog.Nave_disk) fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename);
     26    if (VERBOSE && !tcatalog.Naves_disk) fprintf (stderr, "no data in %s, skipping\n", tcatalog.filename);
    2727
    2828    // select only the brighter stars
  • trunk/Ohana/src/relphot/src/reload_catalogs.c

    r9633 r15743  
    3030      exit (1);
    3131    }
    32     if (VERBOSE && (catalog.Nave_disk == 0)) {
     32    if (VERBOSE && (catalog.Naves_disk == 0)) {
    3333        fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
    3434        dvo_catalog_unlock (&catalog);
  • trunk/Ohana/src/uniphot/src/update.c

    r12332 r15743  
    5252      exit (2);
    5353    }
    54     if (!catalog.Nave_disk) {
     54    if (!catalog.Naves_disk) {
    5555      dvo_catalog_unlock (&catalog);
    5656      dvo_catalog_free (&catalog);
Note: See TracChangeset for help on using the changeset viewer.