Changeset 36941
- Timestamp:
- Jun 30, 2014, 9:36:25 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-20140610/Ohana/src/opihi
- Files:
-
- 2 added
- 8 edited
-
cmd.basic/Makefile (modified) (1 diff)
-
cmd.basic/init.c (modified) (2 diffs)
-
cmd.basic/list.c (modified) (2 diffs)
-
cmd.basic/strmatch.c (added)
-
cmd.data/Makefile (modified) (1 diff)
-
cmd.data/init.c (modified) (2 diffs)
-
cmd.data/print_vectors.c (added)
-
cmd.data/read_vectors.c (modified) (16 diffs)
-
include/shell.h (modified) (1 diff)
-
lib.shell/string.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.basic/Makefile
r35237 r36941 55 55 $(SRC)/substr.$(ARCH).o \ 56 56 $(SRC)/strhash.$(ARCH).o \ 57 $(SRC)/strmatch.$(ARCH).o \ 57 58 $(SRC)/strpop.$(ARCH).o \ 58 59 $(SRC)/strsub.$(ARCH).o \ -
branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.basic/init.c
r35237 r36941 40 40 int fprintf_opihi PROTO((int, char **)); 41 41 int strlen_func PROTO((int, char **)); 42 int strmatch PROTO((int, char **)); 42 43 int substr_func PROTO((int, char **)); 43 44 int strpop PROTO((int, char **)); … … 97 98 {1, "strpop", strpop, "pop a string"}, 98 99 {1, "strsub", strsub, "replace instances of a key in a string"}, 100 {1, "strmatch", strmatch, "string length"}, 99 101 {1, "wait", wait_func, "wait until return is typed"}, 100 102 {1, "which", which, "show command *"} -
branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.basic/list.c
r36084 r36941 2 2 # define D_NLINES 100 3 3 static char prompt[] = ">> "; 4 5 static int set_list_varname (char *line, char *base, int N, int excelStyle);6 4 7 5 int list (int argc, char **argv) { … … 311 309 return (TRUE); 312 310 } 313 314 static int set_list_varname (char *line, char *base, int N, int excelStyle) {315 316 int i;317 318 // A-Z correspond to 0 - 25319 320 if (excelStyle) {321 float f = log(26.0);322 float g = (N == 0) ? 0.0 : log(1.0*N);323 int Ndigit = (int) (g / f) + 1;324 if (Ndigit > 10) {325 sprintf (line, "%s:ZZZZZZZZZZ", base);326 return FALSE;327 }328 char name[12];329 memset (name, 0, 12);330 for (i = 0; i < Ndigit; i++) {331 float Npow = Ndigit - i - 1;332 float g = pow(26.0, Npow);333 int V = (int) (N / g);334 name[i] = (Npow == 0.0) ? 'A' + V : 'A' + V - 1;335 N -= V * g;336 }337 sprintf (line, "%s:%s", base, name);338 } else {339 sprintf (line, "%s:%d", base, N);340 }341 return TRUE;342 } -
branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.data/Makefile
r36679 r36941 98 98 $(SRC)/point.$(ARCH).o \ 99 99 $(SRC)/ps.$(ARCH).o \ 100 $(SRC)/print_vectors.$(ARCH).o \ 100 101 $(SRC)/queuedelete.$(ARCH).o \ 101 102 $(SRC)/queuedrop.$(ARCH).o \ -
branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.data/init.c
r36679 r36941 87 87 int point PROTO((int, char **)); 88 88 int ps PROTO((int, char **)); 89 int print_vectors PROTO((int, char **)); 89 90 int queuelist PROTO((int, char **)); 90 91 int queueload PROTO((int, char **)); … … 250 251 {1, "ppm", jpeg, "convert display graphic to PPM"}, 251 252 {1, "ps", ps, "convert display to PostScript"}, 253 {1, "print_vectors", print_vectors, "print a set of vectors"}, 252 254 {1, "queuedelete", queuedelete, "delete a queue"}, 253 255 {1, "queuedrop", queuedrop, "drop values from queue matching a key"}, -
branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.data/read_vectors.c
r36375 r36941 3 3 FILE *f = (FILE *) NULL; 4 4 char filename[2048]; 5 6 void read_vectors_cleanup (); 5 7 6 8 int datafile (int argc, char **argv) { … … 23 25 // vector types 24 26 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR}; 25 static int FITS_TRANSPOSE; 27 28 static int Nvec = 0; 29 static Vector **vec = NULL; 30 static char **listname = NULL; 31 static int *col = NULL; 32 static int *coltype = NULL; 33 static char *buffer = NULL; 26 34 27 35 int read_vectors (int argc, char **argv) { … … 29 37 int TimeFormat; 30 38 time_t TimeReference; 31 int i, j, Nskip, Narg, Nvec, *col,IsCSV, VERBOSE;32 int Nbytes, Nstart, NELEM, Nelem, nread , *coltype;39 int i, j, Nskip, Narg, IsCSV, VERBOSE; 40 int Nbytes, Nstart, NELEM, Nelem, nread; 33 41 char *colstr, *c0, *c1, *extname; 34 Vector **vec; 35 36 char *buffer = NULL; 37 38 FITS_TRANSPOSE = FALSE; 39 if ((Narg = get_argument (argc, argv, "-transpose"))) { 40 remove_argument (Narg, &argc, argv); 41 FITS_TRANSPOSE = TRUE; 42 } 42 char varname[1024]; // used as a buffer for the names of string fields 43 43 44 44 /* auto-sense table type */ … … 88 88 89 89 Nvec = (argc - 1) / 2; 90 ALLOCATE (listname, char *, Nvec); 90 91 ALLOCATE (vec, Vector *, Nvec); 91 92 ALLOCATE (col, int, Nvec); 92 93 ALLOCATE (coltype, int, Nvec); 94 for (i = 0; i < Nvec; i++) { 95 listname[i] = NULL; 96 vec[i] = NULL; 97 } 93 98 94 99 for (i = 0; i < Nvec; i++) { … … 115 120 } 116 121 117 if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) { 118 gprint (GP_ERR, "USAGE: read name N name N ...\n"); 119 free (vec); 120 free (col); 121 return (FALSE); 122 if (coltype[i] == COLTYPE_CHAR) { 123 listname[i] = strcreate (argv[2*i + 1]); 124 } else { 125 if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) { 126 gprint (GP_ERR, "USAGE: read name N name N ...\n"); 127 read_vectors_cleanup(); 128 return (FALSE); 129 } 122 130 } 123 131 … … 144 152 bad_colname: 145 153 gprint (GP_ERR, "USAGE: read name N name N ...\n"); 146 free (vec); 147 free (col); 154 read_vectors_cleanup(); 148 155 return (FALSE); 149 156 } … … 153 160 NELEM = 1000; 154 161 for (i = 0; i < Nvec; i++) { 155 if ((coltype[i] == COLTYPE_INT) || (coltype[i] == COLTYPE_CHAR)) { 156 ResetVector (vec[i], OPIHI_INT, NELEM); 157 } else { 158 // note that COLTYPE_TIME is a type of float 159 ResetVector (vec[i], OPIHI_FLT, NELEM); 162 switch (coltype[i]) { 163 case COLTYPE_INT: 164 ResetVector (vec[i], OPIHI_INT, NELEM); 165 break; 166 case COLTYPE_FLT: 167 case COLTYPE_TIME: 168 // note that COLTYPE_TIME is a type of float 169 ResetVector (vec[i], OPIHI_FLT, NELEM); 170 break; 171 case COLTYPE_CHAR: 172 default: 173 break; 160 174 } 161 175 } … … 166 180 if (scan_line_maxlen (f, buffer, 0x10000) == EOF) { 167 181 gprint (GP_ERR, "problem reading file %s\n", filename); 168 free (vec); 169 free (col); 182 read_vectors_cleanup(); 170 183 return FALSE; 171 184 } … … 213 226 for (i = 0; i < Nvec; i++) { 214 227 int ivalue; 215 char cvalue;216 228 double dvalue; 217 229 time_t tvalue; … … 224 236 break; 225 237 case COLTYPE_CHAR: 226 readStatus = IsCSV ? charparse_csv (&cvalue, col[i], c0) : charparse (&cvalue, col[i], c0); 227 vec[i][0].elements.Int[Nelem] = readStatus ? cvalue : 0; 228 break; 238 { 239 // I need to get an isolated word in 'value' with the string value of this field 240 char *ptr = IsCSV ? ptrparse_csv (col[i], c0) : ptrparse (col[i], c0); 241 char *value = NULL; 242 if (IsCSV) { 243 char *end = parse_nextword_csv (ptr); 244 if (end) { 245 value = end ? strncreate (ptr, end - ptr) : strcreate (ptr); 246 } 247 } else { 248 value = thisword(ptr); 249 } 250 set_list_varname (varname, listname[i], Nelem, FALSE); 251 set_str_variable (varname, value); 252 free (value); 253 break; 254 } 229 255 case COLTYPE_FLT: 230 256 readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0); … … 256 282 NELEM += 1000; 257 283 for (i = 0; i < Nvec; i++) { 258 if (coltype[i] == COLTYPE_INT) { 259 REALLOCATE (vec[i][0].elements.Int, opihi_int, NELEM); 260 } else { 261 REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM); 284 switch (coltype[i]) { 285 case COLTYPE_INT: 286 ResetVector (vec[i], OPIHI_INT, NELEM); 287 break; 288 case COLTYPE_FLT: 289 case COLTYPE_TIME: 290 ResetVector (vec[i], OPIHI_FLT, NELEM); 291 break; 292 case COLTYPE_CHAR: 293 default: 294 break; 262 295 } 263 296 } … … 266 299 } 267 300 } 301 // set the final vector / list length 268 302 for (i = 0; i < Nvec; i++) { 269 if (coltype[i] == COLTYPE_INT) { 270 REALLOCATE (vec[i][0].elements.Int, opihi_int, MAX (Nelem,1)); 271 } else { 272 REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (Nelem,1)); 273 } 274 vec[i][0].Nelements = Nelem; 275 } 276 277 free (vec); 278 free (col); 279 if (buffer) free (buffer); 303 switch (coltype[i]) { 304 case COLTYPE_INT: 305 ResetVector (vec[i], OPIHI_INT, Nelem); 306 break; 307 case COLTYPE_FLT: 308 case COLTYPE_TIME: 309 ResetVector (vec[i], OPIHI_FLT, Nelem); 310 break; 311 case COLTYPE_CHAR: 312 sprintf (varname, "%s:n", listname[i]); 313 set_int_variable (varname, Nelem); 314 break; 315 default: 316 break; 317 } 318 } 319 read_vectors_cleanup(); 280 320 return (TRUE); 281 282 321 } 283 322 … … 297 336 Header header; 298 337 Vector **vec; 338 int FITS_TRANSPOSE; 299 339 300 340 table.buffer = NULL; 301 341 header.buffer = NULL; 342 343 FITS_TRANSPOSE = FALSE; 344 if ((N = get_argument (argc, argv, "-transpose"))) { 345 remove_argument (N, &argc, argv); 346 FITS_TRANSPOSE = TRUE; 347 } 302 348 303 349 CCDKeyword = NULL; … … 418 464 419 465 if (!FITS_TRANSPOSE) { 466 // read string column into a list rather than a vector 467 if (!strcmp (type, "char")) { 468 char *fieldName = argv[i]; 469 char *Ptr = data; 470 char varname[1024]; // used as a buffer for the names of string fields 471 for (j = 0; j < Ny; j++) { 472 set_list_varname (varname, fieldName, j, FALSE); 473 char *value = strncreate (&Ptr[j*Nval], Nval); 474 // replace instances of $ with _ 475 char *p = strchr (value, '$'); 476 while (p) { 477 *p = '_'; 478 p = strchr (p, '$'); 479 } 480 set_str_variable (varname, value); 481 free (value); 482 } 483 sprintf (varname, "%s:n", fieldName); 484 set_int_variable (varname, Ny); 485 continue; 486 } 487 420 488 // define the multifield vector names (Nval vectors x Ny elements) 421 489 ALLOCATE (vec, Vector *, Nval); … … 429 497 } 430 498 431 if (!strcmp (type, "char")) {432 char *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 499 if (!strcmp (type, "short")) { 440 500 short *Ptr = data; … … 546 606 return (TRUE); 547 607 } 608 609 void read_vectors_cleanup () { 610 611 int i; 612 613 if (col) free (col); 614 if (coltype) free (coltype); 615 if (buffer) free (buffer); 616 if (listname) { 617 for (i = 0; i < Nvec; i++) { 618 if (listname[i]) free (listname[i]); 619 } 620 free (listname); 621 } 622 if (vec) free (vec); 623 } -
branches/eam_branches/ipp-20140610/Ohana/src/opihi/include/shell.h
r33662 r36941 166 166 // wrap readline in ohana mem functions: 167 167 char *opihi_readline PROTO((char *prompt)); 168 169 int set_list_varname (char *line, char *base, int N, int excelStyle); 168 170 169 171 /* gprint functions */ -
branches/eam_branches/ipp-20140610/Ohana/src/opihi/lib.shell/string.c
r33662 r36941 322 322 } 323 323 324 int set_list_varname (char *line, char *base, int N, int excelStyle) { 325 326 int i; 327 328 // A-Z correspond to 0 - 25 329 330 if (excelStyle) { 331 float f = log(26.0); 332 float g = (N == 0) ? 0.0 : log(1.0*N); 333 int Ndigit = (int) (g / f) + 1; 334 if (Ndigit > 10) { 335 sprintf (line, "%s:ZZZZZZZZZZ", base); 336 return FALSE; 337 } 338 char name[12]; 339 memset (name, 0, 12); 340 for (i = 0; i < Ndigit; i++) { 341 float Npow = Ndigit - i - 1; 342 float g = pow(26.0, Npow); 343 int V = (int) (N / g); 344 name[i] = (Npow == 0.0) ? 'A' + V : 'A' + V - 1; 345 N -= V * g; 346 } 347 sprintf (line, "%s:%s", base, name); 348 } else { 349 sprintf (line, "%s:%d", base, N); 350 } 351 return TRUE; 352 }
Note:
See TracChangeset
for help on using the changeset viewer.
