IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15725


Ignore:
Timestamp:
Nov 30, 2007, 12:20:09 PM (18 years ago)
Author:
eugene
Message:

updating dvo_catalog interface to allow segmented read/writes

Location:
branches/eam_branch_20071130/Ohana/src/libdvo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20071130/Ohana/src/libdvo/include/dvo.h

    r15724 r15725  
    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};
    2426
    2527typedef enum {
  • branches/eam_branch_20071130/Ohana/src/libdvo/src/dvo_catalog.c

    r15724 r15725  
    110110
    111111/* 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!)
     112   DVO_CAT_OPEN_FAIL - failure (including lock failure)
     113   DVO_CAT_OPEN_OK - success
     114   DVO_CAT_OPEN_EMPTY - empty file (file may be open or closed!)
    115115*/
    116116int dvo_catalog_lock (Catalog *catalog, int lockmode) {
     
    125125  catalog[0].f = fsetlockfile (catalog[0].filename, 3600.0, catalog[0].lockmode, &dbstate);
    126126
    127   if (dbstate == LCK_MISSING) return (2);
    128   if (dbstate == LCK_EMPTY)   return (2);
    129   if (catalog[0].f == NULL)   return (0);
     127  if (dbstate == LCK_MISSING) return (DVO_CAT_OPEN_EMPTY);
     128  if (dbstate == LCK_EMPTY)   return (DVO_CAT_OPEN_EMPTY);
     129  if (catalog[0].f == NULL)   return (DVO_CAT_OPEN_FAIL);
    130130
    131131  fseek (catalog[0].f, 0, SEEK_SET);
    132   return (1);
     132  return (DVO_CAT_OPEN_OK);
    133133}
    134134
     
    192192 
    193193  switch (dvo_catalog_lock (catalog, catalog[0].lockmode)) {
    194   case 0:
     194  case DVO_CAT_OPEN_FAIL:
    195195    if (VERBOSE) fprintf (stderr, "can't lock file %s\n", catalog[0].filename);
    196196    return (FALSE);
    197   case 1:
     197  case DVO_CAT_OPEN_OK:
    198198    if (!dvo_catalog_load (catalog, VERBOSE)) {
    199199      if (VERBOSE) fprintf (stderr, "failure loading catalog\n");
     
    206206    if (VERBOSE) fprintf (stderr, "loaded existing file %s\n", catalog[0].filename);
    207207    break;
    208   case 2:
     208  case DVO_CAT_OPEN_EMPTY:
    209209    if ((mode == DVO_OPEN_READ) || (mode == DVO_OPEN_UPDATE)) return (TRUE);
    210210    catalog[0].Nsecfilt = Nsecfilt;
  • branches/eam_branch_20071130/Ohana/src/libdvo/src/dvo_catalog_create.c

    r14590 r15725  
    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);
  • branches/eam_branch_20071130/Ohana/src/libdvo/src/dvo_catalog_split.c

    r15724 r15725  
    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_open_subcat (Catalog *catalog, Catalog **Subcat, char *name, int VERBOSE) {
     9
     10  char *path;
     11  Catalog *subcat;
     12
     13  /* in split mode, we need to init & open the corresponding measure file (even if we do not read
     14   * any data in at this stage) */
     15  ALLOCATE (subcat, Catalog, 1);
     16  dvo_catalog_init (subcat, TRUE);
     17
     18  /* needed to find the split files below */
     19  path = pathname (catalog[0].filename);
     20
     21  /* get split filename from main header (paths relative to cpt file) */
     22  if (!gfits_scan (&catalog[0].header, name,  "%s", 1, string)) return (DVO_CAT_OPEN_FAIL);
     23  ALLOCATE (subcat[0].filename, char, strlen(path) + strlen(string) + 2);
     24  sprintf (subcat[0].filename, "%s/%s", path, string);
     25
     26  /* lock & open catalog file */
     27  status = dvo_catalog_lock (subcat, catalog[0].lockmode);
     28  if (status != DVO_CAT_OPEN_OK) {
     29    if (VERBOSE) {
     30      if (status == DVO_CAT_OPEN_EMPTY) {
     31        fprintf (stderr, "%s (%s) is empty\n", name, subcat[0].filename);
     32      } else {
     33        fprintf (stderr, "failure to lock %s (%s)\n", name, subcat[0].filename);
     34      }
     35    }
     36    return (status);
     37  }
     38
     39  /* read PHU */
     40  if (!gfits_load_header (subcat[0].f, &subcat[0].header)) {
     41    if (VERBOSE) fprintf (stderr, "error reading %s header: %s\n", name, subcat[0].filename);
     42    return (DVO_CAT_OPEN_FAIL);
     43  }
     44  /* matrix should be empty : XXX skip the matrix data? */
     45  if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     46    if (VERBOSE) fprintf (stderr, "can't read primary matrix for %s\n", name);
     47    return (DVO_CAT_OPEN_FAIL);
     48  }
     49  /* read Measure table header */
     50  if (!gfits_fread_header (subcat[0].f, &header)) {
     51    if (VERBOSE) fprintf (stderr, "can't read %s PHU header\n", name);
     52    return (DVO_CAT_OPEN_FAIL);
     53  }
     54
     55  *Subcat = subcat;
     56  return (DVO_CAT_OPEN_OK);
     57}
    258
    359int dvo_catalog_load_split (Catalog *catalog, int VERBOSE) {
     
    965  FTable ftable;
    1066  SecFilt *primary;
    11   Catalog *measure, *missing, *secfilt;
    1267
    1368  /* ftable header storage for below */
     
    2984  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
    3085
    31   /* these values are the number of elements loaded into memory */
    32   catalog[0].Naverage = 0;
    33   catalog[0].Nmeasure = 0;
    34   catalog[0].Nmissing = 0;
    35   catalog[0].Nsecfilt = 0;
    36 
    37   /* by default, an unloaded catalog is ready to accept more entries after the end of the table */
    38   catalog[0].Naves_off = catalog[0].Naves_disk;
    39   catalog[0].Nmeas_off = catalog[0].Nmeas_disk;
    40   catalog[0].Nmiss_off = catalog[0].Nmiss_disk;
    41   catalog[0].Nsecf_off = catalog[0].Nsecf_disk;
    42 
    4386  /**  Nsecfilt is unusual: it does not list the number of data items in the table
    4487       instead, the number of items is Nsecfilt * Naverage.  **/
     
    5194  catalog[0].secfilt = NULL;
    5295
    53   /* XXX EAM : validate table mode */
    54 
    5596  /*** Average Table ***/
    56 
    5797  if (catalog[0].catflags & LOAD_AVES) {
    5898    /* move pointer past header -- must be already read (load_catalog) */
    5999    fseek (catalog[0].f, catalog[0].header.size, SEEK_SET);
    60     /* matrix should be empty */
     100    /* matrix should be empty : XXX should we drop this step and skip the data? */
    61101    if (!gfits_fread_matrix (catalog[0].f, &matrix, &catalog[0].header)) {
    62102      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     
    68108      return (FALSE);
    69109    }
    70     /* read Average table data */
     110    /* read Average table data : format is irrelevant here */
    71111    if (!gfits_fread_ftable_data (catalog[0].f, &ftable)) {
    72112      if (VERBOSE) fprintf (stderr, "can't read table average data");
    73113      return (FALSE);
    74114    }
    75     /* old versions of DVO stored one of the average magnitudes in Average. we save this if needed */
     115    /* convert the saved version of the table to the internal version.  Old versions of DVO stored
     116     * one of the average magnitudes in Average.  We save this in case it is needed below.  NOTE:
     117     * primary is only used if we read in the secfilt table, otherwise it should be freed */
    76118    catalog[0].average = FtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
    77     if (Naverage != catalog[0].Naverage) {
    78       fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naverage);
    79     }
    80     gfits_free_header (&header);
     119    if (Naverage != catalog[0].Naves_disk) {
     120      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, catalog[0].Naves_disk);
     121    }
     122    gfits_free_header (&header);
     123    catalog[0].Naverage = Naverage;
     124    catalog[0].Naves_off = 0;
    81125  } else {
    82126    ALLOCATE (catalog[0].average, Average, 1);
     127    catalog[0].Naverage = 0;
     128    catalog[0].Naves_off = Naverage;
    83129  }
    84130
    85131  /*** Measure Table ***/
    86 
    87   measure = NULL;
    88 
    89   /* (Full Load) */
    90   if (catalog[0].catflags & LOAD_MEAS) {
    91     /* in split mode, we need to init & open the corresponding measure file */
    92     ALLOCATE (measure, Catalog, 1);
    93     dvo_catalog_init (measure, TRUE);
    94     catalog[0].measure_catalog = measure;
    95 
    96     /* get split filename from main header (paths relative to cpt file) */
    97     if (!gfits_scan (&catalog[0].header, "MEASURE",  "%s", 1, string)) return (FALSE);
    98     ALLOCATE (measure[0].filename, char, strlen(path) + strlen(string) + 2);
    99     sprintf (measure[0].filename, "%s/%s", path, string);
    100 
    101     /* lock & open catalog file */
    102     if (dvo_catalog_lock (measure, catalog[0].lockmode) != 1) {
    103       fprintf (stderr, "cannot access measure file %s\n", measure[0].filename);
    104       exit (2);
    105     }
    106 
    107     /* read PHU */
    108     if (!gfits_load_header (measure[0].f, &measure[0].header)) {
    109       if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", measure[0].filename);
    110       return (FALSE);
    111     }
    112     /* matrix should be empty */
    113     if (!gfits_fread_matrix (measure[0].f, &matrix, &measure[0].header)) {
    114       if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    115       return (FALSE);
    116     }
    117     /* read Measure table header */
    118     if (!gfits_fread_header (measure[0].f, &header)) {
    119       if (VERBOSE) fprintf (stderr, "can't read measure PHU header\n");
    120       return (FALSE);
    121     }
     132  status = dvo_catalog_open_subcat (catalog, &catalog[0].measure_catalog, "MEASURE");
     133  if (status == DVO_CAT_OPEN_FAIL) {
     134    return (FALSE);
     135  }
     136  if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nmeas_disk > 0)) {
     137    return (FALSE);
     138  }
     139  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MEAS)) {
     140    // XXX this allows an empty Measure catalog with non-empty Average catalog : is that OK?
    122141    /* read Measure table data */
    123     if (!gfits_fread_ftable_data (measure[0].f, &ftable)) {
     142    if (!gfits_fread_ftable_data (catalog[0].measure_catalog[0].f, &ftable)) {
    124143      if (VERBOSE) fprintf (stderr, "can't read table measure data\n");
    125144      return (FALSE);
    126145    }
    127     /* convert data format to internal */
     146    /* convert data format to internal : returns number of row read in Nmeasure */
    128147    catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
    129     if (Nmeasure != catalog[0].Nmeasure) {
    130       fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeasure);
     148    if (Nmeasure != catalog[0].Nmeas_disk) {
     149      fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, catalog[0].Nmeas_disk);
    131150    }
    132151    gfits_free_header (&header);
    133152    gfits_free_matrix (&matrix);
     153    catalog[0].Nmeasure = catalog[0].Nmeas_disk;
     154    catalog[0].Nmeas_off = 0;
    134155  } else {
     156    // XXX is it necessary to generate a template header here?
     157    gfits_create_header (&catalog[0].measure_catalog[0].header);
    135158    ALLOCATE (catalog[0].measure, Measure, 1);
     159    catalog[0].Nmeasure = 0;
     160    catalog[0].Nmeas_off = catalog[0].Nmeas_disk;
    136161  }
    137162
    138163  /*** Missing Table ***/
    139 
    140   missing = NULL;
    141   if (catalog[0].catflags & LOAD_MISS) {
    142     ALLOCATE (missing, Catalog, 1);
    143     dvo_catalog_init (missing, TRUE);
    144 
    145     /* get split filename from main header (paths relative to cpt file) */
    146     if (!gfits_scan (&catalog[0].header, "MISSING",  "%s", 1, string)) return (FALSE);
    147     ALLOCATE (missing[0].filename, char, strlen(path) + strlen(string) + 2);
    148     sprintf (missing[0].filename, "%s/%s", path, string);
    149 
    150     /* lock & open catalog file */
    151     status = dvo_catalog_lock (missing, catalog[0].lockmode);
    152     if (!status) {
    153       fprintf (stderr, "ERROR: cannot access missing file %s\n", missing[0].filename);
    154       exit (2);
    155     }
    156     if (status == 2) {
    157         /* MISSING table is empty (this is not an error) */
    158         gfits_create_header (&missing[0].header);
    159         goto missing_empty;
    160     }
    161 
    162     /* read PHU */
    163     if (!gfits_load_header (missing[0].f, &missing[0].header)) {
    164       if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", missing[0].filename);
    165       return (FALSE);
    166     }
    167     /* matrix should be empty */
    168     if (!gfits_fread_matrix (missing[0].f, &matrix, &missing[0].header)) {
    169       if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    170       return (FALSE);
    171     }
    172     /* read Missing table header */
    173     if (!gfits_fread_header (missing[0].f, &header)) {
    174       if (VERBOSE) fprintf (stderr, "can't read table missing header\n");
    175       return (FALSE);
    176     }
     164  status = dvo_catalog_open_subcat (catalog, &catalog[0].missing_catalog, "MISSING");
     165  if (status == DVO_CAT_OPEN_FAIL) {
     166    return (FALSE);
     167  }
     168  if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nmeas_disk > 0)) {
     169    return (FALSE);
     170  }
     171  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MISS)) {
    177172    /* read Missing table data */
    178     if (!gfits_fread_ftable_data (missing[0].f, &ftable)) {
     173    if (!gfits_fread_ftable_data (catalog[0].missing_catalog[0].f, &ftable)) {
    179174      if (VERBOSE) fprintf (stderr, "can't read table missing data\n");
    180175      return (FALSE);
    181176    }
    182     /* no conversions currently defined */
    183     catalog[0].missing = gfits_table_get_Missing (&ftable, &catalog[0].Nmissing, NULL);
    184     if (Nmissing != catalog[0].Nmissing) {
    185       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmissing);
     177    /* no conversions currently defined : this just does the byte swap */
     178    catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
     179    if (Nmissing != catalog[0].Nmiss_disk) {
     180      fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, catalog[0].Nmiss_disk);
    186181    }
    187182    gfits_free_header (&header);
    188183    gfits_free_matrix (&matrix);
    189   }
    190 missing_empty:
    191   catalog[0].missing_catalog = missing;
     184    catalog[0].Nmissing = catalog[0].Nmiss_disk;
     185    catalog[0].Nmiss_off = 0;
     186  } else {
     187    // XXX is it necessary to generate a template header here?
     188    gfits_create_header (&catalog[0].missing_catalog[0].header);
     189    ALLOCATE (catalog[0].missing, Missing, 1);
     190    catalog[0].Nmissing = 0;
     191    catalog[0].Nmiss_off = catalog[0].Nmiss_disk;
     192  }
    192193
    193194  /*** Secfilt Table ***/
    194 
    195   secfilt = NULL;
    196   if (catalog[0].catflags & LOAD_SECF) {
    197     ALLOCATE (secfilt, Catalog, 1);
    198     dvo_catalog_init (secfilt, TRUE);
    199 
    200     /* get split filename from main header (paths relative to cpt file) */
    201     if (!gfits_scan (&catalog[0].header, "SECFILT",  "%s", 1, string)) return (FALSE);
    202     ALLOCATE (secfilt[0].filename, char, strlen(path) + strlen(string) + 2);
    203     sprintf (secfilt[0].filename, "%s/%s", path, string);
    204 
    205     /* lock & open catalog file */
    206     if (dvo_catalog_lock (secfilt, catalog[0].lockmode) != 1) {
    207       fprintf (stderr, "cannot access secfilt file %s\n", secfilt[0].filename);
    208       exit (2);
    209     }
    210 
    211     /* read PHU */
    212     if (!gfits_load_header (secfilt[0].f, &secfilt[0].header)) {
    213       if (VERBOSE) fprintf (stderr, "catalog file does not exist: %s\n", secfilt[0].filename);
    214       return (FALSE);
    215     }
    216     /* matrix should be empty */
    217     if (!gfits_fread_matrix (secfilt[0].f, &matrix, &secfilt[0].header)) {
    218       if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    219       return (FALSE);
    220     }
    221     /* read secfilt table header */
    222     if (!gfits_fread_header (secfilt[0].f, &header)) {
    223       if (VERBOSE) fprintf (stderr, "can't read table secfilt header\n");
    224       return (FALSE);
    225     }
     195  status = dvo_catalog_open_subcat (catalog, &catalog[0].secfilt_catalog, "SECFILT");
     196  if (status == DVO_CAT_OPEN_FAIL) {
     197    return (FALSE);
     198  }
     199  if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nsecf_disk > 0)) {
     200    return (FALSE);
     201  }
     202  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_SECF)) {
    226203    /* read secfilt table data */
    227204    if (!gfits_fread_ftable_data (secfilt[0].f, &ftable)) {
     
    229206      return (FALSE);
    230207    }
    231     Nexpect = catalog[0].Nsecfilt * catalog[0].Naverage;
    232208    catalog[0].secfilt = FtableToSecFilt (&ftable, &Nitems, &catalog[0].catformat);
    233     if (Nexpect != Nitems) {
    234       fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nexpect, Nitems);
     209    if (Nitems != catalog[0].Nsecf_disk) {
     210      fprintf (stderr, "Warning: mismatch between Nsecfilt items in PHU and Table headers (%d vs %d)\n", Nitems, catalog[0].Nsecf_disk);
    235211    }
    236212
     
    243219      Ntmpfilt = catalog[0].Nsecfilt;
    244220      Nsecfilt = catalog[0].Nsecfilt + 1;
    245       Ntotal = Nsecfilt * catalog[0].Naverage;
     221      Ntotal = Nsecfilt * catalog[0].Naves_disk;
    246222      ALLOCATE (catalog[0].secfilt, SecFilt, Ntotal);
    247223      for (i = 0; i < catalog[0].Naverage; i++) {
     
    252228      }         
    253229      catalog[0].Nsecfilt = Nsecfilt;
     230      catalog[0].Nsecf_disk = Ntotal;
    254231      free (primary);
    255232    }
    256 
    257 
    258233    gfits_free_header (&header);
    259234    gfits_free_matrix (&matrix);
     235    catalog[0].Nsecf_mem = catalog[0].Nsecf_disk;
     236    catalog[0].Nsecf_off = 0;
    260237  } else {
    261     if (primary != NULL) free (primary);
    262   }
    263 
    264   catalog[0].secfilt_catalog = secfilt;
    265 
     238    if (primary != NULL) {
     239      free (primary);
     240      catalog[0].Nsecfilt ++;
     241      catalog[0].Nsecf_disk =  catalog[0].Nsecfilt * catalog[0].Naves_disk;
     242    }
     243    gfits_create_header (&catalog[0].secfilt_catalog[0].header);
     244    ALLOCATE (catalog[0].secfilt, SecFilt, 1);
     245    catalog[0].Nsecf_mem = 0;
     246    catalog[0].Nsecf_off = catalog[0].Nsecf_disk;
     247  }
     248
     249  return (TRUE);
     250}
     251
     252// XXX I either need to always read both average and secfilt at the same time, or
     253// do something sloppy to carry around the primary secfilt values...
     254
     255int dvo_catalog_load_segment_split_average (Catalog *catalog, int start, int Nrows) {
     256
     257  // XXX check the open status of the FILE *f?
     258
     259    /* move pointer past header -- must be already read (load_catalog) */
     260    fseek (catalog[0].f, catalog[0].header.size, SEEK_SET);
     261    /* matrix should be empty : XXX should we drop this step and skip the data? */
     262    if (!gfits_fread_matrix (catalog[0].f, &matrix, &catalog[0].header)) {
     263      if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     264      return (FALSE);
     265    }
     266    /* read Average table header */
     267    if (!gfits_fread_header (catalog[0].f, &header)) {
     268      if (VERBOSE) fprintf (stderr, "can't read table average header");
     269      return (FALSE);
     270    }
     271    /* read Average table data : format is irrelevant here */
     272    if (!gfits_fread_vtable_range (catalog[0].f, &vtable, start, Nrows)) {
     273      if (VERBOSE) fprintf (stderr, "can't read table average data");
     274      return (FALSE);
     275    }
     276
     277    /* convert the saved version of the table to the internal version.  Old versions of DVO stored
     278     * one of the average magnitudes in Average.  We save this in case it is needed below.  NOTE:
     279     * primary is only used if we read in the secfilt table, otherwise it should be freed */
     280
     281    // XXX Vtable version is needed (merge Ftable and Vtable versions?)
     282    catalog[0].average = VtableToAverage (&ftable, &Naverage, &catalog[0].catformat, &primary);
     283
     284    // XXX validate the sizes?  start + Nrows < Naves_disk (no other constraints)
     285    if (Naverage != Nrows) {
     286      fprintf (stderr, "Warning: mismatch between Naverage in PHU and Table headers (%d vs %d)\n", Naverage, Nrows);
     287    }
     288    gfits_free_header (&header);
     289    catalog[0].Naverage = Naverage;
     290    catalog[0].Naves_off = start;
     291
     292    return (TRUE);
     293}
     294
     295int dvo_catalog_load_segment_split_measure (Catalog *catalog, int start, int Nrows) {
     296
     297  // XXX check the open status of the FILE *f?
     298
     299  Catalog *subcat = catalog[0].measure_catalog;
     300
     301  /* move pointer past header -- must be already read (load_catalog) */
     302  fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     303  /* matrix should be empty : XXX should we drop this step and skip the data? */
     304  if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     305    if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     306    return (FALSE);
     307  }
     308  /* read Measure table header */
     309  if (!gfits_fread_header (subcat[0].f, &header)) {
     310    if (VERBOSE) fprintf (stderr, "can't read table measure header");
     311    return (FALSE);
     312  }
     313  /* read Measure table data : format is irrelevant here */
     314  if (!gfits_fread_vtable_range (subcat[0].f, &vtable, start, Nrows)) {
     315    if (VERBOSE) fprintf (stderr, "can't read table measure data");
     316    return (FALSE);
     317  }
     318
     319  /* convert data format to internal : returns number of row read in Nmeasure */
     320  catalog[0].measure = VtableToMeasure (&vtable, &Nmeasure, &catalog[0].catformat);
     321  if (Nmeasure != Nrows) {
     322    fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers (%d vs %d)\n", Nmeasure, Nrows);
     323  }
     324  gfits_free_header (&header);
     325  gfits_free_matrix (&matrix);
     326  catalog[0].Nmeasure = Nmeasure;
     327  catalog[0].Nmeas_off = start;
     328  return (TRUE);
     329}
     330
     331int dvo_catalog_load_segment_split_missing (Catalog *catalog, int start, int Nrows) {
     332
     333  // XXX check the open status of the FILE *f?
     334
     335  Catalog *subcat = catalog[0].missing_catalog;
     336
     337  /* move pointer past header -- must be already read (load_catalog) */
     338  fseek (subcat[0].f, subcat[0].header.size, SEEK_SET);
     339  /* matrix should be empty : XXX should we drop this step and skip the data? */
     340  if (!gfits_fread_matrix (subcat[0].f, &matrix, &subcat[0].header)) {
     341    if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     342    return (FALSE);
     343  }
     344  /* read Missing table header */
     345  if (!gfits_fread_header (subcat[0].f, &header)) {
     346    if (VERBOSE) fprintf (stderr, "can't read table missing header");
     347    return (FALSE);
     348  }
     349  /* read Missing table data : format is irrelevant here */
     350  if (!gfits_fread_vtable_range (subcat[0].f, &vtable, start, Nrows)) {
     351    if (VERBOSE) fprintf (stderr, "can't read table missing data");
     352    return (FALSE);
     353  }
     354
     355  /* convert data format to internal : returns number of row read in Nmissing */
     356  catalog[0].missing = VtableToMissing (&vtable, &Nmissing, &catalog[0].catformat);
     357  if (Nmissing != Nrows) {
     358    fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers (%d vs %d)\n", Nmissing, Nrows);
     359  }
     360  gfits_free_header (&header);
     361  gfits_free_matrix (&matrix);
     362  catalog[0].Nmissing = Nmissing;
     363  catalog[0].Nmiss_off = start;
    266364  return (TRUE);
    267365}
     
    346444    /* write out Average table (convert to FITS table format) */
    347445    if (!AverageToFtable (&ftable, catalog[0].average, catalog[0].Naverage, catalog[0].catformat, primary)) {
    348         fprintf (stderr, "trouble converting format\n");
    349         goto failure;
     446      fprintf (stderr, "trouble converting format\n");
     447      goto failure;
    350448    }
    351449    if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
Note: See TracChangeset for help on using the changeset viewer.