00001 #include "coxplot.h"
00002 #include <math.h>
00003
00004 #ifndef WAY_BIG
00005 # define WAY_BIG 1.e+10
00006 #endif
00007
00008 static float p10( float x ) ;
00009
00010 #undef NCLR
00011 #define NCLR 4
00012 static float ccc[NCLR][3] = {
00013 { 0.0 , 0.0 , 0.0 } ,
00014 { 0.9 , 0.0 , 0.0 } ,
00015 { 0.0 , 0.7 , 0.0 } ,
00016 { 0.0 , 0.0 , 0.9 } ,
00017 } ;
00018
00019 #define STGOOD(s) ( (s) != NULL && (s)[0] != '\0' )
00020
00021 #define THIK 0.003
00022 #define SY 0.07
00023
00024
00025
00026
00027
00028
00029
00030 static float p10( float x )
00031 {
00032 double y ;
00033
00034 if( x == 0.0 ) return 0.0 ;
00035 if( x < 0.0 ) x = -x ;
00036 y = floor(log10(x)+0.000001) ; y = pow( 10.0 , y ) ;
00037 return (float) y ;
00038 }
00039
00040
00041
00042
00043
00044
00045 MEM_topshell_data * plot_strip_init( Display * dpy ,
00046 int nx , float dx ,
00047 int ny , float ybot , float ytop ,
00048 char * lab_xxx , char * lab_yyy ,
00049 char * lab_top , char ** nam_yyy ,
00050 void_func * killfunc )
00051 {
00052 int ii , jj , np , nnax,nnay , mmax,mmay , yall ;
00053 float pbot,ptop , xobot,xotop,yobot,yotop , yll,yhh ;
00054 char str[32] ;
00055 float *ud ;
00056 MEM_topshell_data * mp ;
00057 MEM_plotdata * mplot ;
00058
00059
00060
00061 if( dpy == NULL || ny == 0 || nx < 9 || ybot >= ytop ) return NULL ;
00062
00063 if( dx <= 0.0 ) dx = 1.0 ;
00064
00065 yall = (ny > 0) ; if( !yall ) ny = -ny ; if( ny == 1 ) yall = 1 ;
00066
00067
00068
00069 ptop = p10(nx) ;
00070 nnax = rint(nx/ptop) ;
00071 if( nnax == 1 ) nnax = 10 ;
00072 mmax = (nnax < 3) ? 10
00073 : (nnax < 6) ? 5 : 2 ;
00074
00075 pbot = p10(ybot) ; ptop = p10(ytop) ; if( ptop < pbot ) ptop = pbot ;
00076 nnay = rint((ytop-ybot)/ptop) ;
00077 if( nnay == 1 ) nnay = 10 ;
00078 mmay = (nnay < 3) ? 10
00079 : (nnay < 6) ? 5 : 2 ;
00080
00081
00082
00083 create_memplot_surely( "Striplot" , 1.3 ) ;
00084 set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00085 set_thick_memplot( 0.0 ) ;
00086 mplot = get_active_memplot() ;
00087
00088
00089
00090 xobot = 0.15 ; xotop = 1.27 ;
00091 yobot = 0.1 ; yotop = 0.95 ;
00092
00093 if( STGOOD(lab_top) ){ yotop -= 0.02 ; yobot -= 0.01 ; }
00094 if( nam_yyy != NULL ){ xotop -= 0.16 ; xobot -= 0.02 ; }
00095
00096
00097
00098 if( STGOOD(lab_xxx) )
00099 plotpak_pwritf( 0.5*(xobot+xotop) , yobot-0.06 , lab_xxx , 16 , 0 , 0 ) ;
00100
00101
00102
00103 if( STGOOD(lab_yyy) )
00104 plotpak_pwritf( xobot-0.10 , 0.5*(yobot+yotop) , lab_yyy , 16 , 90 , 0 ) ;
00105
00106
00107
00108 if( STGOOD(lab_top) )
00109 plotpak_pwritf( xobot+0.01 , yotop+0.01 , lab_top , 18 , 0 , -2 ) ;
00110
00111
00112
00113 if( yall ){
00114
00115
00116
00117 if( nam_yyy != NULL ){
00118 float yv = yotop ; int sz ;
00119
00120 for( jj=0 ; jj < ny ; jj++ ){
00121 if( STGOOD(nam_yyy[jj]) ){
00122 set_color_memplot( ccc[jj%NCLR][0] , ccc[jj%NCLR][1] , ccc[jj%NCLR][2] ) ;
00123 set_thick_memplot( 2*THIK ) ;
00124 plotpak_line( xotop+0.008 , yv , xotop+0.042 , yv ) ;
00125 set_thick_memplot( 0.0 ) ;
00126 set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00127 sz = (strlen(nam_yyy[jj]) <= 10) ? 12 : 10 ;
00128 plotpak_pwritf( xotop+0.048 , yv , nam_yyy[jj] , sz , 0 , -1 ) ;
00129 yv -= 0.05 ;
00130 }
00131 }
00132 }
00133
00134
00135
00136 plotpak_set( xobot,xotop , yobot,yotop , 0.0,nx*dx , ybot,ytop , 1 ) ;
00137 plotpak_periml( nnax,mmax , nnay,mmay ) ;
00138
00139 } else {
00140
00141 float dyo = (yotop-yobot) / ( (1.0+SY) * ny - SY ) ;
00142
00143
00144
00145 if( nam_yyy != NULL ){
00146 float yv = yotop ; int sz ;
00147
00148 for( jj=0 ; jj < ny ; jj++ ){
00149 yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00150 if( STGOOD(nam_yyy[jj]) ){
00151 set_color_memplot( ccc[jj%NCLR][0] , ccc[jj%NCLR][1] , ccc[jj%NCLR][2] ) ;
00152 set_thick_memplot( 2*THIK ) ;
00153 yv = 0.7*yhh + 0.3*yll ;
00154 plotpak_line( xotop+0.008 , yv , xotop+0.042 , yv ) ;
00155 set_thick_memplot( 0.0 ) ;
00156 set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00157 sz = (strlen(nam_yyy[jj]) <= 10) ? 12 : 10 ;
00158 plotpak_pwritf( xotop+0.048 , yv , nam_yyy[jj] , sz , 0 , -1 ) ;
00159 }
00160 }
00161 }
00162
00163
00164
00165 nnay = 1 ;
00166 pbot = p10(ybot) ; ptop = p10(ytop) ;
00167 if( ptop > pbot && pbot > 0.0 ) ptop = pbot ;
00168 if( ptop != 0.0 ) mmay = floor( (ytop-ybot) / ptop + 0.5 ) ;
00169 else mmay = 5 ;
00170
00171 if( mmay == 1 ) mmay = 5 ;
00172 else if( mmay == 2 ) mmay = 4 ;
00173 else if( mmay == 3 ) mmay = 6 ;
00174
00175 for( jj=ny-1 ; jj >= 0 ; jj-- ){
00176 yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00177
00178 plotpak_set( xobot,xotop , yll,yhh , 0.0,nx*dx , ybot,ytop , 1 ) ;
00179
00180 plotpak_perimm( nnax,mmax , nnay,mmay , (jj==0) ? 1 : 3 ) ;
00181 if( ybot < 0.0 && ytop > 0.0 ){
00182 plotpak_setlin(5) ;
00183 plotpak_line( 0.0,0.0 , nx*dx,0.0 ) ;
00184 plotpak_setlin(1) ;
00185 }
00186 }
00187 }
00188
00189
00190
00191 mp = memplot_to_topshell( dpy , mplot , killfunc ) ;
00192 if( mp == NULL ) return NULL ;
00193
00194
00195
00196 ud = (float *) calloc( (12+ny) , sizeof(float) ) ;
00197 ud[0] = xobot ; ud[1] = xotop ; ud[2] = yobot ; ud[3] = yotop ;
00198 ud[4] = 0.0 ; ud[5] = nx ; ud[6] = ybot ; ud[7] = ytop ;
00199 ud[8] = ny ; ud[9] = yall ;
00200
00201 ud[10] = MEMPLOT_NLINE(mplot) ;
00202 ud[11] = -1 ;
00203
00204 mp->userdata = ud ;
00205
00206
00207
00208
00209
00210
00211 for( jj=0 ; jj < ny ; jj++ )
00212 for( ii=0 ; ii < nx ; ii++ )
00213 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00214
00215
00216
00217
00218
00219 for( jj=0 ; jj < 2*ny ; jj++ )
00220 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00221
00222
00223
00224 return mp ;
00225 }
00226
00227
00228
00229 void plot_strip_addto( MEM_topshell_data * mp , int nadd , float **y )
00230 {
00231 int ii , jj , yall , start , xx , nx , ny ;
00232 float pbot,ptop , xobot,xotop,yobot,yotop , yll,yhh ;
00233 float xbot,xtop , ybot,ytop ;
00234 float dxx , dyy ;
00235 float * ud ;
00236 MEM_plotdata *mplot ;
00237
00238 if( mp == NULL || mp->userdata == NULL ||
00239 !mp->valid || nadd <= 0 || y == NULL ) return ;
00240
00241 ud = (float *) mp->userdata ;
00242 xobot = ud[0] ; xotop = ud[1] ; yobot = ud[2] ; yotop = ud[3] ;
00243 xbot = ud[4] ; xtop = ud[5] ; ybot = ud[6] ; ytop = ud[7] ;
00244 ny = ud[8] ; yall = ud[9] ; start = ud[10]; xx = ud[11];
00245 nx = xtop ;
00246
00247 if( nadd > nx ) nadd = nx ;
00248
00249 mplot = mp->mp ;
00250 ii = set_active_memplot( MEMPLOT_IDENT(mplot) ) ;
00251 if( ii != 0 ) return ;
00252
00253 dxx = 0.01*nx ;
00254
00255
00256
00257 if( yall ){
00258
00259 dyy = 0.01*(ytop-ybot) ;
00260
00261 plotpak_set( xobot,xotop , yobot,yotop , xbot,xtop , ybot,ytop , 1 ) ;
00262 set_thick_memplot( THIK ) ;
00263
00264 if( xx >= 0 ){
00265 for( jj=0 ; jj < ny ; jj++ ){
00266 insert_at_memplot( start + xx + jj*nx , mplot ) ;
00267 if( ud[12+jj] < WAY_BIG && y[jj][0] < WAY_BIG ){
00268 set_color_memplot( ccc[jj%NCLR][0], ccc[jj%NCLR][1], ccc[jj%NCLR][2] ) ;
00269 plotpak_line( xx , ud[12+jj] , xx+1 , y[jj][0] ) ;
00270 } else {
00271 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00272 }
00273 }
00274 xx++ ; if( xx == nx ) xx = 0 ;
00275
00276 } else {
00277 xx = 0 ;
00278 }
00279
00280 for( ii=1 ; ii < nadd ; ii++ ){
00281 for( jj=0 ; jj < ny ; jj++ ){
00282 insert_at_memplot( start + xx + jj*nx , mplot ) ;
00283 if( y[jj][ii-1] < WAY_BIG && y[jj][ii] < WAY_BIG ){
00284 set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00285 plotpak_line( xx , y[jj][ii-1] , xx+1 , y[jj][ii] ) ;
00286 } else {
00287 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00288 }
00289 }
00290 xx++ ; if( xx == nx ) xx = 0 ;
00291 }
00292
00293
00294
00295 set_thick_memplot( 2*THIK ) ;
00296
00297 ii = nadd-1 ;
00298 for( jj=0 ; jj < ny ; jj++ ){
00299 if( y[jj][ii] < WAY_BIG ){
00300 set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00301 insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00302 plotpak_line( xx-dxx , y[jj][ii]-dyy , xx+dxx , y[jj][ii]+dyy ) ;
00303 insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00304 plotpak_line( xx-dxx , y[jj][ii]+dyy , xx+dxx , y[jj][ii]-dyy ) ;
00305 } else {
00306 insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00307 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00308 insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00309 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00310 }
00311 }
00312
00313 } else {
00314
00315 float dyo = (yotop-yobot) / ( (1.0+SY) * ny - SY ) ;
00316
00317 dyy = 0.01*(ytop-ybot)*ny ;
00318
00319 set_thick_memplot( THIK ) ;
00320
00321 if( xx >= 0 ){
00322 for( jj=0 ; jj < ny ; jj++ ){
00323 insert_at_memplot( start + xx + jj*nx , mplot ) ;
00324 if( ud[12+jj] < WAY_BIG && y[jj][0] < WAY_BIG ){
00325 yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00326 plotpak_set( xobot,xotop , yll,yhh , xbot,xtop , ybot,ytop , 1 ) ;
00327 set_color_memplot( ccc[jj%NCLR][0], ccc[jj%NCLR][1], ccc[jj%NCLR][2] ) ;
00328 plotpak_line( xx , ud[12+jj] , xx+1 , y[jj][0] ) ;
00329 } else {
00330 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00331 }
00332 }
00333 xx++ ; if( xx == nx ) xx = 0 ;
00334
00335 } else {
00336 xx = 0 ;
00337 }
00338
00339 for( ii=1 ; ii < nadd ; ii++ ){
00340 for( jj=0 ; jj < ny ; jj++ ){
00341 insert_at_memplot( start + xx + jj*nx , mplot ) ;
00342 if( y[jj][ii-1] < WAY_BIG && y[jj][ii] < WAY_BIG ){
00343 yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00344 plotpak_set( xobot,xotop , yll,yhh , xbot,xtop , ybot,ytop , 1 ) ;
00345 set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00346 plotpak_line( xx , y[jj][ii-1] , xx+1 , y[jj][ii] ) ;
00347 } else {
00348 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00349 }
00350 }
00351 xx++ ; if( xx == nx ) xx = 0 ;
00352 }
00353
00354
00355
00356 set_thick_memplot( 2*THIK ) ;
00357
00358 ii = nadd-1 ;
00359 for( jj=0 ; jj < ny ; jj++ ){
00360 if( y[jj][ii] < WAY_BIG ){
00361 yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00362 plotpak_set( xobot,xotop , yll,yhh , xbot,xtop , ybot,ytop , 1 ) ;
00363 set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00364 insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00365 plotpak_line( xx-dxx , y[jj][ii]-dyy , xx+dxx , y[jj][ii]+dyy ) ;
00366 insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00367 plotpak_line( xx-dxx , y[jj][ii]+dyy , xx+dxx , y[jj][ii]-dyy ) ;
00368 } else {
00369 insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00370 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00371 insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00372 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00373 }
00374 }
00375
00376 }
00377
00378
00379
00380 insert_at_memplot( -1 , mplot ) ;
00381 set_thick_memplot( 0.0 ) ;
00382 set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00383
00384
00385
00386 redraw_topshell( mp ) ;
00387
00388
00389
00390 ud[11] = xx ;
00391 for( jj=0 ; jj < ny ; jj++ )
00392 ud[12+jj] = y[jj][nadd-1] ;
00393
00394 return ;
00395 }
00396
00397
00398
00399
00400
00401
00402 void plot_strip_clear( MEM_topshell_data * mp )
00403 {
00404 int ii , jj , start , nx , ny ;
00405 float * ud ;
00406 MEM_plotdata *mplot ;
00407
00408 if( mp == NULL || mp->userdata == NULL || !mp->valid ) return ;
00409
00410 ud = (float *) mp->userdata ;
00411 nx = ud[5] ; ny = ud[8] ; start = ud[10] ;
00412
00413 mplot = mp->mp ;
00414
00415 for( jj=0 ; jj < ny ; jj++ ){
00416
00417 for( ii=0 ; ii < nx ; ii++ ){
00418 insert_at_memplot( start + ii + jj*nx , mplot ) ;
00419 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00420 }
00421
00422 insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00423 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00424 insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00425 ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00426 }
00427
00428 insert_at_memplot( -1 , mplot ) ;
00429 redraw_topshell( mp ) ;
00430
00431 ud[11] = -1 ;
00432 return ;
00433 }