9 static int user_center
= 0, user_subcenter
= 0, user_ptable
= 0;
10 static enum {filled
, not_found
, not_checked
, no_file
, init
} status
= init
;
12 struct ParmTable parm_table_user
[256];
15 * sets up user parameter table
18 int setup_user_table(int center
, int subcenter
, int ptable
) {
22 static int file_open
= 0;
23 char *filename
, line
[300];
26 for (i
= 0; i
< 256; i
++) {
27 parm_table_user
[i
].name
= parm_table_user
[i
].comment
= NULL
;
32 if (status
== no_file
) return 0;
34 if ((user_center
== -1 || center
== user_center
) &&
35 (user_subcenter
== -1 || subcenter
== user_subcenter
) &&
36 (user_ptable
== -1 || ptable
== user_ptable
)) {
38 if (status
== filled
) return 1;
39 if (status
== not_found
) return 0;
42 /* open gribtab file if not open */
45 filename
= getenv("GRIBTAB");
46 if (filename
== NULL
) filename
= getenv("gribtab");
47 if (filename
== NULL
) filename
= "gribtab";
49 if ((input
= fopen(filename
,"r")) == NULL
) {
60 user_subcenter
= subcenter
;
63 /* scan for center & subcenter and ptable */
65 if (fgets(line
, 299, input
) == NULL
) {
69 if (atoi(line
) != START
) continue;
70 i
= sscanf(line
,"%d:%d:%d:%d", &j
, ¢er
, &subcenter
, &ptable
);
72 fprintf(stderr
,"illegal gribtab center/subcenter/ptable line: %s\n", line
);
75 if ((center
== -1 || center
== user_center
) &&
76 (subcenter
== -1 || subcenter
== user_subcenter
) &&
77 (ptable
== -1 || ptable
== user_ptable
)) break;
81 user_subcenter
= subcenter
;
84 /* free any used memory */
85 if (parm_table_user
[i
].name
!= NULL
) {
86 for (i
= 0; i
< 256; i
++) {
87 free(parm_table_user
[i
].name
);
88 free(parm_table_user
[i
].comment
);
92 /* read definitions */
95 if (fgets(line
, 299, input
) == NULL
) break;
96 if ((i
= atoi(line
)) == START
) break;
99 /* find the colons and end-of-line */
100 for (c0
= 0; line
[c0
] != ':' && line
[c0
] != 0; c0
++) ;
101 /* skip blank lines */
102 if (line
[c0
] == 0) continue;
104 for (c1
= c0
+ 1; line
[c1
] != ':' && line
[c1
] != 0; c1
++) ;
106 if (line
[c2
-1] == '\n') line
[--c2
] = '\0';
108 fprintf(stderr
,"illegal gribtab line:%s\n", line
);
114 parm_table_user
[i
].name
= (char *) malloc(c1
- c0
);
115 parm_table_user
[i
].comment
= (char *) malloc(c2
- c1
);
116 strcpy(parm_table_user
[i
].name
, line
+c0
+1);
117 strcpy(parm_table_user
[i
].comment
, line
+c1
+1);
120 /* now to fill in undefined blanks */
121 for (i
= 0; i
< 255; i
++) {
122 if (parm_table_user
[i
].name
== NULL
) {
123 parm_table_user
[i
].name
= (char *) malloc(7);
124 sprintf(parm_table_user
[i
].name
, "var%d", i
);
125 parm_table_user
[i
].comment
= (char *) malloc(strlen("undefined")+1);
126 strcpy(parm_table_user
[i
].comment
, "undefined");