IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39463


Ignore:
Timestamp:
Mar 14, 2016, 1:37:09 PM (10 years ago)
Author:
eugene
Message:

make it easier to use -fits -list and -list-fields functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r39360 r39463  
    1010int read_table_sizes (Header *header);
    1111int read_table_fields (Header *header, int isCompressed, int VERBOSE);
    12 void list_extnames (void);
     12void list_extnames (int VERBOSE);
    1313
    1414int datafile (int argc, char **argv) {
     
    409409  }
    410410
     411  // note the order of -v -list-fields -q below:
     412  // VERBOSE = FALSE is the natural default, but if -list-fields is given,
     413  // VERBOSE = TRUE becomes the default.  this can be overridden by -q
     414  // but to make that sequence work, we need to test for those three
     415  // options in that order: -v -list-fields -q
     416  // this is also true for -list (listExtnames)
     417  int VERBOSE = FALSE;
     418  if ((N = get_argument (argc, argv, "-v"))) {
     419    remove_argument (N, &argc, argv);
     420    VERBOSE = TRUE;
     421  }
    411422  int listFields = FALSE;
    412423  if ((N = get_argument (argc, argv, "-list-fields"))) {
    413424    remove_argument (N, &argc, argv);
    414425    listFields = TRUE;
     426    VERBOSE = TRUE;
     427  }
     428  int listExtnames = FALSE;
     429  if (!strcmp(extname, "-list")) {
     430    listExtnames = TRUE;
     431    VERBOSE = TRUE;
     432  }
     433  if ((N = get_argument (argc, argv, "-q"))) {
     434    remove_argument (N, &argc, argv);
     435    VERBOSE = FALSE;
    415436  }
    416437
     
    419440    remove_argument (N, &argc, argv);
    420441    Nextend = atoi (extname);
    421   }
    422 
    423   int VERBOSE = FALSE;
    424   if ((N = get_argument (argc, argv, "-v"))) {
    425     remove_argument (N, &argc, argv);
    426     VERBOSE = TRUE;
    427442  }
    428443
     
    454469  // }
    455470
    456   int listExtnames = FALSE;
    457   if (!strcmp(extname, "-list")) {
    458     listExtnames = TRUE;
    459   }
    460 
    461471  if ((argc < 2) && !getSizes && !listFields && !listExtnames) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...\n");
    462472  if ((argc != 1) && getSizes)   ESCAPE ("USAGE: read -sizes -fits extension [-extnum] (does not read data values)\n");
     
    469479
    470480  if (listExtnames) {
    471     list_extnames ();
     481    list_extnames (VERBOSE);
    472482    return TRUE;
    473483  }
     
    764774    if (!gfits_scan (header, field, "%s", 1, nval)) strcpy (nval, "none");
    765775
    766     if (VERBOSE) gprint (GP_LOG, "%-18s %-18s %-6s %-8s %-8s %-32s\n", type, unit, format, null, nval, comment);
     776    if (VERBOSE) gprint (GP_LOG, "%-18s %-15s %-18s %-6s %-8s %-8s %-32s\n", type, varname, unit, format, null, nval, comment);
    767777  }
    768778
     
    771781}
    772782
    773 void list_extnames (void) {
     783void list_extnames (int VERBOSE) {
    774784
    775785  off_t Nbytes, Nelem;
    776786  int i, Naxis, Ncomp, extend, status;
    777   char extname[82], exttype[82], axisname[32];
     787  char extname[82], varname[32], exttype[82], axisname[32];
    778788  Header header;
    779789
    780790  fseeko (f, 0, SEEK_SET);
    781791
    782   gprint (GP_LOG, "%-30s %-15s NAXIS NAXIS(i)...\n", "extname", "datatype");
     792  if (VERBOSE) gprint (GP_LOG, "%-30s %-15s %-15s NAXIS NAXIS(i)...\n", "extname", "varname", "datatype");
    783793
    784794  Ncomp = 0;
     
    793803      }
    794804    }
    795     gprint (GP_LOG, "%-30s ", extname);
     805    if (VERBOSE) gprint (GP_LOG, "%-30s ", extname);
     806
     807    snprintf (varname, 32, "extname:%d", Ncomp);
     808    set_str_variable (varname, extname);
     809    if (VERBOSE) gprint (GP_LOG, "%-15s ", varname);
    796810
    797811    /* extract the datatype for this component (IMAGE for 0th component) */
     
    804818      }
    805819    }
    806     gprint (GP_LOG, "%-15s ", exttype);
     820    if (VERBOSE) gprint (GP_LOG, "%-15s ", exttype);
    807821
    808822    /* extract the rank of the component */
     
    813827      continue;
    814828    }
    815     gprint (GP_LOG, " %4d", Naxis);
     829    if (VERBOSE) gprint (GP_LOG, " %4d", Naxis);
    816830
    817831    /* extract the individual axes */
     
    822836        gprint (GP_ERR, "missing %s\n", axisname);
    823837      }
    824       gprint (GP_LOG, " "OFF_T_FMT,  Nelem);
    825     }
    826     gprint (GP_LOG, "\n");
     838      if (VERBOSE) gprint (GP_LOG, " "OFF_T_FMT,  Nelem);
     839    }
     840    if (VERBOSE) gprint (GP_LOG, "\n");
    827841
    828842    /* are extensions identified? (we will scan for them anyway) */
     
    840854    Ncomp ++;
    841855  }
     856  set_int_variable ("extname:n", Ncomp);
    842857  return;
    843858}
Note: See TracChangeset for help on using the changeset viewer.