Index: /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
===================================================================
--- /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c	(revision 1058)
+++ /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c	(revision 1058)
@@ -0,0 +1,242 @@
+/** @file  psMatrixVectorArithmetic.c
+ *
+ *  @brief Provides unary and binary functions for simple matrix and vector element operations. Functions
+ *  include:
+ *
+ *      Addition (+)
+ *      Subtraction (-)
+ *      Multiplication (*)
+ *      Division (/)
+ *      Power (^)
+ *      Minimum (min)
+ *      Maximum (max)
+ *      Absolute value (abs)
+ *      Exponent (exp)
+ *      Natural Log (ln)
+ *      Power of 10 (ten)
+ *      Log (log)
+ *      Sine (sin or dsin)
+ *      Cosine (cos or dcos)
+ *      Tangent (tan or dtan)
+ *      Arcsine (asin or dasin)
+ *      Arccosine (acos or dacos)
+ *      Arctan (atan or datan)
+ *
+ *  Currently only vector-vector and image-image binary operations are supported.
+ *
+ *  @ingroup MatrixVectorArithmetic
+ *
+ *  @author Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-18 00:54:43 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+/******************************************************************************/
+/*  INCLUDE FILES                                                             */
+/******************************************************************************/
+#include <string.h>
+#include <math.h>
+#include <stdint.h>
+
+#include "psMemory.h"
+#include "psError.h"
+#include "psImage.h"
+#include "psVector.h"
+
+/******************************************************************************/
+/*  DEFINE STATEMENTS                                                         */
+/******************************************************************************/
+
+// None
+
+/******************************************************************************/
+/*  TYPE DEFINITIONS                                                          */
+/******************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/*  GLOBAL VARIABLES                                                         */
+/*****************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/*  FILE STATIC VARIABLES                                                    */
+/*****************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
+/*****************************************************************************/
+
+#define MIN(A,B) (((A) < (B)) ? (A) : (B))
+
+#define MAX(A,B) (((A) > (B)) ? (A) : (B))
+
+#define VECTOR_VECTOR(OUT,IN1,OP,IN2,TYPE)                                                                   \
+{                                                                                                            \
+    int i = 0;                                                                                               \
+    int npt = 0;                                                                                             \
+    ps##TYPE *o = NULL;                                                                                      \
+    ps##TYPE *i1 = NULL;                                                                                     \
+    ps##TYPE *i2 = NULL;                                                                                     \
+    npt  = ((psVector*)IN1)->n;                                                                              \
+    o  = ((psVector*)OUT)->data.TYPE;                                                                        \
+    i1 = ((psVector*)IN1)->data.TYPE;                                                                        \
+    i2 = ((psVector*)IN2)->data.TYPE;                                                                        \
+    for (i=0; i < npt; i++, o++, i1++, i2++) {                                                               \
+        *o = OP;                                                                                             \
+    }                                                                                                        \
+}
+
+#define IMAGE_IMAGE(OUT,IN1,OP,IN2,TYPE)                                                                     \
+{                                                                                                            \
+    int i = 0;                                                                                               \
+    int j = 0;                                                                                               \
+    int numRows = 0;                                                                                         \
+    int numCols = 0;                                                                                         \
+    ps##TYPE *o = NULL;                                                                                      \
+    ps##TYPE *i1 = NULL;                                                                                     \
+    ps##TYPE *i2 = NULL;                                                                                     \
+    numRows = ((psImage*)IN1)->numRows;                                                                      \
+    numCols = ((psImage*)IN1)->numCols;                                                                      \
+    for(j = 0; j < numCols; j++) {                                                                           \
+        o  = ((psImage*)OUT)->data.TYPE[j];                                                                  \
+        i1 = ((psImage*)IN1)->data.TYPE[j];                                                                  \
+        i2 = ((psImage*)IN2)->data.TYPE[j];                                                                  \
+        for(i = 0; i < numRows; i++, o++, i1++, i2++) {                                                      \
+            *o = OP;                                                                                         \
+        }                                                                                                    \
+    }                                                                                                        \
+}
+
+#define LEVEL1(DIM1,DIM2,OUT,IN1,OP,IN2)                                                                     \
+switch (IN1->type) {                                                                                         \
+case PS_TYPE_S8:                                                                                          \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,S8);                                                                       \
+    break;                                                                                                  \
+case PS_TYPE_U8:                                                                                          \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,U8);                                                                       \
+    break;                                                                                                  \
+case PS_TYPE_S16:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,S16);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_U16:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,U16);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_S32:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,S32);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_U32:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,U32);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_S64:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,S64);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_U64:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,U64);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_F32:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,F32);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_F64:                                                                                         \
+    DIM1##_##DIM2(OUT,IN1,OP,IN2,F64);                                                                      \
+    break;                                                                                                  \
+case PS_TYPE_C32:                                                                                         \
+    psError(__func__, ": Line %d - C32 support not implemented", __LINE__);                               \
+    /*DIM1##_##DIM2(OUT,IN1,OP,IN2,C32);       */                                                            \
+    break;                                                                                                  \
+case PS_TYPE_C64:                                                                                         \
+    psError(__func__, ": Line %d - C64 support not implemented", __LINE__);                               \
+    /*DIM1##_##DIM2(OUT,IN1,OP,IN2,C64);         */                                                         \
+    break;                                                                                                 \
+default:                                                                                                  \
+    psError(__func__, ": Line %d - Invalid PS_TYPE: %d", __LINE__, IN1->type);                           \
+}
+
+#define LEVEL2(DIM1,DIM2,OUT,IN1,OP,IN2)                                                                     \
+if(!strncmp(OP, "+", 1)) {                                                                               \
+    LEVEL1(DIM1,DIM2,OUT,IN1,*i1 + *i2,IN2);                                                             \
+} else if(!strncmp(OP, "-", 1)) {                                                                         \
+    LEVEL1(DIM1, DIM2,OUT,IN1,*i1 - *i2,IN2);                                                            \
+} else if(!strncmp(OP, "*", 1)) {                                                                         \
+    LEVEL1(DIM1,DIM2,OUT,IN1,*i1 * *i2,IN2);                                                             \
+} else if(!strncmp(OP, "/", 1)) {                                                                         \
+    LEVEL1(DIM1,DIM2,OUT,IN1,*i1 / *i2,IN2);                                                             \
+} else if(!strncmp(OP, "^", 1)) {                                                                         \
+    LEVEL1(DIM1,DIM2,OUT,IN1,pow(*i1,*i2),IN2);                                                          \
+} else if(!strncmp(OP, "min", 3)) {                                                                       \
+    LEVEL1(DIM1,DIM2,OUT,IN1,MIN(*i1,*i2),IN2);                                                          \
+} else if(!strncmp(OP, "max", 3)) {                                                                       \
+    LEVEL1(DIM1,DIM2,OUT,IN1,MAX(*i1,*i2),IN2);                                                          \
+} else {                                                                                                  \
+    psError(__func__, ": Line %d - Invalid operator: %s", __LINE__, #OP);                                \
+}
+
+void *psBinaryOp(void *out, void *in1, char *op, void *in2)
+{
+    psDimen dim1 = 0;
+    psDimen dim2 = 0;
+    psDimen dimOut = 0;
+    psType *psType1 = NULL;
+    psType *psType2 = NULL;
+    psType *psTypeOut = NULL;
+
+    psTypeOut = (psType*)out;
+    if(psTypeOut == NULL) {
+        psError(__func__, ": Line %d - Null out argument", __LINE__);
+        return out;
+    }
+
+    psType1 = (psType*)in1;
+    if(psType1 == NULL) {
+        psError(__func__, ": Line %d - Null in1 argument", __LINE__);
+        return out;
+    }
+
+    psType2 = (psType*)in2;
+    if(psType2 == NULL) {
+        psError(__func__, ": Line %d - Null in2 argument", __LINE__);
+        return out;
+    }
+
+    dim1 = psType1->dimen;
+    dim2 = psType2->dimen;
+    dimOut = psTypeOut->dimen;
+
+    if(dimOut == PS_DIMEN_OTHER) {
+        psError(__func__, ": Line %d - Invalid dimensionality for out arg: %d", __LINE__, dimOut);
+        return out;
+    }
+
+    if(dim1 == PS_DIMEN_VECTOR) {
+        if(dim2 == PS_DIMEN_VECTOR) {
+            LEVEL2(VECTOR,VECTOR,out,psType1,op,psType2);      // Vector op vector
+        } else if(dim2 == PS_DIMEN_IMAGE) {
+            //LEVEL2(VECTOR,IMAGE,out,in1,op,in2);       // Vector op image
+        } else {
+            psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
+        }
+    } else if(dim1 == PS_DIMEN_IMAGE) {
+        if(dim2 == PS_DIMEN_VECTOR) {
+            //LEVEL2(IMAGE,VECTOR,out,in1,op,in2);        // Image op vector
+        } else if(dim2 == PS_DIMEN_IMAGE) {
+            LEVEL2(IMAGE,IMAGE,out,psType1,op,in2);        // Image op image
+        } else {
+            psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
+        }
+    } else {
+        psError(__func__, ": Line %d - Invalid dimensionality for in1 arg: %d", __LINE__, dim1);
+    }
+
+    return out;
+}
+
+
+
+
Index: /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.h
===================================================================
--- /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.h	(revision 1058)
+++ /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.h	(revision 1058)
@@ -0,0 +1,87 @@
+/** @file  psMatrixVectorArithmetic.h
+ *
+ *  @brief Provides unary and binary functions for simple matrix and vector element operations. Functions
+ *  include:
+ *
+ *      Addition (+)
+ *      Subtraction (-)
+ *      Multiplication (*)
+ *      Division (/)
+ *      Power (^)
+ *      Minimum (min)
+ *      Maximum (max)
+ *      Absolute value (abs)
+ *      Exponent (exp)
+ *      Natural Log (ln)
+ *      Power of 10 (ten)
+ *      Log (log)
+ *      Sine (sin or dsin)
+ *      Cosine (cos or dcos)
+ *      Tangent (tan or dtan)
+ *      Arcsine (asin or dasin)
+ *      Arccosine (acos or dacos)
+ *      Arctan (atan or datan)
+ *
+ *  Currently only vector-vector and image-image binary operations are supported.
+ *
+ *  @ingroup MatrixVectorArithmetic
+ *
+ *  @author Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-18 00:54:43 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#ifndef PSMATRIX_VECTOR_ARITHMETIC_H
+#define PSMATRIX_VECTOR_ARITHMETIC_H
+
+/// @addtogroup MatrixVectorArithmetic
+/// @{
+
+/** Perform simple binary arithmetic with images or vectors
+ *
+ *  Performs addition, subtraction, multiplication, division, power, minumum, and maximum arithmetic
+ *  operations with images and vectors. Uses the form:
+ *
+ *      out = in1 op in2,
+ *
+ *      Where op is: "+", "-", "*", "/", "^", "min", or "max"
+ *
+ *  This function only supports vector-vector or image-image opertions.
+ *
+ *  @return  psType*: Pointer to either psImage or psVector.
+ */
+psType *psBinaryOp(
+    void *out,  /// Output type, either psImage or psVector.
+    void *in1,  /// First input, either psImage or psVector.
+    char *op,   /// Operator.
+    void *in2   /// Second input, either psImage or psVector.
+);
+
+/** Perform simple unary arithmetic with images or vectors
+ *
+ *  Performs absolute value, exponent, natural log, power of 10, log, sine, cosine, tangent, arcsine,
+ *  arccosine, or arctan. operations with images and vectors. Uses the form:
+ *
+ *     out = op(in),
+ *
+ *     Where op is: "abs", "exp", "ln", "ten", "log", "sin", "cos", "tan" "asin", "acos", "atan", "dsin",
+ *                  "dcos", dtan", "dasin", "dacos", or "datan".
+ *
+ *  Trigometric Operations with "d" prefix use units of degrees. Those without are in radians.
+ *
+ *  This function only supports vector-vector or image-image opertions.
+ *
+ *  @return  psType*: Pointer to either psImage or psVector.
+ */
+psType *psUnaryOp(
+    void *out,  /// Output type, either psImage or psVector.
+    void *in,   /// Input, either psImage or psVector.
+    char *op    /// Operator.
+);
+
+/// @}
+
+#endif
