00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdlib.h>
00018 #include <setjmp.h>
00019
00020 #ifdef NOT_DEFINED
00021
00022
00023 static jmp_buf MXT_exception_env;
00024 static int MXT_exception_valid = 0;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 void
00036 mxt_ErrHandler(void)
00037 {
00038 #ifdef DEBUG
00039 printf(" in mxt_ErrHandler, returning to %s.\n",
00040 MXT_exception_valid ? "caller in main()" : "system");
00041 #endif
00042
00043 if (MXT_exception_valid)
00044 longjmp(MXT_exception_env, 1);
00045 else
00046 exit(1);
00047 }
00048
00049 #endif
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 static
00069 mxArray *
00070 mxt_param_to_matrix(CmdParams_t *params, char *name, int M, int N)
00071 {
00072 mxArray *pA;
00073 double *x;
00074 int i, Ntot;
00075 char name1[80];
00076
00077 if (M < 0 && N < 0)
00078 M = 1;
00079
00080 snprintf(name1, sizeof(name1), "%s_nvals", name);
00081 Ntot = params_get_int(params, name1);
00082
00083 if (M < 0)
00084 M = Ntot / N;
00085 else if (N < 0)
00086 N = Ntot / M;
00087 if (M*N != Ntot)
00088 return NULL;
00089 pA = mxCreateDoubleMatrix(M, N, mxREAL);
00090 if (!pA)
00091 return pA;
00092
00093 x = mxGetPr(pA);
00094 for (i = 0; i < Ntot; i++) {
00095 snprintf(name1, sizeof(name1), "%s_%d_value", name, i);
00096 x[i] = params_get_double(params, name1);
00097 }
00098 return pA;
00099 }
00100
00101
00102
00103
00104 static
00105 mxArray *
00106 mxt_param_to_scalar(CmdParams_t *params, char *name)
00107 {
00108 return mxCreateDoubleScalar(params_get_double(params, name));
00109 }
00110
00111
00112
00113
00114
00115
00116 static
00117 mxArray *
00118 mxt_param_to_string(CmdParams_t *params, char *name)
00119 {
00120 return mxCreateString(params_get_str(params, name));
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 static
00135 DRMS_Array_t *
00136 mxArray2drms_array(mxArray *in_a, DRMS_Type_t out_type) {
00137
00138 int status;
00139 DRMS_Array_t *out_a;
00140 int out_dims[2];
00141 unsigned char *out_data;
00142 double *in_data = mxGetPr(in_a);
00143 const mwSize *in_dims = mxGetDimensions(in_a);
00144 size_t Ntot = mxGetNumberOfElements(in_a);
00145 size_t i;
00146
00147
00148 out_dims[0] = (int) in_dims[0];
00149 out_dims[1] = (int) in_dims[1];
00150
00151 out_a = drms_array_create(out_type, 2, out_dims, NULL, &status);
00152 if (status)
00153 return NULL;
00154
00155 out_data = (unsigned char *) out_a->data;
00156 for (i = 0; i < Ntot; i++)
00157 if (isnan(in_data[i]))
00158 out_data[i] = 0;
00159 else
00160 out_data[i] = (unsigned char) in_data[i];
00161 return out_a;
00162 }