IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2015, 6:52:41 AM (11 years ago)
Author:
eugene
Message:

merge changes from ipp-20150112

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Ohana

    • Property svn:mergeinfo deleted
  • trunk/Ohana/src/opihi/cmd.data/rd.c

    r29938 r38062  
    44int rd (int argc, char **argv) {
    55 
    6   int i, N, status, plane, Nplane, extend, Nextend, Nskip, JustHead, blank;
    7   int ccdsel, done, Nword, IsCompressed;
    8   char region[512], *ccdid, *filename;
    9   FILE *f;
     6  int i, N, Nskip, blank;
     7  int done, Nword;
     8  char region[512];
    109  Buffer *buf;
    1110
    12   JustHead = FALSE;
     11  int JustHead = FALSE;
    1312  if ((N = get_argument (argc, argv, "-head"))) {
    1413    remove_argument (N, &argc, argv);
     
    1615  }
    1716
    18   plane = 1;
     17  int plane = -1;
    1918  if ((N = get_argument (argc, argv, "-plane"))) {
    2019    remove_argument (N, &argc, argv);
     
    2322  }
    2423
    25   extend = FALSE;
    26   Nextend = -1;
     24  int extend = FALSE;
     25  int Nextend = -1;
    2726  if ((N = get_argument (argc, argv, "-x"))) {
    2827    remove_argument (N, &argc, argv);
     
    3231  }
    3332
    34   ccdsel = FALSE;
    35   ccdid = (char *) NULL;
     33  int ccdsel = FALSE;
     34  char *ccdid = NULL;
    3635  if ((N = get_argument (argc, argv, "-n"))) {
    3736    remove_argument (N, &argc, argv);
     
    5251
    5352  /* test if file exists */
    54   f = fopen (argv[2], "r");
     53  FILE *f = fopen (argv[2], "r");
    5554  if (f == (FILE *) NULL) {
    5655    gprint (GP_ERR, "file %s not found\n", argv[2]);
     
    6766
    6867  /* save file name */
    69   filename = filebasename (argv[2]);
     68  char *filename = filebasename (argv[2]);
    7069  strcpy (buf[0].file, filename);
    7170  free (filename);
    7271
    73   status = FALSE;
    74   IsCompressed = FALSE;
     72  int status = FALSE;
     73  int IsCompressed = FALSE;
    7574
    7675  /*** advance to the correct FITS extension ***/
     
    168167
    169168  /* check for valid plane */
    170   Nplane = buf[0].header.Naxis[2];
    171   if (Nplane == 0) Nplane = 1;
    172   if (plane > Nplane) {
    173     gprint (GP_ERR, "-plane is too large: %d total planes\n", Nplane);
    174     DeleteBuffer (buf);
    175     fclose (f);
    176     return (FALSE);
     169  int Nz = buf[0].header.Naxis[2];
     170  if (plane >= 0) {
     171    // we are requesting a specific plane (-1 : all data)
     172    int tooFar = Nz ? (plane >= Nz) : (plane > Nz);
     173    if (tooFar) {
     174      gprint (GP_ERR, "-plane is too large: %d total planes\n", Nz);
     175      DeleteBuffer (buf);
     176      fclose (f);
     177      return (FALSE);
     178    }
    177179  }
    178180
    179181  /* load matrix data */
    180182  if (IsCompressed) {
     183    if (plane > -1) {
     184      gprint (GP_ERR, "-plane incompatible with compressed image\n");
     185      DeleteBuffer (buf);
     186      fclose (f);
     187      return (FALSE);
     188    }
    181189    FTable ftable;
    182190    Header theader;
     
    191199    // XXX this currently does not work for a cube (we get a cube back, not a specific plane)
    192200  } else {
    193     sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane);
    194     status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region);
     201    if (plane > -1) {
     202      // read a single plane into a 2D image
     203      sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane);
     204      status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region);
     205      buf[0].header.Naxis[2] = 0;
     206      buf[0].header.Naxes = 2;
     207      gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2);
     208      gfits_modify (&buf[0].header, "NAXIS3", "%d", 1, 0);
     209    } else {
     210      status = gfits_fread_matrix (f, &buf[0].matrix, &buf[0].header);
     211    }
    195212  }
    196213  fclose (f);
     
    200217    DeleteBuffer (buf);
    201218    return (FALSE);
    202   }
    203 
    204   /* adjust buffer to represent 2D data */
    205   if (Nplane > 1) {
    206     buf[0].header.Naxis[2] = 0;
    207     buf[0].header.Naxes = 2;
    208     gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2);
    209     gfits_delete (&buf[0].header, "NAXIS3", 1);
    210219  }
    211220
     
    215224    buf[0].header.Naxis[1] = 1;
    216225    buf[0].matrix.Naxis[1] = 1;
     226    gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2);
     227    gfits_modify (&buf[0].header, "NAXIS2", "%d", 1, 1);
    217228  }   
    218229
Note: See TracChangeset for help on using the changeset viewer.