IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 1, 2012, 3:24:39 PM (14 years ago)
Author:
eugene
Message:

support for parallel dvo in mextract, avextract, avmerge, gstar, gcat; remove some if-def-ed out code already moved to libdvo; list -vectors and -buffers options (store names of vectors and buffers in lists); list -copy give error if missing source; catlist, hosts & remote functions to support parallel dvos; skyregion -save option; new skycoverage modes (-min-ubercal; -min-dmag-sys; -min-mcal; -max-mcal); gstar output formatting cleanups; add more average info to gstar output; functions for spectral similarity analysis; coords returns nans for projections off the sphere; fix cumulative function; add name:type option to opihi/read function (eg read a:float 2 b:time 3 c:int 4); line -frac option; vtype function to get vector types; threshold function; write -fits option; code for unfinished mtype function (matching vtype)

Location:
trunk/Ohana/src/opihi/cmd.data
Files:
13 edited
6 copied

Legend:

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

    r31635 r33662  
    123123$(SRC)/swapbytes.$(ARCH).o         \
    124124$(SRC)/textline.$(ARCH).o          \
     125$(SRC)/threshold.$(ARCH).o              \
    125126$(SRC)/tv.$(ARCH).o                \
    126127$(SRC)/tvchannel.$(ARCH).o         \
  • trunk/Ohana/src/opihi/cmd.data/cumulative.c

    r20936 r33662  
    2323    opihi_flt *Vi = ivec[0].elements.Flt;
    2424    *Vo = *Vi;
     25    Vi++;
     26    Vo++;
    2527    for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) {
    2628      *Vo = Vo[-1] + *Vi;
     
    2931    opihi_int *Vi = ivec[0].elements.Int;
    3032    *Vo = *Vi;
     33    Vi++;
     34    Vo++;
    3135    for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) {
    3236      *Vo = Vo[-1] + *Vi;
  • trunk/Ohana/src/opihi/cmd.data/cursor.c

    r31635 r33662  
    44
    55  char string[20], key[20], *name;
    6   int i, N, kapa;
     6  int i, N, kapa, VERBOSE;
    77  double X, Y, R, D, Z;
    88  void *oldsignal;
     
    1313  // if ((N = get_argument (argc, argv, "-g"))) {
    1414  // if ((N = get_argument (argc, argv, "-i"))) {
     15
     16  VERBOSE = TRUE;
     17  if ((N = get_argument (argc, argv, "-a"))) {
     18    VERBOSE = FALSE;
     19  }
    1520
    1621  name = NULL;
     
    5358    set_str_variable ("KEY", key);
    5459   
    55     gprint (GP_LOG, "%s %f %f %f %f %f\n", key, X, Y, Z, R, D);
     60    if (VERBOSE) gprint (GP_LOG, "%s %f %f %f %f %f\n", key, X, Y, Z, R, D);
    5661
    5762    if (!strcasecmp (key, "Q")) break;
  • trunk/Ohana/src/opihi/cmd.data/cut.c

    r20936 r33662  
    4848  case 'X':
    4949    /* create output vectors */
    50     ResetVector (xvec, OPIHI_FLT, MAX (nx, 1));
    51     ResetVector (yvec, OPIHI_FLT, MAX (nx, 1));
     50    ResetVector (xvec, OPIHI_FLT, nx);
     51    ResetVector (yvec, OPIHI_FLT, nx);
    5252    bzero (yvec[0].elements.Flt, nx*sizeof(opihi_flt));
    5353    for (i = 0; i < nx; i++) {
     
    8080  case 'y':
    8181  case 'Y':
    82     ResetVector (xvec, OPIHI_FLT, MAX (ny, 1));
    83     ResetVector (yvec, OPIHI_FLT, MAX (ny, 1));
     82    ResetVector (xvec, OPIHI_FLT, ny);
     83    ResetVector (yvec, OPIHI_FLT, ny);
    8484    bzero (yvec[0].elements.Flt, ny*sizeof(opihi_flt));
    8585    for (i = 0; i < ny; i++) {
  • trunk/Ohana/src/opihi/cmd.data/imcut.c

    r20936 r33662  
    3737  dY = dY / L;
    3838
    39   ResetVector (xvec, OPIHI_FLT, MAX (L, 1));
    40   ResetVector (yvec, OPIHI_FLT, MAX (L, 1));
     39  ResetVector (xvec, OPIHI_FLT, L);
     40  ResetVector (yvec, OPIHI_FLT, L);
    4141
    4242  V = (float *)buf[0].matrix.buffer;
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r31667 r33662  
    6161int header           PROTO((int, char **));
    6262int list_vectors     PROTO((int, char **));
     63int vtype            PROTO((int, char **));
    6364int load             PROTO((int, char **));
    6465int lookup           PROTO((int, char **));
     
    111112int swapbytes        PROTO((int, char **));
    112113int textline         PROTO((int, char **));
     114int threshold        PROTO((int, char **));
    113115int tv               PROTO((int, char **));
    114116int tvchannel        PROTO((int, char **));
     
    138140int zplot            PROTO((int, char **));
    139141int zcplot            PROTO((int, char **));
     142
     143// ???
     144// int mtype            PROTO((int, char **));
     145//  {1, "mtype",        mtype,            "return the type of the defined buffer"},
    140146
    141147static Command cmds[] = { 
     
    257263  {1, "swapbytes",    swapbytes,        "byte swap thing"},
    258264  {1, "textline",     textline,         "write text line on graph"},
     265  {1, "threshold",    threshold,        "find (interpolate) location of transition"},
    259266  {1, "tv",           tv,               "display an image on the Kii window"},
    260267  {1, "tvchannel",    tvchannel,        "set the current tv channel"},
     
    269276  {1, "vclip",        vclip,            "clip values in a vector to be within a range"},
    270277  {1, "vectors",      list_vectors,     "list vectors"},
     278  {1, "vtype",        vtype,            "return the vector type (FLT or INT)"},
    271279  {1, "vgauss",       vgauss,           "fit a Gaussian to a vector"},
    272280  {1, "vellipse",     vellipse,         "fit a Ellipse to a vector pair"},
  • trunk/Ohana/src/opihi/cmd.data/line.c

    r13479 r33662  
    33int line (int argc, char **argv) {
    44 
    5   int kapa;
     5  int kapa, N;
    66  Graphdata graphmode;
    77  float x[2], y[2];
     8
     9  /* FracPositions uses coordinates of 0-1 relative to axis range */
     10  int FracPositions = FALSE;
     11  if ((N = get_argument (argc, argv, "-frac"))) {
     12    remove_argument (N, &argc, argv);
     13    FracPositions = TRUE;
     14  }
    815
    916  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
     
    1825  y[1] = atof(argv[5]);
    1926
     27  if (FracPositions) {
     28    x[0] =  x[0] * (graphmode.xmax - graphmode.xmin) + graphmode.xmin;
     29    y[0] =  y[0] * (graphmode.ymax - graphmode.ymin) + graphmode.ymin;
     30    x[1] =  x[1] * (graphmode.xmax - graphmode.xmin) + graphmode.xmin;
     31    y[1] =  y[1] * (graphmode.ymax - graphmode.ymin) + graphmode.ymin;
     32  }   
     33
    2034  /* set point style and errorbar mode (these are NOT sticky) */
    2135  graphmode.style = 0;
  • trunk/Ohana/src/opihi/cmd.data/list_buffers.c

    r2598 r33662  
    99
    1010}
     11
     12# if (0)
     13int mtype (int argc, char **argv) {
     14
     15  Variable = (char *) NULL;
     16  if ((N = get_argument (argc, argv, "-var"))) {
     17    remove_argument (N, &argc, argv);
     18    Variable = strcreate (argv[N]);
     19    remove_argument (N, &argc, argv);
     20  }
     21
     22  if (argc != 2) {
     23    gprint (GP_ERR, "USAGE: mtype (buffer) [-var out]\n");
     24    return (FALSE);
     25  }
     26
     27  Buffer *buf = SelectBuffer (argv[1], OLDBUFFER, FALSE);
     28  if (!buf) {
     29    gprint (GP_ERR, "unknown buffer %s\n", argv[1]);
     30    free (Variable);
     31    return FALSE;
     32  }
     33
     34  if (buf->type == OPIHI_FLT) {
     35    if (Variable) {
     36      set_str_variable (Variable, "FLT");
     37    } else {
     38      gprint (GP_LOG, "%s : FLT\n", argv[1]);
     39    }
     40  } else {
     41    if (Variable) {
     42      set_str_variable (Variable, "INT");
     43    } else {
     44      gprint (GP_LOG, "%s : INT\n", argv[1]);
     45    }
     46  }
     47  if (Variable) free (Variable);
     48
     49  return (TRUE);
     50}
     51# endif
  • trunk/Ohana/src/opihi/cmd.data/list_vectors.c

    r2598 r33662  
    77}
    88
     9int vtype (int argc, char **argv) {
     10
     11  int N;
     12
     13  char *Variable = (char *) NULL;
     14  if ((N = get_argument (argc, argv, "-var"))) {
     15    remove_argument (N, &argc, argv);
     16    Variable = strcreate (argv[N]);
     17    remove_argument (N, &argc, argv);
     18  }
     19
     20  if (argc != 2) {
     21    gprint (GP_ERR, "USAGE: vtype (vector) [-var out]\n");
     22    return (FALSE);
     23  }
     24
     25  Vector *vec = SelectVector (argv[1], OLDVECTOR, FALSE);
     26  if (!vec) {
     27    gprint (GP_ERR, "unknown vector %s\n", argv[1]);
     28    free (Variable);
     29    return FALSE;
     30  }
     31
     32  if (vec->type == OPIHI_FLT) {
     33    if (Variable) {
     34      set_str_variable (Variable, "FLT");
     35    } else {
     36      gprint (GP_LOG, "%s : FLT\n", argv[1]);
     37    }
     38  } else {
     39    if (Variable) {
     40      set_str_variable (Variable, "INT");
     41    } else {
     42      gprint (GP_LOG, "%s : INT\n", argv[1]);
     43    }
     44  }
     45  if (Variable) free (Variable);
     46
     47  return (TRUE);
     48}
     49
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r32632 r33662  
    2121}
    2222
     23// vector types
     24enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME};
     25
    2326int read_vectors (int argc, char **argv) {
    2427 
    25     int i, j, Nskip, Nvec, *col, done, status, IsCSV, VERBOSE;
    26   int Nbytes, nbytes, Nstart, NELEM, N, nread;
     28  int TimeFormat;
     29  time_t TimeReference;
     30  int i, j, Nskip, Narg, Nvec, *col, IsCSV, VERBOSE;
     31  int Nbytes, Nstart, NELEM, Nelem, nread, *coltype;
    2732  char *colstr, *c0, *c1, *buffer, *extname;
    28   double value;
    2933  Vector **vec;
    3034
    3135  /* auto-sense table type */
    32   if ((N = get_argument (argc, argv, "-fits"))) {
    33     remove_argument (N, &argc, argv);
    34     extname = strcreate (argv[N]);
     36  if ((Narg = get_argument (argc, argv, "-fits"))) {
     37    remove_argument (Narg, &argc, argv);
     38    extname = strcreate (argv[Narg]);
    3539    if (extname == (char *) NULL) return (FALSE);
    36     remove_argument (N, &argc, argv);
    37     status = read_table_vectors (argc, argv, extname);
     40    remove_argument (Narg, &argc, argv);
     41    int status = read_table_vectors (argc, argv, extname);
    3842    free (extname);
    3943    return (status);
     
    4145
    4246  Nskip = 0;
    43   if ((N = get_argument (argc, argv, "-skip"))) {
    44     remove_argument (N, &argc, argv);
    45     Nskip = atof (argv[N]);
    46     remove_argument (N, &argc, argv);
     47  if ((Narg = get_argument (argc, argv, "-skip"))) {
     48    remove_argument (Narg, &argc, argv);
     49    Nskip = atof (argv[Narg]);
     50    remove_argument (Narg, &argc, argv);
    4751  }
    4852
    4953  IsCSV = FALSE;
    50   if ((N = get_argument (argc, argv, "-csv"))) {
    51     remove_argument (N, &argc, argv);
     54  if ((Narg = get_argument (argc, argv, "-csv"))) {
     55    remove_argument (Narg, &argc, argv);
    5256    IsCSV = TRUE;
    5357  }
    5458
    5559  VERBOSE = FALSE;
    56   if ((N = get_argument (argc, argv, "-v"))) {
    57     remove_argument (N, &argc, argv);
     60  if ((Narg = get_argument (argc, argv, "-v"))) {
     61    remove_argument (Narg, &argc, argv);
    5862    VERBOSE = TRUE;
    5963  }
     
    6569  /* read name N name N  */
    6670
     71  // do this only optionally?
     72  GetTimeFormat (&TimeReference, &TimeFormat);
     73
    6774  if (f == (FILE *) NULL) {
    6875    gprint (GP_ERR, "no open file for read\n");
     
    7178  fseeko (f, 0LL, SEEK_SET);
    7279
    73 //  if (IsCSV) {
    74 //    status = read_vectors_csv (argc, argv, Nskip, f);
    75 //    return status;
    76 //  }
    77 
    7880  Nvec = (argc - 1) / 2;
    7981  ALLOCATE (vec, Vector *, Nvec);
    8082  ALLOCATE (col, int, Nvec);
     83  ALLOCATE (coltype, int, Nvec);
    8184
    8285  for (i = 0; i < Nvec; i++) {
     86
     87    // interpret the column names including type flags
     88    // XXX review the grammar before releasing this : is foo:type best, or is something else needed?
     89    // Note the conflict wrt list entries
     90    // the name may be of the form foo:type, where type may be one of : int, float, time
     91   
     92    coltype[i] = COLTYPE_FLT;
     93    char *colname = argv[2*i + 1];
     94    char *ptr = strchr (colname, ':');
     95    if (ptr) {
     96      // split out colname and type
     97      *ptr = 0;
     98      ptr ++;
     99      if (!ptr) goto bad_colname;
     100      coltype[i] = COLTYPE_NONE;
     101      if (!strcasecmp(ptr, "float")) { coltype[i] = COLTYPE_FLT; }
     102      if (!strcasecmp(ptr, "int"))   { coltype[i] = COLTYPE_INT; }
     103      if (!strcasecmp(ptr, "time"))  { coltype[i] = COLTYPE_TIME; }
     104      if (!coltype[i]) goto bad_colname;
     105    }
     106
    83107    if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) {
    84108      gprint (GP_ERR, "USAGE: read name N name N ...\n");
     
    87111      return (FALSE);   
    88112    }
    89     // XXX we could allow flags (eg, N.i) to specify INT vs FLT types vectors...
     113
    90114    colstr = argv[2*i+2];
    91115    for (j = 0; j < strlen (colstr); j++) {
     
    119143  NELEM = 1000;
    120144  for (i = 0; i < Nvec; i++) {
    121     ResetVector (vec[i], OPIHI_FLT, NELEM);
     145    if (coltype[i] == COLTYPE_INT) {
     146      ResetVector (vec[i], OPIHI_INT, NELEM);
     147    } else {
     148      // note that COLTYPE_TIME is a type of float
     149      ResetVector (vec[i], OPIHI_FLT, NELEM);
     150    }
    122151  }
    123152 
     
    128157  }
    129158
    130   Nstart = 0;
    131   N = 0;
    132   done = FALSE;
    133   while (!done) {
     159  // we have a working buffer read from the file. we parse the lines in the working buffer
     160  // until we reach the last chunk without an EOL char.  at that point, we shift the start
     161  // of the last (partial) line to the start of the buffer and re-fill.
     162
     163  Nstart = 0; // location of the last valid byte in the buffer (start filling here)
     164  Nelem = 0; // number of valid rows read (vector elements)
     165  while (TRUE) {
    134166    Nbytes = 0x10000 - Nstart;
    135167    bzero (&buffer[Nstart], Nbytes);
     
    139171      break;
    140172    }
    141     if (nread == 0) break;
    142     nbytes = nread + Nstart;
     173    if (nread == 0) break; // end of the file
     174    // nbytes = nread + Nstart;
    143175   
    144     status = TRUE;
    145     c0 = buffer;
    146     while (status) {
    147       c1 = strchr (c0, '\n');
     176    int bufferStatus = TRUE;
     177    c0 = buffer; // c0 always marks the start of a line
     178    while (bufferStatus) {
     179      c1 = strchr (c0, '\n'); // find the end of this current line
    148180      if (c1 == (char *) NULL) {
    149181        Nstart = strlen (c0);
    150182        memmove (buffer, c0, Nstart);
    151         status = FALSE;
    152       } else {
    153         *c1 = 0;
    154       }     
    155       if ((*c0 != '#') && (*c0 != '!')) {
    156         for (i = 0; (i < Nvec) && status; i++) {
     183        bufferStatus = FALSE;
     184        continue;
     185      }
     186      *c1 = 0; // mark the end of the line
     187
     188      if (*c0 == '#') { c0 = c1 + 1; continue; }
     189      if (*c0 == '!') { c0 = c1 + 1; continue; }
     190
     191      // parse the vectors in this line.  this code is a bit inefficient: each column
     192      // requires a separate pass through the line.
     193
     194      int lineStatus = TRUE;
     195      for (i = 0; i < Nvec; i++) {
     196        int ivalue;
     197        double dvalue;
     198        time_t tvalue;
     199        int readStatus = FALSE;
     200        // need to make the if cases for coltype[i]
     201        switch (coltype[i]) {
     202          case COLTYPE_INT:
     203            readStatus = IsCSV ? iparse_csv (&ivalue, col[i], c0) : iparse (&ivalue, col[i], c0);
     204            vec[i][0].elements.Int[Nelem] = readStatus ? ivalue : 0;
     205            break;
     206          case COLTYPE_FLT:
     207            readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0);
     208            vec[i][0].elements.Flt[Nelem] = readStatus ? dvalue : NAN;
     209            break;
     210          case COLTYPE_TIME:
     211            readStatus = IsCSV ? tparse_csv (&tvalue, col[i], c0) : tparse (&tvalue, col[i], c0);
     212            dvalue = TimeValue (tvalue, TimeReference, TimeFormat);
     213            vec[i][0].elements.Flt[Nelem] = readStatus ? dvalue : NAN;
     214            break;
     215        }
     216        if (!readStatus && VERBOSE) {
    157217          if (IsCSV) {
    158             status = dparse_csv (&value, col[i], c0);
     218            gprint (GP_ERR, "suspect field: %d (%s) in %s\n", col[i], argv[2*i+2], c0);
    159219          } else {
    160             status = dparse (&value, col[i], c0);
     220            gprint (GP_ERR, "suspect field: %d in %s\n", col[i], c0);
    161221          }
    162           if (status) {
    163               vec[i][0].elements.Flt[N] = value;
    164           } else {
    165               vec[i][0].elements.Flt[N] = NAN;
    166               if (VERBOSE) {
    167                   if (IsCSV) {
    168                       gprint (GP_ERR, "suspect field: %d (%s) in %s\n", col[i], argv[2*i+2], c0);
    169                   } else {
    170                       gprint (GP_ERR, "suspect field: %d in %s\n", col[i], c0);
    171                   }
    172               }
    173           }
    174         }
    175         if (status) {
    176             N++;
    177         } else {
    178             if (VERBOSE && FALSE) {
    179                 char temp[32];
    180                 strncpy (temp, c0, 32);
    181                 temp[31] = 0;
    182                 gprint (GP_ERR, "skip line %s\n\n", temp);
    183             }
    184         }
    185       }
    186       c0 = c1 + 1;
    187       if (N == NELEM) {
     222        }
     223        lineStatus &= readStatus;
     224      }
     225      if (!lineStatus && VERBOSE) {
     226        char temp[32];
     227        strncpy (temp, c0, 32);
     228        temp[31] = 0;
     229        gprint (GP_ERR, "skip line %s\n\n", temp);
     230      }
     231      Nelem ++;
     232      if (Nelem == NELEM) {
    188233        NELEM += 1000;
    189234        for (i = 0; i < Nvec; i++) {
    190           REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM);
    191         }
    192       }
     235          if (coltype[i] == COLTYPE_INT) {
     236            REALLOCATE (vec[i][0].elements.Int, opihi_int, NELEM);
     237          } else {
     238            REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM);
     239          }
     240        }
     241      }
     242      c0 = c1 + 1;
    193243    }
    194244  }
    195245  for (i = 0; i < Nvec; i++) {
    196     REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (N,1));
    197     vec[i][0].Nelements = N;
     246    if (coltype[i] == COLTYPE_INT) {
     247      REALLOCATE (vec[i][0].elements.Int, opihi_int, MAX (Nelem,1));
     248    } else {
     249      REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (Nelem,1));
     250    }
     251    vec[i][0].Nelements = Nelem;
    198252  }
    199253 
     
    242296    Nextend = atoi (extname);
    243297  }
     298
     299  // XXX ReadAll needs: deal with Extnum vs Extname, save vectors, etc
     300  // ReadAll = FALSE;
     301  // if ((N = get_argument (argc, argv, "-all"))) {
     302  //   remove_argument (N, &argc, argv);
     303  //   ReadAll = atoi (extname);
     304  //   if (argc != 1) ESCAPE ("-all option cannot be mixed with selected field");
     305  // }
    244306
    245307  if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...");
     
    314376  for (i = 1; i < argc; i++) {
    315377    void   *data;
    316     char   *Pc;
    317     short  *Ps;
    318     int    *Pi;
    319     float  *Pf;
    320     double *Pd;
    321378    int Nval;
    322379    char name[80];
     
    345402        sprintf (name, "%s:%d", argv[i], j);
    346403      if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
    347       ResetVector (vec[j], vecType, MAX (Ny,1));
    348     }
    349 
     404      ResetVector (vec[j], vecType, Ny);
     405    }
     406
     407    if (!strcmp (type, "char")) {
     408      char *Ptr = data;
     409      for (j = 0; j < Ny; j++) {
     410        for (k = 0; k < Nval; k++, Ptr++) {
     411          vec[k][0].elements.Int[j] = *Ptr;
     412        }
     413      }
     414    }
     415    if (!strcmp (type, "short")) {
     416      short *Ptr = data;
     417      for (j = 0; j < Ny; j++) {
     418        for (k = 0; k < Nval; k++, Ptr++) {
     419          vec[k][0].elements.Int[j] = *Ptr;
     420        }
     421      }
     422    }
     423    if (!strcmp (type, "int")) {
     424      int *Ptr = data;
     425      for (j = 0; j < Ny; j++) {
     426        for (k = 0; k < Nval; k++, Ptr++) {
     427          vec[k][0].elements.Int[j] = *Ptr;
     428        }
     429      }
     430    }
     431    if (!strcmp (type, "int64_t")) {
     432      int64_t *Ptr = data;
     433      for (j = 0; j < Ny; j++) {
     434        for (k = 0; k < Nval; k++, Ptr++) {
     435          vec[k][0].elements.Int[j] = *Ptr;
     436        }
     437      }
     438    }
     439    if (!strcmp (type, "float")) {
     440      float *Ptr = data;
     441      for (j = 0; j < Ny; j++) {
     442        for (k = 0; k < Nval; k++, Ptr++) {
     443          vec[k][0].elements.Flt[j] = *Ptr;
     444        }
     445      }
     446    }
    350447    if (!strcmp (type, "double")) {
    351       Pd = (double *) data;
    352       for (j = 0; j < Ny; j++) {
    353         for (k = 0; k < Nval; k++, Pd++) {
    354           vec[k][0].elements.Flt[j] = *Pd;
    355         }
    356       }
    357     }
    358     if (!strcmp (type, "float")) {
    359       Pf = (float *) data;
    360       for (j = 0; j < Ny; j++) {
    361         for (k = 0; k < Nval; k++, Pf++) {
    362           vec[k][0].elements.Flt[j] = *Pf;
    363         }
    364       }
    365     }
    366     if (!strcmp (type, "int")) {
    367       Pi = (int *) data;
    368       for (j = 0; j < Ny; j++) {
    369         for (k = 0; k < Nval; k++, Pi++) {
    370           vec[k][0].elements.Int[j] = *Pi;
    371         }
    372       }
    373     }
    374     if (!strcmp (type, "short")) {
    375       Ps = (short *) data;
    376       for (j = 0; j < Ny; j++) {
    377         for (k = 0; k < Nval; k++, Ps++) {
    378           vec[k][0].elements.Int[j] = *Ps;
    379         }
    380       }
    381     }
    382     if (!strcmp (type, "char")) {
    383       Pc = (char *) data;
    384       for (j = 0; j < Ny; j++) {
    385         for (k = 0; k < Nval; k++, Pc++) {
    386           vec[k][0].elements.Int[j] = *Pc;
     448      double *Ptr = data;
     449      for (j = 0; j < Ny; j++) {
     450        for (k = 0; k < Nval; k++, Ptr++) {
     451          vec[k][0].elements.Flt[j] = *Ptr;
    387452        }
    388453      }
     
    396461  return (TRUE);
    397462}
    398 
    399 # if (0)
    400 int read_vectors_csv (int argc, char **argv, int Nskip, FILE *f) {
    401  
    402   int i, j, Nvec, *col, done, status;
    403   int Nbytes, nbytes, Nstart, NELEM, N, nread;
    404   char *colstr, *c0, *c1, *buffer, *extname;
    405   double value;
    406   Vector **vec;
    407 
    408   Nvec = (argc - 1) / 2;
    409   ALLOCATE (vec, Vector *, Nvec);
    410   ALLOCATE (col, int, Nvec);
    411 
    412   for (i = 0; i < Nvec; i++) {
    413     if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) {
    414       gprint (GP_ERR, "USAGE: read name N name N ...\n");
    415       free (vec);
    416       free (col);
    417       return (FALSE);   
    418     }
    419     // XXX we could allow flags (eg, N.i) to specify INT vs FLT types vectors...
    420     colstr = argv[2*i+2];
    421     for (j = 0; j < strlen (colstr); j++) {
    422       if (!isdigit(colstr[j])) {
    423         gprint (GP_ERR, "USAGE: read name N name N ...\n");
    424         free (vec);
    425         free (col);
    426         return (FALSE);   
    427       }
    428     }
    429     col[i] = atof (colstr);
    430   }
    431 
    432   // currently, all read vectors are forced to be type FLT
    433   NELEM = 1000;
    434   for (i = 0; i < Nvec; i++) {
    435     ResetVector (vec[i], OPIHI_FLT, NELEM);
    436   }
    437  
    438   ALLOCATE (buffer, char, 0x10001);
    439   bzero (buffer, 0x10001);
    440   for (i = 0; i < Nskip; i++) {
    441     scan_line (f, buffer);
    442   }
    443 
    444   Nstart = 0;
    445   N = 0;
    446   done = FALSE;
    447   while (!done) {
    448     Nbytes = 0x10000 - Nstart;
    449     bzero (&buffer[Nstart], Nbytes);
    450     nread = fread (&buffer[Nstart], 1, Nbytes, f);
    451     if (ferror (f)) {
    452       perror ("error reading data file");
    453       break;
    454     }
    455     if (nread == 0) break;
    456     nbytes = nread + Nstart;
    457    
    458     status = TRUE;
    459     c0 = buffer;
    460     while (status) {
    461       c1 = strchr (c0, '\n');
    462       if (c1 == (char *) NULL) {
    463         Nstart = strlen (c0);
    464         memmove (buffer, c0, Nstart);
    465         status = FALSE;
    466       } else {
    467         *c1 = 0;
    468       }     
    469       if ((*c0 != '#') && (*c0 != '!')) {
    470         for (i = 0; (i < Nvec) && status; i++) {
    471           status = dparse_csv (&value, col[i], c0);
    472           vec[i][0].elements.Flt[N] = value;
    473           if (!status) vec[i][0].elements.Flt[N] = NAN;
    474         }
    475         if (status) N++;
    476       }
    477       c0 = c1 + 1;
    478       if (N == NELEM) {
    479         NELEM += 1000;
    480         for (i = 0; i < Nvec; i++) {
    481           REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM);
    482         }
    483       }
    484        
    485     }
    486   }
    487   for (i = 0; i < Nvec; i++) {
    488     REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (N,1));
    489     vec[i][0].Nelements = N;
    490   }
    491  
    492   free (vec);
    493   free (col);
    494   free (buffer);
    495   return (TRUE);
    496 
    497 }
    498 
    499 # endif
  • trunk/Ohana/src/opihi/cmd.data/reindex.c

    r30610 r33662  
    2222
    2323  // ovec matches ivec in type and xvec in size (xvec need not have all ivec elements, and may have duplicates
    24   ResetVector (ovec, ivec->type, MAX (xvec[0].Nelements, 1));
     24  ResetVector (ovec, ivec->type, xvec[0].Nelements);
    2525
    2626  Nmax = ivec[0].Nelements - 1;
     
    5151
    5252  // free up unused memory
    53   ResetVector (ovec, ivec->type, MAX (Npts, 1));
     53  ResetVector (ovec, ivec->type, Npts);
    5454  return (TRUE);
    5555
  • trunk/Ohana/src/opihi/cmd.data/select.c

    r20936 r33662  
    2828
    2929  if ((in1->type == OPIHI_INT) && (in2->type == OPIHI_INT)) {
    30     ResetVector (ovec, OPIHI_INT, MAX (tvec[0].Nelements, 1));
     30    ResetVector (ovec, OPIHI_INT, tvec[0].Nelements);
    3131  } else {
    32     ResetVector (ovec, OPIHI_FLT, MAX (tvec[0].Nelements, 1));
     32    ResetVector (ovec, OPIHI_FLT, tvec[0].Nelements);
    3333  }
    3434
  • trunk/Ohana/src/opihi/cmd.data/write_vectors.c

    r30610 r33662  
    77  FILE *f;
    88  char **fmtlist, *fmttype;
    9   char *p0, *p1, *p2, *format;
     9  char *p0, *p1, *p2, *format, *FITS;
    1010  Vector **vec;
    1111
     
    1515    remove_argument (N, &argc, argv);
    1616    format = strcreate (argv[N]);
     17    remove_argument (N, &argc, argv);
     18  }
     19
     20  /* option generate a FITS output table */
     21  FITS = NULL;
     22  if ((N = get_argument (argc, argv, "-fits"))) {
     23    remove_argument (N, &argc, argv);
     24    FITS = strcreate (argv[N]);
    1725    remove_argument (N, &argc, argv);
    1826  }
     
    2937  }
    3038
    31   /* open file for outuput */
    32   if (append) {
    33       f = fopen (argv[1], "a");
    34   } else {
    35       f = fopen (argv[1], "w");
    36   }
    37   if (f == (FILE *) NULL) {
    38     gprint (GP_ERR, "can't open file for write\n");
    39     return (FALSE);
    40   }
    41 
    4239  /* find number of output vectors */
    4340  Nvec = (argc - 2);
    4441  if (Nvec < 1) {
    45       gprint (GP_ERR, "USAGE: write (file) vector vector ...\n");
    46       fclose (f);
    47   fflush (f);
    48       return (FALSE);
     42    gprint (GP_ERR, "USAGE: write (file) vector vector ...\n");
     43    return (FALSE);
    4944  }
    5045  ALLOCATE (vec, Vector *, Nvec);
     
    5651      gprint (GP_ERR, "USAGE: write (file) vector vector ...\n");
    5752      free (vec);
    58       fclose (f);
    59   fflush (f);
    6053      return (FALSE);   
    6154    }
     
    6861      gprint (GP_ERR, "error: vectors must all be the same size\n");
    6962      free (vec);
    70       fclose (f);
    71   fflush (f);
    7263      return (FALSE);   
    7364    }
     65  }
     66
     67  if (FITS) {
     68    int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, format);
     69    free (vec);
     70    return status;
     71  }
     72
     73  /* open file for outuput */
     74  if (append) {
     75    f = fopen (argv[1], "a");
     76  } else {
     77    f = fopen (argv[1], "w");
     78  }
     79  if (f == (FILE *) NULL) {
     80    gprint (GP_ERR, "can't open file for write\n");
     81    return (FALSE);
    7482  }
    7583
     
    8896    fclose (f);
    8997    free (vec);
    90   fflush (f);
     98    fflush (f);
    9199    return (TRUE);
    92100  }
     
    111119      free (format);
    112120      fclose (f);
    113   fflush (f);
     121      fflush (f);
    114122      return (FALSE);
    115123    }
Note: See TracChangeset for help on using the changeset viewer.