Plo2dn.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library
00003  *    Copyright (C) 1998-2001 INRIA
00004  --------------------------------------------------------------------------*/
00005 
00006 #include <string.h> /* in case of dbmalloc use */
00007 #include <stdio.h>
00008 #include <math.h>
00009 #include "math_graphics.h"
00010 #include "PloEch.h"
00011 
00012 #define spINSIDE_SPARSE
00013 #include "../../sparse/includes/spConfig.h"
00014 
00015 #include "SetProperty.h"
00016 #include "GetProperty.h"
00017 #include "InitObjects.h"
00018 #include "DrawObjects.h"
00019 #include "BuildObjects.h"
00020 #include "Axes.h"
00021 #include "BasicAlgos.h"
00022 #include "clipping.h"
00023 #include "sciprint.h"
00024 #include "CurrentObjectsManagement.h"
00025 
00026 #include "MALLOC.h" /* MALLOC */
00027 
00028 extern void initsubwin();
00029 void compute_data_bounds(int cflag, char dataflag,double *x,double *y,integer n1,integer n2,double *drect);
00030 void compute_data_bounds2(int cflag,char dataflag, char * logflags, double *x,double  *y, integer n1,integer n2, double *drect);
00031 BOOL update_specification_bounds(sciPointObj *psubwin, double *rect,int flag);
00032 int re_index_brect(double * brect, double * drect);
00033 extern BOOL strflag2axes_properties(sciPointObj * psubwin, char * strflag);
00034 extern char ** FreeUserLabels(char ** u_xlabels, int *u_nxgrads);
00035 extern double * FreeUserGrads(double * u_xgrads);
00036 extern double * AllocUserGrads(double * u_xgrads, int nb);
00037 extern int CopyUserGrads(double *u_xgrad_SRC, double *u_xgrad_DEST, int dim);
00038 extern char ** AllocAndSetUserLabels(char ** u_xlabels, double * u_xgrads, int u_nxgrads, char logflag);
00039 extern char ** AllocAndSetUserLabelsFromMdl(char ** u_xlabels, char ** u_xlabels_MDL, int u_nxgrads);
00040 extern int CreatePrettyGradsFromNax(sciPointObj * psubwin,int * Nax);
00041 extern int GraduateWithNax(sciSubWindow * ppsubwin,double *min,double *max,int nbtics, double * grads);
00042 int ChooseGoodFormat(char * c_format,char logflag, double *_grads,int n_grads);
00043 
00044 int plot2dn(integer ptype,char *logflags,double *x,double *y,integer *n1,integer *n2,integer *style,char *strflag,char *legend,double *brect,integer *aaint,BOOL flagNax, integer lstr1,integer lstr2);
00045 /*--------------------------------------------------------------------
00046  *  plot2dn(ptype,Logflags,x,y,n1,n2,style,strflag,legend,brect,aaint,lstr1,lstr2)
00047  *  
00048  *  Draw *n1 curves of *n2 points each
00049  *
00050  *  ptype is an integer which gives the polyline drawind mode (0,1,2,3,4)
00051  *
00052  *  Logflags is a two character string
00053  *
00054  *  (x[i+(*n2)*j] ,y[i+(*n2)*j]) Double values giving the point
00055  *  position of point i of curve j (i=0,*n2-1 j=0,*n1-1)
00056  *
00057  *  style[*n1]-> give the style to use for each curve 
00058  *     if style is positive --> a mark is used (mark id = style[i])
00059  *     if style is strictly negative --> a dashed line is used 
00060  *        (dash id = abs(style[i])
00061  *     if there's only one curve, style can be of type style[0]=style,
00062  *     style[1]=pos ( pos in [1,6]) 
00063  *     pos give the legend position (1 to 6) (this can be iteresting
00064  *     if you want to superpose curves with different legends by 
00065  *     calling plot2d more than one time.
00066  *
00067  *  strflag[3] is a string
00068  *  
00069  *     if strflag[0] == '1' then legends are added 
00070  *        legend = "leg1@leg2@....@legn"; gives the legend for each curve
00071  *      else no legend
00072  *
00073  *     if strflag[1] == '1' then  the values of brect are used to fix 
00074  *        the drawing boundaries :  brect[]= <xmin,ymin,xmax,ymax>;
00075  *      if strflag[1] == '2' then the values  are computed from data
00076  *      else if strflag[1]=='0' the previous values 
00077  *                (previous call or defaut values) are used 
00078  *
00079  *     if  strflag[2] == '1' ->then an axis is added
00080  *        the number of intervals 
00081  *        is specified by the vector aaint[4] of integers 
00082  *         <aaint[0],aaint[1]> specifies the x-axis number of  points 
00083  *         <aaint[2],aaint[3]> same for y-axis
00084  *     if  strflag[2] == '2' -> no axis, only a box around the curves
00085  *     else no box and no axis 
00086 
00087  * lstr* : unused ( but used by Fortran ) 
00088  *--------------------------------------------------------------------------*/
00089   
00090 int plot2dn(integer ptype,char *logflags,double *x,double *y,integer *n1,integer *n2,integer *style,char *strflag,char *legend,double *brect,integer *aaint,BOOL flagNax, integer lstr1,integer lstr2)
00091 {
00092   int closeflag = 0;
00093   int jj = 0;
00094   sciPointObj **pptabofpointobj;
00095   sciPointObj  *psubwin;
00096   long hdl;
00097   long *hdltab;
00098   int cmpt=0/*,i*/;
00099   BOOL containsSurface = FALSE ;
00100   int with_leg;
00101   double drect[6];
00102   char dataflag/*,frameflag*/;
00103   sciSubWindow * ppsubwin = NULL;
00104   BOOL bounds_changed = FALSE;
00105   BOOL axes_properties_changed = FALSE;
00106 
00107   psubwin = sciGetCurrentSubWin();
00108   ppsubwin = pSUBWIN_FEATURE(psubwin);
00109 
00110   /* check if the auto_clear property is on and then erase everything */
00111   checkRedrawing() ;
00112   
00113   if ( sciGetSurface(psubwin) !=  NULL ) 
00114   {
00115     containsSurface = TRUE ;
00116   }
00117   
00118   if (sciGetSurface(psubwin) == (sciPointObj *) NULL) /* F.Leray 18.05.04 */
00119     {
00120       ppsubwin->is3d = FALSE;
00121       ppsubwin->project[2]= 0;
00122     }
00123   else
00124     {
00125       ppsubwin->theta_kp=ppsubwin->theta;
00126       ppsubwin->alpha_kp=ppsubwin->alpha;
00127     }
00128   
00129   ppsubwin->alpha  = 0.0;
00130   ppsubwin->theta  = 270.0;
00131   
00132   if (sciGetSurface(psubwin) != (sciPointObj *) NULL){
00133     if(sciGetCurrentScilabXgc () != (struct BCG *) NULL)
00134       UpdateSubwinScale(psubwin);
00135     ppsubwin->is3d = FALSE;
00136   }
00137 
00138 
00139   /* Force psubwin->axes.aaint to those given by argument aaint*/
00140   /* F.Leray 07.10.04 REMOVE AAINT*/
00141  /*  for (i=0;i<4;i++) pSUBWIN_FEATURE(psubwin)->axes.aaint[i] = aaint[i];  */
00142 
00143   
00144 
00145   /* Force psubwin->logflags to those given by argument*/
00146   if ( ppsubwin->FirstPlot )
00147   {
00148     ppsubwin->logflags[0]=logflags[1];
00149     ppsubwin->logflags[1]=logflags[2];
00150   }
00151 
00152   /* Force "cligrf" clipping */
00153   sciSetIsClipping (psubwin,0); 
00154 
00155   /* Force  axes_visible property */
00156   /*pSUBWIN_FEATURE (psubwin)->isaxes  = TRUE;*/ /* WHY ??? */
00157 
00158   if (sciGetGraphicMode (psubwin)->autoscaling) {
00159     /* compute and merge new specified bounds with psubwin->Srect */
00160     switch (strflag[1])  {
00161     case '0': 
00162       /* do not change psubwin->Srect */
00163       break;
00164     case '1' : case '3' : case '5' : case '7':
00165       /* Force psubwin->Srect=brect */
00166       re_index_brect(brect, drect);
00167       break;
00168     case '2' : case '4' : case '6' : case '8': case '9':
00169       /* Force psubwin->Srect to the x and y bounds */
00170       if ( (int)strlen(logflags) < 1) dataflag='g' ; else dataflag=logflags[0];
00171       compute_data_bounds2(0,dataflag,ppsubwin->logflags,x,y,*n1,*n2,drect);
00172       break;
00173     }
00174     if (!pSUBWIN_FEATURE(psubwin)->FirstPlot && 
00175         (strflag[1] == '5' || strflag[1] == '7' || strflag[1] == '8' || strflag[1] == '9')) { /* merge psubwin->Srect and drect */
00176       
00177       drect[0] = Min(ppsubwin->SRect[0],drect[0]); /*xmin*/
00178       drect[2] = Min(ppsubwin->SRect[2],drect[2]); /*ymin*/
00179       drect[1] = Max(ppsubwin->SRect[1],drect[1]); /*xmax*/
00180       drect[3] = Max(ppsubwin->SRect[3],drect[3]); /*ymax*/
00181       
00182     }
00183     if (strflag[1] != '0')
00184       bounds_changed = update_specification_bounds(psubwin, drect,2);
00185   } 
00186   
00187   if(ppsubwin->FirstPlot == TRUE) bounds_changed = TRUE;
00188   
00189   axes_properties_changed = strflag2axes_properties(psubwin, strflag);
00190      
00191   ppsubwin->FirstPlot = FALSE; /* just after strflag2axes_properties */
00192    
00193   with_leg= (strflag[0] == '1');
00194   ppsubwin->with_leg = with_leg;
00195 
00196   /* F.Leray 07.10.04 : trigger algo to init. manual graduation u_xgrads and 
00197      u_ygrads if nax (in matdes.c which is == aaint HERE) was specified */
00198   
00199   ppsubwin->flagNax = flagNax; /* store new value for flagNax */
00200 
00201   if(ppsubwin->flagNax == TRUE){
00202     if(ppsubwin->logflags[0] == 'n' && ppsubwin->logflags[1] == 'n')
00203       {
00204         ppsubwin->axes.auto_ticks[0] = FALSE; /* x and y graduations are imposed by Nax */
00205         ppsubwin->axes.auto_ticks[1] = FALSE;
00206         
00207         CreatePrettyGradsFromNax(psubwin,aaint);
00208       }
00209     else{
00210       sciprint("Warning : Nax does not work with logarithmic scaling\n");}
00211   }
00212   
00213   if(bounds_changed == TRUE || axes_properties_changed == TRUE)
00214     sciDrawObj(sciGetCurrentFigure());
00215   /*     EraseAndOrRedraw(psubwin); /\* inhibit EraseAndOrRedraw for now F.Leray 20.12.04 *\/ */
00216   
00217   /*---- Drawing the curves and the legends ----*/
00218   if ( *n1 != 0 ) {
00219     frame_clip_on ();
00220     if ((hdltab = MALLOC ((*n1+2) * sizeof (long))) == NULL) {
00221       sciprint ("Running out of memory for plot2d\n");
00222       return 0;   
00223     }
00224     if (with_leg) {
00225       /* pptabofpointobj allocated for legends */
00226       if ((pptabofpointobj = MALLOC((*n1)*sizeof(sciPointObj*))) == NULL) {
00227         sciprint ("Running out of memory for plot2d\n");
00228         FREE(hdltab);
00229         return 0;
00230       }
00231     }
00232     for (jj = 0;jj < *n1; jj++) {/*A.Djalel 3D axes*/
00233       sciPointObj * pobj = NULL;
00234       if (style[jj] > 0) { 
00235         sciSetCurrentObj (ConstructPolyline
00236                           (sciGetCurrentSubWin(),&(x[jj*(*n2)]),
00237                            &(y[jj*(*n2)]),PD0,closeflag,*n2,*n1,ptype,
00238                            &style[jj],NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE));
00239       }
00240       else {
00241         int minusstyle = -style[jj];
00242         sciSetCurrentObj (ConstructPolyline
00243                           (sciGetCurrentSubWin(),&(x[jj*(*n2)]),
00244                            &(y[jj*(*n2)]),PD0,closeflag,*n2,*n1,ptype,
00245                            NULL,NULL,&minusstyle,NULL,NULL,FALSE,FALSE,TRUE,FALSE));
00246       }
00247       pobj = sciGetCurrentObj();
00248       
00249       if (with_leg) pptabofpointobj[jj] = pobj;
00250       sciDrawObjIfRequired(pobj);
00251       
00252       hdl=sciGetHandle(pobj);
00253       hdltab[cmpt]=hdl;
00254       cmpt++;
00255     }
00256     
00257     DrawAxesIfRequired(sciGetCurrentObj ()); /* force axes redrawing once is sufficient (F.Leray 10.01.05) */
00258     
00259     frame_clip_off ();
00260 
00261     /*---- Drawing the Legends ----*/
00262     if (with_leg) {
00263       sciSetCurrentObj (ConstructLegend
00264                         (sciGetCurrentSubWin(),
00265                          legend, strlen(legend), *n1, style, pptabofpointobj)); 
00266       hdl=sciGetHandle(sciGetCurrentObj ());   
00267       hdltab[cmpt]=hdl;
00268       cmpt++;
00269       FREE(pptabofpointobj);
00270     }
00271 
00272     /*---- construct Compound ----*/
00273     sciSetCurrentObj(ConstructCompound (hdltab, cmpt)); 
00274     FREE(hdltab);
00275     if ( containsSurface ) {
00276       Merge3d(psubwin);
00277       sciDrawObj(sciGetCurrentFigure ());
00278     }
00279     return(0);
00280   }
00281   
00282 
00283   /*  sciDrawObj(sciGetCurrentFigure ());*/
00284   return(0);
00285 }
00286 
00287 
00288 
00289 
00290 /* Given two set of coordinates x and y this routine computes the corresponding 
00291  *  data bounds rectangle drect=[xmin,ymin,xmax,ymax] taking into account the logflag
00292  *  -> means we have to find among the data the min > 0.
00293  */
00294 void compute_data_bounds2(int cflag,char dataflag, char * logflags, double *x,double  *y, integer n1,integer n2, double *drect)
00295 {
00296   int size_x,size_y;
00297   double xd[2];
00298   double *x1;
00299   switch ( dataflag ) {
00300   case 'e' : 
00301     xd[0] = 1.0; xd[1] = (double)n2;
00302     x1 = xd;size_x = (n2 != 0) ? 2 : 0 ;
00303     break; 
00304   case 'o' : 
00305     x1 = x;size_x = n2;
00306     break;
00307   case 'g' : 
00308   default  : 
00309     x1 = x;size_x = (cflag == 1) ? n1 : (n1*n2) ;
00310     break; 
00311   }
00312 
00313   if (size_x != 0) {
00314     if(logflags[0] != 'l'){
00315       drect[0] =  Mini(x1, size_x); 
00316       drect[1] =  Maxi(x1,size_x); 
00317     }
00318     else { /* log. case */
00319       drect[0] =  sciFindStPosMin(x1,size_x); 
00320       drect[1] =  Maxi(x1,size_x); 
00321     }
00322     
00323   }
00324   else {
00325     if(logflags[0] != 'l'){
00326       drect[0] = 0.0;
00327       drect[1] = 10.0;
00328     }
00329     else{/* log. case */
00330       drect[0] = 1.0;
00331       drect[1] = 10.0;
00332     }
00333   }
00334 
00335   size_y = (cflag == 1) ? n2 : (n1*n2) ;
00336   if (size_y != 0) {
00337     if(logflags[1] != 'l'){
00338       drect[2] =  Mini(y, size_y); 
00339       drect[3] =  Maxi(y,size_y); 
00340     }
00341     else{/* log. case */
00342       drect[2] =  sciFindStPosMin(y,size_y); 
00343       drect[3] =  Maxi(y,size_y); 
00344     }
00345 
00346   }
00347   else {
00348     if(logflags[1] != 'l'){
00349       drect[2] = 0.0;
00350       drect[3] = 10.0;
00351     }
00352     else{/* log. case */
00353       drect[2] = 1.0;
00354       drect[3] = 10.0;
00355     }
00356   }
00357   /* back to default values for  x=[] and y = [] */
00358   if ( drect[2] == LARGEST_REAL ) { drect[2] = 0.0; drect[3] = 10.0 ;} 
00359   if ( drect[0] == LARGEST_REAL ) { drect[0] = 0.0; drect[1] = 10.0 ;} 
00360 
00361 }
00362 
00363 
00364 
00365 
00366 /* Given two set of coordinates x and y this routine computes the corresponding 
00367  *  data bounds rectangle drect=[xmin,ymin,xmax,ymax] 
00368  */
00369 void compute_data_bounds(int cflag, char dataflag,double *x,double *y,integer n1,integer n2,double *drect)
00370 {
00371   int size_x,size_y;
00372   double xd[2];
00373   double *x1;
00374   switch ( dataflag ) {
00375   case 'e' : 
00376     xd[0] = 1.0; xd[1] = (double)n2;
00377     x1 = xd;size_x = (n2 != 0) ? 2 : 0 ;
00378     break; 
00379   case 'o' : 
00380     x1 = x;size_x = n2;
00381     break;
00382   case 'g' : 
00383   default  : 
00384     x1 = x;size_x = (cflag == 1) ? n1 : (n1*n2) ;
00385     break; 
00386   }
00387 
00388   if (size_x != 0) {
00389     drect[0] =  Mini(x1, size_x); 
00390     drect[1] =  Maxi(x1,size_x); 
00391   }
00392   else {
00393     drect[0] = 0.0;
00394     drect[1] = 10.0;
00395   }
00396 
00397   size_y = (cflag == 1) ? n2 : (n1*n2) ;
00398   if (size_y != 0) {
00399     drect[2] =  Mini(y, size_y); 
00400     drect[3] =  Maxi(y,size_y); 
00401   }
00402   else {
00403     drect[2] = 0.0;
00404     drect[3] = 10.0;
00405   }
00406   /* back to default values for  x=[] and y = [] */
00407   if ( drect[2] == LARGEST_REAL ) { drect[2] = 0.0; drect[3] = 10.0 ;} 
00408   if ( drect[0] == LARGEST_REAL ) { drect[0] = 0.0; drect[1] = 10.0 ;} 
00409 
00410 }
00411 BOOL update_specification_bounds(psubwin, rect,flag)
00412      sciPointObj  *psubwin;
00413      double rect[6] ;
00414      int flag;
00415 {
00416   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (psubwin);
00417   BOOL haschanged = FALSE;
00418   
00419   ppsubwin->SRect[0] = rect[0];
00420   ppsubwin->SRect[1] = rect[1];
00421   ppsubwin->SRect[2] = rect[2];
00422   ppsubwin->SRect[3] = rect[3];
00423   if (flag==3) {
00424     ppsubwin->SRect[4] = rect[4];
00425     ppsubwin->SRect[5] = rect[5];
00426   }
00427   
00428   if(flag != 3)
00429     haschanged = sci_update_frame_bounds_2d(psubwin);
00430   else
00431     haschanged = sci_update_frame_bounds_3d(psubwin);
00432   
00433   
00434   return haschanged;
00435 }
00436 
00437 
00438 /* F.Leray */
00439 /* brect must have the same format as drect i.e.: [xmin,xmax,ymin,ymax] */
00440 /* brect = INPUT ; drect = OUTPUT (warning drect is dim 6) */
00441 int re_index_brect(double * brect, double * drect)
00442 {
00443   drect[0] = brect[0];
00444   drect[1] = brect[2];
00445   drect[2] = brect[1];
00446   drect[3] = brect[3];
00447 /*  drect[4] = brect[4];
00448     drect[5] = brect[5];*/
00449   
00450   return 0;
00451 }
00452 /* F.Leray 07.05.04 */
00453 /* Dispatch info contained in strflag to all the flag available in
00454    sciSubwin object (tight_limits, isoview, isaxes...) */
00455 BOOL strflag2axes_properties(sciPointObj * psubwin, char * strflag)
00456 {
00457   BOOL haschanged = FALSE;
00458   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (psubwin);
00459 
00460   /* F.Leray 07.05.04 */
00461   /* strflag[1] Isoview & tight_limits flags management*/
00462   switch (strflag[1])  {
00463   case '0': case '9':
00464     /* no changes */
00465     break;
00466   case '1' : case '2' : case '7' : case '8' :
00467     if(ppsubwin->tight_limits != TRUE){
00468       ppsubwin->tight_limits = TRUE;
00469       haschanged = TRUE;
00470     }
00471     /*pSUBWIN_FEATURE (psubwin)->isoview      = FALSE; */
00472     break;
00473   case '3' : case '4' :
00474     /*pSUBWIN_FEATURE (psubwin)->tight_limits = TRUE;*/
00475     if(ppsubwin->isoview != TRUE){
00476       ppsubwin->isoview = TRUE;
00477       haschanged = TRUE;
00478     }
00479     break;
00480   case '5' : case '6' :
00481     if(ppsubwin->tight_limits != FALSE){
00482       ppsubwin->tight_limits = FALSE; /* pretty axes */
00483       haschanged = TRUE;
00484     }
00485     /*pSUBWIN_FEATURE (psubwin)->isoview      = FALSE;*/
00486     break;
00487   }
00488       
00489   /* F.Leray 07.05.04 */
00490   /* strflag[2] */
00491   switch (strflag[2])  {
00492   case '0': 
00493     if(ppsubwin->FirstPlot == TRUE){
00494       /*       ppsubwin->isaxes = FALSE; */
00495       ppsubwin->axes.axes_visible[0] = FALSE;
00496       ppsubwin->axes.axes_visible[1] = FALSE;
00497       ppsubwin->axes.axes_visible[2] = FALSE; /* also trigger z axis */
00498       ppsubwin->axes.rect = BT_OFF;
00499       haschanged = TRUE;
00500     }
00501     /*else no changes : the isaxes properties is driven by the previous plot */
00502     break;
00503   case '1' : 
00504  /*    ppsubwin->isaxes = TRUE; */
00505     if(ppsubwin->axes.axes_visible[0] != TRUE ||
00506        ppsubwin->axes.axes_visible[1] != TRUE ||
00507        ppsubwin->axes.axes_visible[2] != TRUE ||
00508        ppsubwin->axes.ydir != 'l'){
00509       ppsubwin->axes.axes_visible[0] = TRUE;
00510       ppsubwin->axes.axes_visible[1] = TRUE;
00511       ppsubwin->axes.axes_visible[2] = TRUE; /* also trigger z axis */
00512       ppsubwin->axes.ydir ='l';
00513       ppsubwin->axes.rect = BT_ON;
00514       haschanged = TRUE;
00515     }
00516     break;
00517   case '2' : 
00518   /*   ppsubwin->isaxes = TRUE; */
00519     if(ppsubwin->axes.axes_visible[0] != TRUE ||
00520        ppsubwin->axes.axes_visible[1] != TRUE ||
00521        ppsubwin->axes.axes_visible[2] != TRUE){
00522       ppsubwin->axes.axes_visible[0] = FALSE;
00523       ppsubwin->axes.axes_visible[1] = FALSE;
00524       ppsubwin->axes.axes_visible[2] = FALSE; /* also trigger z axis */
00525       ppsubwin->axes.rect = BT_ON;
00526       haschanged = TRUE;
00527     }
00528     break;
00529   case '3' : 
00530     /*    ppsubwin->isaxes = TRUE; */
00531     if(ppsubwin->axes.axes_visible[0] != TRUE ||
00532        ppsubwin->axes.axes_visible[1] != TRUE ||
00533        ppsubwin->axes.axes_visible[2] != TRUE ||
00534        ppsubwin->axes.ydir != 'r'){
00535       ppsubwin->axes.axes_visible[0] = TRUE;
00536       ppsubwin->axes.axes_visible[1] = TRUE;
00537       ppsubwin->axes.axes_visible[2] = TRUE; /* also trigger z axis */
00538       ppsubwin->axes.ydir ='r';
00539       haschanged = TRUE;
00540     }
00541     break;
00542   case '4' :
00543     /*     ppsubwin->isaxes = TRUE; */
00544     if(ppsubwin->axes.axes_visible[0] != TRUE ||
00545        ppsubwin->axes.axes_visible[1] != TRUE ||
00546        ppsubwin->axes.axes_visible[2] != TRUE){
00547       ppsubwin->axes.axes_visible[0] = TRUE;
00548       ppsubwin->axes.axes_visible[1] = TRUE;
00549       ppsubwin->axes.axes_visible[2] = TRUE; /* also trigger z axis */
00550       ppsubwin->axes.rect = BT_ON;
00551       /* Case not implemented yet : axes are drawn centred in the middle of the frame box. */
00552       haschanged = TRUE;
00553     }
00554     break;
00555   case '5' :
00556  /*    ppsubwin->isaxes = TRUE; */
00557     if(ppsubwin->axes.axes_visible[0] != TRUE ||
00558        ppsubwin->axes.axes_visible[1] != TRUE ||
00559        ppsubwin->axes.axes_visible[2] != TRUE ||
00560        ppsubwin->axes.xdir != 'c' ||
00561        ppsubwin->axes.ydir != 'c'){
00562       ppsubwin->axes.axes_visible[0] = TRUE;
00563       ppsubwin->axes.axes_visible[1] = TRUE;
00564       ppsubwin->axes.axes_visible[2] = TRUE; /* also trigger z axis */
00565       ppsubwin->axes.xdir ='c';
00566       ppsubwin->axes.ydir ='c';
00567       ppsubwin->axes.rect = BT_ON;
00568       haschanged = TRUE;
00569     }
00570     break;
00571   case '9' :
00572     /*     ppsubwin->isaxes = TRUE; */
00573     if(ppsubwin->axes.axes_visible[0] != TRUE ||
00574        ppsubwin->axes.axes_visible[1] != TRUE ||
00575        ppsubwin->axes.axes_visible[2] != TRUE){
00576       ppsubwin->axes.axes_visible[0] = TRUE;
00577       ppsubwin->axes.axes_visible[1] = TRUE;
00578       ppsubwin->axes.axes_visible[2] = TRUE; /* also trigger z axis */
00579       ppsubwin->axes.rect = BT_ON;
00580       haschanged = TRUE;
00581     }
00582   }
00583   return haschanged;
00584 }
00585 
00586 
00587 int CreatePrettyGradsFromNax(sciPointObj * psubwin,int * Nax)
00588 {
00589   double xmin = 0, xmax = 0;
00590   double ymin = 0, ymax = 0;
00591   int nbtics_x = Nax[1];
00592   int nbtics_y = Nax[3];
00593   int nbsubtics_x = Nax[0];
00594   int nbsubtics_y = Nax[2];
00595 
00596   sciSubWindow * ppsubwin = pSUBWIN_FEATURE (psubwin);
00597   
00598   if(sciGetZooming(psubwin) == TRUE) {
00599     xmin= ppsubwin->FRect[0]; 
00600     ymin= ppsubwin->FRect[1]; 
00601     xmax= ppsubwin->FRect[2];
00602     ymax= ppsubwin->FRect[3];
00603   }
00604   else {
00605     xmin = ppsubwin->SRect[0];
00606     ymin = ppsubwin->SRect[2];
00607     xmax = ppsubwin->SRect[1];
00608     ymax = ppsubwin->SRect[3];
00609   }
00610   
00611   /* x graduations */
00612   ppsubwin->axes.u_xgrads  = FreeUserGrads (ppsubwin->axes.u_xgrads);
00613   ppsubwin->axes.u_xlabels = FreeUserLabels(ppsubwin->axes.u_xlabels,
00614                                             &ppsubwin->axes.u_nxgrads);
00615   
00616   ppsubwin->axes.u_nxgrads = nbtics_x;
00617   ppsubwin->axes.u_xgrads = AllocUserGrads(ppsubwin->axes.u_xgrads, nbtics_x);
00618   
00619 /*   GraduateWithNax(ppsubwin,xmin,xmax,xoutmin,xoutmax,nbtics_x,nbsubtics_x,  */
00620 /*                ppsubwin->axes.u_xgrads, ppsubwin->axes.u_nxgrads); */
00621   
00622   GraduateWithNax(ppsubwin,&xmin,&xmax,nbtics_x,ppsubwin->axes.u_xgrads);
00623 
00624   ppsubwin->axes.u_xlabels = AllocAndSetUserLabels(ppsubwin->axes.u_xlabels, 
00625                                                    ppsubwin->axes.u_xgrads, 
00626                                                    ppsubwin->axes.u_nxgrads, 
00627                                                    ppsubwin->logflags[0]);
00628   
00629   /* y graduations */
00630   ppsubwin->axes.u_ygrads  = FreeUserGrads (ppsubwin->axes.u_ygrads);
00631   ppsubwin->axes.u_ylabels = FreeUserLabels(ppsubwin->axes.u_ylabels,
00632                                             &ppsubwin->axes.u_nygrads);
00633   
00634   ppsubwin->axes.u_nygrads = nbtics_y;
00635   ppsubwin->axes.u_ygrads = AllocUserGrads(ppsubwin->axes.u_ygrads, nbtics_y);
00636   
00637   /*   GraduateWithNax(ppsubwin,ymin,ymax,youtmin,youtmax,nbtics_y,nbsubtics_y,  */
00638 /*                ppsubwin->axes.u_ygrads, ppsubwin->axes.u_nygrads); */
00639   
00640   GraduateWithNax(ppsubwin,&ymin,&ymax,nbtics_y,ppsubwin->axes.u_ygrads);
00641   
00642   ppsubwin->axes.u_ylabels = AllocAndSetUserLabels(ppsubwin->axes.u_ylabels, 
00643                                                    ppsubwin->axes.u_ygrads, 
00644                                                    ppsubwin->axes.u_nygrads, 
00645                                                    ppsubwin->logflags[1]);
00646     
00647   /* Subtics storage here */
00648   ppsubwin->axes.nbsubtics[0] = nbsubtics_x +1;
00649   ppsubwin->axes.nbsubtics[1] = nbsubtics_y +1;
00650 
00651   return 0;
00652 }
00653 
00654 int GraduateWithNax(sciSubWindow * ppsubwin,double *min,double *max,int nbtics, double * grads)
00655 {
00656   int i;
00657   double pas;
00658   
00659   if(nbtics == 1){
00660     pas = 0.;
00661     grads[0] = (*min);
00662   }
00663   else{
00664     pas = (*max - *min) / (nbtics -1);
00665     
00666     for(i=0;i<nbtics;i++) 
00667       grads[i] = (*min) + pas*i;
00668   }
00669 
00670   return 0;
00671 }
00672 
00673 char ** FreeUserLabels(char ** u_xlabels, int *u_nxgrads)
00674 {
00675   int i;
00676   
00677   if(u_xlabels != NULL){
00678     for(i=0;i<(*u_nxgrads);i++)
00679       {FREE(u_xlabels[i]); u_xlabels[i] = (char *) NULL;}
00680   }
00681   
00682   u_xlabels = (char **) NULL;
00683     
00684   *u_nxgrads = 0;
00685   
00686   return u_xlabels;
00687 }
00688 
00689 
00690 double * FreeUserGrads(double * u_xgrads)
00691 {
00692   FREE(u_xgrads); u_xgrads = NULL;
00693   return u_xgrads;
00694 }
00695 
00696 double * AllocUserGrads(double * u_xgrads, int nb)
00697 {
00698   
00699   if(nb == 0)
00700     return (double *) NULL;
00701   
00702   if(u_xgrads != NULL)
00703     {
00704       sciprint("Impossible: u_xgrads must be freed before re-allocating");
00705       return (double *) NULL;
00706     }
00707   
00708   if((u_xgrads=(double *)MALLOC(nb*sizeof(double)))==NULL){
00709     sciprint("No more place for allocating user grads using Nax");
00710     return (double *) NULL;
00711   }
00712     
00713   return u_xgrads;
00714 
00715 }
00716 
00717 int CopyUserGrads(double *u_xgrad_SRC, double *u_xgrad_DEST, int dim)
00718 {
00719   int i;
00720 
00721   if(u_xgrad_SRC == NULL)
00722     return 0;
00723 
00724   for(i=0;i<dim;i++)
00725     u_xgrad_DEST[i] = u_xgrad_SRC[i];
00726   
00727   return 0;
00728 }
00729 
00730 
00731 
00732 char ** AllocAndSetUserLabels(char ** u_xlabels, double * u_xgrads, int u_nxgrads, char logflag)
00733 {
00734   int i;
00735   char c_format[5]; 
00736   int nbtics = u_nxgrads;
00737 
00738   if(u_xgrads == NULL)
00739     return (char **) NULL;
00740   
00741   if(u_xlabels != NULL)
00742     {
00743       sciprint("Impossible: u_xlabels must be freed before re-allocating");
00744       return (char **) NULL;
00745     }
00746   
00747 
00748   if((u_xlabels=(char **)MALLOC(u_nxgrads*sizeof(char *)))==NULL){
00749     sciprint("No more place for allocating user labels using Nax");
00750     return (char **) NULL;
00751   }
00752 
00753   ChooseGoodFormat(c_format,logflag,u_xgrads,u_nxgrads);
00754   
00755   for(i=0;i<nbtics;i++)
00756     {  
00757       char foo[100];
00758       
00759       sprintf(foo,c_format, u_xgrads[i]);
00760       
00761       if((u_xlabels[i]=(char *)MALLOC((strlen(foo)+1)*sizeof(char )))==NULL){
00762         sciprint("No more place for allocating u_xlabels");
00763         return (char **) NULL;
00764       }
00765       
00766       strcpy(u_xlabels[i],foo);
00767     }
00768   
00769   return u_xlabels;
00770 }
00771 
00772 
00773 
00774 char ** AllocAndSetUserLabelsFromMdl(char ** u_xlabels, char ** u_xlabels_MDL, int u_nxgrads)
00775 {
00776   int i;
00777   int nbtics = u_nxgrads;
00778 
00779   if(u_nxgrads == 0)
00780     return (char **) NULL;
00781   
00782   if(u_xlabels != NULL)
00783     {
00784       sciprint("Impossible: u_xlabels must be freed before re-allocating");
00785       return (char **) NULL;
00786     }
00787   
00788   if((u_xlabels=(char **)MALLOC(u_nxgrads*sizeof(char *)))==NULL){
00789     sciprint("No more place for allocating user labels using Nax");
00790     return (char **) NULL;
00791   }
00792 
00793   
00794   for(i=0;i<nbtics;i++)
00795     {  
00796       if((u_xlabels[i]=(char *)MALLOC((strlen(u_xlabels_MDL[i])+1)*sizeof(char )))==NULL){
00797         sciprint("No more place for allocating u_xlabels");
00798         return (char **) NULL;
00799       }
00800       
00801       strcpy(u_xlabels[i],u_xlabels_MDL[i]);
00802     }
00803   
00804   return u_xlabels;
00805 }
00806 
00807 

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