IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 6, 2007, 5:09:52 PM (19 years ago)
Author:
eugene
Message:

merging changes from eam_branch_20071015 (read compressed images, clean addstar I/O, other minor issues)

File:
1 edited

Legend:

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

    r13479 r15487  
    55 
    66  int i, N, status, plane, Nplane, extend, Nextend, Nskip, JustHead;
    7   int ccdsel, done;
     7  int ccdsel, done, Nword, IsCompressed;
    88  char region[512], *ccdid, *filename;
    99  FILE *f;
     
    8585      return (FALSE);
    8686    }
     87    if (gfits_extension_is_compressed (&buf[0].header)) {
     88        IsCompressed = TRUE;
     89    }
    8790  }
     91
    8892  /* FITS extension by name */
    8993  if (ccdsel) {
     
    9296    CCDKeyword = get_variable ("CCDKEYWORD");
    9397    if (CCDKeyword == (char *) NULL) {
    94       gprint (GP_ERR, "CCDKEYWORD variable is not set; ");
    95       gprint (GP_ERR, "using EXTNAME as default\n");
     98      // gprint (GP_ERR, "CCDKEYWORD variable is not set; ");
     99      // gprint (GP_ERR, "using EXTNAME as default\n");
    96100      CCDKeyword = strcreate ("EXTNAME");
    97101    }
     
    106110        return (FALSE);
    107111      }
    108       if (!gfits_scan (&buf[0].header, CCDKeyword, "%s", 1, ID)) {
     112
     113      // for compressed data tables, EXTNAME may be duplicated, with the first one containing the
     114      // word 'COMPRESSED_IMAGE'.  in this case, check the second EXTNAME, if CCDKeyword == EXTNAME
     115      // this may have to be a more obscure test specifically for 'imcopy' data...
     116      // need to check each header, since file may contain a mix
     117     
     118      Nword = 1;
     119      IsCompressed = FALSE;
     120      if (gfits_extension_is_compressed (&buf[0].header)) {
     121        if (!strcmp (CCDKeyword, "EXTNAME")) Nword = 2;
     122        IsCompressed = TRUE;
     123      }
     124      if (!gfits_scan (&buf[0].header, CCDKeyword, "%s", Nword, ID)) {
    109125        gprint (GP_ERR, "%s not in header\n", CCDKeyword);
    110126        DeleteBuffer (buf);
     
    123139  /* fix up header, if needed */
    124140  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);
     141    if (!IsCompressed) {
     142      gfits_extended_to_primary (&buf[0].header, TRUE, "Standard FITS");
     143    }
    132144  } else {
    133145      gfits_fread_header (f, &buf[0].header);
     
    135147
    136148  /* for JustHead, we skip reading the data segment */
     149  // XXX for compressed data, we need to convert the header to the equivalent uncompressed version
    137150  if (JustHead) {
    138     /* should be in CreateMatrix / CreateBuffer function */
     151    // XXX what are we doing here exactly?
    139152    buf[0].header.Naxes = 0;
    140153    ALLOCATE (buf[0].matrix.buffer, char, 1);
     
    164177
    165178  /* 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);
     179  if (IsCompressed) {
     180    FTable ftable;
     181    Header theader;
     182    ftable.header = &theader;
     183    gfits_copy_header (&buf[0].header, ftable.header);
     184    status = gfits_fread_ftable_data (f, &ftable);  // XXX does this do more than read the bytes?
     185    status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable, !(ccdsel || extend));
     186    gfits_free_table (&ftable);
     187    // XXX this currently does not work for a cube (we get a cube back, not a specific plane)
     188  } else {
     189    sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane);
     190    status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region);
     191    fclose (f);
     192  }
    169193
    170194  if (!status) {
Note: See TracChangeset for help on using the changeset viewer.