source: SH_SHM/trunk/source/globalparams.c @ 344

Revision 344, 42.5 KB checked in by marcus, 13 years ago (diff)

r183 | walther | 2011-03-10 15:03:12 +0100 (Do, 10 Mär 2011) | 1 line

Added configuration parameter show_evt_info

Line 
1
2/* file globalparams.c
3 *      ==============
4 *
5 * $Revision: 183 $, $Date: 2011-03-10 15:03:12 +0100 (Do, 10 MÀr 2011) $
6 *
7 * Management of global parameters
8 * K. Stammler, 9-May-2006
9 */
10
11
12/*
13 *
14 *  SeismicHandler, seismic analysis software
15 *  Copyright (C) 1992,  Klaus Stammler, Federal Institute for Geosciences
16 *                                       and Natural Resources (BGR), Germany
17 *
18 *  This program is free software; you can redistribute it and/or modify
19 *  it under the terms of the GNU General Public License as published by
20 *  the Free Software Foundation; either version 2 of the License, or
21 *  (at your option) any later version.
22 *
23 *  This program is distributed in the hope that it will be useful,
24 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 *  GNU General Public License for more details.
27 *
28 *  You should have received a copy of the GNU General Public License
29 *  along with this program; if not, write to the Free Software
30 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
31 *
32 */
33
34
35#include <stdio.h>
36#include <string.h>
37#include "basecnst.h"
38#ifdef BC_INC_STDLIB
39#include BC_INC_STDLIB
40#endif
41#include "utusrdef.h"
42#include "globalparams.h"
43
44
45/* local types */
46typedef struct _string_elem {
47        struct _string_elem   *next;  /* pointer to next string element */
48        char             *string;     /* string values */
49        int              strlth;      /* string length excl. term null */
50} TGpStringElem;
51
52
53
54/* integer variables
55 * -----------------
56 */
57
58static char *gpv_i_name[] = {
59        "debug_level",
60        "parfile_version",
61        "parfile_subversion",
62        "min_drag_box_width",
63        "double_click_time",
64        "x_max_drawlth",
65        "drag_box_rubber_val",
66        "default_quality",
67        "default_event_type",
68        "default_phase_flags",
69        "default_depth_type",
70        "default_loc_quality",
71        "max_cursor_form",
72        "top_margin",
73        "parameter_box_x",
74        "parameter_box_y",
75        "parameter_box_w",
76        "parameter_box_h",
77        "phase_box_x",
78        "phase_box_y",
79        "phase_box_w",
80        "phase_box_h",
81        "window_main_x",
82        "window_main_y",
83        "window_main_w",
84        "window_main_h",
85        "single_trace_box_x",
86        "single_trace_box_y",
87        "single_trace_box_w",
88        "single_trace_box_h",
89        "window_border",
90        "draw_area_width",
91        "draw_area_height",
92        "trace_normalisation",
93        "spectrogram_width",
94        "spectrogram_step",
95        "keysym_arrow_up",
96        "keysym_arrow_down",
97        "keysym_arrow_left",
98        "keysym_arrow_right",
99        "i_last_parameter"
100};
101
102/* default values if no parameter file is found */
103static int gpv_i_glob[cGpI_last+1] = {
104        0,    /* debug_level */
105        0,    /* parfile_version */
106        0,    /* parfile_subversion */
107        7,    /* min_drag_box_width */
108        200,  /* double_click_time */
109        4096, /* x_max_drawlth */
110        10,   /* drag_box_rubber_val */
111        2,    /* default_quality */
112        0,    /* default_phase_type */
113        0,    /* default_phase_flags */
114        0,    /* default_depth_type */
115        0,    /* default_loc_quality */
116        5,    /* max_cursor_form */
117        20,   /* top margin */
118        93,   /* parameter_box_x */
119        0,    /* parameter_box_y */
120        125,  /* parameter_box_w */
121        700,  /* parameter_box_h */
122        -38,  /* phase_box_x */
123        0,    /* phase_box_y */
124        155,  /* phase_box_w */
125        720,  /* phase_box_h */
126        224,  /* window_main_x */
127        220,  /* window_main_y */
128        1039, /* window_main_w */
129        516,  /* window_main_h */
130        224,  /* single_trace_box_x */
131        0,    /* single_trace_box_y */
132        1039, /* single_trace_box_w */
133        203,  /* single_trace_box_h */
134        3,    /* window_border */
135        1035, /* draw_area_width */
136        485,  /* draw_area_height */
137        0,    /* trace_normalisation */
138        1024, /* spectrogram_width */
139        4,    /* spectrogram_step */
140        268762962, /* keysym_arrow_up */
141        268762964, /* keysym_arrow_down */
142        268762961, /* keysym_arrow_left */
143        268762963, /* keysym_arrow_right */
144        0     /* last parameter */
145};
146
147
148/* float variables
149 * -----------------
150 */
151
152static char *gpv_f_name[] = {
153        "close_phase_resol",
154        "phase_ampl_diff",
155        "trace_zoom_base",
156        "trace_zoom_exp",
157        "area_zoom_base",
158        "area_zoom_exp",
159        "move_wdw_step",
160        "default_depth",
161        "colour_fg_red",
162        "colour_fg_green",
163        "colour_fg_blue",
164        "colour_bg_red",
165        "colour_bg_green",
166        "colour_bg_blue",
167        "colour_dialog_fg_red",
168        "colour_dialog_fg_green",
169        "colour_dialog_fg_blue",
170        "colour_dialog_bg0_red",
171        "colour_dialog_bg0_green",
172        "colour_dialog_bg0_blue",
173        "colour_dialog_bg1_red",
174        "colour_dialog_bg1_green",
175        "colour_dialog_bg1_blue",
176        "colour_dialog_bg2_red",
177        "colour_dialog_bg2_green",
178        "colour_dialog_bg2_blue",
179        "colour_mark_red",
180        "colour_mark_green",
181        "colour_mark_blue",
182        "colour_mark0_red",
183        "colour_mark0_green",
184        "colour_mark0_blue",
185        "colour_theo_red",
186        "colour_theo_green",
187        "colour_theo_blue",
188        "colour_auto_red",
189        "colour_auto_green",
190        "colour_auto_blue",
191        "colour_crsr_red",
192        "colour_crsr_green",
193        "colour_crsr_blue",
194        "colour_alert_red",
195        "colour_alert_green",
196        "colour_alert_blue",
197        "colour_addfil_red",
198        "colour_addfil_green",
199        "colour_addfil_blue",
200        "calib_wdw_width",
201        "calib_wdw_height",
202        "calib_azimuth_grid",
203        "calib_slowness_grid",
204        "sn_noise_start",
205        "sn_noise_end",
206        "sn_signal_start",
207        "sn_signal_end",
208        "idphases_tol_trav",
209        "idphases_tol_travsurf",
210        "idphases_tol_slow",
211        "idphases_tol_azim",
212        "axis_label_rounding",
213        "autofilter_sepdist",
214        "f_last_parameter"
215};
216
217static float gpv_f_glob[cGpF_last+1] = {
218        8.0,       /* close_phase_resol */
219        60.0,      /* phase_ampl_diff */
220        10.0,      /* trace_zoom_base */
221        3.3333333, /* trace_zoom_exp */
222        10.0,      /* area_zoom_base */
223        25.0,      /* area_zoom_exp */
224        1.0,       /* move_wdw_step */
225        33.0,      /* default_depth */
226        0.0,       /* colour_fg_red */
227        0.0,       /* colour_fg_green */
228        0.0,       /* colour_fg_blue */
229        1.0,       /* colour_bg_red */
230        1.0,       /* colour_bg_green */
231        1.0,       /* colour_bg_blue */
232        0.3882,    /* colour_dialog_fg_red */
233        0.1569,    /* colour_dialog_fg_green */
234        0.1647,    /* colour_dialog_fg_blue */
235        0.9686,    /* colour_dialog_bg0_red */
236        0.8706,    /* colour_dialog_bg0_green */
237        0.7412,    /* colour_dialog_bg0_blue */
238        0.9490,    /* colour_dialog_bg1_red */
239        0.6941,    /* colour_dialog_bg1_green */
240        0.4314,    /* colour_dialog_bg1_blue */
241        0.3882,    /* colour_dialog_bg2_red */
242        0.1569,    /* colour_dialog_bg2_green */
243        0.1647,    /* colour_dialog_bg2_blue */
244        1.0,       /* colour_mark_red */
245        0.0,       /* colour_mark_green */
246        0.0,       /* colour_mark_blue */
247        1.0,       /* colour_mark0_red */
248        0.7,       /* colour_mark0_green */
249        0.7,       /* colour_mark0_blue */
250        0.0,       /* colour_theo_red */
251        1.0,       /* colour_theo_green */
252        0.0,       /* colour_theo_blue */
253        1.0,       /* colour_auto_red */
254        0.5,       /* colour_auto_green */
255        0.5,       /* colour_auto_blue */
256        0.0,       /* colour_crsr_red */
257        0.0,       /* colour_crsr_green */
258        1.0,       /* colour_crsr_blue */
259        0.9,       /* colour_alert_red */
260        0.0,       /* colour_alert_green */
261        0.0,       /* colour_alert_blue */
262        0.6,       /* colour_addfil_red */
263        0.0,       /* colour_addfil_green */
264        0.25,      /* colour_addfil_blue */
265        2.5,       /* calib_wdw_width */
266        2.5,       /* calib_wdw_height */
267        10.0,      /* calib_azimuth_grid */
268        0.5,       /* calib_slowness_grid */
269        -13.0,     /* sn_noise_start */
270        -3.0,      /* sn_noise_end */
271        -1.0,      /* sn_signal_start */
272        9.0,       /* sn_signal_end */
273        20.0,      /* idphases_tol_trav */
274        1200.0,    /* idphases_tol_travsurf */
275        1.5,       /* idphases_tol_slow */
276        20.0,      /* idphases_tol_azim */
277        0.01,      /* axis_label_rounding */
278        5.0,       /* autofilter_sepdist */
279        0.0        /* last parameter */
280};
281
282
283/* char variables
284 * -----------------
285 */
286
287static char *gpv_c_name[] = {
288        "filter_type",
289        "c_last_parameter"
290};
291
292static char gpv_c_glob[cGpC_last+1] = {
293        ' ',       /* filter_type */
294        ' '        /* last parameter */
295};
296
297
298/* string variables
299 * -----------------
300 */
301
302static char *gpv_s_name[] = {
303        "defpath_events",
304        "defpath_gse",
305        "defpath_ah",
306        "defpath_q",
307        "defpath_evid",
308        "defpath_evtout",
309        "defpath_data",
310        "defpath_help",
311        "defpath_errors",
312        "defpath_userdir",
313        "defpath_extprog",
314        "analyst",
315        "list_of_analysts",
316        "texteditor",
317        "refstation",
318        "list_of_refstations",
319        "default_filter",
320        "minmax_format",
321        "default_source",
322        "auto_phase",
323        "depth_phase_list",
324        "theo_phase_list",
325        "diff_phase_list",
326        "event_check_proc",
327        "screendump_proc",
328        "evtview_proc",
329        "reformat_proc",
330        "final_proc",
331        "motif_log",
332        "ftp_address",
333        "ftp_path",
334        "exclusive_agency",
335        "sfdb_command",
336        "sfdb_exec_qual",
337        "sfdb_trailer",
338        "autofilter_local",
339        "autofilter_tele",
340        "s_last_parameter"
341};
342
343static char gpv_s_glob[cGpS_last+1][cGp_TEXTVARLTH+1] = {
344        "default",                       /* defpath_events */
345        "default",                       /* defpath_gse */
346        "default",                       /* defpath_ah */
347        "default",                       /* defpath_q */
348        "default",                       /* defpath_evid */
349        "default",                       /* defpath_evtout */
350        "default",                       /* defpath_data */
351        "default",                       /* defpath_help */
352        "default",                       /* defpath_errors */
353        "default",                       /* defpath_userdir */
354        "default",                       /* defpath_extprog */
355        "",                              /* analyst */
356        "",                              /* list_of_analysts */
357        "xedit",                         /* texteditor */
358        "CENTRE",                        /* refstation */
359        "GRA1,MOX,GRFO,GEC2,CENTRE,---", /* list_of_refstations */
360        "",                              /* default_filter*/
361        "",                              /* minmax_format */
362        "UNDEF",                         /* default_source */
363        "beam",                          /* auto_phase */
364        "pP,sP,pS,sS",                   /* depth_phase_list */
365        "P,S,pP,pS,sP,sS,ScS,PcP,PP,SS", /* theo_phase_list */
366        "S-P,PP-P,Pg-Pn",                /* diff_phase_list */
367        "",                              /* event_check_proc */
368        "screendump.csh",                /* screendump_proc */
369        "ev2view",                       /* evtview_proc */
370        "undefined",                     /* reformat_proc */
371        "",                              /* final_proc */
372        "",                              /* motif_log */
373        "ftp.szgrf.bgr.de",              /* ftp_address */
374        "pub/software/shm",              /* ftp_path */
375        "",                              /* exclusive_agency */
376        "mysql sfdb",                    /* sfdb_command */
377        "-B -e",                         /* sfdb_exec_qual */
378        "",                              /* sfdb_trailer */
379        "SHM_BP_1HZ_8HZ_4",              /* autofilter_local */
380        "S+G_WWSSN_SP",                  /* autofilter_tele */
381        "s_last_parameter"               /* last parameter */
382};
383
384
385/* boolean variables
386 * -----------------
387 */
388
389static char *gpv_b_name[] = {
390        "top_down_order",
391        "auto_pick_first",
392        "auto_scaling",
393        "prompt_analyst",
394        "reverse_xors",
395        "full_phase_names",
396        "own_accelerators",
397        "small_menu_font",
398        "recover_evid",
399        "overwrite_string_lists",
400        "ignore_data_lock",
401        "reads_swap",
402        "reads_invhdr",
403        "autosort_by_distance",
404        "autofilter_by_distance",
405        "show_evt_info",
406        "b_last_parameter"
407};
408
409static long gpv_b_glob =
410        (1 << cGpB_autopick_first)         |
411        (1 << cGpB_auto_scaling)           |
412        (1 << cGpB_overwrite_string_lists) |
413        (1 << cGpB_own_accelerators)       |
414        (1 << cGpB_autosort_by_distance)   |
415        (1 << cGpB_autofilter_by_distance) |
416        (1 << cGpB_reads_swap)
417;
418
419
420/* string list variables
421 * ---------------------
422 */
423
424static char *gpv_l_name[] = {
425        "station_info_file",
426        "filter_lookup_table",
427        "sensitivity_file",
428        "channel_translation",
429        "defpath_filter",
430        "defpath_command",
431        "defpath_globals",
432        "l_last_parameter"
433};
434
435static TGpStringElem gpv_l_glob[cGpL_last+1] = {
436        {NULL,"default",7},            /* station_info_file */
437        {NULL,"default",7},            /* filter_lookup_table */
438        {NULL,"default",7},            /* sensitivity_file */
439        {NULL,"default",7},            /* channel_translation */
440        {NULL,"default",7},            /* defpath_filter */
441        {NULL,"default",7},            /* defpath_command */
442        {NULL,"default",7},            /* defpath_globals */
443        {NULL,"",0}                    /* last parameter */
444};
445
446
447/* prototypes of local routines */
448static void GpReadParametersFromFile( char fname[] );
449static void GpEvaluateVar( char val[] );
450
451
452/*----------------------------------------------------------------------------*/
453
454
455
456void GpReadParfile( void )
457
458/* Reads parameters from file
459 *
460 * no parameters passed
461 */
462{
463        /* local variables */
464        char     *env;               /* pointer to environment */
465        char     parfile[cBcFileLth+1]; /* name of parameter file */
466        char     *cptr;              /* char pointer */
467        int      i;                  /* counter */
468
469        /* executable code */
470
471        /* get parameter file */
472        env = (char *)getenv( "SH_USER_PARAM" );
473        if  (env == NULL)  {
474                env = (char *)getenv( "SH_INPUTS" );
475                if  (strlen(env) < cBcFileLth-15)  {
476                        strcpy( parfile, env );
477                        strcat( parfile, "/shm-config.txt" );
478                } else {
479                        fprintf( stderr, "configuration filename too long.  Abort.\n" );
480                        exit( 1 );
481                } /*endif*/
482        } else {
483                if  (strlen(env) < cBcFileLth)  {
484                        strcpy( parfile, env );
485                } else {
486                        fprintf( stderr, "environment SH_USER_PARAM too long.  Abort.\n" );
487                        exit( 1 );
488                } /*endif*/
489        } /*endif*/
490
491        GpReadParametersFromFile( parfile );
492
493        /* set 'default' strings */
494        if  (strcmp(gpv_s_glob[cGpS_defpath_events],"default") == 0)  {
495                cptr = (char *)getenv( "HOME" );
496                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
497                if  (strlen(cptr) < cGp_TEXTVARLTH)
498                        strcpy( gpv_s_glob[cGpS_defpath_events], cptr );
499        } /*endif*/
500        if  (strcmp(gpv_s_glob[cGpS_defpath_gse],"default") == 0)  {
501                cptr = (char *)getenv( "SH_ROOT" );
502                if  (cptr == NULL)  {printf("SH_ROOT not defined\n"); exit(1);}
503                if  (strlen(cptr) < cGp_TEXTVARLTH-21)  {
504                        strcpy( gpv_s_glob[cGpS_defpath_gse], cptr );
505                        strcat( gpv_s_glob[cGpS_defpath_gse], "/data-examples/gse" );
506                } /*endif*/
507        } /*endif*/
508        if  (strcmp(gpv_s_glob[cGpS_defpath_ah],"default") == 0)  {
509                cptr = (char *)getenv( "HOME" );
510                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
511                if  (strlen(cptr) < cGp_TEXTVARLTH)
512                        strcpy( gpv_s_glob[cGpS_defpath_ah], cptr );
513        } /*endif*/
514        if  (strcmp(gpv_s_glob[cGpS_defpath_q],"default") == 0)  {
515                cptr = (char *)getenv( "HOME" );
516                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
517                if  (strlen(cptr) < cGp_TEXTVARLTH)
518                        strcpy( gpv_s_glob[cGpS_defpath_q], cptr );
519        } /*endif*/
520        if  (strcmp(gpv_s_glob[cGpS_defpath_evid],"default") == 0)  {
521                cptr = (char *)getenv( "SH_PRIVATE" );
522                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
523                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
524                if  (strlen(cptr) < cGp_TEXTVARLTH-6)  {
525                        strcpy( gpv_s_glob[cGpS_defpath_evid], cptr );
526                        strcat( gpv_s_glob[cGpS_defpath_evid], "/evid/" );
527                } /*endif*/
528        } /*endif*/
529        if  (strcmp(gpv_s_glob[cGpS_defpath_evtout],"default") == 0)  {
530                cptr = (char *)getenv( "SH_PRIVATE" );
531                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
532                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
533                if  (strlen(cptr) < cGp_TEXTVARLTH-8)  {
534                        strcpy( gpv_s_glob[cGpS_defpath_evtout], cptr );
535                        strcat( gpv_s_glob[cGpS_defpath_evtout], "/evtout/" );
536                } /*endif*/
537        } /*endif*/
538        if  (strcmp(gpv_s_glob[cGpS_defpath_help],"default") == 0)  {
539                cptr = (char *)getenv( "SH_ROOT" );
540                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
541                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
542                if  (strlen(cptr) < cGp_TEXTVARLTH-6)  {
543                        strcpy( gpv_s_glob[cGpS_defpath_help], cptr );
544                        strcat( gpv_s_glob[cGpS_defpath_help], "/help/" );
545                } /*endif*/
546        } /*endif*/
547        if  (strcmp(gpv_s_glob[cGpS_defpath_errors],"default") == 0)  {
548                cptr = (char *)getenv( "SH_ROOT" );
549                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
550                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
551                if  (strlen(cptr) < cGp_TEXTVARLTH-8)  {
552                        strcpy( gpv_s_glob[cGpS_defpath_errors], cptr );
553                        strcat( gpv_s_glob[cGpS_defpath_errors], "/errors/" );
554                } /*endif*/
555        } /*endif*/
556        if  (strcmp(gpv_s_glob[cGpS_defpath_userdir],"default") == 0)  {
557                /* the usage of SH_USERDIR is for backward compatibility */
558                cptr = (char *)getenv( "SH_USERDIR" );
559                if  (cptr == NULL)  {
560                        cptr = (char *)getenv( "HOME" );
561                        if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
562                        if  (strlen(cptr) < cGp_TEXTVARLTH-17)  {
563                                strcpy( gpv_s_glob[cGpS_defpath_userdir], cptr );
564                                strcat( gpv_s_glob[cGpS_defpath_userdir], "/shfiles/private/" );
565                        } /*endif*/
566                } else {
567                        if  (strlen(cptr) < cGp_TEXTVARLTH)
568                                strcpy( gpv_s_glob[cGpS_defpath_userdir], cptr );
569                } /*endif*/
570        } /*endif*/
571        if  (strcmp(gpv_s_glob[cGpS_defpath_extprog],"default") == 0)  {
572                /* the usage of SH_UTIL is for backward compatibility */
573                cptr = (char *)getenv( "SH_UTIL" );
574                if  (cptr == NULL)  {
575                        cptr = (char *)getenv( "HOME" );
576                        if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
577                        if  (strlen(cptr) < cGp_TEXTVARLTH-17)  {
578                                strcpy( gpv_s_glob[cGpS_defpath_extprog], cptr );
579                                strcat( gpv_s_glob[cGpS_defpath_extprog], "/util/" );
580                        } /*endif*/
581                } else {
582                        if  (strlen(cptr) < cGp_TEXTVARLTH)
583                                strcpy( gpv_s_glob[cGpS_defpath_extprog], cptr );
584                } /*endif*/
585        } /*endif*/
586
587        /* 'default' in string lists */
588        if  (strcmp(gpv_l_glob[cGpL_station_info_file].string,"default") == 0)  {
589                cptr = (char *)getenv( "SH_INPUTS" );
590                if  (cptr != NULL)  {
591                        i = strlen( cptr );
592                        /* "default" value is set by variable initialisation, can't free it */
593                        /*free( gpv_l_glob[cGpL_station_info_file].string );*/
594                        gpv_l_glob[cGpL_station_info_file].string =
595                                (char *)malloc( (int)sizeof(char)*(i+12) );
596                        strcpy( gpv_l_glob[cGpL_station_info_file].string, cptr );
597                        strcat( gpv_l_glob[cGpL_station_info_file].string, "STATINF.DAT" );
598                        gpv_l_glob[cGpL_station_info_file].strlth = i+11;
599                } /*endif*/
600        } /*endif*/
601        if  (strcmp(gpv_l_glob[cGpL_filter_lookup_table].string,"default") == 0)  {
602                cptr = (char *)getenv( "SH_INPUTS" );
603                if  (cptr != NULL)  {
604                        i = strlen( cptr );
605                        /*free( gpv_l_glob[cGpL_filter_lookup_table].string );*/
606                        gpv_l_glob[cGpL_filter_lookup_table].string =
607                                (char *)malloc( (int)sizeof(char)*(i+18) );
608                        strcpy( gpv_l_glob[cGpL_filter_lookup_table].string, cptr );
609                        strcat( gpv_l_glob[cGpL_filter_lookup_table].string, "filter_lookup.txt" );
610                        gpv_l_glob[cGpL_filter_lookup_table].strlth = i+17;
611                } /*endif*/
612        } /*endif*/
613        if  (strcmp(gpv_l_glob[cGpL_sensitivity_file].string,"default") == 0)  {
614                cptr = (char *)getenv( "SH_INPUTS" );
615                if  (cptr != NULL)  {
616                        i = strlen( cptr );
617                        /*free( gpv_l_glob[cGpL_sensitivity_file].string );*/
618                        gpv_l_glob[cGpL_sensitivity_file].string =
619                                (char *)malloc( (int)sizeof(char)*(i+18) );
620                        strcpy( gpv_l_glob[cGpL_sensitivity_file].string, cptr );
621                        strcat( gpv_l_glob[cGpL_sensitivity_file].string, "sensitivities.txt" );
622                        gpv_l_glob[cGpL_sensitivity_file].strlth = i+17;
623                } /*endif*/
624        } /*endif*/
625        if  (strcmp(gpv_l_glob[cGpL_channel_translation].string,"default") == 0)  {
626                cptr = (char *)getenv( "SH_INPUTS" );
627                if  (cptr != NULL)  {
628                        i = strlen( cptr );
629                        /*free( gpv_l_glob[cGpL_channel_translation].string );*/
630                        gpv_l_glob[cGpL_channel_translation].string =
631                                (char *)malloc( (int)sizeof(char)*(i+14) );
632                        strcpy( gpv_l_glob[cGpL_channel_translation].string, cptr );
633                        strcat( gpv_l_glob[cGpL_channel_translation].string, "chantrans.txt" );
634                        gpv_l_glob[cGpL_channel_translation].strlth = i+13;
635                } /*endif*/
636        } /*endif*/
637        if  (strcmp(gpv_l_glob[cGpL_defpath_filter].string,"default") == 0)
638                GpParseStringList( cGpL_defpath_filter, ".,$SH_ROOT/filter" );
639        if  (strcmp(gpv_l_glob[cGpL_defpath_command].string,"default") == 0)
640                GpParseStringList( cGpL_defpath_command, ".,$SH_ROOT/command" );
641        if  (strcmp(gpv_l_glob[cGpL_defpath_globals].string,"default") == 0)
642                GpParseStringList( cGpL_defpath_globals, ".,$SH_ROOT/globals/" );
643
644        /* make some strings uppercase */
645        ut_cap( gpv_s_glob[cGpS_refstation] );
646        ut_cap( gpv_s_glob[cGpS_list_of_refstations] );
647
648        /* check for setting of normalisation */
649        if  (gpv_i_glob[cGpI_trace_normalisation] == cGp_NORM_UNDEF)  {
650                /* trace_normalisation not set take it from 'old' auto_scaling */
651                printf( "--globalparams: warning: auto_scaling obsolete, please set trace_normalisation\n" );
652                gpv_i_glob[cGpI_trace_normalisation] =
653                        (gpv_b_glob & cGpB_auto_scaling) ? cGp_NORM_SW : cGp_NORM_AW;
654        } else {
655                switch  (gpv_i_glob[cGpI_trace_normalisation])  {
656                case cGp_NORM_CONST:  GpSetBoolean( cGpB_auto_scaling, 0 ); break;
657                case cGp_NORM_AW:     GpSetBoolean( cGpB_auto_scaling, 0 ); break;
658                case cGp_NORM_SW:     GpSetBoolean( cGpB_auto_scaling, 1 ); break;
659                default:
660                        printf( "--globalparams: illegal value of trace_normalisation, please correct\n" );
661                        GpSetBoolean( cGpB_auto_scaling, 0 );
662                        gpv_i_glob[cGpI_trace_normalisation] = cGp_NORM_AW;
663                } /*endswitch*/
664        } /*endif*/
665
666        if  (gpv_i_glob[cGpI_parfile_version] == 0)
667                printf( "--globalparams: warning: no version of parameter file found\n" );
668
669} /* end of GpReadParfile */
670
671
672
673/*----------------------------------------------------------------------------*/
674
675
676
677static void GpReadParametersFromFile( char fname[] )
678
679/* reads parametes from file, calls itself on 'include' statement
680 *
681 * parameters of routine
682 * char       fname[];    input; name of file to read
683 */
684{
685        /* local variables */
686        FILE     *fp;                /* pointer to input file */
687        char     line[cBcVeryLongStrLth+1]; /* current line of file */
688        char     name[cBcLineLth+1]; /* variable name */
689        int      namelth;            /* length of name */
690        int      itmp;               /* integer scratch */
691        float    ftmp;               /* float scratch */
692        char     ctmp;               /* char scratch */
693        char     stmp[cBcVeryLongStrLth+1]; /* string scratch */
694        TGpIntIndex  icnt;           /* integer counter */
695        TGpFloatIndex  fcnt;         /* float counter */
696        TGpCharIndex  ccnt;          /* char counter */
697        TGpStringIndex  scnt;        /* string counter */
698        TGpBooleanIndex  bcnt;       /* boolean counter */
699        TGpStringListIndex lcnt;     /* string list counter */
700        int      found;              /* (boolean) parameter found */
701        char     *cptr;              /* char pointer */
702        char     *env;               /* pointer to environment */
703
704        /* executable code */
705
706        if  (GpGetInt(cGpI_debug_level) > 3)
707                printf( "SHM-dbg3: reading parameters from parfile %s\n", fname );
708
709        fp = fopen( fname, "r" );
710        if  (fp == NULL)  {
711                if  (GpGetInt(cGpI_debug_level) > 2)
712                        printf( "SHM-dbg3: parfile %s not found\n", fname );
713                return;
714        } /*endif*/
715
716        while  (fgets(line,cBcVeryLongStrLth,fp) != NULL)  {
717
718                if  (*line == '!' || *line == '#' || *line == '\n')  continue;
719                if  (line[1] == '$')  continue;
720                if  (sscanf(line,"%s",name) != 1)  continue;
721                namelth = strlen( name );
722                if  (strlen(line) < namelth)  {
723                        printf( "--globalparams: empty entry %s, ignore\n", name );
724                        continue;
725                } /*endif*/
726                found = 0;
727
728                /* check for include statement */
729                if  (strcmp(name,"include") == 0)  {
730                        if  (GpGetInt(cGpI_debug_level) > 3)
731                                printf( "SHM-dbg4: include statement found\n", fname );
732                        if  (sscanf(line+namelth,"%s",stmp) != 1)  {
733                                printf( "--globalparams: error reading include in parameter file %s\n",
734                                        fname );
735                        } else {
736                                if  (strlen(stmp) > cGp_TEXTVARLTH)  {
737                                        printf( "--globalparams: include filename %s too long\n", name );
738                                } else {
739                                        /* reentrant call, read from $SH_INPUTS if not absolute */
740                                        if  (*stmp == '/')  {
741                                                /* absolute name, dont't change */
742                                                strcpy( line, stmp );
743                                        } else {
744                                                env = (char *)getenv( "SH_INPUTS" );
745                                                if  (strlen(env)+strlen(stmp)+1 > cBcVeryLongStrLth)  {
746                                                        printf( "--globalparams: string overflow in include statement\n" );
747                                                        continue;
748                                                } /*endif*/
749                                                sprintf( line, "%s/%s", env, stmp );
750                                        } /*endif*/
751                                        GpReadParametersFromFile( line );
752                                } /*endif*/
753                        } /*endif*/
754                        continue;
755                } /*endif*/
756
757                /* check for version number */
758                if  (strcmp(name,"file_version") == 0)  {
759                        if  (sscanf(line+namelth,"%s",stmp) != 1)  {
760                                printf( "--globalparams: error reading version in parameter file %s\n",
761                                        fname );
762                        } else {
763                                if  (strlen(stmp) > cGp_TEXTVARLTH)  {
764                                        printf( "--globalparams: include filename %s too long\n", name );
765                                } else {
766                                        if  (sscanf(stmp,"%d.%d",&itmp,&icnt) == 2)  {
767                                                gpv_i_glob[cGpI_parfile_version] = itmp;
768                                                gpv_i_glob[cGpI_parfile_subversion] = icnt;
769                                                if  (gpv_i_glob[cGpI_parfile_version] > cGp_VERSION
770                                                        || gpv_i_glob[cGpI_parfile_subversion] > cGp_SUBVERSION)  {
771                                                        printf( "--globalparams: warning: file version too new; ");
772                                                        printf( "expect problems while reading\n" );
773                                                        printf( "--globalparams: version %d.%d is expected here\n",
774                                                                cGp_VERSION, cGp_SUBVERSION );
775                                                } else if (gpv_i_glob[cGpI_parfile_version] < cGp_VERSION) {
776                                                        printf( "--globalparams: warning: old parameter file version; ");
777                                                        printf( "consider creating a new one\n" );
778                                                        printf( "--globalparams: version %d.%d is expected here\n",
779                                                                cGp_VERSION, cGp_SUBVERSION );
780                                                } /*endif*/
781                                        } else {
782                                                printf( "--globalparams: error reading parameter version\n" );
783                                        } /*endif*/
784                                } /*endif*/
785                        } /*endif*/
786                        continue;
787                } /*endif*/
788
789                /* integer variables */
790                for  (icnt=0; icnt<cGpI_last; icnt++)
791                        if  (strcmp(gpv_i_name[icnt],name) == 0)  {
792                                if  (sscanf(line+namelth,"%d",&itmp) != 1)  {
793                                        printf( "--globalparams: error reading parameter %s\n", name );
794                                } else {
795                                        gpv_i_glob[icnt] = itmp;
796                                        found = 1;
797                                } /*endif*/
798                                break;
799                        } /*endif*/
800                if  (found)  continue;
801
802                /* float variables */
803                for  (fcnt=0; fcnt<cGpF_last; fcnt++)
804                        if  (strcmp(gpv_f_name[fcnt],name) == 0)  {
805                                if  (sscanf(line+namelth,"%f",&ftmp) != 1)  {
806                                        printf( "--globalparams: error reading parameter %s\n", name );
807                                } else {
808                                        gpv_f_glob[fcnt] = ftmp;
809                                        found = 1;
810                                } /*endif*/
811                                break;
812                        } /*endif*/
813                if  (found)  continue;
814
815                /* char variables */
816                for  (ccnt=0; ccnt<cGpC_last; ccnt++)
817                        if  (strcmp(gpv_c_name[ccnt],name) == 0)  {
818                                /* read first character after blanks and tabs */
819                                cptr = line + namelth;
820                                while  (*cptr == ' ' || *cptr == '\t')  cptr++;
821                                if  (*cptr != '\n' && *cptr != '\0')  {
822                                        gpv_c_glob[ccnt] = *cptr;
823                                        found = 1;
824                                } /*endif*/
825                                break;
826                        } /*endif*/
827                if  (found)  continue;
828
829                /* string variables */
830                for  (scnt=0; scnt<cGpS_last; scnt++)
831                        if  (strcmp(gpv_s_name[scnt],name) == 0)  {
832                                /* skip blanks after keyword and take remaining line as value */
833                                cptr = line + namelth;
834                                while  (*cptr == ' ' || *cptr == '\t')  cptr++;
835                                strcpy( stmp, cptr );
836                                /* drop the linefeed */
837                                itmp = strlen( stmp );
838                                if  (itmp > 0 && stmp[itmp-1] == '\n')  stmp[itmp-1] = '\0';
839                                if  (*stmp == '\0')  {
840                                        printf( "--globalparams: error reading parameter %s\n", name );
841                                } else {
842                                        if  (strlen(stmp) > cGp_TEXTVARLTH)  {
843                                                printf( "--globalparams: string parameter %s too long\n", name );
844                                        } else {
845                                                if  (strcmp(stmp,"<NULL>") == 0 || strcmp(stmp,"NULL") == 0
846                                                        || strcmp(stmp,"<null>") == 0 || strcmp(stmp,"null") == 0)  {
847                                                        gpv_s_glob[scnt][0] = '\0';
848                                                } else {
849                                                        while  (stmp[0] == '$')
850                                                                GpEvaluateVar( stmp );
851                                                        strcpy( gpv_s_glob[scnt], stmp );
852                                                } /*endif*/
853                                                found = 1;
854                                        } /*endif*/
855                                } /*endif*/
856                                break;
857                        } /*endif*/
858
859                /* boolean variables */
860                for  (bcnt=0; bcnt<cGpB_last; bcnt++)
861                        if  (strcmp(gpv_b_name[bcnt],name) == 0)  {
862                                if  (sscanf(line+namelth,"%s",&stmp) != 1)  {
863                                        printf( "--globalparams: error reading parameter %s\n", name );
864                                } else {
865                                        if  (strcmp(stmp,"TRUE") == 0 || strcmp(stmp,"true") == 0
866                                                || strcmp(stmp,"True") == 0 || strcmp(stmp,"1") == 0)  {
867                                                gpv_b_glob |= (1 << bcnt);
868                                                found = 1;
869                                        } else if  (strcmp(stmp,"FALSE") == 0 || strcmp(stmp,"false") == 0
870                                                || strcmp(stmp,"False") == 0 || strcmp(stmp,"0") == 0)  {
871                                                gpv_b_glob &= ~(1 << bcnt);
872                                                found = 1;
873                                        } else {
874                                                printf( "--globalparams: illegal boolean value at %s\n", name );
875                                        } /*endif*/
876                                } /*endif*/
877                                break;
878                        } /*endif*/
879                if  (found)  continue;
880
881                /* string list variables */
882                for  (lcnt=0; lcnt<cGpL_last; lcnt++)
883                        if  (strcmp(gpv_l_name[lcnt],name) == 0)  {
884                                GpParseStringList( lcnt, line+namelth );
885                                found = 1;
886                        } /*endif*/
887
888                if  (!found)
889                        printf( "--globalparams: illegal parameter %s in parameter file\n", name );
890
891        } /*endwhile*/
892
893        fclose( fp );
894
895} /* end of GpReadParametersFromFile */
896
897
898
899/*----------------------------------------------------------------------------*/
900
901
902
903int GpGetInt( TGpIntIndex idx )
904
905/* Returns integer valued global
906 *
907 * parameters of routine
908 * TGpIntIndex   idx;       input; index of variable
909 *                          returns value of variable
910 */
911{
912        /* executable code */
913
914        if  (idx >= 0 && idx < cGpI_last)  {
915                return gpv_i_glob[idx];
916        } else {
917                printf( "--globalparams: illegal index %d in GpGetInt\n", idx );
918                return 0;
919        } /*endif*/
920
921} /* end of GpGetInt */
922
923
924
925/*----------------------------------------------------------------------------*/
926
927
928
929float GpGetFloat( TGpFloatIndex idx )
930
931/* Returns float valued global
932 *
933 * parameters of routine
934 * TGpFloatIndex   idx;     input; index of variable
935 *                          returns value of variable
936 */
937{
938        /* executable code */
939
940        if  (idx >= 0 && idx < cGpF_last)  {
941                return gpv_f_glob[idx];
942        } else {
943                printf( "--globalparams: illegal index %d in GpGetFloat\n", idx );
944                return 0;
945        } /*endif*/
946
947} /* end of GpGetFloat */
948
949
950
951/*----------------------------------------------------------------------------*/
952
953
954
955char GpGetChar( TGpCharIndex idx )
956
957/* Returns char valued global
958 *
959 * parameters of routine
960 * TGpCharIndex   idx;      input; index of variable
961 *                          returns value of variable
962 */
963{
964        /* executable code */
965
966        if  (idx >= 0 && idx < cGpC_last)  {
967                return gpv_c_glob[idx];
968        } else {
969                printf( "globalparams: illegal index %d in GpGetChar\n", idx );
970                return 0;
971        } /*endif*/
972
973} /* end of GpGetChar */
974
975
976
977/*----------------------------------------------------------------------------*/
978
979
980
981char *GpGetString( TGpStringIndex idx )
982
983/* Returns pointer to string valued global
984 *
985 * parameters of routine
986 * TGpStringIndex   idx;    input; index of variable
987 *                          returns value of variable
988 */
989{
990        /* executable code */
991
992        if  (idx >= 0 && idx < cGpS_last)  {
993                return gpv_s_glob[idx];
994        } else {
995                printf( "--globalparams: illegal index %d in GpGetString\n", idx );
996                return 0;
997        } /*endif*/
998
999} /* end of GpGetString */
1000
1001
1002
1003/*----------------------------------------------------------------------------*/
1004
1005
1006
1007int GpGetBoolean( TGpBooleanIndex idx )
1008
1009/* Returns boolean valued global
1010 *
1011 * parameters of routine
1012 * TGpBooleanIndex   idx;   input; index of variable
1013 *                          returns value of variable
1014 */
1015{
1016        /* executable code */
1017
1018        if  (idx >= 0 && idx < cGpB_last)  {
1019                if  ((gpv_b_glob & (1 << idx)) == 0)  {
1020                        return 0;
1021                } else {
1022                        return 1;
1023                } /*endif*/
1024        } else {
1025                printf( "--globalparams: illegal index %d in GpGetBoolean\n", idx );
1026                return 0;
1027        } /*endif*/
1028
1029} /* end of GpGetBoolean */
1030
1031
1032
1033/*----------------------------------------------------------------------------*/
1034
1035
1036
1037char *GpGetStringElem( TGpStringListIndex idx, int elemnum )
1038
1039/* returns string element number elemnum from string list idx
1040 *
1041 * parameters of routine
1042 * TGpStringListIndex idx;     input; index numer of string list
1043 * int                elemnum; input; number of string in list (start with 0)
1044 *                             returns string address or NULL
1045 */
1046{
1047        /* local variables */
1048        TGpStringElem *sel;     /* pointer to string element */
1049
1050        /* executable code */
1051
1052        if  (idx < 0 || idx >= cGpL_last)  return NULL;
1053
1054        sel = gpv_l_glob+idx;
1055
1056        while  (elemnum-- > 0)  {
1057                if  (sel->next == NULL)  return NULL;
1058                sel = sel->next;
1059        } /*endwhile*/
1060
1061        return sel->string;
1062
1063} /* end of GpGetStringElem */
1064
1065
1066
1067/*----------------------------------------------------------------------------*/
1068
1069
1070
1071void GpSetInt( TGpIntIndex idx, int value )
1072
1073/* Sets integer valued global
1074 *
1075 * parameters of routine
1076 * TGpIntIndex   idx;       input; index of variable
1077 * int           value;     input; new value of variable
1078 */
1079{
1080        /* executable code */
1081
1082        if  (idx >= 0 && idx < cGpI_last)  {
1083                gpv_i_glob[idx] = value;
1084        } else {
1085                printf( "--globalparams: illegal index %d in GpSetInt\n", idx );
1086        } /*endif*/
1087
1088} /* end of GpSetInt */
1089
1090
1091
1092/*----------------------------------------------------------------------------*/
1093
1094
1095
1096void GpSetFloat( TGpFloatIndex idx, float value )
1097
1098/* Sets float valued global
1099 *
1100 * parameters of routine
1101 * TGpFloatIndex   idx;     input; index of variable
1102 * float           value;   input; new value of variable
1103 */
1104{
1105        /* executable code */
1106
1107        if  (idx >= 0 && idx < cGpF_last)  {
1108                gpv_f_glob[idx] = value;
1109        } else {
1110                printf( "--globalparams: illegal index %d in GpSetFloat\n", idx );
1111        } /*endif*/
1112
1113} /* end of GpSetFloat */
1114
1115
1116
1117/*----------------------------------------------------------------------------*/
1118
1119
1120
1121void GpSetChar( TGpCharIndex idx, char value )
1122
1123/* Sets char valued global
1124 *
1125 * parameters of routine
1126 * TGpCharIndex   idx;      input; index of variable
1127 * char           value;    input; new value of variable
1128 */
1129{
1130        /* executable code */
1131
1132        if  (idx >= 0 && idx < cGpC_last)  {
1133                gpv_c_glob[idx] = value;
1134        } else {
1135                printf( "--globalparams: illegal index %d in GpSetChar\n", idx );
1136        } /*endif*/
1137
1138} /* end of GpSetChar */
1139
1140
1141
1142/*----------------------------------------------------------------------------*/
1143
1144
1145
1146void GpSetString( TGpStringIndex idx, char str[], int *ok )
1147
1148/* Sets value of string valued global variable
1149 *
1150 * parameters of routine
1151 * TGpStringIndex   idx;    input; index of variable
1152 * char             str[];  input; new value of variable
1153 * int              *ok;    output (if not NULL); 1 = ok, 0 = failure
1154 */
1155{
1156        /* executable code */
1157
1158        if  (strlen(str) > cGp_TEXTVARLTH)  {
1159                if  (ok != NULL)  *ok = 0;
1160                return;
1161        } /*endif*/
1162
1163        if  (idx >= 0 && idx < cGpS_last)  {
1164                strcpy( gpv_s_glob[idx], str );
1165                if  (ok != NULL)  *ok = 1;
1166        } else {
1167                if  (ok != NULL)  *ok = 0;
1168        } /*endif*/
1169
1170} /* end of GpSetString */
1171
1172
1173
1174/*----------------------------------------------------------------------------*/
1175
1176
1177
1178void GpSetBoolean( TGpBooleanIndex idx, int value )
1179
1180/* Sets boolean valued global
1181 *
1182 * parameters of routine
1183 * TGpBooleanIndex   idx;   input; index of variable
1184 * int               value; input; new value of variable
1185 */
1186{
1187        /* executable code */
1188
1189        if  (idx >= 0 && idx < cGpB_last)  {
1190                if  (value)  {
1191                        gpv_b_glob |= (1 << idx);
1192                } else {
1193                        gpv_b_glob &= ~(1 << idx);
1194                } /*endif*/
1195        } else {
1196                printf( "--globalparams: illegal index %d in GpSetBoolean\n", idx );
1197        } /*endif*/
1198
1199} /* end of GpSetBoolean */
1200
1201
1202
1203/*----------------------------------------------------------------------------*/
1204
1205
1206
1207void GpReadParameter( char parname[], int maxlth, char value[], int *ok )
1208
1209/* Reads parameter of name parname from parameter file.
1210 *
1211 * parameters of routine
1212 * char       parname[]; input, name of parameter
1213 * int        maxlth; input; maximum length of output string
1214 * char       value[]; output; value of parameter
1215 * int        *ok; output; 1=ok, 0=not found or string too short
1216 */
1217{
1218        /* local variables */
1219        char     *env;                   /* pointer to environment */
1220        char     parfile[cBcFileLth+1];  /* name of parameter file */
1221        FILE     *fp;                    /* pointer to parameter file */
1222        char     line[cBcVeryLongStrLth+1];  /* current line of file */
1223        int      namelth;                /* length of parameter name */
1224        char     *vptr;                  /* pointer to parameter value */
1225        int      slth;                   /* string length */
1226
1227        /* executable code */
1228
1229        /* get parameter file */
1230        env = (char *)getenv( "SH_USER_PARAM" );
1231        if  (env == NULL)  {
1232                env = (char *)getenv( "SH_INPUTS" );
1233                if  (strlen(env) < cBcFileLth-15)  {
1234                        strcpy( parfile, env );
1235                        strcat( parfile, "/shm-config.txt" );
1236                } else {
1237                        fprintf( stderr, "configuration filename too long.  Abort.\n" );
1238                        exit( 1 );
1239                } /*endif*/
1240        } else {
1241                if  (strlen(env) < cBcFileLth)  {
1242                        strcpy( parfile, env );
1243                } else {
1244                        fprintf( stderr, "environment SH_USER_PARAM too long.  Abort.\n" );
1245                        exit( 1 );
1246                } /*endif*/
1247        } /*endif*/
1248
1249        namelth = strlen( parname );
1250
1251        *ok = 0;
1252        fp = fopen( parfile, "r" );
1253        if  (fp == NULL)  return;
1254
1255        while  (fgets(line,cBcVeryLongStrLth,fp) != NULL)  {
1256
1257                if  (*line == '!' || *line == '#' || *line == '\n')  continue;
1258                if  (strncasecmp(line,parname,namelth) == 0
1259                        && (line[namelth] == ' ' || line[namelth] == '\t'))  {
1260                        vptr = line + namelth;
1261                        while  (*vptr == ' ')  vptr++;
1262                        slth = strlen( vptr );
1263                        if  (vptr[slth-1] == '\n')  vptr[--slth] = '\0';
1264                        *ok = (strlen(vptr) < maxlth);
1265                        if  (*ok)  strcpy( value, vptr );
1266                        break;
1267                } /*endif*/
1268
1269        } /*endwhile*/
1270
1271        fclose( fp );
1272
1273} /* end of GpReadParameter */
1274
1275
1276
1277/*----------------------------------------------------------------------------*/
1278
1279
1280
1281void GpParseTextList( char str[], TGpTextList *tl )
1282
1283/* Parses comma separated text string and returns pointers to elements of list.
1284 * Data structure returned must be freed after use (GpFreeTextList).
1285 *
1286 * parameters of routine
1287 * char       str[];    input; input string to be parsed
1288 * GpTextList *tl;      output; elements of list
1289 */
1290{
1291        /* local variables */
1292        int      strlth;       /* length of input string */
1293        int      i, j;         /* counters */
1294
1295        /* executable code */
1296
1297        strlth = strlen( str );
1298        if  (strlth == 0)  {
1299                tl->numelem = 0;
1300                tl->elem = NULL;
1301                tl->mem = NULL;
1302                return;
1303        } /*endif*/
1304
1305        tl->mem = (char *)malloc( strlth+1 );
1306        if  (tl->mem == NULL)  {
1307                fprintf( stderr, "GpParseTextList: error allocating memory.  Abort.\n" );
1308                exit( 1 );
1309        } /*endif*/
1310        strcpy( tl->mem, str );
1311
1312        /* count elements */
1313        tl->numelem = (*str == '\0') ? 0 : 1;
1314        for  (i=0; i<strlth; i++)
1315                if  (str[i] == ',')  (tl->numelem)++;
1316
1317        tl->elem = (char **)malloc( (int)sizeof(char *)*(tl->numelem) );
1318        if  (tl->elem == NULL)  {
1319                fprintf( stderr, "GpParseTextList: error allocating memory.  Abort.\n" );
1320                exit( 1 );
1321        } /*endif*/
1322
1323        j = 1;
1324        tl->elem[0] = tl->mem;
1325        for  (i=0; i<strlth; i++)  {
1326                if  (tl->mem[i] == ',')  {
1327                        tl->mem[i] = '\0';
1328                        tl->elem[j++] = tl->mem+i+1;
1329                } /*endif*/
1330        } /*endfor*/
1331
1332        /* debug output */
1333        /*
1334        for  (j=0; j<tl->numelem; j++)
1335                printf( "debug-textlist: %2d >%s<\n", j+1, tl->elem[j] );
1336        */
1337
1338} /* end of GpParseTextList */
1339
1340
1341
1342/*----------------------------------------------------------------------------*/
1343
1344
1345
1346void GpFreeTextList( TGpTextList *tl )
1347
1348/* Frees memory of textlist
1349 *
1350 * parameters of routine
1351 * TGpTextList         modify; text list to be freed
1352 */
1353{
1354        /* executable code */
1355
1356        if  (tl->numelem == 0)  return;
1357
1358        if  (tl->elem != NULL)  free( tl->elem );
1359        if  (tl->mem != NULL)  free( tl->mem );
1360
1361} /* end of GpFreeTextList */
1362
1363
1364
1365/*----------------------------------------------------------------------------*/
1366
1367
1368
1369void GpDumpParams( void )
1370
1371/* write all parameters out to stdout
1372 *
1373 * no parameters passed
1374 *
1375 */
1376{
1377        /* local variables */
1378        int    i;    /* counter */
1379        int    j;    /* string counter */
1380        char   *s;   /* string pointer */
1381
1382        /* executable code */
1383
1384        for  (i=0; i<cGpI_last; i++)
1385                printf( "%s: %d\n", gpv_i_name[i], gpv_i_glob[i] );
1386        for  (i=0; i<cGpF_last; i++)
1387                printf( "%s: %g\n", gpv_f_name[i], gpv_f_glob[i] );
1388        for  (i=0; i<cGpC_last; i++)
1389                printf( "%s: %c\n", gpv_c_name[i], gpv_c_glob[i] );
1390        for  (i=0; i<cGpS_last; i++)
1391                printf( "%s: %s\n", gpv_s_name[i], gpv_s_glob[i] );
1392        for  (i=0; i<cGpB_last; i++)
1393                printf( "%s: %d\n", gpv_b_name[i], ((1<<i) & gpv_b_glob) );
1394        for  (i=0; i<cGpL_last; i++)  {
1395                for  (j=0;;j++)  {
1396                        s = GpGetStringElem( i, j );
1397                        if  (s == NULL)  break;
1398                        printf( "%s (%d): %s\n", gpv_l_name[i], j, s );
1399                } /*endfor*/
1400        } /*endfor*/
1401
1402} /* end of GpDumpParams */
1403
1404
1405
1406/*----------------------------------------------------------------------------*/
1407
1408
1409
1410void GpParseStringList( TGpStringListIndex idx, char line[] )
1411
1412/* parses string list and puts result to list number idx
1413 *
1414 * parameters of routine
1415 * TGpStringListIndex idx;    input; string list variable index
1416 * char               line[]; input; line to be parsed
1417 */
1418{
1419        /* local variables */
1420        int      i, j;                /* counters */
1421        TGpStringElem *sel;           /* pointer to string element */
1422        char     val[cBcLineLth+1];   /* string value */
1423
1424        /* excutable code */
1425
1426        sel = gpv_l_glob+idx;
1427
1428        /* !!! should free list before (if not "default") */
1429
1430        sel->next = NULL;
1431        sel->string = '\0';
1432        sel->strlth = 0;
1433
1434        while  (*line != '\0')  {
1435
1436                /* skip blanks */
1437                while  (*line == ' ' || *line == '\t')  line++;
1438                if  (*line == '\0' || *line == '\n')  break;
1439
1440                /* allocate next StringElem if necessary */
1441                if  (sel->string != '\0')  {
1442                        sel->next = (TGpStringElem *)malloc( (int)sizeof(TGpStringElem) );
1443                        if  (sel->next == NULL)  {
1444                                printf( "--globalparams: error allocating memory (1). Abort\n" );
1445                                exit( 1 );
1446                        } /*endif*/
1447                        sel = sel->next;
1448                        sel->next = NULL;
1449                        sel->string = '\0';
1450                        sel->strlth = 0;
1451                } /*endif*/
1452
1453                /* get next string length */
1454                i = 0;
1455                while  (line[i] != '\0' && line[i] != ' ' && line[i] != '\n'
1456                        && line[i] != '\t' && line[i] != ',' && line[i] != ';')
1457                        i++;
1458                if  (i >= cBcLineLth-1)  {
1459                        printf( "--globalparams: string element (idx: %d) too long\n", idx );
1460                        return;
1461                } /*endif*/
1462
1463                /* copy string to StringElem structure */
1464                if  (i > 0)  {
1465
1466                        /* copy string and translate if necessary */
1467                        strncpy( val, line, i );
1468                        val[i] = '\0';
1469
1470                        while  (*val == '$')
1471                                GpEvaluateVar( val );
1472
1473                        j = strlen( val );
1474                        sel->string = (char *)malloc( (int)sizeof(char)*(j+1) );
1475                        if  (sel->string == NULL)  {
1476                                printf( "--globalparams: error allocating memory (2). Abort\n" );
1477                                exit( 1 );
1478                        } /*endif*/
1479                        strcpy( sel->string, val );
1480                        sel->strlth = j;
1481
1482                } /*endif*/
1483
1484                if  (line[i] == '\0' || *line == '\n')  break;
1485                line += i+1;
1486
1487        } /*endwhile*/
1488
1489} /* end of GpParseStringList */
1490
1491
1492
1493/*----------------------------------------------------------------------------*/
1494
1495
1496
1497static void GpEvaluateVar( char val[] )
1498
1499/* Evaluates value of variable
1500 *
1501 * parameters of routine
1502 * char       val[];     modify; input: variable name, output: value
1503 */
1504{
1505        /* local variable */
1506        char     vname[cBcLineLth+1];     /* variable name */
1507        char     appdx[cBcLineLth+1];     /* appendix (after '/') */
1508        int      j;                       /* counter */
1509        int      ok;                      /* string value found */
1510        char     *env;                    /* pointer to environment */
1511
1512        /* executable code */
1513
1514        if  (*val != '$')  return;  /* leave unchanged */
1515
1516        /* try 'v$'-variable in configuration file */
1517        vname[0] = 'v';
1518        j = 0;
1519        while  (val[j] != '/' && val[j] != '\0')  {
1520                vname[j+1] = val[j];
1521                j++;
1522        } /*endwhile*/
1523        vname[j+1] = '\0';
1524        *appdx = '\0';
1525        if  (val[j] == '/')  strcpy( appdx, val+j );
1526        GpReadParameter( vname, cBcLineLth, val, &ok );
1527
1528        if  (!ok)  {
1529                /* try to find environment variable */
1530                env = (char *)getenv( vname+2 );  /* skip v$ */
1531                if  (env == NULL)  {
1532                        strcpy( val, vname+2 );  /* take away '$', results in an error later */
1533                } else if  (strlen(env) < cBcLineLth)  {
1534                        strcpy( val, env );
1535                } else {
1536                        strcpy( val, vname+2 );  /* results in an error later */
1537                } /*endif*/
1538        } /*endif*/
1539
1540        if  (*appdx != '\0')
1541                if  (strlen(val)+strlen(appdx) < cBcLineLth)
1542                        strcat( val, appdx );
1543
1544} /* end of GpEvaluateVar */
1545
1546
1547
1548/*----------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.