00001 #include <string.h>
00002 #include "machine.h"
00003
00004 #include "MALLOC.h"
00005
00006 #include "../../../string/includes/men_Sutils.h"
00007
00008 #include "libinter.h"
00009 #include "cerro.h"
00010
00011 extern int C2F(cvstr) __PARAMS((integer *n, integer *line, char *str, integer *job, unsigned long str_len));
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 void C2F(cchar)(int *n, char **ip,int *op)
00024 {
00025 int i = 0;
00026 F2C(cvstr)(n,op,*ip,&i,*n);
00027 }
00028
00029
00030
00031
00032
00033
00034
00035 void C2F(ccharf)(n,ip,op)
00036 int *n;
00037 char **ip;
00038 int *op;
00039 {
00040 int i = 0;
00041 if (*n > 0) {
00042 F2C(cvstr)(n,op,*ip,&i,*n);
00043 FREE(*ip);
00044 }
00045 }
00046
00047
00048
00049
00050
00051 void C2F(cdouble)(n,ip,op)
00052 int *n;
00053 double *ip[];
00054 double *op;
00055 {
00056 int i;
00057 for (i = 0; i < *n; i++) op[i]=(*ip)[i];
00058 }
00059
00060
00061
00062
00063
00064 void C2F(cdoublef)(n,ip,op)
00065 int *n;
00066 double *ip[];
00067 double *op;
00068 {
00069 int i;
00070 if ( *n >0 ) {
00071 for (i = 0; i < *n; i++) op[i]=(*ip)[i];
00072 FREE((char *)(*ip));
00073 }
00074 }
00075
00076
00077
00078
00079
00080 void C2F(cint)(n,ip,op)
00081 int *n;
00082 int *ip[];
00083 double *op;
00084 {
00085 int i;
00086 for (i = 0; i < *n; i++) op[i]=(double)(*ip)[i];
00087 }
00088
00089
00090
00091
00092
00093 void C2F(cintf)(n,ip,op)
00094 int *n;
00095 int *ip[];
00096 double *op;
00097 {
00098 int i;
00099 if ( *n > 0 ) {
00100 for (i = 0; i < *n; i++)
00101 op[i]=(double)(*ip)[i];
00102 FREE((char *)(*ip));
00103 }
00104 }
00105
00106
00107
00108
00109
00110 void C2F(cfloat)(n,ip,op)
00111 int *n;
00112 float *ip[];
00113 double *op;
00114 {
00115 int i;
00116 for (i = 0; i < *n; i++) op[i]=(double)(*ip)[i];
00117 }
00118
00119
00120
00121
00122
00123 void C2F(cfloatf)(n,ip,op)
00124 int *n;
00125 float *ip[];
00126 double *op;
00127 {
00128 int i;
00129 if ( *n > 0 ) {
00130 for (i = 0; i < *n; i++)
00131 op[i]=(double)(*ip)[i];
00132 FREE((char *)(*ip));
00133 }
00134 }
00135
00136
00137
00138
00139
00140 void C2F(cbool)(n,ip,op)
00141 int *n;
00142 int *ip[];
00143 int *op;
00144 {
00145 int i;
00146 for (i = 0; i < *n; i++) op[i]= (*ip)[i];
00147 }
00148
00149
00150
00151
00152
00153 void C2F(cboolf)(n,ip,op)
00154 int *n;
00155 int *ip[];
00156 int *op;
00157 {
00158 int i;
00159 if ( *n > 0 ) {
00160 for (i = 0; i < *n; i++)
00161 op[i]= (*ip)[i];
00162 FREE((char *)(*ip));
00163 }
00164 }
00165
00166
00167
00168
00169
00170
00171 void cerro(char *str)
00172 {
00173 C2F(erro)(str, (unsigned int)(strlen(str) + 1));
00174 }
00175
00176
00177
00178
00179
00180 void Cout(char *str)
00181 {
00182 C2F(out)(str,(unsigned int)(strlen(str) + 1));
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192 void C2F(cstringf)(ip,sciptr,m,n,max,ierr)
00193 char ***ip;
00194 int *sciptr;
00195 int *m, *n, *max,*ierr;
00196 {
00197 int i,j,l,ie;
00198 int job=0;
00199 int *chars;
00200 *ierr=0;
00201 if (5 + *m * *n > *max) {
00202 *ierr = 1;
00203 return;
00204 }
00205 sciptr[0]=10;
00206 sciptr[1]=*m;
00207 sciptr[2]=*n;
00208 sciptr[3]=0;
00209 sciptr[4]=1;
00210 chars=&(sciptr[5 + *m * *n]);
00211 ie=0;
00212 for (j = 0; j < *n; j++) {
00213 for (i = 0; i < *m; i++) {
00214 l=(int)strlen((*ip)[ie]);
00215 sciptr[ie+5]=sciptr[ie+4]+l;
00216 if (5 + *m * *n + sciptr[ie+5] > *max) {
00217 *ierr = 1;
00218 return;
00219 }
00220 F2C(cvstr)(&l,&(chars[sciptr[ie+4]-1]),(*ip)[ie],&job,l);
00221 FREE((*ip)[ie]);
00222 ie++;
00223 }
00224 }
00225 FREE((char *)*ip);
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235 int C2F(stringc)(sciptr,cptr,ierr)
00236 int *sciptr;
00237 char ***cptr;
00238 int *ierr;
00239 {
00240 char **strings,*p;
00241 int li,ni,*SciS,i,nstring,*ptrstrings;
00242
00243 *ierr=0;
00244 nstring=sciptr[1]*sciptr[2];
00245 strings=(char **) MALLOC((unsigned) (nstring * sizeof(char *)));
00246 if (strings==0) {
00247 *ierr=1; return 0;
00248 }
00249 li=1;
00250 ptrstrings=&(sciptr[4]);
00251 SciS=&(sciptr[5+nstring]);
00252 for ( i=1 ; i<nstring+1 ; i++)
00253 {
00254 ni=ptrstrings[i]-li;
00255 li=ptrstrings[i];
00256 ScilabStr2C(&ni,SciS,&p,ierr);
00257 strings[i-1]=p;
00258 if ( *ierr == 1) return 0;
00259 SciS += ni;
00260 }
00261 *cptr=strings;
00262 return 0;
00263 }
00264
00265
00266
00267
00268
00269 void C2F(dbl2cdbl)(n,ip,op)
00270 int *n;
00271 double *ip[];
00272 double *op;
00273 {
00274 int i;
00275 for (i = 0; i < *n; i++) (*ip)[i]=op[i];
00276 }
00277
00278
00279
00280
00281
00282 void C2F(freeptr)(ip)
00283 double *ip[];
00284 {
00285 if (ip) FREE((char *)(*ip));
00286 }
00287
00288
00289
00290
00291
00292 void C2F(int2cint)(n,ip,op)
00293 int *n;
00294 integer *ip[];
00295 integer *op;
00296 {
00297 int i;
00298 for (i = 0; i < *n; i++) (*ip)[i]=op[i];
00299 }
00300
00309 SciSparse *NewSparse(int *it,int *m,int *n,int *nel)
00310 {
00311 SciSparse *loc;
00312 loc = (SciSparse *) MALLOC((unsigned) sizeof(SciSparse));
00313 if ( loc == (SciSparse *) 0)
00314 {
00315 return((SciSparse *) 0);
00316 }
00317 loc->m = *m;
00318 loc->n = *n;
00319 loc->it = *it;
00320 loc->nel = *nel;
00321 loc->mnel = (int*) MALLOC((unsigned) (*m)*sizeof(int));
00322 if ( loc->mnel == (int *) 0)
00323 {
00324 FREE(loc);
00325 return((SciSparse *) 0);
00326 }
00327 loc->icol = (int*) MALLOC((unsigned) (*nel)*sizeof(int));
00328 if ( loc->icol == (int *) 0)
00329 {
00330 FREE(loc->mnel);
00331 FREE(loc);
00332 return((SciSparse *) 0);
00333 }
00334 loc->R = (double*) MALLOC((unsigned) (*nel)*sizeof(double));
00335 if ( loc->R == (double *) 0)
00336 {
00337 FREE(loc->icol);
00338 FREE(loc->mnel);
00339 FREE(loc);
00340 return((SciSparse *) 0);
00341 }
00342
00343 if ( *it == 1)
00344 {
00345 loc->I = (double*) MALLOC((unsigned) (*nel)*sizeof(double));
00346 if ( loc->I == (double *) 0)
00347 {
00348 FREE(loc->R);
00349 FREE(loc->icol);
00350 FREE(loc->mnel);
00351 FREE(loc);
00352 return((SciSparse *) 0);
00353 }
00354 }
00355 return(loc);
00356 }
00357
00362 void FreeSparse(SciSparse *x)
00363 {
00364 if ( x->it == 1 ) FREE(x->I);
00365 FREE(x->R);
00366 FREE(x->icol);
00367 FREE(x->mnel);
00368 FREE(x);
00369 }
00370
00371
00372
00373
00374
00375 int C2F(csparsef)(SciSparse **x,int *mnel,int *icol,double *R,double *I)
00376 {
00377 int i;
00378 for ( i=0 ; i < (*x)->m ; i++)
00379 mnel[i] = (*x)->mnel[i];
00380 for ( i=0 ; i < (*x)->nel ; i++)
00381 {
00382 icol[i] = (*x)->icol[i];
00383 R[i] = (*x)->R[i];
00384 if ( (*x)->it == 1 )I[i] = (*x)->I[i];
00385 }
00386 FreeSparse(*x);
00387 return 0;
00388 }
00389
00390 void FreeRhsSVar(char **ptrStr)
00391 {
00392 int i=0;
00393
00394 if (ptrStr)
00395 {
00396 while ( ptrStr[i] != NULL)
00397 {
00398 FREE(ptrStr[i]);
00399 i++;
00400 };
00401 FREE(ptrStr);
00402 ptrStr=NULL;
00403 }
00404 };
00405