00001
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <ctype.h>
00005 #ifndef __STDC__
00006 #include <stdlib.h>
00007 #endif
00008 #include <stdio.h>
00009 #include "util.h"
00010
00011 #ifdef _MSC_VER
00012 extern void SciEnv(void);
00013 #endif
00014
00015
00016
00017
00018
00019
00020
00021
00022 char * UsageStr[]={
00023 #ifndef DOC
00024 "Usage : Blatexprs fileres file1 .... filen \n",
00025 #else
00026 "Usage : Blatdocs fileres file1 .... filen \n",
00027 #endif
00028 "\tfile1, ... filen : are n Postscript files produced by Scilab\n",
00029 "\tfileres : a file name for the result \n",
00030 "\tThis command will create fileres.ps and fileres.tex \n",
00031 "fin"};
00032
00033 char entete[160];
00034
00035 void WriteTeX(char *filename, double wide, double height)
00036 {
00037 char filename1[255];
00038 FILE *fdo;
00039 sprintf(filename1,"%s.tex",filename);
00040 fdo=fopen(filename1,"w");
00041 if (fdo == 0 )
00042 {
00043 fprintf (stderr," Can't Create Output file <%s> \n",filename1);
00044 exit(0);
00045 }
00046 #ifndef DOC
00047 fprintf(fdo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00048 fprintf(fdo,"%% Usage: -To include a Figure with a caption, insert the TWO following lines\n");
00049 fprintf(fdo,"%% in your Latex file:\n");
00050 fprintf(fdo,"%% \\input{This_file_name} \n");
00051 fprintf(fdo,"%% \\dessin{The_caption}{The_label}\n");
00052 fprintf(fdo,"%% -To include just a picture, insert the lines \n");
00053 fprintf(fdo,"%% between \\fbox{\\begin{picture}... and \\end{picture}} below \n");
00054 fprintf(fdo,"%% \n");
00055 fprintf(fdo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00056
00057 fprintf(fdo," \n");
00058
00059 fprintf(fdo,"\\long\\def\\Checksifdef#1#2#3{\n");
00060 fprintf(fdo,"\\expandafter\\ifx\\csname #1\\endcsname\\relax#2\\else#3\\fi}\n");
00061 fprintf(fdo,"\\Checksifdef{Figdir}{\\gdef\\Figdir{}}{}\n");
00062 fprintf(fdo,"\\def\\dessin#1#2{\n");
00063 #endif
00064 fprintf(fdo,"\\begin{figure}\n\\begin{center}\n");
00065 fprintf(fdo,"\\setlength{\\unitlength}{1cm}\n");
00066 fprintf(fdo,"\\fbox{\\begin{picture}(%.2f,%.2f)\n",wide,height);
00067 #ifdef EPSFIG
00068 fprintf(fdo,"\\epsfig{file=\\Figdir %s.ps}\n",filename);
00069 #else
00070 fprintf(fdo,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
00071 fprintf(fdo,"%% If you want do not want to use epsfig ,comment the following line \n");
00072 fprintf(fdo,"%% and uncomment the \\special line \n");
00073 fprintf(fdo,"\\epsfig{file=\\Figdir %s.ps}\n",filename);
00074 fprintf(fdo,"%%\\special{psfile=\\Figdir %s.ps}\n", filename);
00075 #endif
00076 fprintf(fdo,"\\end{picture}}\n");
00077 fprintf(fdo,"\\end{center}\n");
00078 #ifndef DOC
00079 fprintf(fdo,"\\caption{\\label{#2}#1}\n\\end{figure}}");
00080 #endif
00081 fclose(fdo);
00082 }
00083
00084
00085
00086
00087
00088
00089 void Sed(char *file, char *strin1, char *strout1, char *strin2, char *strout2, char *strin3, char *strout3, FILE *fdo)
00090 {
00091 FILE *fd;
00092
00093 static char *buff = NULL;
00094 static int buflen = 512;
00095 if ( buff == NULL)
00096 {
00097 buff = malloc(buflen*sizeof(char));
00098 if ( buff == NULL)
00099 {
00100 fprintf(stderr,"Running out of space \n");
00101 exit(1);
00102 }
00103 }
00104
00105 fd=fopen(file,"r");
00106 if (fd != 0)
00107 { int stop=0;
00108 while ( stop != 1)
00109 {
00110 read_one_line (&buff,&stop,fd,&buflen);
00111 if (strncmp(buff,strin1,strlen(strin1))==0)
00112 fprintf(fdo,"%s\n",strout1);
00113 else
00114 {
00115 if (strncmp(buff,strin2,strlen(strin2))==0)
00116 fprintf(fdo,"%s\n",strout2);
00117 else
00118 {
00119 if (strncmp(buff,strin3,strlen(strin3))==0)
00120 fprintf(fdo,"%s\n",strout3);
00121 else
00122 fprintf(fdo,"%s",buff);
00123 }
00124 }
00125 }
00126 fclose(fd);
00127 }
00128 else
00129 {
00130 fprintf(stderr,"file %s not found ",file);
00131 return;
00132 }
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 void ComputeSize(int num, int i, double *x, double *y, double *w, double *h, double *wt, double *ht)
00145 {
00146 switch (num)
00147 {
00148 case 1 :
00150 *wt=15.0;*ht=20.0;
00151 *x=0.0;*y=20.0;*h=20.0;*w=15.0;
00152 break;
00153 case 2 :
00154 *wt=15.0;*ht=20.0;
00156 *x=0.0;*y=(20-(i-1)*10);*h=10.0;*w=15.0;
00157 break;
00158 case 3 :
00159 *wt=15.0;*ht=21.0;
00161 *x=0.0;*y=(21-(i-1)*7);*h=7.0;*w=15.0;
00162 break;
00163 case 4 :
00164
00166 *wt=16.0;*ht=16.0;
00167 if (i <= 2) *y=16.0;else *y=8.0;
00168 if ( (i % 2 ) == 0 )
00169 { *x= 8.0;*h=8.0;*w=8.0;}
00170 else
00171 {*x= 0.0;*h=8.0;*w=8.0;}
00172 break ;
00173 case 5 :
00174 case 6 :
00175 *wt=16.0;*ht=21.0;
00176 if (i <= 2) *y=21.0;else { if ( i <= 4) *y=14.0; else *y=7.0;}
00177 if ( (i % 2 ) == 0 )
00178 { *x= 8.0;*h=7.0;*w=8.0;}
00179 else
00180 {*x= 0 ;*h=7.0;*w=8.0;}
00181 break ;
00182 case 7 :
00183 case 8 :
00184 case 9 :
00185 *wt=16.0;*ht=18.0;
00186 if (i <= 3) *y=18.0;else { if ( i <= 6) *y=12.0; else *y=6.0;}
00187 if ( (i % 3 ) == 0 )
00188 { *x= 2*5.3;*h=6.0;*w=5.3;}
00189 else
00190 {
00191 if ( (i % 3 ) == 1 )
00192 { *x= 0.0;*h=6.0;*w=5.3;}
00193 else
00194 {*x= 5.3 ;*h=6.0;*w=5.3;}
00195 }
00196 break ;
00197 case 10 :
00198 case 11 :
00199 case 12 :
00200 default :
00201 *wt=16.0;*ht=20.0;
00202 if (i <= 3) *y=20.0;
00203 else {
00204 if ( i <= 6) *y=15.0;
00205 else {
00206 if (i <= 9 ) *y=10.0; else *y=5.0;}
00207 }
00208 if ( (i % 3 ) == 0 )
00209 { *x= 2*5.3;*h=5.0;*w=5.3;}
00210 else
00211 {
00212 if ( (i % 3 ) == 1 )
00213 { *x=0.0;*h=5.0;*w=5.3;}
00214 else
00215 {*x= 5.3 ;*h=5.0;*w=5.3;}
00216 }
00217 break ;
00218 }
00219 }
00220
00221
00222
00223 int main(int argc, char **argv)
00224 {
00225 char *env;
00226 char filename1[255];
00227 double x,y,w,h,wt,ht;
00228 char buf[256];
00229 int i ;
00230 FILE *fd;
00231 FILE *fdo;
00232 #ifdef _MSC_VER
00233 SciEnv();
00234 #endif
00235
00236 if (argc <= 2) { int i=0;
00237 while (strcmp(UsageStr[i],"fin")!=0)
00238 {
00239 fprintf(stderr,"%s",UsageStr[i]),i++;
00240 }
00241 exit(0);
00242 }
00243 sprintf(filename1,"%s.ps",argv[1]);
00244 fdo=fopen(filename1,"w");
00245 if (fdo == 0 )
00246 {
00247 fprintf (stderr," Can't Create Output file <%s> \n",filename1);
00248 exit(0);
00249 }
00250 env = getenv("SCI");
00251 if (env == NULL) {
00252 fprintf(stderr,"Environment variable SCI must be defined\n");
00253 exit(0);
00254 }
00255 sprintf(entete,"%s/tools/printer/NperiPos.ps",env);
00256 fd=fopen(entete,"r");
00257 if (fd != 0)
00258 { int c;
00259 while ( (c=getc(fd)) != EOF)
00260 {
00261 putc((char) c,fdo);
00262 }
00263 fclose(fd);
00264 }
00265 else
00266 {
00267 fprintf(stderr,"file %s not found ",entete);
00268 return(1);
00269 }
00270 for ( i = 2 ; i < argc-1 ; i++)
00271 {
00272 ComputeSize(argc-2,i-1,&x,&y,&w,&h,&wt,&ht) ;
00273 sprintf(buf,"gsave [1 0 0 -1 0 0] concat %5.2f %5.2f %5.2f %5.2f DesPosi"
00274 ,x,y,w,h);
00275 Sed(argv[i],"[0.5 10 div 0 0 0.5 10 div neg 0 2120 10 div] concat",
00276 buf," showpage","grestore",
00277 " end saved restore","% end saved restore",fdo);
00278 }
00279 ComputeSize(argc-2,argc-2,&x,&y,&w,&h,&wt,&ht) ;
00280 sprintf(buf,"gsave [1 0 0 -1 0 0] concat %5.2f %5.2f %5.2f %5.2f DesPosi"
00281 ,x,y,w,h);
00282 Sed(argv[argc-1],"[0.5 10 div 0 0 0.5 10 div neg 0 2120 10 div] concat",
00283 buf, " showpage"," grestore ",
00284 " end saved restore"," end saved restore",fdo);
00285 fprintf(fdo,"%%%%BoundingBox: 0 0 %d %d\n",(int)wt ,(int)ht);
00286 fclose(fdo);
00288 WriteTeX(argv[1],wt,ht);
00289 return(0);
00290 }