Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h	(revision 33220)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h	(revision 33221)
@@ -464,4 +464,6 @@
 int WriteRawSecFilt (FILE *f, SecFilt *secfilt, off_t Nsecfilt, char format);
 
+DVOTableFormat FtableGetFormat (FTable *ftable);
+
 Average *FtableToAverage (FTable *ftable, off_t *Naverage, char *format, SecFilt **primary);
 Measure *FtableToMeasure (FTable *ftable, off_t *Nmeasure, char *format);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog.c	(revision 33220)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog.c	(revision 33221)
@@ -250,4 +250,7 @@
 
   dvo_catalog_init (catalog, FALSE);
+
+  // reset the file pointer in case we've already read some data
+  fseeko (catalog[0].f, 0, SEEK_SET);
 
   // load the main catalog header, determine characteristics
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_mef.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_mef.c	(revision 33220)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_mef.c	(revision 33221)
@@ -3,25 +3,18 @@
 int dvo_catalog_load_mef (Catalog *catalog, int VERBOSE) {
   
+  off_t Nbytes;
+  off_t Naverage;
+  off_t Nmeasure;
+  off_t Nmissing;
+  off_t Nitems, Nexpect;
   int Nsecfilt;
-  off_t Nitems, Nbytes, Nexpect, Naverage, Nmeasure, Nmissing;
-  FILE *f;
 
   Header header;
-  Matrix matrix;
   FTable ftable;
 
   SecFilt *primary = NULL;
 
-  f = catalog[0].f;
   ftable.header = &header;
 
-  /* move pointer past header -- must be already read (load_catalog) */
-  fseeko (f, catalog[0].header.datasize, SEEK_SET);
-
-  /* matrix should be empty */
-  if (!gfits_fread_matrix (f, &matrix, &catalog[0].header)) {
-    if (VERBOSE) fprintf (stderr, "can't read primary matrix");
-    return (FALSE);
-  }
   /* get the components from the header */
   if (!gfits_scan (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  &Naverage)) return (FALSE);
@@ -58,14 +51,22 @@
   catalog[0].secfilt = NULL;
 
-  /* validate table mode */
+  /* validate table mode ?*/
+
+  /*** Average Table ***/
+
+  /* need to read the table header to determine format (whether or not we read averages) */
+  /* move pointer past PHU header -- must be already read (load_catalog) */
+  Nbytes = catalog[0].header.datasize + gfits_data_size (&catalog[0].header);
+  fseeko (catalog[0].f, Nbytes, SEEK_SET);
 
   /* read Average table header */
-  if (!gfits_fread_header (f, &header)) {
+  if (!gfits_fread_header (catalog[0].f, &header)) {
     if (VERBOSE) fprintf (stderr, "can't read table average header");
     return (FALSE);
   }
+
   /* read Average table data (or skip) */
   if (catalog[0].catflags & LOAD_AVES) {
-    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
+    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
       if (VERBOSE) fprintf (stderr, "can't read table average data");
       return (FALSE);
@@ -79,6 +80,7 @@
     catalog[0].Naves_off = 0;
   } else {
+    catalog[0].catformat = FtableGetFormat (&ftable);
     Nbytes = gfits_data_size (&header);
-    fseeko (f, Nbytes, SEEK_CUR);
+    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     ALLOCATE (catalog[0].average, Average, 1);
     catalog[0].Naverage = 0;
@@ -89,5 +91,5 @@
 
   /* read Measure table header */
-  if (!gfits_fread_header (f, &header)) {
+  if (!gfits_fread_header (catalog[0].f, &header)) {
     if (VERBOSE) fprintf (stderr, "can't read table measure header");
     return (FALSE);
@@ -95,5 +97,5 @@
   /* read Measure table data */
   if (catalog[0].catflags & LOAD_MEAS) {
-    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
+    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
       if (VERBOSE) fprintf (stderr, "can't read table measure data");
       return (FALSE);
@@ -107,5 +109,5 @@
   } else {
     Nbytes = gfits_data_size (&header);
-    fseeko (f, Nbytes, SEEK_CUR);
+    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     ALLOCATE (catalog[0].measure, Measure, 1);
     catalog[0].Nmeasure = 0;
@@ -114,5 +116,5 @@
 
   /* read Missing table header */
-  if (!gfits_fread_header (f, &header)) {
+  if (!gfits_fread_header (catalog[0].f, &header)) {
     if (VERBOSE) fprintf (stderr, "can't read table missing header");
     return (FALSE);
@@ -120,5 +122,5 @@
   /* read Missing table data */
   if (catalog[0].catflags & LOAD_MISS) {
-    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
+    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
       if (VERBOSE) fprintf (stderr, "can't read table missing data");
       return (FALSE);
@@ -137,5 +139,5 @@
   } else {
     Nbytes = gfits_data_size (&header);
-    fseeko (f, Nbytes, SEEK_CUR);
+    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     ALLOCATE (catalog[0].missing, Missing, 1);
     catalog[0].Nmissing = 0;
@@ -144,5 +146,5 @@
 
   /* read secfilt table header */
-  if (!gfits_fread_header (f, &header)) {
+  if (!gfits_fread_header (catalog[0].f, &header)) {
     if (VERBOSE) fprintf (stderr, "can't read table secfilt header");
     return (FALSE);
@@ -150,5 +152,5 @@
   /* read secfilt table data */
   if (catalog[0].catflags & LOAD_SECF) {
-    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
+    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
       if (VERBOSE) fprintf (stderr, "can't read table secfilt data");
       return (FALSE);
@@ -188,5 +190,5 @@
     /* no real need to skip the data array here... */
     Nbytes = gfits_data_size (&header);
-    fseeko (f, Nbytes, SEEK_CUR);
+    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     if (primary != NULL) {
       free (primary);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_split.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 33220)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 33221)
@@ -160,5 +160,7 @@
 
   off_t Nbytes;
-  off_t Naverage, Nmeasure, Nmissing;
+  off_t Naverage;
+  off_t Nmeasure;
+  off_t Nmissing;
   off_t Nitems;
   int status, Nsecfilt;
@@ -209,13 +211,16 @@
 
   /*** Average Table ***/
+
+  /* need to read the table header to determine format (whether or not we read averages) */
+  /* move pointer past PHU header -- must be already read (load_catalog) */
+  Nbytes = catalog[0].header.datasize + gfits_data_size (&catalog[0].header);
+  fseeko (catalog[0].f, Nbytes, SEEK_SET);
+
+  /* read Average table header */
+  if (!gfits_fread_header (catalog[0].f, &header)) { 
+    if (VERBOSE) fprintf (stderr, "can't read table average header");
+    return (FALSE);
+  }
   if (catalog[0].catflags & LOAD_AVES) {
-    /* move pointer past header -- must be already read (load_catalog) */
-    Nbytes = catalog[0].header.datasize + gfits_data_size (&catalog[0].header);
-    fseeko (catalog[0].f, Nbytes, SEEK_SET);
-    /* read Average table header */
-    if (!gfits_fread_header (catalog[0].f, &header)) { 
-      if (VERBOSE) fprintf (stderr, "can't read table average header");
-      return (FALSE);
-    }
     /* read Average table data : format is irrelevant here */
     if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) { 
@@ -234,4 +239,5 @@
     catalog[0].Naves_off = 0;
   } else {
+    catalog[0].catformat = FtableGetFormat (&ftable);
     ALLOCATE (catalog[0].average, Average, 1);
     catalog[0].Naverage = 0;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert.c	(revision 33220)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/dvo_convert.c	(revision 33221)
@@ -10,4 +10,39 @@
 /** this file might be more readable if I use macros for the repetative
     constructions below **/
+
+DVOTableFormat FtableGetFormat (FTable *ftable) {
+
+  DVOTableFormat format;
+  char extname[80];
+
+  /* read the format of this table */
+  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
+    fprintf (stderr, "EXTNAME missing for average table\n");
+    return (DVO_FORMAT_UNDEF);
+  }
+
+  if (!strcmp (extname, "DVO_AVERAGE")) {
+    format = DVO_FORMAT_INTERNAL;
+    return (format);
+  }
+# define CONVERT_FORMAT(NAME, FORMAT)		\
+  if (!strcmp (extname, NAME)) {		\
+    format = DVO_FORMAT_##FORMAT;		\
+    return (format); }
+
+  CONVERT_FORMAT ("DVO_AVERAGE_ELIXIR", 	 ELIXIR);
+  CONVERT_FORMAT ("DVO_AVERAGE_LONEOS", 	 LONEOS);
+  CONVERT_FORMAT ("DVO_AVERAGE_PANSTARRS_DEV_0", PANSTARRS_DEV_0);
+  CONVERT_FORMAT ("DVO_AVERAGE_PANSTARRS_DEV_1", PANSTARRS_DEV_1);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_1",       PS1_DEV_1);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_2",       PS1_DEV_2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V1",          PS1_V1);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V2",          PS1_V2);
+  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF);
+# undef CONVERT_FORMAT
+
+  fprintf (stderr, "table format unknown: %s\n", extname);
+  return (DVO_FORMAT_UNDEF);
+}
 
 /*** Average / FTable conversion functions ***/
