Original WRF subgrid support version from John Michalakes without fire
[wrffire.git] / wrfv2_fire / chem / KPP / kpp / kpp-2.1 / util / ncar.c
blob78886fb1130d62056d8f7c72b3d0798f46dbf5b3
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"
8 #define MAX_COLORS 9
9 #define MAX_GRAPHS 8
10 #define WS_ID 1
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 }
24 int nGraphs = 0;
25 int nMax;
26 int nCrt;
27 int CrtGraph;
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";
35 float * Xval;
36 float * Yval;
37 float * scale;
38 float * offset;
39 float ch;
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 ];
48 int crtState;
49 int clean = 0;
51 void Boundary();
53 void OpenWin()
55 int i;
56 Gcolr_rep colr;
58 gopen_gks( "stdout", 0 );
59 gopen_ws( WS_ID, (char*)0, 8 );
60 gactivate_ws( WS_ID );
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 );
71 int DefineGraph( char * label, float min, float max )
73 graphName[ nGraphs ] = label;
74 Ymin[ nGraphs ] = min;
75 Ymax[ nGraphs ] = max;
76 nGraphs++;
77 return nGraphs;
80 void SelectGraph( int i )
82 CrtGraph = i;
84 c_agsetf("GRID/BOTTOM.", Ybottom[i]);
85 c_agsetf("GRID/TOP." , Ytop[i]);
87 c_agsetf("Y/MINIMUM.", Ymin[i]);
88 c_agsetf("Y/MAXIMUM.", Ymax[i]);
90 c_agsetf("LEFT/MAJOR/BASE.", Ybase[i] );
92 if( i == 0 )
93 c_agsetf("BOTTOM/TYPE.", 3);
94 else
95 c_agsetf("BOTTOM/TYPE.", 0);
98 void InitGraph( int n, float Xmin, float Xmax, char *title )
100 int i;
101 float step;
102 char buf[100];
104 nMax = n;
105 n = n + 1;
106 XminGraph = Xmin;
107 XmaxGraph = Xmax;
108 graphTitle = title;
110 step = (Xmax - Xmin) / nMax;
112 Xval = (float*)malloc( n * sizeof(float) );
113 for( i = 0; i < n; i++ )
114 Xval[i] = Xmin + step*i;
116 Yval = (float*)malloc( nGraphs * n * sizeof(float) );
117 for( i = 0; i < nGraphs * n; i++ )
118 Yval[i] = NULL/1;
120 c_agseti("WINDOWING.",1);
121 c_agseti("FRAME.", 2 );
122 c_agseti("BACKGROUND.", 3 );
124 c_agsetf("GRID/LEFT." ,.15);
125 c_agsetf("GRID/RIGHT." ,.90);
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;
131 ch = (Ytop[0] - Ybottom[0]);
132 ch = .02/ch;
134 c_agsetf("X/MINIMUM.", Xmin);
135 c_agsetf("X/MAXIMUM.", Xmax);
137 c_agsetc("LABEL/NAME.","T");
138 c_agseti("LINE/NUMBER.",100);
139 c_agsetf("LINE/CH.", 0.1 );
141 c_agsetc("LABEL/NAME.","B");
142 c_agseti("LINE/NUMBER.",-100);
143 c_agsetc("LINE/TEXT.", " " );
145 c_agsetf("BOTTOM/MAJOR/OUTWARD.", .02 );
146 c_agsetf("BOTTOM/WIDTH/MA.", 0.20 );
147 c_agsetf("BOTTOM/WIDTH/EX.", 0.15 );
149 c_agsetc("LABEL/NAME.","L");
150 c_agseti("LINE/NUMBER.",100);
151 c_agsetc("LINE/TEXT.", " " );
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 );
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 );
167 Boundary();
170 float Round( float x )
172 float p;
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);
180 void UpdateGraph( float * val )
182 int i, j, n;
183 static int init = 1;
184 Gint err, oldcolor;
185 int start;
186 float v;
188 if( nCrt >= nMax ) return;
189 n = nMax+1;
191 for( i = 0; i < nGraphs; i++ )
192 Yval[i*n+nCrt] = val[i];
193 nCrt++;
195 start = nGraphs-1;
197 if( init ) {
198 init = 0;
199 ginq_text_colr_ind( &err, &oldcolor );
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 );
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]) );
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];
213 gset_text_colr_ind( i % MAX_COLORS + 2 );
214 c_pcloqu( .86, Ytop[i]-0.01, graphName[i], -1.2, 0, -1 );
216 gupd_ws( WS_ID, GUPD_PEND );
218 gset_text_colr_ind( oldcolor );
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--;
227 for( i = start; i >=0; i-- ) {
228 SelectGraph( i );
229 c_ezxy ( Xval, &Yval[i*n], nCrt, "" );
233 void CloseWin()
235 c_agsetc("LABEL/NAME.", status );
236 c_agsetf("LABEL/SU.", 0. );
238 clean = 1;
239 SelectGraph( nGraphs - 1 );
240 c_ezxy ( Xval, &Yval[(nGraphs - 1)*(nMax+1)], nCrt, "" );
241 clean = 0;
243 c_agsetc("LABEL/NAME.", status );
244 c_agseti("LINE/NUMBER.", 0);
245 c_agsetc("LINE/TEXT.", endMsg );
247 c_ezxy ( Xval, &Yval[(nGraphs - 1)*(nMax+1)], nCrt, "" );
249 getchar();
250 c_clsgks();
253 void Boundary()
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);
263 void agchcu( int * iflag, int * n )
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 );
272 int CmpLabelName( char * s1, char * s2 )
274 while ( isspace( *s1 ) ) s1++;
275 while( *s1 == *s2 ) {
276 s1++; s2++;
278 if( *s2 == '\0' )
279 return 1;
280 return 0;
284 void agchil( int * iflag, char * lname, int * lnum )
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;