-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoy.pro
158 lines (143 loc) · 3.33 KB
/
doy.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
pro julian, day, mon, yr
if n_elements(yr) eq 0 then yr=1
if strlen(strcompress(mon, /remove_all)) lt 3 then begin
print, 'You entered : ', mon, ' : for the month'
return
endif
oldmon=mon
mon = strlowcase(mon)
mon = strmid(mon, 0, 3)
case mon of
'jan' : base=0
'feb' : base=31
'mar' : base=59
'apr' : base=90
'may' : base=120
'jun' : base=151
'jul' : base=181
'aug' : base=212
'sep' : base=243
'oct' : base=273
'nov' : base=304
'dec' : base=334
else : begin
print, 'You entered : ', oldmon, ' for the month.'
return
endelse
endcase
if ((yr mod 4) eq 0) and (mon ne 'jan') and (mon ne 'feb') then base=base+1
print, base+day
end
pro julianFromNum, day, mon, yr
if n_elements(yr) eq 0 then yr=1
if mon gt 12 then begin
print, 'You entered : ', mon, ' : for the month'
return
endif
case mon of
1 : base=0
2 : base=31
3 : base=59
4 : base=90
5 : base=120
6 : base=151
7 : base=181
8 : base=212
9 : base=243
10 : base=273
11 : base=304
12 : base=334
else : begin
print, 'You entered : ', mon, ' for the month.'
return
endelse
endcase
if ((yr mod 4) eq 0) and (mon le 2) then base=base+1
print, base+day
end
FUNCTION getDOY, day, mon, yr
if n_elements(yr) eq 0 then yr=1
if mon gt 12 then begin
print, 'You entered : ', mon, ' : for the month'
return, -1
endif
case mon of
1 : base=0
2 : base=31
3 : base=59
4 : base=90
5 : base=120
6 : base=151
7 : base=181
8 : base=212
9 : base=243
10 : base=273
11 : base=304
12 : base=334
else : begin
print, 'You entered : ', mon, ' for the month.'
return, 0
endelse
ENDCASE
;; leap year calculation (good for a few thousand years
;; so I won't worry about it just yet)
IF ((yr mod 4) eq 0) and (mon le 2) then BEGIN
base=base+1
IF ((yr MOD 100) EQ 0) AND ((year MOD 400) NE 0) THEN base=base-1
ENDIF
return, base+day
end
pro doy, day, mon
if n_elements(mon) GT 0 then begin
julian, day, mon
return
endif
if day lt 32 then begin
print, 'January : ', strcompress(string(day))
return
endif
if day lt 60 then begin
print, 'February : ', strcompress(string(day-31))
return
endif
if day lt 91 then begin
print, 'March : ', strcompress(string(day-59))
return
endif
if day lt 121 then begin
print, 'April : ', strcompress(string(day-90))
return
endif
if day lt 152 then begin
print, 'May : ', strcompress(string(day-120))
return
endif
if day lt 182 then begin
print, 'June : ', strcompress(string(day-151))
return
endif
if day lt 213 then begin
print, 'July : ', strcompress(string(day-181))
return
endif
if day lt 244 then begin
print, 'August : ', strcompress(string(day-212))
return
endif
if day lt 274 then begin
print, 'September : ', strcompress(string(day-243))
return
endif
if day lt 305 then begin
print, 'October : ', strcompress(string(day-273))
return
endif
if day lt 335 then begin
print, 'November : ', strcompress(string(day-304))
return
endif
if day lt 366 then begin
print, 'December : ', strcompress(string(day-334))
return
endif
end