1 // -*- Mode : c++ -*-
2 //
3 // SUMMARY :
4 // USAGE :
5 // ORG :
6 // AUTHOR : Frederic Hecht
7 // E-MAIL : hecht@ann.jussieu.fr
8 //
9
10 /*
11
12 This file is part of Freefem++
13
14 Freefem++ is free software; you can redistribute it and/or modify
15 it under the terms of the GNU Lesser General Public License as published by
16 the Free Software Foundation; either version 2.1 of the License, or
17 (at your option) any later version.
18
19 Freefem++ is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public License
25 along with Freefem++; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29 // ALH - javascript output
30 #ifdef FFJS
31 #ifndef NATIVEFFJS // [[file:~/ffjs/Makefile::NATIVEFFJS]]
32 #include <emscripten.h>
33 #endif // NATIVEFFJS
34 #endif // FFJS
35
36 #define FF_GRAPH_SET_PTR
37 #include <ctime>
38 #include <cstdlib>
39 #include <cstdio>
40 #include <cstring>
41 #include <iostream>
42 #include <cassert>
43 using namespace std;
44 #include "rgraph.hpp"
45
46 #include "error.hpp"
47 #ifdef macintoshxx
48 #include <ConditionalMacros.h>
49 #include <unix.h>
50 #else
51 #include <sys/stat.h>
52 #endif
53 #ifdef xTARGET_CARBON
54 #include <Navigation.h>
55
pStrCopy(StringPtr p1,char * p2)56 int pStrCopy (StringPtr p1, char * p2)
57 /* copies a pascal string `p1 into a C string */
58 {
59 int len,i;
60
61 len = (*p1++) %256;
62 for(i=1;i<=len;i++) *p2++=*p1++;
63 *p2 = 0;
64 return 0;
65 }
66
getprog(char * fn,int argc,char ** argvptr)67 int getprog(char* fn,int argc, char** argvptr)
68 {
69 OSErr anErr;
70
71 NavDialogOptions dialogOptions;
72 NavReplyRecord reply;
73
74 anErr=NavGetDefaultDialogOptions(& dialogOptions);
75 if( anErr != noErr) return -1;
76 anErr =NavChooseFile(0,&reply,&dialogOptions,0,0,0,0,0) ;
77 if (anErr == noErr && reply.validRecord)
78 {
79 // Deal with multiple file selection
80 long count;
81
82 anErr = AECountItems(&(reply.selection), &count);
83 // Set up index for file list
84 if (anErr == noErr)
85 {
86 long index;
87
88 for (index = 1; index <= count; index++)
89 {
90 AEKeyword theKeyword;
91 DescType actualType;
92 Size actualSize;
93 FSSpec documentFSSpec;
94
95 // Get a pointer to selected file
96 anErr = AEGetNthPtr(&(reply.selection), index,
97 typeFSS, &theKeyword,
98 &actualType,&documentFSSpec,
99 sizeof(documentFSSpec),
100 &actualSize);
101 if (anErr == noErr)
102 {
103 anErr = HSetVol(0,documentFSSpec.vRefNum,documentFSSpec.parID);
104 pStrCopy(documentFSSpec.name, fn);
105 }
106 }
107 }
108 // Dispose of NavReplyRecord, resources, descriptors
109 anErr = NavDisposeReply(&reply);
110
111 }
112 return (2);
113 }
114 #else
115 #include "getprog-unix.hpp"
116 #endif
117
118
Min(const T & a,const T & b)119 template<class T> inline T Min (const T &a,const T &b){return a < b ? a : b;}
Max(const T & a,const T & b)120 template<class T> inline T Max (const T &a,const T & b){return a > b ? a : b;}
121
122
123 static long cube6[7][3] ={ { 65535,32000,32000},{ 65535, 65535,0},{0, 65535,0},{0, 65535, 65535},{0,0, 65535}
124 , { 65535,0, 65535},{ 32000,0,0} };
125 static long grey6[2][3] ={ {65534,65534,65534},{0,0,0} };
126
127 static bool grey=false;
128 static FILE *psfile = 0;
129 static FILE *psfile_save = 0;
130 static int LastColor=2; // pour est en couleur par defaut
131
132 const float fMinPixel = -32000;
133 const float fMaxPixel = +32000;
134 #define reel float
135 typedef struct XColor {
136 unsigned short red,green,blue;
137 } XColor;
138 static XColor *colortable;
139 static int ncolortable,fcolor;
140 static reel echx,echy,rxmin,rxmax,rymin,rymax;
141 static int lacouleur=0, width, height, currx=0, curry=0;
142 #define call(i) i
143 static int INITGRAPH=0;
144 void myend();
myend()145 void myend()
146 {
147 if (INITGRAPH)
148 closegraphique();
149 cout << "the end" <<endl;
150 // ExitToShell();
151 }
myexit(int err)152 void myexit(int err) {
153 cout << " The End err=" << err << endl;
154 exit(err);}
155
156 const char * edpfilenamearg=0;
157 bool waitatend=false;
158 bool consoleatend=false;
159
160 #ifdef FREEFEM
161 #include <fstream.h>
162 #include <new.h>
163
164 void out_of_memory ();
165 void myexit(int );
166 void compile(char *fname);
167
168
main(int argc,char ** argv)169 int main (int argc, char **argv)
170 {
171 atexit(myend);
172
173 int OPTION = 0;
174 if (argc == 2)
175 {
176 printf ("PROGRAM FreeFem 1.0 %s \n",argv[1]);
177 initgraphique();
178 compile (argv[1]);
179 closegraphique();
180 }
181 else
182 printf ("To launch freefem you must type freefem and a file name\n");
183 return 0;
184 }
185 #else
186 void doatexitff();
doatexitff()187 void doatexitff()
188 {
189 #ifdef _WIN32
190 bool err=true;
191 if(edpfilenamearg && consoleatend)
192 {
193 cout << " try getConsole " << edpfilenamearg << endl;
194 string fn = edpfilenamearg;
195 err=GetConsoleBuff(fn);
196 }
197 if( waitatend && err)
198 {
199 char c;
200 cout << "wait enter ? ";
201 cin.get();
202 }
203 #endif
204
205 }
206
207 extern int mymain(int argc,char **argv);
208
209 // <<main>>
210
211 // ALH - 4/4/15 - main() is not desired if FF is used as a library
212
213 #ifndef WITHOUT_MAIN
214
215 // ALH - 24/2/15 - the main entry point for javascript is on the HTML page so we need to give it a different name here.
216 // Built by [[file:~/fflib/Makefile::FFLIB_MAIN]] and called by [[file:~/fflib/fflib.cpp::calling_fflib_main]].
217
218 #ifdef FFLIB_MAIN
fflib_main(int argc,char ** argv)219 int fflib_main(int argc,char **argv)
220 #else
221 int main (int argc, char **argv)
222 #endif
223 {
224 atexit(doatexitff);
225 int ret=mymain(argc,argv); // <<calling_mymain>>
226 return ret;
227 }
228
229 #endif // WITHOUT_MAIN
230
231 #endif // FREEFEM
232
233 void message(char *s);
message(char * s)234 void message(char *s)
235 { printf("%s \n",s);}
236
erreur(char * s)237 void erreur(char *s)
238 { message(s); exit(0);}
239 void *safecalloc(size_t nb, size_t size);
safecalloc(size_t nb,size_t size)240 void *safecalloc(size_t nb, size_t size)
241 {
242 void* p=NULL;
243 p = calloc(nb, size);
244 if (p == NULL) printf("Run out of Memory!\n");
245 return p;
246 }
247 void safefree(void** f);
safefree(void ** f)248 void safefree(void** f)
249 {
250 if(*f){ free((char*) *f); *f=NULL;}
251 }
252 void rflush();
rflush()253 void rflush()
254 {
255 }
256
257
LaCouleur()258 int LaCouleur() {return lacouleur;}
259
couleur(int c)260 void couleur(int c)
261 {
262 if ( lacouleur == c) // small optim
263 return;
264
265 c= c > LastColor ? 1 : c; // c=Min(c,LastColor); pour noir et blanc
266 lacouleur = c;
267 float r=1,g=1,b=1;
268 if (colortable) {
269 if (c>0 && c < ncolortable)
270 {
271 r = (float) colortable[c].red /65535.;
272 g = (float) colortable[c].green /65535.;
273 b = (float) colortable[c].blue /65535.;
274 }
275 }
276 else if (c!=0)
277 r=g=b=0;
278 if(psfile)
279 fprintf(psfile,"%.3f %.3f %.3f C\n",r,g,b);
280
281 #ifdef FFJS_GRAPH
282 // ALH - <<ffjs_couleur>> javascript graph [[file:~/ffjs/main.js::ffjs_couleur]]
283 EM_ASM_DOUBLE({ffjs_couleur($0,$1,$2)},r,g,b);
284 #endif
285 }
286
287 extern void DefColor(float & r, float & g, float & b,
288 int k,int nb, bool hsv,bool ggrey,int nbcolors,float *colors);
289
DefColorSansG(int k,int nb,bool hsv,bool ggrey,int nbcolors,float * colors)290 static XColor DefColorSansG( int k,int nb, bool hsv,bool ggrey,int nbcolors,float *colors)
291 {
292 XColor C;
293 float r,g,b;
294 DefColor(r,g,b, k,nb,hsv,ggrey,nbcolors,colors);
295 C.red= (short unsigned int) (65535*r);
296 C.green=(short unsigned int)(65535*g);
297 C.blue= (short unsigned int) (65535*b);
298 return C;
299 }
SetColorTable1(int nb,bool hsv,int nbcolors,float * colors)300 void SetColorTable1(int nb,bool hsv,int nbcolors,float *colors)
301 {
302 static bool greyo = !grey;
303 static float *colorso =0;
304 if(!INITGRAPH) return;
305 if (ncolortable == nb && greyo == grey && colorso == colors ) return;// optim
306 greyo = grey;
307 colorso=colors;
308 if (nbcolors && nb>2)
309 {
310 if(colortable) delete [] colortable;
311 colortable = new XColor[nb];
312 ncolortable = nb;
313 if(LastColor>1) LastColor=nb-1;
314 for (int i0=0;i0<nb;i0++)
315 {
316 colortable[i0]=DefColorSansG(i0,nb,hsv,grey,nbcolors,colors);
317 }
318
319 }
320 else
321 ncolortable =0;
322 }
SetColorTable(int nb)323 void SetColorTable(int nb)
324 {
325 if (fcolor && nb>2 && nb < 256)
326 {
327 nb = Max(nb,8);
328 if (ncolortable == nb) return;// optim
329 if(colortable) delete [] colortable;
330 colortable = new XColor[nb];
331 ncolortable = nb;
332 if(LastColor>1) LastColor=nb-1;
333 // cout << "SetColorTable "<< nb << endl;
334 int k=0;
335 colortable[k].red= 65535;
336 colortable[k].green= 65535;
337 colortable[k].blue= 65535;
338 k++;
339 colortable[k].red=0;
340 colortable[k].green=0;
341 colortable[k].blue=0;
342 k++;
343 nb = nb -2;
344 for (long i0=0;i0<nb;i0++,k++)
345 {
346 // long i1 = nb - i0;
347 long i6 = i0*6;
348 long j0 = i6/nb;// in 0..6
349 long j1 = j0+1;// in 1..6
350 long k0 = i0 - (nb*j0)/6L;
351 long k1 = (nb*j1)/6L-i0;
352 long kk = k0+k1;
353 // cout <<k << " " << i0 << " " << j0 << " " << j1 << " " << k0 << " " << k1 << endl;
354 if ( kk <= 0)
355 { cerr << kk << " " << nb << " " << k0 << " " << k1 << " " << endl;
356 assert(kk);
357 }
358 /* colortable[k].red = (unsigned short) ((long) (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk);
359 colortable[k].green = (unsigned short) ((long) (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk);
360 colortable[k].blue = (unsigned short) ((long) (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk);*/
361 if (! grey)
362 {
363 colortable[k].red = (unsigned short) ((long) (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk);
364 colortable[k].green = (unsigned short) ((long) (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk);
365 colortable[k].blue = (unsigned short) ((long) (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk);
366 }
367 else
368 {
369 kk=nb-1;
370 k1 = i0;
371 k0 = nb - i0 -1;
372 j0=1;
373 j1=0;
374 colortable[k].red = (unsigned short) ((long) (grey6[j1][0]*k0+grey6[j0][0]*k1)/kk);
375 colortable[k].green = (unsigned short) ((long) (grey6[j1][1]*k0+grey6[j0][1]*k1)/kk);
376 colortable[k].blue = (unsigned short) ((long) (grey6[j1][2]*k0+grey6[j0][2]*k1)/kk);
377 }
378
379
380 assert(k<ncolortable);
381 // cout <<colortable[k].pixel
382 // << " r=" << colortable[k].red
383 // << " g=" << colortable[k].green
384 // << " b=" <<colortable[k].blue <<endl;
385 }
386 }
387
388
389 // a faire
390 }
FlushEvent()391 void FlushEvent()
392 {
393 }
394
initgraphique()395 void initgraphique()
396 {
397 colortable=0;
398 ncolortable=0;
399 LastColor=2;// En couleur par default
400 fcolor=1; /* des couleurs */
401 SetColorTable(8);
402 INITGRAPH = 1;
403 width = 10000;// change FH mai 2012 to have more precis graphic for F. Ortegon
404 height = 7071; // <<aspect_ratio>> \sqrt(2)
405 }
406
closegraphique()407 void closegraphique()
408 {
409 if (INITGRAPH)
410 {
411 INITGRAPH = 0;
412 delete [] colortable;
413 closePS();
414 }
415 }
416
cadre(reel xmin,reel xmax,reel ymin,reel ymax)417 void cadre(reel xmin,reel xmax,reel ymin,reel ymax)
418 {
419 rxmin = xmin;
420 rxmax = xmax;
421 rymin = ymin;
422 rymax = ymax;
423
424 echx = width / (xmax - xmin);
425 echy = height / (ymax - ymin);
426 }
427
getcadre(reel & xmin,reel & xmax,reel & ymin,reel & ymax)428 void getcadre(reel &xmin,reel &xmax,reel &ymin,reel &ymax)
429 {
430 xmin = rxmin;
431 xmax = rxmax;
432 ymin = rymin;
433 ymax = rymax;
434
435 }
436
437
InRecScreen(reel x1,reel y1,reel x2,reel y2)438 int InRecScreen(reel x1, reel y1,reel x2, reel y2)
439 {
440
441 return (Max(x1,x2)>= rxmin) && (Min(x1,x2) <= rxmax) && (Max(y1,y2) >= rymin) && (Min(y1,y2) <= rymax);
442 }
InPtScreen(reel x,reel y)443 int InPtScreen( reel x, reel y)
444 {
445 return (x >= rxmin) && (x <= rxmax) && (y >= rymin) && (y <= rymax);
446 }
447
448
449 float scali(int i);
450 float scalj(int i);
451 float scalx(int i);
452 float scaly(int i);
scali(int i)453 float scali(int i)
454 {
455 return i/echx + rxmin;
456 }
scalj(int j)457 float scalj(int j)
458 {
459 return -j/echy + rymax;
460 }
scalx(reel x)461 int scalx(reel x)
462 {
463 return (int) Min(fMaxPixel,Max(fMinPixel,((x - rxmin) * echx)));
464 }
scaly(reel y)465 int scaly(reel y)
466 {
467 return (int)Min(fMaxPixel,Max(fMinPixel,((rymax - y) * echy)));
468 }
469
pointe(reel,reel)470 void pointe(reel , reel )
471 {
472 }
473
474 // <<rmoveto>>
rmoveto(reel x,reel y)475 void rmoveto(reel x, reel y)
476 {
477 currx = scalx(x);
478 curry = scaly(y);
479
480 #ifdef FFJS_GRAPH
481 // ALH - <<ffjs_rmoveto>> javascript graph [[file:~/ffjs/ffapi.js::ffjs_rmoveto]]
482 EM_ASM_INT({ffjs_rmoveto($0,$1)},currx,curry);
483 #endif
484 }
485
rlineto(reel x,reel y)486 void rlineto(reel x, reel y)
487 {
488 int newx = scalx(x), newy = scaly(y);
489 if (psfile)
490 fprintf(psfile,"%d %d %d %d L\n",currx, height-curry, newx, height-newy);
491 currx = newx; curry = newy;
492
493 #ifdef FFJS_GRAPH
494 // ALH - <<ffjs_rlineto>> javascript graph [[file:~/ffjs/main.js::ffjs_rlineto]]
495 EM_ASM_INT({ffjs_rlineto($0,$1)},newx,newy);
496 #endif
497 }
498
cadreortho(reel centrex,reel centrey,reel rayon)499 void cadreortho(reel centrex, reel centrey, reel rayon)
500 {
501
502 if (height < width)
503 {
504 rymin = centrey - rayon;
505 rymax = centrey + rayon;
506 echx = echy= height / (2 * rayon);
507 rxmin= centrex - width / (2 * echx);
508 rxmax= centrex + width / (2 * echx);
509 }
510 else
511 {
512 rxmin = centrex - rayon;
513 rxmax = centrex + rayon;
514 echx = echy = width / (2 * rayon);
515 rymin = centrey - height / (2 * echy);
516 rymax = centrey + height / (2 * echy);
517 }
518 }
519
plotstring(const char * string)520 void plotstring (const char * string)
521 { //int l = strlen(string);
522 if(psfile) fprintf(psfile,"(%s) %d %d S\n",string,currx,height-curry);
523
524 #ifdef FFJS_GRAPH
525 // ALH - <<ffjs_plotstring>> javascript graph - Send the string character by character to
526 // [[file:~/ffjs/main.js::ffjs_plotstring]] because there is no string parameter at the moment
527 // [[http://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#c.EM_ASM_]]
528
529 for(const char *c=string;*c;c++)EM_ASM_INT({ffjs_plotstring($0)},*c);
530 EM_ASM(ffjs_plotstring(0));
531 #endif
532 }
533
showgraphic()534 void showgraphic()
535 {
536 }
537
penthickness(int pepais)538 void penthickness(int pepais)
539 {
540 if (psfile) fprintf(psfile,"%d setlinewidth\n",pepais*2);
541
542 #ifdef FFJS_GRAPH
543 // ALH - <<ffjs_penthickness>> javascript graph [[file:~/ffjs/main.js::ffjs_penthickness]]
544 EM_ASM_INT({ffjs_penthickness($0)},pepais);
545 #endif
546 }
547
548 void x11linsrn(int * ,int * ,int * ,int * );
x11linsrn(int *,int *,int *,int *)549 void x11linsrn(int * ,int * ,int * ,int * )
550 //int *x1,*x2,*y1,*y2;
551 {
552 }
553
554
viderbuff()555 void viderbuff()
556 {
557 }
558
559
560 void cercle(reel , reel , reel );
cercle(reel,reel,reel)561 void cercle(reel , reel , reel )
562 {
563 //int r = (int) (rayon * echx);
564 }
reffecran()565 void reffecran(){
566 #ifdef FFJS_GRAPH
567 // ALH - <<ffjs_graphstart>> javascript graph [[file:~/ffjs/main.js::ffjs_graphstart]]
568 EM_ASM(ffjs_graphstart());
569 #endif
570 }
571
fillpoly(int n,float * poly)572 void fillpoly(int n, float *poly)
573 {
574 int i;
575 if (psfile)
576 {
577 fprintf(psfile,"bF ");
578 for (i=0;i<n;i++)
579 fprintf(psfile,"%d %d ", scalx(poly[2*i]),height-scaly( poly[2*i+1]));
580 fprintf(psfile,"eF\n");
581 }
582
583 #ifdef FFJS_GRAPH
584 // ALH - <<ffjs_fillpoly>> javascript graph [[file:~/ffjs/main.js::ffjs_fillpoly]]
585 EM_ASM_INT({ffjs_fillpoly_begin($0,$1)},scalx(poly[0]),scaly(poly[1]));
586 for(i=1;i<n;i++)EM_ASM_INT({ffjs_fillpoly_next($0,$1)},scalx(poly[2*i]),scaly(poly[2*i+1]));
587 EM_ASM(ffjs_fillpoly_close());
588 #endif
589 }
590
591
execute(const char * str)592 int execute (const char * str)
593 {
594 if(verbosity)
595 cout << "exec: " << str << endl;
596 return system(str);
597 }
598
599 char Getijc(int *x1,int *y1);
Getijc(int * x1,int * y1)600 char Getijc(int *x1,int *y1)
601 {
602 //char char1;
603 *x1=0;
604 *y1=0;
605 //cout << "entre un caractere ? ";
606 //cin >>char1 ;
607 return 0;// char1;
608 }
609
Getxyc(float & x,float & y)610 char Getxyc(float &x,float &y)
611 {
612 // cout << " in Getxyc" << endl;
613 char c;
614 int i,j;
615 c = Getijc( &i,&j);
616 x = scali(i);
617 y = scalj(j);
618 // cout << " out Getxyc" << x << " " << y << " " << c << endl;
619
620 return c;
621 }
622
623 /// <<rattente>>
rattente(int)624 void rattente(int )
625 {
626 }
GetScreenSize(int & ix,int & iy)627 void GetScreenSize(int &ix,int &iy)
628 {
629 ix = width;
630 iy = height;
631 }
632
633 // <<openPS>>
634
openPS(const char * filename)635 void openPS(const char *filename )
636 {
637 char ffff[32];
638 int count=0;
639 if(psfile_save) closePS();
640 time_t t_loc;
641 int widthA4PS=596;
642 //int heightA4PS=842;
643 float s= (double)widthA4PS/width;
644 char username[10];
645 /*if (!cuserid(username)) */ strcpy(username,"inconnue");
646 time(&t_loc);
647 bool notfound;
648 if( !filename)
649 do {
650 struct stat buf;
651 sprintf(ffff,"rgraph_%.3d.ps",count++);
652 volatile int r= stat(ffff,&buf) ;
653 notfound = r !=0;
654 if(count>1000) break;
655 } while ( !notfound );
656
657
658 const char *fps (filename?filename:ffff);
659
660
661 psfile=fopen(fps,"w");
662
663 #ifdef FFJS_GRAPH
664
665 // <<listgraphs>> ALH - extract the list of graphs generated by FF during a run
666 // [[file:~/ffjs/ffapi.js::ffjs_listgraphs]]. Send the file name character by character to
667 // [[file:~/ffjs/ffapi.js::ffjs_listgraphs]] because there is no string parameter at the moment
668 // [[http://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#c.EM_ASM_]]
669
670 for(const char *c=fps;*c;c++)EM_ASM_INT({ffjs_listgraphs($0)},*c);
671 EM_ASM(ffjs_listgraphs(0));
672 #endif
673
674 if(psfile) {
675 psfile_save=psfile;
676 fprintf(psfile,"%%!PS-Adobe-2.0 EPSF-2.0\n%%%%Creator: %s\n%%%%Title: FreeFem++\n","user");
677 fprintf(psfile,"%%%%CreationDate: %s",ctime(&t_loc));
678 fprintf(psfile,"%%%%Pages: 1\n");
679 fprintf(psfile,"%%%%BoundingBox: 0 0 %d %d\n",int(width*s),int(height*s));
680 fprintf(psfile,"%%%%EndComments\n");
681 fprintf(psfile," /L {newpath moveto lineto stroke} def\n");
682 fprintf(psfile," /C {setrgbcolor} def\n");
683 fprintf(psfile," /rec {newpath 4 copy 8 1 roll moveto 3 -1 roll lineto 4 2 roll exch lineto lineto closepath} def\n");
684 fprintf(psfile," %f %f scale \n",s,s);
685 fprintf(psfile," 0 %d 0 %d rec clip\n",int(width),int(height));
686 fprintf(psfile," /Helvetica findfont %d scalefont setfont\n",int(9/s));
687 fprintf(psfile," /S {moveto show} def\n");
688 fprintf(psfile," /bF { mark} def \n");
689 fprintf(psfile," /eF {newpath moveto counttomark 2 idiv {lineto} repeat closepath fill cleartomark} def\n");
690 fprintf(psfile," /P { /yy exch def /xx exch def xx xx 1 add yy yy 1 add rec fill } def\n");
691 fprintf(psfile," 2 setlinewidth\n");
692 }
693 else
694 cerr << " Err opening postscript file " << fps << endl;
695 }
closePS(void)696 void closePS(void)
697 {
698 if(psfile_save) {
699 fprintf(psfile_save,"showpage\n");
700 fclose(psfile_save);
701 }
702 psfile_save=0;
703 psfile=0;
704
705 #ifdef FFJS_GRAPH
706 // ALH - <<ffjs_graphdone>> javascript graph [[file:~/ffjs/main.js::ffjs_graphdone]]
707 EM_ASM({ffjs_graphdone()});
708 #endif
709 }
coutmode(short)710 void coutmode(short ) {}
711 // bof bof ---
GetHeigthFont()712 float GetHeigthFont()
713 {
714 double widthA4PS=596;
715 float s=widthA4PS/width;
716 return 5.5/s/echy;
717 }
Commentaire(const char * c)718 void Commentaire(const char * c)
719 {
720 if(psfile) {
721 fprintf(psfile,"%% %s\n",c);
722 }
723 }
NoirEtBlanc(int NB)724 void NoirEtBlanc(int NB)
725 {
726 if(NB) LastColor=1;
727 else LastColor=ncolortable?ncolortable:2;
728 }
729
MettreDansPostScript(int in)730 void MettreDansPostScript(int in)
731 {
732 if(in) psfile=psfile_save;
733 else psfile=0;
734 }
735
FillRect(float x0,float y0,float x1,float y1)736 static void FillRect(float x0,float y0, float x1, float y1)
737 {
738 float r[8];
739 r[0]=x0;r[1]=y0;
740 r[2]=x1;r[3]=y0;
741 r[4]=x1;r[5]=y1;
742 r[6]=x0;r[7]=y1;
743 fillpoly(4,r);
744 }
745 int PutLevel(int lineno, float xf, int col);
PutLevel(int lineno,float xf,int col)746 int PutLevel(int lineno, float xf, int col)
747 {
748 float xmin,xmax,ymin,ymax;
749 getcadre(xmin,xmax,ymin,ymax);
750 float xleft = xmax - (xmax-xmin)*0.1;
751 float ytop = ymax;
752 float ydelta = (ymax-ymin)/40;
753 ydelta=GetHeigthFont();
754 xleft = xmax - 6*ydelta;
755 ytop -= ydelta*(col+2);
756 couleur(col);
757 FillRect(xleft+ydelta/8.,ytop+ydelta/8.,xleft+ydelta*7./8.,ytop+ydelta*7./8.);
758 rmoveto(xleft+ydelta*1.4,ytop+ydelta/4);
759 char buf[30];
760 sprintf(buf,"%g",xf);
761 couleur(1);
762 plotstring(buf);
763
764 return lineno;
765 }
ShowHelp(const char * s,int k)766 void ShowHelp(const char * s,int k)
767 {
768 if(k) {
769 MettreDansPostScript(0);
770 couleur(1);
771 float xmin,xmax,ymin,ymax;
772 getcadre(xmin,xmax,ymin,ymax);
773 rmoveto(xmin+(xmax-xmin)/100,ymax-(k)*(ymax-ymin)/30);
774 plotstring(s);
775 MettreDansPostScript(1);
776 // couleur(1);
777 }
778 }
779
setgrey(bool gg)780 void setgrey(bool gg ){grey=gg;}
getgrey()781 int getgrey(){ return grey;}
782
783 class Grid;
784 void SaveMesh(Grid &);
785 void SavePlot(int , Grid& , double *);
786 void SavePlot(int , Grid& , float *);
787
SaveMesh(Grid &)788 void SaveMesh(Grid &){}
SavePlot(int,Grid &,double *)789 void SavePlot(int , Grid& , double *){}
SavePlot(int,Grid &,float *)790 void SavePlot(int , Grid& , float *){}
791
792