IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 31, 2015, 8:36:04 AM (11 years ago)
Author:
eugene
Message:

fix up compressed fits table I/O; add lrand, mrand, drand functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/opihi/lib.shell/stack_math.c

    r38062 r38341  
    1212  // set up the possible operations : int OP int -> int, all else yield float
    1313  // OP is the operation performed on *M1 and *M2
    14 # define SSS_FUNC(OP) {                                         \
     14# define SSS_FUNC(OP) {                                                 \
    1515    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;                                                     \
     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;                                             \
    2121      break;                                                            \
    2222    }                                                                   \
    2323    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;                                                     \
     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;                                             \
    2929      break;                                                            \
    3030    }                                                                   \
     
    3232
    3333  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   }
     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}
    4040# undef SSS_FUNC
    4141
     
    6868  // set up the possible operations : int OP int -> int, all else yield float
    6969  // OP is the operation performed on *M1 and *M2
    70 # define VVV_FUNC(OP) {                                         \
     70# define VVV_FUNC(OP) {                                                 \
    7171    if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \
    7272      CopyVector (OUT[0].vector, V1[0].vector);                         \
     
    394394  // OP is the operation performed on *M1 and *M2
    395395# define SV_FUNC(FTYPE,OP) {                                            \
    396     if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) {               \
     396    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) { \
    397397      CopyVector (OUT[0].vector, V2[0].vector);                         \
    398398      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    404404      break;                                                            \
    405405    }                                                                   \
    406     if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) {               \
     406    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) { \
    407407      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    408408      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    414414      break;                                                            \
    415415    }                                                                   \
    416     if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) {               \
     416    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) { \
    417417      CopyVector (OUT[0].vector, V2[0].vector);                         \
    418418      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    434434      break;                                                            \
    435435    }                                                                   \
    436     if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) {               \
     436    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \
    437437      CopyVector (OUT[0].vector, V2[0].vector);                         \
    438438      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    447447
    448448  switch (op[0]) {
    449     case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
    450     case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
    451     case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
    452     case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
    453     case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
    454     case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
    455     case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
    456     case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
    457     case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
    458     case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
    459     case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
    460     case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
    461     case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
    462     case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
    463     case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
    464     case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
    465     case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
    466     case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
    467     case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
    468     case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
    469     default:
    470       snprintf (line, 512, "error: op %c not defined!", op[0]);
    471       push_error (line);
    472       return (FALSE);
    473   }
     449  case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
     450  case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
     451  case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
     452  case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
     453  case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
     454  case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
     455  case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     456  case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     457  case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
     458  case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
     459  case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
     460  case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
     461  case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
     462  case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
     463  case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
     464  case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
     465  case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
     466  case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
     467  case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
     468  case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
     469  default:
     470    snprintf (line, 512, "error: op %c not defined!", op[0]);
     471    push_error (line);
     472    return (FALSE);
     473}
    474474# undef SV_FUNC
    475475
    476476  /** free up any temporary buffers: **/
    477477  if (V2[0].type == ST_VECTOR_TMP) {
    478     free (V2[0].vector[0].elements.Ptr);
    479     free (V2[0].vector);
    480   }
     478  free (V2[0].vector[0].elements.Ptr);
     479  free (V2[0].vector);
     480}
    481481
    482482  clear_stack (V1);
     
    501501  // OP is the operation performed on *M1 and *M2
    502502# define VS_FUNC(FTYPE,OP) {                                            \
    503     if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) {               \
     503    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) { \
    504504      CopyVector (OUT[0].vector, V1[0].vector);                         \
    505505      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    511511      break;                                                            \
    512512    }                                                                   \
    513     if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) {               \
     513    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) { \
    514514      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    515515      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    521521      break;                                                            \
    522522    }                                                                   \
    523     if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) {               \
     523    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) { \
    524524      CopyVector (OUT[0].vector, V1[0].vector);                         \
    525525      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    541541      break;                                                            \
    542542    }                                                                   \
    543     if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) {               \
     543    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \
    544544      CopyVector (OUT[0].vector, V1[0].vector);                         \
    545545      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    554554
    555555  switch (op[0]) {
    556     case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
    557     case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
    558     case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
    559     case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
    560     case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
    561     case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
    562     case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
    563     case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
    564     case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
    565     case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
    566     case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
    567     case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
    568     case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
    569     case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
    570     case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
    571     case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
    572     case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
    573     case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
    574     case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
    575     case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
    576     default:
    577       snprintf (line, 512, "error: op %c not defined!", op[0]);
    578       push_error (line);
    579       return (FALSE);
    580   }
     556  case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
     557  case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
     558  case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
     559  case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
     560  case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
     561  case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
     562  case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     563  case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     564  case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
     565  case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
     566  case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
     567  case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
     568  case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
     569  case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
     570  case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
     571  case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
     572  case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
     573  case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
     574  case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
     575  case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
     576  default:
     577    snprintf (line, 512, "error: op %c not defined!", op[0]);
     578    push_error (line);
     579    return (FALSE);
     580}
    581581# undef VS_FUNC
    582582
     
    584584
    585585  if (V1[0].type == ST_VECTOR_TMP) {
    586     free (V1[0].vector[0].elements.Ptr);
    587     free (V1[0].vector);
    588   }
     586  free (V1[0].vector[0].elements.Ptr);
     587  free (V1[0].vector);
     588}
    589589
    590590  clear_stack (V1);
     
    885885  float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
    886886
    887 # define MS_FUNC(OP) {                                  \
    888     if (V2->type == ST_SCALAR_FLT)  {                           \
    889       opihi_flt M2 = V2[0].FltValue;                    \
     887# define MS_FUNC(OP) {                          \
     888    if (V2->type == ST_SCALAR_FLT)  {           \
     889      opihi_flt M2 = V2[0].FltValue;            \
    890890      for (i = 0; i < Npix; i++, out++, M1++) { \
    891         *out = OP;                                      \
    892       }                                                 \
    893       break;                                            \
    894     }                                                   \
    895     if (V2->type == ST_SCALAR_INT)  {                           \
    896       opihi_int M2 = V2[0].IntValue;                    \
     891        *out = OP;                              \
     892      }                                         \
     893      break;                                    \
     894    }                                           \
     895    if (V2->type == ST_SCALAR_INT)  {           \
     896      opihi_int M2 = V2[0].IntValue;            \
    897897      for (i = 0; i < Npix; i++, out++, M1++) { \
    898         *out = OP;                                      \
    899       }                                                 \
    900       break;                                            \
    901     }                                                   \
     898        *out = OP;                              \
     899      }                                         \
     900      break;                                    \
     901    }                                           \
    902902  }
    903903
     
    961961  float *out   = (float *)OUT[0].buffer[0].matrix.buffer;
    962962
    963 # define SM_FUNC(OP) {                                  \
    964     if (V1->type == ST_SCALAR_FLT)  {                           \
    965       opihi_flt M1 = V1[0].FltValue;                    \
     963# define SM_FUNC(OP) {                          \
     964    if (V1->type == ST_SCALAR_FLT)  {           \
     965      opihi_flt M1 = V1[0].FltValue;            \
    966966      for (i = 0; i < Npix; i++, out++, M2++) { \
    967         *out = OP;                                      \
    968       }                                                 \
    969       break;                                            \
    970     }                                                   \
    971     if (V1->type == ST_SCALAR_INT)  {                           \
    972       opihi_int M1 = V1[0].IntValue;                    \
     967        *out = OP;                              \
     968      }                                         \
     969      break;                                    \
     970    }                                           \
     971    if (V1->type == ST_SCALAR_INT)  {           \
     972      opihi_int M1 = V1[0].IntValue;            \
    973973      for (i = 0; i < Npix; i++, out++, M2++) { \
    974         *out = OP;                                      \
    975       }                                                 \
    976       break;                                            \
    977     }                                                   \
     974        *out = OP;                              \
     975      }                                         \
     976      break;                                    \
     977    }                                           \
    978978  }
    979979
     
    10231023
    10241024# define SS_FUNC(FTYPE,OP) {                                            \
    1025     if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {                   \
     1025    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {   \
    10261026      opihi_flt M1 = V1[0].FltValue;                                    \
    10271027      opihi_flt M2 = V2[0].FltValue;                                    \
    1028       OUT[0].type = ST_SCALAR_FLT;                                              \
     1028      OUT[0].type = ST_SCALAR_FLT;                                      \
    10291029      OUT[0].FltValue = OP;                                             \
    10301030      break;                                                            \
    10311031    }                                                                   \
    1032     if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {                   \
     1032    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {   \
    10331033      opihi_flt M1 = V1[0].FltValue;                                    \
    10341034      opihi_int M2 = V2[0].IntValue;                                    \
    1035       OUT[0].type = ST_SCALAR_FLT;                                              \
     1035      OUT[0].type = ST_SCALAR_FLT;                                      \
    10361036      OUT[0].FltValue = OP;                                             \
    10371037      break;                                                            \
    10381038    }                                                                   \
    1039     if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {                   \
     1039    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {   \
    10401040      opihi_int M1 = V1[0].IntValue;                                    \
    10411041      opihi_flt M2 = V2[0].FltValue;                                    \
    1042       OUT[0].type = ST_SCALAR_FLT;                                              \
     1042      OUT[0].type = ST_SCALAR_FLT;                                      \
    10431043      OUT[0].FltValue = OP;                                             \
    10441044      break;                                                            \
    10451045    }                                                                   \
    1046     if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {       \
     1046    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) { \
    10471047      opihi_int M1 = V1[0].IntValue;                                    \
    10481048      opihi_int M2 = V2[0].IntValue;                                    \
    1049       OUT[0].type = ST_SCALAR_FLT;                                              \
     1049      OUT[0].type = ST_SCALAR_FLT;                                      \
    10501050      OUT[0].FltValue = OP;                                             \
    10511051      break;                                                            \
    10521052    }                                                                   \
    1053     if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {                   \
     1053    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {   \
    10541054      opihi_int M1 = V1[0].IntValue;                                    \
    10551055      opihi_int M2 = V2[0].IntValue;                                    \
    1056       OUT[0].type = ST_SCALAR_INT;                                              \
     1056      OUT[0].type = ST_SCALAR_INT;                                      \
    10571057      OUT[0].IntValue = OP;                                             \
    10581058      break;                                                            \
     
    10611061
    10621062  switch (op[0]) {
    1063     case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
    1064     case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
    1065     case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
    1066     case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
    1067     case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
    1068     case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
    1069     case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
    1070     case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
    1071     case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
    1072     case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
    1073     case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
    1074     case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
    1075     case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
    1076     case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
    1077     case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
    1078     case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
    1079     case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
    1080     case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
    1081     case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
    1082     case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
    1083     default:
    1084       snprintf (line, 512, "error: op %c not defined!", op[0]);
    1085       push_error (line);
    1086       return (FALSE);
    1087   }
     1063  case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
     1064  case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
     1065  case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
     1066  case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
     1067  case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
     1068  case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
     1069  case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1070  case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1071  case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
     1072  case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
     1073  case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
     1074  case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
     1075  case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
     1076  case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
     1077  case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
     1078  case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
     1079  case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
     1080  case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
     1081  case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
     1082  case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
     1083  default:
     1084    snprintf (line, 512, "error: op %c not defined!", op[0]);
     1085    push_error (line);
     1086    return (FALSE);
     1087}
    10881088# undef SS_FUNC
    10891089
     
    11531153}
    11541154
    1155 
    11561155int S_unary (StackVar *OUT, StackVar *V1, char *op) {
    11571156
    11581157  char line[512]; // this is only used to report an error
    11591158 
    1160 # define S_FUNC(OP,FTYPE) {                     \
    1161     if (V1->type == ST_SCALAR_FLT) {                    \
    1162       opihi_flt M1  = V1[0].FltValue;           \
    1163       OUT[0].type = ST_SCALAR_FLT;                      \
    1164       OUT[0].FltValue = OP;                     \
    1165       clear_stack (V1);                         \
    1166       return (TRUE);                            \
    1167     }                                           \
     1159# define S_FUNC(OP,FTYPE) {                                             \
     1160    if (V1->type == ST_SCALAR_FLT) {                                    \
     1161      opihi_flt M1  = V1[0].FltValue;                                   \
     1162      OUT[0].type = ST_SCALAR_FLT;                                      \
     1163      OUT[0].FltValue = OP;                                             \
     1164      clear_stack (V1);                                                 \
     1165      return (TRUE);                                                    \
     1166    }                                                                   \
    11681167    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) {      \
    1169       opihi_int M1  = V1[0].IntValue;           \
    1170       OUT[0].type = ST_SCALAR_FLT;                      \
    1171       OUT[0].FltValue = OP;                     \
    1172       clear_stack (V1);                         \
    1173       return (TRUE);                            \
    1174     }                                           \
     1168      opihi_int M1  = V1[0].IntValue;                                   \
     1169      OUT[0].type = ST_SCALAR_FLT;                                      \
     1170      OUT[0].FltValue = OP;                                             \
     1171      clear_stack (V1);                                                 \
     1172      return (TRUE);                                                    \
     1173    }                                                                   \
    11751174    if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {      \
    1176       opihi_int M1  = V1[0].IntValue;           \
    1177       OUT[0].type = ST_SCALAR_INT;                      \
    1178       OUT[0].IntValue = OP;                     \
    1179       clear_stack (V1);                         \
    1180       return (TRUE);                            \
    1181     }                                           \
     1175      opihi_int M1  = V1[0].IntValue;                                   \
     1176      OUT[0].type = ST_SCALAR_INT;                                      \
     1177      OUT[0].IntValue = OP;                                             \
     1178      clear_stack (V1);                                                 \
     1179      return (TRUE);                                                    \
     1180    }                                                                   \
    11821181  }
    11831182
     
    12111210  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT);
    12121211  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT);
    1213   if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT);
     1212  if (!strcmp (op, "rnd"))    S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
     1213  if (!strcmp (op, "drnd"))   S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT);
     1214  if (!strcmp (op, "lrnd"))   S_FUNC(0*M1 + lrand48(), ST_SCALAR_INT);
     1215  if (!strcmp (op, "mrnd"))   S_FUNC(0*M1 + mrand48(), ST_SCALAR_INT);
    12141216  if (!strcmp (op, "not"))    S_FUNC(!(M1), ST_SCALAR_INT);
    12151217  if (!strcmp (op, "--"))     S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed,
     
    12351237  OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/
    12361238
    1237 # define V_FUNC(OP,FTYPE) {                                     \
    1238     if (V1->vector->type == OPIHI_FLT) {                        \
    1239       CopyVector (OUT[0].vector, V1[0].vector);                 \
    1240       opihi_flt *M1  = V1[0].vector[0].elements.Flt;            \
    1241       opihi_flt *out = OUT[0].vector[0].elements.Flt;           \
    1242       for (i = 0; i < Nx; i++, out++, M1++) {                   \
    1243         *out = OP;                                              \
    1244       }                                                         \
    1245       goto escape;                                              \
    1246     }                                                           \
     1239# define V_FUNC(OP,FTYPE) {                                             \
     1240    if (V1->vector->type == OPIHI_FLT) {                                \
     1241      CopyVector (OUT[0].vector, V1[0].vector);                         \
     1242      opihi_flt *M1  = V1[0].vector[0].elements.Flt;                    \
     1243      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     1244      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     1245        *out = OP;                                                      \
     1246      }                                                                 \
     1247      goto escape;                                                      \
     1248    }                                                                   \
    12471249    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) {  \
    1248       MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);     \
    1249       opihi_int *M1  = V1[0].vector[0].elements.Int;            \
    1250       opihi_flt *out = OUT[0].vector[0].elements.Flt;           \
    1251       for (i = 0; i < Nx; i++, out++, M1++) {                   \
    1252         *out = OP;                                              \
    1253       }                                                         \
    1254       goto escape;                                              \
    1255     }                                                           \
     1250      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
     1251      opihi_int *M1  = V1[0].vector[0].elements.Int;                    \
     1252      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     1253      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     1254        *out = OP;                                                      \
     1255      }                                                                 \
     1256      goto escape;                                                      \
     1257    }                                                                   \
    12561258    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) {  \
    1257       CopyVector (OUT[0].vector, V1[0].vector);                 \
    1258       opihi_int *M1  = V1[0].vector[0].elements.Int;            \
    1259       opihi_int *out = OUT[0].vector[0].elements.Int;           \
    1260       for (i = 0; i < Nx; i++, out++, M1++) {                   \
    1261         *out = OP;                                              \
    1262       }                                                         \
    1263       goto escape;                                              \
     1259      CopyVector (OUT[0].vector, V1[0].vector);                         \
     1260      opihi_int *M1  = V1[0].vector[0].elements.Int;                    \
     1261      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     1262      for (i = 0; i < Nx; i++, out++, M1++) {                           \
     1263        *out = OP;                                                      \
     1264      }                                                                 \
     1265      goto escape;                                                      \
    12641266    } }                                                 
    12651267
     
    12941296  if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT);
    12951297  if (!strcmp (op, "rnd"))    V_FUNC(drand48(), ST_SCALAR_FLT);
     1298  if (!strcmp (op, "drnd"))   V_FUNC(drand48(), ST_SCALAR_FLT);
     1299  if (!strcmp (op, "lrnd"))   V_FUNC(lrand48(), ST_SCALAR_INT);
     1300  if (!strcmp (op, "mrnd"))   V_FUNC(mrand48(), ST_SCALAR_INT);
    12961301  if (!strcmp (op, "ramp"))   V_FUNC(i, ST_SCALAR_INT);
    12971302  if (!strcmp (op, "zero"))   V_FUNC(0, ST_SCALAR_INT);
     
    13201325}
    13211326
     1327# define M_FUNC(OP) { for (i = 0; i < Npix; i++, out++, M1++) { *out = (OP); }}
     1328
    13221329int M_unary (StackVar *OUT, StackVar *V1, char *op) {
    13231330
     
    13371344  M1  = (float *) V1[0].buffer[0].matrix.buffer;
    13381345  out = (float *)OUT[0].buffer[0].matrix.buffer;
    1339 
     1346 
     1347// if (!strcmp (op, "rint"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }}
     1348 
    13401349  if (!strcmp (op, "="))     { }
    1341   if (!strcmp (op, "abs"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = fabs(*M1);         }}
    1342   if (!strcmp (op, "int"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = (opihi_flt)(long long)(*M1); }}
    1343 
    1344   if (!strcmp (op, "floor")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = floor (*M1); }}
    1345   if (!strcmp (op, "ceil"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = ceil (*M1); }}
    1346   // if (!strcmp (op, "rint"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }}
    1347 
    1348   if (!strcmp (op, "exp"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = exp(*M1);          }}
    1349   if (!strcmp (op, "ten"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = pow(10.0,*M1);     }}
    1350   if (!strcmp (op, "log"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = log10(*M1);        }}
    1351   if (!strcmp (op, "ln"))    { for (i = 0; i < Npix; i++, out++, M1++) { *out = log(*M1);          }}
    1352   if (!strcmp (op, "sqrt"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sqrt(*M1);         }}
    1353   if (!strcmp (op, "erf"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = erf(*M1);          }}
    1354 
    1355   if (!strcmp (op, "sinh"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sinh(*M1);         }}
    1356   if (!strcmp (op, "cosh"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = cosh(*M1);         }}
    1357   if (!strcmp (op, "asinh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asinh(*M1);        }}
    1358   if (!strcmp (op, "acosh")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acosh(*M1);        }}
    1359   if (!strcmp (op, "lgamma")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = lgamma(*M1);      }}
    1360 
    1361   if (!strcmp (op, "sin"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1);          }}
    1362   if (!strcmp (op, "cos"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1);          }}
    1363   if (!strcmp (op, "tan"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1);          }}
    1364   if (!strcmp (op, "dsin"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = sin(*M1*RAD_DEG);  }}
    1365   if (!strcmp (op, "dcos"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = cos(*M1*RAD_DEG);  }}
    1366   if (!strcmp (op, "dtan"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = tan(*M1*RAD_DEG);  }}
    1367   if (!strcmp (op, "asin"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1);         }}
    1368   if (!strcmp (op, "acos"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1);         }}
    1369   if (!strcmp (op, "atan"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1);         }}
    1370   if (!strcmp (op, "dasin")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = asin(*M1)*DEG_RAD; }}
    1371   if (!strcmp (op, "dacos")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = acos(*M1)*DEG_RAD; }}
    1372   if (!strcmp (op, "datan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = atan(*M1)*DEG_RAD; }}
    1373   if (!strcmp (op, "not"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = !(*M1);            }}
    1374   if (!strcmp (op, "--"))    { for (i = 0; i < Npix; i++, out++, M1++) { *out = -(*M1);            }}
    1375   if (!strcmp (op, "rnd"))   { for (i = 0; i < Npix; i++, out++, M1++) { *out = drand48();         }}
    1376   if (!strcmp (op, "ramp"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = i;                 }}
    1377   if (!strcmp (op, "zero"))  { for (i = 0; i < Npix; i++, out++, M1++) { *out = 0;                 }}
    1378   if (!strcmp (op, "isinf")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = !finite(*M1);      }}
    1379   if (!strcmp (op, "isnan")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = isnan(*M1);        }}
     1350  if (!strcmp (op, "abs"))    M_FUNC(fabs(*M1));
     1351  if (!strcmp (op, "int"))    M_FUNC((opihi_flt)(long long)(*M1));
     1352  if (!strcmp (op, "floor"))  M_FUNC(floor (*M1));
     1353  if (!strcmp (op, "ceil"))   M_FUNC(ceil (*M1));
     1354  if (!strcmp (op, "exp"))    M_FUNC(exp(*M1));
     1355  if (!strcmp (op, "ten"))    M_FUNC(pow(10.0,*M1));
     1356  if (!strcmp (op, "log"))    M_FUNC(log10(*M1));
     1357  if (!strcmp (op, "ln"))     M_FUNC(log(*M1));
     1358  if (!strcmp (op, "sqrt"))   M_FUNC(sqrt(*M1));
     1359  if (!strcmp (op, "erf"))    M_FUNC(erf(*M1));
     1360  if (!strcmp (op, "sinh"))   M_FUNC(sinh(*M1));
     1361  if (!strcmp (op, "cosh"))   M_FUNC(cosh(*M1));
     1362  if (!strcmp (op, "asinh"))  M_FUNC(asinh(*M1));
     1363  if (!strcmp (op, "acosh"))  M_FUNC(acosh(*M1));
     1364  if (!strcmp (op, "lgamma")) M_FUNC(lgamma(*M1));
     1365  if (!strcmp (op, "sin"))    M_FUNC(sin(*M1));
     1366  if (!strcmp (op, "cos"))    M_FUNC(cos(*M1));
     1367  if (!strcmp (op, "tan"))    M_FUNC(tan(*M1));
     1368  if (!strcmp (op, "dsin"))   M_FUNC(sin(*M1*RAD_DEG));
     1369  if (!strcmp (op, "dcos"))   M_FUNC(cos(*M1*RAD_DEG));
     1370  if (!strcmp (op, "dtan"))   M_FUNC(tan(*M1*RAD_DEG));
     1371  if (!strcmp (op, "asin"))   M_FUNC(asin(*M1));
     1372  if (!strcmp (op, "acos"))   M_FUNC(acos(*M1));
     1373  if (!strcmp (op, "atan"))   M_FUNC(atan(*M1));
     1374  if (!strcmp (op, "dasin"))  M_FUNC(asin(*M1)*DEG_RAD);
     1375  if (!strcmp (op, "dacos"))  M_FUNC(acos(*M1)*DEG_RAD);
     1376  if (!strcmp (op, "datan"))  M_FUNC(atan(*M1)*DEG_RAD);
     1377  if (!strcmp (op, "not"))    M_FUNC(!(*M1));
     1378  if (!strcmp (op, "--"))     M_FUNC(-(*M1));
     1379  if (!strcmp (op, "rnd"))    M_FUNC(drand48());
     1380  if (!strcmp (op, "drnd"))   M_FUNC(drand48());
     1381  if (!strcmp (op, "lrnd"))   M_FUNC(lrand48());
     1382  if (!strcmp (op, "mrnd"))   M_FUNC(mrand48());
     1383  if (!strcmp (op, "ramp"))   M_FUNC(i);
     1384  if (!strcmp (op, "zero"))   M_FUNC(0);
     1385  if (!strcmp (op, "isinf"))  M_FUNC(!finite(*M1));
     1386  if (!strcmp (op, "isnan"))  M_FUNC(isnan(*M1));
    13801387
    13811388  /* xrm and yrm only make sense for 2D matrices. see special meaning for vectors */
Note: See TracChangeset for help on using the changeset viewer.