IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36918


Ignore:
Timestamp:
Jun 19, 2014, 10:36:43 PM (12 years ago)
Author:
eugene
Message:

define lensing & lensobj I/O functions

Location:
branches/eam_branches/ipp-20140610/Ohana/src/libdvo
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/dvo.h

    r36917 r36918  
    7979
    8080/* catalog values to be loaded */
    81 # define LOAD_NONE      0x00
    82 # define LOAD_AVES      0x01
    83 # define LOAD_MEAS      0x02
    84 # define LOAD_MISS      0x04
    85 # define LOAD_SECF      0x08
    86 # define SKIP_AVES      0x10
    87 # define SKIP_MEAS      0x20
    88 # define SKIP_MISS      0x40
    89 # define SKIP_SECF      0x80
    90 
    91 // # define LOAD_MEAS_META 0x100 -- is this used??
     81# define LOAD_NONE      0x000
     82# define LOAD_AVES      0x001
     83# define LOAD_MEAS      0x002
     84# define LOAD_MISS      0x004
     85# define LOAD_SECF      0x008
     86# define SKIP_AVES      0x010
     87# define SKIP_MEAS      0x020
     88# define SKIP_MISS      0x040
     89# define SKIP_SECF      0x080
     90# define LOAD_LENSING   0x100
     91# define LOAD_LENSOBJ   0x200
     92# define SKIP_LENSING   0x400
     93# define SKIP_LENSOBJ   0x800
    9294
    9395/* photometry code types */
     
    552554Measure *Measure_PS1_V4alt_ToInternal (Average *ave, Measure_PS1_V4alt *in, off_t Nvalues);
    553555
     556/* for some reason I have merged the set of tables and the file description,
     557   so I need to have an internal structure to point to the separate files */
     558
    554559/* a catalog contains this data */
    555560typedef struct Catalog {
     
    564569  SecFilt *secfilt;
    565570
     571  // lensing data (optional?)
     572  Lensing *lensing;
     573  Lensobj *lensobj;
     574
    566575  int Nsecfilt;  /* number of secfilt entries for each average entry */
    567   off_t Naverage,   Nmeasure,   Nmissing,   Nsecf_mem;  /* current number of each component in memory */
    568   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */
    569   off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nsecf_off;  /* index of first loaded data value */
     576  off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nsecf_mem;  /* current number of each component in memory */
     577  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nsecf_disk; /* current number of each component on disk */
     578  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nsecf_off;  /* index of first loaded data value */
    570579
    571580  // note that we use these for the full-sky relphot analysis
     
    586595  struct Catalog *missing_catalog;              /* missing catalog data (split) */
    587596  struct Catalog *secfilt_catalog;              /* secfilt catalog data (split) */
     597  struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
     598  struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
    588599
    589600  unsigned int objID;
     
    790801Measure *FtableToMeasure (FTable *ftable, Average *average, off_t *Nmeasure, char *format);
    791802SecFilt *FtableToSecFilt (FTable *ftable, off_t *Nsecfilt, char *format);
     803Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
     804Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
    792805int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    793806
     
    795808int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, char format);
    796809int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, char format);
     810int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
     811int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
    797812int ImageToFtable (FTable *ftable, Header *theader, char format);
    798813int ImageToVtable (VTable *vtable, Header *theader, char format);
     
    915930void dvo_measureT_init (MeasureTiny *measure);
    916931
     932void dvo_lensing_init (Lensing *lensing);
     933void dvo_lensobj_init (Lensobj *lensobj);
     934
    917935void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
    918936void FreeRegionHosts (RegionHostInfo *hosts, int Nhosts);
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/ps1_v5_defs.h

    r36898 r36918  
    88SecFilt_PS1_V5          *SecFiltInternalTo_PS1_V5 (SecFilt *in, off_t Nvalues);
    99
     10Lensing                 *Lensing_PS1_V5_ToInternal (Lensing_PS1_V5 *in, off_t Nvalues);
     11Lensing_PS1_V5          *LensingInternalTo_PS1_V5 (Lensing *in, off_t Nvalues);
     12Lensobj                 *Lensobj_PS1_V5_ToInternal (Lensobj_PS1_V5 *in, off_t Nvalues);
     13Lensobj_PS1_V5          *LensobjInternalTo_PS1_V5 (Lensobj *in, off_t Nvalues);
     14
    1015PhotCode                *PhotCode_PS1_V5_To_Internal (PhotCode_PS1_V5 *in, off_t Nvalues);
    1116PhotCode_PS1_V5         *PhotCode_Internal_To_PS1_V5 (PhotCode *in, off_t Nvalues);
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_catalog.c

    r36917 r36918  
    390390}
    391391
     392// init all data, or just catalog data
     393void dvo_lensing_init (Lensing *lensing) {
     394  lensing->X11_sm_obj = NAN;
     395  lensing->X12_sm_obj = NAN;
     396  lensing->X22_sm_obj = NAN;
     397  lensing->E1_sm_obj  = NAN;
     398  lensing->E2_sm_obj  = NAN;
     399
     400  lensing->X11_sh_obj = NAN;
     401  lensing->X12_sh_obj = NAN;
     402  lensing->X22_sh_obj = NAN;
     403  lensing->E1_sh_obj  = NAN;
     404  lensing->E2_sh_obj  = NAN;
     405
     406  lensing->X11_sm_psf = NAN;
     407  lensing->X12_sm_psf = NAN;
     408  lensing->X22_sm_psf = NAN;
     409  lensing->E1_sm_psf  = NAN;
     410  lensing->E2_sm_psf  = NAN;
     411
     412  lensing->X11_sh_psf = NAN;
     413  lensing->X12_sh_psf = NAN;
     414  lensing->X22_sh_psf = NAN;
     415  lensing->E1_sh_psf  = NAN;
     416  lensing->E2_sh_psf  = NAN;
     417
     418  lensing->F_ApR5     = NAN;
     419  lensing->dF_ApR5    = NAN;
     420  lensing->sF_ApR5    = NAN;
     421  lensing->fF_ApR5    = NAN;
     422
     423  lensing->F_ApR6     = NAN;
     424  lensing->dF_ApR6    = NAN;
     425  lensing->sF_ApR6    = NAN;
     426  lensing->fF_ApR6    = NAN;
     427
     428  lensing->detID = -1;
     429  lensing->objID = -1;
     430  lensing->catID = -1;
     431
     432  lensing->pad = 0;
     433}
     434
     435// init all data, or just catalog data
     436void dvo_lensobj_init (Lensobj *lensobj) {
     437  lensobj->X11_sm_obj = NAN;
     438  lensobj->X12_sm_obj = NAN;
     439  lensobj->X22_sm_obj = NAN;
     440  lensobj->E1_sm_obj  = NAN;
     441  lensobj->E2_sm_obj  = NAN;
     442
     443  lensobj->X11_sh_obj = NAN;
     444  lensobj->X12_sh_obj = NAN;
     445  lensobj->X22_sh_obj = NAN;
     446  lensobj->E1_sh_obj  = NAN;
     447  lensobj->E2_sh_obj  = NAN;
     448
     449  lensobj->X11_sm_psf = NAN;
     450  lensobj->X12_sm_psf = NAN;
     451  lensobj->X22_sm_psf = NAN;
     452  lensobj->E1_sm_psf  = NAN;
     453  lensobj->E2_sm_psf  = NAN;
     454
     455  lensobj->X11_sh_psf = NAN;
     456  lensobj->X12_sh_psf = NAN;
     457  lensobj->X22_sh_psf = NAN;
     458  lensobj->E1_sh_psf  = NAN;
     459  lensobj->E2_sh_psf  = NAN;
     460
     461  lensobj->F_ApR5     = NAN;
     462  lensobj->dF_ApR5    = NAN;
     463  lensobj->sF_ApR5    = NAN;
     464  lensobj->fF_ApR5    = NAN;
     465
     466  lensobj->F_ApR6     = NAN;
     467  lensobj->dF_ApR6    = NAN;
     468  lensobj->sF_ApR6    = NAN;
     469  lensobj->fF_ApR6    = NAN;
     470
     471  lensobj->gamma = NAN;
     472  lensobj->E1 = NAN;
     473  lensobj->E2 = NAN;
     474
     475  lensobj->objID = -1;
     476  lensobj->catID = -1;
     477
     478  lensobj->pad = 0;
     479}
     480
    392481/* possible exit status for lock_catalog:
    393482   DVO_CAT_OPEN_FAIL - failure (including lock failure)
     
    434523
    435524  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    436     if (catalog[0].measure_catalog != NULL) dvo_catalog_unlock (catalog[0].measure_catalog);
    437     if (catalog[0].missing_catalog != NULL) dvo_catalog_unlock (catalog[0].missing_catalog);
    438     if (catalog[0].secfilt_catalog != NULL) dvo_catalog_unlock (catalog[0].secfilt_catalog);
     525    if (catalog[0].measure_catalog) dvo_catalog_unlock (catalog[0].measure_catalog);
     526    if (catalog[0].missing_catalog) dvo_catalog_unlock (catalog[0].missing_catalog);
     527    if (catalog[0].secfilt_catalog) dvo_catalog_unlock (catalog[0].secfilt_catalog);
     528    if (catalog[0].lensing_catalog) dvo_catalog_unlock (catalog[0].lensing_catalog);
     529    if (catalog[0].lensobj_catalog) dvo_catalog_unlock (catalog[0].lensobj_catalog);
    439530  }
    440531  return (1);
     
    702793      free (catalog[0].secfilt_catalog);
    703794    }
     795    if (catalog[0].lensing_catalog) {
     796      free (catalog[0].lensing_catalog[0].filename);
     797      dvo_catalog_free (catalog[0].lensing_catalog);
     798      free (catalog[0].lensing_catalog);
     799    }
     800    if (catalog[0].lensobj_catalog) {
     801      free (catalog[0].lensobj_catalog[0].filename);
     802      dvo_catalog_free (catalog[0].lensobj_catalog);
     803      free (catalog[0].lensobj_catalog);
     804    }
    704805  }
    705806  dvo_catalog_free_data (catalog);
     
    711812
    712813  /* free, initialize data structures */
    713   if (catalog[0].average != NULL) {
     814  if (catalog[0].average) {
    714815    free (catalog[0].average);
    715816    catalog[0].Naverage = 0;
    716817    catalog[0].average = NULL;
    717818  }
    718   if (catalog[0].measure != NULL) {
     819  if (catalog[0].measure) {
    719820    free (catalog[0].measure);
    720821    catalog[0].Nmeasure = 0;
    721822    catalog[0].measure = NULL;
    722823  }
    723   if (catalog[0].missing != NULL) {
     824  if (catalog[0].missing) {
    724825    free (catalog[0].missing);
    725826    catalog[0].Nmissing = 0;
    726827    catalog[0].missing = NULL;
    727828  }
    728   if (catalog[0].secfilt != NULL) {
     829  if (catalog[0].secfilt) {
    729830    free (catalog[0].secfilt);
    730831    catalog[0].Nsecf_mem = 0;
    731832    catalog[0].secfilt = NULL;
     833  }
     834  if (catalog[0].lensing) {
     835    free (catalog[0].lensing);
     836    catalog[0].Nlensing = 0;
     837    catalog[0].lensing = NULL;
     838  }
     839  if (catalog[0].lensobj) {
     840    free (catalog[0].lensobj);
     841    catalog[0].Nlensobj = 0;
     842    catalog[0].lensobj = NULL;
    732843  }
    733844}
     
    819930      }
    820931    }
     932    if (catalog[0].lensing_catalog != NULL) {
     933      if (!dvo_catalog_backup (catalog[0].lensing_catalog, FALSE)) {
     934        return FALSE;
     935      }
     936    }
     937    if (catalog[0].lensobj_catalog != NULL) {
     938      if (!dvo_catalog_backup (catalog[0].lensobj_catalog, FALSE)) {
     939        return FALSE;
     940      }
     941    }
    821942  }
    822943  return TRUE;
     
    860981      }
    861982    }
     983    if (catalog[0].lensing_catalog != NULL) {
     984      if (!dvo_catalog_unlink_backup (catalog[0].lensing_catalog, FALSE)) {
     985        return FALSE;
     986      }
     987    }
     988    if (catalog[0].lensobj_catalog != NULL) {
     989      if (!dvo_catalog_unlink_backup (catalog[0].lensobj_catalog, FALSE)) {
     990        return FALSE;
     991      }
     992    }
    862993  }
    863994  return TRUE;
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_catalog_create.c

    r27435 r36918  
    7070    gfits_modify (&catalog[0].header, "SECFILT", "%s", 1, file);
    7171    free (file);
     72
     73    /* define lensing catalog file */
     74    ALLOCATE (catalog[0].lensing_catalog, Catalog, 1);
     75    dvo_catalog_init (catalog[0].lensing_catalog, TRUE);
     76
     77    /* create basic data for lensing catalog file */
     78    gfits_create_header (&catalog[0].lensing_catalog[0].header);
     79    ALLOCATE (catalog[0].lensing_catalog[0].filename, char, length);
     80    sprintf (catalog[0].lensing_catalog[0].filename, "%s/%s.cpx", path, root);
     81    file = filebasename (catalog[0].lensing_catalog[0].filename);
     82    gfits_modify (&catalog[0].header, "LENSING", "%s", 1, file);
     83    free (file);
     84
     85    /* define lensobj catalog file */
     86    ALLOCATE (catalog[0].lensobj_catalog, Catalog, 1);
     87    dvo_catalog_init (catalog[0].lensobj_catalog, TRUE);
     88
     89    /* create basic data for lensobj catalog file */
     90    gfits_create_header (&catalog[0].lensobj_catalog[0].header);
     91    ALLOCATE (catalog[0].lensobj_catalog[0].filename, char, length);
     92    sprintf (catalog[0].lensobj_catalog[0].filename, "%s/%s.cpy", path, root);
     93    file = filebasename (catalog[0].lensobj_catalog[0].filename);
     94    gfits_modify (&catalog[0].header, "LENSOBJ", "%s", 1, file);
     95    free (file);
     96
    7297    free (path);
    7398    free (root);
     
    84109    }
    85110    if (dvo_catalog_lock (catalog[0].secfilt_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
     111      fprintf (stderr, "error with file lock\n");
     112      exit (2);
     113    }
     114    if (dvo_catalog_lock (catalog[0].lensing_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
     115      fprintf (stderr, "error with file lock\n");
     116      exit (2);
     117    }
     118    if (dvo_catalog_lock (catalog[0].lensobj_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
    86119      fprintf (stderr, "error with file lock\n");
    87120      exit (2);
     
    111144  ALLOCATE (catalog[0].missing, Missing, 1);
    112145  ALLOCATE (catalog[0].secfilt, SecFilt, 1);
     146  ALLOCATE (catalog[0].lensing, Lensing, 1);
     147  ALLOCATE (catalog[0].lensobj, Lensobj, 1);
    113148
    114149  /* setup secondary filters to match photcodes:
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r36898 r36918  
    77  off_t Nmeasure;
    88  off_t Nmissing;
     9  off_t Nlensing;
     10  off_t Nlensobj;
    911  off_t Nitems, Nexpect;
    1012  int Nsecfilt;
     
    2224  if (!gfits_scan (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  &Nmissing)) return (FALSE);
    2325  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &Nsecfilt)) Nsecfilt = 0;
     26  if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) return (FALSE);
     27  if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) return (FALSE);
    2428
    2529  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    4044  catalog[0].Nmiss_disk = Nmissing;
    4145  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     46  catalog[0].Nlensing_disk = Nlensing;
     47  catalog[0].Nlensobj_disk = Nlensobj;
    4248
    4349  /**  Nsecfilt is unusual: it does not list the number of data items in the table
     
    5056  catalog[0].missing = NULL;
    5157  catalog[0].secfilt = NULL;
     58  catalog[0].lensing = NULL;
     59  catalog[0].lensobj = NULL;
    5260
    5361  /* validate table mode ?*/
     
    201209  }
    202210
     211  /* read Lensing table header */
     212  if (!gfits_fread_header (catalog[0].f, &header)) {
     213    if (VERBOSE) fprintf (stderr, "can't read table lensing header");
     214    return (FALSE);
     215  }
     216  /* read Lensing table data */
     217  if (catalog[0].catflags & LOAD_LENSING) {
     218    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
     219      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
     220      return (FALSE);
     221    }
     222    catalog[0].lensing = FtableToLensing (&ftable, &catalog[0].Nlensing, &catalog[0].catformat);
     223    if (Nlensing != catalog[0].Nlensing_disk) {
     224      fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  catalog[0].Nlensing_disk);
     225    }
     226    catalog[0].Nlensing = catalog[0].Nlensing_disk;
     227    catalog[0].Nlensing_off = 0;
     228  } else {
     229    Nbytes = gfits_data_size (&header);
     230    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     231    ALLOCATE (catalog[0].lensing, Lensing, 1);
     232    catalog[0].Nlensing = 0;
     233    catalog[0].Nlensing_off = catalog[0].Nlensing_disk;
     234  }
     235
     236  /* read Lensobj table header */
     237  if (!gfits_fread_header (catalog[0].f, &header)) {
     238    if (VERBOSE) fprintf (stderr, "can't read table lensobj header");
     239    return (FALSE);
     240  }
     241  /* read Lensobj table data */
     242  if (catalog[0].catflags & LOAD_LENSOBJ) {
     243    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
     244      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
     245      return (FALSE);
     246    }
     247    catalog[0].lensobj = FtableToLensobj (&ftable, &catalog[0].Nlensobj, &catalog[0].catformat);
     248    if (Nlensobj != catalog[0].Nlensobj_disk) {
     249      fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  catalog[0].Nlensobj_disk);
     250    }
     251    catalog[0].Nlensobj = catalog[0].Nlensobj_disk;
     252    catalog[0].Nlensobj_off = 0;
     253  } else {
     254    Nbytes = gfits_data_size (&header);
     255    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     256    ALLOCATE (catalog[0].lensobj, Lensobj, 1);
     257    catalog[0].Nlensobj = 0;
     258    catalog[0].Nlensobj_off = catalog[0].Nlensobj_disk;
     259  }
     260
    203261  return (TRUE);
    204262}
     
    249307  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  catalog[0].Nmissing);
    250308  gfits_modify (&catalog[0].header, "NSECFILT", "%d",   1,                        Nsecfilt);
     309  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  catalog[0].Nlensing);
     310  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  catalog[0].Nlensobj);
    251311  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    252312  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    317377  Nitems = catalog[0].Naverage * Nsecfilt;
    318378  SecFiltToFtable (&ftable, secfilt, Nitems, catalog[0].catformat);
     379  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     380    fprintf (stderr, "can't write table header");
     381    goto failure;
     382  }
     383  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     384    fprintf (stderr, "can't write table data");
     385    goto failure;
     386  }
     387  gfits_free_table (&ftable);
     388  gfits_free_header (&header);
     389
     390  /* write out Lensing table (convert to FITS table format) */
     391  LensingToFtable (&ftable, catalog[0].lensing, catalog[0].Nlensing, catalog[0].catformat);
     392  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     393    fprintf (stderr, "can't write table header");
     394    goto failure;
     395  }
     396  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     397    fprintf (stderr, "can't write table data");
     398    goto failure;
     399  }
     400  gfits_free_table (&ftable);
     401  gfits_free_header (&header);
     402
     403  /* write out Lensobj table (convert to FITS table format) */
     404  LensobjToFtable (&ftable, catalog[0].lensobj, catalog[0].Nlensobj, catalog[0].catformat);
    319405  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    320406    fprintf (stderr, "can't write table header");
     
    356442  secfilt header
    357443  secfilt table
     444  lensing header
     445  lensing table
     446  lensobj header
     447  lensobj table
    358448*/
    359449   
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_catalog_split.c

    r36898 r36918  
    161161  fseeko (subcat[0].f, Nskip, SEEK_CUR);
    162162
    163   /* read Measure table header */
     163  /* read table header */
    164164  if (!gfits_fread_header (subcat[0].f, header)) {
    165165    if (VERBOSE) fprintf (stderr, "can't read %s PHU header\n", name);
     
    176176  off_t Nmeasure;
    177177  off_t Nmissing;
     178  off_t Nlensing;
     179  off_t Nlensobj;
    178180  off_t Nitems;
    179181  int status, Nsecfilt;
     
    194196  if (!gfits_scan (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  &Nmissing)) return (FALSE);
    195197  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &Nsecfilt)) Nsecfilt = 0;
     198  if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) return (FALSE);
     199  if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) return (FALSE);
    196200
    197201  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    212216  catalog[0].Nmiss_disk = Nmissing;
    213217  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
     218  catalog[0].Nlensing_disk = Nlensing;
     219  catalog[0].Nlensobj_disk = Nlensobj;
    214220
    215221  /**  Nsecfilt is unusual: it does not list the number of data items in the table
     
    222228  catalog[0].missing = NULL;
    223229  catalog[0].secfilt = NULL;
     230  catalog[0].lensing = NULL;
     231  catalog[0].lensobj = NULL;
    224232
    225233  /*** Average Table ***/
     
    372380  gfits_free_header (ftable.header);
    373381
     382  /*** Lensing Table ***/
     383  if (!(catalog[0].catflags & SKIP_LENSING)) {
     384    // unless we specify 'skip', we still need to load the
     385    status = dvo_catalog_open_subcat (catalog, &catalog[0].lensing_catalog, ftable.header, "LENSING", VERBOSE);
     386    if (status == DVO_CAT_OPEN_FAIL) {
     387      return (FALSE);
     388    }
     389    if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nlensing_disk > 0)) {
     390      return (FALSE);
     391    }
     392  }
     393  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_LENSING)) {
     394    // XXX this allows an empty Lensing catalog with non-empty Average catalog : is that OK?
     395    /* read Lensing table data */
     396    if (!gfits_fread_ftable_data (catalog[0].lensing_catalog[0].f, &ftable, FALSE)) {
     397      if (VERBOSE) fprintf (stderr, "can't read table lensing data\n");
     398      return (FALSE);
     399    }
     400    /* convert data format to internal : returns number of row read in Nlensing */
     401    catalog[0].lensing = FtableToLensing (&ftable, &Nlensing, &catalog[0].catformat);
     402    if (Nlensing != catalog[0].Nlensing_disk) {
     403      fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  catalog[0].Nlensing_disk);
     404    }
     405    catalog[0].Nlensing = catalog[0].Nlensing_disk;
     406    catalog[0].Nlensing_off = 0;
     407  } else {
     408    // XXX is it necessary to generate a template header here?
     409    // XXX this is a memory leak, right?
     410    if (catalog[0].lensing_catalog) {
     411      gfits_free_header (&catalog[0].lensing_catalog[0].header);
     412    } else {
     413      ALLOCATE (catalog[0].lensing_catalog, Catalog, 1);
     414      dvo_catalog_init (catalog[0].lensing_catalog, TRUE);
     415    }
     416    gfits_create_header (&catalog[0].lensing_catalog[0].header);
     417    ALLOCATE (catalog[0].lensing, Lensing, 1);
     418    catalog[0].Nlensing = 0;
     419    catalog[0].Nlensing_off = catalog[0].Nlensing_disk;
     420  }
     421  gfits_free_header (&header);
     422
     423  /*** Lensobj Table ***/
     424  if (!(catalog[0].catflags & SKIP_LENSOBJ)) {
     425    // unless we specify 'skip', we still need to load the
     426    status = dvo_catalog_open_subcat (catalog, &catalog[0].lensobj_catalog, ftable.header, "LENSOBJ", VERBOSE);
     427    if (status == DVO_CAT_OPEN_FAIL) {
     428      return (FALSE);
     429    }
     430    if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nlensobj_disk > 0)) {
     431      return (FALSE);
     432    }
     433  }
     434  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_LENSOBJ)) {
     435    // XXX this allows an empty Lensobj catalog with non-empty Average catalog : is that OK?
     436    /* read Lensobj table data */
     437    if (!gfits_fread_ftable_data (catalog[0].lensobj_catalog[0].f, &ftable, FALSE)) {
     438      if (VERBOSE) fprintf (stderr, "can't read table lensobj data\n");
     439      return (FALSE);
     440    }
     441    /* convert data format to internal : returns number of row read in Nlensobj */
     442    catalog[0].lensobj = FtableToLensobj (&ftable, &Nlensobj, &catalog[0].catformat);
     443    if (Nlensobj != catalog[0].Nlensobj_disk) {
     444      fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  catalog[0].Nlensobj_disk);
     445    }
     446    catalog[0].Nlensobj = catalog[0].Nlensobj_disk;
     447    catalog[0].Nlensobj_off = 0;
     448  } else {
     449    // XXX is it necessary to generate a template header here?
     450    // XXX this is a memory leak, right?
     451    if (catalog[0].lensobj_catalog) {
     452      gfits_free_header (&catalog[0].lensobj_catalog[0].header);
     453    } else {
     454      ALLOCATE (catalog[0].lensobj_catalog, Catalog, 1);
     455      dvo_catalog_init (catalog[0].lensobj_catalog, TRUE);
     456    }
     457    gfits_create_header (&catalog[0].lensobj_catalog[0].header);
     458    ALLOCATE (catalog[0].lensobj, Lensobj, 1);
     459    catalog[0].Nlensobj = 0;
     460    catalog[0].Nlensobj_off = catalog[0].Nlensobj_disk;
     461  }
     462  gfits_free_header (&header);
     463
    374464  return (TRUE);
    375465}
     
    380470
    381471  off_t Nbytes;
    382   off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing;
     472  off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj;
    383473  Header header;
    384474  FTable ftable;
     
    519609    catalog[0].Nmiss_off = start;
    520610  }
     611
     612  // XXX check the open status of the catalog
     613  if (catalog[0].catflags & LOAD_LENSING) {
     614
     615    Catalog *subcat = catalog[0].lensing_catalog;
     616
     617    /* move pointer past header -- must be already read (load_catalog) */
     618    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
     619    fseeko (subcat[0].f, Nbytes, SEEK_SET);
     620
     621    /* read Lensing table header */
     622    if (!gfits_fread_header (subcat[0].f, &header)) {
     623      if (VERBOSE) fprintf (stderr, "can't read table lensing header");
     624      return (FALSE);
     625    }
     626    /* read Lensing table data : format is irrelevant here */
     627    if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     628      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
     629      return (FALSE);
     630    }
     631
     632    /* convert data format to internal : returns number of row read in Nlensing */
     633    catalog[0].lensing = FtableToLensing (&ftable, &Nlensing, &catalog[0].catformat);
     634    if (Nlensing != Nrows) {
     635      // XXX this condition denotes the eof has been reached; not an error or a warning
     636      // fprintf (stderr, "Warning: mismatch between Nlensing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensing,  Nrows);
     637    }
     638    gfits_free_header (&header);
     639    catalog[0].Nlensing = Nlensing;
     640    catalog[0].Nlensing_off = start;
     641  }
     642
     643  // XXX check the open status of the catalog
     644  if (catalog[0].catflags & LOAD_LENSOBJ) {
     645
     646    Catalog *subcat = catalog[0].lensobj_catalog;
     647
     648    /* move pointer past header -- must be already read (load_catalog) */
     649    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
     650    fseeko (subcat[0].f, Nbytes, SEEK_SET);
     651
     652    /* read Lensobj table header */
     653    if (!gfits_fread_header (subcat[0].f, &header)) {
     654      if (VERBOSE) fprintf (stderr, "can't read table lensobj header");
     655      return (FALSE);
     656    }
     657    /* read Lensobj table data : format is irrelevant here */
     658    if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     659      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
     660      return (FALSE);
     661    }
     662
     663    /* convert data format to internal : returns number of row read in Nlensobj */
     664    catalog[0].lensobj = FtableToLensobj (&ftable, &Nlensobj, &catalog[0].catformat);
     665    if (Nlensobj != Nrows) {
     666      // XXX this condition denotes the eof has been reached; not an error or a warning
     667      // fprintf (stderr, "Warning: mismatch between Nlensobj in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nlensobj,  Nrows);
     668    }
     669    gfits_free_header (&header);
     670    catalog[0].Nlensobj = Nlensobj;
     671    catalog[0].Nlensobj_off = start;
     672  }
     673
    521674  return (TRUE);
    522675}
     
    530683  SecFilt *primary, *secfilt;
    531684  int Nsecfilt;
    532   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     685  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
    533686  off_t first, start, Nrows;
    534687
     
    561714  Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
    562715  Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
     716  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
     717  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
    563718
    564719  /* make sure header is consistent with data */
     
    567722  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    568723  gfits_modify (&catalog[0].header, "NSECFILT", "%d",   1, Nsecfilt);
     724  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
     725  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    569726  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    570727  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    679836    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
    680837      fprintf (stderr, "failure writing SecFilt table\n");
     838      goto failure;
     839    }
     840    gfits_free_header (&header);
     841    gfits_free_table (&ftable);
     842  }
     843
     844  /*** Lensing Table ***/
     845  if ((catalog[0].catflags & LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     846
     847    first  = 0;                    // first row in memory to write
     848    start  = catalog[0].Nlensing_off; // first disk row to write
     849    Nrows  = catalog[0].Nlensing - first;
     850
     851    assert (Nrows >= 0);
     852    assert (first >= 0);
     853    assert (first <= catalog[0].Nlensing);
     854    assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
     855
     856    // convert to external table format (note that the block above does not damage or free catalog.average)
     857    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     858      fprintf (stderr, "trouble converting format\n");
     859      goto failure;
     860    }
     861
     862    // write out Lensing table
     863    if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
     864      fprintf (stderr, "trouble writing Lensing table\n");
     865      goto failure;
     866    }
     867    gfits_free_header (&header);
     868    gfits_free_table (&ftable);
     869  }
     870
     871  /*** Lensobj Table ***/
     872  if ((catalog[0].catflags & LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     873
     874    first  = 0;                    // first row in memory to write
     875    start  = catalog[0].Nlensobj_off; // first disk row to write
     876    Nrows  = catalog[0].Nlensobj - first;
     877
     878    assert (Nrows >= 0);
     879    assert (first >= 0);
     880    assert (first <= catalog[0].Nlensobj);
     881    assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
     882
     883    // convert to external table format (note that the block above does not damage or free catalog.average)
     884    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     885      fprintf (stderr, "trouble converting format\n");
     886      goto failure;
     887    }
     888
     889    // write out Lensobj table
     890    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
     891      fprintf (stderr, "trouble writing Lensobj table\n");
    681892      goto failure;
    682893    }
     
    711922  SecFilt *primary, *secfilt;
    712923  int Nsecfilt;
    713   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     924  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
    714925  off_t first, start, Nrows;
    715926
     
    734945  if (catalog[0].Nsecf_off > 0) {
    735946    fprintf (stderr, "ERROR: only partial catalog (Secfilt) was loaded\n");
     947    goto failure;
     948  }
     949  if (catalog[0].Nlensing_off > 0) {
     950    fprintf (stderr, "ERROR: only partial catalog (Lensing) was loaded\n");
     951    goto failure;
     952  }
     953  if (catalog[0].Nlensobj_off > 0) {
     954    fprintf (stderr, "ERROR: only partial catalog (Lensobj) was loaded\n");
    736955    goto failure;
    737956  }
     
    760979  Nmiss_disk_new = catalog[0].Nmissing;
    761980  Nsecf_disk_new = catalog[0].Naverage*Nsecfilt;
     981  Nlensing_disk_new = catalog[0].Nlensing;
     982  Nlensobj_disk_new = catalog[0].Nlensobj;
    762983
    763984  /* make sure header is consistent with data */
     
    766987  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    767988  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
     989  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
     990  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    768991  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    769992  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    8781101    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
    8791102      fprintf (stderr, "failure writing SecFilt table\n");
     1103      goto failure;
     1104    }
     1105    gfits_free_header (&header);
     1106    gfits_free_table (&ftable);
     1107  }
     1108
     1109  /*** Lensing Table ***/
     1110  if ((catalog[0].catflags & LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     1111
     1112    first  = 0;                    // first row in memory to write
     1113    start  = catalog[0].Nlensing_off; // first disk row to write
     1114    Nrows  = catalog[0].Nlensing - first;
     1115
     1116    assert (Nrows >= 0);
     1117    assert (first >= 0);
     1118    assert (first <= catalog[0].Nlensing);
     1119    assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
     1120
     1121    // convert to external table format
     1122    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     1123      fprintf (stderr, "trouble converting format\n");
     1124      goto failure;
     1125    }
     1126
     1127    // write out Lensing table
     1128    if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
     1129      fprintf (stderr, "trouble writing Lensing table\n");
     1130      goto failure;
     1131    }
     1132    gfits_free_header (&header);
     1133    gfits_free_table (&ftable);
     1134  }
     1135
     1136  /*** Lensobj Table ***/
     1137  if ((catalog[0].catflags & LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     1138
     1139    first  = 0;                    // first row in memory to write
     1140    start  = catalog[0].Nlensobj_off; // first disk row to write
     1141    Nrows  = catalog[0].Nlensobj - first;
     1142
     1143    assert (Nrows >= 0);
     1144    assert (first >= 0);
     1145    assert (first <= catalog[0].Nlensobj);
     1146    assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
     1147
     1148    // convert to external table format
     1149    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     1150      fprintf (stderr, "trouble converting format\n");
     1151      goto failure;
     1152    }
     1153
     1154    // write out Lensobj table
     1155    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
     1156      fprintf (stderr, "trouble writing Lensobj table\n");
    8801157      goto failure;
    8811158    }
     
    9091186  SecFilt *primary, *secfilt;
    9101187  int Nsecfilt;
    911   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new;
     1188  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
    9121189  off_t first, start, Nrows;
    9131190
     
    9391216  Nmiss_disk_new = MAX (catalog[0].Nmiss_disk, catalog[0].Nmissing + catalog[0].Nmiss_off);
    9401217  Nsecf_disk_new = MAX (catalog[0].Nsecf_disk, catalog[0].Naverage*Nsecfilt + catalog[0].Nsecf_off);
     1218  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
     1219  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
    9411220
    9421221  /* make sure header is consistent with data */
     
    9451224  gfits_modify (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  Nmiss_disk_new);
    9461225  gfits_modify (&catalog[0].header, "NSECFILT", "%d", 1, Nsecfilt);
     1226  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
     1227  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
    9471228  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    9481229  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    10591340    if (!dvo_catalog_save_subcat (catalog[0].secfilt_catalog, &ftable, start, Nrows, catalog[0].Nsecf_disk, Nsecf_disk_new)) {
    10601341      fprintf (stderr, "failure writing SecFilt table\n");
     1342      goto failure;
     1343    }
     1344    gfits_free_header (&header);
     1345    gfits_free_table (&ftable);
     1346  }
     1347
     1348  /*** Lensing Table ***/
     1349  if (catalog[0].lensing != NULL) {
     1350
     1351    first  = catalog[0].Nlensing_disk - catalog[0].Nlensing_off;  // first row in memory to write
     1352    start  = catalog[0].Nlensing_disk; // first disk row to write
     1353    Nrows  = catalog[0].Nlensing - first;
     1354
     1355    assert (Nrows >= 0);
     1356    assert (first >= 0);
     1357    assert (first <= catalog[0].Nlensing);
     1358    assert (catalog[0].Nlensing_disk >= catalog[0].Nlensing_off);
     1359
     1360    // convert to external table format
     1361    // XXX does catalog.lensing have averef correctly set up?
     1362    if (!LensingToFtable (&ftable, &catalog[0].lensing[first], Nrows, catalog[0].catformat)) {
     1363      fprintf (stderr, "trouble converting format\n");
     1364      goto failure;
     1365    }
     1366
     1367    // write out Lensing table
     1368    if (!dvo_catalog_save_subcat (catalog[0].lensing_catalog, &ftable, start, Nrows, catalog[0].Nlensing_disk, Nlensing_disk_new)) {
     1369      fprintf (stderr, "trouble writing Lensing table\n");
     1370      goto failure;
     1371    }
     1372    gfits_free_header (&header);
     1373    gfits_free_table (&ftable);
     1374  }
     1375
     1376  /*** Lensobj Table ***/
     1377  if (catalog[0].lensobj != NULL) {
     1378
     1379    first  = catalog[0].Nlensobj_disk - catalog[0].Nlensobj_off;  // first row in memory to write
     1380    start  = catalog[0].Nlensobj_disk; // first disk row to write
     1381    Nrows  = catalog[0].Nlensobj - first;
     1382
     1383    assert (Nrows >= 0);
     1384    assert (first >= 0);
     1385    assert (first <= catalog[0].Nlensobj);
     1386    assert (catalog[0].Nlensobj_disk >= catalog[0].Nlensobj_off);
     1387
     1388    // convert to external table format
     1389    // XXX does catalog.lensobj have averef correctly set up?
     1390    if (!LensobjToFtable (&ftable, &catalog[0].lensobj[first], Nrows, catalog[0].catformat)) {
     1391      fprintf (stderr, "trouble converting format\n");
     1392      goto failure;
     1393    }
     1394
     1395    // write out Lensobj table
     1396    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
     1397      fprintf (stderr, "trouble writing Lensobj table\n");
    10611398      goto failure;
    10621399    }
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert.c

    r36898 r36918  
    361361    default:
    362362      fprintf (stderr, "table format unknown (secfilt)\n");
     363      return (FALSE);
     364  }
     365  return (TRUE);
     366}
     367
     368/*** Lensing / FTable conversion functions ***/
     369
     370Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format) {
     371
     372  Lensing *lensing;
     373  char extname[80];
     374
     375  /* convert to the internal format */
     376  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     377    fprintf (stderr, "EXTNAME missing for lensing table\n");
     378    return (FALSE);
     379  }
     380
     381# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     382  if (!strcmp (extname, NAME)) {                                        \
     383    Lensing_##TYPE *tmpLensing;                                         \
     384    tmpLensing = gfits_table_get_Lensing_##TYPE (ftable, Nlensing, NULL); \
     385    if (!tmpLensing) {                                                  \
     386      fprintf (stderr, "ERROR: failed to read lensings\n");             \
     387      exit (2);                                                         \
     388    }                                                                   \
     389    lensing = Lensing_##TYPE##_ToInternal (tmpLensing, *Nlensing); \
     390    free (tmpLensing);                                                  \
     391    *format = DVO_FORMAT_##FORMAT;                                      \
     392    return (lensing); }
     393
     394  if (!strcmp (extname, "DVO_LENSING")) {
     395    lensing = gfits_table_get_Lensing (ftable, Nlensing, NULL);
     396    if (!lensing) {
     397      fprintf (stderr, "ERROR: failed to read lensings\n");
     398      exit (2);
     399    }
     400    *format = DVO_FORMAT_INTERNAL;
     401    return (lensing);
     402  }
     403
     404// CONVERT_FORMAT ("DVO_LENSING_PS1_REF",         PS1_REF,         PS1_REF);
     405// CONVERT_FORMAT ("DVO_LENSING_ELIXIR",          ELIXIR,          Elixir);
     406// CONVERT_FORMAT ("DVO_LENSING_LONEOS",          LONEOS,          Loneos);
     407// CONVERT_FORMAT ("DVO_LENSING_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     408// CONVERT_FORMAT ("DVO_LENSING_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     409// CONVERT_FORMAT ("DVO_LENSING_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     410// CONVERT_FORMAT ("DVO_LENSING_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     411// CONVERT_FORMAT ("DVO_LENSING_PS1_V1",          PS1_V1,          PS1_V1);
     412// CONVERT_FORMAT ("DVO_LENSING_PS1_V2",          PS1_V2,          PS1_V2);
     413// CONVERT_FORMAT ("DVO_LENSING_PS1_V3",          PS1_V3,          PS1_V3);
     414// CONVERT_FORMAT ("DVO_LENSING_PS1_V4",          PS1_V4,          PS1_V4);
     415  CONVERT_FORMAT ("DVO_LENSING_PS1_V5",          PS1_V5,          PS1_V5);
     416# undef CONVERT_FORMAT
     417
     418  fprintf (stderr, "table format unknown: %s\n", extname);
     419
     420  *Nlensing = 0;
     421  return (NULL);
     422}
     423
     424// LensingToFtable needs the Average since old formats stored lensing.dR,dD only
     425int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format) {
     426
     427# define FORMAT_CASE(FORMAT, TYPE)              \
     428    case DVO_FORMAT_##FORMAT: { \
     429      Lensing_##TYPE *tmpLensing; \
     430      tmpLensing = LensingInternalTo_##TYPE (lensing, Nlensing); \
     431      gfits_table_set_Lensing_##TYPE (ftable, tmpLensing, Nlensing); \
     432      free (tmpLensing); \
     433      break; }
     434
     435  /* convert from the internal format */
     436  switch (format) {
     437    case DVO_FORMAT_INTERNAL: {
     438      gfits_table_set_Lensing (ftable, lensing, Nlensing);
     439      break; }
     440
     441//    FORMAT_CASE (PS1_REF,         PS1_REF);
     442//    FORMAT_CASE (ELIXIR,          Elixir);
     443//    FORMAT_CASE (LONEOS,          Loneos);
     444//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     445//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     446//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     447//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     448//    FORMAT_CASE (PS1_V1,          PS1_V1);
     449//    FORMAT_CASE (PS1_V2,          PS1_V2);
     450//    FORMAT_CASE (PS1_V3,          PS1_V3);
     451//    FORMAT_CASE (PS1_V4,          PS1_V4);
     452      FORMAT_CASE (PS1_V5,          PS1_V5);
     453# undef FORMAT_CASE
     454
     455    default:
     456      fprintf (stderr, "table format unknown (lensing)\n");
     457      return (FALSE);
     458  }
     459  return (TRUE);
     460}
     461
     462/*** Lensobj / FTable conversion functions ***/
     463
     464Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format) {
     465
     466  Lensobj *lensobj;
     467  char extname[80];
     468
     469  /* convert to the internal format */
     470  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     471    fprintf (stderr, "EXTNAME missing for lensobj table\n");
     472    return (FALSE);
     473  }
     474
     475# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     476  if (!strcmp (extname, NAME)) {                                        \
     477    Lensobj_##TYPE *tmpLensobj;                                         \
     478    tmpLensobj = gfits_table_get_Lensobj_##TYPE (ftable, Nlensobj, NULL); \
     479    if (!tmpLensobj) {                                                  \
     480      fprintf (stderr, "ERROR: failed to read lensobjs\n");             \
     481      exit (2);                                                         \
     482    }                                                                   \
     483    lensobj = Lensobj_##TYPE##_ToInternal (tmpLensobj, *Nlensobj); \
     484    free (tmpLensobj);                                                  \
     485    *format = DVO_FORMAT_##FORMAT;                                      \
     486    return (lensobj); }
     487
     488  if (!strcmp (extname, "DVO_LENSOBJ")) {
     489    lensobj = gfits_table_get_Lensobj (ftable, Nlensobj, NULL);
     490    if (!lensobj) {
     491      fprintf (stderr, "ERROR: failed to read lensobjs\n");
     492      exit (2);
     493    }
     494    *format = DVO_FORMAT_INTERNAL;
     495    return (lensobj);
     496  }
     497
     498// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_REF",         PS1_REF,         PS1_REF);
     499// CONVERT_FORMAT ("DVO_LENSOBJ_ELIXIR",          ELIXIR,          Elixir);
     500// CONVERT_FORMAT ("DVO_LENSOBJ_LONEOS",          LONEOS,          Loneos);
     501// CONVERT_FORMAT ("DVO_LENSOBJ_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     502// CONVERT_FORMAT ("DVO_LENSOBJ_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     503// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     504// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     505// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V1",          PS1_V1,          PS1_V1);
     506// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V2",          PS1_V2,          PS1_V2);
     507// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V3",          PS1_V3,          PS1_V3);
     508// CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V4",          PS1_V4,          PS1_V4);
     509  CONVERT_FORMAT ("DVO_LENSOBJ_PS1_V5",          PS1_V5,          PS1_V5);
     510# undef CONVERT_FORMAT
     511
     512  fprintf (stderr, "table format unknown: %s\n", extname);
     513
     514  *Nlensobj = 0;
     515  return (NULL);
     516}
     517
     518// LensobjToFtable needs the Average since old formats stored lensobj.dR,dD only
     519int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format) {
     520
     521# define FORMAT_CASE(FORMAT, TYPE)              \
     522    case DVO_FORMAT_##FORMAT: { \
     523      Lensobj_##TYPE *tmpLensobj; \
     524      tmpLensobj = LensobjInternalTo_##TYPE (lensobj, Nlensobj); \
     525      gfits_table_set_Lensobj_##TYPE (ftable, tmpLensobj, Nlensobj); \
     526      free (tmpLensobj); \
     527      break; }
     528
     529  /* convert from the internal format */
     530  switch (format) {
     531    case DVO_FORMAT_INTERNAL: {
     532      gfits_table_set_Lensobj (ftable, lensobj, Nlensobj);
     533      break; }
     534
     535//    FORMAT_CASE (PS1_REF,         PS1_REF);
     536//    FORMAT_CASE (ELIXIR,          Elixir);
     537//    FORMAT_CASE (LONEOS,          Loneos);
     538//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     539//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     540//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     541//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     542//    FORMAT_CASE (PS1_V1,          PS1_V1);
     543//    FORMAT_CASE (PS1_V2,          PS1_V2);
     544//    FORMAT_CASE (PS1_V3,          PS1_V3);
     545//    FORMAT_CASE (PS1_V4,          PS1_V4);
     546      FORMAT_CASE (PS1_V5,          PS1_V5);
     547# undef FORMAT_CASE
     548
     549    default:
     550      fprintf (stderr, "table format unknown (lensobj)\n");
    363551      return (FALSE);
    364552  }
  • branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r36917 r36918  
    407407}
    408408
    409 # if (0)
    410409Lensing *Lensing_PS1_V5_ToInternal (Lensing_PS1_V5 *in, off_t Nvalues) {
    411410
     
    616615  return (out);
    617616}
    618 # endif
    619617
    620618Image *Image_PS1_V5_ToInternal (Image_PS1_V5 *in, off_t Nvalues, off_t Nalloc) {
Note: See TracChangeset for help on using the changeset viewer.