Slatexpr2.c

Go to the documentation of this file.
00001 /* Copyright ENPC/Chancelier Jean-Philippe */
00002 
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include <ctype.h>
00006 #include <stdio.h>
00007 
00008 
00009 #if defined(netbsd)
00010 #include <ieeefp.h>
00011 #endif
00012 
00013 #if defined(freebsd)
00014 #include <floatingpoint.h>
00015 #endif
00016 
00017 #include "util.h" 
00018 
00019 #ifdef _MSC_VER
00020 extern void SciEnv(void);
00021 #endif 
00022 
00023 /*---------------------------------------------------------
00024   Blatexprs fileres file1 .... filen  
00025   fait une mise en page de n dessins scilab ou neoclo 
00026   genere le fichier postscript fileres.ps 
00027   associe ainsi  qu'un fichier TeX fileres.tex
00028 -------------------------------------------------------------*/
00029 
00030 char * UsageStr[]={
00031   "Usage  : Blatexpr2 fileres file1 file2  \n",
00032   "\tfile1, file2 : are 2 Postscript files produced by Scilab\n",
00033   "\tfileres : a file name for the result \n",
00034   "\tThis command will create fileres.ps and fileres.tex \n",
00035   "fin"};
00036 
00037 char entete[160];
00038 
00039 void WriteTeX(char *filename, double wide, double height)
00040 {
00041   char filename1[255];
00042   FILE *fdo;
00043   sprintf(filename1,"%s.tex",filename);
00044   fdo=fopen(filename1,"w");
00045   if (fdo == 0 ) 
00046     {
00047       fprintf (stderr," Can't Create Output file <%s> \n",filename1);
00048       exit(0);
00049     }
00050 
00051   fprintf(fdo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00052   fprintf(fdo,"%% Usage: -To include a Figure with a caption, insert the TWO following lines\n");
00053   fprintf(fdo,"%%        in your Latex file:\n");
00054   fprintf(fdo,"%% \\input{This_file_name} \n");
00055   fprintf(fdo,"%% \\dessin{The_caption}{The_label}\n");
00056   fprintf(fdo,"%%         -To include just a picture, insert the lines \n");
00057   fprintf(fdo,"%%         between \\fbox{\\begin{picture}...  and \\end{picture}} below \n");
00058   fprintf(fdo,"%%          \n");
00059   fprintf(fdo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00060 
00061   fprintf(fdo," \n");
00062 
00063 
00064   fprintf(fdo,"\\long\\def\\Checksifdef#1#2#3{\n");
00065   fprintf(fdo,"\\expandafter\\ifx\\csname #1\\endcsname\\relax#2\\else#3\\fi}\n");
00066   fprintf(fdo,"\\Checksifdef{Figdir}{\\gdef\\Figdir{}}{}\n");
00067   fprintf(fdo,"\\def\\dessin#1#2{\n");
00068   fprintf(fdo,"\\begin{figure}\n\\begin{center}\n");
00069   fprintf(fdo,"\\setlength{\\unitlength}{1cm}\n");
00070   fprintf(fdo,"\\fbox{\\begin{picture}(%.2f,%.2f)\n",wide,height);
00071   fprintf(fdo,"\\special{psfile=\\Figdir %s.ps}\n",
00072           filename);
00073   fprintf(fdo,"\\end{picture}}\n");
00074   fprintf(fdo,"\\end{center}\n\\caption{\\label{#2}#1}\n\\end{figure}}");
00075   fclose(fdo);
00076 }
00077 
00078 /*---------------------------------------------------
00079  remplace strin<i> par strout<i> en lisant le contenu de 
00080  file et en ecrivant sur fdo
00081 -------------------------------------------------------*/
00082 
00083 void Sed(char *file, char *strin1, char *strout1, char *strin2, char *strout2, char *strin3, char *strout3, FILE *fdo)
00084 {
00085   FILE *fd;
00086 
00087   static char *buff = NULL;
00088   static int buflen = 512;
00089   if ( buff == NULL) 
00090     {
00091       buff = malloc(buflen*sizeof(char));
00092       if ( buff == NULL) 
00093         {
00094           fprintf(stderr,"Running out of space \n");
00095           exit(1);
00096         }
00097     }
00098 
00099   fd=fopen(file,"r");
00100   if (fd != 0)
00101     { int stop=0;
00102       while ( stop != 1)
00103         {  
00104            read_one_line (&buff,&stop,fd,&buflen); 
00105            if (strncmp(buff,strin1,strlen(strin1))==0)
00106              fprintf(fdo,"%s\n",strout1);
00107            else
00108              {
00109                if (strncmp(buff,strin2,strlen(strin2))==0)
00110                  fprintf(fdo,"%s\n",strout2);
00111                else 
00112                  {
00113                    if (strncmp(buff,strin3,strlen(strin3))==0)
00114                      fprintf(fdo,"%s\n",strout3);
00115                    else
00116                      fprintf(fdo,"%s",buff);
00117                  }
00118              }
00119          }
00120       fclose(fd);
00121     }
00122   else 
00123     {
00124       fprintf(stderr,"file %s not found ",file);
00125       return;
00126     }
00127 }
00128 
00129 
00130 
00131 /*-----------------------------------------------
00132   calcule la taille pour un dessin suivant le nombre de dessin a 
00133   placer dans la feuille 
00134   num est le nombre de dessins et i le numero du dessin 
00135   renvoit le point gauche dans (*x,*y) la largeur et le hauteur 
00136   dans (*w,*h)
00137   (*wt et *ht sont la hauteur totale et la argeur totale)
00138 -----------------------------------------------------*/
00139 
00140 void ComputeSize(int num, int i, double *x, double *y, double *w, double *h, double *wt, double *ht)
00141 {
00142   switch (num)
00143     {
00144     case 2 :
00145       *wt=15.0;*ht=5.0;
00147       *x=(7.5)*(i-1);*y=(5.0);*h=5.0;*w=7.5;
00148       break;
00149     }
00150 }
00151 
00152 
00153 
00154 int main(int argc, char **argv)
00155 {
00156   char *env;
00157   char filename1[255];
00158   double x,y,w,h,wt,ht;
00159   char buf[256];
00160   int i ;
00161   FILE *fd;
00162   FILE *fdo;
00163 #if defined(freebsd) || defined(netbsd)
00164   fpsetmask(0);
00165 #endif
00166 #ifdef _MSC_VER
00167   SciEnv();
00168 #endif 
00169   if (argc !=4 ) { int i=0;
00170                    while (strcmp(UsageStr[i],"fin")!=0)
00171                      { 
00172                        fprintf(stderr,"%s",UsageStr[i]),i++;
00173                      }
00174                    exit(0);
00175                  }
00176   sprintf(filename1,"%s.ps",argv[1]);
00177   fdo=fopen(filename1,"w");
00178   if (fdo == 0 ) 
00179     {
00180       fprintf (stderr," Can't Create Output file <%s> \n",filename1);
00181       exit(0);
00182     }
00183   env = getenv("SCI");
00184   if (env == NULL) {
00185     fprintf(stderr,"Environment variable SCI must be defined\n");
00186     exit(0);
00187   }
00188   sprintf(entete,"%s/tools/printer/NperiPos.ps",env);
00189   fd=fopen(entete,"r");
00190   if (fd != 0)
00191     { int c;
00192       while ( (c=getc(fd)) != EOF)
00193         {
00194           putc((char) c,fdo);
00195         }
00196       fclose(fd);
00197     }
00198   else 
00199     {
00200       fprintf(stderr,"file %s not found ",entete);
00201       return(1);
00202     }
00203   for ( i = 2 ; i < argc-1 ; i++)
00204     { 
00205       ComputeSize(argc-2,i-1,&x,&y,&w,&h,&wt,&ht)      ;
00206       sprintf(buf,"gsave [1 0 0 -1 0 0] concat %5.2f %5.2f %5.2f %5.2f DesPosi"
00207               ,x,y,w,h);
00208       Sed(argv[i],"[0.5 10 div 0 0 0.5 10 div neg  0 2120 10 div] concat",
00209           buf," showpage","grestore",
00210           " end saved restore","% end saved restore",fdo);
00211     }
00212   ComputeSize(argc-2,argc-2,&x,&y,&w,&h,&wt,&ht)      ;   
00213   sprintf(buf,"gsave [1 0 0 -1 0 0] concat %5.2f %5.2f %5.2f %5.2f DesPosi"
00214           ,x,y,w,h);
00215   Sed(argv[argc-1],"[0.5 10 div 0 0 0.5 10 div neg  0 2120 10 div] concat",
00216       buf, " showpage"," grestore ",
00217       " end saved restore"," end saved restore",fdo);
00218   fclose(fdo);
00220   WriteTeX(argv[1],wt,ht);
00221   return(0);
00222 }

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