Mapper
shefop.c
Go to the documentation of this file.
1 /*Translated by FOR_C, v3.4.2 (-), on 06/07/94 at 17:01:33 */
2 /*FOR_C Options SET: c=2 com=u do=r4 ftn=2ln6k op=iv s=dvn 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 <time.h>
15 #include "shef_structs_external.h"
16 
17 /*---------------------------------------------------------------------
18 
19  FUNCTION
20  shefopen
21 
22  PURPOSE
23  Open files used by the shef decoder. All file names and some
24  program control is read from the configuration file: shef.cfg.
25  The file names can include path names, up to 80 characters long.
26  The format of the shef.cfg files is as follows:
27 
28  shef_in <- directory containing shef data to be decoded
29  shef_out <- directory containing shefout files
30  shef_error <- directory containing error files
31  shef_parm <- (file) parmater file used by the decoder
32  -SHEFOUT <- (control) +=write shef_out, -=do not write
33  +ERRORFILE <- (control) +=always write, -=only if errors
34  +SHEFPASS <- (control) +=call shef_pass -=no call to shef_pass
35 
36  You can either place a plus '+' or minus '-' sign in front of the
37  control names. The '+' turn the control on, the '-' turns it off.
38 
39  File names can include directory paths. This can be useful if
40  you want to place the executable in a /bin directory, and the
41  support file somewhere else. An example may be:
42  /home/shef/inputparm
43 
44 
45  VERSION and UPDATES
46  1.0 MAY 94 David G. Brandon
47  Original Version
48  Also Translated to 'C' using FOR_C
49  1.1 SEP 95 DGB
50  Change to accomodate test option from keyboard.
51  Changed the name of the 'out' and 'err' file names.
52  They are now in the format, 'out.xxx.YRMMDDHRMNSC'
53  or 'err.xxx.YRMMDDHRMNSC' where xxx is the file name.
54  1.2 OCT 95 DGB
55  Add PE_SIZE and TS_SIZE macros for dimenioning.
56  1.3 Remove all FORC I/O & change to C I/O
57  1.4 JAN 3 98 DGB
58  Add -c flag, which explicitly sets the century for
59  the system clock from the command line. Used for
60  testing.
61  1.5 JAN 18 98 DGB
62  Change test for -c flag. Allow for year, month,
63  and day. For example:
64  -c 2000 override system year & set to 2000
65  -c 200012 override year and month
66  -c 20001231 override year, month and day
67  -c 2000123100 override year,month, day, hour
68  -c 200012311010 override year,month,day,hour,min
69  1.6 OCT 3 02 DGB
70  Change strcpy to strncpy
71  *--------------------------------------------------------------------- */
72 
73 
74 
75 int shefop()
76 {
77  char log_file[91], err_file[91], buff_temp[20];
78  char buff[15],buff1[5];
79  char *c;
80  long current_time;
81  static char strg1[10], strg2[10];
82  static short int ier, ier1, ier2, nchn, i;
83  static long int itemp;
84 
85  /* OFFSET Vectors w/subscript range: 1 to dimension */
86  short *const Idate = &datim_.idate[0] - 1;
87 
88  memset(tempfiles_.shef_in,0,sizeof(tempfiles_.shef_in));
89  strncpy(tempfiles_.shef_in,files_.shef_in,sizeof(tempfiles_.shef_in)); /* dgb:10/03/02 */
90 
92  strncpy(tempfiles_.shef_decode_err,files_.shef_decode_err,sizeof(tempfiles_.shef_decode_err )); /* dgb:10/03/02 */
93 
94  memset(tempfiles_.shef_out,0,sizeof(tempfiles_.shef_out));
95  strncpy(tempfiles_.shef_out,files_.shef_out,sizeof(tempfiles_.shef_out )); /* dgb:10/03/02 */
96 
97  memset(tempfiles_.shef_log,0,sizeof(tempfiles_.shef_log));
98  strncpy(tempfiles_.shef_log,files_.shef_log,sizeof( tempfiles_.shef_log)); /* dgb:10/03/02 */
99 
100  memset(tempfiles_.dotbtemp,0,sizeof(tempfiles_.dotbtemp));
101  strncpy(tempfiles_.dotbtemp,"dotbtemp",sizeof(tempfiles_.dotbtemp )); /* dgb:10/03/02 */
102 
103  /* Get the Current Date
104  * This will vary depending upon the operating system
105  * used. Place the year, month, day, etc. into the
106  * array values as follows:
107  * IDATE(1) = MONTH
108  * IDATE(2) = DAY
109  * IDATE(3) = YEAR (4 digit year, e.g., 1994)
110  * IDATE(4) = HOUR
111  * IDATE(5) = MINUTE
112  * IDATE(6) = SECOND
113  */
114 
115  date_time( &Idate[1], &Idate[2], &Idate[3], &Idate[4], &Idate[5],
116  &Idate[6] );
117 
118 
119  if ( test_.test_flag==1 || test_.atest_flag==1 )
120  {
121 
122  if ( test_.century_flag != 0 )
123  {
124 
125  memset(buff,0,sizeof(buff));
126  if ( strlen(test_.century_string) == 4 ) /* dgb:01/18/98 */
127  {
128  memset(buff1,0,sizeof(buff1));
129  strncpy(buff1,&test_.century_string[0],4);
130  Idate[3] = atoi(buff1); /* dgb:01/02/98 */
131  printf("\n***NOTE: system year reset to: %d\n",Idate[3]);
132  }
133  else
134  if ( strlen(test_.century_string) == 6 ) /* dgb:01/18/98 */
135  {
136  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
137  strncpy(buff1,&test_.century_string[0],4); /* dgb:01/18/98 */
138  Idate[3] = atoi(buff1); /* dgb:01/18/98 */
139  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
140  strncpy(buff1,&test_.century_string[4],2); /* dgb:01/18/98 */
141  Idate[1] = atoi(buff1); /* dgb:01/18/98 */
142  printf("\n***NOTE: system year reset to: %d\n",Idate[3]);
143  printf("\n***NOTE: system month reset to: %d\n",Idate[1]);
144  }
145  else /* dgb:01/18/98 */
146  if ( strlen(test_.century_string) == 8 ) /* dgb:01/18/98 */
147  {
148  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
149  strncpy(buff1,&test_.century_string[0],4); /* dgb:01/18/98 */
150  Idate[3] = atoi(buff1); /* dgb:01/18/98 */
151  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
152  strncpy(buff1,&test_.century_string[6],2); /* dgb:01/18/98 */
153  Idate[2] = atoi(buff1); /* dgb:01/18/98 */
154  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
155  strncpy(buff1,&test_.century_string[4],2); /* dgb:01/18/98 */
156  Idate[1] = atoi(buff1); /* dgb:01/18/98 */
157  printf("\n***NOTE: system year reset to: %d\n",Idate[3]);
158  printf("\n***NOTE: system month reset to: %d\n",Idate[1]);
159  printf("\n***NOTE: system day reset to: %d\n",Idate[2]);
160  }
161  else /* dgb:01/18/98 */
162  if ( strlen(test_.century_string) == 10) /* dgb:01/18/98 */
163  {
164  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
165  strncpy(buff1,&test_.century_string[0],4); /* dgb:01/18/98 */
166  Idate[3] = atoi(buff1); /* dgb:01/18/98 */
167  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
168  strncpy(buff1,&test_.century_string[6],2); /* dgb:01/18/98 */
169  Idate[2] = atoi(buff1); /* dgb:01/18/98 */
170  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
171  strncpy(buff1,&test_.century_string[4],2); /* dgb:01/18/98 */
172  Idate[1] = atoi(buff1); /* dgb:01/18/98 */
173  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
174  strncpy(buff1,&test_.century_string[8],2); /* dgb:01/18/98 */
175  Idate[4] = atoi(buff1); /* dgb:01/18/98 */
176  printf("\n***NOTE: system year reset to: %d\n",Idate[3]);
177  printf("\n***NOTE: system month reset to: %d\n",Idate[1]);
178  printf("\n***NOTE: system day reset to: %d\n",Idate[2]);
179  printf("\n***NOTE: system hour reset to: %d\n",Idate[4]);
180  }
181  else /* dgb:01/18/98 */
182  if ( strlen(test_.century_string) == 12) /* dgb:01/18/98 */
183  {
184  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
185  strncpy(buff1,&test_.century_string[0],4); /* dgb:01/18/98 */
186  Idate[3] = atoi(buff1); /* dgb:01/18/98 */
187  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
188  strncpy(buff1,&test_.century_string[6],2); /* dgb:01/18/98 */
189  Idate[2] = atoi(buff1); /* dgb:01/18/98 */
190  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
191  strncpy(buff1,&test_.century_string[4],2); /* dgb:01/18/98 */
192  Idate[1] = atoi(buff1); /* dgb:01/18/98 */
193  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
194  strncpy(buff1,&test_.century_string[8],2); /* dgb:01/18/98 */
195  Idate[4] = atoi(buff1); /* dgb:01/18/98 */
196  memset(buff1,0,sizeof(buff1)); /* dgb:01/18/98 */
197  strncpy(buff1,&test_.century_string[10],2); /* dgb:01/18/98 */
198  Idate[5] = atoi(buff1); /* dgb:01/18/98 */
199  printf("\n***NOTE: system year reset to: %d\n",Idate[3]);
200  printf("\n***NOTE: system month reset to: %d\n",Idate[1]);
201  printf("\n***NOTE: system day reset to: %d\n",Idate[2]);
202  printf("\n***NOTE: system hour reset to: %d\n",Idate[4]);
203  printf("\n***NOTE: system min reset to: %d\n",Idate[5]);
204  }
205  }
206  }
207 
208  /* use 'c' routine to get date/time and construct part of file */
209  current_time = time(NULL);
210  strftime(buff_temp,sizeof(buff_temp),".%m%d.%H%M%S",gmtime(&current_time));
211 
212 
213  /* Open the Shef_in and dotbtemp files */
214 
215 
216  if ( (fp_.lchn = fopen(files_.shef_in,"r") ) == NULL )
217  goto L_900;
218 
219  /* comment out dotbtemp file .. virtual buffer now allows for 48 items in .B line */
220  /*
221  sprintf(tempfiles_.dotbtemp,"%s","dotbtemp");
222  if ( (fp_.mchn = fopen(tempfiles_.dotbtemp,"w") ) == NULL )
223  goto L_915;
224  */
225 
226  /* Open a shef_out file if SHEFOUT is set to '+'.
227  The file name will be constructed from the
228  name of the shef_out file in the shef.cfg file
229  with the datetime stamp.
230  */
231 
232  if( cont_.out_flag[0] == '+' )
233  {
234 
235  /* dgb: 09/20/95 added change to out file name */
236  if ( test_.test_flag )
237  {
238  sprintf(log_file,"%s%s",
239  tempfiles_.shef_out,buff_temp);
240  }
241  else
242  {
243 
244  if ( strlen(stats_.product_name) >= 9 )
245  {
246  sprintf(log_file,"%s/out.%-9.9s%s",
248  }
249  else
250  {
251  sprintf(log_file,"%s/out.%s%s",
253  }
254 
255  }
256 
257  /* open as ascii file */
258 
259 
260  if ( (fp_.jchn = fopen(log_file,"w")) == NULL )
261  goto L_920;
262 
263  /* print to screen if in test mode */
264  if ( test_.test_flag )
265  fprintf(stdout," shef_out_file: %s\n",log_file);
266  }
267 
268 
269  /* Open the shef_decode_err file */
270 
271  /* dgb: 09/20/95 added change to err file name */
272  if ( test_.test_flag )
273  sprintf(err_file,"%s%s",
274  tempfiles_.shef_decode_err,buff_temp);
275  else
276  {
277 
278  if ( strlen(stats_.product_name) >= 9 )
279  {
280  sprintf(err_file,"%s/err.%-9.9s%s",
282  }
283  else
284  {
285  sprintf(err_file,"%s/err.%s%s",
287  }
288 
289  }
290 
291  strncpy(tempfiles_.err_file,err_file,sizeof(tempfiles_.err_file )); /* dgb:10/03/02 */
292  if ( (fp_.icher = fopen(err_file,"w")) == NULL )
293  goto L_910;
294 
295  /* print to screen if in test mode */
296  if ( test_.test_flag )
297  fprintf(stdout," error file: %s\n",err_file);
298 
299  return(0);
300 
301 
302 L_900:
303  fprintf(stdout,"\nshefop:error on opening input file --> %s",files_.shef_in);
304  if ( fp_.lchn != NULL )
305  fclose(fp_.lchn);
306  exit(0);
307 
308 L_910:
309  fprintf(stdout,"\nshefop:error on opening file --> %s",files_.shef_decode_err);
310  if ( fp_.icher != NULL )
311  fclose(fp_.icher);
312  exit(0);
313 /*
314 L_915:
315  fprintf(stdout,"\nshefop:error on opening file --> %s",tempfiles_.dotbtemp);
316  if ( fp_.mchn != NULL )
317  fclose(fp_.mchn);
318  exit(0);
319 */
320 
321 L_920:
322  fprintf(stdout,"\nshefop:error on opening file --> %s",files_.shef_out);
323  if ( fp_.jchn != NULL )
324  fclose(fp_.jchn);
325  exit(0);
326 
327 
328 }
329 
static int i
date_time(short int *mon, short int *day, short int *year, short int *hour, short int *min, short int *sec)
Definition: date_time.c:5
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
printf("fbuf is %s\n", fbuf)
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
struct t_stats_ stats_
struct t_datim_ datim_
struct t_files_ files_
struct t_pointers_ fp_
struct s_test test_
struct t_tempfiles_ tempfiles_
struct t_cont_ cont_
int shefop()
Definition: shefop.c:75
char century_string[13]
Definition: shef_structs.h:212
int test_flag
Definition: shef_structs.h:211
int century_flag
Definition: shef_structs.h:211
int atest_flag
Definition: shef_structs.h:211
char out_flag[13]
Definition: shef_structs.h:75
short int idate[6]
Definition: shef_structs.h:100
char shef_log[MAX_F]
Definition: shef_structs.h:106
char shef_in[MAX_F]
Definition: shef_structs.h:106
char shef_decode_err[MAX_F]
Definition: shef_structs.h:106
char shef_out[MAX_F]
Definition: shef_structs.h:106
FILE * lchn
Definition: shef_structs.h:72
FILE * icher
Definition: shef_structs.h:72
FILE * jchn
Definition: shef_structs.h:72
char product_name[30]
Definition: shef_structs.h:208
char err_file[MAX_F]
Definition: shef_structs.h:222
char shef_log[MAX_F]
Definition: shef_structs.h:221
char shef_in[MAX_F]
Definition: shef_structs.h:221
char dotbtemp[MAX_F]
Definition: shef_structs.h:222
char shef_out[MAX_F]
Definition: shef_structs.h:221
char shef_decode_err[MAX_F]
Definition: shef_structs.h:221