IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36941


Ignore:
Timestamp:
Jun 30, 2014, 9:36:25 PM (12 years ago)
Author:
eugene
Message:

add strmatch (find character class) and print_vectors functions; add read into list from fits or text

Location:
branches/eam_branches/ipp-20140610/Ohana/src/opihi
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.basic/Makefile

    r35237 r36941  
    5555$(SRC)/substr.$(ARCH).o     \
    5656$(SRC)/strhash.$(ARCH).o     \
     57$(SRC)/strmatch.$(ARCH).o     \
    5758$(SRC)/strpop.$(ARCH).o     \
    5859$(SRC)/strsub.$(ARCH).o     \
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.basic/init.c

    r35237 r36941  
    4040int fprintf_opihi   PROTO((int, char **));
    4141int strlen_func     PROTO((int, char **));
     42int strmatch        PROTO((int, char **));
    4243int substr_func     PROTO((int, char **));
    4344int strpop          PROTO((int, char **));
     
    9798  {1, "strpop",        strpop,             "pop a string"},
    9899  {1, "strsub",        strsub,             "replace instances of a key in a string"},
     100  {1, "strmatch",      strmatch,           "string length"},
    99101  {1, "wait",          wait_func,          "wait until return is typed"},
    100102  {1, "which",         which,              "show command *"}
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.basic/list.c

    r36084 r36941  
    22# define D_NLINES 100
    33static char prompt[] = ">> ";
    4 
    5 static int set_list_varname (char *line, char *base, int N, int excelStyle);
    64
    75int list (int argc, char **argv) {
     
    311309  return (TRUE);
    312310}
    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 - 25
    319 
    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  
    9898$(SRC)/point.$(ARCH).o          \
    9999$(SRC)/ps.$(ARCH).o             \
     100$(SRC)/print_vectors.$(ARCH).o  \
    100101$(SRC)/queuedelete.$(ARCH).o    \
    101102$(SRC)/queuedrop.$(ARCH).o      \
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.data/init.c

    r36679 r36941  
    8787int point            PROTO((int, char **));
    8888int ps               PROTO((int, char **));
     89int print_vectors    PROTO((int, char **));
    8990int queuelist        PROTO((int, char **));
    9091int queueload        PROTO((int, char **));
     
    250251  {1, "ppm",          jpeg,             "convert display graphic to PPM"},
    251252  {1, "ps",           ps,               "convert display to PostScript"},
     253  {1, "print_vectors", print_vectors,   "print a set of vectors"},
    252254  {1, "queuedelete",  queuedelete,      "delete a queue"},
    253255  {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  
    33FILE *f = (FILE *) NULL;
    44char filename[2048];
     5
     6void read_vectors_cleanup ();
    57
    68int datafile (int argc, char **argv) {
     
    2325// vector types
    2426enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR};
    25 static int FITS_TRANSPOSE;
     27
     28static int      Nvec     = 0;
     29static Vector **vec      = NULL;
     30static char   **listname = NULL;
     31static int     *col      = NULL;
     32static int     *coltype  = NULL;
     33static char    *buffer   = NULL;
    2634
    2735int read_vectors (int argc, char **argv) {
     
    2937  int TimeFormat;
    3038  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;
    3341  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
    4343
    4444  /* auto-sense table type */
     
    8888
    8989  Nvec = (argc - 1) / 2;
     90  ALLOCATE (listname, char *, Nvec);
    9091  ALLOCATE (vec, Vector *, Nvec);
    9192  ALLOCATE (col, int, Nvec);
    9293  ALLOCATE (coltype, int, Nvec);
     94  for (i = 0; i < Nvec; i++) {
     95    listname[i] = NULL;
     96    vec[i] = NULL;
     97  }
    9398
    9499  for (i = 0; i < Nvec; i++) {
     
    115120    }
    116121
    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      }
    122130    }
    123131
     
    144152    bad_colname:
    145153      gprint (GP_ERR, "USAGE: read name N name N ...\n");
    146       free (vec);
    147       free (col);
     154      read_vectors_cleanup();
    148155      return (FALSE);   
    149156    }
     
    153160  NELEM = 1000;
    154161  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;
    160174    }
    161175  }
     
    166180    if (scan_line_maxlen (f, buffer, 0x10000) == EOF) {
    167181      gprint (GP_ERR, "problem reading file %s\n", filename);
    168       free (vec);
    169       free (col);
     182      read_vectors_cleanup();
    170183      return FALSE;
    171184    }
     
    213226      for (i = 0; i < Nvec; i++) {
    214227        int ivalue;
    215         char cvalue;
    216228        double dvalue;
    217229        time_t tvalue;
     
    224236            break;
    225237          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            }
    229255          case COLTYPE_FLT:
    230256            readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0);
     
    256282        NELEM += 1000;
    257283        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;
    262295          }
    263296        }
     
    266299    }
    267300  }
     301  // set the final vector / list length
    268302  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();
    280320  return (TRUE);
    281 
    282321}
    283322
     
    297336  Header header;
    298337  Vector **vec;
     338  int FITS_TRANSPOSE;
    299339
    300340  table.buffer = NULL;
    301341  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  }
    302348
    303349  CCDKeyword = NULL;
     
    418464       
    419465    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
    420488      // define the multifield vector names (Nval vectors x Ny elements)
    421489      ALLOCATE (vec, Vector *, Nval);
     
    429497      }
    430498
    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       }
    439499      if (!strcmp (type, "short")) {
    440500        short *Ptr = data;
     
    546606  return (TRUE);
    547607}
     608
     609void 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  
    166166// wrap readline in ohana mem functions:
    167167char         *opihi_readline            PROTO((char *prompt));
     168
     169int set_list_varname (char *line, char *base, int N, int excelStyle);
    168170
    169171/* gprint functions */
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/lib.shell/string.c

    r33662 r36941  
    322322}
    323323
     324int 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.