Changeset 41269 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Feb 24, 2020, 3:19:09 PM (6 years ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 7 edited
-
create.c (modified) (2 diffs)
-
list_vectors.c (modified) (1 diff)
-
print_vectors.c (modified) (1 diff)
-
read_vectors.c (modified) (10 diffs)
-
rotate.c (modified) (1 diff)
-
tvcolors.c (modified) (1 diff)
-
write_vectors.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/create.c
r40015 r41269 7 7 Vector *vec; 8 8 9 // create a vector of empty strings 10 if ((N = get_argument (argc, argv, "-str"))) { 11 remove_argument (N, &argc, argv); 12 13 char *stringValue = NULL; 14 if ((N = get_argument (argc, argv, "-value"))) { 15 remove_argument (N, &argc, argv); 16 stringValue = strcreate (argv[N]); 17 remove_argument (N, &argc, argv); 18 } 19 20 if (argc != 3) { 21 gprint (GP_ERR, "USAGE: create vector Nelements -value word\n"); 22 return (FALSE); 23 } 24 25 if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) return (FALSE); 26 int Nelements = atoi (argv[2]); 27 28 // a newly reset vector has NULL-valued pointers 29 ResetVector (vec, OPIHI_STR, Nelements); 30 for (int i = 0; i < Nelements; i++) { 31 vec[0].elements.Str[i] = stringValue ? strcreate (stringValue) : strcreate (""); 32 } 33 return TRUE; 34 } 35 9 36 INT = FALSE; 10 37 if ((N = get_argument (argc, argv, "-int"))) { … … 16 43 gprint (GP_ERR, "USAGE: create vector start end [delta] [-int]\n"); 17 44 gprint (GP_ERR, " -int : resulting vector is integer type (delta must be integer)\n"); 45 gprint (GP_ERR, " -str : resulting vector is string type (only give number of elements)\n"); 18 46 return (FALSE); 19 47 } -
trunk/Ohana/src/opihi/cmd.data/list_vectors.c
r39457 r41269 32 32 } 33 33 34 if (vec->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 } 34 switch (vec->type) { 35 case OPIHI_FLT: 36 if (Variable) { 37 set_str_variable (Variable, "FLT"); 38 } else { 39 gprint (GP_LOG, "%s : FLT\n", argv[1]); 40 } 41 break; 42 case OPIHI_INT: 43 if (Variable) { 44 set_str_variable (Variable, "INT"); 45 } else { 46 gprint (GP_LOG, "%s : INT\n", argv[1]); 47 } 48 break; 49 case OPIHI_STR: 50 if (Variable) { 51 set_str_variable (Variable, "STR"); 52 } else { 53 gprint (GP_LOG, "%s : STR\n", argv[1]); 54 } 55 break; 46 56 } 47 57 if (Variable) free (Variable); -
trunk/Ohana/src/opihi/cmd.data/print_vectors.c
r40545 r41269 56 56 if (vec[i][0].type == OPIHI_FLT) { 57 57 gprint (GP_LOG, "%f ", vec[i][0].elements.Flt[j]); 58 } else { 58 } 59 if (vec[i][0].type == OPIHI_INT) { 59 60 gprint (GP_LOG, OPIHI_INT_FMT" ", vec[i][0].elements.Int[j]); 60 } 61 } 62 if (vec[i][0].type == OPIHI_STR) { 63 gprint (GP_LOG, "%s ", vec[i][0].elements.Str[j]); 64 } 61 65 } 62 66 } -
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r40519 r41269 35 35 36 36 // vector types 37 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR };37 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR, COLTYPE_STR}; 38 38 39 39 static int Nvec = 0; … … 91 91 gprint (GP_ERR, " -skip N : skip N lines before reading\n"); 92 92 gprint (GP_ERR, " column names may include a type: name:type\n"); 93 gprint (GP_ERR, " type is int, float, char, time\n");93 gprint (GP_ERR, " type is int, float, char, str, time\n"); 94 94 gprint (GP_ERR, " for char, values are placed into a list $name:0 - $name:n\n"); 95 gprint (GP_ERR, " for str, values are placed into a string-typed vector\n"); 95 96 gprint (GP_ERR, " for time, values are human-readable date/time strings YYYY/MM/DD,hh:mm:ss\n"); 96 97 gprint (GP_ERR, " the resulting vector is a float based on the TIMEFORMAT, TIMEREF values\n"); … … 152 153 if (!strcasecmp(ptr, "int")) { coltype[i] = COLTYPE_INT; } 153 154 if (!strcasecmp(ptr, "char")) { coltype[i] = COLTYPE_CHAR; } 155 if (!strcasecmp(ptr, "str")) { coltype[i] = COLTYPE_STR; } 154 156 if (!strcasecmp(ptr, "time")) { coltype[i] = COLTYPE_TIME; } 155 157 if (!coltype[i]) goto bad_colname; … … 213 215 // note that COLTYPE_TIME is a type of float 214 216 ResetVector (vec[i], OPIHI_FLT, NELEM); 217 break; 218 case COLTYPE_STR: 219 ResetVector (vec[i], OPIHI_STR, NELEM); 215 220 break; 216 221 case COLTYPE_CHAR: … … 311 316 break; 312 317 } 318 case COLTYPE_STR: 319 { 320 // I need to get an isolated word in 'value' with the string value of this field 321 char *ptr = IsCSV ? ptrparse_csv (col[i], c0) : ptrparse (col[i], c0); 322 char *value = NULL; 323 if (IsCSV) { 324 char *end = parse_nextword_csv (ptr); 325 if (end) { 326 value = end ? strncreate (ptr, end - ptr) : strcreate (ptr); 327 } 328 } else { 329 value = thisword(ptr); 330 } 331 vec[i][0].elements.Str[Nelem] = value; // needs to be freed later. 332 break; 333 } 313 334 case COLTYPE_FLT: 314 335 readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0); … … 348 369 ResetVector (vec[i], OPIHI_FLT, NELEM); 349 370 break; 371 case COLTYPE_STR: 372 ResetVector (vec[i], OPIHI_STR, NELEM); 373 break; 350 374 case COLTYPE_CHAR: 351 375 default: … … 369 393 ResetVector (vec[i], OPIHI_FLT, Nelem); 370 394 break; 395 case COLTYPE_STR: 396 ResetVector (vec[i], OPIHI_STR, Nelem); 397 break; 371 398 case COLTYPE_CHAR: 372 399 sprintf (varname, "%s:n", listname[i]); … … 469 496 } 470 497 471 // if CharAsVectors, char fields will be saved as vectors NAME:0 -- NAME:n for n characters 472 // else char fields will be saved as $NAME:0 - $NAME:m for m rows 498 // by default, we now store a string-type field as a string-type vector. 499 500 // if CharAsList is selected (and My < 10000), char fields will be saved as $NAME:0 - $NAME:m for m rows 501 502 // if CharAsVectors is selected, char fields will be saved as vectors NAME:0 -- NAME:n for n characters 503 473 504 // if (Ny > 10000), force CharAsVectors 474 505 int CharAsVectors = FALSE; … … 476 507 remove_argument (N, &argc, argv); 477 508 CharAsVectors = TRUE; 509 } 510 int CharAsList = FALSE; 511 if ((N = get_argument (argc, argv, "-char-list"))) { 512 remove_argument (N, &argc, argv); 513 CharAsList = TRUE; 478 514 } 479 515 … … 651 687 if (!FITS_TRANSPOSE) { 652 688 // read string column into a list rather than a vector 653 if (!strcmp (type, "char") && !CharAsVectors && (Ny < 3000)) { 654 char *fieldName = argv[i]; 655 char *Ptr = data; 656 char varname[1024]; // used as a buffer for the names of string fields 657 for (j = 0; j < Ny; j++) { 658 set_list_varname (varname, fieldName, j, FALSE); 659 char *value = strncreate (&Ptr[j*Nval], Nval); 660 // replace instances of $ with _ 661 char *p = strchr (value, '$'); 662 while (p) { 663 *p = '_'; 664 p = strchr (p, '$'); 689 if (!strcmp (type, "char")) { 690 // save char-type field as a List: 691 if (CharAsList && (Ny < 3000)) { 692 char *fieldName = argv[i]; 693 char *Ptr = data; 694 char varname[1024]; // used as a buffer for the names of string fields 695 for (j = 0; j < Ny; j++) { 696 set_list_varname (varname, fieldName, j, FALSE); 697 char *value = strncreate (&Ptr[j*Nval], Nval); 698 // replace instances of $ with _ 699 char *p = strchr (value, '$'); 700 while (p) { 701 *p = '_'; 702 p = strchr (p, '$'); 703 } 704 set_str_variable (varname, value); 705 free (value); 665 706 } 666 set_str_variable (varname, value); 667 free (value); 707 sprintf (varname, "%s:n", fieldName); 708 set_int_variable (varname, Ny); 709 continue; 668 710 } 669 sprintf (varname, "%s:n", fieldName); 670 set_int_variable (varname, Ny); 671 continue; 711 // save char-type field as a string-type vector: 712 if (!CharAsVectors) { 713 Vector *myVector = NULL; 714 sprintf (name, "%s", argv[i]); 715 if ((myVector = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n"); 716 ResetVector (myVector, OPIHI_STR, Ny); 717 718 char *Ptr = data; 719 for (j = 0; j < Ny; j++) { 720 myVector[0].elements.Str[j] = strncreate (&Ptr[j*Nval], Nval); 721 // replace instances of $ with _ 722 char *p = strchr (myVector[0].elements.Str[j], '$'); 723 while (p) { *p = '_'; p = strchr (p, '$'); } 724 } 725 continue; 726 } 672 727 } 673 728 674 729 // define the multifield vector names (Nval vectors x Ny elements) 730 // CharAsVectors is handled below automatically 675 731 ALLOCATE (vec, Vector *, Nval); 676 732 for (j = 0; j < Nval; j++) { -
trunk/Ohana/src/opihi/cmd.data/rotate.c
r41164 r41269 268 268 269 269 out_buff = (float *)buf[0].matrix.buffer; 270 270 271 for (j = 0; j < Ly; j++) { 271 272 for (i = 0; i < Lx; i++, out_buff++) { -
trunk/Ohana/src/opihi/cmd.data/tvcolors.c
r40626 r41269 37 37 gprint (GP_ERR, "USAGE: tvcolors (colormap) [-nan red green blue]\n"); 38 38 gprint (GP_ERR, " colormap options : greyscale, -greyscale, rainbow, heat, fullcolor, ruffcolor (also grayscale, -grayscale)\n"); 39 gprint (GP_ERR, " colormap file name of the for WORD:PATH where WORD = (file,csvf,lgcy,cetf)\n"); 40 gprint (GP_ERR, " lgcy:\n"); 41 gprint (GP_ERR, " the colormap file must contain 4 columns: f R B G; each line defines a color transition.\n"); 42 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 43 gprint (GP_ERR, " R,B,G: 0 - 1 define the value of the color at the transition point\n"); 44 gprint (GP_ERR, " file:\n"); 39 gprint (GP_ERR, " colormap file: if colormap name is given as file:path/to/file, the colormap is read from the file\n"); 45 40 gprint (GP_ERR, " the colormap file must contain 4 columns: f R G B; each line defines a color transition.\n"); 46 41 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 47 42 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n"); 48 gprint (GP_ERR, " csvf:\n");49 gprint (GP_ERR, " the colormap file must contain 4 columns: f,R,G,B separate by commas; each line defines a color transition.\n");50 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n");51 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n");52 gprint (GP_ERR, " cetf:\n");53 gprint (GP_ERR, " the colormap file must 256 rows contain 3 columns: R,G,B separate by commas; each line defines a color transition.\n");54 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n");55 gprint (GP_ERR, " CETF-format files can be found at : https://peterkovesi.com/projects/colourmaps\n");56 43 return (FALSE); 57 44 } -
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r41164 r41269 154 154 if (ADD_HEADER) { 155 155 for (j = 0; j < Nvec; j++) { 156 if (j == 0) fprintf (f, "# "); 156 157 if (CSV) { 157 158 fprintf (f, "%s,", vec[j][0].name); 158 159 } else { 159 if (j == 0) fprintf (f, "# ");160 160 fprintf (f, "%s ", vec[j][0].name); 161 161 } … … 166 166 /* default output format */ 167 167 if (format == (char *) NULL) { 168 char padChar = CSV ? ',' : ' '; 168 169 for (i = 0; i < vec[0][0].Nelements; i++) { 169 170 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; 182 181 } 183 182 } … … 226 225 fmttype[j] = 'd'; 227 226 break; 227 case 's': 228 fmttype[j] = 's'; 229 break; 228 230 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"); 230 232 return (FALSE); 231 233 } … … 234 236 strcat (fmtlist[Nvec-1], p0); 235 237 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 236 257 for (i = 0; i < vec[0][0].Nelements; i++) { 237 258 for (j = 0; j < Nvec; j++) { … … 249 270 fprintf (f, fmtlist[j], (opihi_flt)(vec[j][0].elements.Int[i])); 250 271 } 272 } 273 if (fmttype[j] == 's') { 274 fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]); 251 275 } 252 276 }
Note:
See TracChangeset
for help on using the changeset viewer.
