Mapper
shtadj.c
Go to the documentation of this file.
1 /*Translated by FOR_C, v3.4.2 (-), on 06/07/94 at 17:03:02 */
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 "shef_structs_external.h"
15 
16 /*-------------------------------------------------------------------
17 
18  NAME
19  SUBROUTINE SHTADJ(LYEAR,LMON,LDAY,LHOUR,LMIN,LSEC,KADJ,IADJ,STATUS)
20 
21  PURPOSE
22  This routine makes adjustments to the current date/time
23  by adding the value of IADJ. The units of LADJ are given
24  in the code IADJ where:
25  1 = MINUTES
26  2 = HOURS
27  3 = DAYS
28  4 = MONTHS
29  5 = YEARS
30  6 = MONTHS; END OF MONTH
31  7 = SECONDS
32 
33  It is intended that the range of the value LADJ
34  be plus/minus 99, except for minutes where the range
35  may be plus/minus 1440. Also the value of the year
36  may not change by more than one.
37 
38  VERSION and UPDATES
39  1.0 JUL 82 GEOFFREY M BONNIN MBRFC
40  1.1 JAN 84
41  Correct year change problem when adjusting days
42  1.2 AUG 84
43  Add seconds to times
44  1.3 MAY 85
45  Don't go past 1999
46  2.0 JUN 94 David G. Brandon
47  Allow for years 2000 - 2020
48  Also Translated to 'C' using FOR_C
49  Removed alternate returns for subroutine
50 
51  --------------------------------------------------------------------- */
52 
53 void shtadj(lyear, lmon, lday, lhour, lmin, lsec, kadj, iadj, status)
54 short int *lyear, *lmon, *lday, *lhour, *lmin, *lsec, *kadj, *iadj,
55  *status;
56 {
57  static short int ia, ladj, leap, flag;
58 
59  /* OFFSET Vectors w/subscript range: 1 to dimension */
60  short *const Iday = &days_.iday[0] - 1;
61 
62  *status = 0;
63 
64  /* Is there an adjustment to make? */
65 
66  if( *kadj == 0 )
67  goto L_900;
68  ladj = *kadj;
69 
70  /* Check IADJ to see what's being adjusted */
71 
72  switch( *iadj )
73  {
74  case 1: goto L_100;
75  case 2: goto L_200;
76  case 3: goto L_300;
77  case 4: goto L_400;
78  case 5: goto L_500;
79  case 6: goto L_600;
80  case 7: goto L_50;
81  }
82 
83  /* Adjusting seconds */
84 
85 L_50:
86  *lsec = *lsec + ladj;
87  if( *lsec < 60 )
88  goto L_60;
89  ladj = *lsec/60;
90  *lsec = *lsec - ladj*60;
91  goto L_100;
92 
93 L_60:
94  if( *lsec >= 0 )
95  goto L_900;
96  ladj = (*lsec - 60)/60;
97  *lsec = *lsec - ladj*60;
98  if( *lsec != 60 )
99  goto L_100;
100  *lsec = 0;
101  ladj = ladj + 1;
102 
103  /* Adjusting minutes */
104 
105 L_100:
106  *lmin = *lmin + ladj;
107  if( *lmin < 60 )
108  goto L_110;
109  ladj = *lmin/60;
110  *lmin = *lmin - ladj*60;
111  goto L_200;
112 
113 L_110:
114  if( *lmin >= 0 )
115  goto L_900;
116  ladj = (*lmin - 60)/60;
117  *lmin = *lmin - ladj*60;
118  if( *lmin != 60 )
119  goto L_200;
120  *lmin = 0;
121  ladj = ladj + 1;
122 
123  /* Adjusting hours */
124 
125 L_200:
126  *lhour = *lhour + ladj;
127  if( *lhour < 24 )
128  goto L_210;
129  ladj = *lhour/24;
130  *lhour = *lhour - ladj*24;
131  goto L_300;
132 
133 L_210:
134  if( *lhour >= 0 )
135  goto L_900;
136  ladj = (*lhour - 24)/24;
137  *lhour = *lhour - ladj*24;
138  if( *lhour != 24 )
139  goto L_300;
140  *lhour = 0;
141  ladj = ladj + 1;
142 
143  /* Adjusting days
144  * Calculate if the current year is a leap year */
145 
146 L_300:
147  shleap( lyear, &leap );
148 
149  /* Calculate the ordinal day of this year */
150 
151  ia = 30*(*lmon + 2) + (55*(*lmon + 2))/100 - 2*((*lmon + 10)/13) -
152  91 + (leap*(*lmon + 10))/13 + *lday;
153 
154  /* Adjust it */
155 
156  ia = ia + ladj;
157  if( ia <= (365 + leap) )
158  goto L_310;
159  ladj = 1;
160  ia = ia - 365 - leap;
161  leap = 1 - leap;
162  shcal( &ia, &leap, lmon, lday );
163  goto L_500;
164 
165 L_310:
166  if( ia <= 0 )
167  goto L_320;
168  shcal( &ia, &leap, lmon, lday );
169  goto L_900;
170 
171 L_320:
172  ladj = -1;
173  leap = 1 - leap;
174  ia = ia + 365 + leap;
175  shcal( &ia, &leap, lmon, lday );
176  goto L_500;
177 
178  /* Adjusting months */
179 
180 L_400:
181  *lmon = *lmon + ladj;
182  if( *lmon < 13 )
183  goto L_410;
184  ladj = *lmon/12;
185  *lmon = *lmon - ladj*12;
186  if( *lmon != 0 )
187  goto L_500;
188  *lmon = 12;
189  ladj = ladj - 1;
190  goto L_500;
191 
192 L_410:
193  if( *lmon > 0 )
194  goto L_900;
195  ladj = (*lmon - 12)/12;
196  *lmon = *lmon - ladj*12;
197 
198  /* Adjusting the year */
199 
200 L_500:
201  *lyear = *lyear + ladj;
202  /* dgb 032494 */
203 
204  /*
205  if( (*lyear > 20) && (*lyear < 76) )
206  {
207  goto L_9010;
208  }
209  */
210  goto L_900;
211 
212  /* Adjusting months; End of month
213  * Is this acutally the end of a month? */
214 
215 L_600:
216  leap = 0;
217  if( *lmon != 2 )
218  goto L_610;
219  shleap( lyear, &leap );
220 
221 L_610:
222  ia = Iday[*lmon] + leap;
223  if( ia != *lday )
224  goto L_9000; /* NO IT'S NOT */
225 
226  /* Yes it is - adjust it */
227 
228  *lmon = *lmon + ladj;
229  if( *lmon < 13 )
230  goto L_620;
231  ladj = *lmon/12;
232  *lmon = *lmon - ladj*12;
233  if( *lmon != 0 )
234  goto L_630;
235  *lmon = 12;
236  ladj = ladj - 1;
237  goto L_630;
238 
239 L_620:
240  if( *lmon > 0 )
241  goto L_640;
242  ladj = (*lmon - 12)/12;
243  *lmon = *lmon - ladj*12;
244 
245  /* Do the year */
246 
247 L_630:
248  *lyear = *lyear + ladj;
249 
250  /* Now get the correct day */
251 
252 L_640:
253  leap = 0;
254  if( *lmon != 2 )
255  goto L_650;
256  shleap( lyear, &leap );
257 
258 L_650:
259  *lday = Iday[*lmon] + leap;
260 
261  /* Return */
262 
263 L_900:
264  return;
265 
266 L_9000:
267  flag = 36;
268  sherr( &flag );
269  *status = 1;
270  return;
271 /*
272 L_9010:
273  flag = 22;
274  sherr( &flag );
275  *status = 1;
276  return;
277 */
278 
279 }
280 
void shcal(short int *iord, short int *leap, short int *lmon, short int *lday)
Definition: shcal.c:35
struct t_days_ days_
void sherr(short int *ier)
Definition: sherr.c:44
void shleap(short int *lyear, short int *leap)
Definition: shleap.c:42
void * leap
Definition: shleap.cc:39
ia
Definition: shleap.cc:45
void shtadj(short int *lyear, short int *lmon, short int *lday, short int *lhour, short int *lmin, short int *lsec, short int *kadj, short int *iadj, short int *status)
Definition: shtadj.c:53
short int iday[12]
Definition: shef_structs.h:171