Changeset 38441 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Jun 12, 2015, 6:18:23 PM (11 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 9 edited
-
. (modified) (1 prop)
-
src/opihi/cmd.data (modified) (1 prop)
-
src/opihi/cmd.data/cast.c (modified) (4 diffs)
-
src/opihi/cmd.data/rd.c (modified) (5 diffs)
-
src/opihi/cmd.data/read_vectors.c (modified) (11 diffs)
-
src/opihi/cmd.data/tv.c (modified) (1 diff)
-
src/opihi/cmd.data/vstats.c (modified) (1 diff)
-
src/opihi/cmd.data/wd.c (modified) (7 diffs)
-
src/opihi/cmd.data/write_vectors.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/ohana.20150429 merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/opihi/cmd.data
- Property svn:mergeinfo changed
/branches/eam_branches/ohana.20150429/src/opihi/cmd.data (added) merged: 38330,38336,38338,38340-38341,38363,38367,38406,38410,38424,38440
- Property svn:mergeinfo changed
-
trunk/Ohana/src/opihi/cmd.data/cast.c
r36489 r38441 17 17 // out type 18 18 char outType = OPIHI_NOTYPE; 19 if (!strcasecmp(argv[5], "int")) outType = OPIHI_INT; 20 if (!strcasecmp(argv[5], "float")) outType = OPIHI_FLT; 19 if (!strcasecmp(argv[5], "int")) outType = OPIHI_INT; 20 if (!strcasecmp(argv[5], "float")) outType = OPIHI_FLT; 21 if (!strcasecmp(argv[5], "single")) outType = OPIHI_FLT; 22 if (!strcasecmp(argv[5], "int64")) outType = OPIHI_FLT; 21 23 if (outType == OPIHI_NOTYPE) goto usage; 24 25 int ForceSingle = FALSE; 26 if (!strcasecmp(argv[5], "single")) ForceSingle = TRUE; 27 28 int ForceI64 = FALSE; 29 if (!strcasecmp(argv[5], "int64")) ForceI64 = TRUE; 22 30 23 31 if ((ovec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto error; … … 32 40 opihi_flt *vo = ovec[0].elements.Flt; 33 41 for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) { 34 *vo = *vi; 42 if (ForceSingle) { 43 float tmp = *vi; 44 *vo = tmp; 45 } else if (ForceI64) { 46 int64_t tmp = *vi; 47 *vo = tmp; 48 } else { 49 *vo = *vi; 50 } 35 51 } 36 52 return (TRUE); … … 48 64 opihi_flt *vo = ovec[0].elements.Flt; 49 65 for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) { 50 *vo = *vi; 66 if (ForceSingle) { 67 float tmp = *vi; 68 *vo = tmp; 69 } else { 70 *vo = *vi; 71 } 51 72 } 52 73 return (TRUE); … … 66 87 67 88 usage: 68 gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float)\n"); 89 gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float/single)\n"); 90 gprint (GP_ERR, " note: (single) forces vector to have single precision\n"); 69 91 return (FALSE); 70 92 } -
trunk/Ohana/src/opihi/cmd.data/rd.c
r38255 r38441 9 9 Buffer *buf; 10 10 11 int VERBOSE = FALSE; 12 if ((N = get_argument (argc, argv, "-v"))) { 13 remove_argument (N, &argc, argv); 14 VERBOSE = TRUE; 15 } 16 11 17 int JustHead = FALSE; 12 18 if ((N = get_argument (argc, argv, "-head"))) { … … 91 97 return (FALSE); 92 98 } 93 if (gfits_extension_is_compressed (&buf[0].header)) {99 if (gfits_extension_is_compressed_image (&buf[0].header)) { 94 100 IsCompressed = TRUE; 95 101 } … … 124 130 Nword = 1; 125 131 IsCompressed = FALSE; 126 if (gfits_extension_is_compressed (&buf[0].header)) {132 if (gfits_extension_is_compressed_image (&buf[0].header)) { 127 133 if (!strcmp (CCDKeyword, "EXTNAME")) Nword = 1; 128 134 IsCompressed = TRUE; … … 198 204 ftable.header[0].buffer = NULL; 199 205 gfits_copy_header (&buf[0].header, ftable.header); 200 status = gfits_fread_ftable_data (f, &ftable, FALSE); // this just reads the bytes (not even a SWAP) 201 status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable); 206 207 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { gprint (GP_ERR, "problem reading compressed image table data\n"); fclose (f); return FALSE; } 208 if (!gfits_byteswap_varlength_column (&ftable, 1)) { gprint (GP_ERR, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; } 209 if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { gprint (GP_ERR, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; } 210 202 211 // uncompressing the image leaves the format as an extension 203 212 gfits_extended_to_primary (&buf[0].header, TRUE, "Standard FITS"); 204 213 gfits_free_table (&ftable); 214 215 status = TRUE; 205 216 // XXX this currently does not work for a cube (we get a cube back, not a specific plane) 206 217 } else { … … 239 250 buf[0].unsign = buf[0].header.unsign; 240 251 241 gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", 242 buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]); 252 if (VERBOSE) gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]); 243 253 244 254 blank = 0xffff; -
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r38062 r38441 1 1 # include "data.h" 2 int dump_raw_table (FTable *table, char *message); 3 int dump_cmp_table (FTable *table, char *message); 2 4 3 5 FILE *f = (FILE *) NULL; … … 412 414 table.header = &header; 413 415 414 /* load appropriate extension (if extname is a number, use count)*/416 /**** find the appropriate extension and read header (if extname is a number, use count) ****/ 415 417 if (Nextend > -1) { 416 418 // first extension is PHU, cannot be a table. … … 429 431 } 430 432 if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend); 431 432 if (getSizes) {433 read_table_sizes (&header);434 if (CCDKeyword != NULL) free (CCDKeyword);435 gfits_free_header (&header);436 return TRUE;437 }438 439 if (Nrows == -1) {440 Nrows = header.Naxis[1] - start;441 }442 if (start < 0) ESCAPE ("invalid range: start < 0\n");443 if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);444 if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");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 }450 451 // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100452 // Ny = 100, start = 10, Nrows = 90453 454 if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);455 433 } else { 456 434 if (CCDKeyword == NULL) { … … 460 438 CCDKeyword = strcreate ("EXTNAME"); 461 439 } 462 463 440 while (1) { 464 441 if (!gfits_load_header (f, &header)) { … … 469 446 return (TRUE); 470 447 } 471 472 448 Nbytes = gfits_data_size (&header); 473 449 … … 482 458 continue; 483 459 } 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 492 if (Nrows == -1) {493 Nrows = header.Naxis[1] - start;494 }495 if (start < 0) ESCAPE ("invalid range: start < 0\n");496 if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);497 if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");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 }503 504 if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);505 506 // if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");507 508 460 break; 509 461 } 462 } 463 464 int IsCompressed = gfits_extension_is_compressed_table (&header); 465 466 if (getSizes && !IsCompressed) { 467 read_table_sizes (&header); 468 if (CCDKeyword != NULL) free (CCDKeyword); 469 gfits_free_header (&header); 470 return TRUE; 471 } 472 if (IsCompressed) { 473 if (getSizes) { 474 gprint (GP_ERR, "%s[%s] is compressed: -sizes is invalid\n", filename, extname); 475 gfits_free_header (&header); 476 return FALSE; 477 } 478 if ((start > 0) || (Nrows > -1)) { 479 gprint (GP_ERR, "%s[%s] is compressed: must read entire table\n", filename, extname); 480 gfits_free_header (&header); 481 return FALSE; 482 } 483 } 484 485 if (Nrows == -1) { 486 Nrows = header.Naxis[1] - start; 487 } 488 if (start < 0) ESCAPE ("invalid range: start < 0\n"); 489 if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny ("OFF_T_FMT")\n", header.Naxis[1]); 490 if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n"); 491 492 // just a warning: 493 if (start + Nrows > header.Naxis[1]) { 494 if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only "OFF_T_FMT" rows\n", header.Naxis[1] - start); 495 } 496 497 // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100 498 // Ny = 100, start = 10, Nrows = 90 499 500 if (IsCompressed) { 501 if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension %d\n", Nextend); 502 } else { 503 if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend); 510 504 } 511 505 … … 518 512 Binary = !strcmp (type, "BINTABLE"); 519 513 Ny = header.Naxis[1]; 514 515 Header *outheader = &header; 516 FTable *outtable = &table; 517 518 Header rawheader; 519 FTable rawtable; 520 if (IsCompressed) { 521 rawtable.header = &rawheader; 522 523 dump_cmp_table (&table, "rd cmp"); 524 525 int Nfields; 526 if (!gfits_scan (&header, "TFIELDS", "%d", 1, &Nfields)) ESCAPE ("cannot find TFIELDS in header\n"); 527 for (i = 0; i < Nfields; i++) { 528 gfits_byteswap_varlength_column (&table, i+1); 529 } 530 if (!gfits_uncompress_table (&table, &rawtable)) ESCAPE ("failed to uncompress table\n"); 531 dump_raw_table (&rawtable, "rd raw"); 532 533 outheader = &rawheader; 534 outtable = &rawtable; 535 gfits_free_header (&header); 536 gfits_free_table (&table); 537 Ny = rawheader.Naxis[1]; 538 } 520 539 521 540 /* find columns which match requested vectors */ … … 527 546 Nval = 0; 528 547 if (Binary) { 529 if (!gfits_get_bintable_column_type ( &header, argv[i], type, &Nval)) ESCAPE ("requested field not found");530 if (!gfits_get_bintable_column (&header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");548 if (!gfits_get_bintable_column_type (outheader, argv[i], type, &Nval)) ESCAPE ("requested field not found\n"); 549 if (!gfits_get_bintable_column_raw (outheader, outtable, argv[i], &data, IsCompressed)) ESCAPE ("error reading data from specified field\n"); 531 550 } else { 532 if (!gfits_get_table_column_type ( &header, argv[i], type)) ESCAPE ("requested field not found");533 if (!gfits_get_table_column ( &header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");534 } 535 if (Nval == 0) ESCAPE ("no data for field in table ");551 if (!gfits_get_table_column_type (outheader, argv[i], type)) ESCAPE ("requested field not found\n"); 552 if (!gfits_get_table_column (outheader, outtable, argv[i], &data)) ESCAPE ("error reading data from specified field\n"); 553 } 554 if (Nval == 0) ESCAPE ("no data for field in table\n"); 536 555 537 556 vecType = OPIHI_INT; 538 if (!strcmp (type, "double") || !strcmp (type, "float") ) {557 if (!strcmp (type, "double") || !strcmp (type, "float") || !strcmp (type, "int64_t")) { 539 558 vecType = OPIHI_FLT; 540 559 } … … 570 589 else 571 590 sprintf (name, "%s:%d", argv[i], j); 572 if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name ");591 if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n"); 573 592 ResetVector (vec[j], vecType, Ny); 574 593 } 575 594 576 if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s ", type);595 if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type); 577 596 578 597 } else { … … 584 603 else 585 604 sprintf (name, "%s:%d", argv[i], j); 586 if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name ");605 if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n"); 587 606 ResetVector (vec[j], vecType, Nval); 588 607 } 589 608 590 if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s ", type);609 if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s\n", type); 591 610 } 592 611 free (data); … … 594 613 } 595 614 if (CCDKeyword != NULL) free (CCDKeyword); 596 gfits_free_table ( &table);597 gfits_free_header ( &header);615 gfits_free_table (outtable); 616 gfits_free_header (outheader); 598 617 return (TRUE); 599 618 } -
trunk/Ohana/src/opihi/cmd.data/tv.c
r38062 r38441 71 71 int tooBig = buf[0].matrix.Naxis[2] ? (plane >= buf[0].matrix.Naxis[2]) : plane > 0; 72 72 if (tooBig) { 73 gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs %d)\n", plane, buf[0].matrix.Naxis[2]);73 gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs "OFF_T_FMT")\n", plane, buf[0].matrix.Naxis[2]); 74 74 return (FALSE); 75 75 } -
trunk/Ohana/src/opihi/cmd.data/vstats.c
r35109 r38441 121 121 goto skip; 122 122 } 123 // we can hit inf if pmax and pmin are close to the max range 124 if (isinf(dx)) dx = DBL_MAX / Nbin; 123 125 124 126 ALLOCATE (Nval, int, Nbin + 2); -
trunk/Ohana/src/opihi/cmd.data/wd.c
r38062 r38441 18 18 } 19 19 20 char *CompressMode = NULL; 21 if ((N = get_argument (argc, argv, "-compress-mode"))) { 22 remove_argument (N, &argc, argv); 23 CompressMode = strcreate(argv[N]); 24 remove_argument (N, &argc, argv); 25 } else if ((N = get_argument (argc, argv, "-compress"))) { 26 remove_argument (N, &argc, argv); 27 CompressMode = strcreate("GZIP_1"); 28 } 29 20 30 outZero = 0; 21 31 newZero = FALSE; … … 54 64 if (outUnsign == -1) { 55 65 gprint (GP_ERR, "-unsign options: t, f, true, false\n"); 66 FREE (CompressMode); 56 67 return (FALSE); 57 68 } … … 62 73 if (argc != 3) { 63 74 gprint (GP_ERR, "USAGE: wd <buffer> <filename> [-bitpix N] [-bscale X] [-bzero X] [-extend] [-newplane]\n"); 75 FREE (CompressMode); 64 76 return (FALSE); 65 77 } 66 78 67 if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);79 if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) { FREE (CompressMode); return (FALSE); } 68 80 69 81 if (!newBitpix) outBitpix = buf[0].bitpix; … … 159 171 gfits_free_header (&temp_header); 160 172 gfits_free_matrix (&temp_matrix); 173 FREE (CompressMode); 161 174 return (status); 162 175 } 163 176 177 // not compatible with extend 178 if (CompressMode) { 179 Header myHeader; 180 Matrix myMatrix; 181 182 FILE *f = fopen (argv[2], "w"); 183 if (!f) { 184 fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", argv[2]); 185 FREE (CompressMode); 186 return FALSE; 187 } 188 189 gfits_init_header (&myHeader); 190 myHeader.extend = TRUE; 191 gfits_create_header (&myHeader); 192 gfits_create_matrix (&myHeader, &myMatrix); 193 gfits_fwrite_header (f, &myHeader); 194 gfits_fwrite_matrix (f, &myMatrix); 195 gfits_free_header (&myHeader); 196 gfits_free_matrix (&myMatrix); 197 198 FTable ftable; 199 Header theader; 200 201 ftable.header = &theader; 202 203 gfits_compress_image (&temp_header, &temp_matrix, &ftable, NULL, CompressMode); 204 gfits_byteswap_varlength_column (&ftable, 1); 205 gfits_fwrite_Theader (f, &theader); 206 gfits_fwrite_table (f, &ftable); 207 fclose (f); 208 209 gfits_free_header (&theader); 210 gfits_free_table (&ftable); 211 FREE (CompressMode); 212 return (TRUE); 213 } 214 164 215 /* the actual write-to-disk goes here */ 165 216 if (!gfits_write_header (argv[2], &temp_header)) { … … 167 218 gfits_free_header (&temp_header); 168 219 gfits_free_matrix (&temp_matrix); 220 FREE (CompressMode); 169 221 return (FALSE); 170 222 } … … 174 226 gfits_free_header (&temp_header); 175 227 gfits_free_matrix (&temp_matrix); 228 FREE (CompressMode); 176 229 return (FALSE); 177 230 } … … 180 233 gfits_free_matrix (&temp_matrix); 181 234 235 FREE (CompressMode); 182 236 return (TRUE); 183 237 } -
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r35109 r38441 3 3 int write_vectors (int argc, char **argv) { 4 4 5 int append;6 5 int i, j, Nvec, Ne, N; 7 6 FILE *f; 8 7 char **fmtlist, *fmttype; 9 char *p0, *p1, *p2, *format , *FITS;8 char *p0, *p1, *p2, *format; 10 9 Vector **vec; 11 10 … … 34 33 35 34 /* option generate a FITS output table */ 36 FITS = NULL;35 char *FITS = NULL; 37 36 if ((N = get_argument (argc, argv, "-fits"))) { 38 37 remove_argument (N, &argc, argv); … … 58 57 } 59 58 60 append = FALSE;59 int append = FALSE; 61 60 if ((N = get_argument (argc, argv, "-append"))) { 62 61 remove_argument (N, &argc, argv); 63 62 append = TRUE; 63 } 64 65 char *compress = NULL; 66 if ((N = get_argument (argc, argv, "-compress-mode"))) { 67 remove_argument (N, &argc, argv); 68 compress = strcreate(argv[N]); 69 remove_argument (N, &argc, argv); 70 } else if ((N = get_argument (argc, argv, "-compress"))) { 71 remove_argument (N, &argc, argv); 72 compress = strcreate("GZIP_1"); 73 if (!FITS) { 74 fprintf (stderr, "NOTE: write_vectors -compress has no effect on non-FITS\n"); 75 } 64 76 } 65 77 … … 105 117 106 118 if (FITS) { 107 int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, format);119 int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format); 108 120 free (vec); 109 121 return status; … … 243 255 gprint (GP_ERR, " -csv : write a comma-separated values file (eg, to read in excel)\n"); 244 256 gprint (GP_ERR, " -f \"format\" : provide formatting codes for output:\n"); 245 gprint (GP_ERR, " ascii / csv : format consists of c-style format codes in form % NN.Md\n");257 gprint (GP_ERR, " ascii / csv : format consists of c-style format codes in form %%NN.Md\n"); 246 258 gprint (GP_ERR, ", the following codes are allowed\n"); 247 gprint (GP_ERR, " % e -- double,%f -- float\n");248 gprint (GP_ERR, " % d -- int, %c -- char,%x -- hex int\n");259 gprint (GP_ERR, " %%e -- double, %%f -- float\n"); 260 gprint (GP_ERR, " %%d -- int, %%c -- char, %%x -- hex int\n"); 249 261 gprint (GP_ERR, " FITS : format consists of the following FITS binary table format codes:\n"); 250 262 gprint (GP_ERR, " B : 1 byte int\n");
Note:
See TracChangeset
for help on using the changeset viewer.
