IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36375 for trunk/Ohana


Ignore:
Timestamp:
Dec 10, 2013, 2:55:11 PM (13 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-20130904

Location:
trunk
Files:
26 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Ohana

  • trunk/Ohana/src/dvomerge

  • trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r36188 r36375  
    202202
    203203  // PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    204   PrintIOBuffer (buffer, "INSERT IGNORE INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
     204  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
    205205
    206206  return TRUE;
  • trunk/Ohana/src/libohana/src

  • trunk/Ohana/src/opihi

  • trunk/Ohana/src/opihi/cmd.astro

  • trunk/Ohana/src/opihi/cmd.astro/fitplx.c

    r35416 r36375  
    4141    remove_argument (N, &argc, argv);
    4242    VERBOSE = TRUE;
     43  }
     44  if ((N = get_argument (argc, argv, "-vv"))) {
     45    remove_argument (N, &argc, argv);
     46    VERBOSE = 2;
    4347  }
    4448
     
    145149
    146150  PlxFit fit;
    147   FitPMandPar (&fit, X, dX, Y, dY, t, pX, pY, n, VERBOSE);
     151  if (!FitPMandPar (&fit, X, dX, Y, dY, t, pX, pY, n, VERBOSE)) {
     152    return FALSE;
     153  }
    148154
    149155  // fprintf (stderr, "Roff, Doff: %f, %f; dRo, dDo: %f, %f\n", fit.Ro, fit.Do, fit.dRo, fit.dDo);
     
    204210  for (i = 0; i < Npts; i++) {
    205211
    206     if (VERBOSE) fprintf (stderr, "%f %f : %f %f : %f : %f %f\n", X[i], dX[i], Y[i], dY[i], T[i], pR[i], pD[i]);
     212    if (VERBOSE == 2) fprintf (stderr, "%f %f : %f %f : %f : %f %f\n", X[i], dX[i], Y[i], dY[i], T[i], pR[i], pD[i]);
    207213
    208214    /* handle case where dX or dY = 0.0 */
    209     wx = 1.0 / SQ(dX[i]);
    210     wy = 1.0 / SQ(dY[i]);
     215    wx = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
     216    wy = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
    211217
    212218    Wx += wx;
     
    266272  B[4][0] = PRX + PDY;
    267273
    268   dgaussjordan ((double **)A, (double **)B, 5, 1);
     274  if (!dgaussjordan ((double **)A, (double **)B, 5, 1)) {
     275    if (VERBOSE) fprintf (stderr, "error in fit\n");
     276    if (VERBOSE == 2) {
     277      int j;
     278      for (i = 0; i < 5; i++) {
     279        for (j = 0; j < 5; j++) {
     280          fprintf (stderr, "%e ", A[i][j]);
     281        }
     282        fprintf (stderr, " : %e\n", A[i][0]);
     283      }
     284    }
     285    return FALSE;
     286  }
    269287
    270288  fit[0].Ro = B[0][0];
     
    285303    Xf = fit[0].Ro + fit[0].uR*T[i] + fit[0].p*pR[i];
    286304    Yf = fit[0].Do + fit[0].uD*T[i] + fit[0].p*pD[i];
    287     chisq += SQ(X[i] - Xf) / SQ(dX[i]);
    288     chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
    289     if (VERBOSE) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
     305    wx = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
     306    wy = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
     307    chisq += SQ(X[i] - Xf) * wx;
     308    chisq += SQ(Y[i] - Yf) * wy;
     309    // if (VERBOSE) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
    290310  }
    291311  fit[0].Nfit = Npts;
  • trunk/Ohana/src/opihi/cmd.data

  • trunk/Ohana/src/opihi/cmd.data/Makefile

    r36084 r36375  
    6464$(SRC)/imhist.$(ARCH).o \
    6565$(SRC)/imsmooth.$(ARCH).o       \
     66$(SRC)/imsmooth.generic.$(ARCH).o       \
     67$(SRC)/imsmooth.2d.$(ARCH).o    \
    6668$(SRC)/integrate.$(ARCH).o      \
    6769$(SRC)/interpolate.$(ARCH).o    \
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r36084 r36375  
    5353int imhist           PROTO((int, char **));
    5454int imsmooth         PROTO((int, char **));
     55int imsmooth_generic PROTO((int, char **));
     56int imsmooth_2d      PROTO((int, char **));
    5557int integrate        PROTO((int, char **));
    5658int interpolate      PROTO((int, char **));
     
    208210  {1, "imhistogram",  imhist,           "histogram of an image region"},
    209211  {1, "imsmooth",     imsmooth,         "circular gaussian smoothing"},
     212  {1, "imsmooth.generic", imsmooth_generic, "circular non-gaussian smoothing"},
     213  {1, "imsmooth.2d",  imsmooth_2d,      "circular non-gaussian smoothing"},
    210214  {1, "imstats",      imstats,          "statistics on a portion of an image"},
    211215  {1, "integrate",    integrate,        "integrate a vector"},
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r34753 r36375  
    2323// vector types
    2424enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR};
     25static int FITS_TRANSPOSE;
    2526
    2627int read_vectors (int argc, char **argv) {
     
    3435
    3536  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  }
    3643
    3744  /* auto-sense table type */
     
    410417    }
    411418       
    412     // define the multifield vector names
    413     ALLOCATE (vec, Vector *, Nval);
    414     for (j = 0; j < Nval; j++) {
    415       if (Nval == 1)
    416         sprintf (name, "%s", argv[i]);
    417       else
    418         sprintf (name, "%s:%d", argv[i], j);
    419       if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
    420       ResetVector (vec[j], vecType, Ny);
    421     }
    422 
    423     if (!strcmp (type, "char")) {
    424       char *Ptr = data;
     419    if (!FITS_TRANSPOSE) {
     420      // define the multifield vector names (Nval vectors x Ny elements)
     421      ALLOCATE (vec, Vector *, Nval);
     422      for (j = 0; j < Nval; j++) {
     423        if (Nval == 1)
     424          sprintf (name, "%s", argv[i]);
     425        else
     426          sprintf (name, "%s:%d", argv[i], j);
     427        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     428        ResetVector (vec[j], vecType, Ny);
     429      }
     430
     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      if (!strcmp (type, "short")) {
     440        short *Ptr = data;
     441        for (j = 0; j < Ny; j++) {
     442          for (k = 0; k < Nval; k++, Ptr++) {
     443            vec[k][0].elements.Int[j] = *Ptr;
     444          }
     445        }
     446      }
     447      if (!strcmp (type, "int")) {
     448        int *Ptr = data;
     449        for (j = 0; j < Ny; j++) {
     450          for (k = 0; k < Nval; k++, Ptr++) {
     451            vec[k][0].elements.Int[j] = *Ptr;
     452          }
     453        }
     454      }
     455      if (!strcmp (type, "int64_t")) {
     456        int64_t *Ptr = data;
     457        for (j = 0; j < Ny; j++) {
     458          for (k = 0; k < Nval; k++, Ptr++) {
     459            vec[k][0].elements.Int[j] = *Ptr;
     460          }
     461        }
     462      }
     463      if (!strcmp (type, "float")) {
     464        float *Ptr = data;
     465        for (j = 0; j < Ny; j++) {
     466          for (k = 0; k < Nval; k++, Ptr++) {
     467            vec[k][0].elements.Flt[j] = *Ptr;
     468          }
     469        }
     470      }
     471      if (!strcmp (type, "double")) {
     472        double *Ptr = data;
     473        for (j = 0; j < Ny; j++) {
     474          for (k = 0; k < Nval; k++, Ptr++) {
     475            vec[k][0].elements.Flt[j] = *Ptr;
     476          }
     477        }
     478      }
     479    } else {
     480      // define the multifield vector names (Ny vectors x Nval elements)
     481      ALLOCATE (vec, Vector *, Ny);
    425482      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, "short")) {
    432       short *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, "int")) {
    440       int *Ptr = data;
    441       for (j = 0; j < Ny; j++) {
    442         for (k = 0; k < Nval; k++, Ptr++) {
    443           vec[k][0].elements.Int[j] = *Ptr;
    444         }
    445       }
    446     }
    447     if (!strcmp (type, "int64_t")) {
    448       int64_t *Ptr = data;
    449       for (j = 0; j < Ny; j++) {
    450         for (k = 0; k < Nval; k++, Ptr++) {
    451           vec[k][0].elements.Int[j] = *Ptr;
    452         }
    453       }
    454     }
    455     if (!strcmp (type, "float")) {
    456       float *Ptr = data;
    457       for (j = 0; j < Ny; j++) {
    458         for (k = 0; k < Nval; k++, Ptr++) {
    459           vec[k][0].elements.Flt[j] = *Ptr;
    460         }
    461       }
    462     }
    463     if (!strcmp (type, "double")) {
    464       double *Ptr = data;
    465       for (j = 0; j < Ny; j++) {
    466         for (k = 0; k < Nval; k++, Ptr++) {
    467           vec[k][0].elements.Flt[j] = *Ptr;
     483        if (Ny == 1)
     484          sprintf (name, "%s", argv[i]);
     485        else
     486          sprintf (name, "%s:%d", argv[i], j);
     487        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     488        ResetVector (vec[j], vecType, Nval);
     489      }
     490
     491      if (!strcmp (type, "char")) {
     492        char *Ptr = data;
     493        for (j = 0; j < Ny; j++) {
     494          for (k = 0; k < Nval; k++, Ptr++) {
     495            vec[j][0].elements.Int[k] = *Ptr;
     496          }
     497        }
     498      }
     499      if (!strcmp (type, "short")) {
     500        short *Ptr = data;
     501        for (j = 0; j < Ny; j++) {
     502          for (k = 0; k < Nval; k++, Ptr++) {
     503            vec[j][0].elements.Int[k] = *Ptr;
     504          }
     505        }
     506      }
     507      if (!strcmp (type, "int")) {
     508        int *Ptr = data;
     509        for (j = 0; j < Ny; j++) {
     510          for (k = 0; k < Nval; k++, Ptr++) {
     511            vec[j][0].elements.Int[k] = *Ptr;
     512          }
     513        }
     514      }
     515      if (!strcmp (type, "int64_t")) {
     516        int64_t *Ptr = data;
     517        for (j = 0; j < Ny; j++) {
     518          for (k = 0; k < Nval; k++, Ptr++) {
     519            vec[j][0].elements.Int[k] = *Ptr;
     520          }
     521        }
     522      }
     523      if (!strcmp (type, "float")) {
     524        float *Ptr = data;
     525        for (j = 0; j < Ny; j++) {
     526          for (k = 0; k < Nval; k++, Ptr++) {
     527            vec[j][0].elements.Flt[k] = *Ptr;
     528          }
     529        }
     530      }
     531      if (!strcmp (type, "double")) {
     532        double *Ptr = data;
     533        for (j = 0; j < Ny; j++) {
     534          for (k = 0; k < Nval; k++, Ptr++) {
     535            vec[j][0].elements.Flt[k] = *Ptr;
     536          }
    468537        }
    469538      }
  • trunk/Ohana/src/opihi/dvo/Makefile

    r34461 r36375  
    4040$(SRC)/cmpload.$(ARCH).o                \
    4141$(SRC)/cmpread.$(ARCH).o                \
     42$(SRC)/coordimage.$(ARCH).o             \
    4243$(SRC)/ddmags.$(ARCH).o         \
    4344$(SRC)/detrend.$(ARCH).o                \
  • trunk/Ohana/src/opihi/dvo/init.c

    r34461 r36375  
    1313int cmpload         PROTO((int, char **));
    1414int cmpread         PROTO((int, char **));
     15int coordimage      PROTO((int, char **));
    1516int ddmags          PROTO((int, char **));
    1617int detrend         PROTO((int, char **));
     
    7172  {1, "cmpload",     cmpload,      "load cmp file into ?"},
    7273  {1, "cmpread",     cmpread,      "read data from cmp format files"},
     74  {1, "coordimage",  coordimage,   "generate a map of the transformation residuals"},
    7375  {1, "ddmags",      ddmags,       "plot magnitude differences"},
    7476  {1, "detrend",     detrend,      "extract from detrend database?"},
  • trunk/Ohana/src/opihi/include/dvomath.h

    r33662 r36375  
    5555} Buffer;
    5656
     57typedef enum {
     58  ST_NONE,
     59  ST_LEFT,
     60  ST_RIGHT,
     61  ST_COMMA,
     62  ST_TRINARY,
     63  ST_OR,
     64  ST_AND,
     65  ST_LOGIC,
     66  ST_BITWISE,
     67  ST_ADD,
     68  ST_TIMES,
     69  ST_POWER,
     70  ST_UNARY,
     71  ST_BINARY,
     72
     73  ST_VALUE,
     74  ST_SCALAR_INT,
     75  ST_SCALAR_FLT,
     76  ST_VECTOR,
     77  ST_VECTOR_TMP,
     78  ST_MATRIX,
     79  ST_MATRIX_TMP,
     80
     81  ST_STRING,
     82  ST_STRING_TMP,
     83} StackVarType;
     84
    5785typedef struct {                        /* math stack structure */
    5886  char   *name;
    59   char    type;
     87  StackVarType type;
    6088  Buffer *buffer;
    6189  Vector *vector;
     
    77105void          delete_stack          PROTO((StackVar *stack, int Nstack));
    78106void          clear_stack           PROTO((StackVar *stack));
    79 void          assign_stack          PROTO((StackVar *stack, char *name, int type));
     107void          assign_stack          PROTO((StackVar *stack, char *name, StackVarType type));
     108
     109int           SSS_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
     110int           VVV_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
     111int           MMM_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
    80112
    81113int           VV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
  • trunk/Ohana/src/opihi/include/pcontrol.h

    r33662 r36375  
    88/** job status values **/
    99typedef enum {
     10  PCONTROL_JOB_NONE, // XXX OK?
    1011  PCONTROL_JOB_ALLJOBS,
    1112  PCONTROL_JOB_PENDING,
     
    309310char  *GetJobStackName (int StackID);
    310311Stack *GetJobStackByName (char *name);
     312int GetJobStackIDbyName (char *name);
    311313int    PutJob (Job *job, int StackID, int where);
    312314int    PutJobSetState (Job *job, int StackID, int where, int state);
  • trunk/Ohana/src/opihi/lib.shell/check_stack.c

    r34260 r36375  
    1212
    1313  for (i = 0; i < Nstack; i++) {
    14     if (stack[i].type == 'X') {
     14    if (stack[i].type == ST_VALUE) {
    1515
    1616      /** if this is a number, put it on the list of scalars and move on.  assume value is
     
    2727      stack[i].IntValue = strtol (stack[i].name, &c2, 0);
    2828      if ((fabs(stack[i].FltValue) > MAX_INT) && (c1 == stack[i].name + strlen (stack[i].name))) {
    29         stack[i].type  = 'S'; // 'S' == (float)
     29        stack[i].type  = ST_SCALAR_FLT; // (float)
    3030        continue;
    3131      }
    3232      if (c2 == stack[i].name + strlen (stack[i].name)) {
    33         stack[i].type  = 's'; // 's' == (int)
     33        stack[i].type  = ST_SCALAR_INT; // (int)
    3434        continue;
    3535      }
    3636      if (c1 == stack[i].name + strlen (stack[i].name)) {
    37         stack[i].type  = 'S'; // 'S' == (float)
     37        stack[i].type  = ST_SCALAR_FLT; // (float)
    3838        continue;
    3939      }
     
    4242      if (IsBuffer (stack[i].name)) {
    4343        stack[i].buffer = SelectBuffer (stack[i].name, OLDBUFFER, TRUE);
    44         stack[i].type   = 'M';
     44        stack[i].type   = ST_MATRIX;
    4545        if (Nx == -1) {
    4646          Nx = stack[i].buffer[0].matrix.Naxis[0];
     
    6363      if (IsVector (stack[i].name)) {
    6464        stack[i].vector = SelectVector (stack[i].name, OLDVECTOR, FALSE);
    65         stack[i].type   = 'V';
     65        stack[i].type   = ST_VECTOR;
    6666
    6767        if (Nv == -1) Nv = stack[i].vector[0].Nelements;
     
    8080
    8181      /* this is not a scalar, vector, or matrix.  must be string */
    82       stack[i].type  = 'W';
     82      stack[i].type  = ST_STRING;
    8383    }
    8484  }
  • trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r34088 r36375  
    44StackVar *convert_to_RPN (int argc, char **argv, int *nstack) {
    55 
    6   int type;
     6 StackVarType type;
    77  int i, j, Nstack, Nop_stack, NSTACK;
    88  StackVar *stack, *op_stack;
     
    2121   
    2222    /* decide on priority of object */
    23     type = 0;
     23    type = ST_NONE;
     24
     25    /* trinary operations */
     26    if (!strcmp (argv[i], "?"))      { type = ST_TRINARY; goto gotit; }
     27    if (!strcmp (argv[i], ":"))      { type = ST_COMMA; goto gotit; }
     28
    2429    /* unary operations */
    25     if (!strcmp (argv[i], "abs"))    { type = 9; goto gotit; }
    26     if (!strcmp (argv[i], "int"))    { type = 9; goto gotit; }
    27     if (!strcmp (argv[i], "exp"))    { type = 9; goto gotit; }
    28     if (!strcmp (argv[i], "ten"))    { type = 9; goto gotit; }
    29     if (!strcmp (argv[i], "log"))    { type = 9; goto gotit; }
    30     if (!strcmp (argv[i], "ln"))     { type = 9; goto gotit; }
    31     if (!strcmp (argv[i], "sqrt"))   { type = 9; goto gotit; }
    32     if (!strcmp (argv[i], "erf"))    { type = 9; goto gotit; }
    33 
    34     if (!strcmp (argv[i], "sinh"))   { type = 9; goto gotit; }
    35     if (!strcmp (argv[i], "cosh"))   { type = 9; goto gotit; }
    36     if (!strcmp (argv[i], "asinh"))  { type = 9; goto gotit; }
    37     if (!strcmp (argv[i], "acosh"))  { type = 9; goto gotit; }
    38 
    39     if (!strcmp (argv[i], "sin"))    { type = 9; goto gotit; }
    40     if (!strcmp (argv[i], "cos"))    { type = 9; goto gotit; }
    41     if (!strcmp (argv[i], "tan"))    { type = 9; goto gotit; }
    42     if (!strcmp (argv[i], "dsin"))   { type = 9; goto gotit; }
    43     if (!strcmp (argv[i], "dcos"))   { type = 9; goto gotit; }
    44     if (!strcmp (argv[i], "dtan"))   { type = 9; goto gotit; }
    45     if (!strcmp (argv[i], "asin"))   { type = 9; goto gotit; }
    46     if (!strcmp (argv[i], "acos"))   { type = 9; goto gotit; }
    47     if (!strcmp (argv[i], "atan"))   { type = 9; goto gotit; }
    48     if (!strcmp (argv[i], "dasin"))  { type = 9; goto gotit; }
    49     if (!strcmp (argv[i], "dacos"))  { type = 9; goto gotit; }
    50     if (!strcmp (argv[i], "datan"))  { type = 9; goto gotit; }
    51 
    52     if (!strcmp (argv[i], "lgamma")) { type = 9; goto gotit; }
    53 
    54     if (!strcmp (argv[i], "rnd"))    { type = 9; goto gotit; }
    55     if (!strcmp (argv[i], "xramp"))  { type = 9; goto gotit; }
    56     if (!strcmp (argv[i], "yramp"))  { type = 9; goto gotit; }
    57     if (!strcmp (argv[i], "ramp"))   { type = 9; goto gotit; }
    58     if (!strcmp (argv[i], "zero"))   { type = 9; goto gotit; }
    59     if (!strcmp (argv[i], "--"))     { type = 9; goto gotit; }
    60     if (!strcmp (argv[i], "not"))    { type = 9; goto gotit; }
    61     if (!strcmp (argv[i], "isinf"))  { type = 9; goto gotit; }
    62     if (!strcmp (argv[i], "isnan"))  { type = 9; goto gotit; }
     30    if (!strcmp (argv[i], "abs"))    { type = ST_UNARY; goto gotit; }
     31    if (!strcmp (argv[i], "int"))    { type = ST_UNARY; goto gotit; }
     32    if (!strcmp (argv[i], "exp"))    { type = ST_UNARY; goto gotit; }
     33    if (!strcmp (argv[i], "ten"))    { type = ST_UNARY; goto gotit; }
     34    if (!strcmp (argv[i], "log"))    { type = ST_UNARY; goto gotit; }
     35    if (!strcmp (argv[i], "ln"))     { type = ST_UNARY; goto gotit; }
     36    if (!strcmp (argv[i], "sqrt"))   { type = ST_UNARY; goto gotit; }
     37    if (!strcmp (argv[i], "erf"))    { type = ST_UNARY; goto gotit; }
     38    if (!strcmp (argv[i], "sinh"))   { type = ST_UNARY; goto gotit; }
     39    if (!strcmp (argv[i], "cosh"))   { type = ST_UNARY; goto gotit; }
     40    if (!strcmp (argv[i], "asinh"))  { type = ST_UNARY; goto gotit; }
     41    if (!strcmp (argv[i], "acosh"))  { type = ST_UNARY; goto gotit; }
     42    if (!strcmp (argv[i], "sin"))    { type = ST_UNARY; goto gotit; }
     43    if (!strcmp (argv[i], "cos"))    { type = ST_UNARY; goto gotit; }
     44    if (!strcmp (argv[i], "tan"))    { type = ST_UNARY; goto gotit; }
     45    if (!strcmp (argv[i], "dsin"))   { type = ST_UNARY; goto gotit; }
     46    if (!strcmp (argv[i], "dcos"))   { type = ST_UNARY; goto gotit; }
     47    if (!strcmp (argv[i], "dtan"))   { type = ST_UNARY; goto gotit; }
     48    if (!strcmp (argv[i], "asin"))   { type = ST_UNARY; goto gotit; }
     49    if (!strcmp (argv[i], "acos"))   { type = ST_UNARY; goto gotit; }
     50    if (!strcmp (argv[i], "atan"))   { type = ST_UNARY; goto gotit; }
     51    if (!strcmp (argv[i], "dasin"))  { type = ST_UNARY; goto gotit; }
     52    if (!strcmp (argv[i], "dacos"))  { type = ST_UNARY; goto gotit; }
     53    if (!strcmp (argv[i], "datan"))  { type = ST_UNARY; goto gotit; }
     54    if (!strcmp (argv[i], "lgamma")) { type = ST_UNARY; goto gotit; }
     55    if (!strcmp (argv[i], "rnd"))    { type = ST_UNARY; goto gotit; }
     56    if (!strcmp (argv[i], "xramp"))  { type = ST_UNARY; goto gotit; }
     57    if (!strcmp (argv[i], "yramp"))  { type = ST_UNARY; goto gotit; }
     58    if (!strcmp (argv[i], "ramp"))   { type = ST_UNARY; goto gotit; }
     59    if (!strcmp (argv[i], "zero"))   { type = ST_UNARY; goto gotit; }
     60    if (!strcmp (argv[i], "--"))     { type = ST_UNARY; goto gotit; }
     61    if (!strcmp (argv[i], "not"))    { type = ST_UNARY; goto gotit; }
     62    if (!strcmp (argv[i], "isinf"))  { type = ST_UNARY; goto gotit; }
     63    if (!strcmp (argv[i], "isnan"))  { type = ST_UNARY; goto gotit; }
    6364
    6465    /* binary operations */
    65     if (!strcmp (argv[i], "^"))      { type = 8; goto gotit; }
    66 
    67     if (!strcmp (argv[i], "@"))      { type = 7; goto gotit; }
    68     if (!strcmp (argv[i], "/"))      { type = 7; goto gotit; }
    69     if (!strcmp (argv[i], "*"))      { type = 7; goto gotit; }
    70     if (!strcmp (argv[i], "%"))      { type = 7; goto gotit; }
    71 
    72     if (!strcmp (argv[i], "+"))      { type = 6; goto gotit; }
    73     if (!strcmp (argv[i], "-"))      { type = 6; goto gotit; }
     66    if (!strcmp (argv[i], "^"))      { type = ST_POWER; goto gotit; }
     67
     68    if (!strcmp (argv[i], "atan2"))  { type = ST_BINARY; goto gotit; }
     69    if (!strcmp (argv[i], ","))      { type = ST_COMMA; goto gotit; }
     70
     71    if (!strcmp (argv[i], "@"))      { type = ST_TIMES; goto gotit; }
     72    if (!strcmp (argv[i], "/"))      { type = ST_TIMES; goto gotit; }
     73    if (!strcmp (argv[i], "*"))      { type = ST_TIMES; goto gotit; }
     74    if (!strcmp (argv[i], "%"))      { type = ST_TIMES; goto gotit; }
     75
     76    if (!strcmp (argv[i], "+"))      { type = ST_ADD; goto gotit; }
     77    if (!strcmp (argv[i], "-"))      { type = ST_ADD; goto gotit; }
    7478       
    75     if (!strcmp (argv[i], "&"))      { type = 5; goto gotit; }
    76     if (!strcmp (argv[i], "|"))      { type = 5; goto gotit; }
    77 
    78     if (!strcmp (argv[i], "<"))      { type = 4; goto gotit; }
    79     if (!strcmp (argv[i], ">"))      { type = 4; goto gotit; }
    80     if (!strcmp (argv[i], "=="))     { type = 4; strcpy (argv[i], "E"); goto gotit; }
    81     if (!strcmp (argv[i], "!="))     { type = 4; strcpy (argv[i], "N"); goto gotit; }
    82     if (!strcmp (argv[i], "<="))     { type = 4; strcpy (argv[i], "L"); goto gotit; }
    83     if (!strcmp (argv[i], ">="))     { type = 4; strcpy (argv[i], "G"); goto gotit; }
    84     if (!strcmp (argv[i], ">>"))     { type = 4; strcpy (argv[i], "U"); goto gotit; }
    85     if (!strcmp (argv[i], "<<"))     { type = 4; strcpy (argv[i], "D"); goto gotit; }
    86 
    87     if (!strcmp (argv[i], "&&"))     { type = 3; strcpy (argv[i], "A"); goto gotit; }
    88     if (!strcmp (argv[i], "||"))     { type = 3; strcpy (argv[i], "O"); goto gotit; }
    89 
    90     if (!strcmp (argv[i], "("))      { type = 2; goto gotit; }
    91     if (!strcmp (argv[i], ")"))      { type = 1; goto gotit; }
     79    if (!strcmp (argv[i], "&"))      { type = ST_BITWISE; goto gotit; }
     80    if (!strcmp (argv[i], "|"))      { type = ST_BITWISE; goto gotit; }
     81
     82    if (!strcmp (argv[i], "<"))      { type = ST_LOGIC; goto gotit; }
     83    if (!strcmp (argv[i], ">"))      { type = ST_LOGIC; goto gotit; }
     84    if (!strcmp (argv[i], "=="))     { type = ST_LOGIC; strcpy (argv[i], "E"); goto gotit; }
     85    if (!strcmp (argv[i], "!="))     { type = ST_LOGIC; strcpy (argv[i], "N"); goto gotit; }
     86    if (!strcmp (argv[i], "<="))     { type = ST_LOGIC; strcpy (argv[i], "L"); goto gotit; }
     87    if (!strcmp (argv[i], ">="))     { type = ST_LOGIC; strcpy (argv[i], "G"); goto gotit; }
     88    if (!strcmp (argv[i], ">>"))     { type = ST_LOGIC; strcpy (argv[i], "U"); goto gotit; }
     89    if (!strcmp (argv[i], "<<"))     { type = ST_LOGIC; strcpy (argv[i], "D"); goto gotit; }
     90
     91    if (!strcmp (argv[i], "&&"))     { type = ST_AND; strcpy (argv[i], "A"); goto gotit; }
     92    if (!strcmp (argv[i], "||"))     { type = ST_OR ; strcpy (argv[i], "O"); goto gotit; }
     93
     94    if (!strcmp (argv[i], "("))      { type = ST_LEFT; goto gotit; }
     95    if (!strcmp (argv[i], ")"))      { type = ST_RIGHT; goto gotit; }
    9296
    9397  gotit:
    9498    /* choose how to deal with object */
    9599    switch (type) {
    96       case 8:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
     100      case ST_POWER:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
    97101        /* pop previous, higher operators from OP stack to stack */
    98102        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) {
     
    105109        Nop_stack ++;
    106110        break;
    107       case 9: /* unary OPs */
    108       case 7: /* binary OPs */
    109       case 6:
    110       case 5:
    111       case 4:
    112       case 3:
     111      case ST_UNARY:
     112      case ST_BINARY:
     113      case ST_TRINARY:
     114      case ST_TIMES:
     115      case ST_ADD:
     116      case ST_BITWISE:
     117      case ST_LOGIC:
     118      case ST_AND:
     119      case ST_OR:
    113120        /* pop previous, higher or equal operators from OP stack to stack */
    114121        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) {
     
    121128        Nop_stack ++;
    122129        break;
    123       case 2
     130      case ST_LEFT
    124131        /* push operator on OP stack */
    125132        assign_stack (&op_stack[Nop_stack], argv[i], type);
     
    127134        Nop_stack ++;
    128135        break;
    129       case 1:
     136      case ST_RIGHT:
    130137        /* pop rest of operators from OP stack to stack, looking for '(' */
    131         for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) {
    132           move_stack (&stack[Nstack], &op_stack[j]);
    133           Nstack ++;
    134           Nop_stack --;
    135         }
    136         if ((j == -1) || (op_stack[j].type != 2)) {
     138        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != ST_LEFT); j--) {
     139          move_stack (&stack[Nstack], &op_stack[j]);
     140          Nstack ++;
     141          Nop_stack --;
     142        }
     143        if ((j == -1) || (op_stack[j].type != ST_LEFT)) {
    137144          push_error ("syntax error: mismatched parenthesis");
    138145          Nstack = 0;
     
    144151        Nop_stack --;
    145152        break;
    146       case 0:
     153      case ST_COMMA:
     154        /* pop rest of operators from OP stack to stack, looking for '(' (but do not pop the '(')*/
     155        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != ST_LEFT) && (op_stack[j].type != ST_TRINARY); j--) {
     156          move_stack (&stack[Nstack], &op_stack[j]);
     157          Nstack ++;
     158          Nop_stack --;
     159        }
     160        break;
     161      case ST_NONE:
    147162        /* place the value (number or vector/matrix name) on stack */
    148163        /* value of 'X' is used as sentinel until we sort out values */
    149         assign_stack (&stack[Nstack], argv[i], 'X');
     164        assign_stack (&stack[Nstack], argv[i], ST_VALUE);
    150165        Nstack ++;
    151166        break;
     167
     168      default:
     169        push_error ("invalid stack typ");
     170        Nstack = 0;
     171        goto cleanup;
    152172    }
    153173  }
    154174
    155   /* dump remaining operators on stack, checking for ')' */
     175  /* dump remaining operators on stack, checking for '(' */
    156176  for (j = Nop_stack - 1; j >= 0; j--) {
    157     if (op_stack[j].type == 2) {
     177    if (op_stack[j].type == ST_LEFT) {
    158178      push_error ("syntax error: mismatched parenthesis");
    159179      Nstack = 0;
  • trunk/Ohana/src/opihi/lib.shell/dvomath.c

    r31635 r36375  
    8080        sprintf (outname, "%s", stack[0].name);
    8181      } else {
    82         if (stack[0].type == 's') {
     82        if (stack[0].type == ST_SCALAR_INT) {
    8383          sprintf (outname, "%d", stack[0].IntValue);
    8484        } else {
  • trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r34088 r36375  
    22# define VERBOSE 0
    33
    4 # define TWO_OP(A,B,FUNC) \
    5   if (!strncasecmp (&stack[i - 2].type, A, 1) && !strncasecmp (&stack[i - 1].type, B, 1)) \
    6     status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    7 
    8 # define ONE_OP(A,FUNC) \
    9   if (!strncasecmp (&stack[i - 1].type, A, 1)) \
    10     status = FUNC (&tmp_stack, &stack[i - 1], stack[i].name);
     4// all three operands must have the same type
     5# define THREE_OP(A,FUNC)                                               \
     6  if ((stack[i - 3].type == A) && (stack[i - 2].type == A) && (stack[i - 1].type == A)) { \
     7    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     8    goto got_three_op; } \
     9  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A) && (stack[i - 1].type == A)) { \
     10    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     11    goto got_three_op; } \
     12  if ((stack[i - 3].type == A) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A)) { \
     13    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     14    goto got_three_op; } \
     15  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A)) { \
     16    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     17    goto got_three_op; } \
     18  if ((stack[i - 3].type == A) && (stack[i - 2].type == A) && (stack[i - 1].type == A+1)) { \
     19    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     20    goto got_three_op; } \
     21  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A) && (stack[i - 1].type == A+1)) { \
     22    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     23    goto got_three_op; } \
     24  if ((stack[i - 3].type == A) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A+1)) { \
     25    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     26    goto got_three_op; } \
     27  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A+1)) { \
     28    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     29    goto got_three_op; } \
     30
     31// A & B value types all have 2 possible values
     32# define TWO_OP(A,B,FUNC) {                                             \
     33    if ((stack[i - 2].type == A) && (stack[i - 1].type == B)) {         \
     34      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     35      goto got_two_op; }                                                \
     36    if ((stack[i - 2].type == A+1) && (stack[i - 1].type == B)) {       \
     37      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     38      goto got_two_op; }                                                \
     39    if ((stack[i - 2].type == A) && (stack[i - 1].type == B+1)) {       \
     40      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     41      goto got_two_op; }                                                \
     42    if ((stack[i - 2].type == A+1) && (stack[i - 1].type == B+1)) {     \
     43      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     44      goto got_two_op; } \
     45  }
     46
     47# define ONE_OP(A,FUNC)                                         \
     48  if (stack[i - 1].type == A) {                                 \
     49    status = FUNC (&tmp_stack, &stack[i - 1], stack[i].name);   \
     50    goto got_one_op; }
    1151
    1252int evaluate_stack (StackVar *stack, int *Nstack) {
     
    2060
    2161  if (*Nstack == 1) {
    22     if ((stack[0].type == 'S') || (stack[0].type == 's')) {
     62    if ((stack[0].type == ST_SCALAR_INT) || (stack[0].type == ST_SCALAR_FLT)) {
    2363      clear_stack (&tmp_stack);
    2464      return (TRUE);
    2565    }
    26     if (stack[0].type == 'V') {
     66    if (stack[0].type == ST_VECTOR) {
    2767      /* need to make a copy so we set output value? */
    2868      V_unary (&tmp_stack, &stack[0], "=");
     
    3070      return (TRUE);
    3171    }
    32     if (stack[0].type == 'M') {
     72    if (stack[0].type == ST_MATRIX) {
    3373      /* need to make a copy so we set output value? */
    3474      M_unary (&tmp_stack, &stack[0], "=");
     
    5696    }
    5797
    58     /***** binary operators *****/
    59     if ((stack[i].type >= 3) && (stack[i].type <= 8)) {
    60 
    61       if (i < 2) {  /* need two variables to operate on */
    62         sprintf (line, "syntax error: binary operator with one operand: %s\n", stack[i].name);
     98    /***** trinary operators *****/
     99    switch (stack[i].type) {
     100      case ST_TRINARY:
     101
     102        if (i < 3) {  /* need two variables to operate on */
     103          snprintf (line, 512, "syntax error: trinary operator without three operands: %s\n", stack[i].name);
     104          push_error (line);
     105          clear_stack (&tmp_stack);
     106          return (FALSE);
     107        }
     108
     109        status = FALSE;
     110        THREE_OP (ST_MATRIX,MMM_trinary);
     111        THREE_OP (ST_VECTOR,VVV_trinary);
     112
     113        THREE_OP (ST_SCALAR_FLT,SSS_trinary);
     114        THREE_OP (ST_SCALAR_INT,SSS_trinary);
     115
     116        /* there are no valid unary string operators */
     117        push_error ("invalid operands for trinary operator (mismatch types?)");
     118        clear_stack (&tmp_stack);
     119        return (FALSE);
     120
     121      got_three_op:
     122        if (!status) {
     123          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s or %s\n", stack[i-1].name, stack[i-2].name, stack[i-3].name);
     124          push_error (line);
     125          clear_stack (&tmp_stack);
     126          return (FALSE);
     127        }
     128        move_stack (&stack[i-3], &tmp_stack);
     129        delete_stack (&stack[i-2], 3);
     130        for (j = i + 1; j < *Nstack; j++) {
     131          move_stack (&stack[j-3], &stack[j]);
     132        }
     133        *Nstack -= 3;
     134        i -= 3;
     135        init_stack (&tmp_stack);
     136        continue;
     137
     138        /***** binary operators *****/
     139      case ST_OR:
     140      case ST_AND:
     141      case ST_LOGIC:
     142      case ST_BITWISE:
     143      case ST_ADD:
     144      case ST_TIMES:
     145      case ST_POWER:
     146      case ST_BINARY:
     147
     148        if (i < 2) {  /* need two variables to operate on */
     149          snprintf (line, 512, "syntax error: binary operator with one operand: %s\n", stack[i].name);
     150          push_error (line);
     151          clear_stack (&tmp_stack);
     152          return (FALSE);
     153        }
     154
     155        status = FALSE;
     156        TWO_OP (ST_MATRIX,ST_MATRIX,MM_binary);
     157        TWO_OP (ST_MATRIX,ST_VECTOR,MV_binary);
     158        TWO_OP (ST_MATRIX,ST_SCALAR_INT,MS_binary);
     159
     160        TWO_OP (ST_VECTOR,ST_MATRIX,VM_binary);
     161        TWO_OP (ST_VECTOR,ST_VECTOR,VV_binary);
     162        TWO_OP (ST_VECTOR,ST_SCALAR_INT,VS_binary);
     163
     164        TWO_OP (ST_SCALAR_INT,ST_MATRIX,SM_binary);
     165        TWO_OP (ST_SCALAR_INT,ST_VECTOR,SV_binary);
     166        TWO_OP (ST_SCALAR_INT,ST_SCALAR_INT,SS_binary);     
     167
     168        TWO_OP (ST_SCALAR_FLT,ST_MATRIX,SM_binary);
     169        TWO_OP (ST_SCALAR_FLT,ST_VECTOR,SV_binary);
     170        TWO_OP (ST_SCALAR_FLT,ST_SCALAR_INT,SS_binary);     
     171
     172        TWO_OP (ST_STRING,ST_STRING,WW_binary);     
     173        TWO_OP (ST_STRING,ST_SCALAR_INT,WW_binary);     
     174        TWO_OP (ST_SCALAR_INT,ST_STRING,WW_binary);     
     175     
     176      got_two_op:
     177        if (!status) {
     178          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
     179          push_error (line);
     180          clear_stack (&tmp_stack);
     181          return (FALSE);
     182        }
     183        move_stack (&stack[i-2], &tmp_stack);
     184        delete_stack (&stack[i-1], 2);
     185        for (j = i + 1; j < *Nstack; j++) {
     186          move_stack (&stack[j - 2], &stack[j]);
     187        }
     188        *Nstack -= 2;
     189        i -= 2;
     190        init_stack (&tmp_stack);
     191        continue;
     192
     193        /***** unary operators **/
     194      case ST_UNARY:
     195
     196        if (i < 1) {  /* need one variable to operate on */
     197          push_error ("syntax error: unary operator with no operand");
     198          clear_stack (&tmp_stack);
     199          return (FALSE);
     200        }
     201
     202        ONE_OP (ST_MATRIX, M_unary);
     203        ONE_OP (ST_MATRIX_TMP, M_unary);
     204
     205        ONE_OP (ST_VECTOR, V_unary);
     206        ONE_OP (ST_VECTOR_TMP, V_unary);
     207
     208        ONE_OP (ST_SCALAR_INT, S_unary);
     209        ONE_OP (ST_SCALAR_FLT, S_unary);
     210
     211        /* there are no valid unary string operators */
     212        push_error ("syntax error: no valid string unary ops");
     213        clear_stack (&tmp_stack);
     214        return (FALSE);
     215
     216      got_one_op:
     217        move_stack (&stack[i-1], &tmp_stack);
     218        delete_stack (&stack[i], 1);
     219        for (j = i + 1; j < *Nstack; j++) {
     220          move_stack (&stack[j - 1], &stack[j]);
     221        }
     222        init_stack (&tmp_stack);
     223        *Nstack -= 1;
     224        i -= 1;
     225        continue;
     226
     227      case ST_SCALAR_INT:
     228      case ST_SCALAR_FLT:
     229      case ST_VECTOR:
     230      case ST_VECTOR_TMP:
     231      case ST_MATRIX:
     232      case ST_MATRIX_TMP:
     233      case ST_STRING:
     234        continue;
     235
     236      default:
     237        snprintf (line, 512, "syntax error: unexpected operator type %s", stack[i].name);
    63238        push_error (line);
    64239        clear_stack (&tmp_stack);
    65240        return (FALSE);
    66       }
    67 
    68       status = FALSE;
    69       TWO_OP ("M","M",MM_binary);
    70       TWO_OP ("M","V",MV_binary);
    71       TWO_OP ("M","S",MS_binary);
    72       TWO_OP ("V","M",VM_binary);
    73       TWO_OP ("V","V",VV_binary);
    74       TWO_OP ("V","S",VS_binary);
    75       TWO_OP ("S","M",SM_binary);
    76       TWO_OP ("S","V",SV_binary);
    77       TWO_OP ("S","S",SS_binary);     
    78       TWO_OP ("W","W",WW_binary);     
    79       TWO_OP ("W","S",WW_binary);     
    80       TWO_OP ("S","W",WW_binary);     
    81      
    82       if (!status) {
    83         sprintf (line, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
    84         push_error (line);
    85         clear_stack (&tmp_stack);
    86         return (FALSE);
    87       }
    88       move_stack (&stack[i-2], &tmp_stack);
    89       delete_stack (&stack[i-1], 2);
    90       for (j = i + 1; j < *Nstack; j++) {
    91         move_stack (&stack[j - 2], &stack[j]);
    92       }
    93       *Nstack -= 2;
    94       i -= 2;
    95       init_stack (&tmp_stack);
    96       continue;
    97     }
    98 
    99     /***** unary operators **/
    100     if (stack[i].type == 9) {
    101 
    102       if (i < 1) {  /* need one variable to operate on */
    103         push_error ("syntax error: unary operator with no operand");
    104         clear_stack (&tmp_stack);
    105         return (FALSE);
    106       }
    107 
    108       ONE_OP ("M", M_unary);
    109       ONE_OP ("V", V_unary);
    110       ONE_OP ("S", S_unary);
    111 
    112       /* there are no valid unary string operators */
    113       if (!strncasecmp (&stack[i - 1].type, "W", 1)) {
    114         push_error ("syntax error: no valid string unary ops");
    115         clear_stack (&tmp_stack);
    116         return (FALSE);
    117       }
    118 
    119       move_stack (&stack[i-1], &tmp_stack);
    120       delete_stack (&stack[i], 1);
    121       for (j = i + 1; j < *Nstack; j++) {
    122         move_stack (&stack[j - 1], &stack[j]);
    123       }
    124       init_stack (&tmp_stack);
    125       *Nstack -= 1;
    126       i -= 1;
    127       continue;
    128     }
     241    }
    129242  }
    130243  clear_stack (&tmp_stack);
     
    160273
    161274  for (i = 0; i < Nstack; i++) {
    162     if (IsBufferPtr (stack[i].buffer) && (stack[i].type == 'm')) {
     275    if (IsBufferPtr (stack[i].buffer) && (stack[i].type == ST_MATRIX_TMP)) {
    163276      if (VERBOSE) gprint (GP_ERR, "free %s (buff) (%lx)\n", stack[i].name, (long) stack[i].buffer);
    164277      free (stack[i].buffer[0].header.buffer);
     
    167280      stack[i].buffer = NULL;
    168281    }   
    169     if (IsVectorPtr (stack[i].vector) && (stack[i].type == 'v')) {
     282    if (IsVectorPtr (stack[i].vector) && (stack[i].type == ST_VECTOR_TMP)) {
    170283      if (VERBOSE) gprint (GP_ERR, "free %s (vect) (%lx)\n", stack[i].name, (long) stack[i].vector);
    171284      free (stack[i].vector[0].elements.Ptr);
     
    193306}
    194307
    195 void assign_stack (StackVar *stack, char *name, int type) {
     308void assign_stack (StackVar *stack, char *name, StackVarType type) {
    196309  stack->name = strcreate (name);
    197310  stack->type = type;
  • trunk/Ohana/src/opihi/lib.shell/stack_math.c

    r34342 r36375  
    66*/
    77
    8 // XXX we temporarily drop the concept of using one of the temporary input vectors for
    9 // the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors
    10 // as well as their temporary state
    11 
    12 int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
     8int SSS_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
     9
     10  char line[512]; // this is only used to report an error
     11 
     12  // set up the possible operations : int OP int -> int, all else yield float
     13  // OP is the operation performed on *M1 and *M2
     14# define SSS_FUNC(OP) {                                         \
     15    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT) && (V3->type == ST_SCALAR_FLT)) { \
     16      opihi_flt M1  =  V1[0].FltValue;                  \
     17      opihi_flt M2  =  V2[0].FltValue;                  \
     18      opihi_flt M3  =  V3[0].FltValue;                  \
     19      OUT[0].type = ST_SCALAR_FLT;                      \
     20      OUT[0].FltValue = OP;                                                     \
     21      break;                                                            \
     22    }                                                                   \
     23    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT) && (V3->type == ST_SCALAR_INT)) { \
     24      opihi_int M1  =  V1[0].IntValue;                  \
     25      opihi_int M2  =  V2[0].IntValue;                  \
     26      opihi_int M3  =  V3[0].IntValue;                  \
     27      OUT[0].type = ST_SCALAR_INT;                      \
     28      OUT[0].IntValue = OP;                                                     \
     29      break;                                                            \
     30    }                                                                   \
     31  }
     32
     33  switch (op[0]) {
     34    case '?': SSS_FUNC(M1 ? M2: M3);
     35    default:
     36      snprintf (line, 512, "error: op %c not defined!", op[0]);
     37      push_error (line);
     38      return (FALSE);
     39  }
     40# undef SSS_FUNC
     41
     42  clear_stack (V1);
     43  clear_stack (V2);
     44  clear_stack (V3);
     45  return (TRUE);
     46
     47}
     48
     49int VVV_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
    1350
    1451  int i, Nx;
     
    1956    return (FALSE);
    2057  }
     58  if (V1[0].vector[0].Nelements != V3[0].vector[0].Nelements) {
     59    return (FALSE);
     60  }
    2161
    2262  Nx = V1[0].vector[0].Nelements;
     
    2464  // create the output vector guaranteed to be temporary until the very end
    2565  OUT[0].vector = InitVector ();
    26   OUT[0].type = 'v';
     66  OUT[0].type = ST_VECTOR_TMP;
     67
     68  // set up the possible operations : int OP int -> int, all else yield float
     69  // OP is the operation performed on *M1 and *M2
     70# define VVV_FUNC(OP) {                                         \
     71    if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \
     72      CopyVector (OUT[0].vector, V1[0].vector);                         \
     73      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     74      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;                   \
     75      opihi_flt *M3  =  V3[0].vector[0].elements.Flt;                   \
     76      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     77      for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) {               \
     78        *out = OP;                                                      \
     79      }                                                                 \
     80      break;                                                            \
     81    }                                                                   \
     82    if ((V1->vector->type == OPIHI_INT) && (V2->vector->type == OPIHI_INT) && (V3->vector->type == OPIHI_INT)) { \
     83      CopyVector (OUT[0].vector, V1[0].vector);                         \
     84      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     85      opihi_int *M2  =  V2[0].vector[0].elements.Int;                   \
     86      opihi_int *M3  =  V3[0].vector[0].elements.Int;                   \
     87      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     88      for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) {               \
     89        *out = OP;                                                      \
     90      }                                                                 \
     91      break;                                                            \
     92    }                                                                   \
     93  }
     94
     95  switch (op[0]) {
     96    case '?': VVV_FUNC(*M1 ? *M2: *M3);
     97    default:
     98      snprintf (line, 512, "error: op %c not defined!", op[0]);
     99      push_error (line);
     100      return (FALSE);
     101  }
     102# undef VVV_FUNC
     103
     104  /** free up any temporary buffers: **/
     105
     106  if (V1[0].type == ST_VECTOR_TMP) {
     107    free (V1[0].vector[0].elements.Ptr);
     108    free (V1[0].vector);
     109  }
     110  if (V2[0].type == ST_VECTOR_TMP) {
     111    free (V2[0].vector[0].elements.Ptr);
     112    free (V2[0].vector);
     113  }
     114  if (V3[0].type == ST_VECTOR_TMP) {
     115    free (V3[0].vector[0].elements.Ptr);
     116    free (V3[0].vector);
     117  }
     118  /* at the end, V1 and V2 are deleted only if they were temporary */
     119
     120  clear_stack (V1);
     121  clear_stack (V2);
     122  clear_stack (V3);
     123  return (TRUE);
     124
     125}
     126
     127int MMM_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
     128
     129  int i, Nx, Ny;
     130  float *out, *M1, *M2, *M3;
     131  char line[512]; // this is only used to report an error
     132 
     133  Nx = V1[0].buffer[0].matrix.Naxis[0];
     134  Ny = V1[0].buffer[0].matrix.Naxis[1];
     135
     136  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
     137    OUT[0].buffer = V1[0].buffer;
     138    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
     139  } else {
     140    if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/
     141      OUT[0].buffer = V2[0].buffer;
     142      V2[0].type = ST_MATRIX; /* prevent it from being freed below */
     143    } else {  /* no spare temp buffer */
     144      OUT[0].buffer = InitBuffer ();
     145      CopyBuffer (OUT[0].buffer, V1[0].buffer);
     146    }
     147  }
     148  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
     149
     150  M1  = (float *)V1[0].buffer[0].matrix.buffer;
     151  M2  = (float *)V2[0].buffer[0].matrix.buffer;
     152  M3  = (float *)V3[0].buffer[0].matrix.buffer;
     153  out = (float *)OUT[0].buffer[0].matrix.buffer;
     154
     155# define MMM_FUNC(OP)                                   \
     156  for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++, M3++) {        \
     157    *out = OP;                                          \
     158  }                                                     \
     159  break;
     160
     161  switch (op[0]) {
     162    case '?': MMM_FUNC(*M1 ? *M2: *M3);
     163    default:
     164      snprintf (line, 512, "error: op %c not defined!", op[0]);
     165      push_error (line);
     166      return (FALSE);
     167  }
     168# undef MMM_FUNC
     169
     170  /** free up any temporary buffers: **/
     171
     172  if (V1[0].type == ST_MATRIX_TMP) {
     173    free (V1[0].buffer[0].header.buffer);
     174    free (V1[0].buffer[0].matrix.buffer);
     175    free (V1[0].buffer);
     176  }
     177  if (V2[0].type == ST_MATRIX_TMP) {
     178    free (V2[0].buffer[0].header.buffer);
     179    free (V2[0].buffer[0].matrix.buffer);
     180    free (V2[0].buffer);
     181  }
     182  if (V3[0].type == ST_MATRIX_TMP) {
     183    free (V3[0].buffer[0].header.buffer);
     184    free (V3[0].buffer[0].matrix.buffer);
     185    free (V3[0].buffer);
     186  }
     187
     188  /* at the end, V1 and V2 are deleted only if they were temporary */
     189
     190  clear_stack (V1);
     191  clear_stack (V2);
     192  clear_stack (V3);
     193  return (TRUE);
     194
     195}
     196
     197// XXX we temporarily drop the concept of using one of the temporary input vectors for
     198// the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors
     199// as well as their temporary state
     200
     201int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
     202
     203  int i, Nx;
     204  char line[512]; // this is only used to report an error
     205 
     206  // the vectors have to match in length
     207  if (V1[0].vector[0].Nelements != V2[0].vector[0].Nelements) {
     208    return (FALSE);
     209  }
     210
     211  Nx = V1[0].vector[0].Nelements;
     212
     213  // create the output vector guaranteed to be temporary until the very end
     214  OUT[0].vector = InitVector ();
     215  OUT[0].type = ST_VECTOR_TMP;
    27216
    28217  // set up the possible operations : int OP int -> int, all else yield float
     
    59248      break;                                                            \
    60249    }                                                                   \
    61     if ((FTYPE == 'S') && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
     250    if ((FTYPE == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
    62251      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    63252      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    82271
    83272  switch (op[0]) {
    84     case '+': VV_FUNC('s', *M1 + *M2);
    85     case '-': VV_FUNC('s', *M1 - *M2);
    86     case '*': VV_FUNC('s', *M1 * *M2);
    87     case '/': VV_FUNC('S', *M1 / (opihi_flt) *M2);
    88     case '%': VV_FUNC('s', (long long)*M1 % (long long)*M2);
    89     case '^': VV_FUNC('S', pow (*M1, *M2));
    90     case '@': VV_FUNC('S', DEG_RAD*atan2 (*M1, *M2));
    91     case 'D': VV_FUNC('s', MIN (*M1, *M2));
    92     case 'U': VV_FUNC('s', MAX (*M1, *M2));
    93     case '<': VV_FUNC('s', (*M1 < *M2) ? 1 : 0);
    94     case '>': VV_FUNC('s', (*M1 > *M2) ? 1 : 0);
    95     case '&': VV_FUNC('s', ((long long)*M1 & (long long)*M2));
    96     case '|': VV_FUNC('s', ((long long)*M1 | (long long)*M2));
    97     case 'E': VV_FUNC('s', (*M1 == *M2) ? 1 : 0);
    98     case 'N': VV_FUNC('s', (*M1 != *M2) ? 1 : 0);
    99     case 'L': VV_FUNC('s', (*M1 <= *M2) ? 1 : 0);
    100     case 'G': VV_FUNC('s', (*M1 >= *M2) ? 1 : 0);
    101     case 'A': VV_FUNC('s', (*M1 && *M2) ? 1 : 0);
    102     case 'O': VV_FUNC('s', (*M1 || *M2) ? 1 : 0);
     273    case '+': VV_FUNC(ST_SCALAR_INT, *M1 + *M2);
     274    case '-': VV_FUNC(ST_SCALAR_INT, *M1 - *M2);
     275    case '*': VV_FUNC(ST_SCALAR_INT, *M1 * *M2);
     276    case '/': VV_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) *M2);
     277    case '%': VV_FUNC(ST_SCALAR_INT, (long long)*M1 % (long long)*M2);
     278    case '^': VV_FUNC(ST_SCALAR_FLT, pow (*M1, *M2));
     279    case '@': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2));
     280    case 'a': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2));
     281    case 'D': VV_FUNC(ST_SCALAR_INT, MIN (*M1, *M2));
     282    case 'U': VV_FUNC(ST_SCALAR_INT, MAX (*M1, *M2));
     283    case '<': VV_FUNC(ST_SCALAR_INT, (*M1 < *M2) ? 1 : 0);
     284    case '>': VV_FUNC(ST_SCALAR_INT, (*M1 > *M2) ? 1 : 0);
     285    case '&': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)*M2));
     286    case '|': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)*M2));
     287    case 'E': VV_FUNC(ST_SCALAR_INT, (*M1 == *M2) ? 1 : 0);
     288    case 'N': VV_FUNC(ST_SCALAR_INT, (*M1 != *M2) ? 1 : 0);
     289    case 'L': VV_FUNC(ST_SCALAR_INT, (*M1 <= *M2) ? 1 : 0);
     290    case 'G': VV_FUNC(ST_SCALAR_INT, (*M1 >= *M2) ? 1 : 0);
     291    case 'A': VV_FUNC(ST_SCALAR_INT, (*M1 && *M2) ? 1 : 0);
     292    case 'O': VV_FUNC(ST_SCALAR_INT, (*M1 || *M2) ? 1 : 0);
    103293    default:
    104       sprintf (line, "error: op %c not defined!", op[0]);
     294      snprintf (line, 512, "error: op %c not defined!", op[0]);
    105295      push_error (line);
    106296      return (FALSE);
     
    110300  /** free up any temporary buffers: **/
    111301
    112   if (V1[0].type == 'v') {
     302  if (V1[0].type == ST_VECTOR_TMP) {
    113303    free (V1[0].vector[0].elements.Ptr);
    114304    free (V1[0].vector);
    115305  }
    116   if (V2[0].type == 'v') {
     306  if (V2[0].type == ST_VECTOR_TMP) {
    117307    free (V2[0].vector[0].elements.Ptr);
    118308    free (V2[0].vector);
     
    134324
    135325  OUT[0].vector = InitVector ();
    136   OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
     326  OUT[0].type = ST_VECTOR_TMP;   /*** <<--- says this is a temporary matrix ***/
    137327
    138328  // set up the possible operations : int OP int -> int, all else yield float
    139329  // OP is the operation performed on *M1 and *M2
    140330# define SV_FUNC(FTYPE,OP) {                                            \
    141     if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) {         \
     331    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) {               \
    142332      CopyVector (OUT[0].vector, V2[0].vector);                         \
    143333      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    149339      break;                                                            \
    150340    }                                                                   \
    151     if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) {         \
     341    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) {               \
    152342      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    153343      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    159349      break;                                                            \
    160350    }                                                                   \
    161     if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) {         \
     351    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) {               \
    162352      CopyVector (OUT[0].vector, V2[0].vector);                         \
    163353      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    169359      break;                                                            \
    170360    }                                                                   \
    171     if ((FTYPE == 'S') && (V1->type == 's') && (V2->vector->type != OPIHI_FLT)) { \
     361    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \
    172362      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    173363      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    179369      break;                                                            \
    180370    }                                                                   \
    181     if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) {         \
     371    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) {               \
    182372      CopyVector (OUT[0].vector, V2[0].vector);                         \
    183373      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    192382
    193383  switch (op[0]) {
    194     case '+': SV_FUNC('s', M1 + *M2);
    195     case '-': SV_FUNC('s', M1 - *M2);
    196     case '*': SV_FUNC('s', M1 * *M2);
    197     case '/': SV_FUNC('S', M1 / (opihi_flt) *M2);
    198     case '%': SV_FUNC('s', (long long) M1 % (long long) *M2);
    199     case '^': SV_FUNC('S', pow (M1, *M2));
    200     case '@': SV_FUNC('S', DEG_RAD*atan2 (M1, *M2));
    201     case 'D': SV_FUNC('s', MIN (M1, *M2));
    202     case 'U': SV_FUNC('s', MAX (M1, *M2));
    203     case '<': SV_FUNC('s', (M1 < *M2) ? 1 : 0);
    204     case '>': SV_FUNC('s', (M1 > *M2) ? 1 : 0);
    205     case '&': SV_FUNC('s', ((long long)M1 & (long long)*M2));
    206     case '|': SV_FUNC('s', ((long long)M1 | (long long)*M2));
    207     case 'E': SV_FUNC('s', (M1 == *M2) ? 1 : 0);
    208     case 'N': SV_FUNC('s', (M1 != *M2) ? 1 : 0);
    209     case 'L': SV_FUNC('s', (M1 <= *M2) ? 1 : 0);
    210     case 'G': SV_FUNC('s', (M1 >= *M2) ? 1 : 0);
    211     case 'A': SV_FUNC('s', (M1 && *M2) ? 1 : 0);
    212     case 'O': SV_FUNC('s', (M1 || *M2) ? 1 : 0);
     384    case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
     385    case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
     386    case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
     387    case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
     388    case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
     389    case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
     390    case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     391    case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     392    case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
     393    case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
     394    case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
     395    case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
     396    case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
     397    case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
     398    case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
     399    case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
     400    case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
     401    case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
     402    case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
     403    case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
    213404    default:
    214       sprintf (line, "error: op %c not defined!", op[0]);
     405      snprintf (line, 512, "error: op %c not defined!", op[0]);
    215406      push_error (line);
    216407      return (FALSE);
     
    219410
    220411  /** free up any temporary buffers: **/
    221   if (V2[0].type == 'v') {
     412  if (V2[0].type == ST_VECTOR_TMP) {
    222413    free (V2[0].vector[0].elements.Ptr);
    223414    free (V2[0].vector);
     
    240431
    241432  OUT[0].vector = InitVector ();
    242   OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
     433  OUT[0].type = ST_VECTOR_TMP;   /*** <<--- says this is a temporary matrix ***/
    243434
    244435  // set up the possible operations : int OP int -> int, all else yield float
    245436  // OP is the operation performed on *M1 and *M2
    246437# define VS_FUNC(FTYPE,OP) {                                            \
    247     if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) {         \
     438    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) {               \
    248439      CopyVector (OUT[0].vector, V1[0].vector);                         \
    249440      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    255446      break;                                                            \
    256447    }                                                                   \
    257     if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) {         \
     448    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) {               \
    258449      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    259450      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    265456      break;                                                            \
    266457    }                                                                   \
    267     if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) {         \
     458    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) {               \
    268459      CopyVector (OUT[0].vector, V1[0].vector);                         \
    269460      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    275466      break;                                                            \
    276467    }                                                                   \
    277     if ((FTYPE == 'S') && (V2->type == 's') && (V1->vector->type != OPIHI_FLT)) { \
     468    if ((FTYPE == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \
    278469      CopyVector (OUT[0].vector, V1[0].vector);                         \
    279470      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    285476      break;                                                            \
    286477    }                                                                   \
    287     if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) {         \
     478    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) {               \
    288479      CopyVector (OUT[0].vector, V1[0].vector);                         \
    289480      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    298489
    299490  switch (op[0]) {
    300     case '+': VS_FUNC('s', *M1 + M2);
    301     case '-': VS_FUNC('s', *M1 - M2);
    302     case '*': VS_FUNC('s', *M1 * M2);
    303     case '/': VS_FUNC('S', *M1 / (opihi_flt) M2);
    304     case '%': VS_FUNC('s', (long long) *M1 % (long long) M2);
    305     case '^': VS_FUNC('S', pow (*M1, M2));
    306     case '@': VS_FUNC('S', DEG_RAD*atan2 (*M1, M2));
    307     case 'D': VS_FUNC('s', MIN (*M1, M2));
    308     case 'U': VS_FUNC('s', MAX (*M1, M2));
    309     case '<': VS_FUNC('s', (*M1 < M2) ? 1 : 0);
    310     case '>': VS_FUNC('s', (*M1 > M2) ? 1 : 0);
    311     case '&': VS_FUNC('s', ((long long)*M1 & (long long)M2));
    312     case '|': VS_FUNC('s', ((long long)*M1 | (long long)M2));
    313     case 'E': VS_FUNC('s', (*M1 == M2) ? 1 : 0);
    314     case 'N': VS_FUNC('s', (*M1 != M2) ? 1 : 0);
    315     case 'L': VS_FUNC('s', (*M1 <= M2) ? 1 : 0);
    316     case 'G': VS_FUNC('s', (*M1 >= M2) ? 1 : 0);
    317     case 'A': VS_FUNC('s', (*M1 && M2) ? 1 : 0);
    318     case 'O': VS_FUNC('s', (*M1 || M2) ? 1 : 0);
     491    case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
     492    case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
     493    case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
     494    case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
     495    case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
     496    case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
     497    case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     498    case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     499    case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
     500    case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
     501    case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
     502    case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
     503    case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
     504    case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
     505    case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
     506    case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
     507    case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
     508    case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
     509    case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
     510    case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
    319511    default:
    320       sprintf (line, "error: op %c not defined!", op[0]);
     512      snprintf (line, 512, "error: op %c not defined!", op[0]);
    321513      push_error (line);
    322514      return (FALSE);
     
    326518  /** free up any temporary buffers: **/
    327519
    328   if (V1[0].type == 'v') {
     520  if (V1[0].type == ST_VECTOR_TMP) {
    329521    free (V1[0].vector[0].elements.Ptr);
    330522    free (V1[0].vector);
     
    353545
    354546  /* if possible, use V1 as temp buffer, otherwise create new one */
    355   if (V1[0].type == 'm') { 
     547  if (V1[0].type == ST_MATRIX_TMP) { 
    356548    OUT[0].buffer = V1[0].buffer;
    357     V1[0].type = 'M'; /* prevent it from being freed below */
     549    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    358550  } else { 
    359551    /* do buffer.matrix.buffer and buffer.header.buffer get correctly zeroed? */
     
    361553    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    362554  }
    363   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     555  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    364556
    365557  float     *M1  = (float *) V1[0].buffer[0].matrix.buffer;
     
    395587    case '^': MV_FUNC(pow (*M1, *M2));
    396588    case '@': MV_FUNC(DEG_RAD*atan2 (*M1, *M2));
     589    case 'a': MV_FUNC(DEG_RAD*atan2 (*M1, *M2));
    397590    case 'D': MV_FUNC(MIN (*M1, *M2));
    398591    case 'U': MV_FUNC(MAX (*M1, *M2));
     
    408601    case 'O': MV_FUNC((*M1 || *M2) ? 1 : 0);
    409602    default:
    410       sprintf (line, "error: op %c not defined!", op[0]);
     603      snprintf (line, 512, "error: op %c not defined!", op[0]);
    411604      push_error (line);
    412605      return (FALSE);
     
    416609  /** free up any temporary buffers: **/
    417610
    418   if (V1[0].type == 'm') {
     611  if (V1[0].type == ST_MATRIX_TMP) {
    419612    free (V1[0].buffer[0].header.buffer);
    420613    free (V1[0].buffer[0].matrix.buffer);
    421614    free (V1[0].buffer);
    422615  }
    423   if (V2[0].type == 'v') {
     616  if (V2[0].type == ST_VECTOR_TMP) {
    424617    free (V2[0].vector[0].elements.Ptr);
    425618    free (V2[0].vector);
     
    446639
    447640  /* if possible, use V2 as temp buffer, otherwise create new one */
    448   if (V2[0].type == 'm') {
     641  if (V2[0].type == ST_MATRIX_TMP) {
    449642    OUT[0].buffer = V2[0].buffer;
    450     V2[0].type = 'M'; /* prevent it from being freed below */
     643    V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    451644  } else {  /* no spare temp buffer */
    452645    OUT[0].buffer = InitBuffer ();
    453646    CopyBuffer (OUT[0].buffer, V2[0].buffer);
    454647  }
    455   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     648  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    456649
    457650  float     *M2  = (float *) V2[0].buffer[0].matrix.buffer;
     
    487680    case '^': VM_FUNC(pow (*M1, *M2));
    488681    case '@': VM_FUNC(DEG_RAD*atan2 (*M1, *M2));
     682    case 'a': VM_FUNC(DEG_RAD*atan2 (*M1, *M2));
    489683    case 'D': VM_FUNC(MIN (*M1, *M2));
    490684    case 'U': VM_FUNC(MAX (*M1, *M2));
     
    500694    case 'O': VM_FUNC((*M1 || *M2) ? 1 : 0);
    501695    default:
    502       sprintf (line, "error: op %c not defined!", op[0]);
     696      snprintf (line, 512, "error: op %c not defined!", op[0]);
    503697      push_error (line);
    504698      return (FALSE);
     
    508702  /** free up any temporary buffers: **/
    509703
    510   if (V1[0].type == 'v') {
     704  if (V1[0].type == ST_VECTOR_TMP) {
    511705    free (V1[0].vector[0].elements.Ptr);
    512706    free (V1[0].vector);
    513707  }
    514   if (V2[0].type == 'm') {
     708  if (V2[0].type == ST_MATRIX_TMP) {
    515709    free (V2[0].buffer[0].header.buffer);
    516710    free (V2[0].buffer[0].matrix.buffer);
     
    535729  Ny = V1[0].buffer[0].matrix.Naxis[1];
    536730
    537   if (V1[0].type == 'm') {  /** use V1 as temp buffer **/
     731  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
    538732    OUT[0].buffer = V1[0].buffer;
    539     V1[0].type = 'M'; /* prevent it from being freed below */
     733    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    540734  } else {
    541     if (V2[0].type == 'm') { /** use V2 as temp buffer, but header of V1 **/
     735    if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/
    542736      OUT[0].buffer = V2[0].buffer;
    543       V2[0].type = 'M'; /* prevent it from being freed below */
     737      V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    544738    } else {  /* no spare temp buffer */
    545739      OUT[0].buffer = InitBuffer ();
     
    547741    }
    548742  }
    549   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     743  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    550744
    551745  M1  = (float *)V1[0].buffer[0].matrix.buffer;
     
    567761    case '^': MM_FUNC(pow (*M1, *M2));
    568762    case '@': MM_FUNC(DEG_RAD*atan2 (*M1, *M2));
     763    case 'a': MM_FUNC(DEG_RAD*atan2 (*M1, *M2));
    569764    case 'D': MM_FUNC(MIN (*M1, *M2));
    570765    case 'U': MM_FUNC(MAX (*M1, *M2));
     
    580775    case 'O': MM_FUNC((*M1 || *M2) ? 1 : 0);
    581776    default:
    582       sprintf (line, "error: op %c not defined!", op[0]);
     777      snprintf (line, 512, "error: op %c not defined!", op[0]);
    583778      push_error (line);
    584779      return (FALSE);
     
    588783  /** free up any temporary buffers: **/
    589784
    590   if (V1[0].type == 'm') {
     785  if (V1[0].type == ST_MATRIX_TMP) {
    591786    free (V1[0].buffer[0].header.buffer);
    592787    free (V1[0].buffer[0].matrix.buffer);
    593788    free (V1[0].buffer);
    594789  }
    595   if (V2[0].type == 'm') {
     790  if (V2[0].type == ST_MATRIX_TMP) {
    596791    free (V2[0].buffer[0].header.buffer);
    597792    free (V2[0].buffer[0].matrix.buffer);
     
    615810
    616811  /* if possible, use V1 as temp buffer, otherwise create new one */
    617   if (V1[0].type == 'm') {
     812  if (V1[0].type == ST_MATRIX_TMP) {
    618813    OUT[0].buffer = V1[0].buffer;
    619     V1[0].type = 'M'; /* prevent it from being freed below */
     814    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    620815  } else {
    621816    OUT[0].buffer = InitBuffer ();
    622817    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    623818  }
    624   OUT[0].type = 'm';      /*** <<--- says this is a temporary matrix ***/
     819  OUT[0].type = ST_MATRIX_TMP;      /*** <<--- says this is a temporary matrix ***/
    625820
    626821  float *M1    = (float *)V1[0].buffer[0].matrix.buffer;
     
    628823
    629824# define MS_FUNC(OP) {                                  \
    630     if (V2->type == 'S')  {                             \
     825    if (V2->type == ST_SCALAR_FLT)  {                           \
    631826      opihi_flt M2 = V2[0].FltValue;                    \
    632827      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     
    635830      break;                                            \
    636831    }                                                   \
    637     if (V2->type == 's')  {                             \
     832    if (V2->type == ST_SCALAR_INT)  {                           \
    638833      opihi_int M2 = V2[0].IntValue;                    \
    639834      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     
    652847    case '^': MS_FUNC(pow (*M1, M2));
    653848    case '@': MS_FUNC(DEG_RAD*atan2 (*M1, M2));
     849    case 'a': MS_FUNC(DEG_RAD*atan2 (*M1, M2));
    654850    case 'D': MS_FUNC(MIN (*M1, M2));
    655851    case 'U': MS_FUNC(MAX (*M1, M2));
     
    665861    case 'O': MS_FUNC((*M1 || M2) ? 1 : 0);
    666862    default:
    667       sprintf (line, "error: op %c not defined!", op[0]);
     863      snprintf (line, 512, "error: op %c not defined!", op[0]);
    668864      push_error (line);
    669865      return (FALSE);
     
    671867# undef MS_FUNC
    672868
    673   if (V1[0].type == 'm') {
     869  if (V1[0].type == ST_MATRIX_TMP) {
    674870    free (V1[0].buffer[0].header.buffer);
    675871    free (V1[0].buffer[0].matrix.buffer);
     
    691887  Ny = V2[0].buffer[0].matrix.Naxis[1];
    692888
    693   if (V2[0].type == 'm') {  /* V2[0] is NOT temporary, we can't use it for storage */
     889  if (V2[0].type == ST_MATRIX_TMP) {  /* V2[0] is NOT temporary, we can't use it for storage */
    694890    OUT[0].buffer = V2[0].buffer;
    695     V2[0].type = 'M'; /* prevent it from being freed below */
     891    V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    696892  } else {
    697893    OUT[0].buffer = InitBuffer ();
    698894    CopyBuffer (OUT[0].buffer, V2[0].buffer);
    699895  }
    700   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     896  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    701897
    702898  float *M2    = (float *)V2[0].buffer[0].matrix.buffer;
     
    704900
    705901# define SM_FUNC(OP) {                                  \
    706     if (V1->type == 'S')  {                             \
     902    if (V1->type == ST_SCALAR_FLT)  {                           \
    707903      opihi_flt M1 = V1[0].FltValue;                    \
    708904      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     
    711907      break;                                            \
    712908    }                                                   \
    713     if (V1->type == 's')  {                             \
     909    if (V1->type == ST_SCALAR_INT)  {                           \
    714910      opihi_int M1 = V1[0].IntValue;                    \
    715911      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     
    728924    case '^': SM_FUNC(pow (M1, *M2));
    729925    case '@': SM_FUNC(DEG_RAD*atan2 (M1, *M2));
     926    case 'a': SM_FUNC(DEG_RAD*atan2 (M1, *M2));
    730927    case 'D': SM_FUNC(MIN (M1, *M2));
    731928    case 'U': SM_FUNC(MAX (M1, *M2));
     
    741938    case 'O': SM_FUNC((M1 || *M2) ? 1 : 0);
    742939    default:
    743       sprintf (line, "error: op %c not defined!", op[0]);
     940      snprintf (line, 512, "error: op %c not defined!", op[0]);
    744941      push_error (line);
    745942      return (FALSE);
     
    747944# undef SM_FUNC
    748945
    749   if (V2[0].type == 'm') {
     946  if (V2[0].type == ST_MATRIX_TMP) {
    750947    free (V2[0].buffer[0].header.buffer);
    751948    free (V2[0].buffer[0].matrix.buffer);
     
    764961
    765962# define SS_FUNC(FTYPE,OP) {                                            \
    766     if ((V1->type == 'S') && (V2->type == 'S')) {                       \
     963    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {                   \
    767964      opihi_flt M1 = V1[0].FltValue;                                    \
    768965      opihi_flt M2 = V2[0].FltValue;                                    \
    769       OUT[0].type = 'S';                                                \
     966      OUT[0].type = ST_SCALAR_FLT;                                              \
    770967      OUT[0].FltValue = OP;                                             \
    771968      break;                                                            \
    772969    }                                                                   \
    773     if ((V1->type == 'S') && (V2->type == 's')) {                       \
     970    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {                   \
    774971      opihi_flt M1 = V1[0].FltValue;                                    \
    775972      opihi_int M2 = V2[0].IntValue;                                    \
    776       OUT[0].type = 'S';                                                \
     973      OUT[0].type = ST_SCALAR_FLT;                                              \
    777974      OUT[0].FltValue = OP;                                             \
    778975      break;                                                            \
    779976    }                                                                   \
    780     if ((V1->type == 's') && (V2->type == 'S')) {                       \
     977    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {                   \
    781978      opihi_int M1 = V1[0].IntValue;                                    \
    782979      opihi_flt M2 = V2[0].FltValue;                                    \
    783       OUT[0].type = 'S';                                                \
     980      OUT[0].type = ST_SCALAR_FLT;                                              \
    784981      OUT[0].FltValue = OP;                                             \
    785982      break;                                                            \
    786983    }                                                                   \
    787     if ((FTYPE == 'S') && (V1->type == 's') && (V2->type == 's')) {     \
     984    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {       \
    788985      opihi_int M1 = V1[0].IntValue;                                    \
    789986      opihi_int M2 = V2[0].IntValue;                                    \
    790       OUT[0].type = 'S';                                                \
     987      OUT[0].type = ST_SCALAR_FLT;                                              \
    791988      OUT[0].FltValue = OP;                                             \
    792989      break;                                                            \
    793990    }                                                                   \
    794     if ((V1->type == 's') && (V2->type == 's')) {                       \
     991    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {                   \
    795992      opihi_int M1 = V1[0].IntValue;                                    \
    796993      opihi_int M2 = V2[0].IntValue;                                    \
    797       OUT[0].type = 's';                                                \
     994      OUT[0].type = ST_SCALAR_INT;                                              \
    798995      OUT[0].IntValue = OP;                                             \
    799996      break;                                                            \
     
    802999
    8031000  switch (op[0]) {
    804     case '+': SS_FUNC('s', M1 + M2);
    805     case '-': SS_FUNC('s', M1 - M2);
    806     case '*': SS_FUNC('s', M1 * M2);
    807     case '/': SS_FUNC('S', M1 / (opihi_flt) M2);
    808     case '%': SS_FUNC('s', (long long) M1 % (long long) M2);
    809     case '^': SS_FUNC('S', pow (M1, M2));
    810     case '@': SS_FUNC('S', DEG_RAD*atan2 (M1, M2));
    811     case 'D': SS_FUNC('s', MIN (M1, M2));
    812     case 'U': SS_FUNC('s', MAX (M1, M2));
    813     case '<': SS_FUNC('s', (M1 < M2) ? 1 : 0);
    814     case '>': SS_FUNC('s', (M1 > M2) ? 1 : 0);
    815     case '&': SS_FUNC('s', ((long long)M1 & (long long)M2));
    816     case '|': SS_FUNC('s', ((long long)M1 | (long long)M2));
    817     case 'E': SS_FUNC('s', (M1 == M2) ? 1 : 0);
    818     case 'N': SS_FUNC('s', (M1 != M2) ? 1 : 0);
    819     case 'L': SS_FUNC('s', (M1 <= M2) ? 1 : 0);
    820     case 'G': SS_FUNC('s', (M1 >= M2) ? 1 : 0);
    821     case 'A': SS_FUNC('s', (M1 && M2) ? 1 : 0);
    822     case 'O': SS_FUNC('s', (M1 || M2) ? 1 : 0);
     1001    case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
     1002    case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
     1003    case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
     1004    case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
     1005    case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
     1006    case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
     1007    case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1008    case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1009    case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
     1010    case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
     1011    case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
     1012    case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
     1013    case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
     1014    case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
     1015    case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
     1016    case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
     1017    case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
     1018    case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
     1019    case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
     1020    case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
    8231021    default:
    824       sprintf (line, "error: op %c not defined!", op[0]);
     1022      snprintf (line, 512, "error: op %c not defined!", op[0]);
    8251023      push_error (line);
    8261024      return (FALSE);
     
    8441042
    8451043  if ((op[0] != 'N') && (op[0] != 'E')) {
    846     sprintf (line, "error: op %c not defined for string operations!", op[0]);
     1044    snprintf (line, 512, "error: op %c not defined for string operations!", op[0]);
    8471045    push_error (line);
    8481046    return (FALSE);
     
    8531051     thus: string == number -> false */
    8541052
    855   if (!strncasecmp (&V1[0].type, "S", 1)) {
     1053  if (V1[0].type == ST_SCALAR_INT) {
    8561054    value = (op[0] == 'N');
    8571055    goto escape;
    8581056  }
    859   if (!strncasecmp (&V2[0].type, "S", 1)) {
     1057  if (V1[0].type == ST_SCALAR_FLT) {
     1058    value = (op[0] == 'N');
     1059    goto escape;
     1060  }
     1061  if (V2[0].type == ST_SCALAR_INT) {
     1062    value = (op[0] == 'N');
     1063    goto escape;
     1064  }
     1065  if (V2[0].type == ST_SCALAR_FLT) {
    8601066    value = (op[0] == 'N');
    8611067    goto escape;
     
    8701076    break;
    8711077    default:
    872       sprintf (line, "error: op %c not defined for string operations!", op[0]);
     1078      snprintf (line, 512, "error: op %c not defined for string operations!", op[0]);
    8731079      push_error (line);
    8741080      return (FALSE);
     
    8771083escape:
    8781084  OUT[0].FltValue = value;
    879   OUT[0].type = 'S';
     1085  OUT[0].type = ST_SCALAR_FLT;
    8801086
    8811087  clear_stack (V1);
     
    8911097 
    8921098# define S_FUNC(OP,FTYPE) {                     \
    893     if (V1->type == 'S') {                      \
     1099    if (V1->type == ST_SCALAR_FLT) {                    \
    8941100      opihi_flt M1  = V1[0].FltValue;           \
    895       OUT[0].type = 'S';                        \
     1101      OUT[0].type = ST_SCALAR_FLT;                      \
    8961102      OUT[0].FltValue = OP;                     \
    8971103      clear_stack (V1);                         \
    8981104      return (TRUE);                            \
    8991105    }                                           \
    900     if ((FTYPE == 'S') && (V1->type == 's')) {  \
     1106    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) {      \
    9011107      opihi_int M1  = V1[0].IntValue;           \
    902       OUT[0].type = 'S';                        \
     1108      OUT[0].type = ST_SCALAR_FLT;                      \
    9031109      OUT[0].FltValue = OP;                     \
    9041110      clear_stack (V1);                         \
    9051111      return (TRUE);                            \
    9061112    }                                           \
    907     if ((FTYPE == 's') && (V1->type == 's')) {  \
     1113    if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {      \
    9081114      opihi_int M1  = V1[0].IntValue;           \
    909       OUT[0].type = 's';                        \
     1115      OUT[0].type = ST_SCALAR_INT;                      \
    9101116      OUT[0].IntValue = OP;                     \
    9111117      clear_stack (V1);                         \
     
    9141120  }
    9151121
    916   if (!strcmp (op, "="))      S_FUNC(M1, 's');
    917   if (!strcmp (op, "abs"))    S_FUNC(fabs(M1), 's');
    918   if (!strcmp (op, "int"))    S_FUNC((long long)(M1), 's');
    919   if (!strcmp (op, "exp"))    S_FUNC(exp (M1), 'S');
    920   if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1), 'S');
    921   if (!strcmp (op, "log"))    S_FUNC(log10 (M1), 'S');
    922   if (!strcmp (op, "ln"))     S_FUNC(log (M1), 'S');
    923   if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1), 'S');
    924   if (!strcmp (op, "erf"))    S_FUNC(erf (M1), 'S');
    925   if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1), 'S');
    926   if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1), 'S');
    927   if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1), 'S');
    928   if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1), 'S');
    929   if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), 'S');
    930   if (!strcmp (op, "sin"))    S_FUNC(sin (M1), 'S');
    931   if (!strcmp (op, "cos"))    S_FUNC(cos (M1), 'S');
    932   if (!strcmp (op, "tan"))    S_FUNC(tan (M1), 'S');
    933   if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG), 'S');
    934   if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG), 'S');
    935   if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG), 'S');
    936   if (!strcmp (op, "asin"))   S_FUNC(asin (M1), 'S');
    937   if (!strcmp (op, "acos"))   S_FUNC(acos (M1), 'S');
    938   if (!strcmp (op, "atan"))   S_FUNC(atan (M1), 'S');
    939   if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD, 'S');
    940   if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, 'S');
    941   if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, 'S');
    942   if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), 'S');
    943   if (!strcmp (op, "not"))    S_FUNC(!(M1), 's');
    944   if (!strcmp (op, "--"))     S_FUNC(-1*M1, 's'); // NOTE: opihi_int is signed,
    945   if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1), 'S'); // XXX modify in future
    946   if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1), 'S'); // XXX modify in future   
     1122  if (!strcmp (op, "="))      S_FUNC(M1, ST_SCALAR_INT);
     1123  if (!strcmp (op, "abs"))    S_FUNC(fabs(M1), ST_SCALAR_INT);
     1124  if (!strcmp (op, "int"))    S_FUNC((long long)(M1), ST_SCALAR_INT);
     1125  if (!strcmp (op, "exp"))    S_FUNC(exp (M1), ST_SCALAR_FLT);
     1126  if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1), ST_SCALAR_FLT);
     1127  if (!strcmp (op, "log"))    S_FUNC(log10 (M1), ST_SCALAR_FLT);
     1128  if (!strcmp (op, "ln"))     S_FUNC(log (M1), ST_SCALAR_FLT);
     1129  if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1), ST_SCALAR_FLT);
     1130  if (!strcmp (op, "erf"))    S_FUNC(erf (M1), ST_SCALAR_FLT);
     1131  if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1), ST_SCALAR_FLT);
     1132  if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1), ST_SCALAR_FLT);
     1133  if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1), ST_SCALAR_FLT);
     1134  if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1), ST_SCALAR_FLT);
     1135  if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT);
     1136  if (!strcmp (op, "sin"))    S_FUNC(sin (M1), ST_SCALAR_FLT);
     1137  if (!strcmp (op, "cos"))    S_FUNC(cos (M1), ST_SCALAR_FLT);
     1138  if (!strcmp (op, "tan"))    S_FUNC(tan (M1), ST_SCALAR_FLT);
     1139  if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG), ST_SCALAR_FLT);
     1140  if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG), ST_SCALAR_FLT);
     1141  if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG), ST_SCALAR_FLT);
     1142  if (!strcmp (op, "asin"))   S_FUNC(asin (M1), ST_SCALAR_FLT);
     1143  if (!strcmp (op, "acos"))   S_FUNC(acos (M1), ST_SCALAR_FLT);
     1144  if (!strcmp (op, "atan"))   S_FUNC(atan (M1), ST_SCALAR_FLT);
     1145  if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD, ST_SCALAR_FLT);
     1146  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT);
     1147  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT);
     1148  if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT);
     1149  if (!strcmp (op, "not"))    S_FUNC(!(M1), ST_SCALAR_INT);
     1150  if (!strcmp (op, "--"))     S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed,
     1151  if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1), ST_SCALAR_FLT); // XXX modify in future
     1152  if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1), ST_SCALAR_FLT); // XXX modify in future   
    9471153
    9481154# undef S_FUNC
    9491155
    9501156  clear_stack (V1);
    951   sprintf (line, "error: op %s not defined!", op);
     1157  snprintf (line, 512, "error: op %s not defined!", op);
    9521158  push_error (line);
    9531159  return (FALSE);
     
    9621168
    9631169  OUT[0].vector = InitVector ();
    964   OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/
     1170  OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/
    9651171
    9661172# define V_FUNC(OP,FTYPE) {                                     \
     
    9741180      goto escape;                                              \
    9751181    }                                                           \
    976     if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {    \
     1182    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) {  \
    9771183      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);     \
    9781184      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     
    9831189      goto escape;                                              \
    9841190    }                                                           \
    985     if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {    \
     1191    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) {  \
    9861192      CopyVector (OUT[0].vector, V1[0].vector);                 \
    9871193      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     
    9931199    } }                                                 
    9941200
    995   if (!strcmp (op, "="))      V_FUNC(*M1, 's');
    996   if (!strcmp (op, "abs"))    V_FUNC(fabs(*M1), 's');
    997   if (!strcmp (op, "int"))    V_FUNC((long long)(*M1), 's');
    998   if (!strcmp (op, "exp"))    V_FUNC(exp(*M1), 'S');
    999   if (!strcmp (op, "ten"))    V_FUNC(pow(10.0,*M1), 'S');
    1000   if (!strcmp (op, "log"))    V_FUNC(log10(*M1), 'S');
    1001   if (!strcmp (op, "ln"))     V_FUNC(log(*M1), 'S');
    1002   if (!strcmp (op, "sqrt"))   V_FUNC(sqrt(*M1), 'S');
    1003   if (!strcmp (op, "erf"))    V_FUNC(erf(*M1), 'S');
    1004   if (!strcmp (op, "sinh"))   V_FUNC(sinh(*M1), 'S');
    1005   if (!strcmp (op, "cosh"))   V_FUNC(cosh(*M1), 'S');
    1006   if (!strcmp (op, "asinh"))  V_FUNC(asinh(*M1), 'S');
    1007   if (!strcmp (op, "acosh"))  V_FUNC(acosh(*M1), 'S');
    1008   if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), 'S');
    1009   if (!strcmp (op, "sin"))    V_FUNC(sin(*M1), 'S');
    1010   if (!strcmp (op, "cos"))    V_FUNC(cos(*M1), 'S');
    1011   if (!strcmp (op, "tan"))    V_FUNC(tan(*M1), 'S');
    1012   if (!strcmp (op, "dsin"))   V_FUNC(sin(*M1*RAD_DEG), 'S');
    1013   if (!strcmp (op, "dcos"))   V_FUNC(cos(*M1*RAD_DEG), 'S');
    1014   if (!strcmp (op, "dtan"))   V_FUNC(tan(*M1*RAD_DEG), 'S');
    1015   if (!strcmp (op, "asin"))   V_FUNC(asin(*M1), 'S');
    1016   if (!strcmp (op, "acos"))   V_FUNC(acos(*M1), 'S');
    1017   if (!strcmp (op, "atan"))   V_FUNC(atan(*M1), 'S');
    1018   if (!strcmp (op, "dasin"))  V_FUNC(asin(*M1)*DEG_RAD, 'S');
    1019   if (!strcmp (op, "dacos"))  V_FUNC(acos(*M1)*DEG_RAD, 'S');
    1020   if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, 'S');
    1021   if (!strcmp (op, "rnd"))    V_FUNC(drand48(), 'S');
    1022   if (!strcmp (op, "ramp"))   V_FUNC(i, 's');
    1023   if (!strcmp (op, "zero"))   V_FUNC(0, 's');
    1024   if (!strcmp (op, "not"))    V_FUNC(!(*M1), 's');
    1025   if (!strcmp (op, "--"))     V_FUNC(-1*(*M1), 's'); // NOTE: opihi_int is signed
    1026   if (!strcmp (op, "isinf"))  V_FUNC(!finite(*M1), 'S');
    1027   if (!strcmp (op, "isnan"))  V_FUNC(isnan(*M1), 'S');
    1028   if (!strcmp (op, "xramp"))  V_FUNC(i, 's');
    1029   if (!strcmp (op, "yramp"))  V_FUNC(0, 's');
     1201  if (!strcmp (op, "="))      V_FUNC(*M1, ST_SCALAR_INT);
     1202  if (!strcmp (op, "abs"))    V_FUNC(fabs(*M1), ST_SCALAR_INT);
     1203  if (!strcmp (op, "int"))    V_FUNC((long long)(*M1), ST_SCALAR_INT);
     1204  if (!strcmp (op, "exp"))    V_FUNC(exp(*M1), ST_SCALAR_FLT);
     1205  if (!strcmp (op, "ten"))    V_FUNC(pow(10.0,*M1), ST_SCALAR_FLT);
     1206  if (!strcmp (op, "log"))    V_FUNC(log10(*M1), ST_SCALAR_FLT);
     1207  if (!strcmp (op, "ln"))     V_FUNC(log(*M1), ST_SCALAR_FLT);
     1208  if (!strcmp (op, "sqrt"))   V_FUNC(sqrt(*M1), ST_SCALAR_FLT);
     1209  if (!strcmp (op, "erf"))    V_FUNC(erf(*M1), ST_SCALAR_FLT);
     1210  if (!strcmp (op, "sinh"))   V_FUNC(sinh(*M1), ST_SCALAR_FLT);
     1211  if (!strcmp (op, "cosh"))   V_FUNC(cosh(*M1), ST_SCALAR_FLT);
     1212  if (!strcmp (op, "asinh"))  V_FUNC(asinh(*M1), ST_SCALAR_FLT);
     1213  if (!strcmp (op, "acosh"))  V_FUNC(acosh(*M1), ST_SCALAR_FLT);
     1214  if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), ST_SCALAR_FLT);
     1215  if (!strcmp (op, "sin"))    V_FUNC(sin(*M1), ST_SCALAR_FLT);
     1216  if (!strcmp (op, "cos"))    V_FUNC(cos(*M1), ST_SCALAR_FLT);
     1217  if (!strcmp (op, "tan"))    V_FUNC(tan(*M1), ST_SCALAR_FLT);
     1218  if (!strcmp (op, "dsin"))   V_FUNC(sin(*M1*RAD_DEG), ST_SCALAR_FLT);
     1219  if (!strcmp (op, "dcos"))   V_FUNC(cos(*M1*RAD_DEG), ST_SCALAR_FLT);
     1220  if (!strcmp (op, "dtan"))   V_FUNC(tan(*M1*RAD_DEG), ST_SCALAR_FLT);
     1221  if (!strcmp (op, "asin"))   V_FUNC(asin(*M1), ST_SCALAR_FLT);
     1222  if (!strcmp (op, "acos"))   V_FUNC(acos(*M1), ST_SCALAR_FLT);
     1223  if (!strcmp (op, "atan"))   V_FUNC(atan(*M1), ST_SCALAR_FLT);
     1224  if (!strcmp (op, "dasin"))  V_FUNC(asin(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1225  if (!strcmp (op, "dacos"))  V_FUNC(acos(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1226  if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1227  if (!strcmp (op, "rnd"))    V_FUNC(drand48(), ST_SCALAR_FLT);
     1228  if (!strcmp (op, "ramp"))   V_FUNC(i, ST_SCALAR_INT);
     1229  if (!strcmp (op, "zero"))   V_FUNC(0, ST_SCALAR_INT);
     1230  if (!strcmp (op, "not"))    V_FUNC(!(*M1), ST_SCALAR_INT);
     1231  if (!strcmp (op, "--"))     V_FUNC(-1*(*M1), ST_SCALAR_INT); // NOTE: opihi_int is signed
     1232  if (!strcmp (op, "isinf"))  V_FUNC(!finite(*M1), ST_SCALAR_FLT);
     1233  if (!strcmp (op, "isnan"))  V_FUNC(isnan(*M1), ST_SCALAR_FLT);
     1234  if (!strcmp (op, "xramp"))  V_FUNC(i, ST_SCALAR_INT);
     1235  if (!strcmp (op, "yramp"))  V_FUNC(0, ST_SCALAR_INT);
    10301236  /* xramp and yramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */
    10311237
     
    10341240escape:
    10351241
    1036   if (V1[0].type == 'v') {
     1242  if (V1[0].type == ST_VECTOR_TMP) {
    10371243    free (V1[0].vector[0].elements.Ptr);
    10381244    free (V1[0].vector);
     
    10531259  Ny = V1[0].buffer[0].matrix.Naxis[1];
    10541260
    1055   if (V1[0].type == 'm') {
     1261  if (V1[0].type == ST_MATRIX_TMP) {
    10561262    OUT[0].buffer = V1[0].buffer;
    1057     V1[0].type = 'M'; /* prevent it from being freed below */
     1263    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    10581264  } else {
    10591265    OUT[0].buffer = InitBuffer ();
    10601266    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    10611267  }
    1062   OUT[0].type = 'm';      /*** <<--- says this is a temporary matrix ***/
     1268  OUT[0].type = ST_MATRIX_TMP;      /*** <<--- says this is a temporary matrix ***/
    10631269  M1  = (float *) V1[0].buffer[0].matrix.buffer;
    10641270  out = (float *)OUT[0].buffer[0].matrix.buffer;
     
    11161322  }
    11171323 
    1118   if (V1[0].type == 'm') {
     1324  if (V1[0].type == ST_MATRIX_TMP) {
    11191325    free (V1[0].buffer[0].header.buffer);
    11201326    free (V1[0].buffer[0].matrix.buffer);
  • trunk/Ohana/src/opihi/pantasks/CheckController.c

    r23530 r36375  
    2929  if (p != NULL) goto escape;
    3030
     31  /** skip past any leading garbage? ***/
     32
     33  /** find "Njobs: **/
     34  p = memstr (buffer.buffer, "BEGIN BLOCK Njobs:", MIN(buffer.Nbuffer, 256));
     35  p += strlen("BEGIN BLOCK Njobs:");
     36
    3137  /** parse job list **/
    32   status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     38  status = sscanf (p, "%d", &Njobs);
    3339  if (status != 1) goto escape;
    3440  if (VerboseMode()) gprint (GP_ERR, "parse %d jobs on stack %f\n", Njobs, TimerElapsed(&start, TRUE));
    3541
    36   p = buffer.buffer;
     42  /* output looks like:
     43     BEGIN BLOCK Njobs: NN\n
     44     ID name machine\n
     45     ID name machine\n
     46  */
     47
     48  // p is currently pointing at "BEGIN BLOCK Njobs"
     49
    3750  for (i = 0; i < Njobs; i++) {
    3851    q = strchr (p, '\n');
     
    6780  if (p != NULL) goto escape;
    6881
     82  /** skip past any leading garbage? ***/
     83
     84  /** find "Njobs: **/
     85  p = memstr (buffer.buffer, "BEGIN BLOCK Njobs:", MIN(buffer.Nbuffer, 256));
     86  p += strlen("BEGIN BLOCK Njobs:");
     87
    6988  /** parse job list **/
    70   status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     89  status = sscanf (p, "%d", &Njobs);
    7190  if (status != 1) goto escape;
    7291  if (VerboseMode()) gprint (GP_ERR, "check crash stack %f\n", TimerElapsed(&start, TRUE));
    7392
    74   p = buffer.buffer;
     93  /* output looks like:
     94     BEGIN BLOCK Njobs: NN\n
     95     ID name machine\n
     96     ID name machine\n
     97  */
     98
     99  // p is currently pointing at "BEGIN BLOCK Njobs"
     100
    75101  for (i = 0; i < Njobs; i++) {
    76102    q = strchr (p, '\n');
  • trunk/Ohana/src/opihi/pcontrol/JobOps.c

    r32632 r36375  
    5959  pcontrol_exit (53);
    6060  return (NULL);
     61}
     62
     63int GetJobStackIDbyName (char *name) {
     64  if (!strcasecmp (name, "ALLJOBS"))  return PCONTROL_JOB_ALLJOBS;
     65  if (!strcasecmp (name, "PENDING"))  return PCONTROL_JOB_PENDING;
     66  if (!strcasecmp (name, "BUSY"))     return PCONTROL_JOB_BUSY   ;
     67  if (!strcasecmp (name, "RESP"))     return PCONTROL_JOB_RESP   ;
     68  if (!strcasecmp (name, "DONE"))     return PCONTROL_JOB_DONE   ;
     69  if (!strcasecmp (name, "KILL"))     return PCONTROL_JOB_KILL   ;
     70  if (!strcasecmp (name, "EXIT"))     return PCONTROL_JOB_EXIT   ;
     71  if (!strcasecmp (name, "CRASH"))    return PCONTROL_JOB_CRASH  ;
     72  return (PCONTROL_JOB_NONE);
    6173}
    6274
  • trunk/Ohana/src/opihi/pcontrol/jobstack.c

    r12470 r36375  
    2222  /* print list */
    2323  LockStack (stack);
    24   gprint (GP_LOG, "Njobs: %d\n", stack[0].Nobject);
     24  gprint (GP_LOG, "BEGIN BLOCK Njobs: %d\n", stack[0].Nobject);
    2525  for (i = 0; i < stack[0].Nobject; i++) {
    2626    job = stack[0].object[i];
  • trunk/Ohana/src/opihi/pcontrol/status.c

    r32632 r36375  
    11# include "pcontrol.h"
    22
    3 int PrintJobStack (int Nstack);
     3int PrintJobStack (int Nstack, char *command, char *hostname, int state, float age);
    44int PrintHostStack (int Nstack);
    55
    66int status (int argc, char **argv) {
    77
    8   PrintJobStack (PCONTROL_JOB_ALLJOBS);
    9   PrintHostStack (PCONTROL_HOST_ALLHOSTS);
     8  int N;
     9
     10  if (get_argument (argc, argv, "-h")) goto usage;
     11  if (get_argument (argc, argv, "-help")) goto usage;
     12  if (get_argument (argc, argv, "--help")) goto usage;
     13
     14  /* I would like to add the following options:
     15   * strsub on argv[0]
     16   * strsub on hostname, realhost
     17   * list hostname and realhost
     18   * filter by state
     19   * filter by dtime
     20  */
     21
     22  // -cmd (cmd)
     23  // -host (hostname)
     24  // -state (busy, pending, done, kill, exit, crash, resp, hung
     25  // -age (seconds?) (minutes?)
     26  // -nohost
     27
     28  char *COMMAND = NULL;
     29  if ((N = get_argument (argc, argv, "-cmd"))) {
     30    remove_argument (N, &argc, argv);
     31    COMMAND = strcreate (argv[N]);
     32    remove_argument (N, &argc, argv);
     33  }
     34
     35  char *HOSTNAME = NULL;
     36  if ((N = get_argument (argc, argv, "-host"))) {
     37    remove_argument (N, &argc, argv);
     38    HOSTNAME = strcreate (argv[N]);
     39    remove_argument (N, &argc, argv);
     40  }
     41
     42  int STATE = PCONTROL_JOB_ALLJOBS;
     43  if ((N = get_argument (argc, argv, "-state"))) {
     44    remove_argument (N, &argc, argv);
     45    STATE = GetJobStackIDbyName (argv[N]);
     46    remove_argument (N, &argc, argv);
     47    if (STATE == PCONTROL_JOB_NONE) goto usage;
     48  }
     49
     50  float AGE = 0.0;
     51  if ((N = get_argument (argc, argv, "-age"))) {
     52    remove_argument (N, &argc, argv);
     53    AGE = atof (argv[N]);
     54    remove_argument (N, &argc, argv);
     55  }
     56
     57  int SHOWHOST = TRUE;
     58  if ((N = get_argument (argc, argv, "-nohost"))) {
     59    remove_argument (N, &argc, argv);
     60    SHOWHOST = FALSE;
     61  }
     62  if ((N = get_argument (argc, argv, "+jobs"))) {
     63    remove_argument (N, &argc, argv);
     64    SHOWHOST = FALSE;
     65  }
     66
     67  int SHOWJOBS = TRUE;
     68  if ((N = get_argument (argc, argv, "-nojobs"))) {
     69    remove_argument (N, &argc, argv);
     70    SHOWJOBS = FALSE;
     71  }
     72  if ((N = get_argument (argc, argv, "+host"))) {
     73    remove_argument (N, &argc, argv);
     74    SHOWJOBS = FALSE;
     75  }
     76
     77  if (SHOWJOBS) {
     78    PrintJobStack (PCONTROL_JOB_ALLJOBS, COMMAND, HOSTNAME, STATE, AGE);
     79  }
     80  if (SHOWHOST) {
     81    PrintHostStack (PCONTROL_HOST_ALLHOSTS);
     82  }
    1083
    1184  return (TRUE);
     85
     86usage:
     87  gprint (GP_ERR, "USAGE: status [-cmd command] [-host hostname] [-state state] [-age seconds] [+jobs,-nohost] [+host,-nojobs]\n");
     88  return FALSE;
    1289}
    1390
    14 int PrintJobStack (int Nstack) {
     91int PrintJobStack (int Nstack, char *command, char *hostname, int state, float age) {
    1592
    1693  int i, j, Nobject;
     
    30107    job = stack[0].object[i];
    31108    ASSERT (job != NULL, "programming error");
    32     if (job[0].realhost == NULL) {
    33         gprint (GP_LOG, "%3d %9s ", i, job[0].hostname);
    34     } else {
    35         gprint (GP_LOG, "%3d %9s ", i, job[0].realhost);
    36     }
    37     gprint (GP_LOG, "%7s  ", GetJobStackName (job[0].state));
     109
     110    char *thishost = (job[0].realhost == NULL) ? job[0].hostname : job[0].realhost;
    38111
    39112    switch (job[0].state) {
     
    45118        gettimeofday (&now, (void *) NULL);
    46119        dtime = DTIME (now, job[0].start);
    47         gprint (GP_LOG, "%8.2f ", dtime);
    48120        break;
    49121
     
    55127      default:
    56128        dtime = DTIME (job[0].stop, job[0].start);
    57         gprint (GP_LOG, "%8.2f ", dtime);
    58129        break;
    59130    }
     131
     132    // check on the filters
     133    if (command) {
     134      if (!strstr (job[0].argv[0], command)) continue;
     135    }
     136    if (hostname) {
     137      if (!strstr (thishost, hostname)) continue;
     138    }
     139    if (age > 0.0) {
     140      if (dtime < age) continue;
     141    }
     142    if (state != PCONTROL_JOB_ALLJOBS) {
     143      // allow PCONTROL_JOB_RESP == BUSY
     144      int validState = FALSE;
     145      validState |= (state == PCONTROL_JOB_RESP) && (job[0].state == PCONTROL_JOB_BUSY);
     146      validState |= (state == PCONTROL_JOB_BUSY) && (job[0].state == PCONTROL_JOB_RESP);
     147      validState |= (state == job[0].state);
     148      if (!validState) continue;
     149    }
     150
     151    gprint (GP_LOG, "%3d %9s ", i, thishost);
     152    gprint (GP_LOG, "%7s  ", GetJobStackName (job[0].state));
     153    gprint (GP_LOG, "%8.2f ", dtime);
    60154
    61155    PrintID (GP_LOG, job[0].JobID);
  • trunk/Ohana/src/relastro/src

Note: See TracChangeset for help on using the changeset viewer.