[2696] | 1 | #include <stdio.h> |
---|
| 2 | #include <math.h> |
---|
| 3 | #include <ctype.h> |
---|
| 4 | #include <ncarg/ncargC.h> |
---|
| 5 | #include <ncarg/gks.h> |
---|
| 6 | #include "ncar.h" |
---|
| 7 | |
---|
| 8 | #define MAX_COLORS 9 |
---|
| 9 | #define MAX_GRAPHS 8 |
---|
| 10 | #define WS_ID 1 |
---|
| 11 | |
---|
| 12 | Grgb colors[] = {{ 0.0, 0.0, 0.0 }, |
---|
| 13 | { 1.0, 1.0, 1.0 }, |
---|
| 14 | { 0.0, 1.0, 0.0 }, |
---|
| 15 | { 1.0, 1.0, 0.0 }, |
---|
| 16 | { 0.0, 1.0, 1.0 }, |
---|
| 17 | { 1.0, 0.4, 0.4 }, |
---|
| 18 | { 1.0, 0.0, 1.0 }, |
---|
| 19 | { 0.7, 1.0, 0.7 }, |
---|
| 20 | { 0.5, 0.5, 1.0 } |
---|
| 21 | }; |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | int nGraphs = 0; |
---|
| 25 | int nMax; |
---|
| 26 | int nCrt; |
---|
| 27 | int CrtGraph; |
---|
| 28 | |
---|
| 29 | char *graphName[ MAX_GRAPHS ]; |
---|
| 30 | char *graphTitle; |
---|
| 31 | char * startMsg = "Working... Press CTRL-C to stop"; |
---|
| 32 | char * endMsg = "DONE ! Press <ENTER> when ready."; |
---|
| 33 | char * status = "S"; |
---|
| 34 | |
---|
| 35 | float * Xval; |
---|
| 36 | float * Yval; |
---|
| 37 | float * scale; |
---|
| 38 | float * offset; |
---|
| 39 | float ch; |
---|
| 40 | |
---|
| 41 | float XminGraph, XmaxGraph; |
---|
| 42 | float Ybottom[ MAX_GRAPHS ]; |
---|
| 43 | float Ytop[ MAX_GRAPHS ]; |
---|
| 44 | float Ymin[ MAX_GRAPHS ]; |
---|
| 45 | float Ymax[ MAX_GRAPHS ]; |
---|
| 46 | float Ybase[ MAX_GRAPHS ]; |
---|
| 47 | |
---|
| 48 | int crtState; |
---|
| 49 | int clean = 0; |
---|
| 50 | |
---|
| 51 | void Boundary(); |
---|
| 52 | |
---|
| 53 | void OpenWin() |
---|
| 54 | { |
---|
| 55 | int i; |
---|
| 56 | Gcolr_rep colr; |
---|
| 57 | |
---|
| 58 | gopen_gks( "stdout", 0 ); |
---|
| 59 | gopen_ws( WS_ID, (char*)0, 8 ); |
---|
| 60 | gactivate_ws( WS_ID ); |
---|
| 61 | |
---|
| 62 | for( i = 0; i < MAX_COLORS; i++ ) { |
---|
| 63 | colr.rgb.red = colors[i].red; |
---|
| 64 | colr.rgb.green = colors[i].green; |
---|
| 65 | colr.rgb.blue = colors[i].blue; |
---|
| 66 | gset_colr_rep( 1, i, &colr ); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | int DefineGraph( char * label, float min, float max ) |
---|
| 72 | { |
---|
| 73 | graphName[ nGraphs ] = label; |
---|
| 74 | Ymin[ nGraphs ] = min; |
---|
| 75 | Ymax[ nGraphs ] = max; |
---|
| 76 | nGraphs++; |
---|
| 77 | return nGraphs; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | void SelectGraph( int i ) |
---|
| 81 | { |
---|
| 82 | CrtGraph = i; |
---|
| 83 | |
---|
| 84 | c_agsetf("GRID/BOTTOM.", Ybottom[i]); |
---|
| 85 | c_agsetf("GRID/TOP." , Ytop[i]); |
---|
| 86 | |
---|
| 87 | c_agsetf("Y/MINIMUM.", Ymin[i]); |
---|
| 88 | c_agsetf("Y/MAXIMUM.", Ymax[i]); |
---|
| 89 | /* |
---|
| 90 | c_agsetf("LEFT/MAJOR/BASE.", Ybase[i] ); |
---|
| 91 | */ |
---|
| 92 | if( i == 0 ) |
---|
| 93 | c_agsetf("BOTTOM/TYPE.", 3); |
---|
| 94 | else |
---|
| 95 | c_agsetf("BOTTOM/TYPE.", 0); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void InitGraph( int n, float Xmin, float Xmax, char *title ) |
---|
| 99 | { |
---|
| 100 | int i; |
---|
| 101 | float step; |
---|
| 102 | char buf[100]; |
---|
| 103 | |
---|
| 104 | nMax = n; |
---|
| 105 | n = n + 1; |
---|
| 106 | XminGraph = Xmin; |
---|
| 107 | XmaxGraph = Xmax; |
---|
| 108 | graphTitle = title; |
---|
| 109 | |
---|
| 110 | step = (Xmax - Xmin) / nMax; |
---|
| 111 | |
---|
| 112 | Xval = (float*)malloc( n * sizeof(float) ); |
---|
| 113 | for( i = 0; i < n; i++ ) |
---|
| 114 | Xval[i] = Xmin + step*i; |
---|
| 115 | |
---|
| 116 | Yval = (float*)malloc( nGraphs * n * sizeof(float) ); |
---|
| 117 | for( i = 0; i < nGraphs * n; i++ ) |
---|
| 118 | Yval[i] = NULL/1; |
---|
| 119 | |
---|
| 120 | c_agseti("WINDOWING.",1); |
---|
| 121 | c_agseti("FRAME.", 2 ); |
---|
| 122 | c_agseti("BACKGROUND.", 3 ); |
---|
| 123 | |
---|
| 124 | c_agsetf("GRID/LEFT." ,.15); |
---|
| 125 | c_agsetf("GRID/RIGHT." ,.90); |
---|
| 126 | |
---|
| 127 | for( i = 0; i < nGraphs; i++ ) { |
---|
| 128 | Ybottom[i] = .08 + 0.02 + i*0.84/nGraphs; |
---|
| 129 | Ytop[i] = .08 - 0.02 + (i+1)*0.84/nGraphs; |
---|
| 130 | } |
---|
| 131 | ch = (Ytop[0] - Ybottom[0]); |
---|
| 132 | ch = .02/ch; |
---|
| 133 | |
---|
| 134 | c_agsetf("X/MINIMUM.", Xmin); |
---|
| 135 | c_agsetf("X/MAXIMUM.", Xmax); |
---|
| 136 | |
---|
| 137 | c_agsetc("LABEL/NAME.","T"); |
---|
| 138 | c_agseti("LINE/NUMBER.",100); |
---|
| 139 | c_agsetf("LINE/CH.", 0.1 ); |
---|
| 140 | |
---|
| 141 | c_agsetc("LABEL/NAME.","B"); |
---|
| 142 | c_agseti("LINE/NUMBER.",-100); |
---|
| 143 | c_agsetc("LINE/TEXT.", " " ); |
---|
| 144 | |
---|
| 145 | c_agsetf("BOTTOM/MAJOR/OUTWARD.", .02 ); |
---|
| 146 | c_agsetf("BOTTOM/WIDTH/MA.", 0.20 ); |
---|
| 147 | c_agsetf("BOTTOM/WIDTH/EX.", 0.15 ); |
---|
| 148 | |
---|
| 149 | c_agsetc("LABEL/NAME.","L"); |
---|
| 150 | c_agseti("LINE/NUMBER.",100); |
---|
| 151 | c_agsetc("LINE/TEXT.", " " ); |
---|
| 152 | |
---|
| 153 | c_agseti("LEFT/MAJOR/TYPE.", 1 ); |
---|
| 154 | c_agsetf("LEFT/MAJOR/OUTWARD.", .02 ); |
---|
| 155 | c_agseti("LEFT/MINOR/SPACING.",4); |
---|
| 156 | c_agsetf("LEFT/WIDTH/MA.", .7*ch ); |
---|
| 157 | c_agsetf("LEFT/WIDTH/EX.", .5*ch ); |
---|
| 158 | |
---|
| 159 | c_agsetc("LABEL/NAME.", status ); |
---|
| 160 | c_agsetf("LABEL/BASEPOINT/X.", 0.5); |
---|
| 161 | c_agsetf("LABEL/BASEPOINT/Y.", 1+2*ch); |
---|
| 162 | c_agseti("LABEL/ANGLE.", 0); |
---|
| 163 | c_agseti("LINE/NUMBER.", 0); |
---|
| 164 | c_agsetc("LINE/TEXT.", startMsg ); |
---|
| 165 | c_agsetf("LINE/CH.", ch ); |
---|
| 166 | |
---|
| 167 | Boundary(); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | float Round( float x ) |
---|
| 171 | { |
---|
| 172 | float p; |
---|
| 173 | |
---|
| 174 | if( x == 0 ) return x; |
---|
| 175 | p = (float)pow( 10.0, -3.0 + (int)(.5+log10( (double)x ) ) ); |
---|
| 176 | return p * (int)(.5 + x/p); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | void UpdateGraph( float * val ) |
---|
| 181 | { |
---|
| 182 | int i, j, n; |
---|
| 183 | static int init = 1; |
---|
| 184 | Gint err, oldcolor; |
---|
| 185 | int start; |
---|
| 186 | float v; |
---|
| 187 | |
---|
| 188 | if( nCrt >= nMax ) return; |
---|
| 189 | n = nMax+1; |
---|
| 190 | |
---|
| 191 | for( i = 0; i < nGraphs; i++ ) |
---|
| 192 | Yval[i*n+nCrt] = val[i]; |
---|
| 193 | nCrt++; |
---|
| 194 | |
---|
| 195 | start = nGraphs-1; |
---|
| 196 | |
---|
| 197 | if( init ) { |
---|
| 198 | init = 0; |
---|
| 199 | ginq_text_colr_ind( &err, &oldcolor ); |
---|
| 200 | |
---|
| 201 | c_pcloqu( 0.9, 0.03 , "TIME [hours]", -0.9, 0, 0 ); |
---|
| 202 | c_pcloqu( 0.08,0.93, "CONC [ppb]", -0.8, 0, 0 ); |
---|
| 203 | |
---|
| 204 | for( i = 0; i < nGraphs; i++ ) { |
---|
| 205 | v = val[i] == 0 ? .001 : val[i]; |
---|
| 206 | Ymin[i] = Round( v * (1 - Ymin[i]) ); |
---|
| 207 | Ymax[i] = Round( v * (1 + Ymax[i]) ); |
---|
| 208 | /* |
---|
| 209 | Ybase[i] = Round((Ymax[i] - Ymin[i])/2); |
---|
| 210 | Ymin[i] = Ybase[i]*(int)(.5 + Ymin[i]/Ybase[i]); |
---|
| 211 | Ymax[i] = Ymin[i]+2*Ybase[i]; |
---|
| 212 | */ |
---|
| 213 | gset_text_colr_ind( i % MAX_COLORS + 2 ); |
---|
| 214 | c_pcloqu( .86, Ytop[i]-0.01, graphName[i], -1.2, 0, -1 ); |
---|
| 215 | } |
---|
| 216 | gupd_ws( WS_ID, GUPD_PEND ); |
---|
| 217 | |
---|
| 218 | gset_text_colr_ind( oldcolor ); |
---|
| 219 | |
---|
| 220 | SelectGraph(start); |
---|
| 221 | c_ezxy ( Xval, &Yval[start*n], nCrt, "" ); |
---|
| 222 | c_agsetc("LABEL/NAME.", status ); |
---|
| 223 | c_agsetf("LABEL/SU.", 1.); |
---|
| 224 | start--; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | for( i = start; i >=0; i-- ) { |
---|
| 228 | SelectGraph( i ); |
---|
| 229 | c_ezxy ( Xval, &Yval[i*n], nCrt, "" ); |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | void CloseWin() |
---|
| 234 | { |
---|
| 235 | c_agsetc("LABEL/NAME.", status ); |
---|
| 236 | c_agsetf("LABEL/SU.", 0. ); |
---|
| 237 | |
---|
| 238 | clean = 1; |
---|
| 239 | SelectGraph( nGraphs - 1 ); |
---|
| 240 | c_ezxy ( Xval, &Yval[(nGraphs - 1)*(nMax+1)], nCrt, "" ); |
---|
| 241 | clean = 0; |
---|
| 242 | |
---|
| 243 | c_agsetc("LABEL/NAME.", status ); |
---|
| 244 | c_agseti("LINE/NUMBER.", 0); |
---|
| 245 | c_agsetc("LINE/TEXT.", endMsg ); |
---|
| 246 | |
---|
| 247 | c_ezxy ( Xval, &Yval[(nGraphs - 1)*(nMax+1)], nCrt, "" ); |
---|
| 248 | |
---|
| 249 | getchar(); |
---|
| 250 | c_clsgks(); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | void Boundary() |
---|
| 254 | { |
---|
| 255 | c_plotif( 0, 0,0); |
---|
| 256 | c_plotif(32767, 0,1); |
---|
| 257 | c_plotif(32767,32767,1); |
---|
| 258 | c_plotif( 0,32767,1); |
---|
| 259 | c_plotif( 0, 0,1); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | void agchcu( int * iflag, int * n ) |
---|
| 264 | { |
---|
| 265 | c_plotif( 0., 0., 2 ); |
---|
| 266 | if( *iflag == 0 ) |
---|
| 267 | gset_line_colr_ind( CrtGraph % MAX_COLORS + 2 ); |
---|
| 268 | else |
---|
| 269 | gset_line_colr_ind( 1 ); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | int CmpLabelName( char * s1, char * s2 ) |
---|
| 273 | { |
---|
| 274 | while ( isspace( *s1 ) ) s1++; |
---|
| 275 | while( *s1 == *s2 ) { |
---|
| 276 | s1++; s2++; |
---|
| 277 | } |
---|
| 278 | if( *s2 == '\0' ) |
---|
| 279 | return 1; |
---|
| 280 | return 0; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | void agchil( int * iflag, char * lname, int * lnum ) |
---|
| 285 | { |
---|
| 286 | c_plotif( 0., 0., 2 ); |
---|
| 287 | switch( *iflag ) { |
---|
| 288 | case 0: |
---|
| 289 | if( CmpLabelName( lname, status ) ) |
---|
| 290 | gset_text_colr_ind( 1 - clean ); |
---|
| 291 | break; |
---|
| 292 | case 1: gset_text_colr_ind( 1 ); |
---|
| 293 | break; |
---|
| 294 | } |
---|
| 295 | } |
---|