6
// AUTHOR : Frederic Hecht
7
// E-MAIL : hecht@ann.jussieu.fr
12
This file is part of Freefem++
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.
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.
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
28
#define FF_GRAPH_SET_PTR
40
#include <ConditionalMacros.h>
46
#include <Navigation.h>
47
int pStrCopy (StringPtr p1, char * p2)
48
/* copies a pascal string `p1 into a C string */
53
for(i=1;i<=len;i++) *p2++=*p1++;
58
int getprog(char* fn,int argc, char** argvptr)
62
NavDialogOptions dialogOptions;
65
anErr=NavGetDefaultDialogOptions(& dialogOptions);
66
if( anErr != noErr) return -1;
67
anErr =NavChooseFile(0,&reply,&dialogOptions,0,0,0,0,0) ;
68
if (anErr == noErr && reply.validRecord)
70
// Deal with multiple file selection
73
anErr = AECountItems(&(reply.selection), &count);
74
// Set up index for file list
79
for (index = 1; index <= count; index++)
84
FSSpec documentFSSpec;
86
// Get a pointer to selected file
87
anErr = AEGetNthPtr(&(reply.selection), index,
89
&actualType,&documentFSSpec,
90
sizeof(documentFSSpec),
94
anErr = HSetVol(0,documentFSSpec.vRefNum,documentFSSpec.parID);
95
pStrCopy(documentFSSpec.name, fn);
99
// Dispose of NavReplyRecord, resources, descriptors
100
anErr = NavDisposeReply(&reply);
106
#include "getprog-unix.hpp"
110
template<class T> inline T Min (const T &a,const T &b){return a < b ? a : b;}
111
template<class T> inline T Max (const T &a,const T & b){return a > b ? a : b;}
114
static long cube6[7][3] ={ { 65535,32000,32000},{ 65535, 65535,0},{0, 65535,0},{0, 65535, 65535},{0,0, 65535}
115
, { 65535,0, 65535},{ 32000,0,0} };
116
static long grey6[2][3] ={ {65534,65534,65534},{0,0,0} };
118
static bool grey=false;
119
static FILE *psfile = 0;
120
static FILE *psfile_save = 0;
121
static int LastColor=2; // pour est en couleur par defaut
123
const float fMinPixel = -32000;
124
const float fMaxPixel = +32000;
126
typedef struct XColor {
127
unsigned short red,green,blue;
129
static XColor *colortable;
130
static int ncolortable,fcolor;
131
static reel echx,echy,rxmin,rxmax,rymin,rymax;
132
static int lacouleur=0, width, height, currx=0, curry=0;
134
static int INITGRAPH=0;
140
cout << "the end" <<endl;
143
void myexit(int err) {
144
cout << " The End err=" << err << endl;
147
const char * edpfilenamearg=0;
148
bool waitatend=false;
154
void out_of_memory ();
156
void compile(char *fname);
159
int main (int argc, char **argv)
165
printf ("PROGRAM FreeFem 1.0 %s \n",argv[1]);
171
printf ("To launch freefem you must type freefem and a file name\n");
182
cout << " try getConsole " << edpfilenamearg << endl;
183
string fn = edpfilenamearg;
184
err=GetConsoleBuff(fn);
186
if( waitatend && err)
189
cout << "wait enter ? ";
195
extern int mymain(int argc,char **argv);
196
int main (int argc, char **argv)
199
int ret=mymain(argc,argv);
205
void message(char *s);
206
void message(char *s)
207
{ printf("%s \n",s);}
210
{ message(s); exit(0);}
211
void *safecalloc(size_t nb, size_t size);
212
void *safecalloc(size_t nb, size_t size)
215
p = calloc(nb, size);
216
if (p == NULL) printf("Run out of Memory!\n");
219
void safefree(void** f);
220
void safefree(void** f)
222
if(*f){ free((char*) *f); *f=NULL;}
230
int LaCouleur() {return lacouleur;}
234
if ( lacouleur == c) // small optim
237
c= c > LastColor ? 1 : c; // c=Min(c,LastColor); pour noir et blanc
241
if (c>0 && c < ncolortable)
243
r = (float) colortable[c].red /65535.;
244
g = (float) colortable[c].green /65535.;
245
b = (float) colortable[c].blue /65535.;
251
fprintf(psfile,"%.3f %.3f %.3f C\n",r,g,b);
255
static XColor DefColorSansG( int k,int nb, bool hsv,bool ggrey,int nbcolors,float *colors)
259
extern void DefColor(float & r, float & g, float & b,
260
int k,int nb, bool hsv,bool ggrey,int nbcolors,float *colors);
261
DefColor(r,g,b, k,nb,hsv,ggrey,nbcolors,colors);
262
C.red= (short unsigned int) (65535*r);
263
C.green=(short unsigned int)(65535*g);
264
C.blue= (short unsigned int) (65535*b);
267
void SetColorTable1(int nb,bool hsv,int nbcolors,float *colors)
269
static bool greyo = !grey;
270
static float *colorso =0;
271
if(!INITGRAPH) return;
272
if (ncolortable == nb && greyo == grey && colorso == colors ) return;// optim
275
if (nbcolors && nb>2)
277
if(colortable) delete [] colortable;
278
colortable = new XColor[nb];
280
if(LastColor>1) LastColor=nb-1;
281
for (int i0=0;i0<nb;i0++)
283
colortable[i0]=DefColorSansG(i0,nb,hsv,grey,nbcolors,colors);
290
void SetColorTable(int nb)
292
if (fcolor && nb>2 && nb < 256)
295
if (ncolortable == nb) return;// optim
296
if(colortable) delete [] colortable;
297
colortable = new XColor[nb];
299
if(LastColor>1) LastColor=nb-1;
300
// cout << "SetColorTable "<< nb << endl;
302
colortable[k].red= 65535;
303
colortable[k].green= 65535;
304
colortable[k].blue= 65535;
307
colortable[k].green=0;
308
colortable[k].blue=0;
311
for (long i0=0;i0<nb;i0++,k++)
313
// long i1 = nb - i0;
315
long j0 = i6/nb;// in 0..6
316
long j1 = j0+1;// in 1..6
317
long k0 = i0 - (nb*j0)/6L;
318
long k1 = (nb*j1)/6L-i0;
320
// cout <<k << " " << i0 << " " << j0 << " " << j1 << " " << k0 << " " << k1 << endl;
322
{ cerr << kk << " " << nb << " " << k0 << " " << k1 << " " << endl;
325
/* colortable[k].red = (unsigned short) ((long) (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk);
326
colortable[k].green = (unsigned short) ((long) (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk);
327
colortable[k].blue = (unsigned short) ((long) (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk);*/
330
colortable[k].red = (unsigned short) ((long) (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk);
331
colortable[k].green = (unsigned short) ((long) (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk);
332
colortable[k].blue = (unsigned short) ((long) (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk);
341
colortable[k].red = (unsigned short) ((long) (grey6[j1][0]*k0+grey6[j0][0]*k1)/kk);
342
colortable[k].green = (unsigned short) ((long) (grey6[j1][1]*k0+grey6[j0][1]*k1)/kk);
343
colortable[k].blue = (unsigned short) ((long) (grey6[j1][2]*k0+grey6[j0][2]*k1)/kk);
347
assert(k<ncolortable);
348
// cout <<colortable[k].pixel
349
// << " r=" << colortable[k].red
350
// << " g=" << colortable[k].green
351
// << " b=" <<colortable[k].blue <<endl;
366
LastColor=2;// En couleur par default
367
fcolor=1; /* des couleurs */
370
width = 10000;// change FH mai 2012 to have more precis graphic for F. Ortegon
371
height = 7071; // aspect ratio \sqrt(2)
374
void closegraphique()
379
delete [] colortable;
384
void cadre(reel xmin,reel xmax,reel ymin,reel ymax)
391
echx = width / (xmax - xmin);
392
echy = height / (ymax - ymin);
395
void getcadre(reel &xmin,reel &xmax,reel &ymin,reel &ymax)
405
int InRecScreen(reel x1, reel y1,reel x2, reel y2)
408
return (Max(x1,x2)>= rxmin) && (Min(x1,x2) <= rxmax) && (Max(y1,y2) >= rymin) && (Min(y1,y2) <= rymax);
410
int InPtScreen( reel x, reel y)
412
return (x >= rxmin) && (x <= rxmax) && (y >= rymin) && (y <= rymax);
422
return i/echx + rxmin;
426
return -j/echy + rymax;
430
return (int) Min(fMaxPixel,Max(fMinPixel,((x - rxmin) * echx)));
434
return (int)Min(fMaxPixel,Max(fMinPixel,((rymax - y) * echy)));
437
void pointe(reel , reel )
441
void rmoveto(reel x, reel y)
447
void rlineto(reel x, reel y)
449
int newx = scalx(x), newy = scaly(y);
451
fprintf(psfile,"%d %d %d %d L\n",currx, height-curry, newx, height-newy);
452
currx = newx; curry = newy;
455
void cadreortho(reel centrex, reel centrey, reel rayon)
460
rymin = centrey - rayon;
461
rymax = centrey + rayon;
462
echx = echy= height / (2 * rayon);
463
rxmin= centrex - width / (2 * echx);
464
rxmax= centrex + width / (2 * echx);
468
rxmin = centrex - rayon;
469
rxmax = centrex + rayon;
470
echx = echy = width / (2 * rayon);
471
rymin = centrey - height / (2 * echy);
472
rymax = centrey + height / (2 * echy);
476
void plotstring (const char * string)
477
{ //int l = strlen(string);
478
if(psfile) fprintf(psfile,"(%s) %d %d S\n",string,currx,height-curry);
484
void x11draw3(int * ptype);
486
void x11draw3(int * ptype)
494
case 0 : {fprintf(psfile,"[] setdash\n");break;}
495
case 1 : {fprintf(psfile,"[3] setdash\n");break;}
496
default : {fprintf(psfile,"[4 1] setdash\n");break;}
501
void penthickness(int pepais)
503
if (psfile) fprintf(psfile,"%d setlinewidth\n",pepais*2);
506
void x11linsrn(int * ,int * ,int * ,int * );
507
void x11linsrn(int * ,int * ,int * ,int * )
508
//int *x1,*x2,*y1,*y2;
518
void cercle(reel , reel , reel );
519
void cercle(reel , reel , reel )
521
//int r = (int) (rayon * echx);
527
void fillpoly(int n, float *poly)
532
fprintf(psfile,"bF ");
534
fprintf(psfile,"%d %d ", scalx(poly[2*i]),height-scaly( poly[2*i+1]));
535
fprintf(psfile,"eF\n");
541
int execute (const char * str)
543
cout << "exec: " << str << endl;
547
char Getijc(int *x1,int *y1);
548
char Getijc(int *x1,int *y1)
553
//cout << "entre un caractere ? ";
558
char Getxyc(float &x,float &y)
560
// cout << " in Getxyc" << endl;
566
// cout << " out Getxyc" << x << " " << y << " " << c << endl;
573
void GetScreenSize(int &ix,int &iy)
578
void openPS(const char *filename )
582
if(psfile_save) closePS();
585
//int heightA4PS=842;
586
float s= (double)widthA4PS/width;
588
/*if (!cuserid(username)) */ strcpy(username,"inconnue");
594
sprintf(ffff,"rgraph_%.3d.ps",count++);
595
volatile int r= stat(ffff,&buf) ;
597
if(count>1000) break;
598
} while ( !notfound );
601
const char *fps (filename?filename:ffff);
604
psfile=fopen(fps,"w");
607
fprintf(psfile,"%%!PS-Adobe-2.0 EPSF-2.0\n%%%%Creator: %s\n%%%%Title: FreeFem++\n","user");
608
fprintf(psfile,"%%%%CreationDate: %s",ctime(&t_loc));
609
fprintf(psfile,"%%%%Pages: 1\n");
610
fprintf(psfile,"%%%%BoundingBox: 0 0 %d %d\n",int(width*s),int(height*s));
611
fprintf(psfile,"%%%%EndComments\n");
612
fprintf(psfile," /L {newpath moveto lineto stroke} def\n");
613
fprintf(psfile," /C {setrgbcolor} def\n");
614
fprintf(psfile," /rec {newpath 4 copy 8 1 roll moveto 3 -1 roll lineto 4 2 roll exch lineto lineto closepath} def\n");
615
fprintf(psfile," %f %f scale \n",s,s);
616
fprintf(psfile," 0 %d 0 %d rec clip\n",int(width),int(height));
617
fprintf(psfile," /Helvetica findfont 24 scalefont setfont\n");
618
fprintf(psfile," /S {moveto show} def\n");
619
fprintf(psfile," /bF { mark} def \n");
620
fprintf(psfile," /eF {newpath moveto counttomark 2 idiv {lineto} repeat closepath fill cleartomark} def\n");
621
fprintf(psfile," /P { /yy exch def /xx exch def xx xx 1 add yy yy 1 add rec fill } def\n");
622
fprintf(psfile," 2 setlinewidth\n");
625
cerr << " Err openning postscript file " << fps << endl;
630
fprintf(psfile_save,"showpage\n");
636
void coutmode(short ) {}
638
float GetHeigthFont()
642
void Commentaire(const char * c)
645
fprintf(psfile,"%% %s\n",c);
648
void NoirEtBlanc(int NB)
651
else LastColor=ncolortable?ncolortable:2;
654
void MettreDansPostScript(int in)
656
if(in) psfile=psfile_save;
660
static void FillRect(float x0,float y0, float x1, float y1)
669
int PutLevel(int lineno, float xf, int col);
670
int PutLevel(int lineno, float xf, int col)
672
float xmin,xmax,ymin,ymax;
673
getcadre(xmin,xmax,ymin,ymax);
674
float xleft = xmax - (xmax-xmin)*0.1;
676
float ydelta = (ymax-ymin)/40;
677
ydelta=GetHeigthFont();
678
xleft = xmax - 6*ydelta;
679
ytop -= ydelta*(col+2);
681
FillRect(xleft+ydelta/8.,ytop+ydelta/8.,xleft+ydelta*7./8.,ytop+ydelta*7./8.);
682
rmoveto(xleft+ydelta*1.4,ytop+ydelta/4);
684
sprintf(buf,"%g",xf);
690
void ShowHelp(const char * s,int k)
693
MettreDansPostScript(0);
695
float xmin,xmax,ymin,ymax;
696
getcadre(xmin,xmax,ymin,ymax);
697
rmoveto(xmin+(xmax-xmin)/100,ymax-(k)*(ymax-ymin)/30);
699
MettreDansPostScript(1);
704
void setgrey(bool gg ){grey=gg;}
705
int getgrey(){ return grey;}
708
void SaveMesh(Grid &);
709
void SavePlot(int , Grid& , double *);
710
void SavePlot(int , Grid& , float *);
712
void SaveMesh(Grid &){}
713
void SavePlot(int , Grid& , double *){}
714
void SavePlot(int , Grid& , float *){}