tows_c.c File Reference

#include "scicos_block4.h"
#include "machine.h"
#include "stack-c.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "MALLOC.h"

Include dependency graph for tows_c.c:

Go to the source code of this file.

Data Structures

struct  towork_struct

Defines

#define codehm

Functions

int C2F() cvstr (integer *, integer *, char *, integer *, unsigned long int)
int C2F() mputnc ()
int C2F() namstr ()
void C2F() mopen ()
int C2F() cluni0 (char *name, char *nams, integer *ln, long int name_len, long int nams_len)
void C2F() mclose (integer *fd, double *res)
void sciprint (char *fmt,...)
void tows_c (scicos_block *block, int flag)

Variables

static int id [nsiz]
static char fmtd [3] = {'d','l','\000'}
static char fmti [3] = {'i','l','\000'}
static char fmtl [3] = {'l','l','\000'}
static char fmts [3] = {'s','l','\000'}
static char fmtc [3] = {'c','l','\000'}
static char fmtul [3] = {'u','l','\000'}
static char fmtus [3] = {'u','s','\000'}
static char fmtuc [3] = {'u','c','\000'}
static char * str_hmlst [] = {"hm","dims","entries"}


Define Documentation

#define codehm

Value:

ptr_i[6]   = 17; \
        ptr_i[7]   = 3;  \
        ptr_i[8]   = 1;  \
        ptr_i[9]   = ptr_i[8]  + 11; \
        ptr_i[10]  = ptr_i[9]  + 4;  \
        ptr_i[11]  = ptr_i[10] + 2 + nz*nu*nu2; \
        ptr_i[12]  = 10; \
        ptr_i[13]  = 1; \
        ptr_i[14]  = 3; \
        ptr_i[15]  = 0; \
        ptr_i[16]  = 1; \
        ptr_i[17]  = ptr_i[16] + 2; \
        ptr_i[18]  = ptr_i[17] + 4; \
        ptr_i[19]  = ptr_i[18] + 7; \
        i = (int)strlen(str_hmlst[0]);   \
        C2F(cvstr)(&i,&ptr_i[20],str_hmlst[0],(l=0,&l),(unsigned long) i); \
        j = (int)strlen(str_hmlst[1]); \
        C2F(cvstr)(&j,&ptr_i[20+i],str_hmlst[1],(l=0,&l),(unsigned long) j); \
        k = (int)strlen(str_hmlst[2]); \
        C2F(cvstr)(&k,&ptr_i[20+i+j],str_hmlst[2],(l=0,&l),(unsigned long) k); \
        ptr_i[33]  = 8; \
        ptr_i[34]  = 1; \
        ptr_i[35]  = 3; \
        ptr_i[36]  = 4; \
        ptr_i[37]  = nu; \
        ptr_i[38]  = nu2; \
        ptr_i[39]  = nz;

Definition at line 35 of file tows_c.c.

Referenced by tows_c().


Function Documentation

int C2F() cluni0 ( char *  name,
char *  nams,
integer ln,
long int  name_len,
long int  nams_len 
)

expand in_name to produce out_name

Parameters:
in_name the input string that we want to expand
out_name the output string
out_n number of character of out_name
lin length of in_name
lout length of out_name
Returns:
0

Definition at line 35 of file cluni0.c.

References Cluni0(), GetenvB(), getUpdateEnvVar(), HOME, k, PATH_MAX, SCI, SCI_a, and setUpdateEnvVar().

00036 {
00037         int nc= PATH_MAX;
00038         static char SCI[PATH_MAX],HOME[PATH_MAX],TMP[PATH_MAX];
00039         static int k;
00040         
00041         if ( ( n==0 ) || (getUpdateEnvVar() == 1) )
00042         {
00043                 GetenvB("SCI"   , SCI ,nc);
00044                 GetenvB("HOME"  , HOME,nc);
00045                 GetenvB("TMPDIR", TMP ,nc);
00046                 n=n+1;
00047                 setUpdateEnvVar(0);
00048         }
00049         
00050         /* in_name[lin]='\0';*/
00051         if ( Cluni0(SCI,SCI_a,in_name,out_name,lin) == 0 )
00052                 if ( Cluni0(HOME,HOME_a,in_name,out_name,lin) == 0 )
00053                         if ( Cluni0(TMP,TMP_a,in_name,out_name,lin) == 0 )
00054                         {
00055                                 strncpy(out_name,in_name,(size_t)lin);
00056                                 out_name[lin]='\0';
00057                         }
00058         
00059         *out_n = (int)strlen(out_name);
00060         #ifdef _MSC_VER
00061                 for (k=0 ; k < *out_n ;k++) if ( out_name[k]=='/') out_name[k]='\\';
00062         #else
00063                 for (k=0 ; k < *out_n ;k++) if ( out_name[k]=='\\') out_name[k]='/';
00064         #endif
00065         
00066         return(0);
00067 }

Here is the call graph for this function:

int C2F() cvstr ( integer ,
integer ,
char *  ,
integer ,
unsigned long  int 
)

Definition at line 24 of file cvstr.c.

00025 {
00026   if (*job == 0) C2F(asciitocode)(n, line, str, &cx1, str_len);
00027   else C2F(codetoascii)(n, line, str, str_len);
00028   return 0;
00029 }

void C2F() mclose ( integer fd,
double *  res 
)

close the file with id *fd if *id != -1 and *id != -2 the current file if *id = -1 all opened file if *id = -2

Definition at line 22 of file mclose.c.

References _, C2F(), delfile(), fd, GetCurrentFileId(), GetFileOpenedInScilab(), GetMaximumFileOpenedInScilab(), Max, Min, res, res1(), and sciprint().

00023 {     
00024         int fd1;
00025         int res1 = 1;
00026         *res = 0.0;
00027         switch ( *fd )
00028         {
00029         case -2 :
00030                 /* closing all opened files */
00031                 for ( fd1=0; fd1< GetMaximumFileOpenedInScilab(); fd1++) {
00032                         if ( GetFileOpenedInScilab(fd1) )
00033                         {
00034                                 fclose( GetFileOpenedInScilab(fd1) );
00035                                 res1 = ferror( GetFileOpenedInScilab(fd1));
00036                                 if (res1 != 0) *res =1;
00037                                 C2F(delfile)(&fd1);
00038                         }
00039                 }
00040                 break;
00041         default :
00042                 fd1 = (*fd == -1 ) ? GetCurrentFileId() : Min(Max(*fd,0),GetMaximumFileOpenedInScilab()-1);
00043                 if ( fd1 != -1 ) 
00044                 {
00045                         if ( GetFileOpenedInScilab(fd1) )
00046                         {
00047                                 if (fclose(GetFileOpenedInScilab(fd1)))
00048                                 {
00049                                         *res = (double)ferror(GetFileOpenedInScilab(fd1));
00050                                 }
00051                                 C2F(delfile)(&fd1);
00052                         }
00053                         else
00054                         {
00055                                 *res = 0.0;
00056                                 sciprint(_("%s: Cannot close file whose descriptor is %d: File is not active.\n"),"mclose",fd1);
00057                         }
00058                 }
00059                 else 
00060                 {
00061                         *res = -1.0;
00062                         sciprint(_("%s: Cannot close file whose descriptor is %d: No file to close.\n"),"mclose",fd1);
00063                 }
00064         }
00065 }

Here is the call graph for this function:

void C2F() mopen (  ) 

int C2F() mputnc (  ) 

int C2F() namstr (  ) 

void sciprint ( char *  fmt,
  ... 
)

Print

Parameters:
fmt Format of the format string
... 

Definition at line 36 of file sciprint.c.

00037 {
00038         va_list ap;
00039 
00040         va_start(ap,fmt);
00041         scivprint(fmt,ap);
00042         va_end (ap);
00043 }

void tows_c ( scicos_block block,
int  flag 
)

Definition at line 97 of file tows_c.c.

References C2F(), cluni0(), towork_struct::cnt, codehm, cvstr(), env, fd, filename, FILENAME_MAX, fmtc, fmtd, fmti, fmtl, fmts, fmtuc, fmtul, fmtus, FREE, get_scicos_time(), getenv(), GetImagInPortPtrs, GetInPortCols, GetInPortRows, Getint16InPortPtrs, Getint32InPortPtrs, Getint8InPortPtrs, GetInType, GetRealInPortPtrs, Getuint16InPortPtrs, Getuint32InPortPtrs, Getuint8InPortPtrs, i, id, ierr, scicos_block::ipar, j, k, l, towork_struct::loop, lout, mclose(), mopen(), mputnc(), namstr(), nsiz, NULL, out_n, res, scicos_free(), scicos_malloc(), sciprint(), SCSCOMPLEX_N, SCSINT16_COP, SCSINT16_N, SCSINT32_COP, SCSINT32_N, SCSINT8_COP, SCSINT8_N, SCSINT_COP, SCSREAL_COP, SCSREAL_N, SCSUINT16_COP, SCSUINT16_N, SCSUINT32_COP, SCSUINT32_N, SCSUINT8_COP, SCSUINT8_N, set_block_error(), str, swap, towork_struct::work, scicos_block::work, and towork_struct::workt.

00104 {
00105  /* for mopen */
00106  int fd;
00107  char *status;
00108  int swap = 1;
00109  double res;
00110  int out_n;
00111  long int lout;
00112  char filename[FILENAME_MAX];
00113  /* for name of file */
00114  char str[100];
00115  /* generic pointer */
00116  SCSREAL_COP *u_d,*u_cd,*ptr_d,*sav_d;
00117  SCSINT8_COP *u_c,*ptr_c,*sav_c;
00118  SCSUINT8_COP *u_uc, *ptr_uc,*sav_uc;
00119  SCSINT16_COP *u_s,*ptr_s,*sav_s;
00120  SCSUINT16_COP *u_us,*ptr_us,*sav_us;
00121  SCSINT_COP *ptr_i;
00122  SCSINT32_COP *u_l,*ptr_l,*sav_l;
00123  SCSUINT32_COP *u_ul,*ptr_ul,*sav_ul;
00124  double sav_t;
00125  /* the struct ptr of that block */
00126  towork_struct *ptr;
00127  /* */
00128  int nu,nu2,ut;
00129  int nz;
00130  double t,t_old;
00131  /* local */
00132  int i,j,k,l;
00133  int ierr;
00134 
00135  int  ismat=0;
00136 
00137  /* for path of TMPDIR/workspace */
00138  char env[256];
00139  char sep[2];
00140 #ifdef _MSC_VER
00141   sep[0]='\\';
00142 #else
00143   sep[0]='/';
00144 #endif
00145   sep[1]='\0';
00146 
00147  /* retrieve param of that block */
00148  nu  = GetInPortRows(block,1); /* number of rows of inputs*/
00149  nu2 = GetInPortCols(block,1); /* number of cols of inputs*/
00150  ut  = GetInType(block,1);     /* input type */
00151  nz  = block->ipar[0];         /* buffer size */
00152 
00153  /* check if u is a matrix */
00154  if (nu2!=1) {
00155    ismat=1;
00156  }
00157 
00158  if (flag==4) { /* init */
00159 
00160    /* begin campaign of allocations */
00161    if((*(block->work)=(towork_struct*) scicos_malloc(sizeof(towork_struct)))==NULL) {
00162      set_block_error(-16);
00163      return;
00164    }
00165 
00166    ptr = *(block->work);
00167 
00168    /*
00169     * t
00170     */
00171    if((ptr->workt=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00172                                           nz*sizeof(double)))==NULL) {
00173      set_block_error(-16);
00174      scicos_free(ptr);
00175      *(block->work) = NULL;
00176      return;
00177    }
00178    ptr_i    = (int*) ptr->workt;
00179    ptr_i[6] = 1;
00180    ptr_i[7] = nz;
00181    ptr_i[8] = 1;
00182    ptr_i[9] = 0;
00183 
00184    ptr_d = (SCSREAL_COP *) &(ptr_i[10]);
00185    for (i=0;i<nz;i++) {
00186      ptr_d[i]=-1;
00187    }
00188 
00189    /* Scilab variable code name */
00190    C2F(namstr)(id,(i=29,&i),(j=1,&j),(k=0,&k));
00191 
00192    ptr_i    = (int*) ptr->workt;
00193    ptr_i[0] = id[0];
00194    ptr_i[1] = id[1];
00195    ptr_i[2] = id[2];
00196    ptr_i[3] = id[3];
00197    ptr_i[4] = id[4];
00198    ptr_i[5] = id[5];
00199 
00200    /*
00201     * x
00202     */
00203    switch (ut)
00204    {
00205     case SCSREAL_N    :
00206       if (ismat) {
00207         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00208                                              2*sizeof(int) + \
00209                                              4*sizeof(int) + \
00210                                              4*sizeof(int) + \
00211                                              4*sizeof(int) + \
00212                                              (2+4+7)*sizeof(int) + \
00213                                              4*sizeof(int) + \
00214                                              (3)*sizeof(int) + \
00215                                              4*sizeof(int) + \
00216                                              nz*nu*nu2*sizeof(double)))==NULL) {
00217           set_block_error(-16);
00218           scicos_free(ptr->workt);
00219           scicos_free(ptr);
00220           *(block->work) = NULL;
00221           return;
00222         }
00223         ptr_i      = (int*) ptr->work;
00224         codehm
00225         ptr_i[40]  = 1;                     /*head of entries for hm*/
00226         ptr_i[41]  = nu*nu2*nz;
00227         ptr_i[42]  = 1;
00228         ptr_i[43]  = 0;
00229         ptr_d      = (SCSREAL_COP *) &(ptr_i[44]);
00230 
00231       }
00232       else {
00233         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00234                                               nz*nu*sizeof(double)))==NULL) {
00235           set_block_error(-16);
00236           scicos_free(ptr->workt);
00237           scicos_free(ptr);
00238           *(block->work) = NULL;
00239           return;
00240         }
00241         ptr_i      = (int*) ptr->work;
00242         ptr_i[6]   = 1;
00243         ptr_i[7]   = nz;
00244         ptr_i[8]   = nu;
00245         ptr_i[9]   = 0;
00246         ptr_d      = (SCSREAL_COP *) &(ptr_i[10]);
00247       }
00248       for (i=0;i<nu*nu2*nz;i++) {
00249         ptr_d[i] = 0.;
00250       }
00251       break;
00252 
00253     case SCSCOMPLEX_N :
00254       if (ismat) {
00255         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00256                                              2*sizeof(int) + \
00257                                              4*sizeof(int) + \
00258                                              4*sizeof(int) + \
00259                                              4*sizeof(int) + \
00260                                              (2+4+7)*sizeof(int) + \
00261                                              4*sizeof(int) + \
00262                                              (3)*sizeof(int) + \
00263                                              4*sizeof(int) + \
00264                                              2*nz*nu*nu2*sizeof(double)))==NULL) {
00265           set_block_error(-16);
00266           scicos_free(ptr->workt);
00267           scicos_free(ptr);
00268           *(block->work) = NULL;
00269           return;
00270         }
00271         ptr_i      = (int*) ptr->work;
00272         codehm
00273         ptr_i[40]  = 1;                     /*head of entries for hm*/
00274         ptr_i[41]  = nu*nu2*nz;
00275         ptr_i[42]  = 1;
00276         ptr_i[43]  = 1;
00277         ptr_d      = (SCSREAL_COP *) &(ptr_i[44]);
00278 
00279       }
00280       else {
00281         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00282                                               2*nz*nu*sizeof(double)))==NULL) {
00283           set_block_error(-16);
00284           scicos_free(ptr->workt);
00285           scicos_free(ptr);
00286           *(block->work) = NULL;
00287           return;
00288         }
00289         ptr_i      = (int*) ptr->work;
00290         ptr_i[6]   = 1;
00291         ptr_i[7]   = nz;
00292         ptr_i[8]   = nu;
00293         ptr_i[9]   = 1;
00294         ptr_d      = (SCSREAL_COP *) &(ptr_i[10]);
00295       }
00296       for (i=0;i<2*nu*nu2*nz;i++) {
00297         ptr_d[i] = 0.;
00298       }
00299       break;
00300 
00301     case SCSINT8_N    :
00302       if (ismat) {
00303         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00304                                              2*sizeof(int) + \
00305                                              4*sizeof(int) + \
00306                                              4*sizeof(int) + \
00307                                              4*sizeof(int) + \
00308                                              (2+4+7)*sizeof(int) + \
00309                                              4*sizeof(int) + \
00310                                              (3)*sizeof(int) + \
00311                                              4*sizeof(int) + \
00312                                              nz*nu*nu2*sizeof(char)))==NULL) {
00313           set_block_error(-16);
00314           scicos_free(ptr->workt);
00315           scicos_free(ptr);
00316           *(block->work) = NULL;
00317           return;
00318         }
00319         ptr_i      = (int*) ptr->work;
00320         codehm
00321         ptr_i[40]  = 8;                     /*head of entries for hm*/
00322         ptr_i[41]  = nu*nu2*nz;
00323         ptr_i[42]  = 1;
00324         ptr_i[43]  = 1;
00325         ptr_c      = (SCSINT8_COP *) &(ptr_i[44]);
00326 
00327       }
00328       else {
00329         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00330                                               nz*nu*sizeof(char)))==NULL) {
00331           set_block_error(-16);
00332           scicos_free(ptr->workt);
00333           scicos_free(ptr);
00334           *(block->work) = NULL;
00335           return;
00336         }
00337         ptr_i      = (int*) ptr->work;
00338         ptr_i[6]   = 8;
00339         ptr_i[7]   = nz;
00340         ptr_i[8]   = nu;
00341         ptr_i[9]   = 1;
00342         ptr_c      = (SCSINT8_COP *) &(ptr_i[10]);
00343       }
00344       for (i=0;i<nu*nu2*nz;i++) {
00345         ptr_c[i] = 0;
00346       }
00347       break;
00348 
00349     case SCSINT16_N   :
00350       if (ismat) {
00351         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00352                                              2*sizeof(int) + \
00353                                              4*sizeof(int) + \
00354                                              4*sizeof(int) + \
00355                                              4*sizeof(int) + \
00356                                              (2+4+7)*sizeof(int) + \
00357                                              4*sizeof(int) + \
00358                                              (3)*sizeof(int) + \
00359                                              4*sizeof(int) + \
00360                                              nz*nu*nu2*sizeof(short)))==NULL) {
00361           set_block_error(-16);
00362           scicos_free(ptr->workt);
00363           scicos_free(ptr);
00364           *(block->work) = NULL;
00365           return;
00366         }
00367         ptr_i      = (int*) ptr->work;
00368         codehm
00369         ptr_i[40]  = 8;                     /*head of entries for hm*/
00370         ptr_i[41]  = nu*nu2*nz;
00371         ptr_i[42]  = 1;
00372         ptr_i[43]  = 2;
00373         ptr_s      = (SCSINT16_COP *) &(ptr_i[44]);
00374       }
00375       else {
00376         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00377                                               nz*nu*sizeof(short)))==NULL) {
00378           set_block_error(-16);
00379           scicos_free(ptr->workt);
00380           scicos_free(ptr);
00381           *(block->work) = NULL;
00382           return;
00383         }
00384         ptr_i      = (int*) ptr->work;
00385         ptr_i[6]   = 8;
00386         ptr_i[7]   = nz;
00387         ptr_i[8]   = nu;
00388         ptr_i[9]   = 2;
00389         ptr_s      = (SCSINT16_COP *) &(ptr_i[10]);
00390       }
00391       for (i=0;i<nu*nu2*nz;i++) {
00392         ptr_s[i] = 0;
00393       }
00394       break;
00395 
00396     case SCSINT32_N   :
00397       if (ismat) {
00398         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00399                                              2*sizeof(int) + \
00400                                              4*sizeof(int) + \
00401                                              4*sizeof(int) + \
00402                                              4*sizeof(int) + \
00403                                              (2+4+7)*sizeof(int) + \
00404                                              4*sizeof(int) + \
00405                                              (3)*sizeof(int) + \
00406                                              4*sizeof(int) + \
00407                                              nz*nu*nu2*sizeof(long)))==NULL) {
00408           set_block_error(-16);
00409           scicos_free(ptr->workt);
00410           scicos_free(ptr);
00411           *(block->work) = NULL;
00412           return;
00413         }
00414         ptr_i      = (int*) ptr->work;
00415         codehm
00416         ptr_i[40]  = 8;                     /*head of entries for hm*/
00417         ptr_i[41]  = nu*nu2*nz;
00418         ptr_i[42]  = 1;
00419         ptr_i[43]  = 4;
00420         ptr_l      = (SCSINT32_COP *) &(ptr_i[44]);
00421       }
00422       else {
00423         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00424                                               nz*nu*sizeof(long)))==NULL) {
00425           set_block_error(-16);
00426           scicos_free(ptr->workt);
00427           scicos_free(ptr);
00428           *(block->work) = NULL;
00429           return;
00430         }
00431         ptr_i      = (int*) ptr->work;
00432         ptr_i[6]   = 8;
00433         ptr_i[7]   = nz;
00434         ptr_i[8]   = nu;
00435         ptr_i[9]   = 4;
00436         ptr_l      = (SCSINT32_COP *) &(ptr_i[10]);
00437       }
00438       for (i=0;i<nu*nu2*nz;i++) {
00439         ptr_l[i] = 0;
00440       }
00441       break;
00442 
00443     case SCSUINT8_N   :
00444       if (ismat) {
00445         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00446                                              2*sizeof(int) + \
00447                                              4*sizeof(int) + \
00448                                              4*sizeof(int) + \
00449                                              4*sizeof(int) + \
00450                                              (2+4+7)*sizeof(int) + \
00451                                              4*sizeof(int) + \
00452                                              (3)*sizeof(int) + \
00453                                              4*sizeof(int) + \
00454                                              nz*nu*nu2*sizeof(unsigned char)))==NULL) {
00455           set_block_error(-16);
00456           scicos_free(ptr->workt);
00457           scicos_free(ptr);
00458           *(block->work) = NULL;
00459           return;
00460         }
00461         ptr_i      = (int*) ptr->work;
00462         codehm
00463         ptr_i[40]  = 8;                     /*head of entries for hm*/
00464         ptr_i[41]  = nu*nu2*nz;
00465         ptr_i[42]  = 1;
00466         ptr_i[43]  = 11;
00467         ptr_uc     = (SCSUINT8_COP *) &(ptr_i[44]);
00468       }
00469       else {
00470         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00471                                               nz*nu*sizeof(unsigned char)))==NULL) {
00472           set_block_error(-16);
00473           scicos_free(ptr->workt);
00474           scicos_free(ptr);
00475           *(block->work) = NULL;
00476           return;
00477         }
00478         ptr_i       = (int*) ptr->work;
00479         ptr_i[6]    = 8;
00480         ptr_i[7]    = nz;
00481         ptr_i[8]    = nu;
00482         ptr_i[9]    = 11;
00483         ptr_uc      = (SCSUINT8_COP *) &(ptr_i[10]);
00484       }
00485       for (i=0;i<nu*nu2*nz;i++) {
00486         ptr_uc[i] = 0;
00487       }
00488       break;
00489 
00490     case SCSUINT16_N  :
00491       if (ismat) {
00492         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00493                                              2*sizeof(int) + \
00494                                              4*sizeof(int) + \
00495                                              4*sizeof(int) + \
00496                                              4*sizeof(int) + \
00497                                              (2+4+7)*sizeof(int) + \
00498                                              4*sizeof(int) + \
00499                                              (3)*sizeof(int) + \
00500                                              4*sizeof(int) + \
00501                                              nz*nu*nu2*sizeof(unsigned short)))==NULL) {
00502           set_block_error(-16);
00503           scicos_free(ptr->workt);
00504           scicos_free(ptr);
00505           *(block->work) = NULL;
00506           return;
00507         }
00508         ptr_i      = (int*) ptr->work;
00509         codehm
00510         ptr_i[40]  = 8;                     /*head of entries for hm*/
00511         ptr_i[41]  = nu*nu2*nz;
00512         ptr_i[42]  = 1;
00513         ptr_i[43]  = 12;
00514         ptr_us     = (SCSUINT16_COP *) &(ptr_i[44]);
00515       }
00516       else {
00517         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00518                                               nz*nu*sizeof(unsigned short)))==NULL) {
00519           set_block_error(-16);
00520           scicos_free(ptr->workt);
00521           scicos_free(ptr);
00522           *(block->work) = NULL;
00523           return;
00524         }
00525         ptr_i = (int*) ptr->work;
00526         ptr_i[6]    = 8;
00527         ptr_i[7]    = nz;
00528         ptr_i[8]    = nu;
00529         ptr_i[9]    = 12;
00530         ptr_us      = (SCSUINT16_COP *) &(ptr_i[10]);
00531       }
00532       for (i=0;i<nu*nu2*nz;i++) {
00533         ptr_us[i] = 0;
00534       }
00535       break;
00536 
00537     case SCSUINT32_N  :
00538       if (ismat) {
00539         if((ptr->work=(void *) scicos_malloc(6*sizeof(int) + \
00540                                              2*sizeof(int) + \
00541                                              4*sizeof(int) + \
00542                                              4*sizeof(int) + \
00543                                              4*sizeof(int) + \
00544                                              (2+4+7)*sizeof(int) + \
00545                                              4*sizeof(int) + \
00546                                              (3)*sizeof(int) + \
00547                                              4*sizeof(int) + \
00548                                              nz*nu*nu2*sizeof(unsigned long)))==NULL) {
00549           set_block_error(-16);
00550           scicos_free(ptr->workt);
00551           scicos_free(ptr);
00552           *(block->work) = NULL;
00553           return;
00554         }
00555         ptr_i      = (int*) ptr->work;
00556         codehm
00557         ptr_i[40]  = 8;                     /*head of entries for hm*/
00558         ptr_i[41]  = nu*nu2*nz;
00559         ptr_i[42]  = 1;
00560         ptr_i[43]  = 14;
00561         ptr_ul     = (SCSUINT32_COP *) &(ptr_i[44]);
00562       }
00563       else {
00564         if((ptr->work=(void *) scicos_malloc(6*sizeof(int)+4*sizeof(int)+ \
00565                                               nz*nu*sizeof(unsigned long)))==NULL) {
00566           set_block_error(-16);
00567           scicos_free(ptr->workt);
00568           scicos_free(ptr);
00569           *(block->work) = NULL;
00570           return;
00571         }
00572         ptr_i = (int*) ptr->work;
00573         ptr_i[6]    = 8;
00574         ptr_i[7]    = nz;
00575         ptr_i[8]    = nu;
00576         ptr_i[9]    = 14;
00577         ptr_ul      = (SCSUINT32_COP *) &(ptr_i[10]);
00578       }
00579       for (i=0;i<nu*nu2*nz;i++) {
00580         ptr_ul[i] = 0;
00581       }
00582       break;
00583 
00584     default  : /* Add a message here */
00585                break;
00586    }
00587 
00588    /* Scilab variable code name */
00589    C2F(namstr)(id,(i=33,&i),(j=1,&j),(k=0,&k));
00590 
00591    ptr_i    = (int*) ptr->work;
00592    ptr_i[0] = id[0];
00593    ptr_i[1] = id[1];
00594    ptr_i[2] = id[2];
00595    ptr_i[3] = id[3];
00596    ptr_i[4] = id[4];
00597    ptr_i[5] = id[5];
00598 
00599    /*
00600     * cnt
00601     */
00602    ptr->cnt = 0;
00603 
00604    /*
00605     * loop
00606     */
00607    ptr->loop = 0;
00608  }
00609 
00610  else if (flag==5) { /* finish */
00611 
00612    ptr = *(block->work);
00613 
00614    if (ptr!=NULL) {
00615      /* Put file name in str */
00616      C2F(cvstr)(&(block->ipar[1]),&(block->ipar[2]),str,(j=1,&j), \
00617                  (unsigned long)strlen(str));
00618      str[block->ipar[1]] = '\0';
00619 
00620      /* retrieve path of TMPDIR/workspace */
00621      strcpy(env,getenv("TMPDIR"));
00622      strcat(env,sep);
00623      strcat(env,"Workspace");
00624      strcat(env,sep);
00625      strcat(env,str);
00626 
00627      /* open tmp file */
00628      status = "wb"; /* "w" : write */
00629                     /* "b" : binary (required for Windows) */
00630      lout   = FILENAME_MAX;
00631      C2F(cluni0)(env, filename, &out_n,1,lout);
00632      C2F(mopen)(&fd,env,status,&swap,&res,&ierr);
00633      if (ierr != 0) {
00634        sciprint("Error when opening file '%s'.\n",str);
00635        scicos_free(ptr->workt);
00636        scicos_free(ptr);
00637        *(block->work) = NULL;
00638        set_block_error(-3);
00639        return;
00640      }
00641 
00642      /* check loop */
00643 
00644      /* we don't are at the end of the buffer :
00645       * only first records will be saved
00646       */
00647      if ((ptr->cnt==0)&&(ptr->loop==0)) { /* nothing have been stored */
00648        ptr_i = (int*) ptr->workt;
00649        ptr_i[6] = 1;
00650        ptr_i[7] = 0;
00651        ptr_i[8] = 0;
00652        ptr_i[9] = 0;
00653        ptr_i = (int*) ptr->work;
00654        ptr_i[6] = 1;
00655        ptr_i[7] = 0;
00656        ptr_i[8] = 0;
00657        ptr_i[9] = 0;
00658      }
00659      if ((ptr->cnt!=0)&&(ptr->cnt!=nz)&&(ptr->loop==0)) { /* something stored */
00660                                                           /* but we don't are at the end */
00661        ptr_i    = (int*) ptr->workt;
00662        ptr_i[7] = ptr->cnt;
00663        ptr_i    = (int*) ptr->work;
00664        /* hmat */
00665        if (ismat) {
00666          ptr_i[39] = ptr->cnt;
00667          ptr_i[41] = ptr->cnt*nu*nu2;
00668        }
00669        /* vector or matrix */
00670        else {
00671          /* matrix case */
00672          if (ptr_i[8] != 1) {
00673            /* */
00674            k=nz-ptr->cnt;
00675            /* */
00676            switch (ut) {
00677              case SCSREAL_N    :
00678                 for(i=0;i<ptr_i[8]-1;i++) {
00679                   for(j=0;j<ptr->cnt;j++) {
00680                     *((double *)(&ptr_i[10]) + (((i+1)*nz)+j-(i+1)*k)) = \
00681                          *((double *)(&ptr_i[10]) + (((i+1)*nz)+j));
00682                   }
00683                 }
00684                break;
00685 
00686              case SCSCOMPLEX_N :
00687                 for(i=0;i<ptr_i[8]-1;i++) {
00688                   for(j=0;j<ptr->cnt;j++) {
00689                     *((double *)(&ptr_i[10]) + (((i+1)*nz)+j-(i+1)*k)) = \
00690                          *((double *)(&ptr_i[10]) + (((i+1)*nz)+j));
00691                     *((double *)(&ptr_i[10]) + (((i+1)*nz)+j-(i+1)*k)+nz*nu) = \
00692                          *((double *)(&ptr_i[10]) + (((i+1)*nz)+j)+nz*nu);
00693                   }
00694                 }
00695                break;
00696 
00697              case SCSINT8_N :
00698                 for(i=0;i<ptr_i[8]-1;i++) {
00699                   for(j=0;j<ptr->cnt;j++) {
00700                     *((char *)(&ptr_i[10]) + (((i+1)*nz)+j-(i+1)*k)) = \
00701                          *((char *)(&ptr_i[10]) + (((i+1)*nz)+j));
00702                   }
00703                 }
00704                break;
00705 
00706              case SCSINT16_N :
00707                 for(i=0;i<ptr_i[8]-1;i++) {
00708                   for(j=0;j<ptr->cnt;j++) {
00709                     *((short *)(&ptr_i[10]) + (((i+1)*nz)+j-(i+1)*k)) = \
00710                          *((short *)(&ptr_i[10]) + (((i+1)*nz)+j));
00711                   }
00712                 }
00713                break;
00714 
00715              case SCSINT32_N :
00716                 for(i=0;i<ptr_i[8]-1;i++) {
00717                   for(j=0;j<ptr->cnt;j++) {
00718                     *((long *)(&ptr_i[10]) + (((i+1)*nz)+j-(i+1)*k)) = \
00719                          *((long *)(&ptr_i[10]) + (((i+1)*nz)+j));
00720                   }
00721                 }
00722                break;
00723 
00724              case SCSUINT8_N :
00725                 for(i=0;i<ptr_i[8]-1;i++) {
00726                   for(j=0;j<ptr->cnt;j++) {
00727                     *((unsigned char *)(&ptr_i[10]) + (((i+1)*nz)+j-(i+1)*k)) = \
00728                          *((