Mapper
borshef.c
Go to the documentation of this file.
1 
2 #include "prototypes.h"
3 #define ID_PROMPT "Station:"
4 #define DTYPE_PROMPT "DAY"
5 
6 char dtype2[16][9];
7 char pe[16][4];
8 char id_bor[35][5];
9 char id5[35][9];
10 char name[35][30];
11 
12 main(int argc, char *argv[])
13 {
14 FILE *fp, *fp2, *fp3, *fp4,*fq;
15 char buffer[131];
16 char id4[5];
17 char month[4];
18 char *ptdt;
19 char fname[100];
20 char *directory;
21 char dtype[10][11];
22 int year,date,i,j,k,l,start_day,end_day,date_s;
23 int divide[10];
24 int conver[10];
25 int ier;
26 int tim(void);
27 int matchid(char *);
28 int matchpe(char *);
29 void get_data(char [], FILE *, FILE *,int, char [], int, int, int, int [], int []);
30 void ffeed(FILE *, FILE *);
31 
32  date = tim(); /* get date in a form mmdd */
33 
34  start_day=0;
35 
36  end_day= (date - (date/100)*100) - 1;
37 
38  ier=system("rcp lasal:/users/ftp/pub/incoming/bor/borvax.dat wasatch:/usr/db/raw/borshef/data/vax.dat");
39 
40  if(ier != 0) {
41 
42  printf("There has been an error copying\nlasal:/users/ftp/pub/incoming/bor/borvax.dat\n to wasatch:/usr/db/raw/borshef/data/vax.dat");
43 
44  exit(1);
45 
46  }
47 
48  directory="/usr/db/raw/borshef/data/";
49 
50  strcpy(fname,directory);
51  strcat(fname,"vax.dat");
52 
53  if((fp = fopen(fname,"r")) == NULL) {
54 
55  printf("There has been an error opening %s\n",fname);
56  exit(1);
57 
58  }
59 
60  strcpy(fname,directory);
61  strcat(fname,"vax.laser");
62 
63  if((fp2 = fopen(fname,"w")) == NULL) {
64 
65  printf("There has been an error opening %s\n",fname);
66  exit(1);
67 
68  }
69 
70  strcpy(fname,directory);
71  strcat(fname,"idees.dat");
72 
73  if((fp3 = fopen(fname,"r")) == NULL) {
74 
75  printf("There has been an error opening %s\n",fname);
76  exit(1);
77 
78  }
79 
80  strcpy(fname,directory);
81  strcat(fname,"dtypes.dat");
82 
83  if((fp4 = fopen(fname,"r")) == NULL) {
84 
85  printf("There has been an error opening %s\n",fname);
86  exit(1);
87 
88  }
89 
90  strcpy(fname,directory);
91  strcat(fname,"vax.out");
92 
93  if((fq = fopen(fname,"w")) == NULL) {
94 
95  printf("There has been an error opening %s\n",fname);
96  exit(1);
97 
98  }
99 
100  /* read BOR id's and their corr. 5CHID's */
101 
102  j=0;
103  while(fscanf(fp3,"%s %s %s\n", id_bor[j], id5[j], name[j]) != EOF)
104  j++;
105 
106  /* read BOR data types and match them to PEDTSEPs */
107 
108  j=0;
109  while(fscanf(fp4,"%s %s\n", dtype2[j], pe[j]) != EOF)
110  j++;
111  /* read input file from BOR line by line */
112 
113  while(fgets(buffer,134,fp) != NULL)
114 
115  {
116  /* checks buffer for ID_PROMPT */
117 
118  if(strstr(buffer,ID_PROMPT))
119  {
120  sscanf(buffer,"%*s %s", id4); /* get BOR 4 ch ID */
121  l = matchid(id4); /* match it to 5CHID */
122  fgets(buffer,134,fp);
123  sscanf(buffer,"Data for the month of: %s %d",month, &year);
124  }
125 
126  /* checks buffer for DTYPE_PROMPT */
127 
128  else if(strstr(buffer,DTYPE_PROMPT))
129  {
130  i = sscanf(buffer,"%*s %s %s %s %s %s %s %s %s %s %s %s",
131  dtype[0],dtype[1],dtype[2],dtype[3],dtype[4],dtype[5],
132  dtype[6],dtype[7],dtype[8],dtype[9],dtype[10]);
133 
134  fprintf(fq,".BR SLR %4.4d Z DC%4.4d/DH06",date,date);
135 
136  /* since the date is overwritten, the 1st date does not matter */
137 
138  for(j=0;j<i;j++)
139  {
140 
141  divide[j]=0;
142  conver[j]=0;
143  ptdt = dtype[j];
144  k = matchpe(ptdt);
145 
146  /* precip and temp reported under BORid FTRW are nws5id FNTW4
147  whereas all other parameters belong to nws5id GBRW4 */
148 
149  if(strcmp(id5[l],"GBRW4") == 0 &&
150  (strcspn(pe[k],"P") == 0 ||
151  strcspn(pe[k],"T") == 0))
152  memcpy(id5[l],"FNTW4",6);
153 
154  /* pc & temp should be blnn5 */
155 
156  if(strcmp(id5[l],"NVRN5") == 0 &&
157  (strcspn(pe[k],"P") == 0 ||
158  strcspn(pe[k],"T") == 0))
159  memcpy(id5[l],"BLNN5",6);
160 
161  /* duchesne diversion reported under BORid JDRU but needs nws5id DCTU1*/
162 
163  if(strcmp(id5[l],"JRRU1") == 0 &&
164  (strcmp(pe[k],"DUC") == 0))
165  {
166  memcpy(id5[l],"DCTU1",6);
167  memcpy(pe[k],"QDD",4);
168  }
169 
170  /* weber diversion reported under BORid JDRU but needs nws5id WPCU1*/
171 
172  if(strcmp(id5[l],"DCTU1") == 0 &&
173  (strcmp(pe[k],"WEB") == 0))
174  {
175  memcpy(id5[l],"WPCU1",6);
176  memcpy(pe[k],"QDD",4);
177  }
178 
179  if(strcspn(pe[k],"Q")==0 ||
180  strcspn(pe[k],"L")==0)
181  divide[j]=1;
182 
183  if(strcspn(pe[k],"Q")==0 &&
184  strstr(pe[k],"M") != NULL)
185  conver[j]=1;
186 
187  fprintf(fq,"/ %s ",pe[k]);
188 
189  }
190 
191  fprintf(fq,"\n");
192  get_data(month,fp,fq,year,id5[l],i,
193  start_day,end_day,divide,conver);
194  }
195 
196  }
197 
198  ffeed(fp,fp2);
199 
200  fclose(fq);
201 
202  ier=system("cp /usr/db/raw/borshef/data/vax.out /tmp/queue/shef/in/vax.out");
203 
204  if(ier!=0) {
205 
206  printf("There has been an error copying\n lasal:/users/ftp/pub/incoming/bor/borvax.dat to\n/tmp/queue/shef/in/vax.out\n");
207  exit(1);
208 
209  }
210 
211  ier=system("mpage -4b -W84 /usr/db/raw/borshef/data/vax.laser");
212  if(ier!=0) {
213 
214  printf("There has been an error printing /usr/db/raw/borshef/data/vax.laser\n");
215 
216  exit(1);
217 
218  }
219 
220 
221  ier=system("rcp lasal:/users/ftp/pub/incoming/bor/borvax.dat lasal:/users/ftp/pub/incoming/bor/old/borvax.dat");
222 
223  if(ier != 0) {
224 
225  printf("There has been an error copying\nlasal:/users/ftp/pub/incoming/bor/borvax.dat to\nlasal:/users/ftp/pub/incoming/bor/old/borvax.dat\n");
226 
227  exit(1);
228 
229  }
230 
231  ier=system("rsh lasal rm /users/ftp/pub/incoming/bor/borvax.dat");
232 
233  if(ier != 0) {
234 
235  printf("There has been an error deleting\nlasal:/users/ftp/pub/incoming/bor/borvax.dat\n");
236 
237  exit(1);
238 
239  }
240 
241 }
242 
243 matchpe(char *type)
244 
245 {
246 int i;
247 
248 for(i=0;i<16;i++)
249  if(strcmp(type,dtype2[i]) == 0)
250  return i;
251 }
252 
253 matchid(char *id4)
254 
255 {
256 int i;
257 
258 for(i=0;i<35;i++)
259 if(strcmp(id4,id_bor[i]) == 0)
260  return i;
261 
262 }
263 
264 void ffeed(FILE *fp, FILE *fp2)
265 
266 {
267 char buffer[131];
268 char id4[5];
269 int l;
270 
271 rewind(fp);
272 while(fgets(buffer,134,fp) != NULL)
273  {
274  if(strstr(buffer,ID_PROMPT)) /* checks buffer for ID_PROMPT */
275  {
276  sscanf(buffer,"%*s %s",id4);
277  l = matchid(id4);
278  fprintf(fp2,"\f\n%s (BOR id: %s)\n",name[l],id4);
279  }
280  else
281  fputs(buffer,fp2);
282  }
283 }
#define ID_PROMPT
Definition: borshef.c:3
char id5[35][9]
Definition: borshef.c:9
matchpe(char *type)
Definition: borshef.c:243
matchid(char *id4)
Definition: borshef.c:253
void ffeed(FILE *fp, FILE *fp2)
Definition: borshef.c:264
char dtype2[16][9]
Definition: borshef.c:6
char name[35][30]
Definition: borshef.c:10
char id_bor[35][5]
Definition: borshef.c:8
char pe[16][4]
Definition: borshef.c:7
#define DTYPE_PROMPT
Definition: borshef.c:4
main(int argc, char *argv[])
Definition: borshef.c:12
static int i
char directory[100]
Definition: decode_HDP.c:3
int year
Definition: display_data.c:26
int month
Definition: display_data.c:26
get_data(char month[4], FILE *fp, FILE *fq, int year, char id[9], int numpe, int s_day, int e_day, int divide[10], int conver[10])
Definition: get_data.c:6
fclose(fp)
printf("fbuf is %s\n", fbuf)
fp
Definition: make_NEXRAD.c:339
system(tarbuf)
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
int j
Definition: mapp2h.h:48
int k
Definition: mapp2h.h:48
int end_day
Definition: mapper.c:67
char fname[100]
Definition: send_afos.c:6
tim()
Definition: tim.c:4