Index: /trunk/psLib/src/math/psUnaryOp.c
===================================================================
--- /trunk/psLib/src/math/psUnaryOp.c	(revision 7192)
+++ /trunk/psLib/src/math/psUnaryOp.c	(revision 7193)
@@ -30,6 +30,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-18 22:04:28 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-05-24 03:25:14 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -65,121 +65,101 @@
 
 // Unary SCALAR operations
-#define SCALAR(OUT,IN,OP,TYPE)                                                                               \
-{                                                                                                            \
-    ps##TYPE *o = NULL;                                                                                      \
-    ps##TYPE *i1 = NULL;                                                                                     \
-    o  = &((psScalar* )OUT)->data.TYPE;                                                                      \
-    i1 = &((psScalar* )IN)->data.TYPE;                                                                       \
-    *o = OP;                                                                                                 \
+#define SCALAR(OUT,IN,OP,TYPE) \
+{ \
+    ps##TYPE *o  = &((psScalar*)OUT)->data.TYPE; \
+    ps##TYPE *i1 = &((psScalar*)IN)->data.TYPE; \
+    *o = OP; \
 }
 
 // Unary IMAGE operations
-#define VECTOR(OUT,IN,OP,TYPE)                                                                               \
-{                                                                                                            \
-    psS32 i = 0;                                                                                             \
-    psS32 nIn = 0;                                                                                           \
-    psS32 nOut = 0;                                                                                          \
-    ps##TYPE *o = NULL;                                                                                      \
-    ps##TYPE *i1 = NULL;                                                                                     \
-    nIn = ((psVector* )IN)->n;                                                                               \
-    nOut = ((psVector* )OUT)->n;                                                                             \
-    if(nIn != nOut) {                                                                                        \
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                             \
-                PS_ERRORTEXT_psMatrix_COUNT_DIFFERS,                                                         \
-                nIn, nOut);                                                                                  \
-        if (OUT != IN) {                                                                                     \
-            psFree(OUT);                                                                                     \
-        }                                                                                                    \
-        return NULL;                                                                                         \
-    }                                                                                                        \
-    o  = ((psVector* )OUT)->data.TYPE;                                                                       \
-    i1 = ((psVector* )IN)->data.TYPE;                                                                        \
-    for(i = 0; i < nIn; i++, o++, i1++) {                                                                    \
-        *o = OP;                                                                                             \
-    }                                                                                                        \
+#define VECTOR(OUT,IN,OP,TYPE) \
+{ \
+    long nIn = ((psVector*)IN)->n; \
+    long nOut = ((psVector*)OUT)->n; \
+    if (nIn != nOut) { \
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psMatrix_COUNT_DIFFERS, nIn, nOut); \
+        if (OUT != IN) { \
+            psFree(OUT); \
+        } \
+        return NULL; \
+    } \
+    ps##TYPE *o  = ((psVector*)OUT)->data.TYPE; \
+    ps##TYPE *i1 = ((psVector*)IN)->data.TYPE; \
+    for (long i = 0; i < nIn; i++, o++, i1++) { \
+        *o = OP; \
+    } \
 }
 
 // Unary IMAGE operations
-#define IMAGE(OUT,IN,OP,TYPE)                                                                                \
-{                                                                                                            \
-    psS32 i = 0;                                                                                             \
-    psS32 j = 0;                                                                                             \
-    psS32 numRowsIn = 0;                                                                                     \
-    psS32 numColsIn = 0;                                                                                     \
-    psS32 numRowsOut = 0;                                                                                    \
-    psS32 numColsOut = 0;                                                                                    \
-    ps##TYPE *o = NULL;                                                                                      \
-    ps##TYPE *i1 = NULL;                                                                                     \
-    numRowsIn = ((psImage* )IN)->numRows;                                                                    \
-    numColsIn = ((psImage* )IN)->numCols;                                                                    \
-    numRowsOut = ((psImage* )OUT)->numRows;                                                                  \
-    numColsOut = ((psImage* )OUT)->numCols;                                                                  \
-    if(numRowsIn!=numRowsOut || numColsIn!=numColsOut) {                                                     \
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                             \
-                PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS,                                                    \
-                numColsIn, numRowsIn, numColsOut, numRowsOut);                                               \
-        if (OUT != IN) {                                                                                     \
-            psFree(OUT);                                                                                     \
-        }                                                                                                    \
-        return NULL;                                                                                         \
-    }                                                                                                        \
-    for(j = 0; j < numRowsIn; j++) {                                                                         \
-        o  = ((psImage* )OUT)->data.TYPE[j];                                                                 \
-        i1 = ((psImage* )IN)->data.TYPE[j];                                                                  \
-        for(i = 0; i < numColsIn; i++, o++, i1++) {                                                          \
-            *o = OP;                                                                                         \
-        }                                                                                                    \
-    }                                                                                                        \
+#define IMAGE(OUT,IN,OP,TYPE) \
+{ \
+    long numRowsIn = ((psImage*)IN)->numRows; \
+    long numColsIn = ((psImage*)IN)->numCols; \
+    long numRowsOut = ((psImage*)OUT)->numRows; \
+    long numColsOut = ((psImage*)OUT)->numCols; \
+    if(numRowsIn!=numRowsOut || numColsIn!=numColsOut) { \
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS, \
+                numColsIn, numRowsIn, numColsOut, numRowsOut); \
+        if (OUT != IN) { \
+            psFree(OUT); \
+        } \
+        return NULL; \
+    } \
+    for (long j = 0; j < numRowsIn; j++) { \
+        ps##TYPE *o  = ((psImage* )OUT)->data.TYPE[j]; \
+        ps##TYPE *i1 = ((psImage* )IN)->data.TYPE[j]; \
+        for (long i = 0; i < numColsIn; i++, o++, i1++) { \
+            *o = OP; \
+        } \
+    }\
 }
 
 // Preprocessor macro function to create arithmetic function based on input type
-#define UNARY_TYPE(DIM,OUT,IN,OP)                                                                            \
-switch (IN->type) {                                                                                          \
-case PS_TYPE_S32:                                                                                            \
-    DIM(OUT,IN,OP,S32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_F32:                                                                                            \
-    DIM(OUT,IN,OP,F32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_F64:                                                                                            \
-    DIM(OUT,IN,OP,F64);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_C32:                                                                                            \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_S8:                                                                                             \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_U8:                                                                                             \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_S16:                                                                                            \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_U16:                                                                                            \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_U32:                                                                                            \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_S64:                                                                                            \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_U64:                                                                                            \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-case PS_TYPE_C64:                                                                                            \
-    DIM(OUT,IN,OP,C32);                                                                                      \
-    break;                                                                                                   \
-default: {                                                                                                     \
-        char* strType;                                                                                           \
-        PS_TYPE_NAME(strType, IN->type);                                                                         \
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                                 \
-                PS_ERRORTEXT_psMatrix_TYPE_MISMATCH,                                                             \
-                strType);                                                                                        \
-        if (OUT != IN) {                                                                                         \
-            psFree(OUT);                                                                                         \
-        }                                                                                                        \
-        return NULL;                                                                                             \
+#define UNARY_TYPE(DIM,OUT,IN,OP) \
+switch (IN->type) { \
+case PS_TYPE_S32: \
+    DIM(OUT,IN,OP,S32); \
+    break; \
+case PS_TYPE_F32: \
+    DIM(OUT,IN,OP,F32); \
+    break; \
+case PS_TYPE_F64: \
+    DIM(OUT,IN,OP,F64); \
+    break; \
+case PS_TYPE_C32: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_S8: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_U8: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_S16: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_U16: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_U32: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_S64: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_U64: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+case PS_TYPE_C64: \
+    DIM(OUT,IN,OP,C32); \
+    break; \
+default: { \
+        char* strType; \
+        PS_TYPE_NAME(strType, IN->type); \
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true, PS_ERRORTEXT_psMatrix_TYPE_MISMATCH, strType); \
+        if (OUT != IN) { \
+            psFree(OUT); \
+        } \
+        return NULL; \
     } \
 }
@@ -187,119 +167,117 @@
 // Preprocessor macro function to create arithmetic function operation name. Functions below that add
 // FLT_EPSILON are done so to align results with a 64 bit computing architecture
-#define UNARY_OP(DIM,OUT,IN,OP)                                                                              \
-if(!strncmp(OP, "abs", 3)) {                                                                                 \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,cabs(*i1));                                                                    \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,fabs(*i1));                                                                    \
-    }                                                                                                        \
-} else if(!strncmp(OP, "exp", 3)) {                                                                          \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,cexp(*i1));                                                                    \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,exp(*i1));                                                                     \
-    }                                                                                                        \
-} else if(!strncmp(OP, "ln", 2)) {                                                                           \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,clog(*i1));                                                                    \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,log(*i1));                                                                     \
-    }                                                                                                        \
-} else if(!strncmp(OP, "ten", 3)) {                                                                          \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,cpow(10.0,*i1));                                                               \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,pow(10.0,*i1));                                                                \
-    }                                                                                                        \
-} else if(!strncmp(OP, "log", 3)) {                                                                          \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,clog(*i1)/log(10.0));                                                          \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,log10(*i1));                                                                   \
-    }                                                                                                        \
-} else if(!strncmp(OP, "sin", 3)) {                                                                          \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,csin(*i1));                                                                    \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,sin(*i1));                                                                     \
-    }                                                                                                        \
-} else if(!strncmp(OP, "dsin", 4)) {                                                                         \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,csin(*i1*D2R));                                                                \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,sin(*i1*D2R));                                                                 \
-    }                                                                                                        \
-} else if(!strncmp(OP, "cos", 3)) {                                                                          \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,ccos(*i1));                                                                    \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,cos(*i1));                                                                     \
-    }                                                                                                        \
-} else if(!strncmp(OP, "dcos", 4)) {                                                                         \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,ccos(*i1*D2R));                                                                \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,cos(*i1*D2R));                                                                 \
-    }                                                                                                        \
-} else if(!strncmp(OP, "tan", 3)) {                                                                          \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,ctan(*i1));                                                                    \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,tan(*i1));                                                                     \
-    }                                                                                                        \
-} else if(!strncmp(OP, "dtan", 4)) {                                                                         \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,ctan(*i1*D2R));                                                                \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,tan(*i1*D2R));                                                                 \
-    }                                                                                                        \
-} else if(!strncmp(OP, "asin", 4)) {                                                                         \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,casin(*i1));                                                                   \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,asin(*i1));                                                                    \
-    }                                                                                                        \
-} else if(!strncmp(OP, "dasin", 5)) {                                                                        \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,R2D*casin(*i1));                                                               \
-    } else if(PS_IS_PSELEMTYPE_INT(IN->type)) {                                                              \
-        UNARY_TYPE(DIM,OUT,IN,(R2D*asin(*i1)));                                                              \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,(R2D*asin(*i1)));                                                              \
-    }                                                                                                        \
-} else if(!strncmp(OP, "acos", 4)) {                                                                         \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,cacos(*i1));                                                                   \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,acos(*i1));                                                                    \
-    }                                                                                                        \
-} else if(!strncmp(OP, "dacos", 5)) {                                                                        \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,R2D*cacos(*i1));                                                               \
-    } else if(PS_IS_PSELEMTYPE_INT(IN->type)) {                                                              \
-        UNARY_TYPE(DIM,OUT,IN,(R2D*acos(*i1)));                                                              \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,R2D*acos(*i1));                                                                \
-    }                                                                                                        \
-} else if(!strncmp(OP, "atan", 4)) {                                                                         \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,catan(*i1));                                                                   \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,atan(*i1));                                                                    \
-    }                                                                                                        \
-} else if(!strncmp(OP, "datan", 5)) {                                                                        \
-    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) {                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,R2D*catan(*i1));                                                               \
-    } else {                                                                                                 \
-        UNARY_TYPE(DIM,OUT,IN,R2D*atan(*i1));                                                                \
-    }                                                                                                        \
-} else {                                                                                                     \
-    psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                                \
-            PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED,                                                     \
-            OP);                                                                                             \
-    if (OUT != IN) {                                                                                         \
-        psFree(OUT);                                                                                         \
-    }                                                                                                        \
-    return NULL;                                                                                             \
+#define UNARY_OP(DIM,OUT,IN,OP) \
+if(!strncmp(OP, "abs", 3)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,cabs(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,fabs(*i1)); \
+    } \
+} else if(!strncmp(OP, "exp", 3)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,cexp(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,exp(*i1)); \
+    } \
+} else if(!strncmp(OP, "ln", 2)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,clog(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,log(*i1)); \
+    } \
+} else if(!strncmp(OP, "ten", 3)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,cpow(10.0,*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,pow(10.0,*i1)); \
+    } \
+} else if(!strncmp(OP, "log", 3)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,clog(*i1)/log(10.0)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,log10(*i1)); \
+    } \
+} else if(!strncmp(OP, "sin", 3)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,csin(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,sin(*i1)); \
+    } \
+} else if(!strncmp(OP, "dsin", 4)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,csin(*i1*D2R)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,sin(*i1*D2R)); \
+    } \
+} else if(!strncmp(OP, "cos", 3)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,ccos(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,cos(*i1)); \
+    } \
+} else if(!strncmp(OP, "dcos", 4)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,ccos(*i1*D2R)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,cos(*i1*D2R)); \
+    } \
+} else if(!strncmp(OP, "tan", 3)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,ctan(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,tan(*i1)); \
+    } \
+} else if(!strncmp(OP, "dtan", 4)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,ctan(*i1*D2R)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,tan(*i1*D2R)); \
+    } \
+} else if(!strncmp(OP, "asin", 4)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,casin(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,asin(*i1)); \
+    } \
+} else if(!strncmp(OP, "dasin", 5)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,R2D*casin(*i1)); \
+    } else if(PS_IS_PSELEMTYPE_INT(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,(R2D*asin(*i1))); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,(R2D*asin(*i1))); \
+    } \
+} else if(!strncmp(OP, "acos", 4)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,cacos(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,acos(*i1)); \
+    } \
+} else if(!strncmp(OP, "dacos", 5)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,R2D*cacos(*i1)); \
+    } else if(PS_IS_PSELEMTYPE_INT(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,(R2D*acos(*i1))); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,R2D*acos(*i1)); \
+    } \
+} else if(!strncmp(OP, "atan", 4)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,catan(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,atan(*i1)); \
+    } \
+} else if(!strncmp(OP, "datan", 5)) { \
+    if(PS_IS_PSELEMTYPE_COMPLEX(IN->type)) { \
+        UNARY_TYPE(DIM,OUT,IN,R2D*catan(*i1)); \
+    } else { \
+        UNARY_TYPE(DIM,OUT,IN,R2D*atan(*i1)); \
+    } \
+} else { \
+    psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED, OP); \
+    if (OUT != IN) { \
+        psFree(OUT); \
+    } \
+    return NULL; \
 }
 
@@ -318,14 +296,11 @@
     PS_ASSERT_GENERAL_PTR_NON_NULL(op, psUnaryOp_EXIT);
 
-    psDimen dimIn = psTypeIn->dimen;
-    psElemType elTypeIn = psTypeIn->type;
-
-    switch (dimIn) {
+    switch (psTypeIn->dimen) {
     case PS_DIMEN_SCALAR:
         if (out == NULL ||
                 ((psType*)out)->dimen != PS_DIMEN_SCALAR ||
-                ((psScalar*)out)->type.type != elTypeIn) {
+                ((psScalar*)out)->type.type != psTypeIn->type) {
             psFree(out);
-            out = psScalarAlloc(0.0,elTypeIn);
+            out = psScalarAlloc(0.0, psTypeIn->type);
         }
         UNARY_OP(SCALAR, out, psTypeIn, op);    // scalar
@@ -334,15 +309,11 @@
     case PS_DIMEN_TRANSV:
         if (((psVector*)in)->n == 0) {
-            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
-                    PS_ERRORTEXT_psMatrix_VECTOR_EMPTY);
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psMatrix_VECTOR_EMPTY);
             psUnaryOp_EXIT;
         }
 
-        out = psVectorRecycle(out,
-                              ((psVector*)in)->n,
-                              elTypeIn);
+        out = psVectorRecycle(out, ((psVector*)in)->n, psTypeIn->type);
         if (out == NULL) {
-            psError(PS_ERR_UNKNOWN, false,
-                    PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED);
+            psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED);
             psUnaryOp_EXIT;
         }
@@ -353,16 +324,11 @@
     case PS_DIMEN_IMAGE:
         if (((psImage* ) in)->numCols == 0 || ((psImage* ) in)->numRows == 0) {
-            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
-                    PS_ERRORTEXT_psMatrix_IMAGE_EMPTY);
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psMatrix_IMAGE_EMPTY);
             psUnaryOp_EXIT;
         }
 
-        out = psImageRecycle(out,
-                             ((psImage*)in)->numCols,
-                             ((psImage*)in)->numRows,
-                             elTypeIn);
+        out = psImageRecycle(out, ((psImage*)in)->numCols, ((psImage*)in)->numRows, psTypeIn->type);
         if (out == NULL) {
-            psError(PS_ERR_UNKNOWN, false,
-                    PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED);
+            psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED);
             psUnaryOp_EXIT;
         }
@@ -374,7 +340,5 @@
             psFree(out);
         }
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
-                PS_ERRORTEXT_psMatrix_DIMEN_INVALID,
-                "in", dimIn);
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psMatrix_DIMEN_INVALID, "in", psTypeIn->dimen);
         psUnaryOp_EXIT;
     }
@@ -382,5 +346,5 @@
     // Automtically free psScalar types, since they are usually allocated in the argument list when this
     // function is called, provided that the input is not the output.
-    if(psTypeIn->dimen==PS_DIMEN_SCALAR && in!=out) {
+    if (psTypeIn->dimen == PS_DIMEN_SCALAR && in!=out) {
         psFree(in);
     }
