Mapper
shpos.c
Go to the documentation of this file.
1 /*Translated by FOR_C, v3.4.2 (-), on 04/06/95 at 13:56:21 */
2 /*FOR_C Options SET: c=2 com=u do=r44 ftn=ln6kk op=iv s=dvnk str=l sq=i */
3 #define _POSIX_SOURCE
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <ctype.h>
7 #include <dirent.h>
8 #include <unistd.h>
9 #include <math.h>
10 #include <string.h>
11 #include <fcntl.h>
12 #include <sys/stat.h>
13 #include "shef_structs_external.h"
14 
15 /*---------------------------------------------------------------------
16 
17  NAME
18  SUBROUTINE SHPOS(STATUS)
19 
20  PURPOSE
21  This routine decodes the positional fields of the SHEF
22  format. It returns the positional data in the common block
23  data.
24 
25  VERSION and UPDATES
26  1.0 MAY 82 Geoffrey M. Bonnin
27  Original Version
28  1.1 AUG 84
29  Add seconds to time
30  2.0 MAY 94 David G. Brandon
31  Also Translated to 'C' using FOR_C
32  2.1 OCT 95 DGB
33  Allow an underscore '_' as part of the id.
34  2.4 JAN 96 DGB
35  Update struct t_data to include lcent (century).
36  2.5 FEB 11, 96
37  Make strucutural changes to accomodate century
38  in the positional date field.
39  2.6 OCT 19 97 DGB
40  Fix Msource or source for .B type messages.
41  Remove a couple of unused variables e.g. _l0.
42  2.7 DEC 21 97 DGB
43  Add centflag..set to 1 if an explicit century is
44  specified in the postitional data.
45  2.8 JAN 17 98 DGB
46  Add yearflag...set to 1 if explicit year is specified
47  in positional data.
48  2.9 JAN 07 99 dgb
49  Add check if century is missing and year is 00
50  set century to 20...even if century from system
51  clock is 19.
52  3.0 JAN 18 99 DGB
53  Fix century/year overrides for certain cases when the
54  century/year is not explicitly stated in the positional data.
55  3.1 APR 12 99 DGB
56  Fix obscure error of identifying the source for a .BR
57  message.
58 
59  *--------------------------------------------------------------------- */
60 
61 
62 void shpos(status)
63 short int *status;
64 {
65  static short int i, itest, lchar, nchar, ndig, nflag, num;
66  static short int total_ndig; /* dgb:021196 add */
67 
68  /* OFFSET Vectors w/subscript range: 1 to dimension */
69  short *const Idate = &datim_.idate[0] - 1;
70  short *const Idstn = &data_.idstn[0] - 1;
71  short *const Msource = &data_.msource[0] - 1;
72  *status = 0;
73  data_.lhour = 12; /*12 zulu default */
74  data_.lmin = 0;
75  data_.lsec = 0;
76  data_.nadjtz = 0;
77  Idstn[1] = codes_.iblnk;
78  Idstn[2] = codes_.iblnk;
79  Idstn[3] = codes_.iblnk;
80  Idstn[4] = codes_.iblnk;
81  Idstn[5] = codes_.iblnk;
82  Idstn[6] = codes_.iblnk;
83  Idstn[7] = codes_.iblnk;
84  Idstn[8] = codes_.iblnk;
85  data_.posovercentury = -1; /* dgb:01/18/99 */
86  data_.posoveryear = -1; /* dgb:01/18/99 */
87 
88  /* Get the station Source, there should be a blank */
89 
90  if( xchar_.ichar != codes_.iblnk )
91  goto L_260;
92 L_10:
93  nextch( &xchar_.ichar, status );
94  if( *status == 1 )
95  {
96  *status = 0;
97  goto L_9000;
98  }
99  else if( *status == 2 )
100  {
101  *status = 0;
102  goto L_9010;
103  }
104  if( xchar_.ichar == codes_.iblnk )
105  goto L_10;
106 
107  /* Read up to 8 characters , checking for legit ones */
108 
109  nchar = 0;
110 
111  for( i = 1; i <= 8; i++ )
112  {
113 
114  /* CALL IRANG(ICHAR,ICHA,ICHZ,*15) ! CHECK IF A-Z */
115  irang( &xchar_.ichar, &codes_.icha, &codes_.ichz, status ); /* CHECK IF A-Z */
116  if( *status == 1 )
117  {
118  *status = 0;
119  goto L_15;
120  }
121  goto L_17;
122 
123  /* 15 CALL IRANG(ICHAR,ICH0,ICH9,*250) ! CHECK IF 0-9 */
124 L_15:
125  irang( &xchar_.ichar, &codes_.ich0, &codes_.ich9, status ); /* CHECK IF 0-9 */
126  if( *status == 1 )
127  {
128  *status = 0;
129  goto L_16;
130  }
131  goto L_17;
132 
133 L_16:
134  if ( xchar_.ichar == codes_.iscore ) /* dgb: 10/18/95 DGB */
135  goto L_17;
136  else
137  goto L_250;
138 
139 L_17:
140 
141  if ( format_.iform == 3 || format_.iform == 4 ) /* dgb:04/12/99 */
142  Msource[i] = xchar_.ichar; /* dgb:10/19/97 */
143  else /* dgb:10/19/97 */
144  Idstn[i] = xchar_.ichar; /* dgb:10/19/97 */
145 
146  nchar = nchar + 1;
147  nextch( &xchar_.ichar, status );
148  if( *status == 1 )
149  {
150  *status = 0;
151  goto L_9000;
152  }
153  else if( *status == 2 )
154  {
155  *status = 0;
156  goto L_9010;
157  }
158  if( xchar_.ichar == codes_.iblnk )
159  goto L_30;
160  }
161 
162  if( xchar_.ichar != codes_.iblnk )
163  goto L_260;
164 
165 L_30:
166  if( nchar < 3 )
167  goto L_220;
168  goto L_50;
169 
170  /* Find the data group */
171 
172 L_40:
173  if( xchar_.ichar != codes_.iblnk )
174  goto L_60;
175 L_50:
176  nextch( &xchar_.ichar, status );
177  if( *status == 1 )
178  {
179  *status = 0;
180  goto L_9000;
181  }
182  else if( *status == 2 )
183  {
184  *status = 0;
185  goto L_9010;
186  }
187  goto L_40;
188 
189  /* Decode the date group */
190  /* Get the first two digits */
191 
192 L_60:
193  ndig = 2;
194  shint( &data_.lcent, &ndig, 0, status );
195  if( *status == 1 )
196  {
197  *status = 0;
198  goto L_9000;
199  }
200  else if( *status == 2 )
201  {
202  *status = 0;
203  goto L_9010;
204  }
205  else if( *status == 3 )
206  {
207  *status = 0;
208  goto L_240;
209  }
210  total_ndig = 2;
211  data_.centflag = 1; /* dgb:12/21/97 */
212 
213  /* Get the next two digits */
214  ndig = 2;
215  shint( &data_.lyear, &ndig, 1, status );
216  if( *status == 1 )
217  {
218  *status = 0;
219  goto L_9000;
220  }
221  else if( *status == 2 )
222  {
223  *status = 0;
224  goto L_9010;
225  }
226  else if( *status == 3 )
227  {
228  *status = 0;
229  goto L_240;
230  }
231  total_ndig = total_ndig + 2;
232 
233  /* Get the next two digits */
234 
235  ndig = 2;
236  shint( &data_.lmon, &ndig, 1, status );
237  if( *status == 1 )
238  {
239  *status = 0;
240  goto L_9000;
241  }
242  else if( *status == 2 )
243  {
244  *status = 0;
245  goto L_9010;
246  }
247  else if( *status == 3 )
248  {
249  *status = 0;
250  nflag = 0;
251  goto L_75;
252  }
253  total_ndig = total_ndig + 2;
254 
255  /* Get the last two digits */
256 
257  ndig = 2;
258  shint( &data_.lday, &ndig, 1, status );
259  if( *status == 1 )
260  {
261  *status = 0;
262  goto L_9000;
263  }
264  else if( *status == 2 )
265  {
266  *status = 0;
267  goto L_9010;
268  }
269  else if( *status == 3 )
270  {
271  *status = 0;
272  nflag = 0;
273  goto L_75;
274  }
275  total_ndig = total_ndig + 2;
276  nflag = 1;
277 
278  /* if 8 digits decode -> CCYRMMDD */
279  /* If 6 digits decode -> YRMMDD */
280  /* If 4 digits decode -> MMDD */
281  /* any other combination -> error */
282 
283 L_75:
284  if ( total_ndig == 8 )
285  {
287  data_.lmon = data_.lmon;
288  data_.lday = data_.lday;
289  }
290  else
291  if ( total_ndig == 6 )
292  {
293  data_.lday = data_.lmon;
294  data_.lmon = data_.lyear;
296  data_.lcent = -1;
297  data_.posovercentury = -1; /* dgb:01/18/99 */
298  }
299  else
300  if ( total_ndig == 4 )
301  {
302  data_.lmon = data_.lcent;
303  data_.lday = data_.lyear;
304  data_.lcent = -1;
305  data_.lyear = -1;
306  data_.posovercentury = -1; /* dgb:01/18/99 */
307  data_.posoveryear = -1; /* dgb:01/18/99 */
308  }
309  else
310  goto L_240;
311 
312  /* Now default/compute the century and year if needed */
313 
314  if ( data_.lcent == -1 )
315  {
316  if ( data_.lyear >= 0 ) /* dgb:01/07/99 */
317  {
318  if ( data_.lyear <= 30 )
319  data_.lcent = 20; /* dgb:01/07/99 */
320  else
321  data_.lcent = 19;
322  }
323  data_.centflag = -1; /* dgb:12/21/97 */
324  }
325  else
326  {
328  data_.centflag = 1; /* dgb:12/21/97 */
329  }
330 
331  data_.yearflag = 1; /* dgb:01/17/98 */
332  if ( data_.lyear == -1 )
333  {
334  data_.yearflag = -1; /* dgb: 01/18/98 */
335 /* data_.lyear = Idate[3] - ( data_.lcent * 100 ); */
336  data_.lyear = Idate[3] - ( (int) (Idate[3]/100) ) * 100;
337 
338  if ( data_.lyear >= 0 )
339  {
340  if ( data_.lyear <= 30 )
341  data_.lcent = 20;
342  else
343  data_.lcent = 19;
344  }
345  data_.lyear = (data_.lcent * 100) + data_.lyear;
346 
347  itest = data_.lmon - Idate[1];
348  if( itest > 6 )
349  data_.lyear = data_.lyear - 1;
350  if( itest < -6 )
351  data_.lyear = data_.lyear + 1;
352  if( (itest == -6) && (data_.lday < Idate[2]) )
353  data_.lyear = data_.lyear + 1;
354  if( (itest == 6) && (data_.lday > Idate[2]) )
355  data_.lyear = data_.lyear - 1;
356  }
357  else
358  data_.lyear = ( data_.lcent * 100 ) + data_.lyear; /* dgb:01/18/99 */
359 
360  /* Test for bad date */
361 
362 /* L_77: */
363 
364  shtdat( &data_.lyear, &data_.lmon, &data_.lday, status );
365  if( *status == 1 )
366  {
367  *status = 0;
368  goto L_240;
369  }
370 
371  /* Find the time zone group (OPTIONAL) */
372 
373  if( nflag == 0 )
374  goto L_78;
375  nextch( &xchar_.ichar, status );
376  if( *status == 1 )
377  {
378  *status = 0;
379  goto L_9000;
380  }
381  else if( *status == 2 )
382  {
383  *status = 0;
384  goto L_9010;
385  }
386 L_78:
387  if( xchar_.ichar != codes_.iblnk )
388  goto L_260;
389 L_80:
390  nextch( &xchar_.ichar, status );
391  if( *status == 1 )
392  {
393  *status = 0;
394  goto L_9000;
395  }
396  else if( *status == 2 )
397  {
398  *status = 0;
399  goto L_9010;
400  }
401 
402  if( xchar_.ichar == codes_.iblnk )
403  goto L_80;
404  if( xchar_.ichar != codes_.ichz )
405  goto L_95; /* ZULU SPECIFIED */
406  nextch( &xchar_.ichar, status );
407  if( *status == 1 )
408  {
409  *status = 0;
410  goto L_9000;
411  }
412  else if( *status == 2 )
413  {
414  *status = 0;
415  goto L_9010;
416  }
417 
418 
419  goto L_205;
420 
421  /* Get the actual time zone */
422 
423 L_95:
424  if( xchar_.ichar != codes_.ichc )
425  goto L_100; /* CENTRAL TIME */
426  data_.nadjtz = 360;
427  goto L_180;
428 
429 L_100:
430  if( xchar_.ichar != codes_.iche )
431  goto L_110; /* EASTERN TIME */
432  data_.nadjtz = 300;
433  goto L_180;
434 
435 L_110:
436  if( xchar_.ichar != codes_.ichm )
437  goto L_120; /* MOUNTAIN TIME */
438  data_.nadjtz = 420;
439  goto L_180;
440 
441 L_120:
442  if( xchar_.ichar != codes_.icha )
443  goto L_130; /* ATLANTIC TIME */
444  data_.nadjtz = 240;
445  goto L_180;
446 
447 L_130:
448  if( xchar_.ichar != codes_.ichp )
449  goto L_140; /* PACIFIC TIME */
450  data_.nadjtz = 480;
451  goto L_180;
452 
453 L_140:
454  if( xchar_.ichar != codes_.ichl )
455  goto L_150; /* ALASKAN TIME */
456  data_.nadjtz = 600;
457  goto L_180;
458 
459 L_150:
460  if( xchar_.ichar != codes_.ichy )
461  goto L_160; /* YUKON TIME */
462  data_.nadjtz = 540;
463  goto L_180;
464 
465 L_160:
466  if( xchar_.ichar != codes_.ichh )
467  goto L_170; /* HAWAIIAN TIME */
468  data_.nadjtz = 600;
469  goto L_180;
470 
471 L_170:
472  if( xchar_.ichar != codes_.ichb )
473  goto L_175; /* BERING TIME */
474  data_.nadjtz = 660;
475  goto L_180;
476 
477 L_175:
478  if( xchar_.ichar != codes_.ichn )
479  goto L_210; /* NEWFOUNDLAND TIME */
480  data_.nadjtz = 210;
481 
482  /* Now check for daylight or standard time */
483 
484 L_180:
485  lchar = xchar_.ichar;
486  nextch( &xchar_.ichar, status );
487  if( *status == 1 )
488  {
489  *status = 0;
490  goto L_9000;
491  }
492  else if( *status == 2 )
493  {
494  *status = 0;
495  goto L_9010;
496  }
497 
498  if( xchar_.ichar != codes_.iblnk )
499  goto L_185;
500  if( (lchar == codes_.ichn) || (lchar == codes_.ichh) )
501  goto L_200;
503  goto L_200;
504 
505 L_185:
506  if( xchar_.ichar == codes_.ichs )
507  goto L_195;
508  if( xchar_.ichar != codes_.ichd )
509  goto L_230;
510  if( (lchar == codes_.ichn) || (lchar == codes_.ichh) )
511  goto L_195;
512  data_.nadjtz = data_.nadjtz - 60;
513 
514 L_195:
515  nextch( &xchar_.ichar, status );
516  if( *status == 1 )
517  {
518  *status = 0;
519  goto L_9000;
520  }
521  else if( *status == 2 )
522  {
523  *status = 0;
524  goto L_9010;
525  }
526 
527  /* Now default to 0000 */
528 
529 L_200:
530  data_.lhour = 24;
531 
532 L_205:
533  if( xchar_.ichar != codes_.iblnk )
534  goto L_260;
535 
536  /* Return options */
537 
538 L_210:
539  return;
540 
541 L_220:
542  num = 3; /*LESS THAN 3 CHARS IN ID OR MSG SOURCE */
543  goto L_300;
544 
545 L_230:
546  num = 4; /*TZ CODE ERROR */
547  goto L_300;
548 
549 L_240:
550  num = 5; /* DATE GROUP ERROR */
551  goto L_300;
552 
553 L_250:
554  num = 6; /* BAD CHAR IN MSG SOURCE OR STN ID */
555  goto L_300;
556 
557 L_260:
558  num = 2;
559 
560 L_300:
561  sherr( &num );
562  format_.nerr = 1;
563 
564 L_9000:
565  *status = 1;
566  return;
567 
568  /* File read error */
569 
570 L_9010:
571  *status = 2;
572  return;
573 
574 }
575 
static int i
void irang(short int *i, short int *min_, short int *max_, short int *status)
Definition: irang.c:33
void nextch(short int *ichar, short int *status)
Definition: nextch.c:76
struct t_datim_ datim_
struct t_codes_ codes_
struct t_data_ data_
struct t_format_ format_
struct t_xchar_ xchar_
void sherr(short int *ier)
Definition: sherr.c:44
void shint(short int *inum, short int *ndig, short int iflag, short int *status)
Definition: shint.c:37
void shpos(short int *status)
Definition: shpos.c:62
void shtdat(short int *lyear, short int *lmon, short int *lday, short int *status)
Definition: shtdat.c:30
short int iblnk
Definition: shef_structs.h:81
short int iche
Definition: shef_structs.h:78
short int ichl
Definition: shef_structs.h:79
short int ichs
Definition: shef_structs.h:79
short int ichz
Definition: shef_structs.h:80
short int ichy
Definition: shef_structs.h:80
short int ich0
Definition: shef_structs.h:80
short int ichd
Definition: shef_structs.h:78
short int ichm
Definition: shef_structs.h:79
short int ichc
Definition: shef_structs.h:78
short int icha
Definition: shef_structs.h:78
short int ichp
Definition: shef_structs.h:79
short int ichh
Definition: shef_structs.h:78
short int iscore
Definition: shef_structs.h:82
short int ich9
Definition: shef_structs.h:81
short int ichn
Definition: shef_structs.h:79
short int ichb
Definition: shef_structs.h:78
short int lmon
Definition: shef_structs.h:177
short int msource[8]
Definition: shef_structs.h:181
short int lcent
Definition: shef_structs.h:177
short int posoveryear
Definition: shef_structs.h:191
short int nadjtz
Definition: shef_structs.h:181
short int lyear
Definition: shef_structs.h:177
short int lsec
Definition: shef_structs.h:177
short int yearflag
Definition: shef_structs.h:186
short int lhour
Definition: shef_structs.h:177
short int lmin
Definition: shef_structs.h:177
short int idstn[8]
Definition: shef_structs.h:177
short int posovercentury
Definition: shef_structs.h:190
short int lday
Definition: shef_structs.h:177
short int centflag
Definition: shef_structs.h:184
short int idate[6]
Definition: shef_structs.h:100
short int nerr
Definition: shef_structs.h:129
short int iform
Definition: shef_structs.h:129
short int ichar
Definition: shef_structs.h:112