Changeset 38062 for trunk/Ohana/src/opihi/cmd.data/rd.c
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
-
trunk/Ohana
- Property svn:mergeinfo deleted
-
trunk/Ohana/src/opihi/cmd.data/rd.c
r29938 r38062 4 4 int rd (int argc, char **argv) { 5 5 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]; 10 9 Buffer *buf; 11 10 12 JustHead = FALSE;11 int JustHead = FALSE; 13 12 if ((N = get_argument (argc, argv, "-head"))) { 14 13 remove_argument (N, &argc, argv); … … 16 15 } 17 16 18 plane =1;17 int plane = -1; 19 18 if ((N = get_argument (argc, argv, "-plane"))) { 20 19 remove_argument (N, &argc, argv); … … 23 22 } 24 23 25 extend = FALSE;26 Nextend = -1;24 int extend = FALSE; 25 int Nextend = -1; 27 26 if ((N = get_argument (argc, argv, "-x"))) { 28 27 remove_argument (N, &argc, argv); … … 32 31 } 33 32 34 ccdsel = FALSE;35 c cdid = (char *)NULL;33 int ccdsel = FALSE; 34 char *ccdid = NULL; 36 35 if ((N = get_argument (argc, argv, "-n"))) { 37 36 remove_argument (N, &argc, argv); … … 52 51 53 52 /* test if file exists */ 54 f = fopen (argv[2], "r");53 FILE *f = fopen (argv[2], "r"); 55 54 if (f == (FILE *) NULL) { 56 55 gprint (GP_ERR, "file %s not found\n", argv[2]); … … 67 66 68 67 /* save file name */ 69 filename = filebasename (argv[2]);68 char *filename = filebasename (argv[2]); 70 69 strcpy (buf[0].file, filename); 71 70 free (filename); 72 71 73 status = FALSE;74 IsCompressed = FALSE;72 int status = FALSE; 73 int IsCompressed = FALSE; 75 74 76 75 /*** advance to the correct FITS extension ***/ … … 168 167 169 168 /* 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 } 177 179 } 178 180 179 181 /* load matrix data */ 180 182 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 } 181 189 FTable ftable; 182 190 Header theader; … … 191 199 // XXX this currently does not work for a cube (we get a cube back, not a specific plane) 192 200 } 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 } 195 212 } 196 213 fclose (f); … … 200 217 DeleteBuffer (buf); 201 218 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);210 219 } 211 220 … … 215 224 buf[0].header.Naxis[1] = 1; 216 225 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); 217 228 } 218 229
Note:
See TracChangeset
for help on using the changeset viewer.
