Remove graphics.h file.
[scilab.git] / scilab / modules / graphics / src / c / Axes.c
1 /*------------------------------------------------------------------------
2  *    Graphic library
3  *    Copyright (C) 1998-2000 Enpc/Jean-Philippe Chancelier
4  *    Copyright (C) 2006      INRIA/Jean-Baptiste Silvy
5  *    jpc@cereve.enpc.fr 
6  --------------------------------------------------------------------------*/
7 /*------------------------------------------------------------------------
8  * Axis drawing for 2d plots 
9  *--------------------------------------------------------------------------*/
10
11 #include <math.h>
12 #include <string.h>
13 #include <stdio.h>
14 #include "math_graphics.h"
15 #include "PloEch.h"
16 #include "Axes.h"
17 #include "DestroyObjects.h"
18 #include "DrawObjects.h"
19 #include "InitObjects.h"
20 #include "Xcall1.h"
21 #include "SetProperty.h"
22 #include "handleDrawing/drawTextEntity.h"
23 #include "sciprint.h"
24 #include "Format.h"
25 #include "Plo3d.h"
26 #include "axesScale.h"
27
28
29 #include "MALLOC.h" /* MALLOC */
30
31 #include "GetProperty.h"
32
33 static double  x_convert __PARAMS((char xy_type,double x[] ,int i));
34 static double  y_convert __PARAMS((char xy_type,double x[] ,int i));
35 extern void NumberFormat __PARAMS((char *str,integer k,integer a));
36 static void aplotv1  __PARAMS((char*));
37 static void aplotv2  __PARAMS((char*));
38
39
40 static void axesplot(char* ,sciPointObj*);
41 static int SciAxisNew(char pos,sciPointObj *psubwin, double xy,int fontsize,int fontstyle,int textcolor,int ticscolor, int seg);
42
43 static void DrawXTics(char pos, sciPointObj * psubwin, double xy, char * c_format, int * fontid, int textcolor,int ticscolor,int color_kp, int *logrect, int smallersize);
44 static void DrawYTics(char pos, sciPointObj * psubwin, double xy, char * c_format, int * fontid, int textcolor,int ticscolor,int color_kp, int *logrect, int smallersize);
45 static int XDrawAxisLine(double xminval,double xmaxval,double xy, int ticscolor, int color_kp);
46 static int YDrawAxisLine(double yminval,double ymaxval,double xy, int ticscolor, int color_kp);
47 static void FindXYMinMaxAccordingTL(sciPointObj * psubwin, double *xminval,double *yminval,double *xmaxval,double *ymaxval);
48
49 static int DrawXSubTics(char pos, sciPointObj * psubwin, double xy,int ticscolor,int color_kp);
50 static int DrawYSubTics(char pos, sciPointObj * psubwin, double xy,int ticscolor,int color_kp);
51
52 static int DrawXGrid(sciPointObj * psubwin);
53 static int DrawYGrid(sciPointObj * psubwin);
54
55 static void YGradPosition(sciPointObj * psubwin, int xx, int rect2);
56 static void XGradPosition(sciPointObj * psubwin, int yy, int rect3);
57
58 int SciDrawLines(char pos, sciPointObj * psubwin, double xy, int textcolor,int ticscolor);
59
60 #ifdef _MSC_VER
61 extern void Scistring (char *str);
62 #endif
63 /*--------------------------------------------------------------
64  * Draw Axis or only rectangle
65  *----------------------------------------------------------------*/
66
67 void axis_draw(char strflag[])
68
69         static sciPointObj * psubwin;
70   /* using foreground to draw axis */
71   integer verbose=0,narg,xz[10],fg,i,ixbox[5],iybox[5],p=5,n=1,color,color_kp; 
72  /*  int isoflag = -1; */
73   char c = (strlen(strflag) >= 3) ? strflag[2] : '1';
74   C2F(dr)("xget","foreground",&verbose,&fg,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
75   C2F(dr)("xget","line style",&verbose,xz,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
76   C2F(dr)("xset","line style",(i=1,&i),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
77   C2F(dr)("xget","color",&verbose,xz+1,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
78   C2F(dr)("xset","color",&fg,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
79
80
81   psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
82   
83   /* F.Leray test on color here*/
84   color=sciGetBackground(psubwin);
85   
86
87   ixbox[0]=ixbox[4]=Cscale.WIRect1[0];iybox[0]=iybox[4]=Cscale.WIRect1[1];
88   ixbox[1]=ixbox[0];iybox[1]=Cscale.WIRect1[1]+Cscale.WIRect1[3];
89   ixbox[2]=Cscale.WIRect1[0]+Cscale.WIRect1[2];iybox[2]=iybox[1];
90   ixbox[3]=ixbox[2];iybox[3]=iybox[0];
91   C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
92   C2F(dr)("xset","pattern",&color,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
93   C2F(dr)("xarea", "v", &p, ixbox, iybox, &n, PI0, PI0, PD0, PD0, PD0, PD0, 5L,0L);
94   C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
95
96   switch ( c) 
97     {
98     case '0' :
99       break ;
100     case '2' :
101       pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON;  /* NG */
102       C2F(dr)("xrect","xv",&Cscale.WIRect1[0],&Cscale.WIRect1[1],&Cscale.WIRect1[2],&Cscale.WIRect1[3]
103               ,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
104       break;
105     default :
106       axesplot(strflag,psubwin);
107       break;
108     }
109
110
111
112   C2F(dr)("xset","line style",xz,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
113   C2F(dr)("xset","color",xz+1,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
114
115
116 }
117
118 /* F.Leray 16.12.04 */
119 /* Same thing as axis_draw without the background area set */
120 /* Only used in NG mode */
121 void axis_draw2(char strflag[])
122
123         static sciPointObj * psubwin;
124   /* using foreground to draw axis */
125   integer verbose=0,narg,xz[10],fg,i,color; 
126   /*  int isoflag = -1; */
127   char c = (strlen(strflag) >= 3) ? strflag[2] : '1';
128   C2F(dr)("xget","foreground",&verbose,&fg,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
129   C2F(dr)("xget","line style",&verbose,xz,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
130   C2F(dr)("xset","line style",(i=1,&i),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
131   C2F(dr)("xget","color",&verbose,xz+1,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
132   C2F(dr)("xset","color",&fg,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
133   
134   psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
135   
136   /* F.Leray test on color here*/
137   color=sciGetBackground(psubwin);
138   
139   switch ( c) 
140     {
141       /*case '0' :
142         break ;*/
143     case '2' :
144       pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON;
145       
146       C2F(dr)("xrect","xv",&Cscale.WIRect1[0],&Cscale.WIRect1[1],&Cscale.WIRect1[2],&Cscale.WIRect1[3]
147               ,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
148       break;
149     default :
150       axesplot(strflag,psubwin);
151       break;
152     }
153
154   C2F(dr)("xset","line style",xz,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
155   C2F(dr)("xset","color",xz+1,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
156 }
157
158 /* Only paint the area of the axes */
159 /* ans does not draw any graduations or ticks, lines... */
160 void DrawAxesBackground( void )
161
162         static sciPointObj * psubwin;
163   /* using foreground to draw axis */
164   integer verbose=0,narg,xz[10],fg,i,ixbox[5],iybox[5],p=5,n=1,color,color_kp; 
165  /*  int isoflag = -1; */
166   C2F(dr)("xget","foreground",&verbose,&fg,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
167   C2F(dr)("xget","line style",&verbose,xz,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
168   C2F(dr)("xset","line style",(i=1,&i),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
169   C2F(dr)("xget","color",&verbose,xz+1,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
170   C2F(dr)("xset","color",&fg,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
171
172   psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
173     
174   /* F.Leray test on color here*/
175   color=sciGetBackground(psubwin);
176   
177   ixbox[0]=ixbox[4]=Cscale.WIRect1[0];iybox[0]=iybox[4]=Cscale.WIRect1[1];
178   ixbox[1]=ixbox[0];iybox[1]=Cscale.WIRect1[1]+Cscale.WIRect1[3];
179   ixbox[2]=Cscale.WIRect1[0]+Cscale.WIRect1[2];iybox[2]=iybox[1];
180   ixbox[3]=ixbox[2];iybox[3]=iybox[0]; 
181   C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
182   C2F(dr)("xset","pattern",&color,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
183   C2F(dr)("xarea", "v", &p, ixbox, iybox, &n, PI0, PI0, PD0, PD0, PD0, PD0, 5L,0L);
184   C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);          
185
186   C2F(dr)("xset","line style",xz,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
187   C2F(dr)("xset","color",xz+1,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
188
189
190 }
191
192 /*--------------------------------------------------------------
193  *  aplot: used to draw a box + x and y ticks and scales 
194  *  xmin,ymin,xmax,ymax : are the boundary values
195  *  xnax and ynax gives the ticks numbers ex: nax=[3,7];
196  *  will give 8 big ticks (7 intervals) with numbers and 
197  *  each big interval will be divided in 3 small intervals.
198  *----------------------------------------------------------------*/
199
200 static void aplotv2(char *strflag)
201 {
202   char dir = 'l';
203   int nx,ny;
204   int fontsize=-1,textcolor=-1,ticscolor=-1 ; /*==> use default values  */
205   int fontstyle= 0; 
206   int seg =0;
207   double x[4],y[4],x1,y1_;
208   char xstr,ystr;  
209   char dirx = 'd';
210   int i;
211   sciSubWindow * ppSubWin = NULL ;
212   static sciPointObj * psubwin;
213   char c = (strlen(strflag) >= 3) ? strflag[2] : '1';
214   x[0] = Cscale.frect[0]; x[1] = Cscale.frect[2] ; x[2]=Cscale.Waaint1[1];
215   y[0]=  Cscale.frect[1]; y[1] = Cscale.frect[3] ; y[2]=Cscale.Waaint1[3]; 
216
217   /* Comments on the x and y arrays:
218    x = [xmin,xmax,nb_subtics_on_x_axis]
219    y = [ymin,ymax,nb_subtics_on_y_axis]
220   */
221
222   /** Cscale.frect[4]= xmin ymin xmax ymax **/ 
223
224   
225
226
227   /* initialize only there since in old style no subwin */
228   ppSubWin = pSUBWIN_FEATURE(psubwin) ;
229   Cscale.xtics[2] = ppSubWin->axes.xlim[2];
230   Cscale.ytics[2] = ppSubWin->axes.ylim[2]; 
231
232   /* Remis F.Leray 06.05.04 */
233   for(i=0 ; i<4 ; i++ )
234     Cscale.frect[i]=  ppSubWin->FRect[i] ;
235
236   Cscale.xtics[1] = (Cscale.frect[2] / (exp10( Cscale.xtics[2]))) ; 
237   Cscale.xtics[0] = (Cscale.frect[0]  / (exp10( Cscale.xtics[2]))) ;
238   Cscale.xtics[3] = inint(Cscale.xtics[1]-Cscale.xtics[0]);
239   Cscale.ytics[1] = (Cscale.frect[3] / (exp10( Cscale.ytics[2]))) ; 
240   Cscale.ytics[0] = (Cscale.frect[1]  / (exp10( Cscale.ytics[2]))) ;
241   Cscale.ytics[3] = inint(Cscale.ytics[1]-Cscale.ytics[0]);
242
243
244   switch ( c ) 
245     { 
246     case '3' : /* right axis */ 
247       x1 = x[1]; y1_ = y[0]; dir = 'r'; 
248       break;
249     case '4' : /* centred axis */
250       seg=1;
251       x1 = (x[0]+x[1])/2.0;y1_=(y[0]+y[1])/2.0; 
252       break ;
253     case '5': /* centred at (0,0) */
254       seg=1;
255       x1 = y1_ = 0.0; 
256       break;
257     case '1' : /* left axis */
258     default : 
259       x1 = x[0]; y1_ = y[0];   
260       break;
261     } 
262    
263   if ( c != '4' )
264     {  
265       xstr = ppSubWin->axes.xdir;
266       switch (xstr) 
267         {
268         case 'u':  
269           y1_ = y[1];
270           dirx='u';   
271           break;
272         case 'c':  
273           y1_=(y[0]>0.0) ? y[0]: 0.0;
274           y1_=(y[1]<0.0) ? y[0]: y1_; 
275           seg =1; 
276           dirx ='d';                           
277           break;
278         default :  
279           y1_= y[0];;
280           dirx ='d'; 
281           break;
282         }
283       ystr = ppSubWin->axes.ydir;
284       switch (ystr) 
285         {
286         case 'r': 
287           x1=x[1];
288           dir='r';    
289           break;
290         case 'c': 
291           x1=(x[0]>0.0) ? x[0]: 0.0;
292           x1=(x[1]<0.0) ? x[0]: x1; 
293           seg =1; 
294           dir ='l';                              
295           break; 
296         default : 
297           x1= x[0];
298           dir ='l';  
299           break;
300         }
301     }
302   if ( c != '4' && c != '5' ) {
303     if ( ppSubWin->axes.rect == BT_OFF || ppSubWin->axes.rect == BT_HIDDEN_AXIS )
304     {
305       seg=1; /* seg=1 means not to draw a rectangle (cases wherexy-axis is centered in the middle of the frame or in (0,0))*/
306     }
307     else
308     {
309       /** frame rectangle **/
310       C2F(dr)("xrect","v",&Cscale.WIRect1[0],&Cscale.WIRect1[1],&Cscale.WIRect1[2],&Cscale.WIRect1[3], 
311               PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
312     }
313   }
314
315   Cscale.Waaint1[0]= ppSubWin->axes.subint[0]+1;
316   Cscale.Waaint1[1]= (integer) (ppSubWin->axes.xlim[3]); /*SS 02/01/03 */ /* Give the number of intervals on x*/
317   Cscale.Waaint1[2]= ppSubWin->axes.subint[1]+1; 
318   Cscale.Waaint1[3]= (integer) (ppSubWin->axes.ylim[3]);/*SS 02/01/03 */  /* Give the number of intervals on y*/
319
320   /* Above: Number of tics on x-axis: Cscale.Waaint1[0]*/
321   /*        Number of tics on y-axis: Cscale.Waaint1[2]*/
322
323   /* Above: Number of subtics on x-axis: Cscale.Waaint1[1]*/
324   /*        Number of subtics on y-axis: Cscale.Waaint1[3]*/
325
326   ticscolor = ppSubWin->axes.ticscolor;
327   textcolor=sciGetFontForeground(psubwin);
328   fontsize=sciGetFontDeciWidth(psubwin)/100;
329   /* F.Leray 08.04.04 New data for Axes Font*/
330   fontstyle=sciGetFontStyle(psubwin);
331
332  
333   /** x-axis **/
334   ny=1,nx=3;
335   Sci_Axis(dirx,'r',x,&nx,&y1_,&ny,NULL,Cscale.Waaint1[0],NULL,fontsize,textcolor,fontstyle,ticscolor,Cscale.logflag[0],seg,0);
336   /** y-axis **/
337   ny=3,nx=1;
338   Sci_Axis(dir,'r',&x1,&nx,y,&ny,NULL,Cscale.Waaint1[2],NULL,fontsize,textcolor,fontstyle,ticscolor,Cscale.logflag[1],seg,0);
339 }
340
341 static void aplotv1(strflag)
342      char *strflag;
343 {
344   char dir = 'l';
345   char c = (strlen(strflag) >= 3) ? strflag[2] : '1';
346   int nx,ny,seg=0,i;
347   int fontsize = -1 ,textcolor = -1 ,ticscolor = -1 ; /* default values */
348   int fontstyle= 0;
349   double  x1,y1_;
350   char xstr,ystr; 
351   char dirx = 'd';
352   double CSxtics[4], CSytics[4];
353   sciSubWindow * ppSubWin = NULL ;
354   static sciPointObj * psubwin;
355   seg=0; 
356   
357   switch ( c ) 
358     { 
359     case '3' : /* right axis */
360       x1= Cscale.xtics[1]*exp10(Cscale.xtics[2]);
361       y1_= Cscale.ytics[0]*exp10(Cscale.ytics[2]);
362       dir = 'r';
363       break;
364     case '4' : /* centred axis */
365       seg=1;
366       x1= (Cscale.xtics[0]+Cscale.xtics[1])*exp10(Cscale.xtics[2])/2.0;
367       y1_= (Cscale.ytics[0]+Cscale.xtics[1])*exp10(Cscale.ytics[2])/2.0;
368       break ;
369     case '5': /* centred at (0,0) */
370       seg=1;
371       x1 = y1_ = 0.0; 
372       break;
373     case '1' : /* left axis */
374     default :  
375       x1= Cscale.xtics[0]*exp10(Cscale.xtics[2]);
376       y1_= Cscale.ytics[0]*exp10(Cscale.ytics[2]);
377       break;
378     }
379        
380   if ( c != '4' )
381     {  
382       xstr = ppSubWin->axes.xdir;
383       switch (xstr) 
384         {
385         case 'u':  
386           y1_=Cscale.ytics[1]*exp10(Cscale.ytics[2]);
387           dirx='u';   
388           break;
389         case 'c':  
390           y1_=(Cscale.ytics[0]*exp10(Cscale.ytics[2])>0.0)?Cscale.ytics[0]*exp10(Cscale.ytics[2]): 0.0;
391           y1_=(Cscale.ytics[1]*exp10(Cscale.ytics[2])<0.0)?Cscale.ytics[0]*exp10(Cscale.ytics[2]): y1_; 
392           seg =1; 
393           dirx ='d';                           
394           break;
395         default :  
396           y1_= Cscale.ytics[0]*exp10(Cscale.ytics[2]);
397           dirx ='d'; 
398           break;
399         }
400       ystr=pSUBWIN_FEATURE(psubwin)->axes.ydir;
401       switch (ystr) 
402         {
403         case 'r': 
404           x1=Cscale.xtics[1]*exp10(Cscale.xtics[2]);
405           dir='r';    
406           break;
407         case 'c': 
408           x1=(Cscale.xtics[0]*exp10(Cscale.xtics[2])>0.0)?Cscale.xtics[0]*exp10(Cscale.xtics[2]): 0.0;
409           x1=(Cscale.xtics[1]*exp10(Cscale.xtics[2])<0.0)?Cscale.xtics[0]*exp10(Cscale.xtics[2]): x1; 
410           seg =1; 
411           dir ='l';                              
412           break; 
413         default : 
414           x1= Cscale.xtics[0]*exp10(Cscale.xtics[2]);
415           dir ='l';  
416           break;
417         }
418     }
419   
420   if ( c != '4' && c != '5' ) {
421     if ( ppSubWin->axes.rect == BT_OFF || ppSubWin->axes.rect == BT_HIDDEN_AXIS )
422     {
423       seg=1;
424     }
425     else
426     {
427       /** frame rectangle **/
428       C2F(dr)("xrect","v",&Cscale.WIRect1[0],&Cscale.WIRect1[1],&Cscale.WIRect1[2],&Cscale.WIRect1[3], 
429               PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
430     }
431   }
432   ppSubWin = pSUBWIN_FEATURE(psubwin) ;
433   Cscale.Waaint1[0]= ppSubWin->axes.subint[0]+1;
434   Cscale.Waaint1[1]= (integer) (ppSubWin->axes.xlim[3]); /*SS 02/01/03 */
435   Cscale.Waaint1[2]= ppSubWin->axes.subint[1]+1; 
436   Cscale.Waaint1[3]= (integer) (ppSubWin->axes.ylim[3]);/*SS 02/01/03 */
437
438   ticscolor = ppSubWin->axes.ticscolor;
439   textcolor=sciGetFontForeground(psubwin);
440   fontsize=sciGetFontDeciWidth(psubwin)/100;
441   fontstyle=sciGetFontStyle(psubwin);
442  
443   /* Handle CSxtics and CSytics instead of directly overwrite */
444   /* Cscale.xtics and Cscale.ytics */
445
446   for (i=0;i<4;i++) CSxtics[i] = Cscale.xtics[i];
447   for (i=0;i<4;i++) CSytics[i] = Cscale.ytics[i];
448
449
450   /** x-axis **/
451   ny=1,nx=4;
452   Sci_Axis(dirx,'i',CSxtics,&nx,&y1_,&ny,NULL,Cscale.Waaint1[0],
453            NULL,fontsize,textcolor,fontstyle,ticscolor,Cscale.logflag[0],seg,0);
454   
455   /** y-axis **/
456   ny=4,nx=1;
457   Sci_Axis(dir,'i',&x1,&nx,CSytics,&ny,NULL,Cscale.Waaint1[2],
458            NULL,fontsize,textcolor,fontstyle,ticscolor,Cscale.logflag[1],seg,0);
459 }
460
461
462 /*-------------------------------------------------------------
463  * Sci_Axis : 
464  *   Drawing axis 
465  *   pos = 'r' | 'l' | 'u' | 'd' : gives the tics directions 
466  *         'r' and 'l' are used for vertical axis 
467  *         'u' and 'd' for horizontal axis 
468  *   xy_type = 'v' (for vector) or 'r' (for range) 
469  *         'v' means that tics position are given by a vector 
470  *         'r' means that tics position are in a range i.e given by a vector of size 3 
471  *             [min,max,number_of_intervals] 
472  *         'i' means that tics positions are in a range given by four number (integers) 
473  *             [k1,k2,e,number_of intervale] -> [k1*10^e,k2*10^e] 
474  *   x vector of size nx 
475  *   y vector of size ny 
476  *         if pos = 'r' or 'l' then x must be of size 1 
477  *              the size of y i.e ny must be 3 if xy_type == 'r' or 4 if xy_type == 'i'
478  *              str if non null gives the string to be used at ticks marks 
479  *              it must be then of size ny or of size y[3]+1 (if xy_type == 'r') 
480  *              or y[4]+1 (if xy_type == 'i') 
481  *         if pos = 'u' or 'd  ' then y must be of size 1 
482  *              the size of x i.e nx must be 3 if xy_type == 'r' or 4 if xy_type == 'i'
483  *              str if non null gives the string to be used at ticks marks 
484  *              it must be then of size ny or of size y[3]+1 (if xy_type == 'r')
485  *              or y[4]+1 (if xy_type == 'i') 
486  *   str = char *str[] string vector, see above for size constraints 
487  *              Warning str must be null terminated 
488  *   subtics or subints : number of sub intervals 
489  *   format : format for tick marks.
490  *            format is only used if str is NULL
491  *            if format is null a format is computed else format is used 
492  *   fontsize and textcolor : 
493  *            XXXXX : to be done 
494  *   seg_flag : 0 or 1, flag which control the drawing of the segment associated to the axis 
495  *            if 1 the segment is drawn 
496  *-------------------------------------------------------------*/
497
498 void sci_axis(char pos, char xy_type, double *x, int *nx, double *y, int *ny,
499               char *str[], int subtics, char *format, int fontsize, int textcolor, 
500               int fontstyle, int ticscolor, char logflag, int seg_flag)
501 {
502   Sci_Axis(pos,xy_type,x,nx,y,ny,str,subtics,format,fontsize,textcolor,fontstyle,ticscolor,logflag,seg_flag,0);
503 }
504
505 void Sci_Axis(char pos, char xy_type, double *x, int *nx, double *y, int *ny,
506               char *str[], int subtics, char *format, int fontsize, int textcolor, 
507               int fontstyle, int ticscolor, char logflag, int seg_flag, int axisbuild_flag)
508 {
509   int Nx,Ny,j;
510   double angle=0.0,vxx,vxx1;
511   int vx[2],vy[2],xm[2],ym[2];
512   char c_format[5];
513   integer flag=0,xx=0,yy=0,posi[2],rect[4],dash[6],trois=3;/**DJ.Abdemouche 2003**/
514   integer i,barlength;
515   int ns=2,iflag=0;
516   integer fontid[2],fontsize_kp, narg,verbose=0,logrect[4],smallersize,color_kp; 
517   integer pstyle;
518   int x3, y3, xpassed = 0, ypassed = 0; /* for log. case management */
519   /*** 01/07/2002 -> 11.05.04 ***/ /* F.Leray : Re-put the Djalel modif. for a better display 
520                                    using tight_limits='on' and/or isoview='on' */
521   double xmin,xmax,ymin, ymax; 
522   sciPointObj * psubwin = NULL;
523   double pas; /* used for logarithmic grid */
524
525   fontid[0]= fontstyle;
526
527   psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
528
529   C2F(dr)("xget","font",&verbose,fontid,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
530   fontsize_kp = fontid[1] ;
531   if ( fontsize == -1 )
532   {
533     fontid[0]= 0; fontid[1]= 1;  fontsize_kp = fontid[1] ;
534     fontid[0]= fontstyle;
535     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
536   }
537
538   if ( fontsize != -1 ) 
539   {
540     fontid[1] = fontsize ;
541     fontid[0]= fontstyle;
542     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
543   }
544   if ( textcolor != -1 || ticscolor != -1 ) 
545   {
546     C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
547   }
548
549   if (logflag == 'l' )
550   {
551     C2F(dr)("xstringl","10",&xx,&yy,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
552     smallersize=fontid[1]-2;
553     C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
554   }
555
556
557   /* Pb here, dim of x and y can be lesser than 4 (ie in example_eng.tst : nx = 6 and ny = 1) F.Leray 25.02.04
558   x and y are either double x[3] (resp. y[3]) or simply a double !  F.Leray 05.03.04
559   So a test on x[3] (resp. y[3]) is ALWAYS bad!!
560   NO!! It depends on the xy_type as follow (see in aplotv1):*/
561   /*
562   *   xy_type = 'v' (for vector) or 'r' (for range) 
563   *         'v' means that tics position are given by a vector 
564   *         'r' means that tics position are in a range i.e given by a vector of size 3 
565   *             [min,max,number_of_intervals] 
566   *         'i' means that tics positions are in a range given by four number (integers) 
567   *             [k1,k2,e,number_of intervals] -> [k1*10^e,k2*10^e] */
568
569   if(xy_type == 'i')
570   {     /* Adding F.Leray 05.03.04*/
571     /*F.Leray Modification on 09.03.04*/
572     switch ( pos ) {
573       case 'u' : case 'd' :  
574         if(pSUBWIN_FEATURE(psubwin)->logflags[0] == 'n')
575           while (x[3]>10)  x[3]=floor(x[3]/2); 
576         else{
577           if(x[3] > 12){ /* F.Leray arbitrary value=12 for the moment */
578             x3=(int)x[3];     /* if x[3]>12 algo is triggered to search a divisor */
579             for(j=x3-1;j>1;j--)
580             {
581               if(x3%j == 0){
582                 x[3]=j; 
583                 xpassed = 1;
584               }
585             }
586             if(xpassed != 1) { x[3] = 1; }
587           }
588         }
589
590         break;
591       case 'r' : case 'l' :
592         if(pSUBWIN_FEATURE(psubwin)->logflags[1] == 'n')
593           while (y[3]>10)  y[3]=floor(y[3]/2);
594         else{
595           if(y[3] > 12){
596             y3=(int)y[3];
597             for(j=y3-1;j>1;j--)
598               if(y3%j == 0){
599                 y[3]=j;
600                 ypassed = 1;
601               }
602               if(ypassed != 1) y[3] = 1;
603           }
604
605           break;
606         }
607     }
608
609
610   }
611
612
613   /** Real to Pixel values **/
614   switch ( xy_type ) 
615   {
616   case 'v' : Nx= *nx; Ny= *ny; break;
617   case 'r' :
618     switch ( pos ) {
619   case 'u' : case 'd' : Nx = (int) x[2]+1; break;
620   case 'r' : case 'l' : Ny = (int) y[2]+1; break;
621     }
622     break;
623   case 'i' : 
624     switch ( pos ) {
625   case 'u' : case 'd' : Nx = (int) x[3]+1; break; 
626   case 'r' : case 'l' : Ny = (int) y[3]+1; break;
627     }
628     break;
629   default: 
630     sciprint("Sci_Axis: wrong type argument xy_type\r\n");
631   }
632   switch (pos ) 
633   {
634   case 'u' : 
635   case 'd' :
636     /** Horizontal axes **/
637     barlength =  (integer) (Cscale.WIRect1[3]/50.0);
638     /** compute a format **/
639     if (str == NULL && format == NULL )  
640       switch (xy_type ) {
641   case 'v' : ChoixFormatE1(c_format,x,Nx);break;
642   case 'r' : ChoixFormatE (c_format,x[0],x[1],(x[1]-x[0])/x[2]);break;
643   case 'i' : 
644     ChoixFormatE (c_format,
645       (x[0] * exp10(x[2])),
646       (x[1] * exp10(x[2])),
647       ((x[1] * exp10(x[2])) - (x[0] * exp10(x[2])))/x[3]); break; /* Adding F.Leray 06.05.04 */
648     }
649     /** the horizontal segment **/
650
651     vx[0] =  XScale(x_convert(xy_type, x , 0)); /* C EST LA que se calcule les positions initiales et finales (en x et y) de la barre support de l'axe des abscisses */
652     vx[1] =  XScale(x_convert(xy_type, x , Nx-1));
653     vy[0]= vy[1] = ym[0] = YScale(y[0]);
654     if ( seg_flag == 1) 
655     {
656       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
657       C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
658       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
659     }
660     /******* 01/07/2002  -> 11.05.04 **********/
661     psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
662     if ((pSUBWIN_FEATURE (psubwin)->tight_limits == TRUE || pSUBWIN_FEATURE (psubwin)->isoview == TRUE )
663       && axisbuild_flag == 0){{ 
664         xmax=Cscale.frect[2];
665         xmin=Cscale.frect[0];
666
667         if(xy_type == 'i')
668         {
669
670
671           x[1] = floor(  Cscale.xtics[1] );
672           x[0] =  ceil(  Cscale.xtics[0] );
673           x[3]=inint(x[1]-x[0]);
674           while (x[3]>10)  x[3]=floor(x[3]/2);
675           Nx=(int)(x[3]+1);
676
677           /* re-compute a format when tight_limits or isoview == ON */
678           ChoixFormatE (c_format,
679             (x[0] * exp10(x[2])),
680             (x[1] * exp10(x[2])),
681             ((x[1] * exp10(x[2])) - (x[0] * exp10(x[2])))/x[3]); /* Adding F.Leray 15.05.04 */
682         }
683         /* THESE 2 last cases are unreachable because we use the condition : */
684         /* axisbuild_flag == 0 */
685         else if (xy_type == 'r') /* normally unreachable */
686         {
687           sciprint(" Normally, unreachable case \n");
688         }
689         else if(xy_type == 'v') /* normally unreachable */
690         {
691           sciprint(" Normally, unavailable case  AAA \n");
692         }
693     }
694
695
696     pas = ((double) Cscale.WIRect1[2]) / ((double) Cscale.Waaint1[1]);
697
698     /**********************/
699     /** loop on the ticks **/
700     if (Nx==1) break;
701     for (i=0 ; i < Nx ; i++)
702     {  
703       char foo[100];
704       vxx = x_convert(xy_type,x,i);
705       if ( str != NULL)  
706         sprintf(foo,"%s",str[i]);
707       else if ( format == NULL) 
708       {
709         /* defaults format */
710         /*F.Leray 19.05.04 */
711         /* When Sci_Axis is called by aplotv1, format is NULL : it can not be something else...*/
712         /* format can also be NULL if non specified and coming from ConstructAxes method called in Objdrawaxis (see matdes.c) */
713         sprintf(foo,c_format,vxx);
714       }
715       else {
716         sprintf(foo,format,vxx);
717       }
718
719
720       C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
721
722       /* tick is computed in vx,vy and string is displayed at posi[0],posi[1] position */
723
724       vx[0] = vx[1] = xm[0] =  XScale(vxx);
725       posi[0] = inint( xm[0] -rect[2]/2.0);
726
727       if ( pos == 'd' ) 
728       {
729         posi[1]=inint( ym[0] + 1.2*barlength + rect[3]);
730         vy[0]= ym[0];vy[1]= ym[0] + barlength ;
731       }
732       else 
733       { 
734         posi[1]=inint( ym[0] - 1.2*barlength);
735         vy[0]= ym[0];vy[1]= ym[0] - barlength;
736       }
737       if ( textcolor != -1 ) C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
738       C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&angle, PD0,PD0,PD0,0L,0L);
739       if ( logflag == 'l' )
740       {
741         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
742         C2F(dr)("xstring","10",(posi[0] -= logrect[2],&posi[0]),
743           (posi[1] += logrect[3],&posi[1]),
744           PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
745         C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
746       }
747       if ( textcolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
748
749       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
750       C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
751
752       /*** MAJ Djalel.A 21/01/2003 ***/ 
753       if (pSUBWIN_FEATURE (psubwin)->grid[0] > -1) 
754       { /**DJ.Abdemouche 2003**/
755         if(pSUBWIN_FEATURE (psubwin)->logflags[0] == 'l')
756         {
757           if ((vx[0] != Cscale.WIRect1[0]) && (vx[0] != (Cscale.WIRect1[0]+ Cscale.WIRect1[2])))
758           {
759             pstyle=pSUBWIN_FEATURE (psubwin)->grid[0] ;
760             C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
761             C2F (dr) ("xset", "line style",&trois,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
762             vy[0]=Cscale.WIRect1[1];
763             vy[1]=Cscale.WIRect1[1]+Cscale.WIRect1[3];  
764             C2F(dr)("xsegs","v", vx, vy, &ns,&pstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
765           }
766
767           if(i < Nx -1 )
768           {
769             int jinit=1;
770             /* In case there is a log. scale, add. sub-grid taking account of this special scale F.Leray 07.05.04 */
771             pstyle=pSUBWIN_FEATURE (psubwin)->grid[0] ;
772             C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
773             C2F (dr) ("xset", "line style",&trois,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
774             vy[0]=Cscale.WIRect1[1];
775             vy[1]=Cscale.WIRect1[1]+Cscale.WIRect1[3];
776
777             if ( i== 0 ) jinit=2; /* no grid on plot boundary */
778             for (j= jinit; j < 10 ; j++)
779             {
780               vx[0]=vx[1]= Cscale.WIRect1[0] + inint( ((double) i)*pas)+ inint(log10(((double)j))*pas);
781               C2F(dr)("xsegs","v", vx, vy, &ns,&pstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
782             }
783             C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
784           }
785         }
786         else if(pSUBWIN_FEATURE (psubwin)->logflags[0] == 'n')
787         {
788           if ((vx[0] != Cscale.WIRect1[0]) && (vx[0] != (Cscale.WIRect1[0]+ Cscale.WIRect1[2])))
789           {
790             pstyle=pSUBWIN_FEATURE (psubwin)->grid[0] ;
791             C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
792             C2F (dr) ("xset", "line style",&trois,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
793             vy[0]=Cscale.WIRect1[1];
794             vy[1]=Cscale.WIRect1[1]+Cscale.WIRect1[3];  
795             C2F(dr)("xsegs","v", vx, vy, &ns,&pstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
796             C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
797           }
798         }
799       }
800       /***/
801       /* subtics */
802       if ( i < Nx-1 ) 
803       {
804         double dx ; 
805         vxx1= x_convert(xy_type,x,i+1);
806         dx = (vxx1-vxx)/subtics;
807         for ( j = 1 ; j < subtics; j++){ 
808           vx[0] = vx[1] = XScale(vxx+dx*j);
809           if ( pos == 'd' ) 
810           { vy[0]= ym[0];vy[1]=  (integer) (ym[0] + barlength/2.0) ; }
811           else 
812           { vy[0]= ym[0];vy[1]=  (integer) (ym[0] - barlength/2.0) ; }
813           C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
814         }
815       } 
816       /***   01/07/2002  -> 11.05.04 ****/
817       psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
818       if ( (pSUBWIN_FEATURE (psubwin)->tight_limits || pSUBWIN_FEATURE (psubwin)->isoview )
819         && axisbuild_flag == 0)
820       {  
821         if ( i == 0 ) 
822         {
823           double dx ; 
824           vxx1= x_convert(xy_type,x,i+1);
825           dx = (vxx1-vxx)/subtics;
826           for ( j = 1 ; j < subtics; j++) {  
827             if ( vxx-dx*j > xmin){
828               vx[0] = vx[1] = XScale(vxx-dx*j);
829               if ( pos == 'd' ) 
830               { vy[0]= ym[0];vy[1]=(int) (ym[0] + barlength/2.0) ; }
831               else 
832               { vy[0]= ym[0];vy[1]= (int)(ym[0] - barlength/2.0); }
833               C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
834             }}
835         } 
836         if ( i == Nx-1 ) 
837         {
838           double dx ; 
839           vxx1= x_convert(xy_type,x,i+1);
840           dx = (vxx1-vxx)/subtics;
841           for ( j = 1 ; j < subtics; j++) {  
842             if ( vxx+dx*j < xmax){
843               vx[0] = vx[1] = XScale(vxx+dx*j);
844               if ( pos == 'd' ) 
845               { vy[0]= ym[0];vy[1]= (int)(ym[0] + barlength/2.0) ; }
846               else 
847               { vy[0]= ym[0];vy[1]= (int)(ym[0] - barlength/2.0); }
848               C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
849             }}
850         } 
851       }
852       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
853     }
854     break;
855   case 'r' : 
856   case 'l' :
857
858     /** Vertical axes **/
859     barlength =  (integer) (Cscale.WIRect1[2]/75.0);
860     if (str == NULL &&  format == NULL )  
861       switch (xy_type ) {
862   case 'v' : ChoixFormatE1(c_format,y,Ny);break;
863   case 'r' : ChoixFormatE(c_format,y[0],y[1],(y[1]-y[0])/y[2]);break;
864   case 'i' : 
865     ChoixFormatE (c_format,
866       (y[0] * exp10(y[2])),
867       (y[1] * exp10(y[2])),
868       ((y[1] * exp10(y[2])) - (y[0] * exp10(y[2])))/y[3]); break; /* Adding F.Leray 06.05.04 */
869     }
870     /** the vertical segment **/
871     vy[0] =  YScale(y_convert(xy_type, y , 0));
872     vy[1] =  YScale(y_convert(xy_type, y , Ny-1));
873     vx[0]= vx[1] = xm[0]= XScale(x[0]);
874     if ( seg_flag == 1) 
875     {
876       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
877       C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
878       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
879     }
880
881     /***   01/07/2002 -> 11 and 12.05.04 ****/
882     psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
883     if ((pSUBWIN_FEATURE (psubwin)->tight_limits == TRUE || pSUBWIN_FEATURE (psubwin)->isoview == TRUE )
884       && axisbuild_flag == 0){  
885         ymax=Cscale.frect[3];
886         ymin=Cscale.frect[1];
887
888         if(xy_type == 'i')
889         {
890           /*   y[1] = floor(Cscale.frect[3] / (exp10( y[2]))) ;   */
891           /*        y[0] =  ceil(Cscale.frect[1]  / (exp10( y[2]))) ;  */
892
893           y[1] = floor( Cscale.ytics[1] );
894           y[0] =  ceil( Cscale.ytics[0] );
895
896           y[3]=inint(y[1]-y[0]);
897           while (y[3]>10)  y[3]=floor(y[3]/2);
898           Ny=(int)(y[3]+1);
899
900           /* re-compute a format when tight_limits or isoview == ON */
901           ChoixFormatE (c_format,
902             (y[0] * exp10(y[2])),
903             (y[1] * exp10(y[2])),
904             ((y[1] * exp10(y[2])) - (y[0] * exp10(y[2])))/y[3]);
905         }
906         /* THESE 2 last cases are unreachable because we use the condition : */
907         /* axisbuild_flag == 0 */
908         else if (xy_type == 'r') /* normally unreachable */
909         {
910           sciprint(" Normally, unreachable case \n");
911         }
912         else if(xy_type == 'v')  /* normally unreachable */
913         {
914           sciprint(" Normally, unreachable case \n");
915         }
916     }
917
918
919
920     pas = ((double) Cscale.WIRect1[3]) / ((double) Cscale.Waaint1[3]);
921     /** loop on the ticks **/
922     if (Ny==1) break; /*D.Abdemouche 16/12/2003*/
923     for (i=0 ; i < Ny ; i++)
924     { 
925       char foo[100];
926       vxx = y_convert(xy_type,y,i);
927       if ( str != NULL)  
928         sprintf(foo,"%s",str[i]);
929       else if ( format == NULL)
930       { 
931         /* defaults format */
932         /*F.Leray 19.05.04 */
933         /* When Sci_Axis is called by aplotv1, format is NULL : it can not be something else...*/
934         /* format can also be NULL if non specified and coming from ConstructAxes method called in Objdrawaxis (see matdes.c) */
935         sprintf(foo,c_format,vxx);
936       }
937       else{ 
938         sprintf(foo,format,vxx);
939       }
940
941
942       C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
943
944       /* tick is computed in vx,vy and string is displayed at posi[0],posi[1] position */
945
946       vy[0]= vy[1] = ym[0] = YScale(vxx);
947       posi[1]=inint( ym[0] +rect[3]/2.0);
948       if ( pos == 'r' ) 
949       {
950         posi[0]=inint( xm[0] + 1.2*barlength);
951         vx[0]= xm[0];vx[1]= xm[0]+barlength;
952       }
953       else 
954       { 
955         posi[0]=inint(xm[0] - 1.2*barlength - rect[2]);
956         vx[0]= xm[0];vx[1]= xm[0] - barlength;
957       }
958       if ( textcolor != -1 ) C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
959       C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&angle, PD0,PD0,PD0,0L,0L);
960       if ( logflag == 'l' )
961       {
962         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
963         C2F(dr)("xstring","10",(posi[0] -= logrect[2],&posi[0]),
964           (posi[1] += logrect[3],&posi[1]),
965           PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
966         C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
967       }
968       if ( textcolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
969
970       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
971       C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
972       /*** MAJ Djalel.A 21/01/2003 ***/ 
973       if (pSUBWIN_FEATURE (psubwin)->grid[1] > -1 )
974       { /**DJ.Abdemouche 2003**/
975         if(pSUBWIN_FEATURE (psubwin)->logflags[1] == 'l')
976         {
977           if ((vy[0] != Cscale.WIRect1[1]) && (vy[0] != (Cscale.WIRect1[1]+ Cscale.WIRect1[3])))
978           {
979             pstyle=pSUBWIN_FEATURE (psubwin)->grid[1] ;
980             vx[0]=Cscale.WIRect1[0];
981             vx[1]=Cscale.WIRect1[0]+Cscale.WIRect1[2];  
982             C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
983             C2F (dr) ("xset", "line style",&trois,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
984             C2F(dr)("xsegs","v", vx, vy, &ns,&pstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
985           }
986
987           if(i < Ny -1 ){
988             int jinit=1;
989             /* In case there is a log. scale, add. sub-grid taking account of this special scale F.Leray 07.05.04 */
990             pstyle=pSUBWIN_FEATURE (psubwin)->grid[1] ;
991             C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
992             C2F (dr) ("xset", "line style",&trois,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
993             vx[0]=Cscale.WIRect1[0];
994             vx[1]=Cscale.WIRect1[0]+Cscale.WIRect1[2]; 
995
996             if ( i== Cscale.Waaint1[3]-1 ) jinit=2; /* no grid on plot boundary */
997             for (j= jinit; j < 10 ; j++)
998             {
999               vy[0]=vy[1]= Cscale.WIRect1[1] + inint( ((double) i+1)*pas)- inint(log10(((double)j))*pas);
1000               C2F(dr)("xsegs","v", vx, vy, &ns,&pstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1001             }
1002             C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1003           }
1004         }
1005         else  if(pSUBWIN_FEATURE (psubwin)->logflags[1] == 'n'){
1006           if ((vy[0] != Cscale.WIRect1[1]) && (vy[0] != (Cscale.WIRect1[1]+ Cscale.WIRect1[3])))
1007           {
1008             pstyle=pSUBWIN_FEATURE (psubwin)->grid[1] ;
1009             vx[0]=Cscale.WIRect1[0];
1010             vx[1]=Cscale.WIRect1[0]+Cscale.WIRect1[2];  
1011             C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1012             C2F (dr) ("xset", "line style",&trois,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1013             C2F(dr)("xsegs","v", vx, vy, &ns,&pstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1014             C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1015           }
1016         }
1017       }
1018       /* subtics */
1019       if ( i < Ny-1 ) 
1020       {
1021         double dy ; 
1022         vxx1= y_convert(xy_type,y,i+1);
1023         dy = (vxx1-vxx)/subtics;
1024         for ( j = 1 ; j < subtics; j++) 
1025         {
1026           vy[0] = vy[1] = YScale(vxx+dy*j);
1027           if ( pos == 'r' ) 
1028           { vx[0]= xm[0];vx[1]= (integer) (xm[0] + barlength/2.0) ; }
1029           else 
1030           { vx[0]= xm[0];vx[1]= (integer) (xm[0] - barlength/2.0) ; }
1031           C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1032         }
1033       }
1034       /***   01/07/2002 -> 12.05.04 ****/
1035       psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
1036       if ( (pSUBWIN_FEATURE (psubwin)->tight_limits == TRUE || pSUBWIN_FEATURE (psubwin)->isoview == TRUE )
1037         && axisbuild_flag == 0){
1038           if ( i == 0 )  
1039           {
1040             double dy ; 
1041             vxx1= y_convert(xy_type,y,i+1);
1042             dy = (vxx1-vxx)/subtics;
1043             for ( j = 1 ; j < subtics; j++) {  
1044               if ( vxx-dy*j > ymin){
1045                 vy[0] = vy[1] = YScale(vxx-dy*j);
1046                 if ( pos == 'r' ) 
1047                 { vx[0]= xm[0];vx[1]= (int)(xm[0] + barlength/2.0) ; }
1048                 else 
1049                 { vx[0]= xm[0];vx[1]= (int) (xm[0] - barlength/2.0); }
1050                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1051               }}
1052           }
1053           if ( i == Ny-1 )
1054           {
1055             double dy ; 
1056             vxx1= y_convert(xy_type,y,i+1);
1057             dy = (vxx1-vxx)/subtics;
1058             for ( j = 1 ; j < subtics; j++) {  
1059               if ( vxx+dy*j < ymax){
1060                 vy[0] = vy[1] = YScale(vxx+dy*j);
1061                 if ( pos == 'r' ) 
1062                 { vx[0]= xm[0];vx[1]= (int)(xm[0] + barlength/2.0) ; }
1063                 else 
1064                 { vx[0]= xm[0];vx[1]= (int)(xm[0] - barlength/2.0); }
1065                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1066               }}
1067           }  
1068       }
1069       if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1070     }
1071     break;
1072     }
1073     /* reset font to its current size */ 
1074     if ( fontsize != -1 || logflag == 'l' )
1075     {
1076       fontid[1] = fontsize_kp;
1077       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1078     }
1079     /* reset to current color */
1080     if ( textcolor != -1 || ticscolor != -1 ) 
1081     {
1082       C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1083     }
1084
1085   }
1086
1087
1088
1089 /* from double to pixel */ 
1090
1091 static double  x_convert(char xy_type, double *x , int i)
1092 {
1093   switch ( xy_type ) { 
1094   case 'v' :  return x[i];
1095   case 'r' :  return x[0]+i*(x[1]-x[0])/x[2];
1096   case 'i' :  return exp10(x[2])*(x[0] + i*(x[1]-x[0])/x[3]);
1097   }
1098   return 0.0;
1099 }
1100
1101 static double y_convert(char xy_type, double *y , int i)
1102 {
1103   switch ( xy_type ) { 
1104   case 'v' :  return y[i]; 
1105   case 'r' :  return y[0]+i*(y[1]-y[0])/y[2];
1106   case 'i' :  return exp10(y[2])*(y[0] + i*(y[1]-y[0])/y[3]); 
1107   }
1108   return 0.0; 
1109 }
1110
1111
1112
1113 /* Format pour imprimer un nombre de la forme k10^a */
1114
1115 extern void NumberFormat(char *str, integer k, integer a)
1116 {
1117   if ( k==0)
1118     {
1119       sprintf(str,"0");
1120     }
1121   else
1122     {
1123       switch (a)
1124         {
1125         case -1: sprintf(str,"%.1f",(double)k/10.0);break;
1126         case -2: sprintf(str,"%.2f",(double)k/100.0);break;
1127         case 0 : sprintf(str,"%d",(int)k);break;
1128         case 1 : sprintf(str,"%d0",(int)k);break;
1129         case 2 : sprintf(str,"%d00",(int)k);break;
1130         default: sprintf(str,"%de%d",(int)k,(int)a) ;break;
1131
1132         }
1133     }
1134
1135 }
1136
1137
1138 static void axesplot(char * strflag, sciPointObj * psubwin)
1139 {
1140   char dir = 'l';
1141   char c = (strlen(strflag) >= 3) ? strflag[2] : '1';
1142   int seg=0;
1143   int fontsize = -1 ,textcolor = -1 ,ticscolor = -1 ; /* default values */
1144   int fontstyle= 0;
1145   double  x1,y1_;
1146   char xstr,ystr; 
1147   char dirx = 'd';
1148  /*  double CSxtics[4], CSytics[4]; */
1149
1150
1151   int lastxindex = 0, lastyindex = 0;
1152   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
1153
1154   if( ppsubwin->tight_limits == TRUE || ppsubwin->isoview == TRUE)
1155     {
1156       switch ( c )
1157         {
1158         case '3' : /* right axis */
1159           x1= ppsubwin->axes.xlim[1];
1160           y1_= ppsubwin->axes.ylim[0];
1161           dir = 'r';
1162           break;
1163         case '4' : /* centred axis */
1164           seg=1;
1165           x1= (ppsubwin->axes.xlim[0]+ppsubwin->axes.xlim[1])/2.0;
1166           y1_= (ppsubwin->axes.ylim[0]+ppsubwin->axes.ylim[1])/2.0;
1167           break ;
1168         case '5': /* centred at (0,0) */
1169           seg=1;
1170           x1 = y1_ = 0.0;
1171           break;
1172         case '1' : /* left axis */
1173         default :
1174           x1=  ppsubwin->axes.xlim[0];
1175           y1_=  ppsubwin->axes.ylim[1];
1176           break;
1177         }
1178     }
1179   else  /* tight_limits == FALSE */
1180     {
1181       lastxindex = ppsubwin->axes.nxgrads - 1;
1182       lastyindex = ppsubwin->axes.nygrads - 1;
1183      
1184         switch ( c )
1185         {
1186         case '3' : /* right axis */
1187           x1= ppsubwin->axes.xgrads[lastxindex];
1188           y1_= ppsubwin->axes.ygrads[0];
1189           dir = 'r';
1190           break;
1191         case '4' : /* centred axis */
1192           seg=1;
1193           x1= (ppsubwin->axes.xgrads[0]+ppsubwin->axes.xgrads[lastxindex])/2.0;
1194           y1_= (ppsubwin->axes.ygrads[0]+ppsubwin->axes.ygrads[lastyindex])/2.0;
1195           break ;
1196         case '5': /* centred at (0,0) */
1197           seg=1;
1198           x1 = y1_ = 0.0;
1199           break;
1200         case '1' : /* left axis */
1201         default :
1202           x1= ppsubwin->axes.xgrads[0];
1203           y1_= ppsubwin->axes.ygrads[0];
1204         break;
1205         }
1206     }
1207        
1208
1209
1210   if(ppsubwin->tight_limits == TRUE || ppsubwin->isoview == TRUE)
1211     {
1212       if (c != '4')
1213         {
1214           xstr=ppsubwin->axes.xdir;
1215           if(ppsubwin->axes.reverse[1] == FALSE)
1216             { /* y reverse axis : NO */
1217               switch (xstr)
1218                 {
1219                 case 'u':
1220                   y1_= ppsubwin->axes.ylim[1];
1221                   dirx='u';
1222                   break;
1223                 case 'c':
1224                   y1_= (ppsubwin->axes.ylim[0]>0.0)?ppsubwin->axes.ylim[0]:0.0;
1225                   y1_= (ppsubwin->axes.ylim[1]<0.0)?ppsubwin->axes.ylim[0]:y1_;
1226                   seg =1;
1227                   dirx ='d';
1228                   break;
1229                 default :
1230                   y1_= ppsubwin->axes.ylim[0];
1231                   dirx ='d';
1232                   break;
1233                 }
1234             }
1235           else
1236             { /* y reverse axis : YES */
1237               switch (xstr)
1238                 {
1239                 case 'u':
1240                   y1_= ppsubwin->axes.ylim[0];
1241                   dirx='u';
1242                   break;
1243                 case 'c':
1244                   y1_= (ppsubwin->axes.ylim[0]>0.0)?ppsubwin->axes.ylim[0]:0.0;
1245                   y1_= (ppsubwin->axes.ylim[1]<0.0)?ppsubwin->axes.ylim[0]:y1_;
1246                   seg =1;
1247                   dirx ='d';
1248                   break;
1249                 default :
1250                   y1_= ppsubwin->axes.ylim[1];
1251                   dirx ='d';
1252                   break;
1253                 }
1254             }
1255
1256           ystr=ppsubwin->axes.ydir;
1257           if(ppsubwin->axes.reverse[0] == FALSE)
1258             { /* x reverse axis : NO */
1259               switch (ystr)
1260                 {
1261                 case 'r':
1262                   x1= ppsubwin->axes.xlim[1];
1263                   dir='r';
1264                   break;
1265                 case 'c':
1266                   x1=(ppsubwin->axes.xlim[0]>0.0)?ppsubwin->axes.xlim[0]:0.0;
1267                   x1=(ppsubwin->axes.xlim[1]<0.0)?ppsubwin->axes.xlim[0]:x1;
1268                   seg =1;
1269                   dir ='l';
1270                   break;
1271                 default :
1272                   x1= ppsubwin->axes.xlim[0];
1273                   dir ='l';
1274                   break;
1275                 }
1276             }
1277           else
1278             { /* x reverse axis : YES */
1279               switch (ystr)
1280                 {
1281                 case 'r':
1282                   x1= ppsubwin->axes.xlim[0];
1283                   dir='r';
1284                   break;
1285                 case 'c':
1286                   x1=(ppsubwin->axes.xlim[0]>0.0)?ppsubwin->axes.xlim[0]:0.0;
1287                   x1=(ppsubwin->axes.xlim[1]<0.0)?ppsubwin->axes.xlim[0]:x1;
1288                   seg =1;
1289                   dir ='l';
1290                   break;
1291                 default :
1292                   x1= ppsubwin->axes.xlim[1];
1293                   dir ='l';
1294                   break;
1295                 }
1296             }
1297         }
1298     }
1299   else  /* tight_limits == FALSE */
1300     {
1301       lastxindex = ppsubwin->axes.nxgrads - 1;
1302       lastyindex = ppsubwin->axes.nygrads - 1;
1303       
1304       if (c != '4')
1305         {
1306           xstr=ppsubwin->axes.xdir;
1307           if(ppsubwin->axes.reverse[1] == FALSE)
1308             { /* y reverse axis : NO */
1309               switch (xstr)
1310                 {
1311                 case 'u':
1312                   y1_=ppsubwin->axes.ygrads[lastyindex];
1313                   dirx='u';
1314                   break;
1315                 case 'c':
1316                   y1_=(ppsubwin->axes.ygrads[0]>0.0)?ppsubwin->axes.ygrads[0]:0.0;
1317                   y1_=(ppsubwin->axes.ygrads[lastyindex]<0.0)?ppsubwin->axes.ygrads[0]:y1_;
1318                   seg =1;
1319                   dirx ='d';
1320               break;
1321                 default :
1322                   y1_= ppsubwin->axes.ygrads[0];
1323                   dirx ='d';
1324                   break;
1325                 }
1326             }
1327           else
1328             { /* y reverse axis : YES */
1329               switch (xstr)
1330                 {
1331                 case 'u':
1332                   y1_=ppsubwin->axes.ygrads[0];
1333                   dirx='u';
1334                   break;
1335                 case 'c':
1336                   y1_=(ppsubwin->axes.ygrads[0]>0.0)?ppsubwin->axes.ygrads[0]:0.0;
1337                   y1_=(ppsubwin->axes.ygrads[lastyindex]<0.0)?ppsubwin->axes.ygrads[0]:y1_;
1338                   seg =1;
1339                   dirx ='d';
1340                   break;
1341                 default :
1342                   y1_= ppsubwin->axes.ygrads[lastyindex];
1343                   dirx ='d';
1344                   break;
1345                 }
1346             }
1347           
1348           ystr=ppsubwin->axes.ydir;
1349           if(ppsubwin->axes.reverse[0] == FALSE)
1350             { /* x reverse axis : NO */
1351               switch (ystr)
1352                 {
1353                 case 'r':
1354                   x1= ppsubwin->axes.xgrads[lastxindex];
1355                   dir='r';
1356                   break;
1357                 case 'c':
1358                   x1=(ppsubwin->axes.xgrads[0]>0.0)?ppsubwin->axes.xgrads[0]:0.0;
1359                   x1=(ppsubwin->axes.xgrads[lastxindex]<0.0)?ppsubwin->axes.xgrads[0]:x1;
1360                   seg =1;
1361                   dir ='l';
1362                   break;
1363                 default :
1364                   x1= ppsubwin->axes.xgrads[0];
1365                   dir ='l';
1366                   break;
1367                 }
1368             }
1369           else
1370             { /* x reverse axis : YES */
1371               switch (ystr)
1372                 {
1373                 case 'r':
1374                   x1= ppsubwin->axes.xgrads[0];
1375                   dir='r';
1376                   break;
1377                 case 'c':
1378                   x1=(ppsubwin->axes.xgrads[0]>0.0)?ppsubwin->axes.xgrads[0]:0.0;
1379                   x1=(ppsubwin->axes.xgrads[lastxindex]<0.0)?ppsubwin->axes.xgrads[0]:x1;
1380                   seg =1;
1381                   dir ='l';
1382                   break;
1383                 default :
1384                   x1= ppsubwin->axes.xgrads[lastxindex];
1385                   dir ='l';
1386                   break;
1387                 }
1388             }
1389         }
1390     }
1391   
1392   ticscolor=sciGetForeground(psubwin);
1393   textcolor=sciGetFontForeground(psubwin);
1394   fontsize=sciGetFontDeciWidth(psubwin)/100;
1395   fontstyle=sciGetFontStyle(psubwin);
1396  
1397   /** x-axis **/
1398   SciAxisNew(dirx,psubwin,y1_,fontsize,fontstyle,textcolor,ticscolor,seg);
1399   
1400   /** y-axis **/
1401   SciAxisNew(dir,psubwin,x1,fontsize,fontstyle,textcolor,ticscolor,seg);
1402
1403   /* Once the 2 axes are plotted, we can draw :
1404      1. the axes lines
1405      2. the box lines over if necessary (i.e. seg == 1) */
1406   if ( ppsubwin->axes.axes_visible[0] )
1407   {
1408     SciDrawLines(dirx,psubwin,y1_,textcolor,ticscolor);
1409   }
1410   SciDrawLines(dir, psubwin,x1,textcolor,ticscolor);
1411   
1412   
1413   if ( c != '4' && c != '5' )
1414   {
1415     if ( sciGetBoxType(psubwin) == BT_OFF || sciGetBoxType(psubwin) == BT_HIDDEN_AXIS )
1416     {
1417       seg = 1 ;
1418     }
1419     else
1420     {
1421       /** frame rectangle **/
1422       C2F(dr)("xrect","v",&Cscale.WIRect1[0],&Cscale.WIRect1[1],&Cscale.WIRect1[2],&Cscale.WIRect1[3], 
1423               PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1424     }
1425   }
1426 }
1427
1428
1429 /****************************************************************************/
1430 /********************************** COMMON to X and Y ***********************/
1431 /****************************************************************************/
1432
1433
1434 int SciDrawLines(char pos, sciPointObj * psubwin, double xy, int textcolor,int ticscolor)
1435 {
1436   double xminval, yminval, xmaxval, ymaxval;
1437   int verbose = 0, narg, color_kp;
1438
1439   if ( textcolor != -1 || ticscolor != -1 ) 
1440     {
1441       C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1442     }
1443   
1444   FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval);
1445
1446   if(pos=='u' || pos=='d'){ /* X */
1447     if( pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] == TRUE )
1448       XDrawAxisLine(xminval,xmaxval,xy,ticscolor,color_kp);
1449   } else if(pos=='l' || pos=='r'){ /* Y */
1450     if(pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] == TRUE)
1451       YDrawAxisLine(yminval,ymaxval,xy,ticscolor,color_kp);
1452   }
1453   
1454   
1455   
1456   
1457   return 0;
1458 }
1459
1460 /****************************************************************************/
1461 /********************************** X ***************************************/
1462 /****************************************************************************/
1463
1464
1465 static int DrawXSubTics(char pos, sciPointObj * psubwin, double xy,int ticscolor,int color_kp)
1466 {
1467   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
1468   double xminval,yminval,xmaxval,ymaxval;
1469    
1470   int vx[2],vy[2],ym[2];
1471   int barlength = 0;
1472   int ns=2,iflag=0;
1473   
1474   int nbtics = 0,i,j;
1475   int nbsubtics = ppsubwin->axes.nbsubtics[0];
1476   char logflag = ppsubwin->logflags[0];
1477   
1478   double *grads = (double *) NULL;
1479
1480   ym[0] = YScale(xy);
1481    
1482   barlength =  (integer) (Cscale.WIRect1[3]/50.0);
1483   
1484   FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval); /* here i only need x data (ymin ymax are computed but not used after) */
1485  
1486
1487   if(ppsubwin->axes.auto_ticks[0] == FALSE){
1488     grads =  ppsubwin->axes.u_xgrads;
1489     nbtics = ppsubwin->axes.u_nxgrads;
1490   }
1491   else{
1492     grads =  ppsubwin->axes.xgrads;
1493     nbtics = ppsubwin->axes.nxgrads;
1494   }
1495   
1496   
1497   if(logflag =='l')
1498     {
1499       double tmp[2];
1500       double pas=0;
1501       double * tmp_log_grads = (double *) NULL;
1502       
1503       for(i=0;i<nbtics-1;i++)
1504         {
1505           int k;
1506           tmp[0] = exp10(grads[i]);
1507           tmp[1] = exp10(grads[i+1]);
1508           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1509           
1510           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1511             sciprint("Error allocating tmp_log_grads\n");
1512             return -1;
1513           }
1514           
1515           for(k=0;k<nbsubtics;k++) tmp_log_grads[k] = log10(tmp[0]+(k)*pas);
1516           
1517           for(j=0;j<nbsubtics;j++)
1518             {
1519               double val = tmp_log_grads[j];
1520               /* the length of the ticks in pixels */
1521               /* minimum 2 pixels */
1522               /* use of integer division for speed */
1523               int ticksLength =  Max( ( 3 * barlength ) / 4,  2 ) ;
1524               vx[0] = vx[1] = XScale(val);
1525               
1526               if(val<xminval || val>xmaxval) continue;     
1527               
1528               if ( pos == 'd' ) 
1529               { 
1530                 vy[0] = ym[0] ;
1531                 vy[1] = ym[0] + ticksLength ; 
1532               }
1533               else 
1534               { 
1535                 vy[0] = ym[0] ; 
1536                 vy[1] = ym[0] - ticksLength ;
1537               }
1538               if ( ppsubwin->axes.axes_visible[0] )
1539               {
1540                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1541               }
1542             }
1543           
1544           FREE(tmp_log_grads); tmp_log_grads = NULL;
1545         }
1546     }
1547   else
1548     {
1549       for(i=0;i<nbtics-1;i++)
1550         {
1551           double xtmp = grads[i];
1552           double dx = (grads[i+1]-grads[i]) / nbsubtics;
1553           for( j = 0 ; j < nbsubtics ; j++ )
1554             {
1555               double val = xtmp+dx*j;
1556               /* the length of the ticks in pixels */
1557               /* minimum 2 pixels */
1558               /* use of integer division for speed */
1559               int ticksLength =  Max( ( 3 * barlength ) / 4,  2 ) ;
1560               vx[0] = vx[1] = XScale(val);
1561               
1562               if(val<xminval || val>xmaxval) continue;     
1563               
1564               if ( pos == 'd' ) 
1565               {
1566                 
1567                 vy[0]= ym[0];
1568                 vy[1]= ym[0] + ticksLength ; 
1569               }
1570               else 
1571               { 
1572                 vy[0]= ym[0];
1573                 vy[1]= ym[0] - ticksLength ; 
1574               }
1575               if ( ppsubwin->axes.axes_visible[0] )
1576               {
1577                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1578               }
1579             }
1580         }
1581     }
1582   
1583   return 0;
1584 }
1585
1586
1587 static int DrawXGrid(sciPointObj * psubwin)
1588 {
1589   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
1590   double xminval,yminval,xmaxval,ymaxval;
1591   int verbose=0,narg;
1592
1593   int vx[2],vy[2],ym[2];
1594   int dash[6],lineMode=2;
1595   int ns=2,style=0,iflag=0;
1596   
1597   double * grads = (double *) NULL;
1598   int nbtics = 0,i,j;
1599   int nbsubtics = ppsubwin->axes.nbsubtics[0];
1600   char logflag = ppsubwin->logflags[0];
1601    
1602   FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval);
1603   
1604   
1605   ym[0] = YScale(yminval);
1606   ym[1] = YScale(ymaxval);
1607
1608   if(ppsubwin->axes.auto_ticks[0] == FALSE){
1609     grads =  ppsubwin->axes.u_xgrads;
1610     nbtics = ppsubwin->axes.u_nxgrads;
1611   }
1612   else{
1613     grads =  ppsubwin->axes.xgrads;
1614     nbtics = ppsubwin->axes.nxgrads;
1615   }
1616   
1617   /* Grid style */
1618   C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1619   C2F (dr) ("xset", "line style",&lineMode,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1620   style = ppsubwin->grid[0];
1621   
1622   /* Grid based on tics */
1623   for(i=0;i<nbtics;i++)
1624     {
1625       double xtmp = grads[i];
1626       vx[0] = vx[1] = XScale(xtmp);
1627       
1628       if(xtmp<xminval || xtmp>xmaxval) continue;           
1629       
1630       vy[0]= ym[0];vy[1]=  ym[1];
1631       if ( ppsubwin->axes.axes_visible[0] )
1632       {
1633         C2F(dr)("xsegs","v", vx, vy, &ns,&style,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1634       }
1635     }
1636   
1637   /* Grid based on subtics : ONLY for log. case */
1638   if(logflag =='l')
1639     {
1640       double tmp[2];
1641       double pas=0;
1642       double * tmp_log_grads = (double *) NULL;
1643       
1644       for(i=0;i<nbtics-1;i++)
1645         {
1646           int k;
1647           tmp[0] = exp10(grads[i]);
1648           tmp[1] = exp10(grads[i+1]);
1649           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1650           
1651           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1652             sciprint("Error allocating tmp_log_grads\n");
1653             return -1;
1654           }
1655           
1656           for(k=0;k<nbsubtics;k++) tmp_log_grads[k] = log10(tmp[0]+(k)*pas);
1657           
1658           for(j=0;j<nbsubtics;j++)
1659             {
1660               double val = tmp_log_grads[j];
1661               vx[0] = vx[1] = XScale(val);
1662               
1663               if(val<xminval || val>xmaxval) continue;    
1664               
1665               vy[0]= ym[0];vy[1]=  ym[1];
1666               if ( ppsubwin->axes.axes_visible[0] )
1667               {
1668                 C2F(dr)("xsegs","v", vx, vy, &ns,&style,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1669               }
1670             }
1671           
1672           FREE(tmp_log_grads); tmp_log_grads = NULL;
1673         }
1674     }
1675  
1676   /* return to solid mode (in default mode) */
1677   C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1678   
1679
1680   return 0;
1681 }
1682
1683
1684
1685 static void DrawXTics(char pos, sciPointObj * psubwin, double xy, char * c_format, int * fontid, int textcolor,int ticscolor,int color_kp, int *logrect, int smallersize)
1686 {
1687   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
1688   double xminval,yminval,xmaxval,ymaxval;
1689   int  flag=0,xx=0,yy=0,rect[4];
1690   
1691   int vx[2],vy[2],xm[2],ym[2];
1692   int barlength = 0;
1693   int posi[2];
1694   double angle=0.0;
1695   int ns=2,iflag=0;
1696   
1697   int nbtics = 0,i;
1698   char logflag = ppsubwin->logflags[0];
1699
1700   ym[0] = YScale(xy);
1701  
1702   barlength =  Max( (integer) (Cscale.WIRect1[3]/50.0), 2 ) ;
1703   
1704   /*ppsubwin->firsttime_x = TRUE;*/
1705   
1706   if(ppsubwin->axes.auto_ticks[0] == FALSE)
1707     {
1708       /* we display the x tics specified by the user*/
1709       FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval); /* here i only need x data (ymin ymax are computed but not used after) */
1710       nbtics = ppsubwin->axes.u_nxgrads;
1711       
1712       for(i=0;i<nbtics;i++)
1713         {
1714           double xtmp = ppsubwin->axes.u_xgrads[i];
1715           char *foo = ppsubwin->axes.u_xlabels[i];
1716           
1717           if(xtmp<xminval || xtmp>xmaxval) continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichées de tte facon */
1718                                                      /* donc autant ne pas aller plus loin dans l'algo... */
1719           
1720
1721           /***************************************************************/
1722           /************************* COMMON PART *************************/
1723           /***************************************************************/
1724           
1725           C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1726           /* tick is computed in vx,vy and string is displayed at posi[0],posi[1] position */
1727           
1728           vx[0] = vx[1] = xm[0] =  XScale(xtmp);
1729           posi[0] = inint( xm[0] -rect[2]/2.0);
1730           
1731           if ( pos == 'd')
1732             {
1733               posi[1]=inint( ym[0] + 1.2*barlength + rect[3]);
1734               vy[0]= ym[0];vy[1]= ym[0] + barlength ;
1735             }
1736           else 
1737             {
1738               posi[1]=inint( ym[0] - 1.2*barlength);
1739               vy[0]= ym[0];vy[1]= ym[0] - barlength;
1740             }
1741           
1742           if ( ppsubwin->axes.axes_visible[0] )
1743           {
1744             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1745           
1746             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1747             
1748             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&angle, PD0,PD0,PD0,0L,0L);
1749           }
1750           XGradPosition(psubwin,posi[1],rect[3]);
1751
1752           if ( ppsubwin->axes.axes_visible[0] )
1753           {
1754             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1755             if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1756             
1757             /* le tic proprement dit ("petit baton") */
1758             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1759           }
1760           if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1761           
1762           /***************************************************************/
1763           /************************* END COMMON PART *********************/
1764           /***************************************************************/
1765           
1766         }
1767       
1768     }
1769   else
1770     {
1771       
1772       FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval); /* here i only need x data (ymin ymax are computed but not used after) */
1773       nbtics = ppsubwin->axes.nxgrads;
1774       
1775
1776       /* test ici */
1777     /*   for(i=0;i<nbtics;i++) sciprint("xgrads(%d) = %lf\n",i,ppsubwin->axes.xgrads[i]); */
1778 /*       sciprint("\n\n"); */
1779
1780       for(i=0;i<nbtics;i++)
1781         {
1782           char foo[256]; 
1783           double xtmp = ppsubwin->axes.xgrads[i];
1784           
1785           /* if ( xtmp < xminval || xtmp > xmaxval )  */
1786 /*           { */
1787 /*             continue; /\* cas ou TL est ON et on a des graduations qui ne seront pas affichées de tte facon *\/ */
1788 /*                       /\* donc autant ne pas aller plus loin dans l'algo... *\/ */
1789 /*           } */
1790           
1791           /* chack that xtmp < xminval || xtmp > xmalval */
1792           /* but if xtmp is very close to xminval or xmaxval we display it */
1793           if ( !SAFE_LT( xminval, xtmp, EPSILON ) || !SAFE_LT( xtmp, xmaxval, EPSILON ) )
1794           {
1795             continue ;
1796           }
1797
1798           sprintf(foo,c_format,xtmp);
1799           
1800           /***************************************************************/
1801           /************************* COMMON PART *************************/
1802           /***************************************************************/
1803
1804           C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1805           /* tick is computed in vx,vy and string is displayed at posi[0],posi[1] position */
1806           
1807           vx[0] = vx[1] = xm[0] =  XScale(xtmp);
1808           posi[0] = inint( xm[0] -rect[2]/2.0);
1809           
1810           if ( pos == 'd')
1811             {
1812               posi[1]=inint( ym[0] + 1.2*barlength + rect[3]);
1813               vy[0]= ym[0];vy[1]= ym[0] + barlength ;
1814             }
1815           else 
1816             {
1817               posi[1]=inint( ym[0] - 1.2*barlength);
1818               vy[0]= ym[0];vy[1]= ym[0] - barlength;
1819             }
1820           
1821           if ( ppsubwin->axes.axes_visible[0] )
1822           {
1823             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1824
1825             
1826             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&angle, PD0,PD0,PD0,0L,0L);
1827           }
1828           XGradPosition(psubwin,posi[1],rect[3]);
1829           if ( logflag == 'l' )
1830             {
1831               if ( ppsubwin->axes.axes_visible[0] )
1832               {
1833                 C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1834                 
1835                 C2F(dr)("xstring","10",(posi[0] -= logrect[2],&posi[0]),
1836                         (posi[1] += logrect[3],&posi[1]),
1837                         PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
1838               }
1839               XGradPosition(psubwin,posi[1],rect[3]);
1840               if ( ppsubwin->axes.axes_visible[0] )
1841               {
1842                 C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1843               }
1844             }
1845           if ( ppsubwin->axes.axes_visible[0] )
1846           {
1847             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1848             if ( ticscolor != -1 )
1849             {
1850               C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1851             }
1852             
1853             /* le tic proprement dit ("petit baton") */
1854             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L); 
1855             
1856             if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
1857           }
1858           /***************************************************************/
1859           /************************* END COMMON PART *********************/
1860           /***************************************************************/
1861
1862
1863         }
1864       
1865
1866     }
1867   
1868
1869   
1870
1871   
1872
1873 }
1874
1875
1876 /****************************************************************************/
1877 /********************************** Y ***************************************/
1878 /****************************************************************************/
1879
1880
1881
1882 static int DrawYSubTics(char pos, sciPointObj * psubwin, double xy,int ticscolor,int color_kp)
1883 {
1884   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
1885   double xminval,yminval,xmaxval,ymaxval;
1886
1887   int vx[2],vy[2],xm[2];
1888   int barlength = 0;
1889  int ns=2,iflag=0;
1890   
1891   int nbtics = 0,i,j;
1892   int nbsubtics = ppsubwin->axes.nbsubtics[1];
1893   char logflag = ppsubwin->logflags[1];
1894   
1895   double *grads = (double *) NULL;
1896
1897   xm[0] = XScale(xy);
1898    
1899   barlength =  (integer) (Cscale.WIRect1[2]/75.0);
1900   
1901   FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval); /* here i only need x data (ymin ymax are computed but not used after) */
1902  
1903
1904   if(ppsubwin->axes.auto_ticks[1] == FALSE){
1905     grads =  ppsubwin->axes.u_ygrads;
1906     nbtics = ppsubwin->axes.u_nygrads;
1907   }
1908   else{
1909     grads =  ppsubwin->axes.ygrads;
1910     nbtics = ppsubwin->axes.nygrads;
1911   }
1912   
1913   
1914   if(logflag =='l')
1915     {
1916       double tmp[2];
1917       double pas=0;
1918       double * tmp_log_grads = (double *) NULL;
1919       
1920       for(i=0;i<nbtics-1;i++)
1921         {
1922           int k;
1923           tmp[0] = exp10(grads[i]);
1924           tmp[1] = exp10(grads[i+1]);
1925           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
1926           
1927           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
1928             sciprint("Error allocating tmp_log_grads\n");
1929             return -1;
1930           }
1931           
1932           for(k=0;k<nbsubtics;k++) tmp_log_grads[k] = log10(tmp[0]+(k)*pas);
1933           
1934           for(j=0;j<nbsubtics;j++)
1935             {
1936               double val = tmp_log_grads[j];
1937               /* the length of the ticks in pixels */
1938               /* minimum 2 pixels */
1939               /* use of integer division for speed */
1940               int ticksLength =  Max( ( 3 * barlength ) / 4,  1 ) ;
1941               vy[0] = vy[1] = YScale(val);
1942               
1943               if(val<yminval || val>ymaxval) continue;     
1944               
1945               if ( pos == 'r' ) 
1946               { 
1947                 vx[0] = xm[0] ;
1948                 vx[1] = xm[0] + ticksLength ; 
1949               }
1950               else 
1951               { 
1952                 vx[0] = xm[0] ;
1953                 vx[1] = xm[0] - ticksLength ; 
1954               }
1955               if ( ppsubwin->axes.axes_visible[1] )
1956               {
1957                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1958               }
1959             }
1960           
1961           FREE(tmp_log_grads); tmp_log_grads = NULL;
1962         }
1963     }
1964   else
1965     {
1966       for(i=0;i<nbtics-1;i++)
1967         {
1968           double xtmp = grads[i];
1969           double dx = (grads[i+1]-grads[i]) / nbsubtics;
1970           for(j=0;j<nbsubtics;j++)
1971             {
1972               double val = xtmp+dx*j;
1973               /* the length of the ticks in pixels */
1974               /* minimum 2 pixels */
1975               /* use of integer division for speed */
1976               int ticksLength =  Max( ( 3 * barlength ) / 4, 1 ) ;
1977               vy[0] = vy[1] = YScale(val);
1978               
1979               if(val<yminval || val>ymaxval) continue;     
1980               
1981               if ( pos == 'r' ) 
1982               { 
1983                 vx[0] = xm[0] ;
1984                 vx[1]=  xm[0] + ticksLength ; 
1985               }
1986               else 
1987               { 
1988                 vx[0] = xm[0] ;
1989                 vx[1] = xm[0] - ticksLength ; 
1990               }
1991               if ( ppsubwin->axes.axes_visible[1] )
1992               {
1993                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
1994               }
1995             }
1996         }
1997     }
1998   
1999   return 0;
2000 }
2001
2002
2003 static int DrawYGrid(sciPointObj * psubwin)
2004 {
2005   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
2006   double xminval,yminval,xmaxval,ymaxval;
2007   int verbose=0,narg;
2008
2009   int vx[2],vy[2],xm[2];
2010   int dash[6],lineMode=2;
2011   int ns=2,style=0,iflag=0;
2012   
2013   double * grads = (double *) NULL;
2014   int nbtics = 0,i,j;
2015   int nbsubtics = ppsubwin->axes.nbsubtics[1];
2016   char logflag = ppsubwin->logflags[1];
2017    
2018   FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval);
2019   
2020   
2021   xm[0] = XScale(xminval);
2022   xm[1] = XScale(xmaxval);
2023
2024   if(ppsubwin->axes.auto_ticks[1] == FALSE){
2025     grads =  ppsubwin->axes.u_ygrads;
2026     nbtics = ppsubwin->axes.u_nygrads;
2027   }
2028   else{
2029     grads =  ppsubwin->axes.ygrads;
2030     nbtics = ppsubwin->axes.nygrads;
2031   }
2032   
2033   /* Grid style */
2034   C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2035   C2F (dr) ("xset", "line style",&lineMode,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2036   style = ppsubwin->grid[1];
2037   
2038   /* Grid based on tics */
2039   for(i=0;i<nbtics;i++)
2040     {
2041       double xtmp = grads[i];
2042       vy[0] = vy[1] = YScale(xtmp);
2043       
2044       if(xtmp<yminval || xtmp>ymaxval) continue;           
2045       
2046       vx[0]= xm[0];vx[1]=  xm[1];
2047       if ( ppsubwin->axes.axes_visible[1] )
2048       {
2049         C2F(dr)("xsegs","v", vx, vy, &ns,&style,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2050       }
2051     }
2052   
2053   /* Grid based on subtics : ONLY for log. case */
2054   if(logflag =='l')
2055     {
2056       double tmp[2];
2057       double pas=0;
2058       double * tmp_log_grads = (double *) NULL;
2059       
2060       for(i=0;i<nbtics-1;i++)
2061         {
2062           int k;
2063           tmp[0] = exp10(grads[i]);
2064           tmp[1] = exp10(grads[i+1]);
2065           pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
2066           
2067           if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
2068             sciprint("Error allocating tmp_log_grads\n");
2069             return -1;
2070           }
2071           
2072           for(k=0;k<nbsubtics;k++) tmp_log_grads[k] = log10(tmp[0]+(k)*pas);
2073           
2074           for(j=0;j<nbsubtics;j++)
2075             {
2076               double val = tmp_log_grads[j];
2077               vy[0] = vy[1] = YScale(val);
2078               
2079               if(val<yminval || val>ymaxval) continue;    
2080               
2081               vx[0]= xm[0];vx[1]=  xm[1];
2082               if ( ppsubwin->axes.axes_visible[1] )
2083               {
2084                 C2F(dr)("xsegs","v", vx, vy, &ns,&style,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2085               }
2086             }
2087           
2088           FREE(tmp_log_grads); tmp_log_grads = NULL;
2089         }
2090     }
2091  
2092
2093   /* return to solid mode (in default mode) */
2094   C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2095
2096   return 0;
2097 }
2098
2099
2100
2101
2102
2103 static void DrawYTics(char pos, sciPointObj * psubwin, double xy, char * c_format, int * fontid, int textcolor,int ticscolor,int color_kp, int *logrect, int smallersize)
2104 {
2105   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
2106   double xminval,yminval,xmaxval,ymaxval;
2107   int  flag=0,xx=0,yy=0,rect[4];
2108   
2109   int vx[2],vy[2],xm[2],ym[2];
2110   int barlength = 0;
2111   int posi[2];
2112   double angle=0.0;
2113   int ns=2,iflag=0;
2114   
2115   int nbtics = 0,i;
2116   char logflag = ppsubwin->logflags[1];
2117   
2118   xm[0] = XScale(xy); /* F.Leray modified le 28.09.04 */
2119   /*  xm[0] = (ppsubwin->logflags[0]=='n')?XScale(xy):XLogScale(xy);*/
2120   
2121   /* at least 1 pixels */
2122   barlength =  Max( (integer) (Cscale.WIRect1[2]/75.0), 2 ) ;
2123   
2124   /* ppsubwin->firsttime_y = TRUE */;
2125
2126   if(ppsubwin->axes.auto_ticks[1] == FALSE)
2127     {
2128       /* we display the x tics specified by the user*/
2129       FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval); /* here i only need y data (xmin xmax are computed but not used after) */
2130       nbtics = ppsubwin->axes.u_nygrads;
2131       
2132       for(i=0;i<nbtics;i++)
2133         {
2134           double ytmp = ppsubwin->axes.u_ygrads[i];
2135           char *foo = ppsubwin->axes.u_ylabels[i];
2136           
2137           if(ytmp<yminval || ytmp>ymaxval) continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichées de tte facon */
2138                                                      /* donc autant ne pas aller plus loin dans l'algo... */
2139
2140           /* Rajout 24.09.04 */
2141 /*        if(logflag == 'l') */
2142 /*          ytmp = log10(ytmp); */
2143           /* fin Rajout 24.09.04 */
2144
2145           /***************************************************************/
2146           /************************* COMMON PART *************************/
2147           /***************************************************************/
2148           
2149           C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2150           /* tick is computed in vx,vy and string is displayed at posi[0],posi[1] position */
2151           
2152           vy[0]= vy[1] = ym[0] = YScale(ytmp);
2153           posi[1]=inint( ym[0] +rect[3]/2.0);
2154           if ( pos == 'r' ) 
2155             {
2156               posi[0]=inint( xm[0] + 1.2*barlength);
2157               vx[0]= xm[0];vx[1]= xm[0]+barlength;
2158             }
2159           else 
2160             { 
2161               posi[0]=inint(xm[0] - 1.2*barlength - rect[2]);
2162               vx[0]= xm[0];vx[1]= xm[0] - barlength;
2163             }
2164
2165
2166
2167
2168           if ( ppsubwin->axes.axes_visible[1] )
2169           {
2170             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2171             
2172             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2173             
2174             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&angle, PD0,PD0,PD0,0L,0L);
2175           }
2176           YGradPosition(psubwin,posi[0],rect[2]);
2177           /*   if ( logflag == 'l' ) */
2178           /*        { */
2179           /*          C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); */
2180           /*          C2F(dr)("xstring","10",(posi[0] -= logrect[2],&posi[0]), */
2181           /*                  (posi[1] += logrect[3],&posi[1]), */
2182           /*                  PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L); */
2183           /*          C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); */
2184           /*        } */
2185           if ( ppsubwin->axes.axes_visible[1] )
2186           {
2187             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2188             
2189             if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2190             
2191             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2192             
2193             if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2194           }
2195           
2196           /***************************************************************/
2197           /************************* END COMMON PART *********************/
2198           /***************************************************************/
2199           
2200         }
2201     }
2202   else
2203     {
2204
2205       FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval); /* here i only need y data (xmin xmax are computed but not used after) */
2206       nbtics = ppsubwin->axes.nygrads;
2207       
2208       for(i=0;i<nbtics;i++)
2209         {
2210           char foo[256];
2211           double ytmp = ppsubwin->axes.ygrads[i];
2212           
2213           /* if ( ytmp < yminval || ytmp > ymaxval )  */
2214 /*           { */
2215 /*             continue; /\* cas ou TL est ON et on a des graduations qui ne seront pas affichées de tte facon *\/ */
2216 /*             /\* donc autant ne pas aller plus loin dans l'algo... *\/ */
2217 /*           } */
2218           
2219           /* chack that xtmp < xminval || xtmp > xmalval */
2220           /* but if xtmp is very close to xminval or xmaxval we display it */
2221           if ( !SAFE_LT( yminval, ytmp, EPSILON ) || !SAFE_LT( ytmp, ymaxval, EPSILON ) )
2222           {
2223             continue ;
2224           }
2225
2226           sprintf(foo,c_format,ytmp);
2227           
2228           
2229           /***************************************************************/
2230           /************************* COMMON PART *************************/
2231           /***************************************************************/
2232           
2233           C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2234           /* tick is computed in vx,vy and string is displayed at posi[0],posi[1] position */
2235
2236           vy[0]= vy[1] = ym[0] = YScale(ytmp);
2237           posi[1]=inint( ym[0] +rect[3]/2.0);
2238
2239           if ( pos == 'r' ) 
2240             {
2241               posi[0]=inint( xm[0] + 1.2*barlength);
2242               vx[0]= xm[0];vx[1]= xm[0]+barlength;
2243             }
2244           else 
2245             { 
2246               posi[0]=inint(xm[0] - 1.2*barlength - rect[2]);
2247               vx[0]= xm[0];vx[1]= xm[0] - barlength;
2248             }
2249
2250
2251
2252 /*        if ( pos == 'r' )  */
2253 /*          { */
2254 /*            posi[0]=inint( xm[0] + 1.2*barlength); */
2255 /*            vx[0]= xm[0];vx[1]= xm[0]+barlength; */
2256 /*          } */
2257 /*        else  */
2258 /*          {  */
2259 /*            posi[0]=inint(xm[0] - 1.2*barlength - rect[2]); */
2260 /*            vx[0]= xm[0];vx[1]= xm[0] - barlength; */
2261 /*          } */
2262           
2263           /* if ( !CheckDisplay( 1.5, 1.5, */
2264 /*                               ppsubwin->logflags[1], */
2265 /*                               foo, posi, */
2266 /*                               fontid, oldRect ) ) */
2267 /*           { */
2268 /*             continue ; */
2269 /*           } */
2270
2271 /*           /\* update old_rect *\/ */
2272 /*           getTicksLabelBox( 1.5, 1.5, foo, posi, fontid, old_rect ) ; */
2273           
2274           
2275           if ( ppsubwin->axes.axes_visible[1] )
2276           {
2277             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2278             
2279             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&angle, PD0,PD0,PD0,0L,0L);
2280           }
2281           YGradPosition(psubwin,posi[0],rect[2]);
2282           
2283           if ( logflag == 'l' )
2284             {
2285               if ( ppsubwin->axes.axes_visible[1] )
2286               {
2287                 C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2288                 
2289                 C2F(dr)("xstring","10",(posi[0] -= logrect[2],&posi[0]),
2290                         (posi[1] += logrect[3],&posi[1]),
2291                         PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
2292               }
2293               YGradPosition(psubwin,posi[0],rect[2]); /* adding F.Leray 04.08.05 */
2294               if ( ppsubwin->axes.axes_visible[1] )
2295               {
2296                 C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2297               }
2298             }
2299           if ( ppsubwin->axes.axes_visible[1] )
2300           {
2301             if ( textcolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2302             
2303             if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2304             
2305             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2306           
2307             if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2308           }
2309           /***************************************************************/
2310           /************************* END COMMON PART *********************/
2311           /***************************************************************/
2312           
2313         }
2314     }
2315 }
2316
2317 static int XDrawAxisLine(double xminval,double xmaxval,double xy, int ticscolor, int color_kp)
2318 {
2319   int vx[2], vy[2];
2320   int ns=2, iflag=0;
2321   
2322   vx[0] =  XScale(xminval); /* C EST LA que se calcule les positions initiales et finales (en x et y) de la barre support de l'axe des abscisses */
2323   vx[1] =  XScale(xmaxval);
2324   vy[0]= vy[1] = YScale(xy);
2325   
2326   if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2327   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2328   if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2329
2330
2331   return 0;
2332 }
2333
2334 static int YDrawAxisLine(double yminval,double ymaxval,double xy, int ticscolor, int color_kp)
2335 {
2336   int vx[2], vy[2];
2337   int ns=2, iflag=0;
2338
2339   vy[0] =  YScale(yminval); /* C EST LA que se calcule les positions initiales et finales (en x et y) de la barre support de l'axe des abscisses */
2340   vy[1] =  YScale(ymaxval);
2341   vx[0]= vx[1] = XScale(xy);
2342   
2343   if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2344   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
2345   if ( ticscolor != -1 ) C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2346
2347
2348   return 0;
2349 }
2350
2351
2352 void FindXYMinMaxAccordingTL(sciPointObj * psubwin, double *xminval,double *yminval,double *xmaxval,double *ymaxval)
2353 {
2354   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
2355   
2356   *xminval = ppsubwin->axes.xlim[0];
2357   *yminval = ppsubwin->axes.ylim[0];
2358   
2359   *xmaxval = ppsubwin->axes.xlim[1];
2360   *ymaxval = ppsubwin->axes.ylim[1];
2361 }
2362
2363
2364
2365
2366 static int SciAxisNew(char pos,sciPointObj *psubwin, double xy, int fontsize,int fontstyle,int textcolor,int ticscolor,int seg)
2367 {
2368   int switchXY = -1;
2369   
2370   char c_format[5];
2371   integer xx=0,yy=0;
2372   integer barlength;
2373   integer fontid[2],fontsize_kp, narg,verbose=0,logrect[4],smallersize=0,color_kp; 
2374   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
2375   double xminval, yminval, xmaxval, ymaxval;
2376   
2377   char logflag ;
2378   /* int lastxindex, lastyindex; */
2379   BOOL auto_ticks;
2380
2381
2382   if(pos=='u' || pos=='d'){
2383     switchXY = 0;
2384     logflag = ppsubwin->logflags[0];
2385     auto_ticks = ppsubwin->axes.auto_ticks[0];
2386   }
2387   else if(pos=='l' || pos=='r'){
2388     switchXY = 1;
2389     logflag = ppsubwin->logflags[1];
2390     auto_ticks = ppsubwin->axes.auto_ticks[1];
2391   }
2392
2393
2394   fontid[0]= fontstyle;
2395   
2396   C2F(dr)("xget","font",&verbose,fontid,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2397   fontsize_kp = fontid[1] ;
2398   if (fontsize == -1 )
2399     { fontid[0]= 0; fontid[1]= 1;  fontsize_kp = fontid[1] ;
2400     fontid[0]= fontstyle;
2401     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);}
2402   
2403   if ( fontsize != -1 ) 
2404     {
2405       fontid[1] = fontsize ;
2406       fontid[0]= fontstyle;
2407       C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2408     }
2409   if ( textcolor != -1 || ticscolor != -1 ) 
2410     {
2411       C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2412     }
2413   
2414   if (logflag == 'l' && auto_ticks == TRUE)
2415     {
2416       C2F(dr)("xstringl","10",&xx,&yy,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);       
2417       smallersize=fontid[1]-2;
2418       C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2419     }
2420   
2421
2422
2423   FindXYMinMaxAccordingTL(psubwin,&xminval,&yminval,&xmaxval,&ymaxval);
2424
2425
2426   switch (switchXY)
2427   {
2428   case 0: /* x horizontal axis */
2429     {
2430       /** Horizontal axes **/
2431
2432       char formatY[5] ;
2433       barlength =  (integer) (Cscale.WIRect1[3]/50.0);
2434       
2435       /* remove concealing tics labels */
2436       
2437       updateXaxesTics( psubwin, pos, xy, fontid, smallersize ) ;
2438       
2439       /* the format may have changed */
2440       findFormat( psubwin, c_format, formatY ) ;
2441
2442       /* le "loop on the ticks" */
2443       DrawXTics(pos, psubwin, xy, c_format, fontid, textcolor, ticscolor, color_kp, logrect, smallersize);
2444       
2445       /* subtics display*/
2446       DrawXSubTics(pos, psubwin, xy, ticscolor, color_kp);
2447     }
2448     break;
2449   case 1: /* y vertical axis */
2450     {
2451     /** Vertical axes **/
2452       char formatX[5] ;
2453       
2454       /* int ticsDir[2] = {1,0} ; */
2455       barlength =  (integer) (Cscale.WIRect1[2]/75.0);
2456
2457       /* remove concealing tics labels */
2458       updateYaxesTics( psubwin, pos, xy, fontid, smallersize ) ;
2459
2460        /* the format may have changed */
2461       findFormat( psubwin, formatX, c_format ) ;
2462
2463       /* le "loop on the ticks" */
2464       DrawYTics(pos, psubwin, xy, c_format, fontid, textcolor, ticscolor, color_kp, logrect, smallersize);
2465       
2466       /* subtics display*/
2467       DrawYSubTics(pos, psubwin, xy, ticscolor, color_kp);
2468     }
2469     
2470     break;
2471   default:
2472     sciprint("Axes.c : SciAxisNew : Impossible case");
2473     return -1;
2474   }
2475   
2476   return 0;
2477 }
2478
2479 void YGradPosition(sciPointObj * psubwin, int xx, int rect2)
2480 {
2481   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
2482   
2483   if(ppsubwin->firsttime_y == TRUE)
2484     {
2485       ppsubwin->YGradMostOnLeft = xx;
2486       ppsubwin->YGradMostOnRight = xx + rect2;
2487       ppsubwin->firsttime_y = FALSE;
2488     }
2489   else
2490     {
2491       if(xx < ppsubwin->YGradMostOnLeft)  ppsubwin->YGradMostOnLeft  = xx;
2492       if(xx + rect2 > ppsubwin->YGradMostOnRight) ppsubwin->YGradMostOnRight = xx + rect2;
2493     }
2494 }
2495
2496 void XGradPosition(sciPointObj * psubwin, int yy, int rect3)
2497 {
2498   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
2499   
2500   if( ppsubwin->firsttime_x )
2501   {
2502     ppsubwin->XGradMostOnTop = yy - rect3 ;
2503     ppsubwin->XGradMostOnBottom = yy ;
2504     ppsubwin->firsttime_x = FALSE;
2505   }
2506   else
2507   {
2508     if(yy > ppsubwin->XGradMostOnBottom)
2509     {
2510       ppsubwin->XGradMostOnBottom  = yy ;
2511     }
2512     if( yy - rect3 < ppsubwin->XGradMostOnTop)
2513     {
2514       ppsubwin->XGradMostOnTop = yy - rect3 ;
2515     }
2516   }
2517 }
2518
2519 /*--------------------------------------------------------------------------------*/
2520 /* clear a subwindow from all of its children */
2521 void clearSubWin( sciPointObj * pSubWin )
2522 {
2523   sciSons * curSon = sciGetSons (pSubWin);
2524   
2525   while ( curSon != NULL && curSon->pointobj != NULL )
2526   {
2527     if ( curSon->pointobj->entitytype != SCI_LABEL )
2528     {
2529       DestroyAllGraphicsSons (curSon->pointobj) ;
2530       curSon = sciGetSons ( pSubWin ) ;
2531     }
2532     else
2533     {
2534       curSon = curSon->pnext ;
2535     }
2536     
2537   }
2538 }
2539 /*--------------------------------------------------------------------------------*/
2540 /* reinit a subwindow (but don't change position ) */
2541 void reinitSubWin( sciPointObj * pSubWin )
2542 {
2543   sciSubWindow * ppSubWin  = pSUBWIN_FEATURE (pSubWin) ;
2544   
2545   clearSubWin(   pSubWin ) ;
2546  
2547   initSubWinBounds( pSubWin ) ;
2548   ppSubWin->axes.xdir = 'd' ;
2549   ppSubWin->axes.ydir = 'l' ;
2550   
2551   ppSubWin->visible = TRUE;
2552   
2553   initSubWinAngles( pSubWin ) ;
2554   
2555   ppSubWin->surfcounter = 0 ;
2556   
2557   ppSubWin->FirstPlot = TRUE;
2558   
2559
2560 }
2561 /*--------------------------------------------------------------------------------*/
2562 /* reinit the viewing angles of a subwindow */
2563 void initSubWinAngles( sciPointObj * pSubWin )
2564 {
2565   sciSubWindow * ppSubWin  = pSUBWIN_FEATURE (pSubWin ) ;
2566   sciSubWindow * ppAxesMdl = pSUBWIN_FEATURE (getAxesModel()) ;
2567   ppSubWin->is3d     = ppAxesMdl->is3d     ;
2568   ppSubWin->alpha_kp = ppAxesMdl->alpha_kp ;
2569   ppSubWin->theta_kp = ppAxesMdl->theta_kp ;
2570   ppSubWin->alpha    = ppAxesMdl->alpha    ;
2571   ppSubWin->theta    = ppAxesMdl->theta    ;
2572 }
2573
2574 /*--------------------------------------------------------------------------------*/
2575 /* set the size and position of the subwindow to the default */
2576 void initSubWinSize( sciPointObj * pSubWin )
2577 {
2578   sciSubWindow * ppSubWin  = pSUBWIN_FEATURE (pSubWin ) ;
2579   sciSubWindow * ppAxesMdl = pSUBWIN_FEATURE (getAxesModel()) ;
2580   ppSubWin->WRect[0] = ppAxesMdl->WRect[0] ;
2581   ppSubWin->WRect[1] = ppAxesMdl->WRect[1] ;
2582   ppSubWin->WRect[2] = ppAxesMdl->WRect[2] ;
2583   ppSubWin->WRect[3] = ppAxesMdl->WRect[3] ;
2584
2585 }
2586 /*--------------------------------------------------------------------------------*/
2587 /* set the data_bounds of the axes to the default value */
2588 void initSubWinBounds( sciPointObj * pSubWin )
2589 {
2590   sciSubWindow * ppSubWin  = pSUBWIN_FEATURE (pSubWin ) ;
2591   sciSubWindow * ppAxesMdl = pSUBWIN_FEATURE (getAxesModel()) ;
2592   ppSubWin->FRect[0] = ppAxesMdl->FRect[0] ;
2593   ppSubWin->FRect[1] = ppAxesMdl->FRect[1] ;
2594   ppSubWin->FRect[2] = ppAxesMdl->FRect[2] ;
2595   ppSubWin->FRect[3] = ppAxesMdl->FRect[3] ;
2596   ppSubWin->FRect[4] = ppAxesMdl->FRect[4] ;
2597   ppSubWin->FRect[5] = ppAxesMdl->FRect[5] ;
2598
2599   ppSubWin->SRect[0] = ppAxesMdl->SRect[0] ;
2600   ppSubWin->SRect[1] = ppAxesMdl->SRect[1] ;
2601   ppSubWin->SRect[2] = ppAxesMdl->SRect[2] ;
2602   ppSubWin->SRect[3] = ppAxesMdl->SRect[3] ;
2603   ppSubWin->SRect[4] = ppAxesMdl->SRect[4] ;
2604   ppSubWin->SRect[5] = ppAxesMdl->SRect[5] ;
2605 }
2606 /*--------------------------------------------------------------------------------*/
2607 /* reinit the selected subwindow if the auto_clear property is set to on */
2608 /* return TRUE if the window has been redrawn */
2609 BOOL checkRedrawing( void )
2610 {
2611   
2612   sciPointObj * pSubWin = sciGetSelectedSubWin( sciGetCurrentFigure() ) ;
2613   if ( !sciGetAddPlot( pSubWin ) )
2614   {
2615       /* redraw the axis */
2616       reinitSubWin( pSubWin ) ;
2617       return TRUE ;
2618   }
2619   return FALSE ;
2620 }
2621
2622 /*--------------------------------------------------------------------------------*/
2623
2624 /* 1----------4 */
2625 /* |          | */
2626 /* |          | */
2627 /* |          | */
2628 /* 2----------3 */
2629 /* check if the graduation text foo is inside the old_rect */
2630 /* in this case it should not been displayed */
2631 /* taken from drawobject.c */
2632 BOOL CheckDisplay(double fact_h, double fact_w, char logflag, char *foo,int *posi,int *fontid,int *old_rect) 
2633 {
2634   int rect[4],i;
2635   int point[4][2];
2636   int logrect[4] ;
2637   int XX = 0 ;
2638   int YY = 0 ;
2639   
2640   if(old_rect[0] == 0 && old_rect[1] == 0 && old_rect[2] == 0 && old_rect[3] == 0)
2641   {
2642     return TRUE ;
2643   }
2644   
2645   C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
2646   
2647   /* compute bounding of "10"  string used for log scale ON and auto_ticks ON */
2648   C2F(dr)("xstringl","10",&XX,&YY,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
2649  
2650   getTicksLabelBox( 1.0, 1.0, foo, posi, fontid, logflag, rect, TRUE ) ;
2651  
2652   point[0][0] = rect[0]; /* upper left point */
2653   point[0][1] = rect[1];
2654   
2655   point[1][0] = rect[0]; /* lower left point */
2656   point[1][1] = rect[1]+rect[3];
2657   
2658   point[2][0] = rect[0]+rect[2]; /* lower right point */
2659   point[2][1] = rect[1]+rect[3];
2660   
2661   point[3][0] = rect[0]+rect[2]; /* upper right point */
2662   point[3][1] = rect[1];
2663   
2664   for(i=0;i<4;i++)
2665   {
2666     if( !IsInsideRectangle(old_rect,point[i]) )
2667     {
2668       return FALSE; /* If one inside the old_rect, DO NOT display the graduation ! */
2669     }
2670   }
2671
2672   return TRUE;
2673 }
2674
2675 /*--------------------------------------------------------------------------------*/
2676
2677 /* The unit is the pixel */
2678 /* return 0 if the point is inside the rect */
2679 /* 1 if it is actually outside the rect */
2680 /* (rect[0],rect[1]) : upper left point of the bounding box  in pixel */
2681 /* (rect[2],rect[3]) : width and height in pixel */
2682 /* point[0] : x component */
2683 /* point[1] : y component */
2684 BOOL IsInsideRectangle(int * rect, int *point)
2685 {
2686
2687   if((point[0] >= rect[0] && point[0] <= rect[0]+rect[2]) &&
2688      (point[1] >= rect[1] && point[1] <= rect[1]+rect[3]))
2689     return FALSE;
2690   
2691   return TRUE;
2692 }
2693
2694 /*--------------------------------------------------------------------------------*/
2695
2696 /* get the bounding rectangle of a label of a ticks */
2697 /* similar to stringBoundingRect but only for ticks labels */
2698 void getTicksLabelBox( double   fact_h   ,
2699                        double   fact_w   , 
2700                        char   * label    ,
2701                        int      pos[2]   ,
2702                        int      fontId[2],
2703                        char     logflag  ,
2704                        int      bbox[4]  ,
2705                        BOOL     changeFont )
2706 {  
2707   int prevFontId[2] ;
2708   
2709   if ( changeFont )
2710   {
2711     int verbose = 0 ;
2712     int narg ;
2713     C2F(dr)("xget","font",&verbose,prevFontId,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2714     C2F(dr)("xset","font",fontId,fontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2715   }
2716   
2717   if ( logflag == 'n' )
2718   { 
2719     C2F(dr)("xstringl",label,&pos[0],&pos[1],bbox,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2720     bbox[3] = (int)(fact_h * bbox[3]);
2721     bbox[2] = (int)(fact_w * bbox[2]);
2722   }
2723   else
2724   {
2725     int smallersize = fontId[1]-2;
2726     int rect10[4];
2727     int posi10[2];
2728     int logrect[4] ;
2729     int XX = 1 ;
2730     int YY = 1 ;
2731     /* compute bounding of "10"  string used for log scale ON and auto_ticks ON */
2732     C2F(dr)("xstringl","10",&XX,&YY,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
2733     
2734     posi10[0] = pos[0] - logrect[2];
2735     posi10[1] = pos[1] + logrect[3];
2736     
2737     /* get the bbox of the 10 */
2738     C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2739     
2740     pos[0] = rect10[0] + rect10[2];
2741     pos[1] = (int) (rect10[1] - rect10[3]*.1);
2742     
2743     C2F(dr)("xset","font",fontId,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2744     
2745     /* get the bbox of the exponent */
2746     C2F(dr)("xstringl",label,(&pos[0]),(&pos[1]),bbox,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2747     
2748     bbox[2] = (integer)(fact_w*(bbox[2] + rect10[2]));
2749     bbox[3] = (integer)(fact_h*(bbox[3] + rect10[3] + (int) (rect10[3]*.1))); /* added the 01.06.05 */
2750     bbox[0] = rect10[0];
2751     /* bbox[1] = bbox[1]; */
2752     
2753     C2F(dr)("xset","font",fontId,fontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2754   }
2755
2756   if ( changeFont )
2757   {
2758     C2F(dr)("xset","font",prevFontId,prevFontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2759   }
2760 }
2761
2762 /*--------------------------------------------------------------------------------*/
2763
2764 /* remove the concealed ticks before display on the X axis */
2765 BOOL checkXAxes2dTics( sciPointObj * psubwin  ,
2766                        char          side     ,
2767                        double        y        ,
2768                        char        * cFormat  ,
2769                        int           fontId[2],
2770                        int           smallersize )
2771 {
2772   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin) ;
2773   double xminval, yminval, xmaxval, ymaxval ;
2774   int  /* flag=0, */xx=0,yy=0,rect[4] ;
2775   int xm[2],ym[2];
2776   int barlength = 0;
2777   int posi[2];
2778   int prevFontId[2] ;
2779   int verbose = 0 ;
2780   int narg ;
2781   
2782   double factX = 1.2 ;
2783   double factY = 1.2 ;
2784   int nbtics = 0,i ;
2785   int prevRect[4] = { 0, 0, 0, 0 } ;
2786   
2787   /*--------*/
2788   /* x axis */
2789   /*--------*/
2790   
2791   ym[0] = YScale(y) ;
2792
2793   barlength =  Max( (integer) (Cscale.WIRect1[3]/50.0), 2 ) ;
2794
2795   ppsubwin->firsttime_x = TRUE ;
2796
2797   /* suppose auto_ticks is off */
2798   /* here i only need x data (ymin ymax are computed but not used after) */
2799   FindXYMinMaxAccordingTL( psubwin, &xminval, &yminval, &xmaxval, &ymaxval ) ;
2800   nbtics = ppsubwin->axes.nxgrads ;
2801   
2802   C2F(dr)("xget","font",&verbose,prevFontId,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2803   C2F(dr)("xset","font",fontId,fontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
2804   
2805   for( i = 0 ; i < nbtics; i++ )
2806   {
2807     
2808     char foo[256];
2809     double xtmp = ppsubwin->axes.xgrads[i] ;
2810
2811     if( xtmp < xminval || xtmp > xmaxval ) 
2812     {
2813       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichées de tte facon */
2814                 /* donc autant ne pas aller plus loin dans l'algo... */
2815     }
2816     
2817     sprintf(foo, cFormat,xtmp);
2818     
2819     /* compute the bounding box of the label */
2820    
2821     C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2822     
2823     xm[0] = XScale(xtmp);
2824     posi[0] = inint( xm[0] - rect[2]/2.0 ) ;
2825     
2826     if ( side == 'd')
2827     {
2828       /* ticks are drawn under the axis */
2829       posi[1] = inint( ym[0] + 1.2 * barlength + rect[3] ) ;
2830     }
2831     else /* side = 'u' */
2832     {
2833       /* ticks are drawn above the axis */
2834       posi[1] = inint( ym[0] - 1.2 * barlength ) ;
2835     }
2836
2837     /* check that the new display doesnot concealed the previous */
2838     if ( !CheckDisplay( factX, factY,
2839                         ppsubwin->logflags[0],
2840                         foo, posi,
2841                         fontId, prevRect ) )
2842     {
2843       /* put the font back */
2844       C2F(dr)("xset","font",prevFontId,prevFontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2845       return FALSE ;
2846     }
2847     
2848     /* get the boundig rectangle of the new label */
2849     getTicksLabelBox( factX, factY, foo, posi, fontId, ppsubwin->logflags[0],  prevRect, FALSE ) ;
2850
2851     XGradPosition(psubwin,posi[1],rect[3]) ;
2852     
2853   }
2854
2855
2856   /* put the font back */
2857   C2F(dr)("xset","font",prevFontId,prevFontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2858
2859   return TRUE ;    
2860 }
2861
2862 /*--------------------------------------------------------------------------------*/
2863
2864 /* remove the concealed ticks before display on the X axis */
2865 BOOL checkYAxes2dTics( sciPointObj * psubwin  ,
2866                        char          side     ,
2867                        double        x        ,
2868                        char        * cFormat  ,
2869                        int           fontId[2],
2870                        int           smallersize )
2871 {
2872   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin) ;
2873   double xminval, yminval, xmaxval, ymaxval ;
2874   int  /* flag=0, */xx=0,yy=0,rect[4] ;
2875   int xm[2],ym[2];
2876   int barlength = 0;
2877   int posi[2];
2878   int prevFontId[2] ;
2879   int verbose = 0 ;
2880   int narg ;
2881   double factX = 1.5 ;
2882   double factY = 1.5 ;
2883   int nbtics = 0,i ;
2884   int prevRect[4] = { 0, 0, 0, 0 } ;
2885   
2886   /*--------*/
2887   /* y axis */
2888   /*--------*/
2889   
2890   xm[0] = XScale(x) ;
2891
2892   barlength =  Max( (integer) (Cscale.WIRect1[2]/75.0), 2 ) ;
2893
2894   ppsubwin->firsttime_y = TRUE ;
2895
2896   /* suppose auto_ticks is off */
2897   /* here i only need x data (ymin ymax are computed but not used after) */
2898   FindXYMinMaxAccordingTL( psubwin, &xminval, &yminval, &xmaxval, &ymaxval ) ;
2899   nbtics = ppsubwin->axes.nygrads ;
2900   
2901   C2F(dr)("xget","font",&verbose,prevFontId,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2902   C2F(dr)("xset","font",fontId,fontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
2903   
2904   for( i = 0 ; i < nbtics; i++ )
2905   {
2906     
2907     char foo[256];
2908     double ytmp = ppsubwin->axes.ygrads[i] ;
2909
2910     if( ytmp < yminval || ytmp > ymaxval ) 
2911     {
2912       continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichées de tte facon */
2913                 /* donc autant ne pas aller plus loin dans l'algo... */
2914     }
2915     
2916     sprintf(foo, cFormat,ytmp);
2917     
2918     /* compute the bounding box of the label */
2919    
2920     C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
2921     
2922     ym[0] = YScale(ytmp);
2923     posi[1] = inint( ym[0] + rect[2]/2.0 ) ;
2924     
2925     if ( side == 'r')
2926     {
2927       /* ticks are drawn under the axis */
2928       posi[0] = inint( xm[0] + 1.2 * barlength ) ;
2929     }
2930     else /* side = 'l' */
2931     {
2932       /* ticks are drawn above the axis */
2933       posi[0] = inint( xm[0] - 1.2 * barlength - rect[2] ) ;
2934     }
2935
2936     /* check that the new display doesnot concealed the previous */
2937     if ( !CheckDisplay( factX, factY,
2938                         ppsubwin->logflags[1],
2939                         foo, posi,
2940                         fontId, prevRect ) )
2941     {
2942       /* put the font back */
2943       C2F(dr)("xset","font",prevFontId,prevFontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2944       return FALSE ;
2945     }
2946     
2947     /* get the boundig rectangle of the new label */
2948     getTicksLabelBox( factX, factY, foo, posi, fontId, ppsubwin->logflags[1],  prevRect, FALSE ) ;
2949
2950     YGradPosition(psubwin,posi[0],rect[2]) ;
2951     
2952   }
2953
2954
2955   /* put the font back */
2956   C2F(dr)("xset","font",prevFontId,prevFontId+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L) ;
2957   
2958   return TRUE ;
2959 }
2960
2961 /*--------------------------------------------------------------------------------*/
2962
2963 /* check if the ticks are not concealing each others */
2964 /* in this case some are removed until it's fit */
2965 void updateXaxesTics( sciPointObj * psubwin  ,
2966                       char          side     ,
2967                       double        y        ,
2968                       int           fontId[2] ,
2969                       int           smallersize )
2970 {
2971   sciSubWindow * ppSubWin = pSUBWIN_FEATURE( psubwin ) ;
2972   char labelXFormat[5] ;
2973   char labelYFormat[5] ;
2974   findFormat( psubwin, labelXFormat, labelYFormat ) ;
2975   
2976   /* check if the ticks are concealing or not */
2977   if ( !checkXAxes2dTics( psubwin, side, y, labelXFormat, fontId, smallersize ) ) 
2978   {
2979     double xMin ;
2980     double xMax ;
2981     double yMin ;
2982     double yMax ;
2983     double zMin ;
2984     double zMax ;
2985     int    ticksStatus = 0 ;
2986     
2987     sciGetDisplayedBounds( psubwin, &xMin, &xMax, &yMin, &yMax, &zMin, &zMax ) ;
2988     
2989     ppSubWin->axes.nxgrads = ( ppSubWin->axes.nxgrads + 1 ) / 2 ;
2990     
2991     /* recompute the ticks */
2992     if ( ppSubWin->logflags[0] == 'n' )
2993     {
2994       TheTicks( &xMin, &xMax, ppSubWin->axes.xgrads, &ppSubWin->axes.nxgrads, TRUE ) ;
2995     }
2996     else
2997     {
2998       GradLog( xMin, xMax, ppSubWin->axes.xgrads, &ppSubWin->axes.nxgrads, TRUE ) ;
2999     }
3000
3001     findFormat( psubwin, labelXFormat, labelYFormat ) ;
3002
3003     while( ticksStatus == 0 && !checkXAxes2dTics( psubwin, side, y, labelXFormat, fontId, smallersize ) )
3004     {
3005       ppSubWin->axes.nxgrads = ( ppSubWin->axes.nxgrads + 1 ) / 2 ;
3006       if (  ppSubWin->logflags[0] == 'n' )
3007       {
3008         ticksStatus = TheTicks( &xMin, &xMax, ppSubWin->axes.xgrads, &ppSubWin->axes.nxgrads, TRUE ) ;
3009       }
3010       else
3011       {
3012         GradLog( xMin, xMax, ppSubWin->axes.xgrads, &ppSubWin->axes.nxgrads, TRUE ) ;
3013       }
3014
3015       findFormat( psubwin, labelXFormat, labelYFormat ) ;
3016
3017     }
3018
3019   }
3020   /* else everything ok */
3021 }
3022
3023 /*--------------------------------------------------------------------------------*/
3024
3025 /* check if the ticks are not concealing each others */
3026 /* in this case some are removed until it's fit */
3027 void updateYaxesTics( sciPointObj * psubwin  ,
3028                       char          side     ,
3029                       double        x        ,
3030                       int           fontId[2],
3031                       int           smallersize )
3032 {
3033   sciSubWindow * ppSubWin = pSUBWIN_FEATURE( psubwin ) ;
3034   char labelXFormat[5] ;
3035   char labelYFormat[5] ;
3036   findFormat( psubwin, labelXFormat, labelYFormat ) ;
3037   
3038   /* check if the ticks are concealing or not */
3039   if ( !checkYAxes2dTics( psubwin, side, x, labelYFormat, fontId, smallersize ) ) 
3040   {
3041     double xMin ;
3042     double xMax ;
3043     double yMin ;
3044     double yMax ;
3045     double zMin ;
3046     double zMax ;
3047     int    ticksStatus = 0 ;
3048     
3049     sciGetDisplayedBounds( psubwin, &xMin, &xMax, &yMin, &yMax, &zMin, &zMax ) ;
3050     
3051     ppSubWin->axes.nygrads = ( ppSubWin->axes.nygrads + 1 ) / 2 ;
3052     
3053     /* recompute the ticks */
3054     if ( ppSubWin->logflags[1] == 'n' )
3055     {
3056       TheTicks( &yMin, &yMax, ppSubWin->axes.ygrads, &ppSubWin->axes.nygrads, TRUE ) ;
3057     }
3058     else
3059     {
3060       GradLog( yMin, yMax, ppSubWin->axes.ygrads, &ppSubWin->axes.nygrads, TRUE ) ;
3061     }
3062
3063     findFormat( psubwin, labelXFormat, labelYFormat ) ;
3064
3065     while( ticksStatus == 0 && !checkYAxes2dTics( psubwin, side, x, labelYFormat, fontId, smallersize ) )
3066     {
3067       ppSubWin->axes.nygrads = ( ppSubWin->axes.nygrads + 1 ) / 2 ;
3068       if (  ppSubWin->logflags[1] == 'n' )
3069       {
3070         ticksStatus = TheTicks( &yMin, &yMax, ppSubWin->axes.ygrads, &ppSubWin->axes.nygrads, TRUE ) ;
3071       }
3072       else
3073       {
3074         GradLog( yMin, yMax, ppSubWin->axes.ygrads, &ppSubWin->axes.nygrads, TRUE ) ;
3075       }
3076
3077       findFormat( psubwin, labelXFormat, labelYFormat ) ;
3078
3079     }
3080
3081   }
3082   /* else everything ok */
3083 }
3084
3085 /*--------------------------------------------------------------------------------*/
3086  
3087 /* remove in the ticks array the indices i such as removedTicks[i] */
3088 /* is true. The value nbtics is an in-out variable */
3089 void removeBadTicks( double * ticks, BOOL * removedTicks, int * nbTicks )
3090 {
3091   int i ;
3092   for ( i = *nbTicks - 1 ; i >= 0 ; i-- )
3093   {
3094     if ( removedTicks[i] )
3095     {
3096       removeIndex( ticks, *nbTicks, i ) ;
3097       *nbTicks = *nbTicks - 1 ;
3098     }
3099   }
3100 }
3101
3102 /*--------------------------------------------------------------------------------*/
3103
3104 /* remove an element in the array from translating the next
3105    elements on step backward */
3106 void removeIndex( double * changedArray, int size, int ind )
3107 {
3108   int i ;
3109   for ( i = ind + 1 ; i < size ; i++ )
3110   {
3111     changedArray[i-1] = changedArray[i] ;
3112   } 
3113 }
3114
3115 /*--------------------------------------------------------------------------------*/
3116
3117 /* compute the needed formats to display the ticks of a subWin */
3118 void findFormat( sciPointObj * pSubWin, char formatX[5], char formatY[5] )
3119 {
3120   sciSubWindow * ppSubWin = pSUBWIN_FEATURE( pSubWin ) ;
3121   int lastIndex ;
3122
3123   /* x axis */
3124   lastIndex = Max( ppSubWin->axes.nxgrads - 1, 0 ) ;
3125
3126   ChoixFormatE( formatX,
3127                 ppSubWin->axes.xgrads[0],
3128                 ppSubWin->axes.xgrads[lastIndex],
3129                ( (ppSubWin->axes.xgrads[lastIndex])-(ppSubWin->axes.xgrads[0]))/(lastIndex)); /* Adding F.Leray 06.05.04 */
3130
3131   /* y-axis */
3132   lastIndex = Max( ppSubWin->axes.nygrads - 1, 0 ) ;
3133   
3134   ChoixFormatE( formatY,
3135                 ppSubWin->axes.ygrads[0],
3136                 ppSubWin->axes.ygrads[lastIndex],
3137                 ((ppSubWin->axes.ygrads[lastIndex])-(ppSubWin->axes.ygrads[0]))/(lastIndex)); /* Adding F.Leray 06.05.04 */
3138   
3139 }
3140
3141 /*--------------------------------------------------------------------------------*/
3142 void updateSubWinScale( sciPointObj * pSubWin )
3143 {
3144   double xBox[8] ;
3145   double yBox[8] ;
3146   double zBox[8] ;
3147   double dBox[6] ;
3148
3149
3150   set_scale ("tttftt", pSUBWIN_FEATURE(pSubWin)->WRect,
3151     pSUBWIN_FEATURE(pSubWin)->FRect,
3152     NULL, pSUBWIN_FEATURE(pSubWin)->logflags, 
3153     pSUBWIN_FEATURE(pSubWin)->ARect); 
3154
3155   /* Scales are not be updated with an automatic drawing */
3156   if ( pSUBWIN_FEATURE(pSubWin)->is3d )
3157   {
3158     updateScale3d( pSubWin, dBox, xBox, yBox, zBox ) ;
3159   }
3160   else
3161   {
3162     sci_update_frame_bounds_2d( pSubWin ) ;
3163   }
3164 }
3165 /*-----------------------------------------------------------------------------------------*/
3166 void updateScaleIfRequired( sciPointObj * pSubWin )
3167 {
3168   if ( !sciGetIsAutoDrawable( pSubWin ) )
3169   {
3170     updateSubWinScale( pSubWin ) ;
3171   }
3172 }
3173 /*-----------------------------------------------------------------------------------------*/
3174 void drawAxesGrid( sciPointObj * psubwin )
3175 {
3176   if( pSUBWIN_FEATURE(psubwin)->grid[0] > -1 )
3177   {
3178     DrawXGrid(psubwin);
3179   }
3180
3181   if( pSUBWIN_FEATURE(psubwin)->grid[1] > -1 )
3182   {
3183     DrawYGrid(psubwin);
3184   }
3185 }
3186 /*-----------------------------------------------------------------------------------------*/
3187 /**axis_3ddraw 10/2003
3188 * @author Djalel Abdemouche
3189 * Should be in Axes.c file
3190 */
3191 void axis_3ddraw(sciPointObj *pobj, double *xbox, double *ybox, double *zbox, integer *InsideU, integer *InsideD) 
3192 {
3193   double dbox[6];
3194   integer flag,i,p,n,pat,hiddencolor, x[5]; /* F. Leray : redimmensionnment (+1) du tableau x[4];*/
3195   static double Alpha, Teta;
3196   int verbose=0,narg;
3197   integer ixbox[8],iybox[8],xind[8],dash[6];
3198   integer background,zero=0, color_old; /* Adding color_old 04.03.04*/
3199   sciSubWindow * ppsubwin =  pSUBWIN_FEATURE (pobj);
3200   EAxesBoxType subWinBoxType = sciGetBoxType( pobj ) ;
3201
3202   /* Initialisation phase for x (to detect bug): x set to -1000 F.Leray 05.03.04*/
3203   for(i=0;i<5;i++) { x[i] = -1000 ; }
3204
3205   if(sciGetEntityType (pobj) == SCI_SUBWIN)
3206   {  
3207
3208     updateScale3d( pobj, dbox, xbox, ybox, zbox ) ;
3209     /* Until here we have computed + reset the 3d scale*/
3210     Teta  = ppsubwin->theta  ;
3211     Alpha =  ppsubwin->alpha ;
3212     if( Abs( Teta ) < 0.1 )
3213     {
3214       /* to avoid bug at limit when theta == 0 */
3215       /* I recompute temp value xyzbox with theta == 0.1 */
3216       /* to have a correct xind, InsideU et InsideD */
3217       ComputeCorrectXindAndInsideUD( Teta, Alpha, dbox, xind, InsideU, InsideD ) ;
3218     }
3219     else
3220     {
3221       sciAxesVerticesIndices( InsideU, InsideD, xbox, ybox, xind ) ;
3222     }
3223
3224     /* F.Leray Rajout 02.04.04 :*/
3225     background = sciGetBackground(pobj) ;
3226
3227     for ( i = 0 ; i < 6 ; i++ )
3228     {
3229       ixbox[i]=XScale(xbox[xind[i]]);
3230       iybox[i]=YScale(ybox[xind[i]]);
3231     }
3232     ixbox[6] = ixbox[0] ;
3233     iybox[6] = iybox[0] ;
3234     p = 7 ;
3235     n = 1 ; 
3236
3237     C2F(dr)("xget","pattern",&verbose,&color_old,&zero,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3238     C2F(dr)("xset","pattern",&background,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);     
3239     C2F (dr) ("xarea", "v", &p, ixbox, iybox, &n, PI0, PI0, PD0, PD0, PD0, PD0, 5L,0L);
3240     C2F(dr)("xset","pattern",&color_old,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3241     /***********/
3242     /***  hidden axis */
3243
3244     flag = ppsubwin->axes.flag[2]; /* box drawing */
3245
3246     if ( subWinBoxType != BT_OFF )
3247     { 
3248       x[2] = sciGetLineWidth (pobj);
3249       x[3] = sciGetLineStyle (pobj);
3250       C2F (dr) ("xset","thickness",x+2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3251
3252       hiddencolor = sciSetGoodIndex( pobj, ppsubwin->axes.hiddenAxisColor ) ;
3253
3254       if (zbox[InsideU[0]] > zbox[InsideD[0]])
3255       {
3256         DrawAxis(xbox,ybox,InsideD,hiddencolor);
3257       }  
3258       else
3259       {
3260         DrawAxis(xbox,ybox,InsideU,hiddencolor);        
3261       }
3262       if (Ishidden(pobj))
3263       {
3264         ppsubwin->hiddenstate=(InsideU[0] % 4);
3265       }
3266       else
3267       {
3268         ppsubwin->hiddenstate=(InsideD[0] % 4);
3269       }
3270     }
3271     /**  l'enveloppe cvxe*/
3272     x[0] = sciGetForeground (pobj);      /* F.Leray 05.03.04 Useless or not?? because we used set pattern instead of set foreground (because Windows uses BRUSH and PEN...)*/
3273     /* Wrong explanation: We use sciGetForeground in NG mode and used set foreground in old graphic mode*/
3274     x[2] = sciGetLineWidth (pobj); /* Adding this line 05.03.04*/
3275     x[3] = sciGetLineStyle (pobj);
3276     x[4] = 0; 
3277     C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
3278     C2F(dr)("xget","pattern",&verbose,&pat,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3279     /* We are in axis_3ddraw() and sciGetEntityType (pobj) == SCI_SUBWIN*/
3280     C2F (dr) ("xset", "dashes", x, x, x+4, x+4, x+4,PI0,PD0,PD0,PD0,PD0, 5L, 6L);
3281     C2F (dr) ("xset","foreground",x,x,x+4,x+4,x+4,PI0,PD0,PD0,PD0,PD0,5L,4096); /* F.Leray 05.03.04 Useless too*/
3282     C2F (dr) ("xset","thickness",x+2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3283     C2F (dr) ("xset", "line style", x+3,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3284
3285     p = 7 ;
3286     n = 1 ;
3287     for ( i = 0 ; i < p ; i++ )
3288     {
3289       ixbox[i] = XScale( xbox[ xind[i] ] ) ;
3290       iybox[i] = YScale( ybox[ xind[i] ] ) ;
3291     }
3292     ixbox[p-1]=ixbox[0];iybox[p-1]=iybox[0]; 
3293
3294     if ( subWinBoxType == BT_BACK_HALF || subWinBoxType == BT_ON )
3295     {
3296       C2F(dr)("xpolys","v",ixbox,iybox,x,&n,&p,PI0,PD0,PD0,PD0,PD0,0L,0L);
3297
3298     }
3299     Axes3dStrings2(ixbox,iybox,xind) ;
3300
3301     C2F(dr)("xset","pattern",&pat,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3302     C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3303   }
3304 }
3305 /*-----------------------------------------------------------------------------------------*/
3306 void triedre(sciPointObj *pobj, double *xbox, double *ybox, double *zbox, integer *InsideU, integer *InsideD)
3307 {
3308   integer  x[5],narg = 0;
3309   integer color_kp,verbose = 0,thick_kp ;
3310   integer style_kp[3] ;
3311
3312   C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /*F.Leray Replacement*/
3313   C2F(dr)("xget","thickness",&verbose,&thick_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /*F.Leray addings here*/
3314   C2F(dr)("xget","line style",&verbose,style_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /*F.Leray addings here*/
3315
3316   if(sciGetEntityType (pobj) == SCI_SUBWIN)
3317   {
3318     if(pSUBWIN_FEATURE (pobj)->axes.rect == BT_ON)
3319     {
3320       x[0] = sciGetForeground (pobj);   
3321       x[2] = sciGetLineWidth (pobj);
3322       x[3] = sciGetLineStyle (pobj);
3323       x[4] = 0;
3324
3325       /* C2F (dr) ("xset","foreground",x,x,x+4,x+4,x+4,PI0,PD0,PD0,PD0,PD0,5L,4096);*/
3326       C2F(dr)("xset","pattern",x,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
3327       C2F(dr)("xset","thickness",x+2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3328       C2F(dr)("xset", "line style", x+3,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3329
3330       if (zbox[InsideU[0]] > zbox[InsideD[0]])
3331       {
3332         DrawAxis(xbox,ybox,InsideU,x[0]);
3333       }
3334       else
3335       {
3336         DrawAxis(xbox,ybox,InsideD,x[0]);
3337       }
3338     }
3339   }
3340   C2F(dr)("xset", "line style",&(style_kp[0]),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);/*F.Leray addings here*/
3341   C2F(dr)("xset","thickness",&thick_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);/*F.Leray addings here*/
3342   C2F(dr)("xset","pattern",&color_kp,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /*F.Leray addings here*/
3343
3344 }
3345 /*-----------------------------------------------------------------------------------------*/
3346 /* F.Leray 07.05.04 */
3347 /* This routine rebuild a needed strflag for axis_draw call in sciDrawObj*/
3348 /* It may be less complete than the original strflag given in plot2dn (or other 2D - plot function)
3349 due to less info. Nevertheless this new strflag is sufficient for axis_draw because
3350 tests are on strflag[1] (case =='5' or '6') and strflag[2] */
3351 void rebuild_strflag( sciPointObj * psubwin, char * STRFLAG)
3352 {
3353
3354   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
3355   BOOL isaxes = GetIsAxes2D(psubwin);
3356
3357   /* strflag[0]*/
3358   STRFLAG[0] = '0'; /* flag for caption display unused here so set to NULL by default */
3359   if( pSUBWIN_FEATURE (psubwin)->with_leg == 1)
3360     STRFLAG[0] = '0';
3361   else
3362     STRFLAG[0] = '1';
3363
3364   /* strflag[1]*/
3365   /* Here isoview mode test is not needed because axis_draw do not use it */
3366   STRFLAG[1] = '0'; /* Init. to NULL <=> use the previous scale */
3367   if(ppsubwin->tight_limits == TRUE)
3368   {
3369     STRFLAG[1] = '8';
3370   }
3371   else /* using auto rescale : enlarged for pretty axes*/
3372   {
3373     STRFLAG[1] = '6';
3374   }
3375
3376   /* strflag[2]*/
3377   STRFLAG[2] = '1'; /* Init with y-axis on the left AND axes is on*/
3378   if(isaxes == TRUE)
3379   {
3380     if(ppsubwin->axes.ydir =='l')
3381       STRFLAG[2] = '1';
3382     else if(ppsubwin->axes.ydir =='r')
3383       STRFLAG[2] = '3';
3384     else if((ppsubwin->axes.xdir =='c') && (ppsubwin->axes.ydir =='c'))
3385       STRFLAG[2] = '5';
3386   }
3387   else
3388   {
3389     if(ppsubwin->axes.rect == BT_ON)
3390       STRFLAG[2] = '2';
3391     else
3392       STRFLAG[2] = '0';
3393   }
3394
3395   STRFLAG[3] = '\0';
3396 }
3397 /*-----------------------------------------------------------------------------------------*/
3398
3399 /*----------------------------------------------------------------------------------*/
3400 /* draw the title and the two labels of a 2d axis                                 */
3401 /*----------------------------------------------------------------------------------*/
3402 int labels2D_draw( sciPointObj * psubwin )
3403 {
3404   /* Rewritten by jb Silvy 06/2006 */
3405
3406   integer rect1[4] ;
3407   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (psubwin);
3408   int offset[2] ; /* vertical and horizontal offsets to move labels a little from axes */
3409
3410   if ( !sciGetVisibility(psubwin) )
3411   {
3412     return 0 ;
3413   }
3414
3415   /* get the size of the current subwin in pixels */
3416   rect1[0]= Cscale.WIRect1[0] ; /* upper left point of the axes x coordinate. */
3417   rect1[1]= Cscale.WIRect1[1] ; /* upper left point of the axes y coordinate. */
3418   rect1[2]= Cscale.WIRect1[2] ; /* width of the axes */
3419   rect1[3]= Cscale.WIRect1[3] ; /* height of the axes */
3420
3421   /* the little displacment of the labels from the axes box */
3422   offset[0] = rect1[2] / 50 + 1 ;
3423   offset[1] = rect1[3] / 25 + 1 ;
3424
3425
3426   /*********/
3427   /* TITLE */
3428   /*********/
3429
3430   if ( sciGetVisibility(ppsubwin->mon_title) )
3431   {
3432     /* get the pointer on the title */
3433     sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_title ) ;
3434
3435     /* get position and orientation of the title */
3436     if ( ppLabel->auto_rotation )
3437     {
3438       sciSetFontOrientation( ppsubwin->mon_title, 0 ) ;
3439     }
3440
3441
3442     if ( ppLabel->auto_position )
3443     {
3444       int segmentStart[2] = { rect1[0] + rect1[2], rect1[1] } ;
3445       int segmentEnd[2]   = { rect1[0]           , rect1[1] } ;
3446       computeLabelAutoPos( ppsubwin->mon_title, segmentStart, segmentEnd, offset ) ;
3447     }
3448     /* draw the label */
3449     drawTextEntity( ppLabel->text ) ;
3450
3451   }
3452
3453   /***********/
3454   /* x label */
3455   /***********/
3456
3457   if( sciGetVisibility(ppsubwin->mon_x_label) )
3458   {
3459     /* get the pointer on the title */
3460     sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_x_label ) ;
3461
3462     if( ppLabel->auto_rotation )
3463     {
3464       sciSetFontOrientation(ppsubwin->mon_x_label, 0 ) ;
3465     }
3466
3467
3468     if( ppLabel->auto_position )
3469     {
3470       int segmentStart[2] ;
3471       int segmentEnd[2]   ;
3472
3473       if(ppsubwin->axes.xdir == 'u')
3474       {
3475         segmentStart[0] = rect1[0] + rect1[2] ;
3476         segmentEnd[0]   = rect1[0] ;
3477
3478         /* we add the size of the numbers to the height */
3479         segmentStart[1] = ppsubwin->XGradMostOnTop ;
3480         segmentEnd[1]   = ppsubwin->XGradMostOnTop ;
3481       }
3482       else
3483       {
3484         segmentStart[0] = rect1[0] ;
3485         segmentEnd[0]   = rect1[0] + rect1[2] ;
3486
3487         segmentStart[1] = ppsubwin->XGradMostOnBottom ;
3488         segmentEnd[1]   = ppsubwin->XGradMostOnBottom ;
3489       }
3490       computeLabelAutoPos( ppsubwin->mon_x_label, segmentStart, segmentEnd, offset ) ;
3491     }
3492
3493     drawTextEntity( ppLabel->text ) ;
3494
3495   }
3496
3497
3498   /***********/
3499   /* y label */
3500   /***********/
3501
3502
3503   if ( sciGetVisibility(ppsubwin->mon_y_label) )
3504   {
3505     sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_y_label ) ;
3506
3507     if( ppLabel->auto_rotation )
3508     {
3509       sciInitFontOrientation( ppsubwin->mon_y_label, 270 * 10 ) ;
3510     }
3511
3512     if( ppLabel->auto_position )
3513     {
3514       int segmentStart[2] ;
3515       int segmentEnd[2]   ;
3516
3517       if(ppsubwin->axes.ydir == 'r')
3518       {
3519
3520         /* we add the size of the numbers to the height */
3521         segmentStart[0] = ppsubwin->YGradMostOnRight ;
3522         segmentEnd[0]   = ppsubwin->YGradMostOnRight ;
3523
3524         segmentStart[1] = rect1[1] + rect1[3] ;
3525         segmentEnd[1]   = rect1[1] ;
3526       }
3527       else
3528       {
3529         segmentStart[0] = ppsubwin->YGradMostOnLeft ;
3530         segmentEnd[0]   = ppsubwin->YGradMostOnLeft ;
3531
3532         segmentStart[1] = rect1[1] ;
3533         segmentEnd[1]   = rect1[1] + rect1[3] ;
3534       }
3535       computeLabelAutoPos( ppsubwin->mon_y_label, segmentStart, segmentEnd, offset ) ;
3536     }
3537     drawTextEntity( ppLabel->text ) ;
3538   }
3539
3540   return 0;
3541 }
3542 /*-----------------------------------------------------------------------------------------*/
3543 void DrawAxis(double xbox[8], double ybox[8], integer Indices[4], integer style)
3544 {
3545   integer ixbox[6],iybox[6],npoly=6,lstyle[6],verbose=0,narg_,hiddencolor;
3546   integer i, iflag=0, j=1;
3547   sciPointObj *psubwin;
3548   for ( i = 0 ; i <= 4 ; i=i+2)
3549   {
3550     ixbox[i]=XScale(xbox[Indices[0]]);iybox[i]=YScale(ybox[Indices[0]]);
3551   }
3552   ixbox[1]=XScale(xbox[Indices[1]]);iybox[1]=YScale(ybox[Indices[1]]);
3553   ixbox[3]=XScale(xbox[Indices[2]]);iybox[3]=YScale(ybox[Indices[2]]);
3554   ixbox[5]=XScale(xbox[Indices[3]]);iybox[5]=YScale(ybox[Indices[3]]);
3555   C2F(dr)("xget","line style",&verbose,lstyle,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
3556   /**DJ.Abdemouche 2003**/
3557
3558   psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ()); 
3559   hiddencolor = pSUBWIN_FEATURE (psubwin)->hiddencolor;
3560   j = sciGetLineStyle (psubwin) ;
3561
3562   C2F(dr)("xset","line style",&j,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3563   C2F(dr)("xsegs","v",ixbox,iybox,&npoly,&style,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3564   C2F(dr)("xset","line style",lstyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3565
3566 }
3567 /*-----------------------------------------------------------------------------------------*/
3568 int Axes3dStrings2( integer * ixbox, integer * iybox, integer * xind )
3569 {
3570   integer verbose=0,narg,xz[2],fontid[2],fontsize_kp,color_kp,size;
3571   integer iof,barlengthx = 0,barlengthy = 0, posi[2]; 
3572   integer rect[4],flag=0,x=0,y=0;
3573   double ang=0.0, bbox[6];
3574   int fontsize=-1,textcolor=-1,ticscolor=-1;
3575   int fontstyle=0; /* F.Leray 08.04.04 */
3576   sciPointObj *psubwin = NULL;
3577   sciSubWindow * ppsubwin = NULL;
3578   int ns=2,iflag=0,gstyle,gridStyle=2,dash[6];
3579   double xx[4],yy[4],zz[4],vxx1,vyy1,vzz1;
3580   integer i,xm,ym,vx[2],vy[2],xg[2],yg[2],j;
3581   integer fontid_old[2], textcolor_old;
3582
3583   int lastzindex = 0, lastxindex = 0, lastyindex = 0;
3584   double xminval, yminval, zminval, xmaxval, ymaxval, zmaxval;
3585   int nbtics = 0;
3586   int nbsubtics = 0;
3587
3588   int logrect[4], XX = 0, YY = 0; /* see below */ /* ah ouais ou ca ? */
3589   double angle=0.0;
3590
3591   int constOffset[2] ; /* displacment of labels from the axes segments. */
3592   int maxTicksLabelSize[2] ; /* for each axis the maximum size of ticks label */
3593
3594
3595   psubwin= (sciPointObj *)sciGetSelectedSubWin (sciGetCurrentFigure ());
3596   ppsubwin = pSUBWIN_FEATURE (psubwin);
3597
3598   /** le cot\'e gauche ( c'est tjrs un axe des Z **/
3599   xz[0] = Cscale.WIRect1[2] ;
3600   xz[1] = Cscale.WIRect1[2] ;
3601   iof = (xz[0]+xz[1])/50;
3602
3603   ticscolor = sciGetForeground(psubwin);
3604   textcolor=sciGetFontForeground(psubwin);
3605
3606   fontsize=sciGetFontDeciWidth(psubwin)/100;
3607   fontstyle=sciGetFontStyle(psubwin);
3608
3609   if(sciGetEntityType (psubwin) != SCI_SUBWIN) { 
3610     sciprint("Impossible case\n");
3611     return 0;
3612   }
3613
3614
3615   bbox[0] =  xminval = pSUBWIN_FEATURE (psubwin)->FRect[0]; /*xmin*/
3616   bbox[1] =  xmaxval = pSUBWIN_FEATURE (psubwin)->FRect[2]; /*xmax*/
3617   bbox[2] =  yminval = pSUBWIN_FEATURE (psubwin)->FRect[1]; /*ymin*/
3618   bbox[3] =  ymaxval = pSUBWIN_FEATURE (psubwin)->FRect[3]; /*ymax*/ 
3619   bbox[4] =  zminval = pSUBWIN_FEATURE (psubwin)->FRect[4]; /*zmin*/
3620   bbox[5] =  zmaxval = pSUBWIN_FEATURE (psubwin)->FRect[5]; /*zmax*/
3621
3622   C2F(dr)("xget","font",&verbose,fontid,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3623
3624   fontid[0]= fontstyle;
3625   fontsize_kp = fontid[1] ;
3626   if( fontsize == -1 ){ 
3627     fontid[1]= 1;
3628     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3629   }
3630   else {
3631     fontid[1] = fontsize ;
3632     C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3633   }
3634   if ( textcolor != -1 || ticscolor != -1 ) 
3635     C2F(dr)("xget","pattern",&verbose,&color_kp,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
3636
3637   for (i=0; i<3 ; i++) {
3638     xx[i]=pSUBWIN_FEATURE (psubwin)->axes.xlim[i];
3639     yy[i]=pSUBWIN_FEATURE (psubwin)->axes.ylim[i];
3640     zz[i]=pSUBWIN_FEATURE (psubwin)->axes.zlim[i];
3641   } 
3642
3643   /* main title */ /* We fix the title always at the top */
3644   rect[0]= Cscale.WIRect1[0] ;
3645   rect[1]= Cscale.WIRect1[1] ;
3646   rect[2]= Cscale.WIRect1[2] ;
3647   rect[3]= Cscale.WIRect1[3]/6 ;
3648   textcolor_old = textcolor;
3649   fontid_old[0] = fontid[0];
3650   fontid_old[1] = fontid[1];
3651
3652   constOffset[0] = Cscale.WIRect1[2] / 50 + 1 ;
3653   constOffset[1] = Cscale.WIRect1[3] / 25 + 1 ;
3654
3655   if( sciGetVisibility(ppsubwin->mon_title) )
3656   {
3657     /* get the pointer on the title */
3658     sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_title ) ;
3659
3660     /* get position and orientation of the title */
3661     if ( ppLabel->auto_rotation )
3662     {
3663       sciSetFontOrientation( ppsubwin->mon_title, 0 ) ;
3664     }
3665
3666     if ( ppLabel->auto_position )
3667     {
3668       /* same as in 2d */
3669       int segmentStart[2] = { rect[0] + rect[2], rect[1] } ;
3670       int segmentEnd[2]   = { rect[0]          , rect[1] } ;
3671       computeLabelAutoPos( ppsubwin->mon_title, segmentStart, segmentEnd, constOffset ) ;
3672     }
3673     /* draw the label */
3674     drawTextEntity( ppLabel->text ) ;
3675   }
3676
3677   textcolor = textcolor_old;
3678   fontid[0] = fontid_old[0];
3679   fontid[1] = fontid_old[1];
3680
3681   size = xz[0]>=xz[1] ? (integer) (xz[1]/50.0) : (integer) (xz[0]/50.0); 
3682
3683   /* compute bounding of "10"  string used for log scale ON and auto_ticks ON */
3684   C2F(dr)("xstringl","10",&XX,&YY,logrect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
3685
3686   /********************************************/
3687   /* draw the axis line if axes_visible is on */
3688   /********************************************/
3689   {
3690     int x2[5] ;
3691     int two = 2 ;
3692     int one = 1 ;
3693     int verbose2 = 0 ;
3694     int dash2[6] ;
3695     int pat ;
3696     int narg2 ;
3697     x2[0] = sciGetForeground (psubwin);
3698     x2[2] = sciGetLineWidth (psubwin) ;
3699     x2[3] = sciGetLineStyle (psubwin);
3700     x2[4] = 0;
3701     C2F(dr)("xget","line style",&verbose2,dash2,&narg2,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
3702     C2F(dr)("xget","pattern",&verbose2,&pat,&narg2,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3703     C2F (dr) ("xset", "dashes", x2, x2, x2+4, x2+4, x2+4,PI0,PD0,PD0,PD0,PD0, 5L, 6L);
3704     C2F (dr) ("xset","foreground",x2,x2,x2+4,x2+4,x2+4,PI0,PD0,PD0,PD0,PD0,5L,4096); /* F.Leray 05.03.04 Useless too*/
3705     C2F (dr) ("xset","thickness",x2+2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3706     C2F (dr) ("xset", "line style", x2+3,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3707     if ( ppsubwin->axes.axes_visible[2] )
3708     {
3709       /* draw the line of the axis like in 2d */
3710       /* the two bounds are (ixbox[2],iybox[2]) and (ixbox[2],iybox[2]) */
3711       C2F(dr)("xpolys","v",&(ixbox[2]),&(iybox[2]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
3712     }
3713     if ( ( xind[4]+xind[5] == 3) || ( xind[4]+xind[5] == 11 ) )
3714     {
3715       /* i copy this test but I don't know what it mean... jb Silvy 03/2006 */
3716       if ( ppsubwin->axes.axes_visible[1] )
3717       {
3718         /* draw the line of the axis like in 2d */
3719         /* the two bounds are (ixbox[3],iybox[3]) and (ixbox[3],iybox[3]) */
3720         C2F(dr)("xpolys","v",&(ixbox[3]),&(iybox[3]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
3721       }
3722       if ( ppsubwin->axes.axes_visible[0] )
3723       {
3724         /* draw the line of the axis like in 2d */
3725         /* the two bounds are (ixbox[4],iybox[4]) and (ixbox[4],iybox[4]) */
3726         C2F(dr)("xpolys","v",&(ixbox[4]),&(iybox[4]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
3727       }
3728     }
3729     else
3730     {
3731       if ( ppsubwin->axes.axes_visible[1] )
3732       {
3733         /* draw the line of the axis like in 2d */
3734         /* the two bounds are (ixbox[3],iybox[3]) and (ixbox[3],iybox[3]) */
3735         C2F(dr)("xpolys","v",&(ixbox[4]),&(iybox[4]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
3736       }
3737       if ( ppsubwin->axes.axes_visible[0] )
3738       {
3739         /* draw the line of the axis like in 2d */
3740         /* the two bounds are (ixbox[4],iybox[4]) and (ixbox[4],iybox[4]) */
3741         C2F(dr)("xpolys","v",&(ixbox[3]),&(iybox[3]),x2,&one,&two, PI0,PD0,PD0,PD0,PD0,0L,0L);
3742       }
3743     }
3744     C2F(dr)("xset","pattern",&pat,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3745     C2F(dr)("xset","line style",dash2,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3746   }  
3747
3748   /********************/
3749   /*** le z scaling ***/ /* DISPLAY Z graduations */
3750   /********************/
3751
3752
3753   if (pSUBWIN_FEATURE (psubwin)->project[2]==1)
3754   {
3755     double fx,fy,fz; 
3756     char c_format[5] ;
3757
3758     integer Ticsdir[2];
3759     Ticsdir[0]=ixbox[3]-ixbox[4]; /* <=> en pixel direction/vecteur non norme(e)s des tics en x */
3760     Ticsdir[1]=iybox[3]-iybox[4]; /* <=> idem pour y */
3761     /* NB: for a default plot3d (simply calling plot3d in siclab console) */
3762     /* Ticsdir[0] & Ticsdir[1] are negative : we do min - max here... */
3763
3764     BBoxToval(&fx,&fy,&fz,xind[3],bbox); /* xind[3] <=> en bas a gauche <=> zmin */
3765     x=ixbox[2]-(xz[0]+xz[1])/20;
3766     y=(iybox[3]+iybox[2])/2;
3767
3768     /*       NumberFormat(str,((integer) zz[0]),((integer) zz[2])); */
3769
3770
3771     if( !ppsubwin->axes.auto_ticks[2] )
3772     {
3773       /* we display the z tics specified by the user*/
3774       nbtics = ppsubwin->axes.u_nzgrads;
3775       nbsubtics = ppsubwin->axes.nbsubtics[2];
3776
3777       maxTicksLabelSize[0] = 0 ;
3778       maxTicksLabelSize[1] = 0 ;
3779
3780       for(i=0;i<nbtics;i++)
3781       {
3782         char *foo = ppsubwin->axes.u_zlabels[i]; 
3783         double ztmp = ppsubwin->axes.u_zgrads[i];
3784
3785         if(ztmp<zminval || ztmp>zmaxval) 
3786         {
3787           /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
3788           continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
3789           /* donc autant ne pas aller plus loin dans l'algo... */
3790         }
3791
3792
3793         /***************************************************************/
3794         /************************* COMMON PART *************************/
3795         /***************************************************************/
3796
3797         if( ppsubwin->axes.reverse[2] )
3798         {
3799           ztmp = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],ztmp);
3800         }
3801
3802         ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&ztmp);
3803
3804
3805         vx[0]=xm;vy[0]=ym;
3806
3807         barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
3808         barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
3809         vx[1]=vx[0]+barlengthx;
3810         vy[1]=vy[0]+barlengthy;
3811
3812         /* foo is set above with sprintf(foo,c_format,xtmp); */
3813
3814         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
3815
3816         /* get the size of ticks label */
3817         C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3818         maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
3819         maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
3820
3821
3822         posi[0] = inint( xm+2*barlengthx - rect[2]); 
3823         posi[1]=inint( ym + 2*barlengthy + rect[3]/2);
3824
3825
3826         if(ppsubwin->axes.axes_visible[2] == TRUE){
3827           C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3828           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3829           C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
3830           C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3831           C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3832         }
3833         /* grid to put here */
3834         if ( ppsubwin->grid[2] > -1 && ppsubwin->axes.axes_visible[2] )
3835         {
3836           gstyle = pSUBWIN_FEATURE (psubwin)->grid[2];
3837
3838           if((ppsubwin->logflags[2] =='l') && (i != nbtics-1))
3839           {
3840             double tmp[2];
3841             double pas=0;
3842             double * tmp_log_grads = (double *) NULL;
3843
3844
3845             double * grads = ppsubwin->axes.u_zgrads;
3846
3847             tmp[0] = exp10(grads[i]);
3848             tmp[1] = exp10(grads[i+1]);
3849             pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
3850
3851             if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
3852               sciprint("Error allocating tmp_log_grads\n");
3853               return -1;
3854             }
3855
3856             for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
3857
3858             for(j=0;j<nbsubtics;j++)
3859             {
3860               vzz1 = tmp_log_grads[j];
3861
3862               if(vzz1<=zminval || vzz1>=zmaxval) continue;       
3863
3864               if(ppsubwin->axes.reverse[2] == TRUE)
3865                 vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
3866
3867               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
3868
3869               /*  if ((ym != iybox[3]) && (ym != iybox[2])) */
3870               /*                            { */
3871               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3872               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3873               xg[0]= ixbox[3];yg[0]= ym;
3874               if (Ishidden(psubwin))
3875               {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
3876               else
3877               {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
3878               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3879               xg[0]=xg[1];  ; xg[1] =ixbox[0];
3880               yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
3881               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3882               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3883               /*   } */
3884             }
3885             FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
3886           }
3887           else
3888           { 
3889             if(ztmp>zminval && ztmp<zmaxval) 
3890             {
3891               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3892               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3893               xg[0]= ixbox[3];yg[0]= ym;
3894               if (Ishidden(psubwin))
3895               {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
3896               else
3897               {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
3898               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3899               xg[0]=xg[1];  ; xg[1] =ixbox[0];
3900               yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
3901               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3902               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
3903             }
3904           }
3905         }
3906
3907         /* and subtics */
3908         if(i != nbtics-1)
3909         {
3910           if(ppsubwin->logflags[2] =='l')
3911           {
3912             double tmp[2];
3913             double pas=0;
3914             double * tmp_log_grads = (double *) NULL;
3915
3916
3917             double * grads = ppsubwin->axes.u_zgrads;
3918
3919             tmp[0] = exp10(grads[i]);
3920             tmp[1] = exp10(grads[i+1]);
3921             pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
3922
3923             if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
3924               sciprint("Error allocating tmp_log_grads\n");
3925               return -1;
3926             }
3927
3928             for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
3929
3930             for(j=0;j<nbsubtics;j++)
3931             {
3932               vzz1 = tmp_log_grads[j];
3933
3934               if(vzz1<zminval || vzz1>zmaxval) continue;
3935
3936               if(ppsubwin->axes.reverse[2] == TRUE)
3937                 vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
3938
3939               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
3940
3941               vx[0]=xm;vy[0]=ym;
3942               vx[1]= (integer) (vx[0]+barlengthx/2.0);
3943               vy[1]= (integer) (vy[0]+barlengthy/2.0);
3944
3945               if(ppsubwin->axes.axes_visible[2] == TRUE)
3946                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3947             }
3948             FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
3949           } /* end NEW */
3950           else
3951           {
3952             double xtmp = ppsubwin->axes.u_zgrads[i];
3953             double dx = (ppsubwin->axes.u_zgrads[i+1] - ppsubwin->axes.u_zgrads[i]) / nbsubtics;
3954             for(j=0;j<nbsubtics;j++)
3955             {
3956               vzz1=xtmp+dx*j;
3957
3958               if(vzz1<zminval || vzz1>zmaxval) continue;         
3959
3960               if(ppsubwin->axes.reverse[2] == TRUE)
3961                 vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
3962
3963               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
3964               /*                      trans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1); */
3965
3966
3967               vx[0]=xm;vy[0]=ym;
3968               vx[1]= (integer) (vx[0]+barlengthx/2.0);
3969               vy[1]= (integer) (vy[0]+barlengthy/2.0);
3970
3971               if(ppsubwin->axes.axes_visible[2] == TRUE)
3972                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
3973             }
3974           } 
3975         }
3976
3977         /***************************************************************/
3978         /************************* END OF COMMON PART ******************/
3979         /***************************************************************/
3980       }
3981     }
3982     else /* we display the computed tics */
3983     {
3984       AdaptGraduationsOnZ(x,y,size,Ticsdir,fontid,psubwin,zminval,zmaxval,fx,fy,0.);
3985
3986       lastzindex = ppsubwin->axes.nzgrads - 1;
3987
3988       if(lastzindex == 0)
3989         ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.zgrads[0]));
3990       else
3991         ChoixFormatE(c_format,
3992         ppsubwin->axes.zgrads[0],
3993         ppsubwin->axes.zgrads[lastzindex],
3994         ((ppsubwin->axes.zgrads[lastzindex])-(ppsubwin->axes.zgrads[0]))/(lastzindex));
3995
3996       nbtics = ppsubwin->axes.nzgrads;
3997       nbsubtics = ppsubwin->axes.nbsubtics[2];
3998
3999       maxTicksLabelSize[0] = 0 ;
4000       maxTicksLabelSize[1] = 0 ;
4001
4002       for(i=0;i<nbtics;i++)
4003       {
4004         char foo[256]; 
4005         double ztmp = ppsubwin->axes.zgrads[i];
4006
4007         if(ztmp<zminval || ztmp>zmaxval) 
4008         {
4009           /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
4010           continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
4011           /* donc autant ne pas aller plus loin dans l'algo... */
4012         }
4013
4014         sprintf(foo,c_format,ztmp);
4015
4016         /***************************************************************/
4017         /************************* COMMON PART *************************/
4018         /***************************************************************/
4019         if(ppsubwin->axes.reverse[2] == TRUE)
4020           ztmp = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],ztmp);
4021
4022         ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&ztmp);
4023
4024         /*            trans3d(psubwin,1,&xm,&ym,&fx,&fy,&ztmp); */
4025
4026
4027         vx[0]=xm;vy[0]=ym;
4028
4029         barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4030         barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4031         vx[1]=vx[0]+barlengthx;
4032         vy[1]=vy[0]+barlengthy;
4033
4034         /* foo is set above with sprintf(foo,c_format,xtmp); */
4035
4036         C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
4037
4038         /* get the size of ticks label */
4039         C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4040         maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
4041         maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
4042
4043         posi[0] = inint( xm+2*barlengthx - rect[2]); 
4044         posi[1]=inint( ym + 2*barlengthy + rect[3]/2);
4045
4046         if(ppsubwin->axes.axes_visible[2] == TRUE){
4047           C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4048           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4049           if ( ppsubwin->logflags[2] == 'l' )
4050           {
4051             int smallersize = fontid[1]-2;
4052             int old_rect10[4];
4053             /*              char str[2] = "xv"; */
4054             int posi10[2];
4055
4056             posi10[0] = posi[0] - logrect[2];
4057             posi10[1] = posi[1] + logrect[3];
4058
4059             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4060             C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
4061
4062             C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4063
4064             posi[0] = old_rect10[0] + old_rect10[2];
4065             posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
4066
4067             C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4068             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
4069
4070             /* put back the current fontid */
4071             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4072           }
4073           else{
4074             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
4075           }
4076
4077           C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
4078           C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4079         }
4080         /* grid to put here */
4081         if ( ppsubwin->grid[2] > -1 && ppsubwin->axes.axes_visible[2] )
4082         {
4083           gstyle = pSUBWIN_FEATURE (psubwin)->grid[2];
4084
4085           if((ppsubwin->logflags[2] =='l') && (i != nbtics-1))
4086           {
4087             double tmp[2];
4088             double pas=0;
4089             double * tmp_log_grads = (double *) NULL;
4090
4091
4092             double * grads = ppsubwin->axes.zgrads;
4093
4094             tmp[0] = exp10(grads[i]);
4095             tmp[1] = exp10(grads[i+1]);
4096             pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
4097
4098             if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
4099               sciprint("Error allocating tmp_log_grads\n");
4100               return -1;
4101             }
4102
4103             for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
4104
4105             for(j=0;j<nbsubtics;j++)
4106             {
4107               vzz1 = tmp_log_grads[j];
4108
4109               if(vzz1<=zminval || vzz1>=zmaxval) continue;       
4110
4111               if(ppsubwin->axes.reverse[2] == TRUE)
4112                 vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
4113
4114               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
4115
4116               /*  if ((ym != iybox[3]) && (ym != iybox[2])) */
4117               /*                            { */
4118               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4119               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4120               xg[0]= ixbox[3];yg[0]= ym;
4121               if (Ishidden(psubwin))
4122               {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
4123               else
4124               {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
4125               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4126               xg[0]=xg[1];  ; xg[1] =ixbox[0];
4127               yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
4128               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4129               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4130               /*   } */
4131             }
4132             FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
4133           }
4134           else
4135           {
4136             if(ztmp>zminval && ztmp<zmaxval) 
4137             {
4138               C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4139               C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4140               xg[0]= ixbox[3];yg[0]= ym;
4141               if (Ishidden(psubwin))
4142               {  xg[1]=ixbox[4];  yg[1]= iybox[4]- iybox[3]+ym;}
4143               else
4144               {xg[1]=ixbox[1];  yg[1]= iybox[1]- iybox[2]+ym;}
4145               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4146               xg[0]=xg[1];  ; xg[1] =ixbox[0];
4147               yg[0]=yg[1]; yg[1]= ym- iybox[3]+ iybox[5];
4148               C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4149               C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4150             }
4151           }
4152         }
4153
4154         /* and subtics */
4155         if(i != nbtics-1)
4156         {
4157           if(ppsubwin->logflags[2] =='l')
4158           {
4159             double tmp[2];
4160             double pas=0;
4161             double * tmp_log_grads = (double *) NULL;
4162
4163
4164             double * grads = ppsubwin->axes.zgrads;
4165
4166             tmp[0] = exp10(grads[i]);
4167             tmp[1] = exp10(grads[i+1]);
4168             pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
4169
4170             if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
4171               sciprint("Error allocating tmp_log_grads\n");
4172               return -1;
4173             }
4174
4175             for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
4176
4177             for(j=0;j<nbsubtics;j++)
4178             {
4179               vzz1 = tmp_log_grads[j];
4180
4181               if(vzz1<zminval || vzz1>zmaxval) continue;
4182
4183               if(ppsubwin->axes.reverse[2] == TRUE)
4184                 vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
4185
4186               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
4187
4188               vx[0]=xm;vy[0]=ym;
4189               vx[1]= (integer) (vx[0]+barlengthx/2.0);
4190               vy[1]= (integer) (vy[0]+barlengthy/2.0);
4191
4192               if(ppsubwin->axes.axes_visible[2] == TRUE)
4193                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4194             }
4195             FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
4196           } /* end NEW */
4197           else
4198           {
4199             double ztmp2 = ppsubwin->axes.zgrads[i];
4200             double dz = (ppsubwin->axes.zgrads[i+1] - ppsubwin->axes.zgrads[i]) / nbsubtics;
4201             for(j=0;j<nbsubtics;j++)
4202             {
4203               vzz1=ztmp2+dz*j;
4204
4205               if(vzz1<zminval || vzz1>zmaxval) continue;
4206
4207               if(ppsubwin->axes.reverse[2] == TRUE)
4208                 vzz1 = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],vzz1);
4209
4210               ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1);
4211               /*                      trans3d(psubwin,1,&xm,&ym,&fx,&fy,&vzz1); */
4212
4213
4214               vx[0]=xm;vy[0]=ym;
4215               vx[1]= (integer) (vx[0]+barlengthx/2.0);
4216               vy[1]= (integer) (vy[0]+barlengthy/2.0);
4217
4218               if(ppsubwin->axes.axes_visible[2] == TRUE)
4219                 C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4220             }
4221           }
4222         }
4223         /***************************************************************/
4224         /************************* END OF COMMON PART ******************/
4225         /***************************************************************/
4226
4227       }
4228     }
4229   }
4230
4231   if ( sciGetVisibility(ppsubwin->mon_z_label) )
4232   {
4233     /* draw z label */
4234     sciLabel * ppLabel = pLABEL_FEATURE(ppsubwin->mon_z_label) ;
4235
4236     if ( ppLabel->auto_rotation )
4237     {
4238       /* mult by 10 because */
4239       sciSetFontOrientation(ppsubwin->mon_z_label, 270 * 10 ) ;
4240     }
4241
4242     if( ppLabel->auto_position )
4243     {
4244
4245       int segmentStart[2] = { ixbox[2], iybox[2] } ;
4246       int segmentEnd[2]   = { ixbox[3], iybox[3] } ;
4247
4248       /* add the bar size and ticks label size to the offset */
4249       int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
4250         constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
4251       computeLabelAutoPos( ppsubwin->mon_z_label, segmentStart, segmentEnd, offset ) ;
4252     }
4253     /* a trick to force the display with 2d scale */
4254     drawTextEntity( ppLabel->text ) ;
4255
4256   }
4257
4258
4259   /***********************/ /** bottom right side ***/
4260   /*** le  x-y scaling ***/ /* DISPLAY x or y graduations */
4261   /***********************/
4262
4263
4264   if (( xind[4]+xind[5] == 3) || ( xind[4]+xind[5] == 11))
4265   {
4266     if (pSUBWIN_FEATURE (psubwin)->project[0]==1) /* x HERE */
4267     {
4268       double fx,fy,fz;
4269       char c_format[5];
4270
4271       integer Ticsdir[2]; 
4272       Ticsdir[0]=ixbox[4]-ixbox[3];
4273       Ticsdir[1]=iybox[4]-iybox[3];
4274       BBoxToval(&fx,&fy,&fz,xind[4],bbox);
4275       x=inint((ixbox[4]+ixbox[5])/2+1.5*rect[2] +iof);
4276       y=inint(((2/3.0)*iybox[4]+(1/3.0)*iybox[5])+1.5*rect[3]+iof);
4277
4278       if( !ppsubwin->axes.auto_ticks[0] )
4279       {
4280         /* we display the x tics specified by the user*/
4281         nbtics = ppsubwin->axes.u_nxgrads;
4282         nbsubtics = ppsubwin->axes.nbsubtics[0];
4283
4284         maxTicksLabelSize[0] = 0 ;
4285         maxTicksLabelSize[1] = 0 ;
4286
4287         for(i=0;i<nbtics;i++)
4288         {
4289           char *foo = ppsubwin->axes.u_xlabels[i]; 
4290           double xtmp = ppsubwin->axes.u_xgrads[i];
4291
4292           if(xtmp<xminval || xtmp>xmaxval) 
4293           {
4294             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
4295             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
4296             /* donc autant ne pas aller plus loin dans l'algo... */
4297           }
4298
4299           /***************************************************************/
4300           /************************* COMMON PART *************************/
4301           /***************************************************************/
4302
4303           if(ppsubwin->axes.reverse[0] == TRUE)
4304             xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
4305
4306           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
4307           /*   trans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz); */
4308
4309
4310           vx[0]=xm;vy[0]=ym;
4311
4312           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4313           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4314
4315           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
4316
4317           /* get the size of the icks label */
4318           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4319           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
4320           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
4321
4322
4323           if (IsDownAxes(psubwin)){
4324             vx[1]=vx[0];
4325             vy[1]=vy[0]+iof/2;
4326             posi[0] = inint(xm-rect[2]/2); 
4327             posi[1]=inint( vy[0] + iof + rect[3]);}
4328           else{
4329             vx[1]=vx[0]+barlengthx;
4330             vy[1]=vy[0]+barlengthy;
4331             posi[0] = inint( xm+2*barlengthx);
4332             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
4333
4334           if( ppsubwin->axes.axes_visible[0] )
4335           {    
4336             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4337             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4338             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
4339             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
4340             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4341           }
4342           /* grid to put here */
4343           if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0] )
4344           {
4345             gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
4346
4347             if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
4348             {
4349               double tmp[2];
4350               double pas=0;
4351               double * tmp_log_grads = (double *) NULL;
4352
4353
4354               double * grads = ppsubwin->axes.u_xgrads;
4355
4356               tmp[0] = exp10(grads[i]);
4357               tmp[1] = exp10(grads[i+1]);
4358               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
4359
4360               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
4361                 sciprint("Error allocating tmp_log_grads\n");
4362                 return -1;
4363               }
4364
4365               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
4366
4367               for(j=0;j<nbsubtics;j++)
4368               {
4369                 vxx1 = tmp_log_grads[j];
4370
4371                 if(vxx1<=xminval || vxx1>=xmaxval) continue;
4372
4373                 if(ppsubwin->axes.reverse[0] == TRUE)
4374                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
4375
4376                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
4377
4378                 /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
4379                 /*                              {  */
4380                 xg[0]= xm;  yg[0]= ym;  
4381                 if (Ishidden(psubwin)) 
4382                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
4383                 else
4384                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
4385
4386                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4387                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4388                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4389                 xg[0]= xg[1]; yg[0]= yg[1];
4390                 xg[1] = ixbox[3] - ixbox[4] +xm; 
4391                 yg[1]=  iybox[2] - iybox[4] +ym;
4392                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4393                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
4394                 /*      } */
4395               }
4396               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
4397             }
4398             else
4399             {
4400               if(xtmp>xminval && xtmp<xmaxval) 
4401               {
4402                 xg[0]= xm;  yg[0]= ym;  
4403                 if (Ishidden(psubwin)) 
4404                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
4405                 else
4406                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
4407                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4408                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4409                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4410                 xg[0]= xg[1]; yg[0]= yg[1];
4411                 xg[1] = ixbox[3] - ixbox[4] +xm; 
4412                 yg[1]=  iybox[2] - iybox[4] +ym;
4413                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4414                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
4415               }
4416             }
4417           }
4418
4419           /* and subtics */
4420           if(i != nbtics-1)
4421           {
4422             if(ppsubwin->logflags[0] =='l')
4423             {
4424               double tmp[2];
4425               double pas=0;
4426               double * tmp_log_grads = (double *) NULL;
4427
4428
4429               double * grads = ppsubwin->axes.u_xgrads;
4430
4431               tmp[0] = exp10(grads[i]);
4432               tmp[1] = exp10(grads[i+1]);
4433               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
4434
4435               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
4436                 sciprint("Error allocating tmp_log_grads\n");
4437                 return -1;
4438               }
4439
4440               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
4441
4442               for(j=0;j<nbsubtics;j++)
4443               {
4444                 vxx1 = tmp_log_grads[j];
4445
4446                 if(vxx1<xminval || vxx1>xmaxval) continue;
4447
4448                 if(ppsubwin->axes.reverse[0] == TRUE)
4449                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
4450
4451                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
4452
4453                 if (IsDownAxes(psubwin))
4454                 {
4455                   vx[1]=vx[0]=xm;
4456                   vy[0]=ym;
4457                   vy[1]=vy[0]+iof/4;
4458                 }
4459                 else
4460                 {
4461                   vx[0]=xm;vy[0]=ym;
4462                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
4463                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
4464                 }
4465
4466                 if(ppsubwin->axes.axes_visible[0] == TRUE)
4467                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4468               }
4469
4470               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
4471             } /* end NEW */
4472             else
4473             {
4474               double xtmp2 = ppsubwin->axes.u_xgrads[i];
4475               double dx = (ppsubwin->axes.u_xgrads[i+1] - ppsubwin->axes.u_xgrads[i]) / nbsubtics;
4476
4477               for (j=1;j<nbsubtics;j++)
4478               {  
4479                 vxx1=xtmp2+dx*j;
4480
4481                 if(vxx1<xminval || vxx1>xmaxval) continue;
4482
4483                 if(ppsubwin->axes.reverse[0] == TRUE)
4484                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
4485
4486                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
4487                 /*                        trans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz); */
4488
4489
4490                 if (IsDownAxes(psubwin))
4491                 {
4492                   vx[1]=vx[0]=xm;
4493                   vy[0]=ym;
4494                   vy[1]=vy[0]+iof/4;
4495                 }
4496                 else
4497                 {
4498                   vx[0]=xm;vy[0]=ym;
4499                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
4500                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
4501                 }
4502
4503                 if(ppsubwin->axes.axes_visible[0] == TRUE)   
4504                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4505               }
4506             }
4507           }
4508           /***************************************************************/
4509           /************************* END OF COMMON PART ******************/
4510           /***************************************************************/
4511
4512         }
4513       }
4514       else /* we display the computed tics */
4515       {
4516         AdaptGraduationsOnXBottomRight(iof,x,y,size,Ticsdir,fontid,psubwin,xminval,xmaxval,0.,fy,fz);
4517
4518         lastxindex = ppsubwin->axes.nxgrads - 1;
4519
4520         if(lastxindex == 0)
4521         {
4522           ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.xgrads[0]));
4523         }
4524         else
4525         {
4526           ChoixFormatE(c_format,
4527             ppsubwin->axes.xgrads[0],
4528             ppsubwin->axes.xgrads[lastxindex],
4529             ((ppsubwin->axes.xgrads[lastxindex])-(ppsubwin->axes.xgrads[0]))/(lastxindex));
4530         }
4531
4532         nbtics = ppsubwin->axes.nxgrads;
4533         nbsubtics = ppsubwin->axes.nbsubtics[0];
4534
4535         maxTicksLabelSize[0] = 0 ;
4536         maxTicksLabelSize[1] = 0 ;
4537
4538         for(i=0;i<nbtics;i++)
4539         {
4540           char foo[256]; 
4541           double xtmp = ppsubwin->axes.xgrads[i];
4542
4543           if(xtmp<xminval || xtmp>xmaxval) 
4544           {
4545             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
4546             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
4547             /* donc autant ne pas aller plus loin dans l'algo... */
4548           }
4549
4550           sprintf(foo,c_format,xtmp);
4551
4552           /***************************************************************/
4553           /************************* COMMON PART *************************/
4554           /***************************************************************/
4555
4556
4557           /* F.Leray 03.11.04 Test if log scale to perform a : exp10(x) because trans3d will */
4558           /* re-do a log10() (that is needed for data computations) */
4559
4560           if( ppsubwin->axes.reverse[0] )
4561           {
4562             xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
4563           }
4564
4565           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
4566
4567           vx[0]=xm;vy[0]=ym; 
4568
4569           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4570           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4571
4572           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
4573
4574           /* get the size of ticks label */
4575           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4576           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
4577           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
4578
4579           if (IsDownAxes(psubwin)){
4580             vx[1]=vx[0];
4581             vy[1]=vy[0]+iof/2;
4582             posi[0] = inint(xm-rect[2]/2); 
4583             posi[1]=inint( vy[0] + iof + rect[3]);}
4584           else{
4585             vx[1]=vx[0]+barlengthx;
4586             vy[1]=vy[0]+barlengthy;
4587             posi[0] = inint( xm+2*barlengthx);
4588             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
4589
4590           if( ppsubwin->axes.axes_visible[0] )
4591           {
4592             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4593             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4594             if ( ppsubwin->logflags[0] == 'l' )
4595             {
4596               int smallersize = fontid[1]-2;
4597               int old_rect10[4];
4598               int posi10[2];
4599
4600               posi10[0] = posi[0] - logrect[2];
4601               posi10[1] = posi[1] + logrect[3];
4602
4603               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4604               C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
4605
4606               C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4607
4608               posi[0] = old_rect10[0] + old_rect10[2];
4609               posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
4610
4611               C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4612               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
4613
4614               /* put back the current fontid */
4615               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4616             }
4617             else
4618             {
4619               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
4620             }       
4621             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
4622             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4623           }
4624           /* grid to put here */
4625           if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0]  )
4626           {
4627             gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
4628
4629             if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
4630             {
4631               double tmp[2];
4632               double pas=0;
4633               double * tmp_log_grads = (double *) NULL;
4634
4635
4636               double * grads = ppsubwin->axes.xgrads;
4637
4638               tmp[0] = exp10(grads[i]);
4639               tmp[1] = exp10(grads[i+1]);
4640               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
4641
4642               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
4643                 sciprint("Error allocating tmp_log_grads\n");
4644                 return -1;
4645               }
4646
4647               for(j=0;j<nbsubtics;j++)
4648               {
4649                 tmp_log_grads[j] = log10( tmp[0] + (j) * pas ) ;
4650               }
4651
4652               for(j=0;j<nbsubtics;j++)
4653               {
4654                 vxx1 = tmp_log_grads[j];
4655
4656                 if(vxx1<=xminval || vxx1>=xmaxval) continue;
4657
4658                 if(ppsubwin->axes.reverse[0] == TRUE)
4659                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
4660
4661                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
4662
4663                 /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
4664                 /*                              {  */
4665                 xg[0]= xm;  yg[0]= ym;  
4666                 if (Ishidden(psubwin)) 
4667                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
4668                 else
4669                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
4670
4671                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4672                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4673                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4674                 xg[0]= xg[1]; yg[0]= yg[1];
4675                 xg[1] = ixbox[3] - ixbox[4] +xm; 
4676                 yg[1]=  iybox[2] - iybox[4] +ym;
4677                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4678                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
4679                 /*      } */
4680               }
4681               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
4682             }
4683             else
4684             {
4685               if(xtmp>xminval && xtmp<xmaxval) 
4686               {
4687                 xg[0]= xm;  yg[0]= ym;  
4688                 if (Ishidden(psubwin)) 
4689                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
4690                 else
4691                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
4692                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4693                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4694                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4695                 xg[0]= xg[1]; yg[0]= yg[1];
4696                 xg[1] = ixbox[3] - ixbox[4] +xm; 
4697                 yg[1]=  iybox[2] - iybox[4] +ym;
4698                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4699                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
4700               }
4701             }   
4702           }
4703
4704           /* and subtics */
4705           if(i != nbtics-1) /* F.Leray NEW 03.11.04 */
4706           {
4707
4708             if(ppsubwin->logflags[0] =='l')
4709             {
4710               double tmp[2];
4711               double pas=0;
4712               double * tmp_log_grads = (double *) NULL;
4713
4714
4715               double * grads = ppsubwin->axes.xgrads;
4716
4717               tmp[0] = exp10(grads[i]);
4718               tmp[1] = exp10(grads[i+1]);
4719               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
4720
4721               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
4722                 sciprint("Error allocating tmp_log_grads\n");
4723                 return -1;
4724               }
4725
4726               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
4727
4728               for(j=0;j<nbsubtics;j++)
4729               {
4730                 vxx1 = tmp_log_grads[j];
4731
4732                 if(vxx1<xminval || vxx1>xmaxval) continue;
4733
4734                 if(ppsubwin->axes.reverse[0] == TRUE)
4735                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
4736
4737                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
4738
4739                 if (IsDownAxes(psubwin))
4740                 {
4741                   vx[1]=vx[0]=xm;
4742                   vy[0]=ym;
4743                   vy[1]=vy[0]+iof/4;
4744                 }
4745                 else
4746                 {
4747                   vx[0]=xm;vy[0]=ym;
4748                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
4749                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
4750                 }
4751
4752                 if( ppsubwin->axes.axes_visible[0] )
4753                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4754               }
4755
4756               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
4757             } /* end NEW */
4758             else
4759             {
4760               double xtmp2 = ppsubwin->axes.xgrads[i];
4761               double dx = (ppsubwin->axes.xgrads[i+1] - ppsubwin->axes.xgrads[i]) / nbsubtics;
4762
4763               for (j=1;j<nbsubtics;j++)
4764               {  
4765                 vxx1=xtmp2+dx*j;
4766
4767                 if(vxx1<xminval || vxx1>xmaxval) continue;
4768
4769                 if(ppsubwin->axes.reverse[0] == TRUE)
4770                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
4771
4772                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
4773
4774                 if (IsDownAxes(psubwin))
4775                 {
4776                   vx[1]=vx[0]=xm;
4777                   vy[0]=ym;
4778                   vy[1]=vy[0]+iof/4;
4779                 }
4780                 else
4781                 {
4782                   vx[0]=xm;vy[0]=ym;
4783                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
4784                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
4785                 }
4786
4787                 if(ppsubwin->axes.axes_visible[0] == TRUE)
4788                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4789               }
4790             }
4791           }
4792
4793           /***************************************************************/
4794           /************************* END OF COMMON PART ******************/
4795           /***************************************************************/
4796
4797         }
4798       }
4799     }
4800     if ( sciGetVisibility(ppsubwin->mon_x_label) )
4801     {
4802       sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_x_label ) ;
4803       if( ppLabel->auto_rotation )
4804       {
4805         sciSetFontOrientation(ppsubwin->mon_x_label, 0) ;
4806       }
4807
4808
4809       if( ppLabel->auto_position )
4810       {
4811
4812         int segmentStart[2] = { ixbox[4], iybox[4] } ;
4813         int segmentEnd[2]   = { ixbox[5], iybox[5] } ;
4814
4815         /* add the bar size and ticks label size to the offset */
4816         int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
4817           constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
4818         computeLabelAutoPos( ppsubwin->mon_x_label, segmentStart, segmentEnd, offset ) ;
4819       }
4820       /* a trick to force the display with 2d scale */
4821       drawTextEntity( ppLabel->text ) ;
4822
4823     }
4824   }
4825   else
4826   {
4827
4828     if ( pSUBWIN_FEATURE (psubwin)->project[1]==1) /* y is HERE */
4829     {
4830       double fx,fy,fz; 
4831       char c_format[5];
4832
4833       integer Ticsdir[2];
4834       Ticsdir[0]=ixbox[4]-ixbox[3];
4835       Ticsdir[1]=iybox[4]-iybox[3];
4836       BBoxToval(&fx,&fy,&fz,xind[4],bbox);
4837
4838       x=inint((ixbox[4]+ixbox[5])/2+1.5*rect[2] +iof);
4839       y=inint(((2/3.0)*iybox[4]+(1/3.0)*iybox[5])+1.5*rect[3]+iof);
4840
4841       if(ppsubwin->axes.auto_ticks[1] == FALSE)
4842       {
4843         /* we display the y tics specified by the user*/
4844         nbtics = ppsubwin->axes.u_nygrads;
4845         nbsubtics = ppsubwin->axes.nbsubtics[1];
4846
4847         maxTicksLabelSize[0] = 0 ;
4848         maxTicksLabelSize[1] = 0 ;
4849
4850         for(i=0;i<nbtics;i++)
4851         {
4852           char *foo = ppsubwin->axes.u_ylabels[i]; 
4853           double ytmp = ppsubwin->axes.u_ygrads[i];
4854
4855           if(ytmp<yminval || ytmp>ymaxval) 
4856           {
4857             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
4858             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
4859             /* donc autant ne pas aller plus loin dans l'algo... */
4860           }
4861
4862
4863           /***************************************************************/
4864           /************************* COMMON PART *************************/
4865           /***************************************************************/
4866
4867           if(ppsubwin->axes.reverse[1] == TRUE)
4868             ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
4869
4870           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
4871           /*              trans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz); */
4872
4873
4874
4875           vx[0]=xm;vy[0]=ym;
4876
4877           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4878           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
4879           /*    NumberFormat(foo,((integer) (yy[0] + i*ceil((yy[1]-yy[0])/yy[3]))), */
4880           /*                         ((integer) yy[2])); */
4881           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
4882
4883           /* get the size of the ticks */
4884           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4885           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
4886           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
4887
4888
4889           if (IsDownAxes(psubwin)){
4890             vx[1]=vx[0];
4891             vy[1]=vy[0]+iof/2;
4892             posi[0] = inint(xm-rect[2]/2); 
4893             posi[1]=inint( vy[0] + iof + rect[3]);}
4894           else{ 
4895             vx[1]=vx[0]+barlengthx;
4896             vy[1]=vy[0]+barlengthy;
4897             /*              posi[0] = inint( xm+2*barlengthx - rect[2]/2); */
4898             /*              posi[0] = inint( xm+2*barlengthx - rect[2]); */
4899             posi[0] = inint( xm+2*barlengthx);
4900             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
4901
4902           if(ppsubwin->axes.axes_visible[1] == TRUE){
4903             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4904             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4905             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
4906             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
4907             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4908           }
4909           /* grid to put here */
4910           if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
4911           {
4912             gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
4913
4914             if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
4915             {
4916               double tmp[2];
4917               double pas=0;
4918               double * tmp_log_grads = (double *) NULL;
4919
4920
4921               double * grads = ppsubwin->axes.u_ygrads;
4922
4923               tmp[0] = exp10(grads[i]);
4924               tmp[1] = exp10(grads[i+1]);
4925               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
4926
4927               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
4928                 sciprint("Error allocating tmp_log_grads\n");
4929                 return -1;
4930               }
4931
4932               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
4933
4934               for(j=0;j<nbsubtics;j++)
4935               {
4936                 vyy1 = tmp_log_grads[j];
4937
4938                 if(vyy1<=yminval || vyy1>=ymaxval) continue;
4939
4940                 if(ppsubwin->axes.reverse[1] == TRUE)
4941                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
4942
4943                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
4944
4945                 /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
4946                 /*                              {  */
4947                 xg[0]= xm;  yg[0]= ym;  
4948                 if (Ishidden(psubwin))
4949                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
4950                 else
4951                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
4952                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4953                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4954                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4955                 xg[0]= xg[1]; yg[0]= yg[1];
4956                 xg[1] = ixbox[3] - ixbox[4] +xm; 
4957                 yg[1]=  iybox[2] - iybox[4] +ym;
4958                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4959                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
4960                 /*      } */
4961               }
4962               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
4963             }
4964             else
4965             {
4966               if(ytmp>yminval && ytmp<ymaxval) 
4967               {
4968                 xg[0]= xm;  yg[0]= ym;  
4969                 if (Ishidden(psubwin))
4970                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
4971                 else
4972                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
4973                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4974                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
4975                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4976                 xg[0]= xg[1]; yg[0]= yg[1];
4977                 xg[1] = ixbox[3] - ixbox[4] +xm; 
4978                 yg[1]=  iybox[2] - iybox[4] +ym;
4979                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
4980                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
4981               }
4982             }
4983           }
4984
4985           /* and subtics */
4986           if(i != nbtics-1)
4987           {
4988             if(ppsubwin->logflags[1] =='l')
4989             {
4990               double tmp[2];
4991               double pas=0;
4992               double * tmp_log_grads = (double *) NULL;
4993
4994
4995               double * grads = ppsubwin->axes.u_ygrads;
4996
4997               tmp[0] = exp10(grads[i]);
4998               tmp[1] = exp10(grads[i+1]);
4999               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
5000
5001               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
5002                 sciprint("Error allocating tmp_log_grads\n");
5003                 return -1;
5004               }
5005
5006               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
5007
5008               for(j=0;j<nbsubtics;j++)
5009               {
5010                 vyy1 = tmp_log_grads[j];
5011
5012                 if(vyy1<yminval || vyy1>ymaxval) continue;
5013
5014                 if(ppsubwin->axes.reverse[1] == TRUE)
5015                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
5016
5017                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
5018
5019                 if (IsDownAxes(psubwin))
5020                 {
5021                   vx[1]=vx[0]=xm;
5022                   vy[0]=ym;
5023                   vy[1]=vy[0]+iof/4;
5024                 }
5025                 else
5026                 {
5027                   vx[0]=xm;vy[0]=ym;
5028                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5029                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5030                 }
5031
5032                 if(ppsubwin->axes.axes_visible[1] == TRUE)
5033                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5034               }
5035               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
5036
5037             } /* end NEW */
5038             else
5039             {
5040               double ytmp2 = ppsubwin->axes.u_ygrads[i];
5041               double dy = (ppsubwin->axes.u_ygrads[i+1] - ppsubwin->axes.u_ygrads[i]) / nbsubtics;
5042               for(j=0;j<nbsubtics;j++)
5043               {
5044                 vyy1=ytmp2+dy*j;
5045
5046                 if(vyy1<yminval || vyy1>ymaxval) continue;
5047
5048                 if(ppsubwin->axes.reverse[1] == TRUE)
5049                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
5050
5051                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
5052
5053                 if (IsDownAxes(psubwin))
5054                 {
5055                   vx[1]=vx[0]=xm;
5056                   vy[0]=ym;
5057                   vy[1]=vy[0]+iof/4;
5058                 }
5059                 else
5060                 {
5061                   vx[0]=xm;vy[0]=ym;
5062                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5063                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5064                 }
5065
5066                 if(ppsubwin->axes.axes_visible[1] == TRUE)
5067                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5068               }
5069             }
5070           }
5071
5072           /***************************************************************/
5073           /************************* END OF COMMON PART ******************/
5074           /***************************************************************/
5075         }
5076       }
5077       else /* we display the computed tics */
5078       {
5079         AdaptGraduationsOnYBottomRight(iof,x,y,size,Ticsdir,fontid,psubwin,yminval,ymaxval,fx,0.,fz);
5080
5081         lastyindex = ppsubwin->axes.nygrads - 1;
5082
5083         if(lastyindex == 0)
5084           ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.ygrads[0]));
5085         else
5086           ChoixFormatE(c_format,
5087           ppsubwin->axes.ygrads[0],
5088           ppsubwin->axes.ygrads[lastyindex],
5089           ((ppsubwin->axes.ygrads[lastyindex])-(ppsubwin->axes.ygrads[0]))/(lastyindex));
5090
5091         nbtics = ppsubwin->axes.nygrads;
5092         nbsubtics = ppsubwin->axes.nbsubtics[1];
5093
5094         maxTicksLabelSize[0] = 0 ;
5095         maxTicksLabelSize[1] = 0 ;
5096
5097         for(i=0;i<nbtics;i++)
5098         {
5099           char foo[256]; 
5100           double ytmp2 = ppsubwin->axes.ygrads[i];
5101
5102           if(ytmp2<yminval || ytmp2>ymaxval) 
5103           {
5104             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
5105             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
5106             /* donc autant ne pas aller plus loin dans l'algo... */
5107           }
5108
5109           sprintf(foo,c_format,ytmp2);
5110
5111           /***************************************************************/
5112           /************************* COMMON PART *************************/
5113           /***************************************************************/
5114
5115           /* F.Leray 03.11.04 Test if log scale to perform a : exp10(x) because trans3d will */
5116           /* re-do a log10() (that is needed for data computations) */
5117
5118
5119           if(ppsubwin->axes.reverse[1] == TRUE)
5120             ytmp2 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp2);
5121
5122           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp2,&fz);
5123
5124
5125           vx[0]=xm;vy[0]=ym;
5126
5127           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5128           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5129
5130           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
5131
5132
5133           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5134           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
5135           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
5136
5137           if (IsDownAxes(psubwin)){
5138             vx[1]=vx[0];
5139             vy[1]=vy[0]+iof/2;
5140             posi[0] = inint(xm-rect[2]/2); 
5141             posi[1]=inint( vy[0] + iof + rect[3]);}
5142           else{ 
5143             vx[1]=vx[0]+barlengthx;
5144             vy[1]=vy[0]+barlengthy;
5145             /*              posi[0] = inint( xm+2*barlengthx - rect[2]/2); */
5146             /*              posi[0] = inint( xm+2*barlengthx - rect[2]); */
5147             posi[0] = inint( xm+2*barlengthx);
5148             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
5149
5150           if(ppsubwin->axes.axes_visible[1] == TRUE){
5151             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5152             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5153             if ( ppsubwin->logflags[1] == 'l' )
5154             {
5155               int smallersize = fontid[1]-2;
5156               int old_rect10[4];
5157               /*                    char str[2] = "xv"; */
5158               int posi10[2];
5159
5160               posi10[0] = posi[0] - logrect[2];
5161               posi10[1] = posi[1] + logrect[3];
5162
5163               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5164               C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
5165
5166               C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5167
5168               posi[0] = old_rect10[0] + old_rect10[2];
5169               posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
5170
5171               C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5172               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
5173
5174               /* put back the current fontid */
5175               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5176             }
5177             else
5178               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
5179
5180             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
5181             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5182           }
5183
5184           /* grid to put here */
5185
5186           if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
5187           {
5188             gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
5189
5190             if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
5191             {
5192               double tmp[2];
5193               double pas=0;
5194               double * tmp_log_grads = (double *) NULL;
5195
5196
5197               double * grads = ppsubwin->axes.ygrads;
5198
5199               tmp[0] = exp10(grads[i]);
5200               tmp[1] = exp10(grads[i+1]);
5201               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
5202
5203               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
5204                 sciprint("Error allocating tmp_log_grads\n");
5205                 return -1;
5206               }
5207
5208               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
5209
5210               for(j=0;j<nbsubtics;j++)
5211               {
5212                 vyy1 = tmp_log_grads[j];
5213
5214                 if(vyy1<=yminval || vyy1>=ymaxval) continue;
5215
5216                 if(ppsubwin->axes.reverse[1] == TRUE)
5217                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
5218
5219                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
5220
5221                 /*  if ((xm != ixbox[5]) && (xm != ixbox[4])) */
5222                 /*                              {  */
5223                 xg[0]= xm;  yg[0]= ym;  
5224                 if (Ishidden(psubwin))
5225                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
5226                 else
5227                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
5228                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5229                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5230                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5231                 xg[0]= xg[1]; yg[0]= yg[1];
5232                 xg[1] = ixbox[3] - ixbox[4] +xm; 
5233                 yg[1]=  iybox[2] - iybox[4] +ym;
5234                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5235                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
5236                 /*      } */
5237               }
5238               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
5239             }
5240             else
5241             {
5242               if(ytmp2>yminval && ytmp2<ymaxval) 
5243               {
5244                 xg[0]= xm;  yg[0]= ym;  
5245                 if (Ishidden(psubwin))
5246                 { xg[1]= xm; yg[1]= iybox[2] -iybox[3]+ym; }
5247                 else
5248                 {xg[1]= ixbox[3] - ixbox[4] +xm; yg[1]= iybox[3] - iybox[4] +ym; } 
5249                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5250                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5251                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5252                 xg[0]= xg[1]; yg[0]= yg[1];
5253                 xg[1] = ixbox[3] - ixbox[4] +xm; 
5254                 yg[1]=  iybox[2] - iybox[4] +ym;
5255                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5256                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
5257               }
5258             }
5259           }
5260
5261           /* and subtics */
5262           if(i != nbtics-1)
5263           {
5264             if(ppsubwin->logflags[1] =='l')
5265             {
5266               double tmp[2];
5267               double pas=0;
5268               double * tmp_log_grads = (double *) NULL;
5269
5270
5271               double * grads = ppsubwin->axes.ygrads;
5272
5273               tmp[0] = exp10(grads[i]);
5274               tmp[1] = exp10(grads[i+1]);
5275               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
5276
5277               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
5278                 sciprint("Error allocating tmp_log_grads\n");
5279                 return -1;
5280               }
5281
5282               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
5283
5284               for(j=0;j<nbsubtics;j++)
5285               {
5286                 vyy1 = tmp_log_grads[j];
5287
5288                 if(vyy1<yminval || vyy1>ymaxval) continue;
5289
5290                 if(ppsubwin->axes.reverse[1] == TRUE)
5291                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
5292
5293                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
5294
5295                 if (IsDownAxes(psubwin))
5296                 {
5297                   vx[1]=vx[0]=xm;
5298                   vy[0]=ym;
5299                   vy[1]=vy[0]+iof/4;
5300                 }
5301                 else
5302                 {
5303                   vx[0]=xm;vy[0]=ym;
5304                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5305                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5306                 }
5307
5308                 if(ppsubwin->axes.axes_visible[1] == TRUE)
5309                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5310               }
5311               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
5312
5313             } /* end NEW */
5314             else
5315             {
5316               double ytmp3 = ppsubwin->axes.ygrads[i];
5317               double dy = (ppsubwin->axes.ygrads[i+1] - ppsubwin->axes.ygrads[i]) / nbsubtics;
5318               for(j=0;j<nbsubtics;j++)
5319               {
5320                 vyy1=ytmp3+dy*j;
5321
5322                 if(vyy1<yminval || vyy1>ymaxval) continue;
5323
5324                 if(ppsubwin->axes.reverse[1] == TRUE)
5325                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
5326
5327                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
5328                 /*   trans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz); */
5329
5330                 if (IsDownAxes(psubwin))
5331                 {
5332                   vx[1]=vx[0]=xm;
5333                   vy[0]=ym;
5334                   vy[1]=vy[0]+iof/4;
5335                 }
5336                 else
5337                 {
5338                   vx[0]=xm;vy[0]=ym;
5339                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5340                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5341                 }
5342
5343                 if(ppsubwin->axes.axes_visible[1] == TRUE)
5344                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5345               }
5346             }
5347           }
5348           /***************************************************************/
5349           /************************* END OF COMMON PART ******************/
5350           /***************************************************************/
5351
5352         }
5353       }
5354     }
5355     if ( sciGetVisibility(ppsubwin->mon_y_label) )
5356     {
5357       sciLabel * ppLabel = pLABEL_FEATURE( ppsubwin->mon_y_label ) ;
5358       if( ppLabel->auto_rotation )
5359       {
5360         sciSetFontOrientation( ppsubwin->mon_y_label, 0 ) ;
5361       }
5362
5363       if( ppLabel->auto_position )
5364       {
5365
5366         int segmentStart[2] = { ixbox[4], iybox[4] } ;
5367         int segmentEnd[2]   = { ixbox[5], iybox[5] } ;
5368
5369         /* add the bar size and ticks label size to the offset */
5370         int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
5371           constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
5372         computeLabelAutoPos( ppsubwin->mon_y_label, segmentStart, segmentEnd, offset ) ;
5373       }
5374       /* a trick to force the display with 2d scale */
5375       drawTextEntity( ppLabel->text ) ;
5376
5377     }
5378   }
5379
5380
5381
5382   /***********************/ /** bottom left side ***/
5383   /*** le  x-y scaling ***/ /* DISPLAY x or y graduations */
5384   /***********************/
5385
5386   if (( xind[3]+xind[4] == 3) || ( xind[3]+xind[4] == 11))
5387   {
5388     if (pSUBWIN_FEATURE (psubwin)->project[0]==1) /* x HERE */
5389     {
5390       double fx,fy,fz;
5391       char c_format[5];
5392
5393
5394       integer Ticsdir[2];
5395       Ticsdir[0]=ixbox[4]-ixbox[5];
5396       Ticsdir[1]=iybox[4]-iybox[5];
5397       BBoxToval(&fx,&fy,&fz,xind[3],bbox);
5398
5399       x=inint((ixbox[3]+ixbox[4])/2.0 -rect[2] -iof);
5400       y=inint((1/3.0)*iybox[3]+(2/3.0)*iybox[4]+ iof+ 1.5*rect[3]); 
5401
5402       if(ppsubwin->axes.auto_ticks[0] == FALSE)
5403       {
5404         /* we display the x tics specified by the user*/
5405         nbtics = ppsubwin->axes.u_nxgrads;
5406         nbsubtics = ppsubwin->axes.nbsubtics[0];
5407
5408         maxTicksLabelSize[0] = 0 ;
5409         maxTicksLabelSize[1] = 0 ;
5410
5411         for(i=0;i<nbtics;i++)
5412         {
5413           char *foo = ppsubwin->axes.u_xlabels[i]; 
5414           double xtmp = ppsubwin->axes.u_xgrads[i];
5415
5416           if(xtmp<xminval || xtmp>xmaxval) 
5417           {
5418             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
5419             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
5420             /* donc autant ne pas aller plus loin dans l'algo... */
5421           }
5422
5423           /***************************************************************/
5424           /************************* COMMON PART *************************/
5425           /***************************************************************/
5426
5427           if(ppsubwin->axes.reverse[0] == TRUE)
5428             xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
5429
5430           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
5431           /*              trans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz); */
5432
5433
5434           vx[0]=xm;vy[0]=ym;
5435
5436           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5437           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5438
5439           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
5440
5441           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5442           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
5443           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
5444
5445
5446           if (IsDownAxes(psubwin)){
5447             vx[1]=vx[0];
5448             vy[1]=vy[0]+iof/2;
5449             posi[0] = inint(xm-rect[2]/2); 
5450             posi[1]=inint( vy[0] + iof + rect[3]);}
5451           else{
5452             vx[1]=vx[0]+barlengthx;
5453             vy[1]=vy[0]+barlengthy;
5454             posi[0] = inint( xm+2*barlengthx-rect[2]); 
5455             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
5456
5457           if(ppsubwin->axes.axes_visible[0] == TRUE){
5458             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5459             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5460             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
5461             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
5462             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5463           }
5464           /* grid to put here */
5465           if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0]  )
5466           {
5467             gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
5468
5469             if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
5470             {
5471               double tmp[2];
5472               double pas=0;
5473               double * tmp_log_grads = (double *) NULL;
5474
5475
5476               double * grads = ppsubwin->axes.u_xgrads;
5477
5478               tmp[0] = exp10(grads[i]);
5479               tmp[1] = exp10(grads[i+1]);
5480               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
5481
5482               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
5483                 sciprint("Error allocating tmp_log_grads\n");
5484                 return -1;
5485               }
5486
5487               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
5488
5489               for(j=0;j<nbsubtics;j++)
5490               {
5491                 vxx1 = tmp_log_grads[j];
5492
5493                 if(vxx1<=xminval || vxx1>=xmaxval) continue;
5494
5495                 if(ppsubwin->axes.reverse[0] == TRUE)
5496                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
5497
5498                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
5499
5500                 /*   if ((xm != ixbox[3]) && (xm != ixbox[4])) */
5501                 /*                              {  */
5502                 xg[0]= xm;  yg[0]= ym;  
5503                 if (Ishidden(psubwin))
5504                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
5505                 else
5506                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
5507                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5508                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5509                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5510                 xg[0]= xg[1]; yg[0]= yg[1];
5511                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
5512                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5513                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
5514                 /*      } */
5515               }
5516               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
5517             }
5518             else
5519             {
5520               if(xtmp>xminval && xtmp<xmaxval) 
5521               {
5522                 xg[0]= xm;  yg[0]= ym;  
5523                 if (Ishidden(psubwin))
5524                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
5525                 else
5526                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
5527                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5528                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5529                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5530                 xg[0]= xg[1]; yg[0]= yg[1];
5531                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
5532                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5533                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
5534               }
5535             }
5536           }
5537
5538           /* and subtics */
5539           if(i != nbtics-1)
5540           {
5541             if(ppsubwin->logflags[0] =='l')
5542             {
5543               double tmp[2];
5544               double pas=0;
5545               double * tmp_log_grads = (double *) NULL;
5546
5547
5548               double * grads = ppsubwin->axes.u_xgrads;
5549
5550               tmp[0] = exp10(grads[i]);
5551               tmp[1] = exp10(grads[i+1]);
5552               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
5553
5554               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
5555                 sciprint("Error allocating tmp_log_grads\n");
5556                 return -1;
5557               }
5558
5559               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
5560
5561               for(j=0;j<nbsubtics;j++)
5562               {
5563                 vxx1 = tmp_log_grads[j];
5564
5565                 if(vxx1<xminval || vxx1>xmaxval) continue;
5566
5567                 if(ppsubwin->axes.reverse[0] == TRUE)
5568                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
5569
5570                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
5571
5572                 if (IsDownAxes(psubwin))
5573                 {
5574                   vx[1]=vx[0]=xm;
5575                   vy[0]=ym;
5576                   vy[1]=vy[0]+iof/4;
5577                 }
5578                 else
5579                 {
5580                   vx[0]=xm;vy[0]=ym;
5581                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5582                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5583                 }
5584
5585                 if(ppsubwin->axes.axes_visible[0] == TRUE)
5586                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5587               }
5588
5589               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
5590             } /* end NEW */
5591             else
5592             {
5593               double xtmp2 = ppsubwin->axes.u_xgrads[i];
5594               double dx = (ppsubwin->axes.u_xgrads[i+1] - ppsubwin->axes.u_xgrads[i]) / nbsubtics;
5595
5596               for (j=1;j<nbsubtics;j++)
5597               {  
5598                 vxx1=xtmp2+dx*j;
5599
5600                 if(vxx1<xminval || vxx1>xmaxval) continue;
5601
5602                 if(ppsubwin->axes.reverse[0] == TRUE)
5603                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
5604
5605                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
5606                 /*                trans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz); */
5607
5608
5609                 if (IsDownAxes(psubwin))
5610                 {
5611                   vx[1]=vx[0]=xm;
5612                   vy[0]=ym;
5613                   vy[1]=vy[0]+iof/4;
5614                 }
5615                 else
5616                 {
5617                   vx[0]=xm;vy[0]=ym;
5618                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5619                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5620                 }
5621
5622                 if(ppsubwin->axes.axes_visible[0] == TRUE)
5623                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5624               }
5625             }
5626           }
5627           /***************************************************************/
5628           /************************* COMMON PART *************************/
5629           /***************************************************************/
5630
5631
5632         }
5633
5634       }
5635       else /* we display the computed tics */
5636       {
5637         AdaptGraduationsOnXBottomLeft(iof,x,y,size,Ticsdir,fontid,psubwin,xminval,xmaxval,0.,fy,fz);
5638
5639         lastxindex = ppsubwin->axes.nxgrads - 1;
5640
5641         if(lastxindex == 0)
5642           ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.xgrads[0]));
5643         else
5644           ChoixFormatE(c_format,
5645           ppsubwin->axes.xgrads[0],
5646           ppsubwin->axes.xgrads[lastxindex],
5647           ((ppsubwin->axes.xgrads[lastxindex])-(ppsubwin->axes.xgrads[0]))/(lastxindex));
5648
5649         nbtics = ppsubwin->axes.nxgrads;
5650         nbsubtics = ppsubwin->axes.nbsubtics[0];
5651
5652         maxTicksLabelSize[0] = 0 ;
5653         maxTicksLabelSize[1] = 0 ;
5654
5655         for(i=0;i<nbtics;i++)
5656         {
5657           char foo[256]; 
5658           double xtmp = ppsubwin->axes.xgrads[i];
5659
5660           if(xtmp<xminval || xtmp>xmaxval) 
5661           {
5662             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
5663             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
5664             /* donc autant ne pas aller plus loin dans l'algo... */
5665           }
5666
5667           sprintf(foo,c_format,xtmp);
5668
5669           /***************************************************************/
5670           /************************* COMMON PART *************************/
5671           /***************************************************************/
5672
5673           if(ppsubwin->axes.reverse[0] == TRUE)
5674             xtmp = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],xtmp);
5675
5676           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&xtmp,&fy,&fz);
5677
5678           vx[0]=xm;vy[0]=ym;
5679
5680           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5681           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5682
5683           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
5684
5685           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5686           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
5687           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
5688
5689           if (IsDownAxes(psubwin)){
5690             vx[1]=vx[0];
5691             vy[1]=vy[0]+iof/2;
5692             posi[0] = inint(xm-rect[2]/2); 
5693             posi[1]=inint( vy[0] + iof + rect[3]);}
5694           else{
5695             vx[1]=vx[0]+barlengthx;
5696             vy[1]=vy[0]+barlengthy;
5697             posi[0] = inint( xm+2*barlengthx-rect[2]); 
5698             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
5699
5700           if(ppsubwin->axes.axes_visible[0] == TRUE){
5701             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5702             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5703             if ( ppsubwin->logflags[0] == 'l' )
5704             {
5705               int smallersize = fontid[1]-2;
5706               int old_rect10[4];
5707               int posi10[2];
5708
5709               posi10[0] = posi[0] - logrect[2];
5710               posi10[1] = posi[1] + logrect[3];
5711
5712               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5713               C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
5714
5715               C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5716
5717               posi[0] = old_rect10[0] + old_rect10[2];
5718               posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
5719
5720               C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5721               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
5722
5723               /* put back the current fontid */
5724               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5725             }
5726             else
5727               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
5728
5729             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
5730             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5731           }
5732           /* grid to put here */
5733           if ( ppsubwin->grid[0] > -1 && ppsubwin->axes.axes_visible[0] )
5734           {
5735             gstyle = pSUBWIN_FEATURE (psubwin)->grid[0];
5736
5737             if((ppsubwin->logflags[0] =='l') && (i != nbtics-1))
5738             {
5739               double tmp[2];
5740               double pas=0;
5741               double * tmp_log_grads = (double *) NULL;
5742
5743
5744               double * grads = ppsubwin->axes.xgrads;
5745
5746               tmp[0] = exp10(grads[i]);
5747               tmp[1] = exp10(grads[i+1]);
5748               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
5749
5750               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
5751                 sciprint("Error allocating tmp_log_grads\n");
5752                 return -1;
5753               }
5754
5755               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
5756
5757               for(j=0;j<nbsubtics;j++)
5758               {
5759                 vxx1 = tmp_log_grads[j];
5760
5761                 if(vxx1<=xminval || vxx1>=xmaxval) continue;
5762
5763                 if(ppsubwin->axes.reverse[0] == TRUE)
5764                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
5765
5766                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
5767
5768
5769                 xg[0]= xm;  yg[0]= ym;  
5770                 if (Ishidden(psubwin))
5771                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
5772                 else
5773                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
5774                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5775                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5776                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5777                 xg[0]= xg[1]; yg[0]= yg[1];
5778                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
5779                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5780                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
5781
5782               }
5783               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
5784             }
5785             else
5786             {
5787               if(xtmp>xminval && xtmp<xmaxval) 
5788               {
5789                 xg[0]= xm;  yg[0]= ym;  
5790                 if (Ishidden(psubwin))
5791                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
5792                 else
5793                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
5794                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5795                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5796                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5797                 xg[0]= xg[1]; yg[0]= yg[1];
5798                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
5799                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5800                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
5801               }
5802             }
5803           }
5804
5805           /* and subtics */
5806           if(i != nbtics-1)
5807           {
5808             if(ppsubwin->logflags[0] =='l')
5809             {
5810               double tmp[2];
5811               double pas=0;
5812               double * tmp_log_grads = (double *) NULL;
5813
5814
5815               double * grads = ppsubwin->axes.xgrads;
5816
5817               tmp[0] = exp10(grads[i]);
5818               tmp[1] = exp10(grads[i+1]);
5819               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
5820
5821               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
5822                 sciprint("Error allocating tmp_log_grads\n");
5823                 return -1;
5824               }
5825
5826               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
5827
5828               for(j=0;j<nbsubtics;j++)
5829               {
5830                 vxx1 = tmp_log_grads[j];
5831
5832                 if(vxx1<xminval || vxx1>xmaxval) continue;
5833
5834                 if(ppsubwin->axes.reverse[0] == TRUE)
5835                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
5836
5837                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
5838
5839                 if (IsDownAxes(psubwin))
5840                 {
5841                   vx[1]=vx[0]=xm;
5842                   vy[0]=ym;
5843                   vy[1]=vy[0]+iof/4;
5844                 }
5845                 else
5846                 {
5847                   vx[0]=xm;vy[0]=ym;
5848                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5849                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5850                 }
5851
5852                 if(ppsubwin->axes.axes_visible[0] == TRUE)
5853                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5854               }
5855               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
5856             } /* end NEW */
5857             else
5858             {
5859               double xtmp2 = ppsubwin->axes.xgrads[i];
5860               double dx = (ppsubwin->axes.xgrads[i+1] - ppsubwin->axes.xgrads[i]) / nbsubtics;
5861
5862               for (j=1;j<nbsubtics;j++)
5863               {  
5864                 vxx1=xtmp2+dx*j;
5865
5866                 if(vxx1<xminval || vxx1>xmaxval) continue;
5867
5868                 if(ppsubwin->axes.reverse[0] == TRUE)
5869                   vxx1 = InvAxis(ppsubwin->FRect[0],ppsubwin->FRect[2],vxx1);
5870
5871                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz);
5872                 /*                trans3d(psubwin,1,&xm,&ym,&vxx1,&fy,&fz); */
5873
5874
5875                 if (IsDownAxes(psubwin))
5876                 {
5877                   vx[1]=vx[0]=xm;
5878                   vy[0]=ym;
5879                   vy[1]=vy[0]+iof/4;
5880                 }
5881                 else
5882                 {
5883                   vx[0]=xm;vy[0]=ym;
5884                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
5885                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
5886                 }
5887
5888                 if(ppsubwin->axes.axes_visible[0] == TRUE)
5889                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
5890               }
5891             }
5892           }
5893           /***************************************************************/
5894           /************************* COMMON PART *************************/
5895           /***************************************************************/
5896
5897         }
5898       }
5899     }
5900
5901     if ( sciGetVisibility(ppsubwin->mon_x_label) )
5902     { 
5903
5904       sciLabel * ppLabel = pLABEL_FEATURE(ppsubwin->mon_x_label) ;
5905       if( ppLabel->auto_rotation )
5906       {
5907         sciSetFontOrientation(ppsubwin->mon_x_label, 0 ) ;
5908       }
5909
5910
5911       if( ppLabel->auto_position )
5912       {
5913
5914         int segmentStart[2] = { ixbox[3], iybox[3] } ;
5915         int segmentEnd[2]   = { ixbox[4], iybox[4] } ;
5916
5917         /* add the bar size and ticks label size to the offset */
5918         int offset[2] = { constOffset[0] + maxTicksLabelSize[0] + abs( barlengthx ), 
5919           constOffset[1] + maxTicksLabelSize[1] + abs( barlengthy )  } ;
5920         computeLabelAutoPos( ppsubwin->mon_x_label, segmentStart, segmentEnd, offset ) ;
5921       }
5922       /* a trick to force the display with 2d scale */
5923       drawTextEntity( ppLabel->text ) ;
5924
5925     }
5926   }
5927   else 
5928   {
5929     if  (pSUBWIN_FEATURE (psubwin)->project[1]==1) /* y is HERE */
5930     {
5931       double fx,fy,fz;
5932       char c_format[5];
5933
5934       integer Ticsdir[2];
5935       Ticsdir[0]=ixbox[4]-ixbox[5];
5936       Ticsdir[1]=iybox[4]-iybox[5];
5937       BBoxToval(&fx,&fy,&fz,xind[3],bbox);
5938
5939       x=inint((ixbox[3]+ixbox[4])/2.0 -rect[2] -iof);
5940       y=inint((1/3.0)*iybox[3]+(2/3.0)*iybox[4]+ iof + 1.5*rect[3]);  
5941
5942       if(ppsubwin->axes.auto_ticks[1] == FALSE)
5943       {
5944         /* we display the y tics specified by the user*/
5945         nbtics = ppsubwin->axes.u_nygrads;
5946         nbsubtics = ppsubwin->axes.nbsubtics[1];
5947
5948         maxTicksLabelSize[0] = 0 ;
5949         maxTicksLabelSize[1] = 0 ;
5950
5951         for(i=0;i<nbtics;i++)
5952         {
5953           char *foo = ppsubwin->axes.u_ylabels[i]; 
5954           double ytmp = ppsubwin->axes.u_ygrads[i];
5955
5956           if(ytmp<yminval || ytmp>ymaxval) 
5957           {
5958             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
5959             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
5960             /* donc autant ne pas aller plus loin dans l'algo... */
5961           }
5962
5963           /***************************************************************/
5964           /************************* COMMON PART *************************/
5965           /***************************************************************/
5966
5967           if(ppsubwin->axes.reverse[1] == TRUE)
5968             ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
5969
5970           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
5971           /*              trans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz); */
5972
5973
5974           vx[0]=xm;vy[0]=ym; 
5975
5976           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5977           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
5978
5979           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
5980
5981           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
5982           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
5983           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
5984
5985           if (IsDownAxes(psubwin)){
5986             vx[1]=vx[0];
5987             vy[1]=vy[0]+iof/2;
5988             posi[0] = inint(xm-rect[2]/2); 
5989             posi[1]=inint( vy[0] + iof + rect[3]);}
5990           else{
5991             vx[1]=vx[0]+barlengthx;
5992             vy[1]=vy[0]+barlengthy;
5993             /*              posi[0] = inint( xm+2*barlengthx-rect[2]/2);  */
5994             posi[0] = inint( xm+2*barlengthx-rect[2]); 
5995             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
5996
5997
5998           if(ppsubwin->axes.axes_visible[1] == TRUE){
5999             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6000             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6001             C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
6002             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
6003             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6004           }
6005           /* grid to put here */
6006           if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
6007           {
6008             gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
6009
6010             if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
6011             {
6012               double tmp[2];
6013               double pas=0;
6014               double * tmp_log_grads = (double *) NULL;
6015
6016
6017               double * grads = ppsubwin->axes.u_ygrads;
6018
6019               tmp[0] = exp10(grads[i]);
6020               tmp[1] = exp10(grads[i+1]);
6021               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
6022
6023               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
6024                 sciprint("Error allocating tmp_log_grads\n");
6025                 return -1;
6026               }
6027
6028               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
6029
6030               for(j=0;j<nbsubtics;j++)
6031               {
6032                 vyy1 = tmp_log_grads[j];
6033
6034                 if(vyy1<=yminval || vyy1>=ymaxval) continue;
6035
6036                 if(ppsubwin->axes.reverse[1] == TRUE)
6037                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
6038
6039                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
6040
6041                 /*   if ((xm != ixbox[3]) && (xm != ixbox[4])) */
6042                 /*                              { */ 
6043                 xg[0]= xm;  yg[0]= ym;  
6044                 if (Ishidden(psubwin))
6045                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
6046                 else
6047                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
6048                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6049                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6050                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6051                 xg[0]= xg[1]; yg[0]= yg[1];
6052                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
6053                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6054                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
6055                 /*      } */
6056               }
6057               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
6058             }
6059             else
6060             {
6061               if(ytmp>yminval && ytmp<ymaxval) 
6062               {
6063                 xg[0]= xm;  yg[0]= ym;  
6064                 if (Ishidden(psubwin))
6065                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
6066                 else
6067                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
6068                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6069                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6070                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6071                 xg[0]= xg[1]; yg[0]= yg[1];
6072                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
6073                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6074                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
6075               }
6076             }
6077           }
6078
6079           /* and subtics */
6080           if(i != nbtics-1)
6081           {
6082             if(ppsubwin->logflags[1] =='l')
6083             {
6084               double tmp[2];
6085               double pas=0;
6086               double * tmp_log_grads = (double *) NULL;
6087
6088
6089               double * grads = ppsubwin->axes.u_ygrads;
6090
6091               tmp[0] = exp10(grads[i]);
6092               tmp[1] = exp10(grads[i+1]);
6093               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
6094
6095               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
6096                 sciprint("Error allocating tmp_log_grads\n");
6097                 return -1;
6098               }
6099
6100               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
6101
6102               for(j=0;j<nbsubtics;j++)
6103               {
6104                 vyy1 = tmp_log_grads[j];
6105
6106                 if(vyy1<yminval || vyy1>ymaxval) continue;
6107
6108                 if(ppsubwin->axes.reverse[1] == TRUE)
6109                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
6110
6111                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
6112
6113                 if (IsDownAxes(psubwin))
6114                 {
6115                   vx[1]=vx[0]=xm;
6116                   vy[0]=ym;
6117                   vy[1]=vy[0]+iof/4;
6118                 }
6119                 else
6120                 {
6121                   vx[0]=xm;vy[0]=ym;
6122                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
6123                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
6124                 }
6125
6126                 if(ppsubwin->axes.axes_visible[1] == TRUE)
6127                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6128               }
6129               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
6130
6131             } /* end NEW */
6132             else
6133             {
6134
6135               double ytmp2 = ppsubwin->axes.u_ygrads[i];
6136               double dy = (ppsubwin->axes.u_ygrads[i+1] - ppsubwin->axes.u_ygrads[i]) / nbsubtics;
6137               for(j=0;j<nbsubtics;j++)
6138               {
6139                 vyy1=ytmp2+dy*j;
6140
6141                 if(vyy1<yminval || vyy1>ymaxval) continue;
6142
6143                 if(ppsubwin->axes.reverse[1] == TRUE)
6144                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
6145
6146                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
6147                 /*                trans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz); */
6148
6149
6150                 if (IsDownAxes(psubwin))
6151                 {
6152                   vx[1]=vx[0]=xm;
6153                   vy[0]=ym;
6154                   vy[1]=vy[0]+iof/4;
6155                 }
6156                 else
6157                 {
6158                   vx[0]=xm;vy[0]=ym;
6159                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
6160                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
6161                 }
6162
6163                 if(ppsubwin->axes.axes_visible[1] == TRUE)
6164                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6165               }
6166             }
6167           }
6168           /***************************************************************/
6169           /************************* COMMON PART *************************/
6170           /***************************************************************/
6171
6172         }
6173       }
6174       else /* we display the computed tics */
6175       {
6176         AdaptGraduationsOnYBottomLeft(iof,x,y,size,Ticsdir,fontid,psubwin,yminval,ymaxval,fx,0.,fz);
6177
6178         lastyindex = ppsubwin->axes.nygrads - 1;
6179
6180         if(lastyindex == 0)
6181           ChooseFormatForOneGrad(c_format,&(ppsubwin->axes.ygrads[0]));
6182         else
6183           ChoixFormatE(c_format,
6184           ppsubwin->axes.ygrads[0],
6185           ppsubwin->axes.ygrads[lastyindex],
6186           ((ppsubwin->axes.ygrads[lastyindex])-(ppsubwin->axes.ygrads[0]))/(lastyindex));
6187
6188         nbtics = ppsubwin->axes.nygrads;
6189         nbsubtics = ppsubwin->axes.nbsubtics[1];
6190
6191         maxTicksLabelSize[0] = 0 ;
6192         maxTicksLabelSize[1] = 0 ;
6193
6194         for(i=0;i<nbtics;i++)
6195         {
6196           char foo[256]; 
6197           double ytmp = ppsubwin->axes.ygrads[i];
6198
6199           if(ytmp<yminval || ytmp>ymaxval) 
6200           {
6201             /*   sciprint("je rejete la valeur: %lf\n\n",xtmp); */
6202             continue; /* cas ou TL est ON et on a des graduations qui ne seront pas affichees de tte facon */
6203             /* donc autant ne pas aller plus loin dans l'algo... */
6204           }
6205
6206           sprintf(foo,c_format,ytmp);
6207
6208           /***************************************************************/
6209           /************************* COMMON PART *************************/
6210           /***************************************************************/
6211
6212           if(ppsubwin->axes.reverse[1] == TRUE)
6213             ytmp = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],ytmp);
6214
6215           ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz);
6216           /*              trans3d(psubwin,1,&xm,&ym,&fx,&ytmp,&fz); */
6217
6218
6219           vx[0]=xm;vy[0]=ym; 
6220
6221           barlengthx= (integer) (( Ticsdir[0])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
6222           barlengthy= (integer) (( Ticsdir[1])/sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1])*size);
6223
6224           C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); /* fix bug noticed by R.N. */
6225
6226           C2F(dr)("xstringl",foo,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6227           maxTicksLabelSize[0] = Max( maxTicksLabelSize[0], rect[2] ) ;
6228           maxTicksLabelSize[1] = Max( maxTicksLabelSize[1], rect[3] ) ;
6229
6230           if (IsDownAxes(psubwin)){
6231             vx[1]=vx[0];
6232             vy[1]=vy[0]+iof/2;
6233             posi[0] = inint(xm-rect[2]/2); 
6234             posi[1]=inint( vy[0] + iof + rect[3]);}
6235           else{
6236             vx[1]=vx[0]+barlengthx;
6237             vy[1]=vy[0]+barlengthy;
6238             /*              posi[0] = inint( xm+2*barlengthx-rect[2]/2);  */
6239             posi[0] = inint( xm+2*barlengthx-rect[2]); 
6240             posi[1]=inint( ym + 2*barlengthy + rect[3]);}
6241
6242           if(ppsubwin->axes.axes_visible[1] == TRUE){
6243             C2F(dr)("xset","pattern",&textcolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6244             C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6245             if ( ppsubwin->logflags[1] == 'l' )
6246             {
6247               int smallersize = fontid[1]-2;
6248               int old_rect10[4];
6249               /*                    char str[2] = "xv"; */
6250               int posi10[2];
6251
6252               posi10[0] = posi[0] - logrect[2];
6253               posi10[1] = posi[1] + logrect[3];
6254
6255               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6256               C2F(dr)("xstring","10",(&posi10[0]),(&posi10[1]),PI0,&flag,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
6257
6258               C2F(dr)("xstringl","10",(&posi10[0]),(&posi10[1]),old_rect10,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6259
6260               posi[0] = old_rect10[0] + old_rect10[2];
6261               posi[1] = (int) (old_rect10[1] - old_rect10[3]*.1);
6262
6263               C2F(dr)("xset","font",fontid,&smallersize,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6264               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
6265
6266               /* put back the current fontid */
6267               C2F(dr)("xset","font",fontid,fontid+1,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6268             }
6269             else
6270               C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag,PI0,PI0,&ang, PD0,PD0,PD0,0L,0L);
6271
6272             C2F(dr)("xset","pattern",&ticscolor,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);   
6273             C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6274           }
6275           /* grid to put here */
6276           if ( ppsubwin->grid[1] > -1 && ppsubwin->axes.axes_visible[1] )
6277           {
6278             gstyle = pSUBWIN_FEATURE (psubwin)->grid[1];
6279
6280             if((ppsubwin->logflags[1] =='l') && (i != nbtics-1))
6281             {
6282               double tmp[2];
6283               double pas=0;
6284               double * tmp_log_grads = (double *) NULL;
6285
6286
6287               double * grads = ppsubwin->axes.ygrads;
6288
6289               tmp[0] = exp10(grads[i]);
6290               tmp[1] = exp10(grads[i+1]);
6291               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
6292
6293               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
6294                 sciprint("Error allocating tmp_log_grads\n");
6295                 return -1;
6296               }
6297
6298               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
6299
6300               for(j=0;j<nbsubtics;j++)
6301               {
6302                 vyy1 = tmp_log_grads[j];
6303
6304                 if(vyy1<=yminval || vyy1>=ymaxval) continue;
6305
6306                 if(ppsubwin->axes.reverse[1] == TRUE)
6307                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
6308
6309                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
6310
6311                 /*    if ((xm != ixbox[3]) && (xm != ixbox[4])) */
6312                 /*                              {  */
6313                 xg[0]= xm;  yg[0]= ym;  
6314                 if (Ishidden(psubwin))
6315                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
6316                 else
6317                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
6318                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6319                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6320                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6321                 xg[0]= xg[1]; yg[0]= yg[1];
6322                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
6323                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6324                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
6325                 /*      } */
6326               }
6327               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
6328             }
6329             else
6330             {
6331               if(ytmp>yminval && ytmp<ymaxval) 
6332               {
6333                 xg[0]= xm;  yg[0]= ym;  
6334                 if (Ishidden(psubwin))
6335                 { xg[1]= xm; yg[1]= iybox[0] -iybox[5]+ym; }
6336                 else
6337                 {xg[1]= ixbox[1] - ixbox[3] +xm; yg[1]= iybox[5] - iybox[4] +ym; } 
6338                 C2F(dr)("xget","line style",&verbose,dash,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6339                 C2F (dr) ("xset", "line style",&gridStyle,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
6340                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6341                 xg[0]= xg[1]; yg[0]= yg[1];
6342                 xg[1] = ixbox[1] - ixbox[3] +xm; yg[1]=  iybox[0] - iybox[4] +ym;
6343                 C2F(dr)("xsegs","v", xg, yg, &ns,&gstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6344                 C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);  
6345               }
6346             }
6347           }
6348
6349           /* and subtics */
6350           if(i != nbtics-1)
6351           {
6352             if(ppsubwin->logflags[1] =='l')
6353             {
6354               double tmp[2];
6355               double pas=0;
6356               double * tmp_log_grads = (double *) NULL;
6357
6358
6359               double * grads = ppsubwin->axes.ygrads;
6360
6361               tmp[0] = exp10(grads[i]);
6362               tmp[1] = exp10(grads[i+1]);
6363               pas = (exp10(grads[i+1]) - exp10(grads[i])) / (nbsubtics );
6364
6365               if((tmp_log_grads = (double *)MALLOC(nbsubtics*sizeof(double)))==NULL){
6366                 sciprint("Error allocating tmp_log_grads\n");
6367                 return -1;
6368               }
6369
6370               for(j=0;j<nbsubtics;j++) tmp_log_grads[j] = log10(tmp[0]+(j)*pas);
6371
6372               for(j=0;j<nbsubtics;j++)
6373               {
6374                 vyy1 = tmp_log_grads[j];
6375
6376                 if(vyy1<yminval || vyy1>ymaxval) continue;
6377
6378                 if(ppsubwin->axes.reverse[1] == TRUE)
6379                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
6380
6381                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
6382
6383                 if (IsDownAxes(psubwin))
6384                 {
6385                   vx[1]=vx[0]=xm;
6386                   vy[0]=ym;
6387                   vy[1]=vy[0]+iof/4;
6388                 }
6389                 else
6390                 {
6391                   vx[0]=xm;vy[0]=ym;
6392                   vx[1]= (integer) (vx[0]+barlengthx/2.0);
6393                   vy[1]= (integer) (vy[0]+barlengthy/2.0);
6394                 }
6395
6396                 if(ppsubwin->axes.axes_visible[1] == TRUE)
6397                   C2F(dr)("xsegs","v", vx, vy, &ns,&ticscolor,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
6398               }
6399               FREE(tmp_log_grads); tmp_log_grads = (double *) NULL;
6400
6401             } /* end NEW */
6402             else
6403             {
6404
6405               double ytmp2 = ppsubwin->axes.ygrads[i];
6406               double dy = (ppsubwin->axes.ygrads[i+1] - ppsubwin->axes.ygrads[i]) / nbsubtics;
6407               for(j=0;j<nbsubtics;j++)
6408               {
6409                 vyy1=ytmp2+dy*j;
6410
6411                 if(vyy1<yminval || vyy1>ymaxval) continue;
6412
6413                 if(ppsubwin->axes.reverse[1] == TRUE)
6414                   vyy1 = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],vyy1);
6415
6416                 ComputeGoodTrans3d(psubwin,1,&xm,&ym,&fx,&vyy1,&fz);
6417
6418                 if (IsDownAxes(psubwin))
6419                 {
6420                   vx[1]=vx[0]=xm;
6421                   vy[0]=ym;
6422          &nbs