IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2020, 2:04:27 PM (6 years ago)
Author:
tdeboer
Message:

quick undo

File:
1 edited

Legend:

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

    r41340 r41341  
    3232  }
    3333
    34   /* option generate a FITS output table */
     34  // option generate a FITS output table (FITS holds the filename)
     35  // in FITS output context, -header is interpretted as a buffer containing
     36  // header keywords to supplement the FITS table header
    3537  char *FITS = NULL;
     38  Header *fitsheader = NULL;
     39  Buffer *headbuffer = NULL;
    3640  if ((N = get_argument (argc, argv, "-fits"))) {
    3741    remove_argument (N, &argc, argv);
    3842    FITS = strcreate (argv[N]);
    3943    remove_argument (N, &argc, argv);
    40   }
    41 
     44
     45    if ((N = get_argument (argc, argv, "-header"))) {
     46      remove_argument (N, &argc, argv);
     47      if ((headbuffer = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE);
     48      fitsheader = &headbuffer->header;
     49      remove_argument (N, &argc, argv);
     50    }
     51  }
     52 
    4253  /* option generate a FITS output table */
    4354  int CSV = FALSE;
     
    124135
    125136  if (FITS) {
    126     int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format, Ntile);
     137    int status = WriteVectorTableFITS (argv[1], FITS, fitsheader, vec, Nvec, append, compress, format, Ntile);
    127138    free (vec);
    128139    return status;
     
    143154  if (ADD_HEADER) {
    144155    for (j = 0; j < Nvec; j++) {
     156      if (j == 0) fprintf (f, "# ");
    145157      if (CSV) {
    146158        fprintf (f, "%s,", vec[j][0].name);
    147159      } else {
    148         if (j == 0) fprintf (f, "# ");
    149160        fprintf (f, "%s ", vec[j][0].name);
    150161      }
     
    155166  /* default output format */
    156167  if (format == (char *) NULL) {
     168    char padChar = CSV ? ',' : ' ';
    157169    for (i = 0; i < vec[0][0].Nelements; i++) {
    158170      for (j = 0; j < Nvec; j++) {
    159         if (vec[j][0].type == OPIHI_FLT) {
    160           if (CSV) {
    161             fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]);
    162           } else {
    163             fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]);
    164           }
    165         } else {
    166           if (CSV) {
    167             fprintf (f, OPIHI_INT_FMT",", vec[j][0].elements.Int[i]);
    168           } else {
    169             fprintf (f, OPIHI_INT_FMT" ", vec[j][0].elements.Int[i]);
    170           }
     171        switch (vec[j][0].type) {
     172          case OPIHI_FLT:
     173            fprintf (f, "%.12g%c", vec[j][0].elements.Flt[i], padChar);
     174            break;
     175          case OPIHI_INT:
     176            fprintf (f, OPIHI_INT_FMT"%c", vec[j][0].elements.Int[i], padChar);
     177            break;
     178          case OPIHI_STR:
     179            fprintf (f, "%s%c", vec[j][0].elements.Str[i], padChar);
     180            break;
    171181        }
    172182      }
     
    215225        fmttype[j] = 'd';
    216226        break;
     227      case 's':
     228        fmttype[j] = 's';
     229        break;
    217230      default:
    218         gprint (GP_ERR, "syntax error in format (only e,f,d,c,x allowed)\n");
     231        gprint (GP_ERR, "syntax error in format (only e,f,d,c,x,s allowed)\n");
    219232        return (FALSE);
    220233    }
     
    223236  strcat (fmtlist[Nvec-1], p0);
    224237 
     238  // check format types against vector types:
     239  for (j = 0; j < Nvec; j++) {
     240    switch (vec[j][0].type) {
     241      case OPIHI_FLT:
     242      case OPIHI_INT:
     243        if (fmttype[j] == 's') {
     244          gprint (GP_ERR, "mismatch between string format and numerical vector for %s\n", vec[j][0].name);
     245          return FALSE;
     246        }
     247        break;
     248      case OPIHI_STR:
     249        if (fmttype[j] != 's') {
     250          gprint (GP_ERR, "mismatch between numerical format and string vector for %s\n", vec[j][0].name);
     251          return FALSE;
     252        }
     253        break;
     254    }
     255  }
     256
    225257  for (i = 0; i < vec[0][0].Nelements; i++) {
    226258    for (j = 0; j < Nvec; j++) {
     
    239271        }
    240272      }
     273      if (fmttype[j] == 's') {
     274        fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]);
     275      }
    241276    }
    242277    fprintf (f, "\n");
     
    260295    gprint (GP_ERR, "  -append : write to the end of the existing file\n");
    261296    gprint (GP_ERR, "  -fits NAME : write a fits table (extention name is NAME, column names match vector names)\n");
     297    gprint (GP_ERR, "     in FITS output context, -header takes an additional argument which is interpretted\n");
     298    gprint (GP_ERR, "     as a buffer containing header keywords to supplement the FITS table header\n");
    262299    gprint (GP_ERR, "  -csv : write a comma-separated values file (eg, to read in excel)\n");
    263300    gprint (GP_ERR, "  -f \"format\" : provide formatting codes for output:\n");
Note: See TracChangeset for help on using the changeset viewer.