IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 24, 2020, 3:19:09 PM (6 years ago)
Author:
eugene
Message:

adding string-type vectors to opihi

File:
1 edited

Legend:

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

    r41164 r41269  
    154154  if (ADD_HEADER) {
    155155    for (j = 0; j < Nvec; j++) {
     156      if (j == 0) fprintf (f, "# ");
    156157      if (CSV) {
    157158        fprintf (f, "%s,", vec[j][0].name);
    158159      } else {
    159         if (j == 0) fprintf (f, "# ");
    160160        fprintf (f, "%s ", vec[j][0].name);
    161161      }
     
    166166  /* default output format */
    167167  if (format == (char *) NULL) {
     168    char padChar = CSV ? ',' : ' ';
    168169    for (i = 0; i < vec[0][0].Nelements; i++) {
    169170      for (j = 0; j < Nvec; j++) {
    170         if (vec[j][0].type == OPIHI_FLT) {
    171           if (CSV) {
    172             fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]);
    173           } else {
    174             fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]);
    175           }
    176         } else {
    177           if (CSV) {
    178             fprintf (f, OPIHI_INT_FMT",", vec[j][0].elements.Int[i]);
    179           } else {
    180             fprintf (f, OPIHI_INT_FMT" ", vec[j][0].elements.Int[i]);
    181           }
     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;
    182181        }
    183182      }
     
    226225        fmttype[j] = 'd';
    227226        break;
     227      case 's':
     228        fmttype[j] = 's';
     229        break;
    228230      default:
    229         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");
    230232        return (FALSE);
    231233    }
     
    234236  strcat (fmtlist[Nvec-1], p0);
    235237 
     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
    236257  for (i = 0; i < vec[0][0].Nelements; i++) {
    237258    for (j = 0; j < Nvec; j++) {
     
    249270          fprintf (f, fmtlist[j], (opihi_flt)(vec[j][0].elements.Int[i]));
    250271        }
     272      }
     273      if (fmttype[j] == 's') {
     274        fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]);
    251275      }
    252276    }
Note: See TracChangeset for help on using the changeset viewer.