Changeset 31667 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Jun 22, 2011, 12:40:23 AM (15 years ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 4 edited
- 2 copied
-
init.c (modified) (2 diffs)
-
read_vectors.c (modified) (8 diffs)
-
test/csv.dat (copied) (copied from branches/eam_branches/ipp-20110505/Ohana/src/opihi/cmd.data/test/csv.dat )
-
test/csv1.dat (copied) (copied from branches/eam_branches/ipp-20110505/Ohana/src/opihi/cmd.data/test/csv1.dat )
-
tvcolors.c (modified) (2 diffs)
-
zplot.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/init.c
r31450 r31667 137 137 int zap PROTO((int, char **)); 138 138 int zplot PROTO((int, char **)); 139 int zcplot PROTO((int, char **)); 139 140 140 141 static Command cmds[] = { … … 284 285 {1, "zap", zap, "assign values to pixel regions"}, 285 286 {1, "zplot", zplot, "plot x y with size scaled by z"}, 287 {1, "zcplot", zcplot, "plot x y with color scaled by z"}, 286 288 }; 287 289 -
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r29938 r31667 2 2 3 3 FILE *f = (FILE *) NULL; 4 char filename[2 56];4 char filename[2048]; 5 5 6 6 int datafile (int argc, char **argv) { … … 23 23 int read_vectors (int argc, char **argv) { 24 24 25 int i, j, Nskip, Nvec, *col, done, status ;25 int i, j, Nskip, Nvec, *col, done, status, IsCSV; 26 26 int Nbytes, nbytes, Nstart, NELEM, N, nread; 27 27 char *colstr, *c0, *c1, *buffer, *extname; … … 47 47 } 48 48 49 IsCSV = FALSE; 50 if ((N = get_argument (argc, argv, "-csv"))) { 51 remove_argument (N, &argc, argv); 52 IsCSV = TRUE; 53 } 54 49 55 if ((argc < 3) || !(argc % 2)) { 50 56 gprint (GP_ERR, "USAGE: read name N name N ...\n"); … … 58 64 } 59 65 fseeko (f, 0LL, SEEK_SET); 66 67 // if (IsCSV) { 68 // status = read_vectors_csv (argc, argv, Nskip, f); 69 // return status; 70 // } 60 71 61 72 Nvec = (argc - 1) / 2; … … 73 84 colstr = argv[2*i+2]; 74 85 for (j = 0; j < strlen (colstr); j++) { 75 if (!isdigit(colstr[j])) { 76 gprint (GP_ERR, "USAGE: read name N name N ...\n"); 77 free (vec); 78 free (col); 79 return (FALSE); 80 } 81 } 82 col[i] = atof (colstr); 86 if (isdigit(colstr[j])) { 87 col[i] = atof (colstr); 88 continue; 89 } 90 // allow 'excel' columns names of the form A-Z, AA-AZ, BA-BZ, .. ZA-ZZ 91 if (strlen(colstr) >= 3) goto bad_colname; 92 if (colstr[0] < 'A') goto bad_colname; 93 if (colstr[0] > 'Z') goto bad_colname; 94 if (colstr[1] && colstr[1] < 'A') goto bad_colname; 95 if (colstr[1] && colstr[1] > 'Z') goto bad_colname; 96 97 col[i] = colstr[0] - 'A' + 1; 98 if (colstr[1]) { 99 col[i] *= 26; 100 col[i] += colstr[1] - 'A' + 1; 101 } 102 continue; 103 104 bad_colname: 105 gprint (GP_ERR, "USAGE: read name N name N ...\n"); 106 free (vec); 107 free (col); 108 return (FALSE); 109 } 83 110 } 84 111 … … 94 121 scan_line (f, buffer); 95 122 } 123 124 int Nfield = 0; 125 int Nline = 0; 96 126 97 127 Nstart = 0; … … 122 152 if ((*c0 != '#') && (*c0 != '!')) { 123 153 for (i = 0; (i < Nvec) && status; i++) { 124 status = dparse (&value, col[i], c0); 154 if (IsCSV) { 155 status = dparse_csv (&value, col[i], c0); 156 } else { 157 status = dparse (&value, col[i], c0); 158 } 125 159 vec[i][0].elements.Flt[N] = value; 160 if (status) { 161 Nfield ++; 162 } 126 163 if (!status) vec[i][0].elements.Flt[N] = NAN; 127 164 } 128 165 if (status) N++; 129 166 } 167 Nline ++; 168 if (c1) { 169 // fprintf (stderr, "line %d, chars %ld, fields %d\n", Nline, (c1 - c0), Nfield); 170 } 171 Nfield = 0; 130 172 c0 = c1 + 1; 131 173 if (N == NELEM) { … … 341 383 return (TRUE); 342 384 } 385 386 # if (0) 387 int read_vectors_csv (int argc, char **argv, int Nskip, FILE *f) { 388 389 int i, j, Nvec, *col, done, status; 390 int Nbytes, nbytes, Nstart, NELEM, N, nread; 391 char *colstr, *c0, *c1, *buffer, *extname; 392 double value; 393 Vector **vec; 394 395 Nvec = (argc - 1) / 2; 396 ALLOCATE (vec, Vector *, Nvec); 397 ALLOCATE (col, int, Nvec); 398 399 for (i = 0; i < Nvec; i++) { 400 if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) { 401 gprint (GP_ERR, "USAGE: read name N name N ...\n"); 402 free (vec); 403 free (col); 404 return (FALSE); 405 } 406 // XXX we could allow flags (eg, N.i) to specify INT vs FLT types vectors... 407 colstr = argv[2*i+2]; 408 for (j = 0; j < strlen (colstr); j++) { 409 if (!isdigit(colstr[j])) { 410 gprint (GP_ERR, "USAGE: read name N name N ...\n"); 411 free (vec); 412 free (col); 413 return (FALSE); 414 } 415 } 416 col[i] = atof (colstr); 417 } 418 419 // currently, all read vectors are forced to be type FLT 420 NELEM = 1000; 421 for (i = 0; i < Nvec; i++) { 422 ResetVector (vec[i], OPIHI_FLT, NELEM); 423 } 424 425 ALLOCATE (buffer, char, 0x10001); 426 bzero (buffer, 0x10001); 427 for (i = 0; i < Nskip; i++) { 428 scan_line (f, buffer); 429 } 430 431 Nstart = 0; 432 N = 0; 433 done = FALSE; 434 while (!done) { 435 Nbytes = 0x10000 - Nstart; 436 bzero (&buffer[Nstart], Nbytes); 437 nread = fread (&buffer[Nstart], 1, Nbytes, f); 438 if (ferror (f)) { 439 perror ("error reading data file"); 440 break; 441 } 442 if (nread == 0) break; 443 nbytes = nread + Nstart; 444 445 status = TRUE; 446 c0 = buffer; 447 while (status) { 448 c1 = strchr (c0, '\n'); 449 if (c1 == (char *) NULL) { 450 Nstart = strlen (c0); 451 memmove (buffer, c0, Nstart); 452 status = FALSE; 453 } else { 454 *c1 = 0; 455 } 456 if ((*c0 != '#') && (*c0 != '!')) { 457 for (i = 0; (i < Nvec) && status; i++) { 458 status = dparse_csv (&value, col[i], c0); 459 vec[i][0].elements.Flt[N] = value; 460 if (!status) vec[i][0].elements.Flt[N] = NAN; 461 } 462 if (status) N++; 463 } 464 c0 = c1 + 1; 465 if (N == NELEM) { 466 NELEM += 1000; 467 for (i = 0; i < Nvec; i++) { 468 REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM); 469 } 470 } 471 472 } 473 } 474 for (i = 0; i < Nvec; i++) { 475 REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (N,1)); 476 vec[i][0].Nelements = N; 477 } 478 479 free (vec); 480 free (col); 481 free (buffer); 482 return (TRUE); 483 484 } 485 486 # endif -
trunk/Ohana/src/opihi/cmd.data/tvcolors.c
r25757 r31667 5 5 int N, kapa; 6 6 char *name; 7 KapaImageData data;7 // KapaImageData data; 8 8 9 9 name = NULL; … … 13 13 remove_argument (N, &argc, argv); 14 14 } 15 if (!Get Image (&data, &kapa, name)) return (FALSE);15 if (!GetGraph (NULL, &kapa, name)) return (FALSE); 16 16 FREE (name); 17 17 -
trunk/Ohana/src/opihi/cmd.data/zplot.c
r20936 r31667 58 58 } 59 59 60 int zcplot (int argc, char **argv) { 61 62 int i, kapa; 63 opihi_flt *out; 64 double min, range; 65 Graphdata graphmode; 66 Vector *xvec, *yvec, *zvec, Zvec; 60 67 68 if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE); 69 70 if (argc != 6) { 71 gprint (GP_ERR, "USAGE: zplot <x> <y> <z> min max\n"); 72 return (FALSE); 73 } 74 75 min = atof(argv[4]); 76 range = atof(argv[5]) - min; 77 78 /* find vectors */ 79 if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 80 if ((yvec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE); 81 if ((zvec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE); 82 if (xvec[0].Nelements != yvec[0].Nelements) { 83 gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[2]); 84 return (FALSE); 85 } 86 if (xvec[0].Nelements != zvec[0].Nelements) { 87 gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]); 88 return (FALSE); 89 } 90 SetVector (&Zvec, OPIHI_FLT, zvec[0].Nelements); 91 out = Zvec.elements.Flt; 92 93 if (zvec[0].type == OPIHI_FLT) { 94 opihi_flt *in = zvec[0].elements.Flt; 95 for (i = 0; i < Zvec.Nelements; i++, in++, out++) { 96 *out = MIN (1.0, MAX (0.01, (*in - min) / range)); 97 } 98 } else { 99 opihi_int *in = zvec[0].elements.Int; 100 for (i = 0; i < Zvec.Nelements; i++, in++, out++) { 101 *out = MIN (1.0, MAX (0.01, (*in - min) / range)); 102 } 103 } 104 105 /* point size determined by Zvec */ 106 graphmode.style = 2; /* plot points */ 107 graphmode.color = -1; /* point color determined by Zvec */ 108 graphmode.etype = 0; /* no errorbars */ 109 PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode); 110 111 free (Zvec.elements.Ptr); 112 113 return (TRUE); 114 115 } 116 117
Note:
See TracChangeset
for help on using the changeset viewer.
