00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "getPropertyAssignedValue.h"
00011 #include "stack-c.h"
00012 #include "sciprint.h"
00013 #include "MALLOC.h"
00014 #include "BasicAlgos.h"
00015
00016
00017 BOOL isParameterHandle( int type )
00018 {
00019 return ( type == 9 ) ;
00020 }
00021
00022 BOOL isParameterDoubleMatrix( int type )
00023 {
00024 return ( type == 1 ) ;
00025 }
00026
00027 BOOL isParameterTlist( int type )
00028 {
00029 return ( type == 16 ) ;
00030 }
00031
00032 BOOL isParameterStringMatrix( int type )
00033 {
00034 return ( type == 10 ) ;
00035 }
00036
00037 double getDoubleFromStack( int stackPointer )
00038 {
00039 return *(stk( stackPointer ));
00040 }
00041
00042 double * getDoubleMatrixFromStack( int stackPointer )
00043 {
00044 return stk( stackPointer ) ;
00045 }
00046
00047 void copyDoubleVectorFromStack( int stackPointer, double dest[], int nbElement )
00048 {
00049 doubleArrayCopy( dest, getDoubleMatrixFromStack( stackPointer ), nbElement ) ;
00050 }
00051
00052 void copyDoubleVectorToIntFromStack( int stackPointer, int dest[], int nbElement )
00053 {
00054 int i ;
00055 double * values = getDoubleMatrixFromStack( stackPointer ) ;
00056 for ( i = 0 ; i < nbElement ; i++ )
00057 {
00058 dest[i] = (int) values[i] ;
00059 }
00060 }
00061
00062 double * createCopyDoubleVectorFromStack( int stackPointer, int nbElement )
00063 {
00064 double * res = MALLOC( nbElement * sizeof(double) ) ;
00065 if ( res == NULL )
00066 {
00067 return NULL ;
00068 }
00069 copyDoubleVectorFromStack( stackPointer, res, nbElement ) ;
00070 return res ;
00071 }
00072
00073 char * getStringFromStack( int stackPointer )
00074 {
00075 return cstk( stackPointer ) ;
00076 }
00077
00078 char ** getStringMatrixFromStack( int stackPointer )
00079 {
00080
00081 return (char **) stackPointer ;
00082 }
00083
00084 char ** createCopyStringMatrixFromStack( int stackPointer, int nbElement )
00085 {
00086 int i ;
00087 char ** res = MALLOC( nbElement * sizeof(char *) ) ;
00088 char ** values = getStringMatrixFromStack( stackPointer ) ;
00089
00090 if ( res == NULL )
00091 {
00092 return NULL ;
00093 }
00094
00095 for ( i = 0 ; i < nbElement ; i++ )
00096 {
00097 int size = strlen( values[i] ) + 1 ;
00098 res[i] = MALLOC( size * sizeof(char) ) ;
00099
00100 if ( res[i] == NULL )
00101 {
00102
00103 int j ;
00104 for ( j = 0 ; j < i ; j++ )
00105 {
00106 FREE( res[j] ) ;
00107 }
00108 FREE( res ) ;
00109 return NULL ;
00110 }
00111
00112 strcpy( res[i], values[i] ) ;
00113 }
00114
00115 return res ;
00116
00117 }
00118
00119 unsigned long getHandleFromStack( int stackPointer )
00120 {
00121 return (unsigned long) *(hstk( stackPointer )) ;
00122 }
00123
00124 BOOL isStringParamEqual( int stackPointer, const char * str )
00125 {
00126 if ( strcmp( getStringFromStack( stackPointer ), str ) == 0 )
00127 {
00128 return TRUE ;
00129 }
00130 else
00131 {
00132 return FALSE ;
00133 }
00134 }
00135
00136
00137 int getStackListNbElement( int paramNum )
00138 {
00139 int nbRow = 0 ;
00140 int nbCol = 0 ;
00141 int stackPointer = 0 ;
00142
00143 GetRhsVar( paramNum, "t", &nbRow, &nbCol, &stackPointer ) ;
00144
00145 return nbRow - 1 ;
00146
00147 }
00148
00149 AssignedList * createAssignedList( int paramNum, int nbElement )
00150 {
00151 AssignedList * newList = NULL ;
00152 int nbRow = 0 ;
00153 int nbCol = 0 ;
00154
00155 newList = MALLOC( sizeof(AssignedList) ) ;
00156
00157 if ( newList == NULL )
00158 {
00159 return NULL ;
00160 }
00161
00162 newList->nbElement = nbElement + 1 ;
00163 newList->curElement = 2 ;
00164 newList->paramNumber = paramNum ;
00165
00166
00167 GetRhsVar( paramNum, "t", &nbRow, &nbCol, &(newList->stackPointer) ) ;
00168
00169
00170 if ( nbRow != newList->nbElement || nbCol != 1 )
00171 {
00172 sciprint( "Wrong size for tlist.\n" ) ;
00173 return NULL ;
00174 }
00175 return newList ;
00176 }
00177
00178 void destroyAssignedList( AssignedList * list )
00179 {
00180 FREE( list ) ;
00181 }
00182
00183 int getAssignedListNbElement( AssignedList * list )
00184 {
00185 return list->nbElement - 1 ;
00186 }
00187
00188 void rewindAssignedList( AssignedList * list )
00189 {
00190 list->curElement = 2 ;
00191 }
00192
00193 BOOL isListCurrentElementDoubleMatrix( AssignedList * list )
00194 {
00195 return ( ElementType( list->paramNumber, list->curElement ) == 1 ) ;
00196 }
00197
00198 BOOL isListCurrentElementStringMatrix( AssignedList * list )
00199 {
00200 return ( ElementType( list->paramNumber, list->curElement ) == 10 ) ;
00201 }
00202
00203 BOOL isListCurrentElementEmptyMatrix( AssignedList * list )
00204 {
00205 int nbRow = 0 ;
00206 int nbCol = 0 ;
00207
00208 if ( !isListCurrentElementDoubleMatrix( list ) )
00209 {
00210
00211 return FALSE ;
00212 }
00213
00214 getDoubleMatrixFromList( list, list->curElement, &nbRow, &nbCol ) ;
00215
00216 if ( nbRow * nbCol == 0 )
00217 {
00218 return TRUE ;
00219 }
00220
00221 return FALSE ;
00222
00223 }
00224
00225 double * getDoubleMatrixFromList( AssignedList * list, int rank, int * nbRow, int * nbCol )
00226 {
00227 int valueStackPointer = 0 ;
00228 GetListRhsVar( list->paramNumber, rank, "d", nbRow, nbCol, &valueStackPointer ) ;
00229
00230 return getDoubleMatrixFromStack( valueStackPointer ) ;
00231 }
00232
00233 char ** getStringMatrixFromList( AssignedList * list, int rank, int * nbRow, int * nbCol )
00234 {
00235 int valueStackPointer = 0 ;
00236 GetListRhsVar( list->paramNumber, rank, "S", nbRow, nbCol, &valueStackPointer ) ;
00237
00238 return getStringMatrixFromStack( valueStackPointer ) ;
00239 }
00240
00241 double * getCurrentDoubleMatrixFromList( AssignedList * list, int * nbRow, int * nbCol )
00242 {
00243 double * res = NULL ;
00244 if ( list->curElement > list->nbElement )
00245 {
00246 *nbRow = 0 ;
00247 *nbCol = 0 ;
00248 return NULL ;
00249 }
00250
00251 res = getDoubleMatrixFromList( list, list->curElement, nbRow, nbCol ) ;
00252 list->curElement++ ;
00253 return res ;
00254 }
00255
00256 char ** getCurrentStringMatrixFromList( AssignedList * list, int * nbRow, int * nbCol )
00257 {
00258 char ** res = NULL ;
00259 if ( list->curElement > list->nbElement )
00260 {
00261 *nbRow = 0 ;
00262 *nbCol = 0 ;
00263 return NULL ;
00264 }
00265
00266 res = getStringMatrixFromList( list, list->curElement, nbRow, nbCol ) ;
00267 list->curElement++ ;
00268 return res ;
00269
00270 }
00271
00272 double * createCopyDoubleMatrixFromList( AssignedList * list, int * nbRow, int * nbCol )
00273 {
00274
00275 double * stackValues = getCurrentDoubleMatrixFromList( list, nbRow, nbCol ) ;
00276 int nbElement = (*nbRow) * (*nbCol) ;
00277
00278 double * copyMatrix = NULL ;
00279
00280 if ( nbElement == 0 )
00281 {
00282 return NULL ;
00283 }
00284
00285
00286
00287 copyMatrix = MALLOC( (*nbRow) * (*nbCol) * sizeof( double ) ) ;
00288
00289 if ( copyMatrix == NULL )
00290 {
00291 *nbRow = -1 ;
00292 *nbCol = -1 ;
00293 return NULL ;
00294 }
00295
00296 doubleArrayCopy( copyMatrix, stackValues, nbElement ) ;
00297
00298 return copyMatrix ;
00299
00300 }
00301
00302 char ** createCopyStringMatrixFromList( AssignedList * list, int * nbRow, int * nbCol )
00303 {
00304
00305 char ** stackValues = getCurrentStringMatrixFromList( list, nbRow, nbCol ) ;
00306 int nbElement = (*nbRow) * (*nbCol) ;
00307
00308 if ( nbElement == 0 )
00309 {
00310 return NULL ;
00311 }
00312
00313 return createStringArrayCopy( stackValues, nbElement ) ;
00314 }
00315