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

Revision 68, 42.4 KB checked in by marcus, 15 years ago (diff)

r53 | svn | 2008-10-21 09:13:49 +0200 (Di, 21 Okt 2008) | 1 line

implemented special channels (++) with translation tables

Line 
1
2/* file globalparams.c
3 *      ==============
4 *
5 * $Revision: 53 $, $Date: 2008-10-21 09:13:49 +0200 (Di, 21 Okt 2008) $
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        "b_last_parameter"
406};
407
408static long gpv_b_glob =
409        (1 << cGpB_autopick_first)         |
410        (1 << cGpB_auto_scaling)           |
411        (1 << cGpB_overwrite_string_lists) |
412        (1 << cGpB_own_accelerators)       |
413        (1 << cGpB_autosort_by_distance)   |
414        (1 << cGpB_autofilter_by_distance) |
415        (1 << cGpB_reads_swap)
416;
417
418
419/* string list variables
420 * ---------------------
421 */
422
423static char *gpv_l_name[] = {
424        "station_info_file",
425        "filter_lookup_table",
426        "sensitivity_file",
427        "channel_translation",
428        "defpath_filter",
429        "defpath_command",
430        "defpath_globals",
431        "l_last_parameter"
432};
433
434static TGpStringElem gpv_l_glob[cGpL_last+1] = {
435        {NULL,"default",7},            /* station_info_file */
436        {NULL,"default",7},            /* filter_lookup_table */
437        {NULL,"default",7},            /* sensitivity_file */
438        {NULL,"default",7},            /* channel_translation */
439        {NULL,"default",7},            /* defpath_filter */
440        {NULL,"default",7},            /* defpath_command */
441        {NULL,"default",7},            /* defpath_globals */
442        {NULL,"",0}                    /* last parameter */
443};
444
445
446/* prototypes of local routines */
447static void GpReadParametersFromFile( char fname[] );
448static void GpEvaluateVar( char val[] );
449
450
451/*----------------------------------------------------------------------------*/
452
453
454
455void GpReadParfile( void )
456
457/* Reads parameters from file
458 *
459 * no parameters passed
460 */
461{
462        /* local variables */
463        char     *env;               /* pointer to environment */
464        char     parfile[cBcFileLth+1]; /* name of parameter file */
465        char     *cptr;              /* char pointer */
466        int      i;                  /* counter */
467
468        /* executable code */
469
470        /* get parameter file */
471        env = (char *)getenv( "SH_USER_PARAM" );
472        if  (env == NULL)  {
473                env = (char *)getenv( "SH_INPUTS" );
474                if  (strlen(env) < cBcFileLth-15)  {
475                        strcpy( parfile, env );
476                        strcat( parfile, "/shm-config.txt" );
477                } else {
478                        fprintf( stderr, "configuration filename too long.  Abort.\n" );
479                        exit( 1 );
480                } /*endif*/
481        } else {
482                if  (strlen(env) < cBcFileLth)  {
483                        strcpy( parfile, env );
484                } else {
485                        fprintf( stderr, "environment SH_USER_PARAM too long.  Abort.\n" );
486                        exit( 1 );
487                } /*endif*/
488        } /*endif*/
489
490        GpReadParametersFromFile( parfile );
491
492        /* set 'default' strings */
493        if  (strcmp(gpv_s_glob[cGpS_defpath_events],"default") == 0)  {
494                cptr = (char *)getenv( "HOME" );
495                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
496                if  (strlen(cptr) < cGp_TEXTVARLTH)
497                        strcpy( gpv_s_glob[cGpS_defpath_events], cptr );
498        } /*endif*/
499        if  (strcmp(gpv_s_glob[cGpS_defpath_gse],"default") == 0)  {
500                cptr = (char *)getenv( "SH_ROOT" );
501                if  (cptr == NULL)  {printf("SH_ROOT not defined\n"); exit(1);}
502                if  (strlen(cptr) < cGp_TEXTVARLTH-21)  {
503                        strcpy( gpv_s_glob[cGpS_defpath_gse], cptr );
504                        strcat( gpv_s_glob[cGpS_defpath_gse], "/data-examples/gse" );
505                } /*endif*/
506        } /*endif*/
507        if  (strcmp(gpv_s_glob[cGpS_defpath_ah],"default") == 0)  {
508                cptr = (char *)getenv( "HOME" );
509                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
510                if  (strlen(cptr) < cGp_TEXTVARLTH)
511                        strcpy( gpv_s_glob[cGpS_defpath_ah], cptr );
512        } /*endif*/
513        if  (strcmp(gpv_s_glob[cGpS_defpath_q],"default") == 0)  {
514                cptr = (char *)getenv( "HOME" );
515                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
516                if  (strlen(cptr) < cGp_TEXTVARLTH)
517                        strcpy( gpv_s_glob[cGpS_defpath_q], cptr );
518        } /*endif*/
519        if  (strcmp(gpv_s_glob[cGpS_defpath_evid],"default") == 0)  {
520                cptr = (char *)getenv( "SH_PRIVATE" );
521                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
522                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
523                if  (strlen(cptr) < cGp_TEXTVARLTH-6)  {
524                        strcpy( gpv_s_glob[cGpS_defpath_evid], cptr );
525                        strcat( gpv_s_glob[cGpS_defpath_evid], "/evid/" );
526                } /*endif*/
527        } /*endif*/
528        if  (strcmp(gpv_s_glob[cGpS_defpath_evtout],"default") == 0)  {
529                cptr = (char *)getenv( "SH_PRIVATE" );
530                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
531                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
532                if  (strlen(cptr) < cGp_TEXTVARLTH-8)  {
533                        strcpy( gpv_s_glob[cGpS_defpath_evtout], cptr );
534                        strcat( gpv_s_glob[cGpS_defpath_evtout], "/evtout/" );
535                } /*endif*/
536        } /*endif*/
537        if  (strcmp(gpv_s_glob[cGpS_defpath_help],"default") == 0)  {
538                cptr = (char *)getenv( "SH_ROOT" );
539                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
540                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
541                if  (strlen(cptr) < cGp_TEXTVARLTH-6)  {
542                        strcpy( gpv_s_glob[cGpS_defpath_help], cptr );
543                        strcat( gpv_s_glob[cGpS_defpath_help], "/help/" );
544                } /*endif*/
545        } /*endif*/
546        if  (strcmp(gpv_s_glob[cGpS_defpath_errors],"default") == 0)  {
547                cptr = (char *)getenv( "SH_ROOT" );
548                if  (cptr == NULL)  cptr = (char *)getenv( "HOME" );
549                if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
550                if  (strlen(cptr) < cGp_TEXTVARLTH-8)  {
551                        strcpy( gpv_s_glob[cGpS_defpath_errors], cptr );
552                        strcat( gpv_s_glob[cGpS_defpath_errors], "/errors/" );
553                } /*endif*/
554        } /*endif*/
555        if  (strcmp(gpv_s_glob[cGpS_defpath_userdir],"default") == 0)  {
556                /* the usage of SH_USERDIR is for backward compatibility */
557                cptr = (char *)getenv( "SH_USERDIR" );
558                if  (cptr == NULL)  {
559                        cptr = (char *)getenv( "HOME" );
560                        if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
561                        if  (strlen(cptr) < cGp_TEXTVARLTH-17)  {
562                                strcpy( gpv_s_glob[cGpS_defpath_userdir], cptr );
563                                strcat( gpv_s_glob[cGpS_defpath_userdir], "/shfiles/private/" );
564                        } /*endif*/
565                } else {
566                        if  (strlen(cptr) < cGp_TEXTVARLTH)
567                                strcpy( gpv_s_glob[cGpS_defpath_userdir], cptr );
568                } /*endif*/
569        } /*endif*/
570        if  (strcmp(gpv_s_glob[cGpS_defpath_extprog],"default") == 0)  {
571                /* the usage of SH_UTIL is for backward compatibility */
572                cptr = (char *)getenv( "SH_UTIL" );
573                if  (cptr == NULL)  {
574                        cptr = (char *)getenv( "HOME" );
575                        if  (cptr == NULL)  {printf("HOME not defined\n"); exit(1);}
576                        if  (strlen(cptr) < cGp_TEXTVARLTH-17)  {
577                                strcpy( gpv_s_glob[cGpS_defpath_extprog], cptr );
578                                strcat( gpv_s_glob[cGpS_defpath_extprog], "/util/" );
579                        } /*endif*/
580                } else {
581                        if  (strlen(cptr) < cGp_TEXTVARLTH)
582                                strcpy( gpv_s_glob[cGpS_defpath_extprog], cptr );
583                } /*endif*/
584        } /*endif*/
585
586        /* 'default' in string lists */
587        if  (strcmp(gpv_l_glob[cGpL_station_info_file].string,"default") == 0)  {
588                cptr = (char *)getenv( "SH_INPUTS" );
589                if  (cptr != NULL)  {
590                        i = strlen( cptr );
591                        /* "default" value is set by variable initialisation, can't free it */
592                        /*free( gpv_l_glob[cGpL_station_info_file].string );*/
593                        gpv_l_glob[cGpL_station_info_file].string =
594                                (char *)malloc( (int)sizeof(char)*(i+12) );
595                        strcpy( gpv_l_glob[cGpL_station_info_file].string, cptr );
596                        strcat( gpv_l_glob[cGpL_station_info_file].string, "STATINF.DAT" );
597                        gpv_l_glob[cGpL_station_info_file].strlth = i+11;
598                } /*endif*/
599        } /*endif*/
600        if  (strcmp(gpv_l_glob[cGpL_filter_lookup_table].string,"default") == 0)  {
601                cptr = (char *)getenv( "SH_INPUTS" );
602                if  (cptr != NULL)  {
603                        i = strlen( cptr );
604                        /*free( gpv_l_glob[cGpL_filter_lookup_table].string );*/
605                        gpv_l_glob[cGpL_filter_lookup_table].string =
606                                (char *)malloc( (int)sizeof(char)*(i+18) );
607                        strcpy( gpv_l_glob[cGpL_filter_lookup_table].string, cptr );
608                        strcat( gpv_l_glob[cGpL_filter_lookup_table].string, "filter_lookup.txt" );
609                        gpv_l_glob[cGpL_filter_lookup_table].strlth = i+17;
610                } /*endif*/
611        } /*endif*/
612        if  (strcmp(gpv_l_glob[cGpL_sensitivity_file].string,"default") == 0)  {
613                cptr = (char *)getenv( "SH_INPUTS" );
614                if  (cptr != NULL)  {
615                        i = strlen( cptr );
616                        /*free( gpv_l_glob[cGpL_sensitivity_file].string );*/
617                        gpv_l_glob[cGpL_sensitivity_file].string =
618                                (char *)malloc( (int)sizeof(char)*(i+18) );
619                        strcpy( gpv_l_glob[cGpL_sensitivity_file].string, cptr );
620                        strcat( gpv_l_glob[cGpL_sensitivity_file].string, "sensitivities.txt" );
621                        gpv_l_glob[cGpL_sensitivity_file].strlth = i+17;
622                } /*endif*/
623        } /*endif*/
624        if  (strcmp(gpv_l_glob[cGpL_channel_translation].string,"default") == 0)  {
625                cptr = (char *)getenv( "SH_INPUTS" );
626                if  (cptr != NULL)  {
627                        i = strlen( cptr );
628                        /*free( gpv_l_glob[cGpL_channel_translation].string );*/
629                        gpv_l_glob[cGpL_channel_translation].string =
630                                (char *)malloc( (int)sizeof(char)*(i+14) );
631                        strcpy( gpv_l_glob[cGpL_channel_translation].string, cptr );
632                        strcat( gpv_l_glob[cGpL_channel_translation].string, "chantrans.txt" );
633                        gpv_l_glob[cGpL_channel_translation].strlth = i+13;
634                } /*endif*/
635        } /*endif*/
636        if  (strcmp(gpv_l_glob[cGpL_defpath_filter].string,"default") == 0)
637                GpParseStringList( cGpL_defpath_filter, ".,$SH_ROOT/filter" );
638        if  (strcmp(gpv_l_glob[cGpL_defpath_command].string,"default") == 0)
639                GpParseStringList( cGpL_defpath_command, ".,$SH_ROOT/command" );
640        if  (strcmp(gpv_l_glob[cGpL_defpath_globals].string,"default") == 0)
641                GpParseStringList( cGpL_defpath_globals, ".,$SH_ROOT/globals/" );
642
643        /* make some strings uppercase */
644        ut_cap( gpv_s_glob[cGpS_refstation] );
645        ut_cap( gpv_s_glob[cGpS_list_of_refstations] );
646
647        /* check for setting of normalisation */
648        if  (gpv_i_glob[cGpI_trace_normalisation] == cGp_NORM_UNDEF)  {
649                /* trace_normalisation not set take it from 'old' auto_scaling */
650                printf( "--globalparams: warning: auto_scaling obsolete, please set trace_normalisation\n" );
651                gpv_i_glob[cGpI_trace_normalisation] =
652                        (gpv_b_glob & cGpB_auto_scaling) ? cGp_NORM_SW : cGp_NORM_AW;
653        } else {
654                switch  (gpv_i_glob[cGpI_trace_normalisation])  {
655                case cGp_NORM_CONST:  GpSetBoolean( cGpB_auto_scaling, 0 ); break;
656                case cGp_NORM_AW:     GpSetBoolean( cGpB_auto_scaling, 0 ); break;
657                case cGp_NORM_SW:     GpSetBoolean( cGpB_auto_scaling, 1 ); break;
658                default:
659                        printf( "--globalparams: illegal value of trace_normalisation, please correct\n" );
660                        GpSetBoolean( cGpB_auto_scaling, 0 );
661                        gpv_i_glob[cGpI_trace_normalisation] = cGp_NORM_AW;
662                } /*endswitch*/
663        } /*endif*/
664
665        if  (gpv_i_glob[cGpI_parfile_version] == 0)
666                printf( "--globalparams: warning: no version of parameter file found\n" );
667
668} /* end of GpReadParfile */
669
670
671
672/*----------------------------------------------------------------------------*/
673
674
675
676static void GpReadParametersFromFile( char fname[] )
677
678/* reads parametes from file, calls itself on 'include' statement
679 *
680 * parameters of routine
681 * char       fname[];    input; name of file to read
682 */
683{
684        /* local variables */
685        FILE     *fp;                /* pointer to input file */
686        char     line[cBcVeryLongStrLth+1]; /* current line of file */
687        char     name[cBcLineLth+1]; /* variable name */
688        int      namelth;            /* length of name */
689        int      itmp;               /* integer scratch */
690        float    ftmp;               /* float scratch */
691        char     ctmp;               /* char scratch */
692        char     stmp[cBcVeryLongStrLth+1]; /* string scratch */
693        TGpIntIndex  icnt;           /* integer counter */
694        TGpFloatIndex  fcnt;         /* float counter */
695        TGpCharIndex  ccnt;          /* char counter */
696        TGpStringIndex  scnt;        /* string counter */
697        TGpBooleanIndex  bcnt;       /* boolean counter */
698        TGpStringListIndex lcnt;     /* string list counter */
699        int      found;              /* (boolean) parameter found */
700        char     *cptr;              /* char pointer */
701        char     *env;               /* pointer to environment */
702
703        /* executable code */
704
705        if  (GpGetInt(cGpI_debug_level) > 3)
706                printf( "SHM-dbg3: reading parameters from parfile %s\n", fname );
707
708        fp = fopen( fname, "r" );
709        if  (fp == NULL)  {
710                if  (GpGetInt(cGpI_debug_level) > 2)
711                        printf( "SHM-dbg3: parfile %s not found\n", fname );
712                return;
713        } /*endif*/
714
715        while  (fgets(line,cBcVeryLongStrLth,fp) != NULL)  {
716
717                if  (*line == '!' || *line == '#' || *line == '\n')  continue;
718                if  (line[1] == '$')  continue;
719                if  (sscanf(line,"%s",name) != 1)  continue;
720                namelth = strlen( name );
721                if  (strlen(line) < namelth)  {
722                        printf( "--globalparams: empty entry %s, ignore\n", name );
723                        continue;
724                } /*endif*/
725                found = 0;
726
727                /* check for include statement */
728                if  (strcmp(name,"include") == 0)  {
729                        if  (GpGetInt(cGpI_debug_level) > 3)
730                                printf( "SHM-dbg4: include statement found\n", fname );
731                        if  (sscanf(line+namelth,"%s",stmp) != 1)  {
732                                printf( "--globalparams: error reading include in parameter file %s\n",
733                                        fname );
734                        } else {
735                                if  (strlen(stmp) > cGp_TEXTVARLTH)  {
736                                        printf( "--globalparams: include filename %s too long\n", name );
737                                } else {
738                                        /* reentrant call, read from $SH_INPUTS if not absolute */
739                                        if  (*stmp == '/')  {
740                                                /* absolute name, dont't change */
741                                                strcpy( line, stmp );
742                                        } else {
743                                                env = (char *)getenv( "SH_INPUTS" );
744                                                if  (strlen(env)+strlen(stmp)+1 > cBcVeryLongStrLth)  {
745                                                        printf( "--globalparams: string overflow in include statement\n" );
746                                                        continue;
747                                                } /*endif*/
748                                                sprintf( line, "%s/%s", env, stmp );
749                                        } /*endif*/
750                                        GpReadParametersFromFile( line );
751                                } /*endif*/
752                        } /*endif*/
753                        continue;
754                } /*endif*/
755
756                /* check for version number */
757                if  (strcmp(name,"file_version") == 0)  {
758                        if  (sscanf(line+namelth,"%s",stmp) != 1)  {
759                                printf( "--globalparams: error reading version in parameter file %s\n",
760                                        fname );
761                        } else {
762                                if  (strlen(stmp) > cGp_TEXTVARLTH)  {
763                                        printf( "--globalparams: include filename %s too long\n", name );
764                                } else {
765                                        if  (sscanf(stmp,"%d.%d",&itmp,&icnt) == 2)  {
766                                                gpv_i_glob[cGpI_parfile_version] = itmp;
767                                                gpv_i_glob[cGpI_parfile_subversion] = icnt;
768                                                if  (gpv_i_glob[cGpI_parfile_version] > cGp_VERSION
769                                                        || gpv_i_glob[cGpI_parfile_subversion] > cGp_SUBVERSION)  {
770                                                        printf( "--globalparams: warning: file version too new; ");
771                                                        printf( "expect problems while reading\n" );
772                                                        printf( "--globalparams: version %d.%d is expected here\n",
773                                                                cGp_VERSION, cGp_SUBVERSION );
774                                                } else if (gpv_i_glob[cGpI_parfile_version] < cGp_VERSION) {
775                                                        printf( "--globalparams: warning: old parameter file version; ");
776                                                        printf( "consider creating a new one\n" );
777                                                        printf( "--globalparams: version %d.%d is expected here\n",
778                                                                cGp_VERSION, cGp_SUBVERSION );
779                                                } /*endif*/
780                                        } else {
781                                                printf( "--globalparams: error reading parameter version\n" );
782                                        } /*endif*/
783                                } /*endif*/
784                        } /*endif*/
785                        continue;
786                } /*endif*/
787
788                /* integer variables */
789                for  (icnt=0; icnt<cGpI_last; icnt++)
790                        if  (strcmp(gpv_i_name[icnt],name) == 0)  {
791                                if  (sscanf(line+namelth,"%d",&itmp) != 1)  {
792                                        printf( "--globalparams: error reading parameter %s\n", name );
793                                } else {
794                                        gpv_i_glob[icnt] = itmp;
795                                        found = 1;
796                                } /*endif*/
797                                break;
798                        } /*endif*/
799                if  (found)  continue;
800
801                /* float variables */
802                for  (fcnt=0; fcnt<cGpF_last; fcnt++)
803                        if  (strcmp(gpv_f_name[fcnt],name) == 0)  {
804                                if  (sscanf(line+namelth,"%f",&ftmp) != 1)  {
805                                        printf( "--globalparams: error reading parameter %s\n", name );
806                                } else {
807                                        gpv_f_glob[fcnt] = ftmp;
808                                        found = 1;
809                                } /*endif*/
810                                break;
811                        } /*endif*/
812                if  (found)  continue;
813
814                /* char variables */
815                for  (ccnt=0; ccnt<cGpC_last; ccnt++)
816                        if  (strcmp(gpv_c_name[ccnt],name) == 0)  {
817                                /* read first character after blanks and tabs */
818                                cptr = line + namelth;
819                                while  (*cptr == ' ' || *cptr == '\t')  cptr++;
820                                if  (*cptr != '\n' && *cptr != '\0')  {
821                                        gpv_c_glob[ccnt] = *cptr;
822                                        found = 1;
823                                } /*endif*/
824                                break;
825                        } /*endif*/
826                if  (found)  continue;
827
828                /* string variables */
829                for  (scnt=0; scnt<cGpS_last; scnt++)
830                        if  (strcmp(gpv_s_name[scnt],name) == 0)  {
831                                /* skip blanks after keyword and take remaining line as value */
832                                cptr = line + namelth;
833                                while  (*cptr == ' ' || *cptr == '\t')  cptr++;
834                                strcpy( stmp, cptr );
835                                /* drop the linefeed */
836                                itmp = strlen( stmp );
837                                if  (itmp > 0 && stmp[itmp-1] == '\n')  stmp[itmp-1] = '\0';
838                                if  (*stmp == '\0')  {
839                                        printf( "--globalparams: error reading parameter %s\n", name );
840                                } else {
841                                        if  (strlen(stmp) > cGp_TEXTVARLTH)  {
842                                                printf( "--globalparams: string parameter %s too long\n", name );
843                                        } else {
844                                                if  (strcmp(stmp,"<NULL>") == 0 || strcmp(stmp,"NULL") == 0
845                                                        || strcmp(stmp,"<null>") == 0 || strcmp(stmp,"null") == 0)  {
846                                                        gpv_s_glob[scnt][0] = '\0';
847                                                } else {
848                                                        while  (stmp[0] == '$')
849                                                                GpEvaluateVar( stmp );
850                                                        strcpy( gpv_s_glob[scnt], stmp );
851                                                } /*endif*/
852                                                found = 1;
853                                        } /*endif*/
854                                } /*endif*/
855                                break;
856                        } /*endif*/
857
858                /* boolean variables */
859                for  (bcnt=0; bcnt<cGpB_last; bcnt++)
860                        if  (strcmp(gpv_b_name[bcnt],name) == 0)  {
861                                if  (sscanf(line+namelth,"%s",&stmp) != 1)  {
862                                        printf( "--globalparams: error reading parameter %s\n", name );
863                                } else {
864                                        if  (strcmp(stmp,"TRUE") == 0 || strcmp(stmp,"true") == 0
865                                                || strcmp(stmp,"True") == 0 || strcmp(stmp,"1") == 0)  {
866                                                gpv_b_glob |= (1 << bcnt);
867                                                found = 1;
868                                        } else if  (strcmp(stmp,"FALSE") == 0 || strcmp(stmp,"false") == 0
869                                                || strcmp(stmp,"False") == 0 || strcmp(stmp,"0") == 0)  {
870                                                gpv_b_glob &= ~(1 << bcnt);
871                                                found = 1;
872                                        } else {
873                                                printf( "--globalparams: illegal boolean value at %s\n", name );
874                                        } /*endif*/
875                                } /*endif*/
876                                break;
877                        } /*endif*/
878                if  (found)  continue;
879
880                /* string list variables */
881                for  (lcnt=0; lcnt<cGpL_last; lcnt++)
882                        if  (strcmp(gpv_l_name[lcnt],name) == 0)  {
883                                GpParseStringList( lcnt, line+namelth );
884                                found = 1;
885                        } /*endif*/
886
887                if  (!found)
888                        printf( "--globalparams: illegal parameter %s in parameter file\n", name );
889
890        } /*endwhile*/
891
892        fclose( fp );
893
894} /* end of GpReadParametersFromFile */
895
896
897
898/*----------------------------------------------------------------------------*/
899
900
901
902int GpGetInt( TGpIntIndex idx )
903
904/* Returns integer valued global
905 *
906 * parameters of routine
907 * TGpIntIndex   idx;       input; index of variable
908 *                          returns value of variable
909 */
910{
911        /* executable code */
912
913        if  (idx >= 0 && idx < cGpI_last)  {
914                return gpv_i_glob[idx];
915        } else {
916                printf( "--globalparams: illegal index %d in GpGetInt\n", idx );
917                return 0;
918        } /*endif*/
919
920} /* end of GpGetInt */
921
922
923
924/*----------------------------------------------------------------------------*/
925
926
927
928float GpGetFloat( TGpFloatIndex idx )
929
930/* Returns float valued global
931 *
932 * parameters of routine
933 * TGpFloatIndex   idx;     input; index of variable
934 *                          returns value of variable
935 */
936{
937        /* executable code */
938
939        if  (idx >= 0 && idx < cGpF_last)  {
940                return gpv_f_glob[idx];
941        } else {
942                printf( "--globalparams: illegal index %d in GpGetFloat\n", idx );
943                return 0;
944        } /*endif*/
945
946} /* end of GpGetFloat */
947
948
949
950/*----------------------------------------------------------------------------*/
951
952
953
954char GpGetChar( TGpCharIndex idx )
955
956/* Returns char valued global
957 *
958 * parameters of routine
959 * TGpCharIndex   idx;      input; index of variable
960 *                          returns value of variable
961 */
962{
963        /* executable code */
964
965        if  (idx >= 0 && idx < cGpC_last)  {
966                return gpv_c_glob[idx];
967        } else {
968                printf( "globalparams: illegal index %d in GpGetChar\n", idx );
969                return 0;
970        } /*endif*/
971
972} /* end of GpGetChar */
973
974
975
976/*----------------------------------------------------------------------------*/
977
978
979
980char *GpGetString( TGpStringIndex idx )
981
982/* Returns pointer to string valued global
983 *
984 * parameters of routine
985 * TGpStringIndex   idx;    input; index of variable
986 *                          returns value of variable
987 */
988{
989        /* executable code */
990
991        if  (idx >= 0 && idx < cGpS_last)  {
992                return gpv_s_glob[idx];
993        } else {
994                printf( "--globalparams: illegal index %d in GpGetString\n", idx );
995                return 0;
996        } /*endif*/
997
998} /* end of GpGetString */
999
1000
1001
1002/*----------------------------------------------------------------------------*/
1003
1004
1005
1006int GpGetBoolean( TGpBooleanIndex idx )
1007
1008/* Returns boolean valued global
1009 *
1010 * parameters of routine
1011 * TGpBooleanIndex   idx;   input; index of variable
1012 *                          returns value of variable
1013 */
1014{
1015        /* executable code */
1016
1017        if  (idx >= 0 && idx < cGpB_last)  {
1018                if  ((gpv_b_glob & (1 << idx)) == 0)  {
1019                        return 0;
1020                } else {
1021                        return 1;
1022                } /*endif*/
1023        } else {
1024                printf( "--globalparams: illegal index %d in GpGetBoolean\n", idx );
1025                return 0;
1026        } /*endif*/
1027
1028} /* end of GpGetBoolean */
1029
1030
1031
1032/*----------------------------------------------------------------------------*/
1033
1034
1035
1036char *GpGetStringElem( TGpStringListIndex idx, int elemnum )
1037
1038/* returns string element number elemnum from string list idx
1039 *
1040 * parameters of routine
1041 * TGpStringListIndex idx;     input; index numer of string list
1042 * int                elemnum; input; number of string in list (start with 0)
1043 *                             returns string address or NULL
1044 */
1045{
1046        /* local variables */
1047        TGpStringElem *sel;     /* pointer to string element */
1048
1049        /* executable code */
1050
1051        if  (idx < 0 || idx >= cGpL_last)  return NULL;
1052
1053        sel = gpv_l_glob+idx;
1054
1055        while  (elemnum-- > 0)  {
1056                if  (sel->next == NULL)  return NULL;
1057                sel = sel->next;
1058        } /*endwhile*/
1059
1060        return sel->string;
1061
1062} /* end of GpGetStringElem */
1063
1064
1065
1066/*----------------------------------------------------------------------------*/
1067
1068
1069
1070void GpSetInt( TGpIntIndex idx, int value )
1071
1072/* Sets integer valued global
1073 *
1074 * parameters of routine
1075 * TGpIntIndex   idx;       input; index of variable
1076 * int           value;     input; new value of variable
1077 */
1078{
1079        /* executable code */
1080
1081        if  (idx >= 0 && idx < cGpI_last)  {
1082                gpv_i_glob[idx] = value;
1083        } else {
1084                printf( "--globalparams: illegal index %d in GpSetInt\n", idx );
1085        } /*endif*/
1086
1087} /* end of GpSetInt */
1088
1089
1090
1091/*----------------------------------------------------------------------------*/
1092
1093
1094
1095void GpSetFloat( TGpFloatIndex idx, float value )
1096
1097/* Sets float valued global
1098 *
1099 * parameters of routine
1100 * TGpFloatIndex   idx;     input; index of variable
1101 * float           value;   input; new value of variable
1102 */
1103{
1104        /* executable code */
1105
1106        if  (idx >= 0 && idx < cGpF_last)  {
1107                gpv_f_glob[idx] = value;
1108        } else {
1109                printf( "--globalparams: illegal index %d in GpSetFloat\n", idx );
1110        } /*endif*/
1111
1112} /* end of GpSetFloat */
1113
1114
1115
1116/*----------------------------------------------------------------------------*/
1117
1118
1119
1120void GpSetChar( TGpCharIndex idx, char value )
1121
1122/* Sets char valued global
1123 *
1124 * parameters of routine
1125 * TGpCharIndex   idx;      input; index of variable
1126 * char           value;    input; new value of variable
1127 */
1128{
1129        /* executable code */
1130
1131        if  (idx >= 0 && idx < cGpC_last)  {
1132                gpv_c_glob[idx] = value;
1133        } else {
1134                printf( "--globalparams: illegal index %d in GpSetChar\n", idx );
1135        } /*endif*/
1136
1137} /* end of GpSetChar */
1138
1139
1140
1141/*----------------------------------------------------------------------------*/
1142
1143
1144
1145void GpSetString( TGpStringIndex idx, char str[], int *ok )
1146
1147/* Sets value of string valued global variable
1148 *
1149 * parameters of routine
1150 * TGpStringIndex   idx;    input; index of variable
1151 * char             str[];  input; new value of variable
1152 * int              *ok;    output (if not NULL); 1 = ok, 0 = failure
1153 */
1154{
1155        /* executable code */
1156
1157        if  (strlen(str) > cGp_TEXTVARLTH)  {
1158                if  (ok != NULL)  *ok = 0;
1159                return;
1160        } /*endif*/
1161
1162        if  (idx >= 0 && idx < cGpS_last)  {
1163                strcpy( gpv_s_glob[idx], str );
1164                if  (ok != NULL)  *ok = 1;
1165        } else {
1166                if  (ok != NULL)  *ok = 0;
1167        } /*endif*/
1168
1169} /* end of GpSetString */
1170
1171
1172
1173/*----------------------------------------------------------------------------*/
1174
1175
1176
1177void GpSetBoolean( TGpBooleanIndex idx, int value )
1178
1179/* Sets boolean valued global
1180 *
1181 * parameters of routine
1182 * TGpBooleanIndex   idx;   input; index of variable
1183 * int               value; input; new value of variable
1184 */
1185{
1186        /* executable code */
1187
1188        if  (idx >= 0 && idx < cGpB_last)  {
1189                if  (value)  {
1190                        gpv_b_glob |= (1 << idx);
1191                } else {
1192                        gpv_b_glob &= ~(1 << idx);
1193                } /*endif*/
1194        } else {
1195                printf( "--globalparams: illegal index %d in GpSetBoolean\n", idx );
1196        } /*endif*/
1197
1198} /* end of GpSetBoolean */
1199
1200
1201
1202/*----------------------------------------------------------------------------*/
1203
1204
1205
1206void GpReadParameter( char parname[], int maxlth, char value[], int *ok )
1207
1208/* Reads parameter of name parname from parameter file.
1209 *
1210 * parameters of routine
1211 * char       parname[]; input, name of parameter
1212 * int        maxlth; input; maximum length of output string
1213 * char       value[]; output; value of parameter
1214 * int        *ok; output; 1=ok, 0=not found or string too short
1215 */
1216{
1217        /* local variables */
1218        char     *env;                   /* pointer to environment */
1219        char     parfile[cBcFileLth+1];  /* name of parameter file */
1220        FILE     *fp;                    /* pointer to parameter file */
1221        char     line[cBcVeryLongStrLth+1];  /* current line of file */
1222        int      namelth;                /* length of parameter name */
1223        char     *vptr;                  /* pointer to parameter value */
1224        int      slth;                   /* string length */
1225
1226        /* executable code */
1227
1228        /* get parameter file */
1229        env = (char *)getenv( "SH_USER_PARAM" );
1230        if  (env == NULL)  {
1231                env = (char *)getenv( "SH_INPUTS" );
1232                if  (strlen(env) < cBcFileLth-15)  {
1233                        strcpy( parfile, env );
1234                        strcat( parfile, "/shm-config.txt" );
1235                } else {
1236                        fprintf( stderr, "configuration filename too long.  Abort.\n" );
1237                        exit( 1 );
1238                } /*endif*/
1239        } else {
1240                if  (strlen(env) < cBcFileLth)  {
1241                        strcpy( parfile, env );
1242                } else {
1243                        fprintf( stderr, "environment SH_USER_PARAM too long.  Abort.\n" );
1244                        exit( 1 );
1245                } /*endif*/
1246        } /*endif*/
1247
1248        namelth = strlen( parname );
1249
1250        *ok = 0;
1251        fp = fopen( parfile, "r" );
1252        if  (fp == NULL)  return;
1253
1254        while  (fgets(line,cBcVeryLongStrLth,fp) != NULL)  {
1255
1256                if  (*line == '!' || *line == '#' || *line == '\n')  continue;
1257                if  (strncasecmp(line,parname,namelth) == 0
1258                        && (line[namelth] == ' ' || line[namelth] == '\t'))  {
1259                        vptr = line + namelth;
1260                        while  (*vptr == ' ')  vptr++;
1261                        slth = strlen( vptr );
1262                        if  (vptr[slth-1] == '\n')  vptr[--slth] = '\0';
1263                        *ok = (strlen(vptr) < maxlth);
1264                        if  (*ok)  strcpy( value, vptr );
1265                        break;
1266                } /*endif*/
1267
1268        } /*endwhile*/
1269
1270        fclose( fp );
1271
1272} /* end of GpReadParameter */
1273
1274
1275
1276/*----------------------------------------------------------------------------*/
1277
1278
1279
1280void GpParseTextList( char str[], TGpTextList *tl )
1281
1282/* Parses comma separated text string and returns pointers to elements of list.
1283 * Data structure returned must be freed after use (GpFreeTextList).
1284 *
1285 * parameters of routine
1286 * char       str[];    input; input string to be parsed
1287 * GpTextList *tl;      output; elements of list
1288 */
1289{
1290        /* local variables */
1291        int      strlth;       /* length of input string */
1292        int      i, j;         /* counters */
1293
1294        /* executable code */
1295
1296        strlth = strlen( str );
1297        if  (strlth == 0)  {
1298                tl->numelem = 0;
1299                tl->elem = NULL;
1300                tl->mem = NULL;
1301                return;
1302        } /*endif*/
1303
1304        tl->mem = (char *)malloc( strlth+1 );
1305        if  (tl->mem == NULL)  {
1306                fprintf( stderr, "GpParseTextList: error allocating memory.  Abort.\n" );
1307                exit( 1 );
1308        } /*endif*/
1309        strcpy( tl->mem, str );
1310
1311        /* count elements */
1312        tl->numelem = (*str == '\0') ? 0 : 1;
1313        for  (i=0; i<strlth; i++)
1314                if  (str[i] == ',')  (tl->numelem)++;
1315
1316        tl->elem = (char **)malloc( (int)sizeof(char *)*(tl->numelem) );
1317        if  (tl->elem == NULL)  {
1318                fprintf( stderr, "GpParseTextList: error allocating memory.  Abort.\n" );
1319                exit( 1 );
1320        } /*endif*/
1321
1322        j = 1;
1323        tl->elem[0] = tl->mem;
1324        for  (i=0; i<strlth; i++)  {
1325                if  (tl->mem[i] == ',')  {
1326                        tl->mem[i] = '\0';
1327                        tl->elem[j++] = tl->mem+i+1;
1328                } /*endif*/
1329        } /*endfor*/
1330
1331        /* debug output */
1332        /*
1333        for  (j=0; j<tl->numelem; j++)
1334                printf( "debug-textlist: %2d >%s<\n", j+1, tl->elem[j] );
1335        */
1336
1337} /* end of GpParseTextList */
1338
1339
1340
1341/*----------------------------------------------------------------------------*/
1342
1343
1344
1345void GpFreeTextList( TGpTextList *tl )
1346
1347/* Frees memory of textlist
1348 *
1349 * parameters of routine
1350 * TGpTextList         modify; text list to be freed
1351 */
1352{
1353        /* executable code */
1354
1355        if  (tl->numelem == 0)  return;
1356
1357        if  (tl->elem != NULL)  free( tl->elem );
1358        if  (tl->mem != NULL)  free( tl->mem );
1359
1360} /* end of GpFreeTextList */
1361
1362
1363
1364/*----------------------------------------------------------------------------*/
1365
1366
1367
1368void GpDumpParams( void )
1369
1370/* write all parameters out to stdout
1371 *
1372 * no parameters passed
1373 *
1374 */
1375{
1376        /* local variables */
1377        int    i;    /* counter */
1378        int    j;    /* string counter */
1379        char   *s;   /* string pointer */
1380
1381        /* executable code */
1382
1383        for  (i=0; i<cGpI_last; i++)
1384                printf( "%s: %d\n", gpv_i_name[i], gpv_i_glob[i] );
1385        for  (i=0; i<cGpF_last; i++)
1386                printf( "%s: %g\n", gpv_f_name[i], gpv_f_glob[i] );
1387        for  (i=0; i<cGpC_last; i++)
1388                printf( "%s: %c\n", gpv_c_name[i], gpv_c_glob[i] );
1389        for  (i=0; i<cGpS_last; i++)
1390                printf( "%s: %s\n", gpv_s_name[i], gpv_s_glob[i] );
1391        for  (i=0; i<cGpB_last; i++)
1392                printf( "%s: %d\n", gpv_b_name[i], ((1<<i) & gpv_b_glob) );
1393        for  (i=0; i<cGpL_last; i++)  {
1394                for  (j=0;;j++)  {
1395                        s = GpGetStringElem( i, j );
1396                        if  (s == NULL)  break;
1397                        printf( "%s (%d): %s\n", gpv_l_name[i], j, s );
1398                } /*endfor*/
1399        } /*endfor*/
1400
1401} /* end of GpDumpParams */
1402
1403
1404
1405/*----------------------------------------------------------------------------*/
1406
1407
1408
1409void GpParseStringList( TGpStringListIndex idx, char line[] )
1410
1411/* parses string list and puts result to list number idx
1412 *
1413 * parameters of routine
1414 * TGpStringListIndex idx;    input; string list variable index
1415 * char               line[]; input; line to be parsed
1416 */
1417{
1418        /* local variables */
1419        int      i, j;                /* counters */
1420        TGpStringElem *sel;           /* pointer to string element */
1421        char     val[cBcLineLth+1];   /* string value */
1422
1423        /* excutable code */
1424
1425        sel = gpv_l_glob+idx;
1426
1427        /* !!! should free list before (if not "default") */
1428
1429        sel->next = NULL;
1430        sel->string = '\0';
1431        sel->strlth = 0;
1432
1433        while  (*line != '\0')  {
1434
1435                /* skip blanks */
1436                while  (*line == ' ' || *line == '\t')  line++;
1437                if  (*line == '\0' || *line == '\n')  break;
1438
1439                /* allocate next StringElem if necessary */
1440                if  (sel->string != '\0')  {
1441                        sel->next = (TGpStringElem *)malloc( (int)sizeof(TGpStringElem) );
1442                        if  (sel->next == NULL)  {
1443                                printf( "--globalparams: error allocating memory (1). Abort\n" );
1444                                exit( 1 );
1445                        } /*endif*/
1446                        sel = sel->next;
1447                        sel->next = NULL;
1448                        sel->string = '\0';
1449                        sel->strlth = 0;
1450                } /*endif*/
1451
1452                /* get next string length */
1453                i = 0;
1454                while  (line[i] != '\0' && line[i] != ' ' && line[i] != '\n'
1455                        && line[i] != '\t' && line[i] != ',' && line[i] != ';')
1456                        i++;
1457                if  (i >= cBcLineLth-1)  {
1458                        printf( "--globalparams: string element (idx: %d) too long\n", idx );
1459                        return;
1460                } /*endif*/
1461
1462                /* copy string to StringElem structure */
1463                if  (i > 0)  {
1464
1465                        /* copy string and translate if necessary */
1466                        strncpy( val, line, i );
1467                        val[i] = '\0';
1468
1469                        while  (*val == '$')
1470                                GpEvaluateVar( val );
1471
1472                        j = strlen( val );
1473                        sel->string = (char *)malloc( (int)sizeof(char)*(j+1) );
1474                        if  (sel->string == NULL)  {
1475                                printf( "--globalparams: error allocating memory (2). Abort\n" );
1476                                exit( 1 );
1477                        } /*endif*/
1478                        strcpy( sel->string, val );
1479                        sel->strlth = j;
1480
1481                } /*endif*/
1482
1483                if  (line[i] == '\0' || *line == '\n')  break;
1484                line += i+1;
1485
1486        } /*endwhile*/
1487
1488} /* end of GpParseStringList */
1489
1490
1491
1492/*----------------------------------------------------------------------------*/
1493
1494
1495
1496static void GpEvaluateVar( char val[] )
1497
1498/* Evaluates value of variable
1499 *
1500 * parameters of routine
1501 * char       val[];     modify; input: variable name, output: value
1502 */
1503{
1504        /* local variable */
1505        char     vname[cBcLineLth+1];     /* variable name */
1506        char     appdx[cBcLineLth+1];     /* appendix (after '/') */
1507        int      j;                       /* counter */
1508        int      ok;                      /* string value found */
1509        char     *env;                    /* pointer to environment */
1510
1511        /* executable code */
1512
1513        if  (*val != '$')  return;  /* leave unchanged */
1514
1515        /* try 'v$'-variable in configuration file */
1516        vname[0] = 'v';
1517        j = 0;
1518        while  (val[j] != '/' && val[j] != '\0')  {
1519                vname[j+1] = val[j];
1520                j++;
1521        } /*endwhile*/
1522        vname[j+1] = '\0';
1523        *appdx = '\0';
1524        if  (val[j] == '/')  strcpy( appdx, val+j );
1525        GpReadParameter( vname, cBcLineLth, val, &ok );
1526
1527        if  (!ok)  {
1528                /* try to find environment variable */
1529                env = (char *)getenv( vname+2 );  /* skip v$ */
1530                if  (env == NULL)  {
1531                        strcpy( val, vname+2 );  /* take away '$', results in an error later */
1532                } else if  (strlen(env) < cBcLineLth)  {
1533                        strcpy( val, env );
1534                } else {
1535                        strcpy( val, vname+2 );  /* results in an error later */
1536                } /*endif*/
1537        } /*endif*/
1538
1539        if  (*appdx != '\0')
1540                if  (strlen(val)+strlen(appdx) < cBcLineLth)
1541                        strcat( val, appdx );
1542
1543} /* end of GpEvaluateVar */
1544
1545
1546
1547/*----------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the repository browser.