CallScilab.h File Reference

#include <stdio.h>
#include <string.h>
#include "machine.h"
#include "stack-c.h"
#include "version.h"

Include dependency graph for CallScilab.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void DisableInteractiveMode (void)
int StartScilab (char *SCIpath, char *ScilabStartup, int *Stacksize)
int TerminateScilab (char *ScilabQuit)
int SendScilabJob (char *job)
int SendScilabJobs (char **jobs, int numberjobs)
BOOL GetLastJob (char *JOB, int nbcharsJOB)
void ScilabDoOneEvent (void)
int ScilabHaveAGraph (void)


Function Documentation

void DisableInteractiveMode ( void   ) 

Disable TCL/TK and graphic interfaces Scilab no GUI no TCL/TK "kernel mode"

Definition at line 60 of file CallScilab.c.

References FALSE, and SetWITH_GUI().

00061 {
00062         SetWITH_GUI(FALSE);
00063 }

Here is the call graph for this function:

BOOL GetLastJob ( char *  JOB,
int  nbcharsJOB 
)

Returns last job send to scilab by SendScilabJobs or SendScilabJob

Parameters:
[out] JOB the last job
[out] nbcharsJOB the size of JOB
 Example :
 jobs[0] : a = 1;
 jobs[1] : b = V_NOT_EXIST;
 jobs[2] : c = a + b;
 if (SendScilabJobs(jobs,3))
 {
        char lastjob[4096]; // bsiz in scilab 
        if (GetLastJob(lastjob,4096))
        {
                printf("%s\n",lastjob);
        }
 }
Returns:

Definition at line 107 of file SendScilabJobs.c.

References FALSE, lastjob, and TRUE.

Referenced by example3(), and troisieme_exemple().

00108 {
00109         BOOL bOK=FALSE;
00110         if (JOB)
00111         {
00112                 if ((int)strlen(lastjob)<nbcharsJOB)
00113                 {
00114                         strcpy(JOB,lastjob);
00115                 }
00116                 else strncpy(JOB,lastjob,nbcharsJOB);
00117                 bOK=TRUE;
00118         }
00119         return bOK;
00120 }

Here is the caller graph for this function:

void ScilabDoOneEvent ( void   ) 

This procedure is the entry point to Scilab's event loop

Definition at line 166 of file CallScilab.c.

References C2F, GetWITH_GUI(), int, ismenu(), scirun(), sxevents(), and TextMessage1().

Referenced by deuxieme_exemple(), example2(), and Java_javasci_Scilab_Events().

00167 {
00168         if ( GetWITH_GUI() )
00169         {
00170                 #ifdef _MSC_VER
00171                         TextMessage1 (1);
00172                 #else 
00173                         C2F(sxevents)();
00174                 #endif
00175 
00176                 while(C2F(ismenu)()==1 ) 
00177                 {
00178                         C2F(scirun)("quit;",(int)strlen("quit;"));
00179                 }
00180         }
00181 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ScilabHaveAGraph ( void   ) 

Get the information is a graphic windows is opened or not

Returns:
Returns TRUE if a graphic windows is opened

Definition at line 183 of file CallScilab.c.

References GetWITH_GUI(), ids, iflag, num, and sciGetIdFigure().

Referenced by deuxieme_exemple(), and example2().

00184 {
00185         integer iflag =0,ids,num;
00186         int vInt=0;
00187 
00188         if ( GetWITH_GUI() )
00189         {
00190                         
00191           sciGetIdFigure (&ids,&num,&iflag);
00192           if (num > 0) { vInt = 1 ; }
00193         }
00194         else
00195         {
00196                 vInt=0;
00197         }
00198 
00199         return vInt;
00200 }

Here is the call graph for this function:

Here is the caller graph for this function:

int SendScilabJob ( char *  job  ) 

Send a job to scilab

Parameters:
job the Scilab Job
Returns:
error code operation 0 : OK

Definition at line 17 of file SendScilabJobs.c.

References C2F, cmatptr(), code, command, cwritechain(), FREE, int, lp, m, MALLOC, n, NULL, ReadMatrix, scirun(), and SetLastJob().

00018 {
00019         int retCode = -1;
00020         int lencommand=0;
00021         static char *command=NULL;
00022         
00023         char ScirunCommand[]="Err=execstr(TMP_EXEC_STRING,\"errcatch\",\"n\");quit;";
00024         char ClearTmpVariables[]="clear TMP_EXEC_STRING;clear Err;quit;";
00025         
00026         lencommand=strlen(job);
00027         command=MALLOC(sizeof(char)*(lencommand+1));
00028 
00029         if (command)
00030         {
00031                 /* clear prev. Err , TMP_EXEC_STRING scilab variables */
00032                 C2F(scirun)(ClearTmpVariables,strlen(ClearTmpVariables));
00033 
00034                 strcpy(command,job);
00035                 SetLastJob(command);
00036 
00037                 /* Creation Variable temporaire dans Scilab */
00038                 if (!C2F(cwritechain)("TMP_EXEC_STRING",&lencommand,(char*)command,(int)strlen("TMP_EXEC_STRING"),(int)strlen(command)) )
00039                 {
00040                         /* Probleme */
00041                         fprintf(stderr,"Error : SendScilabJob (1) 'TMP_EXEC_STRING'.\n");
00042                         retCode = -1;
00043 
00044                         if (command) {FREE(command);command=NULL;}
00045                         return retCode;
00046                 }
00047                 else
00048                 {
00049                         int m=0,n=0,lp=0;
00050 
00051                         C2F(scirun)(ScirunCommand,strlen(ScirunCommand));
00052 
00053                         /* get error code from scilab */
00054 
00055                         if ( ! C2F(cmatptr)("Err", &m, &n, &lp,strlen("Err")))
00056                         {
00057                                 fprintf(stderr,"Error : SendScilabJob (2) 'Err'.\n");
00058                                 retCode = -2;
00059                         }
00060                         else
00061                         {
00062                                 if (m*n == 1)
00063                                 {
00064                                         double code = -1;
00065                                         ReadMatrix("Err", &m, &n, &code);
00066                                         retCode = (int) code ;
00067                                 }
00068                                 else 
00069                                 {
00070                                         fprintf(stderr,"Error : SendScilabJob (3) 'Err'.\n");   
00071                                         retCode = -3;
00072                                 }
00073                         }
00074 
00075                         /* clear prev. Err , TMP_EXEC_STRING scilab variables */
00076                         C2F(scirun)(ClearTmpVariables,strlen(ClearTmpVariables));
00077                 }
00078                 if (command) {FREE(command);command=NULL;}
00079         }
00080         else
00081         {
00082                 fprintf(stderr,"Error : SendScilabJob (4) 'command' MALLOC.\n");
00083                 retCode = -4;
00084         }
00085 
00086         return retCode;
00087 }

Here is the call graph for this function:

int SendScilabJobs ( char **  jobs,
int  numberjobs 
)

Send jobs to scilab

        jobs[0] : a = 1;
        jobs[1] : b = 3;
        jobs[2] : c = a + b;
        SendScilabJobs(jobs,3);
Returns:
last error code operation 0 : OK

Definition at line 122 of file SendScilabJobs.c.

References BufferSecuritySize, CleanBuffers(), FALSE, i, MALLOC, NULL, RemoveCharsFromEOL(), RemoveComments(), retcode, SendScilabJob(), and TRUE.

Referenced by example3(), and troisieme_exemple().

00123 {
00124         #define BufferSecuritySize 64
00125 
00126         int retcode=-10;
00127 
00128         if (jobs)
00129         {
00130                 int i=0;
00131                 int nbcharsjobs=0;
00132                 char *bufCommands=NULL;
00133                 char **LOCALJOBS=NULL;
00134 
00135                 int jobsloop=0;
00136 
00137                 LOCALJOBS=(char**)MALLOC(sizeof(char*)*numberjobs);
00138 
00139                 if (LOCALJOBS)
00140                 {
00141                         for (i=0;i<numberjobs;i++)
00142                         {
00143                                 if (jobs[i])
00144                                 {
00145                                         nbcharsjobs = nbcharsjobs+(int)strlen(jobs[i]);
00146                                         LOCALJOBS[i]=(char*)MALLOC( sizeof(char)*(strlen(jobs[i])+BufferSecuritySize) );
00147                                         if (LOCALJOBS[i])
00148                                         {
00149                                                 strcpy(LOCALJOBS[i],jobs[i]);
00150                                         }
00151                                         else
00152                                         {
00153                                                 CleanBuffers(bufCommands,LOCALJOBS,numberjobs);
00154                                                 fprintf(stderr,"Error : SendScilabJobs (1) 'LOCALJOBS[%d] MALLOC'.\n",i);       
00155                                                 return retcode;
00156                                         }
00157                                 }
00158                                 else
00159                                 {
00160                                         fprintf(stderr,"Error : SendScilabJobs (2) 'jobs[%d] == NULL'.\n",i);   
00161                                         return retcode;
00162                                 }
00163                         }
00164 
00165                         bufCommands = (char*)MALLOC( sizeof(char)*(nbcharsjobs+numberjobs+BufferSecuritySize) );
00166 
00167                         if (bufCommands)
00168                         {
00169                                 strcpy(bufCommands,"");
00170 
00171                                 for (jobsloop=0;jobsloop<numberjobs;jobsloop++)
00172                                 {
00173                                         if (jobs[jobsloop])
00174                                         {
00175                                                 char *currentline=NULL;
00176                                                 BOOL AddSemiColon;
00177 
00178                                                 if (jobsloop == 0) AddSemiColon=FALSE;
00179                                                 else  AddSemiColon=TRUE;
00180 
00181                                 DOTDOTLOOP:
00182                                                 currentline=LOCALJOBS[jobsloop];
00183 
00184                                                 RemoveCharsFromEOL(currentline,'\n');
00185                                                 RemoveComments(currentline);
00186                                                 RemoveCharsFromEOL(currentline,' ');
00187 
00188                                                 if (RemoveCharsFromEOL(currentline,'.'))
00189                                                 {
00190                                                         RemoveCharsFromEOL(currentline,' ');
00191                                                         strcat(bufCommands,currentline);
00192                                                         jobsloop++;
00193                                                         AddSemiColon=FALSE;
00194                                                         goto DOTDOTLOOP;
00195                                                 }
00196                                                 else
00197                                                 {
00198                                                         if (!AddSemiColon)
00199                                                         {
00200                                                                 AddSemiColon=TRUE;
00201                                                                 strcat(currentline,";");
00202                                                         }
00203                                                         else
00204                                                         {
00205                                                                 strcat(bufCommands,";");
00206                                                         }
00207                                                         
00208                                                         strcat(bufCommands,currentline);
00209                                                 }
00210                                         }
00211                                 }
00212 
00213                                 retcode=SendScilabJob(bufCommands);
00214 
00215                                 CleanBuffers(bufCommands,LOCALJOBS,numberjobs);
00216                         }
00217                         else
00218                         {
00219                                 CleanBuffers(bufCommands,LOCALJOBS,numberjobs);
00220                                 fprintf(stderr,"Error : SendScilabJobs (3) 'bufCommands MALLOC'.\n");   
00221                                 return retcode;
00222                         }
00223                 }
00224                 else
00225                 {
00226                         CleanBuffers(bufCommands,LOCALJOBS,numberjobs);
00227                         fprintf(stderr,"Error : SendScilabJobs (4) 'LOCALJOBS == NULL'.\n");    
00228                         return retcode;
00229                 }
00230         }
00231         else
00232         {
00233                 fprintf(stderr,"Error : SendScilabJobs (5) 'jobs == NULL'.\n"); 
00234                 retcode = -10;
00235         }
00236         
00237         return retcode;
00238 }

Here is the call graph for this function:

Here is the caller graph for this function:

int StartScilab ( char *  SCIpath,
char *  ScilabStartup,
int Stacksize 
)

Initialize Scilab

Parameters:
SCIpath define SCI environment variable : Default --> NULL
ScilabStartup path & filename of scilab.start : Default --> NULL
Stacksize : Default --> NULL
Returns:
TRUE if it is OK else FALSE

Definition at line 65 of file CallScilab.c.

References C2F, DefaultScilabStartup, DefaultStacksize, env, FALSE, FREE, ierr, iflag, inisci(), InitWindowGraphDll(), int, MALLOC, NULL, putenv, scirun(), SetFromCToON(), setSCIpath(), settmpdir(), StartScilabIsOK, and TRUE.

00066 {
00067         int bOK=FALSE;
00068 
00069         char *ScilabStartupUsed=NULL;
00070         char *InitStringToScilab=NULL;
00071         int StacksizeUsed=0;
00072         int lengthStringToScilab=0;
00073 
00074         static int iflag=-1,ierr=0;
00075 
00076         if (StartScilabIsOK) return bOK;
00077 
00078         SetFromCToON();
00079 
00080         if (SCIpath==NULL)
00081         {
00082                 #ifdef _MSC_VER
00083                         SetSciEnv();
00084                 #else
00085                 {
00086                         char env[2048];
00087                         setSCIpath(SCIpath);
00088                         sprintf(env,"SCI=%s",SCIpath);
00089                         putenv(env);
00090                 }
00091                 #endif
00092         }
00093         else
00094         {
00095                 char env[2048];
00096                 setSCIpath(SCIpath);
00097                 sprintf(env,"SCI=%s",SCIpath);
00098                 putenv(env);
00099         }
00100 
00101         if (ScilabStartup==NULL)
00102         {
00103                 ScilabStartupUsed=(char*)MALLOC((strlen(DefaultScilabStartup)+1)*sizeof(char));
00104                 sprintf(ScilabStartupUsed,"%s",DefaultScilabStartup);
00105         }
00106         else
00107         {
00108                 ScilabStartupUsed=(char*)MALLOC((strlen(DefaultScilabStartup)+1)*sizeof(char));
00109                 sprintf(ScilabStartupUsed,"%s",ScilabStartup);
00110         }
00111         
00112         if (Stacksize==NULL)
00113         {
00114                 StacksizeUsed=DefaultStacksize;
00115         }
00116         else
00117         {
00118                 StacksizeUsed=*Stacksize;
00119         }
00120 
00121         /* running the startup */ 
00122         C2F(settmpdir)();
00123 
00124         /* Scilab Initialization */ 
00125         C2F(inisci)(&iflag,&StacksizeUsed,&ierr);
00126 
00127         if ( ierr > 0 ) 
00128     {
00129           bOK=FALSE;
00130       return bOK;
00131     }
00132 
00133 #ifdef _MSC_VER
00134         InitWindowGraphDll();
00135 #endif
00136 
00137         lengthStringToScilab=(int)(strlen("exec(\"SCI/etc/scilab.start\",-1);quit;")+strlen(ScilabStartupUsed));
00138         InitStringToScilab=(char*)MALLOC(lengthStringToScilab*sizeof(char));
00139         sprintf(InitStringToScilab,"exec(\"%s\",-1);quit;",ScilabStartupUsed);
00140         
00141         C2F(scirun)(InitStringToScilab,strlen(InitStringToScilab));
00142 
00143         if (ScilabStartupUsed) {FREE(ScilabStartupUsed);ScilabStartupUsed=NULL;}
00144         if (InitStringToScilab) {FREE(InitStringToScilab);InitStringToScilab=NULL;}
00145 
00146         bOK=TRUE;
00147         StartScilabIsOK=TRUE;
00148 
00149         return bOK;
00150 }

Here is the call graph for this function:

int TerminateScilab ( char *  ScilabQuit  ) 

Terminate Scilab

Parameters:
ScilabQuit path & filename of scilab.quit : Default --> NULL
Returns:
TRUE if it is OK else FALSE

Definition at line 152 of file CallScilab.c.

References ExitScilab(), FALSE, StartScilabIsOK, and TRUE.

00153 {
00154         int bOK=FALSE;
00155 
00156         if (StartScilabIsOK)
00157         {
00158                 ExitScilab();
00159                 StartScilabIsOK=FALSE;
00160                 bOK=TRUE;
00161         }
00162 
00163         return bOK;
00164 }

Here is the call graph for this function:


Generated on Sun Mar 4 15:12:05 2007 for Scilab [trunk] by  doxygen 1.5.1