IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 23, 2007, 10:45:20 AM (19 years ago)
Author:
eugene
Message:

updates and additions to enable reading compressed fits images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20071015/Ohana/src/opihi/cmd.data/rd.c

    r13479 r15353  
    8686    }
    8787  }
     88
    8889  /* FITS extension by name */
    8990  if (ccdsel) {
     
    9293    CCDKeyword = get_variable ("CCDKEYWORD");
    9394    if (CCDKeyword == (char *) NULL) {
    94       gprint (GP_ERR, "CCDKEYWORD variable is not set; ");
    95       gprint (GP_ERR, "using EXTNAME as default\n");
     95      // gprint (GP_ERR, "CCDKEYWORD variable is not set; ");
     96      // gprint (GP_ERR, "using EXTNAME as default\n");
    9697      CCDKeyword = strcreate ("EXTNAME");
    9798    }
     
    106107        return (FALSE);
    107108      }
    108       if (!gfits_scan (&buf[0].header, CCDKeyword, "%s", 1, ID)) {
     109
     110      // for compressed data tables, EXTNAME may be duplicated, with the first one containing the
     111      // word 'COMPRESSED_IMAGE'.  in this case, check the second EXTNAME, if CCDKeyword == EXTNAME
     112      // this may have to be a more obscure test specifically for 'imcopy' data...
     113      // need to check each header, since file may contain a mix
     114     
     115      Nword = 1;
     116      IsCompressed = FALSE;
     117      if (gfits_extension_is_compressed_data (&buf[0].header)) {
     118        if (!strcmp (CCDKeyword, "EXTNAME")) Nword = 2;
     119        IsCompressed = TRUE;
     120      }
     121      if (!gfits_scan (&buf[0].header, CCDKeyword, "%s", Nword, ID)) {
    109122        gprint (GP_ERR, "%s not in header\n", CCDKeyword);
    110123        DeleteBuffer (buf);
     
    123136  /* fix up header, if needed */
    124137  if (extend || ccdsel) {
    125     static char simple[] = "SIMPLE  =                    T / Standard FITS";
    126     int Ns, No;
    127 
    128     Ns = strlen (simple);
    129     No = 80 - Ns;
    130     strncpy (buf[0].header.buffer, simple, Ns);
    131     memset (&buf[0].header.buffer[Ns], ' ', No);
     138    if (!IsCompressed) {
     139      gfits_extended_to_primary (buf[0].header, TRUE, "Standard FITS");
     140    }
    132141  } else {
    133142      gfits_fread_header (f, &buf[0].header);
     
    135144
    136145  /* for JustHead, we skip reading the data segment */
     146  // XXX for compressed data, we need to convert the header to the equivalent uncompressed version
    137147  if (JustHead) {
    138     /* should be in CreateMatrix / CreateBuffer function */
     148    // XXX what are we doing here exactly?
    139149    buf[0].header.Naxes = 0;
    140150    ALLOCATE (buf[0].matrix.buffer, char, 1);
     
    164174
    165175  /* load matrix data */
    166   sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane);
    167   status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region);
    168   fclose (f);
     176  if (IsCompressed) {
     177    FTable ftable;
     178    Header theader;
     179    ftable.header = &theader;
     180    gfits_copy_header (&buf[0].header, ftable.header);
     181    status = gfits_fread_table (f, &ftable);  // XXX does this do more than read the bytes?
     182    status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, ftable, ccdsel || extend);
     183    gfits_free_table (&ftable);
     184    // XXX this currently does not work for a cube (we get a cube back, not a specific plane)
     185  } else {
     186    sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane);
     187    status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region);
     188    fclose (f);
     189  }
    169190
    170191  if (!status) {
Note: See TracChangeset for help on using the changeset viewer.