4 #include <ncarg/ncargC.h>
12 Grgb colors
[] = {{ 0.0, 0.0, 0.0 },
29 char *graphName
[ MAX_GRAPHS
];
31 char * startMsg
= "Working... Press CTRL-C to stop";
32 char * endMsg
= "DONE ! Press <ENTER> when ready.";
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
];
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
;
80 void SelectGraph( int 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] );
93 c_agsetf("BOTTOM/TYPE.", 3);
95 c_agsetf("BOTTOM/TYPE.", 0);
98 void InitGraph( int n
, float Xmin
, float Xmax
, char *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
++ )
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]);
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
);
170 float Round( float x
)
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
)
188 if( nCrt
>= nMax
) return;
191 for( i
= 0; i
< nGraphs
; i
++ )
192 Yval
[i
*n
+nCrt
] = val
[i
];
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
);
221 c_ezxy ( Xval
, &Yval
[start
*n
], nCrt
, "" );
222 c_agsetc("LABEL/NAME.", status
);
223 c_agsetf("LABEL/SU.", 1.);
227 for( i
= start
; i
>=0; i
-- ) {
229 c_ezxy ( Xval
, &Yval
[i
*n
], nCrt
, "" );
235 c_agsetc("LABEL/NAME.", status
);
236 c_agsetf("LABEL/SU.", 0. );
239 SelectGraph( nGraphs
- 1 );
240 c_ezxy ( Xval
, &Yval
[(nGraphs
- 1)*(nMax
+1)], nCrt
, "" );
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
, "" );
256 c_plotif(32767, 0,1);
257 c_plotif(32767,32767,1);
258 c_plotif( 0,32767,1);
263 void agchcu( int * iflag
, int * n
)
265 c_plotif( 0., 0., 2 );
267 gset_line_colr_ind( CrtGraph
% MAX_COLORS
+ 2 );
269 gset_line_colr_ind( 1 );
272 int CmpLabelName( char * s1
, char * s2
)
274 while ( isspace( *s1
) ) s1
++;
275 while( *s1
== *s2
) {
284 void agchil( int * iflag
, char * lname
, int * lnum
)
286 c_plotif( 0., 0., 2 );
289 if( CmpLabelName( lname
, status
) )
290 gset_text_colr_ind( 1 - clean
);
292 case 1: gset_text_colr_ind( 1 );