00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #include "common.h"
00061
00062
00063 #include <stdio.h>
00064 #ifdef HAVE_STRING_H
00065 # include <string.h>
00066 #else
00067 # include <strings.h>
00068 #endif
00069 #include <math.h>
00070
00071
00072 #include "machine.h"
00073 #include "vmath.h"
00074 #include "plot3.h"
00075
00076
00077 #define TIC 100
00078 #define REF_WIDTH 0.857143
00079 #define NUM_DISTANCE 250
00080 #define LAB_LNGTH 860
00081
00082 void tp_ftoa(float x, char *s);
00083 void tp_fixsc(float *x, int npts, float size, float *xs, float *xmin, float *xmax, float *dx);
00084 void tp_sep(float x, float *coef, int *ex);
00085 double tp_ipow(double x, int n);
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void
00102 tp_plot(FILE *fp,
00103 int xp,
00104 int yp,
00105 int xl,
00106 int yl,
00107 char *xtitle,
00108 char *ytitle,
00109 float *x,
00110 float *y,
00111 int n,
00112 double cscale)
00113 {
00114 int ddx, ddy, xend, yend, xpen, ypen;
00115 float fxl, fyl, xs, ys, xmin, xmax, ymin, ymax, dx, dy;
00116 float lab;
00117 int xtics, ytics, i, xtl, ytl, j;
00118 int ix[101], iy[101], isave;
00119 char str[32];
00120
00121 if( xl == 0 ){
00122 j = 0;
00123 goto loop;
00124 }
00125 fxl = xl/1000.0;
00126 fyl = yl/1000.0;
00127 n -= 1;
00128 tp_fixsc (x, n, fxl, &xs, &xmin, &xmax, &dx);
00129 tp_fixsc (y, n, fyl, &ys, &ymin, &ymax, &dy);
00130 ddx = dx*xs;
00131 ddy = dy*ys;
00132 xtics = LAB_LNGTH / ddx + 1.0;
00133 ytics = 500/ddy + 1.0;
00134 xend = xl+xp;
00135 xpen = xp;
00136
00137 pl_move(fp, xpen, yp-TIC);
00138 pl_cont(fp, xpen,yp);
00139
00140
00141 lab = xmin;
00142 sprintf( str, "%3.3g", xmin );
00143 tp_2symbol( fp, str, (double)(xpen-171),(double)(yp-TIC-NUM_DISTANCE), cscale, 0.0);
00144
00145 i = 0;
00146 while((xpen+ddx)<=xend){
00147 i++;
00148 xpen += ddx;
00149 pl_line( fp, xpen, yp, xpen, yp-TIC );
00150
00151 lab += dx;
00152
00153 if( (i%xtics) == 0){
00154 sprintf( str, "%3.3g", lab );
00155 tp_2symbol( fp, str, (double)(xpen-171), (double)(yp-TIC-NUM_DISTANCE), cscale, 0.0);
00156 }
00157 }
00158
00159
00160 xtl = xp+(xl - strlen(xtitle)*cscale)/2;
00161 ytl = yp - 8 * cscale;
00162 tp_2symbol( fp, xtitle,(double)xtl, (double)ytl, 100.0, 0.0);
00163 yend = yl+yp;
00164 ypen= yp;
00165 pl_line( fp, xp-TIC, ypen, xp, ypen );
00166
00167
00168 lab = ymin;
00169 sprintf( str, "%3.3g", lab );
00170 tp_2symbol( fp,str, (double)(xp-TIC-LAB_LNGTH-NUM_DISTANCE), (double)ypen, cscale, 0.0);
00171
00172 i=0;
00173 while((ypen+ddy)<=yend){
00174 i++;
00175 ypen += ddy;
00176 pl_line( fp, xp, ypen, xp-TIC, ypen );
00177
00178 lab += dy;
00179 if(( i%ytics) ==0){
00180 sprintf( str, "%3.3g", lab );
00181 tp_2symbol( fp,str, (double)(xp-TIC-LAB_LNGTH-NUM_DISTANCE), (double)ypen, cscale, 0.0);
00182 }
00183 }
00184
00185
00186 xtl= xp-1500;
00187 ytl= yp + (yl - strlen(ytitle)*cscale)/2 ;
00188 tp_2symbol( fp,ytitle,(double)xtl,(double)ytl,100.0,90.0);
00189
00190
00191 j = 0;
00192
00193 loop:
00194 if( n <= 100 ) {
00195 isave = n-1;
00196 } else {
00197 isave = 100;
00198 n -= 101;
00199 }
00200
00201 if(j == 0){
00202 ix[0] = (x[j] - xmin)*xs + xp;
00203 iy[0] = (y[j] - ymin)*ys + yp;
00204 j++;
00205 } else {
00206 ix[0] = (x[j-1] - xmin)*xs + xp;
00207 iy[0] = (y[j-1] - ymin)*ys + yp;
00208 }
00209
00210 i = 1;
00211 while( i <= isave ){
00212 ix[i] = (x[j] - xmin)*xs + xp;
00213 iy[i] = (y[j] - ymin)*ys + yp;
00214 i++;
00215 j++;
00216 }
00217 tp_i2list( fp, ix, iy, isave+1 );
00218 if( isave == 100 ) {
00219 goto loop;
00220 }
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230 void
00231 tp_ftoa(float x, char *s)
00232 {
00233 int ex,tmp;
00234 float coef;
00235 char esgn, nsgn;
00236 char i;
00237
00238 tp_sep(x, &coef, &ex);
00239 if( ex < -15 ){
00240 ex = 0;
00241 *s++ = '0';
00242 *s++ = '.';
00243 *s++ = '0';
00244 *s++ = '0';
00245 *s++ = '0';
00246 *s++ = 'e';
00247 *s++ = '+';
00248 *s++ = '0';
00249 *s++ = '0';
00250 *s = 0 ;
00251 return;
00252 }
00253
00254 if(ex < 0){
00255 esgn = '-';
00256 ex = -ex;
00257 } else {
00258 esgn = '+';
00259 }
00260
00261 if( coef < 0.0){
00262 nsgn = '-';
00263 coef = -coef;
00264 } else {
00265 nsgn = ' ';
00266 }
00267 *s++ = nsgn;
00268
00269
00270 tmp = coef;
00271 *s++ = tmp + '0';
00272 coef = (coef - tmp)*10.0;
00273 *s++ = '.';
00274
00275
00276 for( i=1 ; i<=3 ; ++i){
00277 tmp = coef;
00278 coef = (coef - tmp)*10.0;
00279 *s++ = tmp + '0';
00280 }
00281
00282
00283 *s++ = 'e';
00284
00285
00286 *s++ = esgn;
00287
00288
00289 if( ex < 0)
00290 ex = -ex;
00291
00292 if( ex < 10 ){
00293 *s++ = '0';
00294 *s++ = ex + '0';
00295 } else{
00296 tmp = ex/10;
00297 *s++ = tmp + '0';
00298 ex = ex - tmp*10;
00299 *s++ = ex +'0';
00300 }
00301
00302 *s = 0;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 void
00332 tp_fixsc(float *x,
00333 int npts,
00334 float size,
00335 float *xs,
00336 float *xmin,
00337 float *xmax,
00338 float *dx)
00339 {
00340 float txmi, txma, coef, delta, diff;
00341 int i, ex;
00342
00343 txmi=txma=x[0];
00344 i = 0;
00345 while( i <= npts ) {
00346 if( x[i] < txmi)
00347 txmi = x[i];
00348 if( x[i] > txma)
00349 txma = x[i];
00350 i++;
00351 }
00352
00353 diff = txma - txmi;
00354 if( diff < .000001 )
00355 diff = .000001;
00356
00357 tp_sep (diff, &coef, &ex);
00358 if( coef < 2.0 )
00359 delta = .1;
00360 else if ( coef < 4.0 )
00361 delta = .2;
00362 else
00363 delta = .5;
00364
00365 i = 0;
00366 if(ex < 0 ){
00367 ex = -ex;
00368 i=12;
00369 }
00370
00371 delta *= tp_ipow(10.0,ex);
00372 if(i == 12)
00373 delta = 1.0/delta;
00374 *dx = delta;
00375
00376 i = (fabs(txmi)/delta);
00377 *xmin = i*delta;
00378 if( txmi < 0.0 )
00379 *xmin = -(*xmin+delta);
00380
00381 i = (fabs(txma)/delta);
00382 *xmax = i*delta;
00383 if( txma < 0.0)
00384 *xmax = - *xmax;
00385 else
00386 *xmax = *xmax+delta;
00387 *xs = 1000.*size/(*xmax - *xmin);
00388 }
00389
00390
00391
00392
00393
00394
00395
00396 void
00397 tp_sep(float x, float *coef, int *ex)
00398 {
00399 int i, isv;
00400 float xx;
00401
00402 isv = 1;
00403 if(x < 0.0 ){
00404 isv = -1;
00405 x = -x;
00406 }
00407
00408 if( x > 1.0 ){
00409 xx = x;
00410 *ex = 0;
00411 *coef = 0.0;
00412
00413 if ( xx < 10.0){
00414 *coef = xx*isv;
00415 return;
00416 }
00417
00418 for ( i=1 ; i < 39 ; ++i){
00419 *ex += 1;
00420 xx = xx/10.0;
00421 if( xx < 10.0 )
00422 break;
00423 }
00424 *coef = xx*isv;
00425 return;
00426 } else{
00427 xx = x;
00428 *ex = 0;
00429 *coef = 0.0;
00430 for ( i=1 ; i<39 ; ++i){
00431 *ex -= 1;
00432 xx *= 10.0;
00433 if( xx >= 1.0 )
00434 break;
00435 }
00436 *coef = xx*isv;
00437 return;
00438 }
00439 }
00440
00441
00442
00443
00444
00445
00446
00447
00448 double tp_ipow (double x, int n)
00449 {
00450 return(n>0?x*tp_ipow(x,n-1):1);
00451 }
00452
00453
00454
00455
00456
00457 void
00458 PL_FORTRAN(fplot, FPLOT)(FILE **fp, int *xp, int *yp, int *xl, int *yl, char *xtitle, char *ytitle, float *x, float *y, int *n, float *cscale)
00459 {
00460 tp_plot(*fp, *xp, *yp, *xl, *yl, xtitle, ytitle, x, y, *n, *cscale);
00461 }
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472