Mapper
getparm.c
Go to the documentation of this file.
1 /*Translated by FOR_C, v3.4.2 (-), on 04/06/95 at 14:16:22 */
2 /*FOR_C Options SET: c=2 com=u do=r44 ftn=ln6kk op=iv s=dvnk str=l sq=i */
3 
4 #define _POSIX_SOURCE
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <dirent.h>
9 #include <unistd.h>
10 #include <math.h>
11 #include <string.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 #include "shef_structs_external.h"
15 
16 /*---------------------------------------------------------------------
17 
18  NAME
19  SUBROUTINE GETPARM
20 
21  PURPOSE
22  Read in the file inputparm into memeory
23 
24  VERSION and UPDATES
25  1.0 MAY 94 David G. Brandon
26  Original Version
27  Aslo translated to 'C' using FOR_C
28  1.1 APR 95 David G. Brandon
29  Removed some of the I/O functions created by the FORTRAN_C
30  translator and replaced them with standard 'C'
31  functions.
32  1.1 OCT 95 DGB
33  Change from fixed array sizes to values read out of the
34  header file. Add iscore to t_codes array;
35  1.3 JAN 96 DGB
36  Remove fixed format scanf and replace with fgets
37  for more robust method of reading in parameter file.
38  *--------------------------------------------------------------------- */
39 
40 
41 void getparm()
42 {
43  char *str1, *str2;
44  static char headr[3];
45  static int notfound;
46  static short int i, i_, ii, ndurval, nexval, npeval, nproval, nsenval,
47  ntsval;
48  char temp_buff[20], buff_temp[200];
49 
50  /* OFFSET Vectors w/subscript range: 1 to dimension */
51  short *const Durvalue = &parms2_.durvalue[0] - 1;
52  short *const Exvalue = &parms2_.exvalue[0] - 1;
53  short *const Numval = &parms2_.numval[0] - 1;
54  double *const Pevalue = &parms3_.pevalue[0] - 1;
55  double *const Provalue = &parms3_.provalue[0] - 1;
56  short *const Sendflag = &parms2_.sendflag[0] - 1;
57  short *const Tsvalue = &parms2_.tsvalue[0] - 1;
58 
59  /*
60  Initialize Max Number or Values in inputparm file
61  These values, as well as the dimensions above will
62  need to be changed if additional values are used.
63  */
64 
65  npeval = NUM_PEVAL;
66  ndurval = NUM_DURVAL;
67  ntsval = NUM_TSVAL;
68  nexval = NUM_EXVAL;
69  nproval = NUM_PROVAL;
70  nsenval = NUM_SENVAL;
71 
72  if ( DEBUG )
73  {
74  printf("\nNUM_PEVAL = %d",npeval);
75  printf("\nNUM_DURVAL = %d",ndurval);
76  printf("\nNUM_TSVAL = %d",ntsval);
77  printf("\nNUM_EXVAL = %d",nexval);
78  printf("\nNUM_PROVAL = %d",nproval);
79  printf("\nNUM_SENVAL = %d",nsenval);
80 
81  }
82 
83  /* INITIALIZE */
84 
85  for( i = 1; i <= 6; i++ )
86  {
87  i_ = i - 1;
88  Numval[i] = 0;
89  }
90  /* Find the Beginning at *1 */
91 
92  i = 0;
93  notfound = 1;
94  while( notfound )
95  {
96  while ( (fgets(buff_temp,sizeof(buff_temp),fp_.kchn)) != NULL )
97  {
98  if ( strpat(buff_temp,"*1",'$','%') >= 0 )
99  {
100  if ( DEBUG )
101  printf("\n found *1");
102  notfound = 0;
103  break;
104  }
105  if ( i > npeval ) goto L_9000;
106  i++;
107  }
108  }
109  if ( notfound ) goto L_9000;
110 
111 
112  /* Read in Pe Codes *1 */
113 
114  notfound = 1;
115  i = 1;
116  while( notfound )
117  {
118  if( i > npeval ) goto L_9010;
119  while ( (fgets(buff_temp,sizeof(buff_temp),fp_.kchn)) != NULL )
120  {
121  if ( DEBUG )
122  printf("\n %s",buff_temp);
123  if ( strpat(buff_temp,"*2",'$','%') >= 0 )
124  {
125  if ( DEBUG )
126  printf("\n found *2");
127  notfound = 0;
128  break;
129  }
130  str2 = buff_temp;
131 
132  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
133  goto L_9010;
134 
135  strncpy(parms1_.peval[i-1],str1,sizeof(parms1_.peval[i-1])); /* dgb:10/03/02 */
136  str2 = 0;
137  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
138  goto L_9010;
139  parms3_.pevalue[i-1] = atof(str1);
140  memset(buff_temp,0,sizeof(buff_temp));
141  i = i + 1;
142  }
143 
144  }
145 
146  Numval[1] = i - 1;
147 
148  /* Duration codes */
149 
150  notfound = 1;
151  i = 1;
152  while( notfound )
153  {
154  if( i > ndurval ) goto L_9020;
155  while ( (fgets(buff_temp,sizeof(buff_temp),fp_.kchn)) != NULL )
156  {
157  if ( DEBUG )
158  printf("\n %s",buff_temp);
159  if ( strpat(buff_temp,"*3",'$','%') >= 0 )
160  {
161  if ( DEBUG )
162  printf("\n found *3");
163 
164  notfound = 0;
165  break;
166  }
167  str2 = buff_temp;
168  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
169  goto L_9020;
170  strncpy(parms1_.durval[i-1],str1,1);
171  str2 = 0;
172  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
173  goto L_9020;
174  parms2_.durvalue[i-1] = atof(str1);
175  memset(buff_temp,0,sizeof(buff_temp));
176  i = i + 1;
177 
178  }
179 
180  }
181  Numval[2] = i - 1;
182 
183  /* Type Source Codes */
184 
185  notfound = 1;
186  i = 1;
187 
188  while( notfound )
189  {
190  if( i > ntsval ) goto L_9030;
191 
192  while ( (fgets(buff_temp,sizeof(buff_temp),fp_.kchn)) != NULL )
193  {
194  if ( DEBUG )
195  printf("\n %s",buff_temp);
196  if ( strpat(buff_temp,"*4",'$','%') >= 0 )
197  {
198  if ( DEBUG )
199  printf("\n found *4");
200 
201  notfound = 0;
202  break;
203  }
204  str2 = buff_temp;
205  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
206  goto L_9030;
207  strncpy(parms1_.tsval[i-1],str1,2);
208  str2 = 0;
209  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
210  goto L_9030;
211  parms2_.tsvalue[i-1] = atoi(str1);
212  memset(buff_temp,0,sizeof(buff_temp));
213  i = i + 1;
214 
215  }
216 
217  }
218 
219  Numval[3] = i - 1;
220 
221  /* Extremnum Codes */
222  notfound = 1;
223  i = 1;
224 
225  while( notfound )
226  {
227  if( i > nexval ) goto L_9040;
228  while ( (fgets(buff_temp,sizeof(buff_temp),fp_.kchn)) != NULL )
229  {
230  if ( DEBUG )
231  printf("\n %s",buff_temp);
232  if ( strpat(buff_temp,"*5",'$','%') >= 0 )
233  {
234  if ( DEBUG )
235  printf("\n found *5");
236 
237  notfound = 0;
238  break;
239  }
240  str2 = buff_temp;
241  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
242  goto L_9040;
243  strncpy(parms1_.exval[i-1],str1,1);
244  str2 = 0;
245  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
246  goto L_9040;
247  parms2_.exvalue[i-1] = atoi(str1);
248  memset(buff_temp,0,sizeof(buff_temp));
249  i = i + 1;
250 
251  }
252  }
253 
254  Numval[4] = i - 1;
255 
256  /* Probability Codes */
257 
258  notfound = 1;
259  i = 1;
260  while( notfound )
261  {
262  if( i > nproval ) goto L_9050;
263 
264  while ( (fgets(buff_temp,sizeof(buff_temp),fp_.kchn)) != NULL )
265  {
266  if ( DEBUG )
267  printf("\n %s",buff_temp);
268  if ( strpat(buff_temp,"*6",'$','%') >= 0 )
269  {
270  if ( DEBUG )
271  printf("\n found *6");
272  notfound = 0;
273  break;
274  }
275  str2 = buff_temp;
276  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
277  goto L_9050;
278  strncpy(parms1_.proval[i-1],str1,1);
279  str2 = 0;
280  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
281  goto L_9050;
282  parms3_.provalue[i-1] = (double) atof(str1);
283  memset(buff_temp,0,sizeof(buff_temp));
284  i = i + 1;
285 
286  }
287 
288  }
289 
290  Numval[5] = i - 1;
291 
292  /* Send Codes */
293 
294 
295  notfound = 1;
296  i = 1;
297 
298  while( notfound )
299  {
300  memset (temp_buff,0, sizeof(temp_buff));
301  if( i > nsenval ) goto L_9060;
302 
303  while ( (fgets(buff_temp,sizeof(buff_temp),fp_.kchn)) != NULL )
304  {
305  if ( DEBUG )
306  {
307  printf("\n %s",buff_temp);
308  fflush(stdout);
309  }
310 
311  if ( strpat(buff_temp,"**",'$','%') >= 0 )
312  {
313  if ( DEBUG )
314  printf("\n found **");
315 
316  notfound = 0;
317  break;
318  }
319  str2 = buff_temp;
320  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
321  goto L_9060;
322  strncpy(parms1_.senval[i-1],str1,sizeof(parms1_.senval[0]));
323  str2 = 0;
324  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
325  goto L_9060;
326  strncpy(parms2_.sendcodes[i-1],str1,sizeof(parms2_.sendcodes[0]));
327  str2 = 0;
328  if ( (str1 = strtok(str2," \t\n\r")) == NULL )
329  goto L_9060;
330  parms2_.sendflag[i-1] = atoi(str1);
331  memset(buff_temp,0,sizeof(buff_temp));
332  for ( ii = 0; ii < 8; ii++)
333  {
334  if ( parms2_.sendcodes[i-1][ii] == 0 )
335  parms2_.sendcodes[i-1][ii] = 32;
336  }
337 
338  i = i + 1;
339 
340  }
341  }
342 
343  Numval[6] = i - 1;
344  if ( DEBUG )
345  {
346  printf("\n returning from getparm");
347  fflush(stdout);
348  }
349 
350  return;
351 
352  /* Errors */
353 
354 L_9000:
355  fprintf( stdout, "\ngetparm:error - could not find *1 - start of PE codes\n");
356  if ( fp_.kchn != NULL )
357  fclose(fp_.kchn);
358  exit(0);
359 
360 
361 L_9010:
362  fprintf(stdout,"\ngetparm:error - could not find *2 - start of duration codes\n");
363  if ( fp_.kchn != NULL )
364  fclose(fp_.kchn);
365  exit(0);
366 
367 L_9020:
368  fprintf(stdout,"\ngetparm:error - could not find *3 - start of TS codes\n");
369  if ( fp_.kchn != NULL )
370  fclose(fp_.kchn);
371  exit(0);
372 
373 L_9030:
374  fprintf(stdout,"\ngetparm:error - could not find *4 - start of extremun codes\n");
375  if ( fp_.kchn != NULL )
376  fclose(fp_.kchn);
377  exit(0);
378 
379 L_9040:
380  fprintf(stdout,"\ngetparm:error - could not find *5 - start of probability codes\n");
381  if ( fp_.kchn != NULL )
382  fclose(fp_.kchn);
383  exit(0);
384 
385 L_9050:
386  fprintf(stdout,"\ngetparm:error - could not find *6 - start of send codes\n");
387  if ( fp_.kchn != NULL )
388  fclose(fp_.kchn);
389  exit(0);
390 
391 L_9060:
392  fprintf(stdout,"\ngetparm:error - could not find ** - end of file\n");
393  if ( fp_.kchn != NULL )
394  fclose(fp_.kchn);
395  exit(0);
396 
397 }
398 
static int i
void getparm()
Definition: getparm.c:41
int DEBUG
Definition: shef_structs.h:248
fclose(fp)
printf("fbuf is %s\n", fbuf)
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
#define NUM_DURVAL
Definition: shef.h:19
#define NUM_SENVAL
Definition: shef.h:23
#define NUM_PROVAL
Definition: shef.h:22
#define NUM_EXVAL
Definition: shef.h:21
#define NUM_PEVAL
Definition: shef.h:18
#define NUM_TSVAL
Definition: shef.h:20
struct t_parms1_ parms1_
struct t_pointers_ fp_
struct t_parms2_ parms2_
struct t_parms3_ parms3_
strpat(char buffer[], char token[], int numtemp, int chartemp)
Definition: strpat.c:30
char senval[NUM_SENVAL][3]
Definition: shef_structs.h:86
char exval[NUM_EXVAL][3]
Definition: shef_structs.h:86
char peval[NUM_PEVAL][3]
Definition: shef_structs.h:85
char tsval[NUM_TSVAL][3]
Definition: shef_structs.h:85
char proval[NUM_PROVAL][3]
Definition: shef_structs.h:86
char durval[NUM_DURVAL][3]
Definition: shef_structs.h:85
short int numval[7]
Definition: shef_structs.h:90
char sendcodes[NUM_SENVAL][7]
Definition: shef_structs.h:91
short int exvalue[NUM_EXVAL]
Definition: shef_structs.h:89
short int durvalue[NUM_DURVAL]
Definition: shef_structs.h:89
short int tsvalue[NUM_TSVAL]
Definition: shef_structs.h:89
short int sendflag[NUM_SENVAL]
Definition: shef_structs.h:90
double provalue[NUM_PROVAL]
Definition: shef_structs.h:94
double pevalue[NUM_PEVAL]
Definition: shef_structs.h:94
FILE * kchn
Definition: shef_structs.h:72