IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 13, 2006, 12:15:05 PM (19 years ago)
Author:
Paul Price
Message:

Adding functions to read/write tables within the FPA hierarchy (specifically, in the analysis metadata within the cell) from/to FITS files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPARead.c

    r9599 r9949  
    614614}
    615615
     616
     617int pmCellReadTable(pmCell *cell, psFits *fits, const char *name)
     618{
     619    PS_ASSERT_PTR_NON_NULL(cell, 0);
     620    PS_ASSERT_PTR_NON_NULL(fits, 0);
     621    PS_ASSERT_STRING_NON_EMPTY(name, 0);
     622
     623    const char *chipName = psMetadataLookupStr(NULL, cell->parent->concepts, "CHIP.NAME"); // Name of chip
     624    const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell
     625    psString extname = NULL;            // Extension name
     626    psStringAppend(&extname, "%s_%s_%s", name, chipName, cellName);
     627
     628    // XXX Could do a table lookup from the camera format, in case the input file isn't laid out with
     629    // NAME_CHIP_CELL extension names --- use these as keys, and the value as the proper extension name.
     630    // Allow interpolation of concepts, e.g., "{CHIP.NAME}" --> "ccd13".
     631
     632    if (!psFitsMoveExtName(fits, extname)) {
     633        psError(PS_ERR_IO, false, "Unable to move to extension %s\n", extname);
     634        psFree(extname);
     635        return 0;
     636    }
     637
     638    psMetadata *header = psFitsReadHeader(NULL, fits); // The FITS header
     639    if (!header) {
     640        psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", extname);
     641        psFree(extname);
     642        psFree(header);
     643        return 0;
     644    }
     645
     646    psString headerName = NULL;         // Name for header
     647    psStringAppend(&headerName, "%s.HEADER", name);
     648    if (!psMetadataAdd(cell->analysis, PS_LIST_TAIL, headerName, PS_DATA_METADATA,
     649                       "FITS table header", header)) {
     650        psError(PS_ERR_UNKNOWN, false, "Unable to add header from extension %s to analysis metadata "
     651                "for chip %s, cell %s\n", extname, chipName, cellName);
     652        psFree(headerName);
     653        psFree(header);
     654        psFree(extname);
     655        return 0;
     656    }
     657    psFree(headerName);
     658    psFree(header);
     659
     660    psArray *table = psFitsReadTable(fits); // The table
     661    if (!psMetadataAdd(cell->analysis, PS_LIST_TAIL, name, PS_DATA_ARRAY, "FITS table", table)) {
     662        psError(PS_ERR_UNKNOWN, false, "Unable to add table from extension %s to analysis metadata "
     663                "for chip %s, cell %s\n", extname, chipName, cellName);
     664        psFree(table);
     665        psFree(extname);
     666        return 0;
     667    }
     668
     669    psFree(extname);
     670    psFree(table);                      // Dropping reference
     671
     672    return 1;
     673}
     674
     675
     676int pmChipReadTable(pmChip *chip, psFits *fits, const char *name)
     677{
     678    PS_ASSERT_PTR_NON_NULL(chip, 0);
     679    PS_ASSERT_PTR_NON_NULL(fits, 0);
     680    PS_ASSERT_STRING_NON_EMPTY(name, 0);
     681
     682    int numRead = 0;                    // Number of reads
     683    psArray *cells = chip->cells;       // Array of cells
     684    for (int i = 0; i < cells->n; i++) {
     685        pmCell *cell = cells->data[i];  // Cell of interest
     686        numRead += pmCellReadTable(cell, fits, name);
     687    }
     688
     689    return numRead;
     690}
     691
     692
     693int pmFPAReadTable(pmFPA *fpa, psFits *fits, const char *name)
     694{
     695    PS_ASSERT_PTR_NON_NULL(fpa, 0);
     696    PS_ASSERT_PTR_NON_NULL(fits, 0);
     697    PS_ASSERT_STRING_NON_EMPTY(name, 0);
     698
     699    int numRead = 0;                    // Number of reads
     700    psArray *chips = fpa->chips;        // Array of chips
     701    for (int i = 0; i < chips->n; i++) {
     702        pmChip *chip = chips->data[i];  // Chip of interest
     703        numRead += pmChipReadTable(chip, fits, name);
     704    }
     705
     706    return numRead;
     707}
Note: See TracChangeset for help on using the changeset viewer.