- Timestamp:
- Feb 4, 2016, 5:04:49 PM (10 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 2 edited
-
cmd.basic/list.c (modified) (13 diffs)
-
cmd.data/read_vectors.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.basic/list.c
r38972 r39328 93 93 set_str_variable (line, argv[i+3]); 94 94 } 95 s printf (line, "%s:n", argv[1]);95 snprintf (line, 1024, "%s:n", argv[1]); 96 96 set_int_variable (line, i); 97 98 return (TRUE); 99 } 100 101 // return an error if -add is given with no other args 102 if ((argc > 2) && (!strcmp (argv[2], "-join"))) { 103 if (argc != 4) { 104 gprint (GP_ERR, "USAGE: list (root) -join (variable)\n"); 105 return (FALSE); 106 } 107 108 int isFound; 109 110 snprintf (line, 1024, "%s:n", argv[1]); 111 int nList = get_int_variable (line, &isFound); 112 if (!isFound) { 113 gprint (GP_ERR, "list %s not found\n", argv[1]); 114 return FALSE; 115 } 116 117 char tmpline[1024], output[1024]; 118 memset (tmpline, 0, 1024); 119 memset (output, 0, 1024); 120 121 for (i = 0; i < nList; i++) { 122 snprintf (line, 1024, "%s:%d", argv[1], i); 123 char *word = get_variable (line); 124 if (!word) break; 125 if (i > 0) { 126 snprintf (output, 1024, "%s %s", tmpline, word); 127 } else { 128 snprintf (output, 1024, "%s", word); 129 } 130 strcpy (tmpline, output); 131 } 132 set_str_variable (argv[3], output); 97 133 98 134 return (TRUE); … … 118 154 119 155 // old list must exist, or give an error 120 s printf (line, "%s:n", argv[3]);156 snprintf (line, 1024, "%s:n", argv[3]); 121 157 N = get_int_variable (line, &found); 122 158 if (!found) { … … 127 163 128 164 129 s printf (line, "%s:n", argv[1]);165 snprintf (line, 1024, "%s:n", argv[1]); 130 166 set_int_variable (line, N); 131 167 for (i = 0; i < N; i++) { 132 s printf (line, "%s:%d", argv[3], i);168 snprintf (line, 1024, "%s:%d", argv[3], i); 133 169 value = get_variable (line); 134 // s printf (line, "%s:%d", argv[1], i);170 // snprintf (line, 1024, "%s:%d", argv[1], i); 135 171 set_list_varname (line, argv[1], i, EXCEL_STYLE); 136 172 set_str_variable (line, value); … … 146 182 } 147 183 148 s printf (line, "%s:n", argv[1]);184 snprintf (line, 1024, "%s:n", argv[1]); 149 185 N = get_int_variable (line, &found); 150 186 for (i = 0; i < argc - 3; i++) { 151 // s printf (line, "%s:%d", argv[1], N + i);187 // snprintf (line, 1024, "%s:%d", argv[1], N + i); 152 188 set_list_varname (line, argv[1], N + i, EXCEL_STYLE); 153 189 set_str_variable (line, argv[i+3]); 154 190 } 155 s printf (line, "%s:n", argv[1]);191 snprintf (line, 1024, "%s:n", argv[1]); 156 192 set_int_variable (line, N + i); 157 193 … … 170 206 char line2[1024]; 171 207 172 s printf (line, "%s:n", argv[1]);208 snprintf (line, 1024, "%s:n", argv[1]); 173 209 N = get_int_variable (line, &found); 174 210 for (i = 0; i < N; i++) { 175 // s printf (line, "%s:%d", argv[1], i);211 // snprintf (line, 1024, "%s:%d", argv[1], i); 176 212 set_list_varname (line, argv[1], i, EXCEL_STYLE); 177 213 value = get_variable (line); … … 180 216 free (value); 181 217 for (j = i + 1; j < N; j++) { 182 // s printf (line2, "%s:%d", argv[1], j);218 // snprintf (line, 10242, "%s:%d", argv[1], j); 183 219 set_list_varname (line2, argv[1], j, EXCEL_STYLE); 184 220 next_value = get_variable (line2); … … 187 223 } 188 224 DeleteNamedScalar (line); 189 s printf (line2, "%s:n", argv[1]);225 snprintf (line, 10242, "%s:n", argv[1]); 190 226 set_int_variable (line2, N - 1); 191 227 return (TRUE); … … 238 274 depth --; 239 275 if (depth < 0) { /* we hit the last "END", loop is done */ 240 s printf (line, "%s:n", argv[1]);276 snprintf (line, 1024, "%s:n", argv[1]); 241 277 set_int_variable (line, i); 242 278 free (input); … … 246 282 247 283 if (*input) { 248 // s printf (line, "%s:%d", argv[1], i);284 // snprintf (line, 1024, "%s:%d", argv[1], i); 249 285 set_list_varname (line, argv[1], i, EXCEL_STYLE); 250 286 set_str_variable (line, input); … … 310 346 free (val); 311 347 312 s printf (line, "%s:n", listname);348 snprintf (line, 1024, "%s:n", listname); 313 349 set_int_variable (line, i); 314 350 return (TRUE); … … 328 364 // otherwise save all glob matches 329 365 if (globList.gl_pathc == 0) { 330 s printf (line, "%s:n", listname);366 snprintf (line, 1024, "%s:n", listname); 331 367 set_int_variable (line, 0); 332 368 return TRUE; … … 338 374 set_str_variable (line, globList.gl_pathv[i]); 339 375 } 340 s printf (line, "%s:n", listname);376 snprintf (line, 1024, "%s:n", listname); 341 377 set_int_variable (line, Nfile); 342 378 return (TRUE); … … 371 407 FREE (new); 372 408 } 373 s printf (line, "%s:n", argv[1]);409 snprintf (line, 1024, "%s:n", argv[1]); 374 410 set_int_variable (line, nWords); 375 411 -
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.
