Changeset 39328 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Feb 4, 2016, 5:04:49 PM (10 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/read_vectors.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r39227 r39328 8 8 void read_vectors_cleanup (); 9 9 int read_table_sizes (Header *header); 10 int read_table_fields (Header *header, int isCompressed, int VERBOSE); 11 void list_extnames (void); 10 12 11 13 int datafile (int argc, char **argv) { … … 87 89 gprint (GP_ERR, " for time, values are human-readable date/time strings YYYY/MM/DD,hh:mm:ss\n"); 88 90 gprint (GP_ERR, " the resulting vector is a float based on the TIMEFORMAT, TIMEREF values\n"); 91 92 gprint (GP_ERR, " -fits options:\n"); 93 gprint (GP_ERR, " -transpose : read rows as columns and vice-versa\n"); 94 95 gprint (GP_ERR, " -keyword (FIELD) : use FIELD to identify the extension (default: EXTNAME)\n"); 96 gprint (GP_ERR, " -pad-if-short : allow reading of broken files by padding missing data\n"); 97 gprint (GP_ERR, " -sizes : return a list of table size information ($table:Nx, $table:Ny, $table:$Nfields) \n"); 98 gprint (GP_ERR, " -list-fields : return a list of table columns ($tfields:0 to $tfields:n) (use -v to see the list)\n"); 99 gprint (GP_ERR, " -extnum (N) : use the number to find the Nth extension (ignore EXTNAME)\n"); 100 gprint (GP_ERR, " -range (start) (Nrows) : read the specified portion of the file\n"); 101 gprint (GP_ERR, " -v : verbose \n"); 102 gprint (GP_ERR, " -char-vectors : char fields will be saved as vectors NAME:0 -- NAME:n for n characters \n"); 103 89 104 return (FALSE); 90 105 } … … 393 408 } 394 409 410 int listFields = FALSE; 411 if ((N = get_argument (argc, argv, "-list-fields"))) { 412 remove_argument (N, &argc, argv); 413 listFields = TRUE; 414 } 415 395 416 int Nextend = -1; 396 417 if ((N = get_argument (argc, argv, "-extnum"))) { … … 432 453 // } 433 454 434 if ((argc < 2) && !getSizes) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...\n"); 435 if ((argc != 1) && getSizes) ESCAPE ("USAGE: read -sizes -fits extension [-extnum] (does not read data values)\n"); 455 int listExtnames = FALSE; 456 if (!strcmp(extname, "-list")) { 457 listExtnames = TRUE; 458 } 459 460 if ((argc < 2) && !getSizes && !listFields && !listExtnames) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...\n"); 461 if ((argc != 1) && getSizes) ESCAPE ("USAGE: read -sizes -fits extension [-extnum] (does not read data values)\n"); 462 if ((argc != 1) && listFields) ESCAPE ("USAGE: read -list-fields -fits extension [-extnum] (does not read data values)\n"); 463 if ((argc != 1) && listExtnames) ESCAPE ("USAGE: read -list-fields -fits extension [-extnum] (does not read data values)\n"); 436 464 437 465 if (f == NULL) ESCAPE ("file not found\n"); 438 466 fseeko (f, 0LL, SEEK_SET); 439 467 table.header = &header; 468 469 if (listExtnames) { 470 list_extnames (); 471 return TRUE; 472 } 440 473 441 474 /**** find the appropriate extension and read header (if extname is a number, use count) ****/ … … 491 524 if (getSizes && !IsCompressed) { 492 525 read_table_sizes (&header); 526 if (CCDKeyword != NULL) free (CCDKeyword); 527 gfits_free_header (&header); 528 return TRUE; 529 } 530 if (listFields) { 531 read_table_fields (&header, IsCompressed, VERBOSE); 493 532 if (CCDKeyword != NULL) free (CCDKeyword); 494 533 gfits_free_header (&header); … … 676 715 } 677 716 717 // read -fits foo -sizes -- Nx, Ny, Nfields -> $table:Nx, $table:Ny, $table:$Nfields 718 // read -fits foo -fields 719 720 int read_table_fields (Header *header, int isCompressed, int VERBOSE) { 721 722 int i, Nfields; 723 char field[32], varname[32], type[80], comment[80], format[80], unit[80], null[80], nval[80]; 724 725 gfits_scan (header, "TFIELDS", "%d", 1, &Nfields); 726 727 set_int_variable ("table:Nx", header->Naxis[0]); 728 set_int_variable ("table:Ny", header->Naxis[1]); 729 set_int_variable ("table:Nfields", Nfields); 730 set_int_variable ("tfields:n", Nfields); 731 732 for (i = 1; i <= Nfields; i++) { 733 memset (field, 0, 32); 734 memset (type, 0, 80); 735 memset (comment, 0, 80); 736 memset (format, 0, 80); 737 memset (unit, 0, 80); 738 memset (null, 0, 80); 739 memset (nval, 0, 80); 740 741 snprintf (field, 32, "TTYPE%d", i); 742 gfits_scan (header, field, "%s", 1, type); 743 744 snprintf (varname, 32, "tfields:%d", i - 1); 745 set_str_variable (varname, type); 746 747 gfits_scan_alt (header, field, "%C", 1, comment); 748 749 if (!isCompressed) { 750 snprintf (field, 32, "TFORM%d", i); 751 } else { 752 snprintf (field, 32, "ZFORM%d", i); 753 } 754 gfits_scan (header, field, "%s", 1, format); 755 756 snprintf (field, 32, "TUNIT%d", i); 757 gfits_scan (header, field, "%s", 1, unit); 758 snprintf (field, 32, "TNULL%d", i); 759 if (!gfits_scan (header, field, "%s", 1, null)) strcpy (null, "none"); 760 snprintf (field, 32, "TNVAL%d", i); 761 if (!gfits_scan (header, field, "%s", 1, nval)) strcpy (nval, "none"); 762 763 if (VERBOSE) gprint (GP_LOG, "%-18s %-18s %-6s %-8s %-8s %-32s\n", type, unit, format, null, nval, comment); 764 } 765 766 767 return TRUE; 768 } 769 770 void list_extnames (void) { 771 772 off_t Nbytes, Nelem; 773 int i, Naxis, Ncomp, extend, status; 774 char extname[82], exttype[82], axisname[32]; 775 Header header; 776 777 fseeko (f, 0, SEEK_SET); 778 779 gprint (GP_LOG, "%-30s %-15s NAXIS NAXIS(i)...\n", "extname", "datatype"); 780 781 Ncomp = 0; 782 while (gfits_fread_header (f, &header)) { 783 /* extract the EXTNAME for this component (set to PHU for 0th component) */ 784 status = gfits_scan (&header, "EXTNAME", "%s", 1, extname); 785 if (!status) { 786 if (Ncomp == 0) { 787 strcpy (extname, "PHU"); 788 } else { 789 strcpy (extname, "UNKNOWN"); 790 } 791 } 792 gprint (GP_LOG, "%-30s ", extname); 793 794 /* extract the datatype for this component (IMAGE for 0th component) */ 795 if (Ncomp == 0) { 796 strcpy (exttype, "IMAGE"); 797 } else { 798 status = gfits_scan (&header, "XTENSION", "%s", 1, exttype); 799 if (!status) { 800 strcpy (exttype, "UNKNOWN"); 801 } 802 } 803 gprint (GP_LOG, "%-15s ", exttype); 804 805 /* extract the rank of the component */ 806 status = gfits_scan (&header, "NAXIS", "%d", 1, &Naxis); 807 if (!status) { 808 gprint (GP_ERR, "component %d is missing Naxis!\n", Ncomp); 809 Ncomp ++; 810 continue; 811 } 812 gprint (GP_LOG, " %4d", Naxis); 813 814 /* extract the individual axes */ 815 for (i = 0; i < Naxis; i++) { 816 sprintf (axisname, "NAXIS%d", i+1); 817 status = gfits_scan (&header, axisname, OFF_T_FMT, 1, &Nelem); 818 if (!status) { 819 gprint (GP_ERR, "missing %s\n", axisname); 820 } 821 gprint (GP_LOG, " "OFF_T_FMT, Nelem); 822 } 823 gprint (GP_LOG, "\n"); 824 825 /* are extensions identified? (we will scan for them anyway) */ 826 if (Ncomp == 0) { 827 extend = FALSE; 828 gfits_scan_alt (&header, "EXTEND", "%t", 1, &extend); 829 if (!extend) { 830 gprint (GP_ERR, "no extensions listed in file\n"); 831 } 832 } 833 834 Nbytes = gfits_data_size (&header); 835 fseeko (f, Nbytes, SEEK_CUR); 836 837 Ncomp ++; 838 } 839 return; 840 }
Note:
See TracChangeset
for help on using the changeset viewer.
