Changeset 38441 for trunk/Ohana/src/opihi/cmd.data/read_vectors.c
- Timestamp:
- Jun 12, 2015, 6:18:23 PM (11 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
src/opihi/cmd.data (modified) (1 prop)
-
src/opihi/cmd.data/read_vectors.c (modified) (11 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/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 }
Note:
See TracChangeset
for help on using the changeset viewer.
