Changeset 33662 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Apr 1, 2012, 3:24:39 PM (14 years ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 13 edited
- 6 copied
-
Makefile (modified) (1 diff)
-
cumulative.c (modified) (2 diffs)
-
cursor.c (modified) (3 diffs)
-
cut.c (modified) (2 diffs)
-
imcut.c (modified) (1 diff)
-
init.c (modified) (5 diffs)
-
line.c (modified) (2 diffs)
-
list_buffers.c (modified) (1 diff)
-
list_vectors.c (modified) (1 diff)
-
read_vectors.c (modified) (12 diffs)
-
reindex.c (modified) (2 diffs)
-
select.c (modified) (1 diff)
-
test/read.sh (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.data/test/read.sh )
-
test/read.t1.dat (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.data/test/read.t1.dat )
-
test/read.t2.dat (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.data/test/read.t2.dat )
-
test/read.t3.dat (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.data/test/read.t3.dat )
-
test/read.t4.dat (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.data/test/read.t4.dat )
-
threshold.c (copied) (copied from branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.data/threshold.c )
-
write_vectors.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/Makefile
r31635 r33662 123 123 $(SRC)/swapbytes.$(ARCH).o \ 124 124 $(SRC)/textline.$(ARCH).o \ 125 $(SRC)/threshold.$(ARCH).o \ 125 126 $(SRC)/tv.$(ARCH).o \ 126 127 $(SRC)/tvchannel.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/cumulative.c
r20936 r33662 23 23 opihi_flt *Vi = ivec[0].elements.Flt; 24 24 *Vo = *Vi; 25 Vi++; 26 Vo++; 25 27 for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) { 26 28 *Vo = Vo[-1] + *Vi; … … 29 31 opihi_int *Vi = ivec[0].elements.Int; 30 32 *Vo = *Vi; 33 Vi++; 34 Vo++; 31 35 for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) { 32 36 *Vo = Vo[-1] + *Vi; -
trunk/Ohana/src/opihi/cmd.data/cursor.c
r31635 r33662 4 4 5 5 char string[20], key[20], *name; 6 int i, N, kapa ;6 int i, N, kapa, VERBOSE; 7 7 double X, Y, R, D, Z; 8 8 void *oldsignal; … … 13 13 // if ((N = get_argument (argc, argv, "-g"))) { 14 14 // if ((N = get_argument (argc, argv, "-i"))) { 15 16 VERBOSE = TRUE; 17 if ((N = get_argument (argc, argv, "-a"))) { 18 VERBOSE = FALSE; 19 } 15 20 16 21 name = NULL; … … 53 58 set_str_variable ("KEY", key); 54 59 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); 56 61 57 62 if (!strcasecmp (key, "Q")) break; -
trunk/Ohana/src/opihi/cmd.data/cut.c
r20936 r33662 48 48 case 'X': 49 49 /* 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); 52 52 bzero (yvec[0].elements.Flt, nx*sizeof(opihi_flt)); 53 53 for (i = 0; i < nx; i++) { … … 80 80 case 'y': 81 81 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); 84 84 bzero (yvec[0].elements.Flt, ny*sizeof(opihi_flt)); 85 85 for (i = 0; i < ny; i++) { -
trunk/Ohana/src/opihi/cmd.data/imcut.c
r20936 r33662 37 37 dY = dY / L; 38 38 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); 41 41 42 42 V = (float *)buf[0].matrix.buffer; -
trunk/Ohana/src/opihi/cmd.data/init.c
r31667 r33662 61 61 int header PROTO((int, char **)); 62 62 int list_vectors PROTO((int, char **)); 63 int vtype PROTO((int, char **)); 63 64 int load PROTO((int, char **)); 64 65 int lookup PROTO((int, char **)); … … 111 112 int swapbytes PROTO((int, char **)); 112 113 int textline PROTO((int, char **)); 114 int threshold PROTO((int, char **)); 113 115 int tv PROTO((int, char **)); 114 116 int tvchannel PROTO((int, char **)); … … 138 140 int zplot PROTO((int, char **)); 139 141 int zcplot PROTO((int, char **)); 142 143 // ??? 144 // int mtype PROTO((int, char **)); 145 // {1, "mtype", mtype, "return the type of the defined buffer"}, 140 146 141 147 static Command cmds[] = { … … 257 263 {1, "swapbytes", swapbytes, "byte swap thing"}, 258 264 {1, "textline", textline, "write text line on graph"}, 265 {1, "threshold", threshold, "find (interpolate) location of transition"}, 259 266 {1, "tv", tv, "display an image on the Kii window"}, 260 267 {1, "tvchannel", tvchannel, "set the current tv channel"}, … … 269 276 {1, "vclip", vclip, "clip values in a vector to be within a range"}, 270 277 {1, "vectors", list_vectors, "list vectors"}, 278 {1, "vtype", vtype, "return the vector type (FLT or INT)"}, 271 279 {1, "vgauss", vgauss, "fit a Gaussian to a vector"}, 272 280 {1, "vellipse", vellipse, "fit a Ellipse to a vector pair"}, -
trunk/Ohana/src/opihi/cmd.data/line.c
r13479 r33662 3 3 int line (int argc, char **argv) { 4 4 5 int kapa ;5 int kapa, N; 6 6 Graphdata graphmode; 7 7 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 } 8 15 9 16 if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE; … … 18 25 y[1] = atof(argv[5]); 19 26 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 20 34 /* set point style and errorbar mode (these are NOT sticky) */ 21 35 graphmode.style = 0; -
trunk/Ohana/src/opihi/cmd.data/list_buffers.c
r2598 r33662 9 9 10 10 } 11 12 # if (0) 13 int 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 7 7 } 8 8 9 int 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 21 21 } 22 22 23 // vector types 24 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME}; 25 23 26 int read_vectors (int argc, char **argv) { 24 27 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; 27 32 char *colstr, *c0, *c1, *buffer, *extname; 28 double value;29 33 Vector **vec; 30 34 31 35 /* 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]); 35 39 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); 38 42 free (extname); 39 43 return (status); … … 41 45 42 46 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); 47 51 } 48 52 49 53 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); 52 56 IsCSV = TRUE; 53 57 } 54 58 55 59 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); 58 62 VERBOSE = TRUE; 59 63 } … … 65 69 /* read name N name N */ 66 70 71 // do this only optionally? 72 GetTimeFormat (&TimeReference, &TimeFormat); 73 67 74 if (f == (FILE *) NULL) { 68 75 gprint (GP_ERR, "no open file for read\n"); … … 71 78 fseeko (f, 0LL, SEEK_SET); 72 79 73 // if (IsCSV) {74 // status = read_vectors_csv (argc, argv, Nskip, f);75 // return status;76 // }77 78 80 Nvec = (argc - 1) / 2; 79 81 ALLOCATE (vec, Vector *, Nvec); 80 82 ALLOCATE (col, int, Nvec); 83 ALLOCATE (coltype, int, Nvec); 81 84 82 85 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 83 107 if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) { 84 108 gprint (GP_ERR, "USAGE: read name N name N ...\n"); … … 87 111 return (FALSE); 88 112 } 89 // XXX we could allow flags (eg, N.i) to specify INT vs FLT types vectors... 113 90 114 colstr = argv[2*i+2]; 91 115 for (j = 0; j < strlen (colstr); j++) { … … 119 143 NELEM = 1000; 120 144 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 } 122 151 } 123 152 … … 128 157 } 129 158 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) { 134 166 Nbytes = 0x10000 - Nstart; 135 167 bzero (&buffer[Nstart], Nbytes); … … 139 171 break; 140 172 } 141 if (nread == 0) break; 142 nbytes = nread + Nstart;173 if (nread == 0) break; // end of the file 174 // nbytes = nread + Nstart; 143 175 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 148 180 if (c1 == (char *) NULL) { 149 181 Nstart = strlen (c0); 150 182 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) { 157 217 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); 159 219 } else { 160 status = dparse (&value, col[i], c0);220 gprint (GP_ERR, "suspect field: %d in %s\n", col[i], c0); 161 221 } 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) { 188 233 NELEM += 1000; 189 234 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; 193 243 } 194 244 } 195 245 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; 198 252 } 199 253 … … 242 296 Nextend = atoi (extname); 243 297 } 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 // } 244 306 245 307 if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ..."); … … 314 376 for (i = 1; i < argc; i++) { 315 377 void *data; 316 char *Pc;317 short *Ps;318 int *Pi;319 float *Pf;320 double *Pd;321 378 int Nval; 322 379 char name[80]; … … 345 402 sprintf (name, "%s:%d", argv[i], j); 346 403 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 } 350 447 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; 387 452 } 388 453 } … … 396 461 return (TRUE); 397 462 } 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 FLT433 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 22 22 23 23 // 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); 25 25 26 26 Nmax = ivec[0].Nelements - 1; … … 51 51 52 52 // free up unused memory 53 ResetVector (ovec, ivec->type, MAX (Npts, 1));53 ResetVector (ovec, ivec->type, Npts); 54 54 return (TRUE); 55 55 -
trunk/Ohana/src/opihi/cmd.data/select.c
r20936 r33662 28 28 29 29 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); 31 31 } else { 32 ResetVector (ovec, OPIHI_FLT, MAX (tvec[0].Nelements, 1));32 ResetVector (ovec, OPIHI_FLT, tvec[0].Nelements); 33 33 } 34 34 -
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r30610 r33662 7 7 FILE *f; 8 8 char **fmtlist, *fmttype; 9 char *p0, *p1, *p2, *format ;9 char *p0, *p1, *p2, *format, *FITS; 10 10 Vector **vec; 11 11 … … 15 15 remove_argument (N, &argc, argv); 16 16 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]); 17 25 remove_argument (N, &argc, argv); 18 26 } … … 29 37 } 30 38 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 42 39 /* find number of output vectors */ 43 40 Nvec = (argc - 2); 44 41 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); 49 44 } 50 45 ALLOCATE (vec, Vector *, Nvec); … … 56 51 gprint (GP_ERR, "USAGE: write (file) vector vector ...\n"); 57 52 free (vec); 58 fclose (f);59 fflush (f);60 53 return (FALSE); 61 54 } … … 68 61 gprint (GP_ERR, "error: vectors must all be the same size\n"); 69 62 free (vec); 70 fclose (f);71 fflush (f);72 63 return (FALSE); 73 64 } 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); 74 82 } 75 83 … … 88 96 fclose (f); 89 97 free (vec); 90 fflush (f);98 fflush (f); 91 99 return (TRUE); 92 100 } … … 111 119 free (format); 112 120 fclose (f); 113 fflush (f);121 fflush (f); 114 122 return (FALSE); 115 123 }
Note:
See TracChangeset
for help on using the changeset viewer.
