00001
00002
00003
00004
00005
00006 #include <string.h>
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"
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
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
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;
00099 BOOL containsSurface = FALSE ;
00100 int with_leg;
00101 double drect[6];
00102 char dataflag;
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
00111 checkRedrawing() ;
00112
00113 if ( sciGetSurface(psubwin) != NULL )
00114 {
00115 containsSurface = TRUE ;
00116 }
00117
00118 if (sciGetSurface(psubwin) == (sciPointObj *) NULL)
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
00140
00141
00142
00143
00144
00145
00146 if ( ppsubwin->FirstPlot )
00147 {
00148 ppsubwin->logflags[0]=logflags[1];
00149 ppsubwin->logflags[1]=logflags[2];
00150 }
00151
00152
00153 sciSetIsClipping (psubwin,0);
00154
00155
00156
00157
00158 if (sciGetGraphicMode (psubwin)->autoscaling) {
00159
00160 switch (strflag[1]) {
00161 case '0':
00162
00163 break;
00164 case '1' : case '3' : case '5' : case '7':
00165
00166 re_index_brect(brect, drect);
00167 break;
00168 case '2' : case '4' : case '6' : case '8': case '9':
00169
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')) {
00176
00177 drect[0] = Min(ppsubwin->SRect[0],drect[0]);
00178 drect[2] = Min(ppsubwin->SRect[2],drect[2]);
00179 drect[1] = Max(ppsubwin->SRect[1],drect[1]);
00180 drect[3] = Max(ppsubwin->SRect[3],drect[3]);
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;
00192
00193 with_leg= (strflag[0] == '1');
00194 ppsubwin->with_leg = with_leg;
00195
00196
00197
00198
00199 ppsubwin->flagNax = 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;
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
00216
00217
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
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++) {
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 ());
00258
00259 frame_clip_off ();
00260
00261
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
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
00284 return(0);
00285 }
00286
00287
00288
00289
00290
00291
00292
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 {
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{
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{
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{
00353 drect[2] = 1.0;
00354 drect[3] = 10.0;
00355 }
00356 }
00357
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
00367
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
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
00439
00440
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
00448
00449
00450 return 0;
00451 }
00452
00453
00454
00455 BOOL strflag2axes_properties(sciPointObj * psubwin, char * strflag)
00456 {
00457 BOOL haschanged = FALSE;
00458 sciSubWindow * ppsubwin = pSUBWIN_FEATURE (psubwin);
00459
00460
00461
00462 switch (strflag[1]) {
00463 case '0': case '9':
00464
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
00472 break;
00473 case '3' : case '4' :
00474
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;
00483 haschanged = TRUE;
00484 }
00485
00486 break;
00487 }
00488
00489
00490
00491 switch (strflag[2]) {
00492 case '0':
00493 if(ppsubwin->FirstPlot == TRUE){
00494
00495 ppsubwin->axes.axes_visible[0] = FALSE;
00496 ppsubwin->axes.axes_visible[1] = FALSE;
00497 ppsubwin->axes.axes_visible[2] = FALSE;
00498 ppsubwin->axes.rect = BT_OFF;
00499 haschanged = TRUE;
00500 }
00501
00502 break;
00503 case '1' :
00504
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;
00512 ppsubwin->axes.ydir ='l';
00513 ppsubwin->axes.rect = BT_ON;
00514 haschanged = TRUE;
00515 }
00516 break;
00517 case '2' :
00518
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;
00525 ppsubwin->axes.rect = BT_ON;
00526 haschanged = TRUE;
00527 }
00528 break;
00529 case '3' :
00530
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;
00538 ppsubwin->axes.ydir ='r';
00539 haschanged = TRUE;
00540 }
00541 break;
00542 case '4' :
00543
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;
00550 ppsubwin->axes.rect = BT_ON;
00551
00552 haschanged = TRUE;
00553 }
00554 break;
00555 case '5' :
00556
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;
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
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;
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
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
00620
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
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
00638
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
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