#include "ObjectStructure.h"#include "StringMatrix.h"


Go to the source code of this file.
Functions | |
| int C2F() | graduate (double *xmi, double *xma, double *xi, double *xa, integer *np1, integer *np2, integer *kminr, integer *kmaxr, integer *ar) |
| int | ComputeC_format (sciPointObj *pobj, char *c_format) |
| int | ComputeXIntervals (sciPointObj *pobj, char xy_type, double **vector, int *N, int checkdim) |
| StringMatrix * | computeDefaultTicsLabels (sciPointObj *pobj) |
| int | ChooseGoodFormat (char *c_format, char logflag, double *_grads, int n_grads) |
| void | ChoixFormatE1 (char *fmt, double *xx, integer nx) |
| void | ChoixFormatE (char *fmt, double xmin, double xmax, double xpas) |
| double * | ReBuildTicksLog2Lin (char logflag, int nbtics, double *grads) |
| void | correctBounds (double min, double max, double *lBound, double *uBound) |
| char * | copyFormatedValue (double value, const char format[5], int bufferSize) |
| char ** | copyFormatedArray (const double values[], int nbStrings, const char format[5], int bufferSize) |
| int | TheTicks (double *xminv, double *xmaxv, double *grads, int *ngrads, int compNgrads) |
| int | GradLog (double _min, double _max, double *_grads, int *n_grads, int compNgrads) |
| int | GradEqual (const double grads[], const int *ngrads) |
| char * | getFPF (void) |
| int | sciGetLogExponent (double minBound, double maxBound, double *expMin, double *expMax) |
| void ChoixFormatE | ( | char * | fmt, | |
| double | xmin, | |||
| double | xmax, | |||
| double | xpas | |||
| ) |
ChoixFormatE returns a format ("%.*f" or "%.*e") in fmt given xmin,xmax,pas. fmt : character string fmt gives a format which can be used to display number in range xmin:step:xmax Exemple : ChoixFormatE(format,min,max,step); fprintf(format,min+k*step); The format is searched so as to give distinct values for the numeric values xmin + k*xpas in [xmin,xmax] and give enough precision.
Definition at line 80 of file Format.c.
References c, FormatPrec(), and Fsepare().
Referenced by ChooseGoodFormat(), ComputeC_format(), sciGraphics::AutomaticTicksComputer::getTicksPosition(), and sciGraphics::AutoLogTicksComputer::getTicksPosition().
00081 { 00082 char c; 00083 integer des,len = 0; 00084 /* format f minimal */ 00085 for ( des = 0 ; des < 5 ; des++) 00086 { 00087 if (Fsepare("%.*f",des,&len,xmin,xmax,xpas)) break; 00088 } 00089 if ( des < 5 && len <= 6) 00090 { 00091 c='f'; 00092 strcpy(fmt,"%.*f"); 00093 } 00094 else 00095 { 00096 for ( des = 0 ; des < 5 ; des++) 00097 { 00098 if (Fsepare("%.*e",des,&len,xmin,xmax,xpas)) break; 00099 } 00100 c='e'; 00101 strcpy(fmt,"%.*e"); 00102 } 00103 FormatPrec(fmt,&des,xmin,xmax,xpas); 00104 sprintf(fmt,"%%.%d%c",des,c); 00105 }


| void ChoixFormatE1 | ( | char * | fmt, | |
| double * | xx, | |||
| integer | nx | |||
| ) |
same as ChoixFormatE when numbers are given through an array xx[0:nx-1];
Definition at line 156 of file Format.c.
References c, FormatPrec1(), and Fsepare1().
Referenced by ComputeC_format(), and contourI().
00157 { 00158 char c; 00159 integer des,len = 0; 00160 /* format f minimal */ 00161 for ( des = 0 ; des < 5 ; des++) 00162 { 00163 if (Fsepare1("%.*f",des,&len,xx,nx)) break; 00164 } 00165 if ( des < 5 && len <= 6) 00166 { 00167 c='f'; 00168 strcpy(fmt,"%.*f"); 00169 } 00170 else 00171 { 00172 for ( des = 0 ; des < 5 ; des++) 00173 { 00174 if (Fsepare1("%.*e",des,&len,xx,nx)) break; 00175 } 00176 c='e'; 00177 strcpy(fmt,"%.*e"); 00178 } 00179 FormatPrec1(fmt,&des,xx,nx); 00180 sprintf(fmt,"%%.%d%c",des,c); 00181 }


| int ChooseGoodFormat | ( | char * | c_format, | |
| char | logflag, | |||
| double * | _grads, | |||
| int | n_grads | |||
| ) |
add comment
| c_format | ||
| logflag | ||
| _grads | ||
| n_grads |
Definition at line 1380 of file Format.c.
Referenced by AllocAndSetUserLabels().
01381 { 01382 int last_index = n_grads - 1; 01383 01384 if(logflag == 'l') 01385 { 01386 ChoixFormatE(c_format, 01387 exp10(_grads[0]), 01388 exp10(_grads[last_index]), 01389 (( exp10(_grads[last_index]))-( exp10(_grads[0])))/(last_index)); 01390 } 01391 else 01392 { 01393 ChoixFormatE(c_format, 01394 _grads[0], 01395 _grads[last_index], 01396 ((_grads[last_index])-(_grads[0]))/(last_index)); /* Adding F.Leray 06.05.04 */ 01397 } 01398 01399 return 0; 01400 01401 }

| int ComputeC_format | ( | sciPointObj * | pobj, | |
| char * | c_format | |||
| ) |
add comment
| pobj | ||
| c_format |
Real to Pixel values
Horizontal axes
compute a format
the horizontal segment
Vertical axes
the vertical segment
Definition at line 1052 of file Format.c.
References _, ChoixFormatE(), ChoixFormatE1(), FREE, i, j, MALLOC, NULL, pAXES_FEATURE, pos, pSUBWIN_FEATURE, SCI_AXES, sciGetCurrentSubWin(), sciGetEntityType(), sciprint(), x, and y.
Referenced by computeDefaultTicsLabels(), sciGraphics::AxesTicksComputer::getTicksPosition(), set_xtics_coord_property(), and set_ytics_coord_property().
01053 { 01054 int i,j; 01055 char pos; 01056 char xy_type; 01057 double *x = NULL; 01058 double *y = NULL; 01059 int *nx = NULL; 01060 int *ny = NULL; 01061 char * format = NULL; 01062 sciPointObj * psubwin = sciGetCurrentSubWin(); 01063 int xpassed = 0, ypassed = 0, Nx = 0, Ny = 0, x3, y3; 01064 01065 01066 if(sciGetEntityType(pobj) != SCI_AXES){ 01067 sciprint(_("Error: ComputeFormat must be used with SCI_AXES objects\n")); 01068 return -1; 01069 } 01070 01071 pos = pAXES_FEATURE(pobj)->dir; 01072 xy_type = pAXES_FEATURE (pobj)->tics; 01073 /* Allocating space before re-copying values to not polluate the good values 01074 that will be used inside Axes.c */ 01075 if((x=MALLOC((pAXES_FEATURE (pobj)->nx)*sizeof(double)))==NULL){ 01076 sciprint(_("%s: No more memory.\n"),"ComputeC_format"); 01077 return -1; 01078 } 01079 01080 if((y=MALLOC((pAXES_FEATURE (pobj)->ny)*sizeof(double)))==NULL){ 01081 sciprint(_("%s: No more memory.\n"),"ComputeC_format"); 01082 return -1; 01083 } 01084 01085 if((nx=MALLOC(sizeof(int)))==NULL){ 01086 sciprint(_("%s: No more memory.\n"),"ComputeC_format"); 01087 return -1; 01088 } 01089 01090 if((ny=MALLOC(sizeof(int)))==NULL){ 01091 sciprint(_("%s: No more memory.\n"),"ComputeC_format"); 01092 return -1; 01093 } 01094 01095 if((format=MALLOC(5*(sizeof(char ))+1))==NULL){ 01096 sciprint(_("%s: No more memory.\n"),"ComputeC_format"); 01097 return -1; 01098 } 01099 01100 nx[0] = pAXES_FEATURE (pobj)->nx; 01101 for(i=0;i<(*nx);i++) x[i] = pAXES_FEATURE(pobj)->vx[i]; 01102 01103 ny[0] = pAXES_FEATURE (pobj)->ny; 01104 for(i=0;i<(*ny);i++) y[i] = pAXES_FEATURE(pobj)->vy[i]; 01105 01106 format = pAXES_FEATURE (pobj)->format; 01107 01108 /* Algo. here */ 01109 if(xy_type == 'i') { 01110 switch ( pos ) { 01111 case 'u' : case 'd' : 01112 if(pSUBWIN_FEATURE(psubwin)->logflags[0] == 'n') 01113 while (x[3]>10) x[3]=floor(x[3]/2); 01114 else{ 01115 if(x[3] > 12){ /* F.Leray arbitrary value=12 for the moment */ 01116 x3=(int)x[3]; /* if x[3]>12 algo is triggered to search a divisor */ 01117 for(j=x3-1;j>1;j--) 01118 if(x3%j == 0){ 01119 x[3]=j; 01120 xpassed = 1; 01121 } 01122 if(xpassed != 1) x[3] = 1; 01123 } 01124 } 01125 01126 break; 01127 case 'r' : case 'l' : 01128 if(pSUBWIN_FEATURE(psubwin)->logflags[1] == 'n') 01129 while (y[3]>10) y[3]=floor(y[3]/2); 01130 else{ 01131 if(y[3] > 12){ 01132 y3=(int)y[3]; 01133 for(j=y3-1;j>1;j--) 01134 if(y3%j == 0){ 01135 y[3]=j; 01136 ypassed = 1; 01137 } 01138 if(ypassed != 1) y[3] = 1; 01139 } 01140 } 01141 } 01142 } 01143 01144 01146 switch ( xy_type ) 01147 { 01148 case 'v' : Nx= *nx; Ny= *ny; break; 01149 case 'r' : 01150 switch ( pos ) { 01151 case 'u' : case 'd' : Nx = (int) x[2]+1; break; 01152 case 'r' : case 'l' : Ny = (int) y[2]+1; break; 01153 } 01154 break; 01155 case 'i' : 01156 switch ( pos ) { 01157 case 'u' : case 'd' : Nx = (int) x[3]+1; break; 01158 case 'r' : case 'l' : Ny = (int) y[3]+1; break; 01159 } 01160 break; 01161 default: 01162 sciprint(_("%s: Wrong type argument %s.\n"),"Sci_Axis","xy_type"); 01163 } 01164 switch (pos ) 01165 { 01166 case 'u' : 01167 case 'd' : 01169 /* barlength = (integer) (Cscale.WIRect1[3]/50.0); */ 01171 /* if (str == NULL && format == NULL ) */ 01172 if (format == NULL ) 01173 switch (xy_type ) { 01174 case 'v' : ChoixFormatE1(c_format,x,Nx);break; 01175 case 'r' : ChoixFormatE (c_format,x[0],x[1],(x[1]-x[0])/x[2]);break; 01176 case 'i' : 01177 ChoixFormatE (c_format, 01178 (x[0] * exp10(x[2])), 01179 (x[1] * exp10(x[2])), 01180 ((x[1] * exp10(x[2])) - (x[0] * exp10(x[2])))/x[3]); break; /* Adding F.Leray 06.05.04 */ 01181 01182 } 01183 break; 01185 case 'r' : 01186 case 'l' : 01187 01189 /* barlength = (integer) (Cscale.WIRect1[2]/75.0); */ 01190 /* if (str == NULL && format == NULL ) */ 01191 if (format == NULL ) 01192 switch (xy_type ) { 01193 case 'v' : ChoixFormatE1(c_format,y,Ny);break; 01194 case 'r' : ChoixFormatE(c_format,y[0],y[1],(y[1]-y[0])/y[2]);break; 01195 case 'i' : 01196 ChoixFormatE (c_format, 01197 (y[0] * exp10(y[2])), 01198 (y[1] * exp10(y[2])), 01199 ((y[1] * exp10(y[2])) - (y[0] * exp10(y[2])))/y[3]); break; /* Adding F.Leray 06.05.04 */ 01200 } 01202 break; 01203 } 01204 01205 /* c_format should be filled now */ 01206 01207 FREE(x); x = NULL; 01208 FREE(y); y = NULL; 01209 FREE(nx); nx = NULL; 01210 FREE(ny); ny = NULL; 01211 FREE(format); format = NULL; 01212 01213 return 0; 01214 01215 }


| StringMatrix* computeDefaultTicsLabels | ( | sciPointObj * | pobj | ) |
add comment
| pobj |
| in/out] | pobj the axis object |
Definition at line 1321 of file Format.c.
References _, ComputeC_format(), ComputeXIntervals(), copyStrMatElement(), FREE, i, newMatrix(), NULL, pAXES_FEATURE, Scierror(), and sciprint().
Referenced by get_tics_labels_property().
01322 { 01323 StringMatrix * ticsLabels = NULL ; 01324 int nbTics = 0 ; 01325 char c_format[5] ; 01326 double * vector = NULL ; /* position of labels */ 01327 char curLabelBuffer[257] ; 01328 int i ; 01329 01330 if ( pAXES_FEATURE(pobj)->format == NULL ) 01331 { 01332 /* we need to compute c_format */ 01333 ComputeC_format( pobj, c_format ) ; 01334 } 01335 else 01336 { 01337 int i2 ; 01338 for ( i2 = 0 ; i2 < 5 ; i2++ ) 01339 { 01340 c_format[i2] = pAXES_FEATURE(pobj)->format[i2] ; 01341 } 01342 } 01343 01344 /* vector is allocated here */ 01345 if( ComputeXIntervals( pobj, pAXES_FEATURE (pobj)->tics, &vector, &nbTics, 1 ) != 0 ) 01346 { 01347 Scierror(999,_("Error: Bad size in %s: you must first increase the size of the %s.\n"),"tics_coord","tics_coord"); 01348 return 0; 01349 } 01350 01351 ComputeC_format( pobj, c_format ) ; 01352 01353 /* create a vector of strings */ 01354 ticsLabels = newMatrix( 1, nbTics ) ; 01355 01356 if ( curLabelBuffer == NULL ) 01357 { 01358 sciprint(_("%s: No more memory.\n"),"computeDefaultTicsLabels"); 01359 return NULL ; 01360 } 01361 01362 for( i = 0 ; i < nbTics ; i++ ) 01363 { 01364 sprintf(curLabelBuffer,c_format,vector[i]) ; /* we can't know for sure the size of the label */ 01365 /* That's why it is first stored in a big array */ 01366 copyStrMatElement( ticsLabels, 0, i, curLabelBuffer ) ; 01367 } 01368 FREE(vector) ; 01369 vector = NULL; 01370 01371 /* I recompute the nb_tics_labels */ 01372 /* Why ??? jb Silvy */ 01373 pAXES_FEATURE (pobj)->nb_tics_labels = nbTics; 01374 01375 return ticsLabels ; 01376 01377 }


| int ComputeXIntervals | ( | sciPointObj * | pobj, | |
| char | xy_type, | |||
| double ** | vector, | |||
| int * | N, | |||
| int | checkdim | |||
| ) |
add comment
| pobj | ||
| xy_type | ||
| vector | ||
| N | ||
| checkdim |
Definition at line 1217 of file Format.c.
References _, FALSE, i, MALLOC, n, NULL, sciAxes::nx, sciAxes::ny, pAXES_FEATURE, sciprint(), TRUE, val, sciAxes::vx, and sciAxes::vy.
Referenced by computeDefaultTicsLabels(), sciGraphics::AxesPositioner::getAxisBounds(), sciGraphics::AxesTicksComputer::getNbTicks(), sciGraphics::AxesTicksComputer::getTicksPosition(), set_tics_style_property(), set_xtics_coord_property(), and set_ytics_coord_property().
01218 { 01219 int i; 01220 sciAxes * ppaxes = pAXES_FEATURE (pobj); 01221 double * val = NULL; /* reprensents ppaxes->x or ppaxes->y */ 01222 int nval; 01223 01224 int n; 01225 01226 /* draw an horizontal axis : YES (horizontal axis) or NO (vertical axis) */ 01227 BOOL ishoriz = (ppaxes->nx > ppaxes->ny)? TRUE : FALSE; 01228 01229 if(ishoriz == TRUE){ 01230 val = ppaxes->vx; 01231 nval = ppaxes->nx; 01232 } 01233 else{ 01234 val = ppaxes->vy; 01235 nval = ppaxes->ny; 01236 } 01237 01238 if(xy_type == 'v') 01239 { 01240 *N = n = nval; 01241 01242 if((*vector = (double *) MALLOC(n*sizeof(double ))) == NULL){ 01243 sciprint(_("%s: No more memory.\n"),"ComputeXIntervals"); 01244 return -1; 01245 } 01246 01247 for(i=0;i<n;i++) 01248 (*vector)[i] = val[i]; 01249 } 01250 else if(xy_type == 'r') 01251 { 01252 double step = 0; 01253 01254 *N = n = (int)val[2]+1; /* intervals number is given by ppaxes->x or ppaxes->y */ 01255 01256 if(checkdim){ 01257 if(nval != 3) 01258 sciprint(_("Warning: %s must be changed, %s is '%s' and %s dimension is not %d.\n"),"tics_coord","xy_type","r","tics_coord",3); 01259 01260 if(nval < 3){ 01261 sciprint(_("Error: %s must be changed FIRST, %s is '%s' and %s dimension < %d.\n"),"tics_coord","xy_type","r","tics_coord",3); 01262 *vector = (double *) NULL; 01263 return -1; 01264 } 01265 } 01266 01267 if((*vector = (double *) MALLOC(n*sizeof(double ))) == NULL){ 01268 sciprint(_("%s: No more memory.\n"),"ComputeXIntervals"); 01269 return -1; 01270 } 01271 01272 step = (val[1] - val[0])/(n-1); 01273 01274 for(i=0;i<n-1;i++) 01275 (*vector)[i] = val[0] + i*step; 01276 01277 (*vector)[n-1] = val[1]; /* xmax */ 01278 01279 } 01280 else if(xy_type == 'i') 01281 { 01282 double step = 0; 01283 01284 *N = n = (int)val[3]+1; 01285 01286 if(checkdim){ 01287 if(nval != 4) 01288 sciprint(_("Warning: %s must be changed, %s is '%S' and %s dimension is not %d.\n"),"tics_coord","xy_type","i","tics_coord",4); 01289 01290 if(nval < 4){ 01291 sciprint(_("Error: %s must be changed FIRST, %s is '%s' and %s dimension < %d.\n"),"tics_coord","xy_type","i","tics_coord",4); 01292 *vector = (double *) NULL; 01293 return -1; 01294 } 01295 } 01296 01297 if((*vector =(double *) MALLOC(n*sizeof(double ))) == NULL){ 01298 sciprint(_("%s: No more memory.\n"),"ComputeXIntervals"); 01299 return -1; 01300 } 01301 01302 step = (val[1]*exp10(val[2]) - val[0]*exp10(val[2]))/val[3]; 01303 01304 01305 for(i=0;i<n-1;i++) 01306 (*vector)[i] = val[0]*exp10(val[2]) + i*step; 01307 01308 (*vector)[n-1] = val[1]*exp10(val[2]); /* xmax */ 01309 01310 } 01311 01312 return 0; 01313 }


| char** copyFormatedArray | ( | const double | values[], | |
| int | nbStrings, | |||
| const char | format[5], | |||
| int | bufferSize | |||
| ) |
Create a new string array which is the conversion of the doubles values.
| bufferSize | size of the buffer used to store the store before the copying it to the result. It must greater than the length of any of the strings. and ideally the maximum length. |
Definition at line 1479 of file Format.c.
References _, copyFormatedValue(), i, MALLOC, NULL, res, and sciprint().
Referenced by sciGraphics::AxesTicksComputer::getTicksPosition(), set_xtics_coord_property(), and set_ytics_coord_property().
01480 { 01481 int i ; 01482 char ** res = MALLOC( nbStrings * sizeof(char *) ) ; 01483 01484 if ( res == NULL ) 01485 { 01486 sciprint(_("%s: No more memory.\n"),"copyFormatedArray"); 01487 return NULL ; 01488 } 01489 01490 for ( i = 0 ; i < nbStrings ; i++ ) 01491 { 01492 res[i] = copyFormatedValue( values[i], format, bufferSize ) ; 01493 } 01494 01495 return res ; 01496 01497 }


| char* copyFormatedValue | ( | double | value, | |
| const char | format[5], | |||
| int | bufferSize | |||
| ) |
Create a new string which is the result the conversion of a double value using a certain format
| bufferSize | size of the buffer used to store the store before the copying it to the result. It must greater than the length of the returning string. and ideally the same length. |
Definition at line 1447 of file Format.c.
References _, buffer, FREE, MALLOC, NULL, res, and sciprint().
Referenced by copyFormatedArray().
01448 { 01449 char * buffer = MALLOC( bufferSize * sizeof(char) ) ; 01450 char * res = NULL ; 01451 int resLength = 0 ; 01452 01453 if ( buffer == NULL ) 01454 { 01455 sciprint(_("%s: No more memory.\n"),"copyFormatedValue"); 01456 return NULL ; 01457 } 01458 01459 sprintf( buffer , format, value ) ; 01460 01461 resLength = (int)strlen( buffer ) + 1 ; /* + 1 <=> 0 terminating char */ 01462 01463 res = MALLOC( resLength * sizeof(char) ) ; 01464 01465 if ( res == NULL ) 01466 { 01467 sciprint(_("%s: No more memory.\n"),"copyFormatedValue"); 01468 FREE( buffer ) ; 01469 return NULL ; 01470 } 01471 01472 strncpy( res, buffer, resLength ) ; 01473 01474 FREE( buffer ) ; 01475 01476 return res ; 01477 }


| void correctBounds | ( | double | min, | |
| double | max, | |||
| double * | lBound, | |||
| double * | uBound | |||
| ) |
add comment
| min | ||
| max | ||
| lBound | ||
| uBound |
| [in] | min | Given minimal bound. |
| [in] | max | Given maximal bound. |
| [out] | lBound | New lower bound which can be displayed. |
| [out] | uBound | New upper bound which can be displayed. |
Definition at line 714 of file Format.c.
00715 { 00716 double offset ; 00717 00718 if ( Abs(min) < 10.0 && Abs(max) < 10.0 ) 00719 { 00720 /* we can use 1 */ 00721 offset = 1.0 ; 00722 } 00723 else 00724 { 00725 /* get the power 10 just below |min| and |max| */ 00726 /* we could use 1 also but for huge values this does not work (if val + 1 == val) */ 00727 offset = pow( 10.0, floor( log10( Max( Abs(min), Abs(max) ) ) ) ) ; 00728 } 00729 00730 /* first try to just get the closest integer */ 00731 *lBound = floor( min ) ; 00732 *uBound = ceil( max ) ; 00733 00734 00735 /* check if it is enough */ 00736 if ( min - *lBound < 0.2 ) 00737 { 00738 *lBound = *lBound - offset ; 00739 } 00740 if ( *uBound - max < 0.2 ) 00741 { 00742 *uBound = *uBound + offset ; 00743 } 00744 }
| char* getFPF | ( | void | ) |
add comment
| void |
Definition at line 1506 of file Format.c.
Referenced by contourI().
01507 { 01508 return(FPF); 01509 }
