1 | |
---|
2 | /* file gmtch.c |
---|
3 | * ======= |
---|
4 | * |
---|
5 | * version 1, 7-Jul-2007 |
---|
6 | * |
---|
7 | * GMT channel for graphics output module |
---|
8 | * K. Stammler, 7-Jul-2007 |
---|
9 | */ |
---|
10 | |
---|
11 | |
---|
12 | #include <stdio.h> |
---|
13 | #include <string.h> |
---|
14 | #include BASECNST |
---|
15 | #include BC_SYSBASE |
---|
16 | #include "graphbas.h" |
---|
17 | #include "gmtusrdef.h" |
---|
18 | #include "gmterrors.h" |
---|
19 | |
---|
20 | /* global constants */ |
---|
21 | #define GMTC_MAXSTYLE 10 |
---|
22 | /* maximum number of different line styles */ |
---|
23 | #define DEFAULTWIDTH 100.0 |
---|
24 | /* default width of user coo */ |
---|
25 | #define DEFAULTHEIGHT 100.0 |
---|
26 | /* default height of user coo */ |
---|
27 | #define DEFAULTPLOTW 25.9 |
---|
28 | #define DEFAULTPLOTH 19.5 |
---|
29 | /* default plot size */ |
---|
30 | #define MAXDEFSTYLE 6 |
---|
31 | /* number of default styles */ |
---|
32 | |
---|
33 | #define GMTFILENAME "GMT_TMP" |
---|
34 | /* PostScript file */ |
---|
35 | |
---|
36 | |
---|
37 | /* global variable */ |
---|
38 | static char gmtv_outputdir[BC_FILELTH+1]; /* output directory */ |
---|
39 | static char gmtv_inputdir[BC_FILELTH+1]; /* input directory */ |
---|
40 | |
---|
41 | |
---|
42 | /* global variables */ |
---|
43 | static BOOLEAN gmtv_isinit; /* GMT is initialised */ |
---|
44 | static GMTOUT gmtv_width; /* width of display */ |
---|
45 | static GMTOUT gmtv_height; /* heigth of display */ |
---|
46 | static GMTOUT gmtv_xoffset; /* x-offset */ |
---|
47 | static GMTOUT gmtv_yoffset; /* y-offset */ |
---|
48 | static float gmtv_trafo_xf; /* trafo x-factor */ |
---|
49 | static float gmtv_trafo_yf; /* trafo y-factor */ |
---|
50 | static GMTOUT gmtv_trafo_xo; /* x-offset */ |
---|
51 | static GMTOUT gmtv_trafo_yo; /* y-offset */ |
---|
52 | static BOOLEAN gmtv_arrayswap=FALSE; /* swap arrayplot coo's */ |
---|
53 | static int gmtv_currstyle; /* currently used style */ |
---|
54 | static float gmtv_csize[GMTC_MAXSTYLE]; /* character sizes (units of height) */ |
---|
55 | static float gmtv_lwidth[GMTC_MAXSTYLE]; /* line widths */ |
---|
56 | static FILE *gmtv_pf; /* pointer to PostScript file */ |
---|
57 | static BOOLEAN gmtv_move=FALSE;/* moveto buffer is not empty */ |
---|
58 | static GBC_COO gmtv_move_x; /* moveto x-coo */ |
---|
59 | static GBC_COO gmtv_move_y; /* moveto y-coo */ |
---|
60 | |
---|
61 | static char gmtv_currfile[BC_FILELTH+1]; /* name of active GMT file */ |
---|
62 | |
---|
63 | /* prototypes of local routines */ |
---|
64 | void gmth_trafo( GBC_COO ux, GBC_COO uy, GMTOUT *dx, GMTOUT *dy ); |
---|
65 | void gmth_create_hcname( char name[] ); |
---|
66 | void gmth_insertheader( FILE *gmt ); |
---|
67 | void gmth_closefile( FILE *gmt ); |
---|
68 | void gmth_changestyle( int style ); |
---|
69 | |
---|
70 | /*----------------------------------------------------------------------------*/ |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | void gmt_init( int attribs, GMTOUT xlo, GMTOUT ylo, GMTOUT width, GMTOUT height, |
---|
75 | STATUS *status ) |
---|
76 | |
---|
77 | /* initialises PostScript channel |
---|
78 | * |
---|
79 | * parameters of routine |
---|
80 | * int attribs; input; attributes |
---|
81 | * GMTOUT xlo, ylo; input; offset of output |
---|
82 | * GMTOUT width, height; input; size of output |
---|
83 | * STATUS *status; output; return status |
---|
84 | */ |
---|
85 | { |
---|
86 | /* local variables */ |
---|
87 | int i; /* counter */ |
---|
88 | FILE *fp; /* file pointer */ |
---|
89 | |
---|
90 | /* executable code */ |
---|
91 | |
---|
92 | printf ("--> in gmt_init\n" ); |
---|
93 | |
---|
94 | if (attribs == 0) { |
---|
95 | ; /* just to access attrib once */ |
---|
96 | } /*endif*/ |
---|
97 | |
---|
98 | if (*gmtv_currfile == '\0') { |
---|
99 | if (strlen(gmtv_currfile)+strlen(GMTFILENAME)+8 > BC_FILELTH) { |
---|
100 | *status = GMTE_STROVFL; |
---|
101 | return; |
---|
102 | } /*endif*/ |
---|
103 | /* search for existing files */ |
---|
104 | i = 0; |
---|
105 | FOREVER { |
---|
106 | sprintf( gmtv_currfile, "%s%s%05d.ps", gmtv_outputdir, GMTFILENAME, i ); |
---|
107 | fp = fopen( gmtv_currfile, "r" ); |
---|
108 | if (fp == NULL) break; |
---|
109 | fclose( fp ); |
---|
110 | i++; |
---|
111 | } /*endfor*/ |
---|
112 | } /*endif*/ |
---|
113 | |
---|
114 | if ((width <= 0.0) || (height <= 0.0)) { |
---|
115 | *status = GMTE_ILPAR; |
---|
116 | return; |
---|
117 | } /*endif*/ |
---|
118 | |
---|
119 | if (gmtv_isinit) gmt_exit(); |
---|
120 | |
---|
121 | gmtv_xoffset = xlo; |
---|
122 | gmtv_yoffset = ylo; |
---|
123 | gmtv_width = width; |
---|
124 | gmtv_height = height; |
---|
125 | |
---|
126 | gmtv_currstyle = 0; |
---|
127 | for (i=0; i<GMTC_MAXSTYLE; i++) |
---|
128 | if (gmtv_csize[i] == 0.0) |
---|
129 | gmtv_csize[i] = 40.0; |
---|
130 | for (i=0; i<GMTC_MAXSTYLE; i++) |
---|
131 | if (gmtv_lwidth[i] == 0.0) |
---|
132 | gmtv_lwidth[i] = 0.4; |
---|
133 | |
---|
134 | /* open GMT file */ |
---|
135 | gmtv_pf = sy_fopen( gmtv_currfile, "w" ); |
---|
136 | if (gmtv_pf == NULL) { |
---|
137 | *status = GMTE_FOPNWR; |
---|
138 | return; |
---|
139 | } /*endif*/ |
---|
140 | gmtv_isinit = TRUE; |
---|
141 | gmtv_move = FALSE; |
---|
142 | |
---|
143 | gmth_insertheader( gmtv_pf ); |
---|
144 | gmt_setcoo( 0., 0., DEFAULTWIDTH, DEFAULTHEIGHT, status ); |
---|
145 | |
---|
146 | } /* end of gmt_init */ |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | /*----------------------------------------------------------------------------*/ |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | void gmt_exit( void ) |
---|
155 | |
---|
156 | /* exits GMT channel |
---|
157 | * |
---|
158 | * no parameters |
---|
159 | */ |
---|
160 | { |
---|
161 | /* executable code */ |
---|
162 | |
---|
163 | printf ("--> in gmt_exit\n" ); |
---|
164 | if (!gmtv_isinit) return; |
---|
165 | fclose( gmtv_pf ); |
---|
166 | sy_fdelete( gmtv_currfile ); |
---|
167 | gmtv_isinit = FALSE; |
---|
168 | |
---|
169 | } /* end of ps_exit */ |
---|
170 | |
---|
171 | |
---|
172 | |
---|
173 | /*----------------------------------------------------------------------------*/ |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | void gmt_resize( GMTOUT xlo, GMTOUT ylo, GMTOUT width, GMTOUT height, |
---|
178 | STATUS *status ) |
---|
179 | |
---|
180 | /* resizes output of GMT |
---|
181 | * |
---|
182 | * parameters of routine |
---|
183 | * GMTOUT xlo, ylo; input; offset of output |
---|
184 | * GMTOUT width, height; input; size of output |
---|
185 | * STATUS *status; output; return status |
---|
186 | */ |
---|
187 | { |
---|
188 | /* executable code */ |
---|
189 | |
---|
190 | if ((width <= 0.0) || (height <= 0.0)) { |
---|
191 | *status = GMTE_ILPAR; |
---|
192 | return; |
---|
193 | } /*endif*/ |
---|
194 | |
---|
195 | if (!gmtv_isinit) gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, status); |
---|
196 | |
---|
197 | gmtv_xoffset = xlo; |
---|
198 | gmtv_yoffset = ylo; |
---|
199 | gmtv_width = width; |
---|
200 | gmtv_height = height; |
---|
201 | |
---|
202 | } /* end of gmt_resize */ |
---|
203 | |
---|
204 | |
---|
205 | |
---|
206 | /*----------------------------------------------------------------------------*/ |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | void gmt_erase( void ) |
---|
211 | |
---|
212 | /* clears GMT output channel |
---|
213 | * |
---|
214 | * no parameters |
---|
215 | */ |
---|
216 | { |
---|
217 | /* local variables */ |
---|
218 | int dmy=0; |
---|
219 | |
---|
220 | /* executable code */ |
---|
221 | |
---|
222 | printf ("--> in gmt_erase\n" ); |
---|
223 | if (gmtv_isinit) { |
---|
224 | fseek( gmtv_pf, 0L, 0 ); |
---|
225 | gmth_insertheader( gmtv_pf ); |
---|
226 | gmtv_currstyle = 0; |
---|
227 | } else { |
---|
228 | gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, &dmy ); |
---|
229 | } /*endif*/ |
---|
230 | gmtv_move = FALSE; |
---|
231 | |
---|
232 | } /* end of gmt_erase */ |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | /*----------------------------------------------------------------------------*/ |
---|
237 | |
---|
238 | |
---|
239 | |
---|
240 | void gmt_setcoo( GBC_COO x, GBC_COO y, GBC_COO w, GBC_COO h, STATUS *status ) |
---|
241 | |
---|
242 | /* sets user coordinates |
---|
243 | * |
---|
244 | * parameters of routine |
---|
245 | * GBC_COO x, y; input; offset |
---|
246 | * GBC_COO w, h; input; size |
---|
247 | * STATUS *status; output; return status |
---|
248 | */ |
---|
249 | { |
---|
250 | /* executable code */ |
---|
251 | |
---|
252 | if ((w <= 0.0) || (h <= 0.0)) { |
---|
253 | *status = GMTE_ILPAR; |
---|
254 | return; |
---|
255 | } /*endif*/ |
---|
256 | |
---|
257 | if (!gmtv_isinit) gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, status); |
---|
258 | |
---|
259 | gmtv_trafo_xf = gmtv_width / w; |
---|
260 | gmtv_trafo_yf = gmtv_height / h; |
---|
261 | gmtv_trafo_xo = gmtv_xoffset - x*gmtv_trafo_xf; |
---|
262 | gmtv_trafo_yo = gmtv_yoffset - y*gmtv_trafo_yf; |
---|
263 | |
---|
264 | } /* end of gmt_setcoo */ |
---|
265 | |
---|
266 | |
---|
267 | |
---|
268 | /*----------------------------------------------------------------------------*/ |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | void gmt_moveto( GBC_COO x, GBC_COO y ) |
---|
273 | |
---|
274 | /* moves to position (x,y) in user coordinates, disabled |
---|
275 | * |
---|
276 | * parameters of routine |
---|
277 | * GBC_COO x, y; input; position |
---|
278 | */ |
---|
279 | { |
---|
280 | /* local variables */ |
---|
281 | STATUS dmy=0; /* scratch */ |
---|
282 | |
---|
283 | /* executable code */ |
---|
284 | |
---|
285 | #ifdef XXX |
---|
286 | if (!gmtv_isinit) gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, &dmy ); |
---|
287 | |
---|
288 | gmtv_move_x = x; |
---|
289 | gmtv_move_y = y; |
---|
290 | gmtv_move = TRUE; |
---|
291 | #endif |
---|
292 | |
---|
293 | } /* end of gmt_moveto */ |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | /*----------------------------------------------------------------------------*/ |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | void gmt_drawto( int style, GBC_COO x, GBC_COO y ) |
---|
302 | |
---|
303 | /* draws to position (x,y) in user coordinates, disabled |
---|
304 | * |
---|
305 | * parameters of routine |
---|
306 | * int style; input; style parameter |
---|
307 | * GBC_COO x, y; input; position |
---|
308 | */ |
---|
309 | { |
---|
310 | /* local variables */ |
---|
311 | static int linecnt=0; /* counter of lineto commands */ |
---|
312 | GMTOUT dx, dy; /* device coordinates */ |
---|
313 | STATUS dmy=0; /* scratch */ |
---|
314 | |
---|
315 | /* executable code */ |
---|
316 | |
---|
317 | #ifdef XXX |
---|
318 | if (!gmtv_isinit) gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, &dmy ); |
---|
319 | |
---|
320 | if ((style < 0) || (style >= GMTC_MAXSTYLE)) style = 0; |
---|
321 | if (style != gmtv_currstyle) |
---|
322 | gmth_changestyle( style ); |
---|
323 | |
---|
324 | if (gmtv_move) { |
---|
325 | gmth_trafo( gmtv_move_x, gmtv_move_y, &dx, &dy ); |
---|
326 | fprintf( gmtv_pf, "%d %d M\n", Nint(dx), Nint(dy) ); |
---|
327 | gmtv_move = FALSE; |
---|
328 | linecnt = 0; |
---|
329 | } /*endif*/ |
---|
330 | |
---|
331 | gmth_trafo( x, y, &dx, &dy ); |
---|
332 | fprintf( gmtv_pf, "%d %d L\n", Nint(dx), Nint(dy) ); |
---|
333 | #endif |
---|
334 | |
---|
335 | } /* end of gmt_drawto */ |
---|
336 | |
---|
337 | |
---|
338 | /*----------------------------------------------------------------------------*/ |
---|
339 | |
---|
340 | |
---|
341 | |
---|
342 | void gmt_arrayplot( int style, long cnt, int red, GBC_COO xoff, |
---|
343 | GBC_COO xinc, GBC_COO yoff, GBC_COO yarr[], float yzoom, STATUS *status ) |
---|
344 | |
---|
345 | /* plots array of data points |
---|
346 | * |
---|
347 | * parameters of routine |
---|
348 | * int style; input; style parameter |
---|
349 | * long cnt; input; number of data samples in yarr |
---|
350 | * int red; input; reduction factor |
---|
351 | * GBC_COO xoff; input; x offset |
---|
352 | * GBC_COO xinc; input; x increment |
---|
353 | * GBC_COO yoff; input; y offset |
---|
354 | * GBC_COO yarr[]; input; data array |
---|
355 | * float yzoom; input; amplitude zoom factor |
---|
356 | * STATUS *status; output; return status |
---|
357 | */ |
---|
358 | { |
---|
359 | /* local variables */ |
---|
360 | long i; /* sample counter */ |
---|
361 | GBC_COO cx, cy; /* current user coordinates */ |
---|
362 | GMTOUT dx, dy; /* current GMT coordinates */ |
---|
363 | long lcnt; /* lineto counter */ |
---|
364 | |
---|
365 | /* executable code */ |
---|
366 | |
---|
367 | printf ("--> in gmt_arrayplot\n" ); |
---|
368 | if (!gmtv_isinit) gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, status); |
---|
369 | |
---|
370 | if (style != gmtv_currstyle) |
---|
371 | gmth_changestyle( style ); |
---|
372 | |
---|
373 | fprintf( gmtv_pf, "newpath\n" ); |
---|
374 | |
---|
375 | lcnt = 0; |
---|
376 | if (gmtv_arrayswap) { |
---|
377 | cx = yoff + (*yarr)*yzoom; |
---|
378 | cy = xoff; |
---|
379 | gmth_trafo( cx, cy, &dx, &dy ); |
---|
380 | fprintf( gmtv_pf, "%d %d M\n", Nint(dx), Nint(dy) ); |
---|
381 | for (i=red; i<cnt; i += red) { |
---|
382 | cx = yoff + yarr[i]*yzoom; |
---|
383 | cy = xoff + xinc*(float)i; |
---|
384 | gmth_trafo( cx, cy, &dx, &dy ); |
---|
385 | fprintf( gmtv_pf, "%d %d L\n", Nint(dx), Nint(dy) ); |
---|
386 | } /*endfor*/ |
---|
387 | } else { |
---|
388 | cx = xoff; |
---|
389 | cy = yoff + (*yarr)*yzoom; |
---|
390 | gmth_trafo( cx, cy, &dx, &dy ); |
---|
391 | fprintf( gmtv_pf, "%d %d M\n", Nint(dx), Nint(dy) ); |
---|
392 | for (i=red; i<cnt; i += red) { |
---|
393 | cx = xoff + xinc*(float)i; |
---|
394 | cy = yoff + yarr[i]*yzoom; |
---|
395 | gmth_trafo( cx, cy, &dx, &dy ); |
---|
396 | fprintf( gmtv_pf, "%d %d L\n", Nint(dx), Nint(dy) ); |
---|
397 | } /*endfor*/ |
---|
398 | } /*endif*/ |
---|
399 | |
---|
400 | fprintf( gmtv_pf, "stroke\n" ); |
---|
401 | |
---|
402 | gmtv_move = FALSE; |
---|
403 | |
---|
404 | } /* end of gmt_arrayplot */ |
---|
405 | |
---|
406 | |
---|
407 | |
---|
408 | /*----------------------------------------------------------------------------*/ |
---|
409 | |
---|
410 | |
---|
411 | |
---|
412 | void gmt_text( int style, GBC_COO x, GBC_COO y, char text[] ) |
---|
413 | |
---|
414 | /* prints text at position (x,y), disabled |
---|
415 | * |
---|
416 | * parameters of routine |
---|
417 | * int style; input; style parameter (size) |
---|
418 | * GBC_COO x, y; input; text position (user coordinates) |
---|
419 | * char text[]; input; text to be printed |
---|
420 | */ |
---|
421 | { |
---|
422 | /* local variables */ |
---|
423 | GMTOUT dx, dy; /* device coordinates */ |
---|
424 | /* int slen; */ /* length of string */ |
---|
425 | /* float size; */ /* size of output */ |
---|
426 | STATUS dmy; /* scratch */ |
---|
427 | |
---|
428 | /* executable code */ |
---|
429 | |
---|
430 | #ifdef XXX |
---|
431 | if (!gmtv_isinit) gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, &dmy ); |
---|
432 | |
---|
433 | if (style < 0) style = 0; |
---|
434 | if (style >= GMTC_MAXSTYLE) style = GMTC_MAXSTYLE-1; |
---|
435 | gmth_trafo( x, y, &dx, &dy ); |
---|
436 | /* slen = (int)strlen( text ); */ |
---|
437 | /* size = psv_csize[style] * psv_height; */ |
---|
438 | if (style != psv_currstyle) |
---|
439 | gmth_changestyle( style ); |
---|
440 | fprintf( gmtv_pf, "%d %d M\n(%s)\ndrawstr\n", Nint(dx), Nint(dy), text ); |
---|
441 | #endif |
---|
442 | |
---|
443 | } /* end of gmt_text */ |
---|
444 | |
---|
445 | |
---|
446 | |
---|
447 | /*----------------------------------------------------------------------------*/ |
---|
448 | |
---|
449 | |
---|
450 | |
---|
451 | void gmt_setstyle( int style, char item[], char value[], STATUS *status ) |
---|
452 | |
---|
453 | /* sets style parameter number "style" |
---|
454 | * |
---|
455 | * parameters of routine |
---|
456 | * int style; input; number of style |
---|
457 | * char item[]; input; name of style attribute |
---|
458 | * char value[]; input; new value of style attribute (as string expr.) |
---|
459 | * STATUS *status; output; return status |
---|
460 | */ |
---|
461 | { |
---|
462 | /* local variables */ |
---|
463 | float num; /* scratch */ |
---|
464 | float r, g, b; /* colours */ |
---|
465 | |
---|
466 | /* executable code */ |
---|
467 | |
---|
468 | if ((style < 0) || (style >= GMTC_MAXSTYLE)) { |
---|
469 | *status = GMTE_ILSTYLE; |
---|
470 | return; |
---|
471 | } /*endif*/ |
---|
472 | |
---|
473 | /* if (!psv_isinit) ps_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, status); */ |
---|
474 | |
---|
475 | if (strcmp(item,"CHARSIZE") == 0 || strcmp(item,"CHARHEIGHT") == 0) { |
---|
476 | if (sscanf(value,"%f",&num) != 1) { |
---|
477 | *status = GMTE_ILVALUE; |
---|
478 | return; |
---|
479 | } /*endif*/ |
---|
480 | gmtv_csize[style] = num*3000.0; |
---|
481 | } else if (strcmp(item,"WRMODE") == 0) { |
---|
482 | } else if (strcmp(item,"LINESTYLE") == 0) { |
---|
483 | /* not yet implemented */ |
---|
484 | } else if (strcmp(item,"COLOR") == 0) { |
---|
485 | if (sscanf(value,"%f,%f,%f",&r,&g,&b) != 3) { |
---|
486 | *status = GMTE_ILVALUE; |
---|
487 | return; |
---|
488 | } /*endif*/ |
---|
489 | /* not yet implemented */ |
---|
490 | } else if (strcmp(item,"CHARROT") == 0) { |
---|
491 | } else if (strcmp(item,"FONT") == 0) { |
---|
492 | } else if (strcmp(item,"LINEWIDTH") == 0) { |
---|
493 | if (sscanf(value,"%f",&num) != 1) { |
---|
494 | *status = GMTE_ILVALUE; |
---|
495 | return; |
---|
496 | } /*endif*/ |
---|
497 | gmtv_lwidth[style] = num*1.8; |
---|
498 | } else if (strcmp(item,"LINEPATTERN") == 0) { |
---|
499 | } else if (strcmp(item,"CHARSIZE_ATARI") == 0) { |
---|
500 | } else if (strcmp(item,"TEXTEFFECTS") == 0) { |
---|
501 | } else { |
---|
502 | *status = GMTE_UKITEM; |
---|
503 | return; |
---|
504 | } /*endif*/ |
---|
505 | |
---|
506 | } /* end of gmt_setstyle */ |
---|
507 | |
---|
508 | |
---|
509 | |
---|
510 | /*----------------------------------------------------------------------------*/ |
---|
511 | |
---|
512 | |
---|
513 | |
---|
514 | void gmt_set_outputdir( char dir[], STATUS *status ) |
---|
515 | |
---|
516 | /* sets scratch directory |
---|
517 | * |
---|
518 | * parameters of routine |
---|
519 | * char dir[]; input; new directory name of scratch path |
---|
520 | * STATUS *status; output; return status |
---|
521 | */ |
---|
522 | { |
---|
523 | /* executable code */ |
---|
524 | |
---|
525 | if (strlen(dir) > BC_FILELTH) { |
---|
526 | *status = GMTE_STROVFL; |
---|
527 | return; |
---|
528 | } /*endif*/ |
---|
529 | strcpy( gmtv_outputdir, dir ); |
---|
530 | |
---|
531 | } /* end of gmt_set_outputdir */ |
---|
532 | |
---|
533 | |
---|
534 | |
---|
535 | /*----------------------------------------------------------------------------*/ |
---|
536 | |
---|
537 | |
---|
538 | |
---|
539 | void gmt_set_inputdir( char dir[], STATUS *status ) |
---|
540 | |
---|
541 | /* sets scratch directory |
---|
542 | * |
---|
543 | * parameters of routine |
---|
544 | * char dir[]; input; new directory name |
---|
545 | * STATUS *status; output; return status |
---|
546 | */ |
---|
547 | { |
---|
548 | /* executable code */ |
---|
549 | |
---|
550 | if (strlen(dir) > BC_FILELTH) { |
---|
551 | *status = GMTE_STROVFL; |
---|
552 | return; |
---|
553 | } /*endif*/ |
---|
554 | strcpy( gmtv_inputdir, dir ); |
---|
555 | |
---|
556 | } /* end of gmt_set_inputdir */ |
---|
557 | |
---|
558 | |
---|
559 | |
---|
560 | /*----------------------------------------------------------------------------*/ |
---|
561 | |
---|
562 | |
---|
563 | |
---|
564 | void gmt_prepare( STATUS *status ) |
---|
565 | |
---|
566 | /* prepares hardcopy |
---|
567 | * |
---|
568 | * parameters of routine |
---|
569 | * STATUS *status; output; return status |
---|
570 | */ |
---|
571 | { |
---|
572 | /* local variables */ |
---|
573 | |
---|
574 | /* executable code */ |
---|
575 | |
---|
576 | printf ("--> in gmt_prepare\n" ); |
---|
577 | gmt_erase(); |
---|
578 | if (Severe(status)) return; /* just to use status */ |
---|
579 | |
---|
580 | } /* end of gmt_prepare */ |
---|
581 | |
---|
582 | |
---|
583 | |
---|
584 | /*----------------------------------------------------------------------------*/ |
---|
585 | |
---|
586 | |
---|
587 | |
---|
588 | void gmt_cleanup( char outf[], STATUS *status ) |
---|
589 | |
---|
590 | /* finishes GMT output |
---|
591 | * |
---|
592 | * parameters of routine |
---|
593 | * char outf[]; output; output filename |
---|
594 | * STATUS *status; output; return status |
---|
595 | */ |
---|
596 | { |
---|
597 | /* local variables */ |
---|
598 | char hcname[BC_LINELTH+1]; /* name of hardcopy file */ |
---|
599 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
600 | /* char cmd[BC_LINELTH+1]; */ /* command string */ |
---|
601 | |
---|
602 | /* executable code */ |
---|
603 | |
---|
604 | printf ("--> in gmt_cleanup\n" ); |
---|
605 | if (!gmtv_isinit) gmt_init( 0, 0.0, 0.0, DEFAULTPLOTW, DEFAULTPLOTH, status); |
---|
606 | |
---|
607 | /* close PostScript file */ |
---|
608 | gmth_closefile( gmtv_pf ); |
---|
609 | |
---|
610 | /* create hardcopy name */ |
---|
611 | gmth_create_hcname( hcname ); |
---|
612 | |
---|
613 | strcpy( str, gmtv_outputdir ); |
---|
614 | strcat( str, hcname ); |
---|
615 | sy_fdelete( str ); |
---|
616 | sy_frename( gmtv_currfile, str ); |
---|
617 | if (outf != NULL) strcpy( outf, str ); |
---|
618 | |
---|
619 | /* open GMT file */ |
---|
620 | gmtv_pf = sy_fopen( gmtv_currfile, "w" ); |
---|
621 | if (gmtv_pf == NULL) { |
---|
622 | *status = GMTE_FOPNWR; |
---|
623 | return; |
---|
624 | } /*endif*/ |
---|
625 | gmth_insertheader( gmtv_pf ); |
---|
626 | gmtv_currstyle = 0; /* reset style block number */ |
---|
627 | |
---|
628 | } /* end of gmt_cleanup */ |
---|
629 | |
---|
630 | |
---|
631 | |
---|
632 | /*----------------------------------------------------------------------------*/ |
---|
633 | |
---|
634 | |
---|
635 | |
---|
636 | void gmt_setpar( char item[], char value[], STATUS *status ) |
---|
637 | |
---|
638 | /* sets hardcopy parameters |
---|
639 | * |
---|
640 | * parameters of routine |
---|
641 | * char item[]; input; item to be set |
---|
642 | * char value[]; input; new value of item |
---|
643 | * STATUS *status; output; return status |
---|
644 | */ |
---|
645 | { |
---|
646 | /* executable code */ |
---|
647 | |
---|
648 | #ifdef XXX |
---|
649 | if (strlen(value) > BC_LINELTH) { |
---|
650 | *status = GMTE_STROVFL; |
---|
651 | return; |
---|
652 | } /*endif*/ |
---|
653 | |
---|
654 | if (strcmp(item,"PRINT_CMD") == 0) { |
---|
655 | /* strcpy( psv_printfmt, value ) */; |
---|
656 | } else if (strcmp(item,"PSHEADER") == 0) { |
---|
657 | if (strlen(value) < BC_FILELTH) |
---|
658 | strcpy( psv_headerfile, value ); |
---|
659 | } else { |
---|
660 | *status = PSE_UKHCITEM; |
---|
661 | return; |
---|
662 | } /*endif*/ |
---|
663 | #endif |
---|
664 | |
---|
665 | } /* end of gmt_setpar */ |
---|
666 | |
---|
667 | |
---|
668 | |
---|
669 | /*----------------------------------------------------------------------------*/ |
---|
670 | |
---|
671 | |
---|
672 | |
---|
673 | void gmt_arrayswap( BOOLEAN on_off ) |
---|
674 | |
---|
675 | /* switches array-swap on ot off |
---|
676 | * |
---|
677 | * parameter of routine |
---|
678 | * BOOLEAN on_off; TRUE=on, FALSE=off |
---|
679 | */ |
---|
680 | { |
---|
681 | /* executable code */ |
---|
682 | |
---|
683 | gmtv_arrayswap = on_off; |
---|
684 | |
---|
685 | } /* end of gmt_arrayswap */ |
---|
686 | |
---|
687 | |
---|
688 | |
---|
689 | /*----------------------------------------------------------------------------*/ |
---|
690 | /* local routines */ |
---|
691 | /*----------------------------------------------------------------------------*/ |
---|
692 | |
---|
693 | |
---|
694 | |
---|
695 | void gmth_trafo( GBC_COO ux, GBC_COO uy, GMTOUT *dx, GMTOUT *dy ) |
---|
696 | |
---|
697 | /* transforms user coordinates (ux,uy) to device coordinates (dx,dy) |
---|
698 | * |
---|
699 | * parameters of routine |
---|
700 | * GBC_COO ux, uy; input; user coordinates |
---|
701 | * GMTOUT dx, dy; output; device coordinates |
---|
702 | */ |
---|
703 | { |
---|
704 | /* executable code */ |
---|
705 | |
---|
706 | *dx = ux * gmtv_trafo_xf + gmtv_trafo_xo; |
---|
707 | *dy = uy * gmtv_trafo_yf + gmtv_trafo_yo; |
---|
708 | |
---|
709 | } /* end of gmth_trafo */ |
---|
710 | |
---|
711 | |
---|
712 | |
---|
713 | /*----------------------------------------------------------------------------*/ |
---|
714 | |
---|
715 | |
---|
716 | |
---|
717 | void gmth_create_hcname( char name[] ) |
---|
718 | |
---|
719 | /* creates hardcopy filename |
---|
720 | * |
---|
721 | * parameters of routine |
---|
722 | * char name[]; output; filename created |
---|
723 | */ |
---|
724 | { |
---|
725 | /* local variables */ |
---|
726 | static int hc_count=0; /* hardcopy counter */ |
---|
727 | |
---|
728 | /* executable code */ |
---|
729 | |
---|
730 | strcpy( name, "HC" ); |
---|
731 | sprintf( name+2, "%03d", ++hc_count ); |
---|
732 | strcat( name, ".gmt" ); |
---|
733 | |
---|
734 | } /* end of gmth_create_filename */ |
---|
735 | |
---|
736 | |
---|
737 | |
---|
738 | /*----------------------------------------------------------------------------*/ |
---|
739 | |
---|
740 | |
---|
741 | void gmth_insertheader( FILE *gmt ) |
---|
742 | |
---|
743 | /* inserts header to GMT file |
---|
744 | * |
---|
745 | * parameter of routine |
---|
746 | * FILE *gmt; input; PostScript file to insert header |
---|
747 | */ |
---|
748 | { |
---|
749 | /* local variables */ |
---|
750 | FILE *hf; /* header file */ |
---|
751 | char line[BC_LONGSTRLTH+1]; /* current line */ |
---|
752 | char timestr[BC_LINELTH+1]; /* time string */ |
---|
753 | |
---|
754 | /* executable code */ |
---|
755 | |
---|
756 | fprintf( gmt, "# some comment\n" ); |
---|
757 | |
---|
758 | } /* end of gmth_insertheader */ |
---|
759 | |
---|
760 | |
---|
761 | |
---|
762 | /*----------------------------------------------------------------------------*/ |
---|
763 | |
---|
764 | |
---|
765 | void gmth_closefile( FILE *gmt ) |
---|
766 | |
---|
767 | /* closes hardcopy file |
---|
768 | * |
---|
769 | * parameter of routine |
---|
770 | * FILE *gmt; input; pointer to hardcopy file |
---|
771 | */ |
---|
772 | { |
---|
773 | |
---|
774 | /* executable code */ |
---|
775 | |
---|
776 | fclose( gmt ); |
---|
777 | |
---|
778 | } /* end of gmth_closepsf */ |
---|
779 | |
---|
780 | |
---|
781 | |
---|
782 | /*----------------------------------------------------------------------------*/ |
---|
783 | |
---|
784 | |
---|
785 | |
---|
786 | void gmth_changestyle( int style ) |
---|
787 | |
---|
788 | /* changes the current style, disabled |
---|
789 | * |
---|
790 | * parameters of routine |
---|
791 | * int style; input; new style number |
---|
792 | */ |
---|
793 | { |
---|
794 | /* executable code */ |
---|
795 | |
---|
796 | if (style < 0) style = 0; |
---|
797 | if (style >= GMTC_MAXSTYLE) style = 0; |
---|
798 | gmtv_currstyle = style; |
---|
799 | |
---|
800 | } /* end of gmth_changestyle */ |
---|
801 | |
---|
802 | |
---|
803 | |
---|
804 | /*----------------------------------------------------------------------------*/ |
---|