Changeset 38062 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Mar 29, 2015, 6:52:41 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
- 3 copied
-
. (modified) (1 prop)
-
Ohana (modified) (1 prop)
-
Ohana/src/opihi/cmd.data/Makefile (modified) (3 diffs)
-
Ohana/src/opihi/cmd.data/init.c (modified) (6 diffs)
-
Ohana/src/opihi/cmd.data/interpolate.c (modified) (3 diffs)
-
Ohana/src/opihi/cmd.data/mcreate.c (modified) (1 diff)
-
Ohana/src/opihi/cmd.data/mget3d.c (copied) (copied from branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/mget3d.c )
-
Ohana/src/opihi/cmd.data/rd.c (modified) (10 diffs)
-
Ohana/src/opihi/cmd.data/read_vectors.c (modified) (6 diffs)
-
Ohana/src/opihi/cmd.data/squash3d.c (copied) (copied from branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/squash3d.c )
-
Ohana/src/opihi/cmd.data/tdhistogram.c (copied) (copied from branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/tdhistogram.c )
-
Ohana/src/opihi/cmd.data/tv.c (modified) (2 diffs)
-
Ohana/src/opihi/cmd.data/wd.c (modified) (1 diff)
-
Ohana/src/opihi/cmd.data/zplot.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
-
trunk/Ohana
- Property svn:mergeinfo deleted
-
trunk/Ohana/src/opihi/cmd.data/Makefile
r37807 r38062 61 61 $(SRC)/ungridify.$(ARCH).o \ 62 62 $(SRC)/histogram.$(ARCH).o \ 63 $(SRC)/tdhistogram.$(ARCH).o \ 63 64 $(SRC)/hermitian1d.$(ARCH).o \ 64 65 $(SRC)/hermitian2d.$(ARCH).o \ … … 89 90 $(SRC)/medacc.$(ARCH).o \ 90 91 $(SRC)/mget.$(ARCH).o \ 92 $(SRC)/mget3d.$(ARCH).o \ 91 93 $(SRC)/minterpolate.$(ARCH).o \ 92 94 $(SRC)/medimage.$(ARCH).o \ … … 130 132 $(SRC)/imspline_apply.$(ARCH).o \ 131 133 $(SRC)/imspline_construct.$(ARCH).o \ 134 $(SRC)/squash3d.$(ARCH).o \ 132 135 $(SRC)/imstats.$(ARCH).o \ 133 136 $(SRC)/style.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/init.c
r37807 r38062 51 51 int ungridify PROTO((int, char **)); 52 52 int histogram PROTO((int, char **)); 53 int tdhistogram PROTO((int, char **)); 53 54 int hermitian1d PROTO((int, char **)); 54 55 int hermitian2d PROTO((int, char **)); … … 80 81 int medacc PROTO((int, char **)); 81 82 int mget PROTO((int, char **)); 83 int mget3d PROTO((int, char **)); 82 84 int minterp PROTO((int, char **)); 83 85 int medimage_command PROTO((int, char **)); … … 117 119 int imspline_apply PROTO((int, char **)); 118 120 int imspline_construct PROTO((int, char **)); 121 int squash3d PROTO((int, char **)); 119 122 int stats PROTO((int, char **)); 120 123 int imstats PROTO((int, char **)); … … 217 220 {1, "header", header, "print image header"}, 218 221 {1, "histogram", histogram, "generate histogram from vector"}, 222 {1, "tdhistogram", tdhistogram, "generate 2D histogram image from vector set"}, 219 223 {1, "hermitian1d", hermitian1d, "generate 1-D Hermitian Polynomial"}, 220 224 {1, "hermitian2d", hermitian2d, "generate 2-D Hermitian Polynomial"}, … … 243 247 {1, "medacc", medacc, "accumulate vector values in another vector"}, 244 248 {1, "mget", mget, "extract a vector from an image"}, 249 {1, "mget3d", mget3d, "extract a vector from a 3D image"}, 245 250 {1, "imget", mget, "extract a vector from an image"}, 246 251 {1, "minterp", minterp, "interpolate image pixels"}, … … 289 294 {1, "imspline.apply", imspline_apply, "apply spline fit to generate an image"}, 290 295 {1, "imspline.const", imspline_construct, "create spline 2nd deriv. terms"}, 296 {1, "squash3d", squash3d, "squash 3d buffer to 2d"}, 291 297 {1, "stats", imstats, "statistics on a portion of an image"}, 292 298 {1, "style", style, "set the style for graph plots"}, -
trunk/Ohana/src/opihi/cmd.data/interpolate.c
r20936 r38062 1 1 # include "data.h" 2 2 3 // XXX use 'threshold' to interpolate to a value 3 4 int interpolate (int argc, char **argv) { 4 5 … … 11 12 gprint (GP_ERR, "USAGE: interpolate Xi Yi Xo Yo\n"); 12 13 gprint (GP_ERR, " Xi Yi - sorted reference vectors\n"); 13 gprint (GP_ERR, " Xo - output positions\n"); 14 gprint (GP_ERR, " Yo - output values\n"); 14 gprint (GP_ERR, " Xo - output positions (vector)\n"); 15 gprint (GP_ERR, " Yo - output values (vector)\n"); 16 gprint (GP_ERR, " (use 'threshold' to interpolate to a value)\n"); 15 17 return (FALSE); 16 18 } … … 18 20 if ((xin = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 19 21 if ((yin = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE); 22 23 // target positions are a vector 20 24 if ((xout = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE); 21 25 if ((yout = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); -
trunk/Ohana/src/opihi/cmd.data/mcreate.c
r9275 r38062 3 3 int mcreate (int argc, char **argv) { 4 4 5 int N x, Ny;5 int N; 6 6 Buffer *buf; 7 7 8 int Nz = 0; 9 if ((N = get_argument (argc, argv, "-nz"))) { 10 remove_argument (N, &argc, argv); 11 Nz = atoi (argv[N]); 12 remove_argument (N, &argc, argv); 13 } 14 8 15 if (argc != 4) { 9 gprint (GP_ERR, "USAGE: mcreate <buffer> Nx Ny \n");16 gprint (GP_ERR, "USAGE: mcreate <buffer> Nx Ny [-nz Nz]\n"); 10 17 return (FALSE); 11 18 } 12 19 13 20 if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) return (FALSE); 14 Nx = atof (argv[2]);15 Ny = atof (argv[3]);21 int Nx = atof (argv[2]); 22 int Ny = atof (argv[3]); 16 23 17 24 /* I should encapsulate this in a create_default_buffer */ 18 25 gfits_free_matrix (&buf[0].matrix); 19 26 gfits_free_header (&buf[0].header); 20 CreateBuffer (buf, Nx, Ny, -32, 1.0, 0.0); 27 28 if (Nz) { 29 CreateBuffer3D (buf, Nx, Ny, Nz, -32, 1.0, 0.0); 30 } else { 31 CreateBuffer (buf, Nx, Ny, -32, 1.0, 0.0); 32 } 21 33 return (TRUE); 22 34 } -
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 -
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r37807 r38062 372 372 } 373 373 374 int VERBOSE = FALSE; 375 if ((N = get_argument (argc, argv, "-v"))) { 376 remove_argument (N, &argc, argv); 377 VERBOSE = TRUE; 378 } 379 374 380 int start = 0; 375 381 int Nrows = -1; // -1 : read entire table … … 399 405 // } 400 406 401 if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...\n"); 407 if ((argc < 2) && !getSizes) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...\n"); 408 if ((argc != 1) && getSizes) ESCAPE ("USAGE: read -sizes -fits extension [-extnum] (does not read data values)\n"); 402 409 403 410 if (f == NULL) ESCAPE ("file not found\n"); … … 436 443 if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]); 437 444 if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n"); 438 if (start + Nrows > header.Naxis[1]) ESCAPE ("invalid range: start + Nrows > Ny (%d)\n", header.Naxis[1]); 445 446 // just a warning: 447 if (start + Nrows > header.Naxis[1]) { 448 if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start); 449 } 439 450 440 451 // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100 … … 472 483 } 473 484 485 if (getSizes) { 486 read_table_sizes (&header); 487 if (CCDKeyword != NULL) free (CCDKeyword); 488 gfits_free_header (&header); 489 return TRUE; 490 } 491 474 492 if (Nrows == -1) { 475 493 Nrows = header.Naxis[1] - start; … … 478 496 if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]); 479 497 if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n"); 480 if (start + Nrows > header.Naxis[1]) ESCAPE ("invalid range: start + Nrows > Ny (%d)\n", header.Naxis[1]); 498 499 // just a warning: 500 if (start + Nrows > header.Naxis[1]) { 501 if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start); 502 } 481 503 482 504 if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend); … … 603 625 604 626 set_int_variable ("table:Nx", header->Naxis[0]); 605 set_int_variable ("table:N x", header->Naxis[0]);627 set_int_variable ("table:Ny", header->Naxis[1]); 606 628 set_int_variable ("table:Nfields", Nfields); 607 629 -
trunk/Ohana/src/opihi/cmd.data/tv.c
r37807 r38062 28 28 } 29 29 30 int plane = 0; 31 if ((N = get_argument (argc, argv, "-plane"))) { 32 remove_argument (N, &argc, argv); 33 plane = atoi (argv[N]); 34 remove_argument (N, &argc, argv); 35 } 36 if (plane < 0) { 37 gprint (GP_ERR, " ERROR: -plane (plane) : cannot be negative\n"); 38 return (FALSE); 39 } 40 30 41 /* shell exits on pipe close, FIX */ 31 42 if ((N = get_argument (argc, argv, "-kill"))) { … … 55 66 GetCoords (&coords, &buf[0].header); 56 67 57 image.data1d = (float *) buf[0].matrix.buffer;58 68 image.Nx = buf[0].matrix.Naxis[0]; 59 69 image.Ny = buf[0].matrix.Naxis[1]; 70 71 int tooBig = buf[0].matrix.Naxis[2] ? (plane >= buf[0].matrix.Naxis[2]) : plane > 0; 72 if (tooBig) { 73 gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs %d)\n", plane, buf[0].matrix.Naxis[2]); 74 return (FALSE); 75 } 76 int Npix2D = image.Nx * image.Ny; 77 78 float *imdata = (float *) buf[0].matrix.buffer; 79 image.data1d = &imdata[plane*Npix2D]; 60 80 61 81 // send only the root of the file, not the full path -
trunk/Ohana/src/opihi/cmd.data/wd.c
r27435 r38062 81 81 memcpy (temp_header.buffer, buf[0].header.buffer, temp_header.datasize); 82 82 83 if (temp_header.Naxes) { 84 // the inBlank value probably does not matter: temp_matrix is float, so nan is used 85 gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, 0xffff, outUnsign); 86 } else { 87 gfits_modify (&temp_header, "BITPIX", "%d", 1, outBitpix); 88 gfits_modify (&temp_header, "BSCALE", "%lf", 1, outScale); 89 gfits_modify (&temp_header, "BZERO", "%lf", 1, outZero); 90 gfits_modify_alt (&temp_header, "UNSIGN", "%t", 1, outUnsign); 91 } 83 gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, 0xffff, outUnsign); 92 84 85 // Extend puts the output matrix in the first available non-PHU slot (ie, the last one) 86 // it updates NEXTEND and set EXTEND to TRUE, and modifies the PHU header (neither should happen) 87 // if those keywords do not exist... 93 88 if (Extend) { 94 89 Header Xhead; -
trunk/Ohana/src/opihi/cmd.data/zplot.c
r34613 r38062 4 4 5 5 char *outname = NULL; 6 int i, kapa, valid, size;6 int i, N, kapa, valid, size; 7 7 opihi_flt *out; 8 8 double min, range; 9 9 Graphdata graphmode; 10 Vector *xvec, *yvec, *zvec, Zvec;10 Vector *xvec, *yvec, *zvec, *dxmvec, *dxpvec, *dymvec, *dypvec, Zvec; 11 11 12 12 if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE); 13 14 /* decide on error bars */ 15 dxmvec = dxpvec = dymvec = dypvec = NULL; 16 if ((N = get_argument (argc, argv, "-dx"))) { 17 remove_argument (N, &argc, argv); 18 if ((dxmvec = SelectVector (argv[N], OLDVECTOR, TRUE)) == NULL) return (FALSE); 19 remove_argument (N, &argc, argv); 20 } 21 if ((N = get_argument (argc, argv, "+dx"))) { 22 remove_argument (N, &argc, argv); 23 if ((dxpvec = SelectVector (argv[N], OLDVECTOR, TRUE)) == NULL) return (FALSE); 24 remove_argument (N, &argc, argv); 25 } 26 if ((N = get_argument (argc, argv, "-dy"))) { 27 remove_argument (N, &argc, argv); 28 if ((dymvec = SelectVector (argv[N], OLDVECTOR, TRUE)) == NULL) return (FALSE); 29 remove_argument (N, &argc, argv); 30 } 31 if ((N = get_argument (argc, argv, "+dy"))) { 32 remove_argument (N, &argc, argv); 33 if ((dypvec = SelectVector (argv[N], OLDVECTOR, TRUE)) == NULL) return (FALSE); 34 remove_argument (N, &argc, argv); 35 } 13 36 14 37 valid = (argc == 6); … … 40 63 } 41 64 65 /* set errorbar mode (these are NOT sticky) */ 66 graphmode.etype = 0; 67 if ((dymvec != NULL) && (dypvec == NULL)) dypvec = dymvec; 68 if ((dypvec != NULL) && (dymvec == NULL)) dymvec = dypvec; 69 if ((dypvec != NULL) || (dymvec != NULL)) graphmode.etype |= 0x01; 70 if ((dxmvec != NULL) && (dxpvec == NULL)) dxpvec = dxmvec; 71 if ((dxpvec != NULL) && (dxmvec == NULL)) dxmvec = dxpvec; 72 if ((dxpvec != NULL) || (dxmvec != NULL)) graphmode.etype |= 0x02; 73 42 74 /* find vectors */ 43 75 if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); … … 56 88 return (FALSE); 57 89 } 90 if (dypvec && (dypvec->Nelements != xvec->Nelements)) goto mismatch; 91 if (dymvec && (dymvec->Nelements != xvec->Nelements)) goto mismatch; 92 if (dxpvec && (dxpvec->Nelements != xvec->Nelements)) goto mismatch; 93 if (dxmvec && (dxmvec->Nelements != xvec->Nelements)) goto mismatch; 94 58 95 SetVector (&Zvec, OPIHI_FLT, zvec[0].Nelements); 59 96 out = Zvec.elements.Flt; 60 97 98 // note actual size is 3.3x plot -sz sizes. (DrawObjects.c:399) 61 99 if (zvec[0].type == OPIHI_FLT) { 62 100 opihi_flt *in = zvec[0].elements.Flt; … … 81 119 graphmode.style = 2; /* plot points */ 82 120 graphmode.size = -1; /* point size determined by Zvec */ 83 graphmode.etype = 0; /* no errorbars */84 121 PlotVectorTriplet (kapa, xvec, yvec, &Zvec, mask, &graphmode); 122 if (graphmode.etype & 0x01) { 123 PlotVectorSingle (kapa, dymvec, mask, "dym"); 124 PlotVectorSingle (kapa, dypvec, mask, "dyp"); 125 } 126 if (graphmode.etype & 0x02) { 127 PlotVectorSingle (kapa, dxmvec, mask, "dxm"); 128 PlotVectorSingle (kapa, dxpvec, mask, "dxp"); 129 } 85 130 86 131 free (Zvec.elements.Ptr); 87 132 if (mask) free (mask); 88 DeleteNamedVector (outname); 133 134 if (outname) { 135 DeleteNamedVector (outname); 136 free (outname); 137 } 89 138 90 139 return (TRUE); 91 140 141 mismatch: 142 gprint (GP_ERR, "error and data vector lengths are mismatched\n"); 143 if (outname) { 144 DeleteNamedVector (outname); 145 free (outname); 146 } 147 return (FALSE); 92 148 } 93 149
Note:
See TracChangeset
for help on using the changeset viewer.
