UPP  11.0.0
 All Data Structures Files Functions Pages
ZENSUN.f
Go to the documentation of this file.
1 
5 
62  subroutine zensun(day,time,lat,lon,pi,sun_zenith,sun_azimuth)
63 
64 !
65  use kinds, only: r_kind,i_kind
66 
67  implicit none
68 
69  integer(i_kind),intent(in):: day
70  real(r_kind),intent(in) :: pi,time,lat,lon
71  integer(i_kind) di
72  real(r_kind) z,gaz
73  real(r_kind) ut,noon
74  real(r_kind) y(5),y2(5),x(2,5),tx(5,2),xtx(2,2),atx(5,2),det
75  real(r_kind) tt,eqtime,decang,latsun,lonsun
76  real(r_kind) nday(74),eqt(74),dec(74)
77  real(r_kind) beta(2), beta2(2), a(2,2)
78  real(r_kind) t0,t1,p0,p1,zz,xx,yy
79  real(r_kind),intent(out) :: sun_zenith,sun_azimuth
80 
81  data nday/1.0, 6.0, 11.0, 16.0, 21.0, 26.0, 31.0, 36.0, 41.0, 46.0,&
82  51.0, 56.0, 61.0, 66.0, 71.0, 76.0, 81.0, 86.0, 91.0, 96.0,&
83  101.0, 106.0, 111.0, 116.0, 121.0, 126.0, 131.0, 136.0, 141.0, 146.0,&
84  151.0, 156.0, 161.0, 166.0, 171.0, 176.0, 181.0, 186.0, 191.0, 196.0,&
85  201.0, 206.0, 211.0, 216.0, 221.0, 226.0, 231.0, 236.0, 241.0, 246.0,&
86  251.0, 256.0, 261.0, 266.0, 271.0, 276.0, 281.0, 286.0, 291.0, 296.0,&
87  301.0, 306.0, 311.0, 316.0, 321.0, 326.0, 331.0, 336.0, 341.0, 346.0,&
88  351.0, 356.0, 361.0, 366.0/
89 
90  data eqt/ -3.23, -5.49, -7.60, -9.48,-11.09,-12.39,-13.34,-13.95,-14.23,-14.19,&
91  -13.85,-13.22,-12.35,-11.26,-10.01, -8.64, -7.18, -5.67, -4.16, -2.69,&
92  -1.29, -0.02, 1.10, 2.05, 2.80, 3.33, 3.63, 3.68, 3.49, 3.09,&
93  2.48, 1.71, 0.79, -0.24, -1.33, -2.41, -3.45, -4.39, -5.20, -5.84,&
94  -6.28, -6.49, -6.44, -6.15, -5.60, -4.82, -3.81, -2.60, -1.19, 0.36,&
95  2.03, 3.76, 5.54, 7.31, 9.04, 10.69, 12.20, 13.53, 14.65, 15.52,&
96  16.12, 16.41, 16.36, 15.95, 15.19, 14.09, 12.67, 10.93, 8.93, 6.70,&
97  4.32, 1.86, -0.62, -3.23/
98 
99  data dec/ -23.06,-22.57,-21.91,-21.06,-20.05,-18.88,-17.57,-16.13,-14.57,-12.91,&
100  -11.16, -9.34, -7.46, -5.54, -3.59, -1.62, 0.36, 2.33, 4.28, 6.19,&
101  8.06, 9.88, 11.62, 13.29, 14.87, 16.34, 17.70, 18.94, 20.04, 21.00,&
102  21.81, 22.47, 22.95, 23.28, 23.43, 23.40, 23.21, 22.85, 22.32, 21.63,&
103  20.79, 19.80, 18.67, 17.42, 16.05, 14.57, 13.00, 11.33, 9.60, 7.80,&
104  5.95, 4.06, 2.13, 0.19, -1.75, -3.69, -5.62, -7.51, -9.36,-11.16,&
105  -12.88,-14.53,-16.07,-17.50,-18.81,-19.98,-20.99,-21.85,-22.52,-23.02,&
106  -23.33,-23.44,-23.35,-23.06/
107 
108 !
109 ! compute the subsolar coordinates
110 !
111 
112  tt= mod(real((int(day)+time/24.-1.)),365.25) +1. ! fractional day number
113  ! with 12am 1jan = 1.
114  do di = 1, 73
115  if ((tt >= nday(di)) .and. (tt <= nday(di+1))) exit
116  end do
117 
118 !============== Perform a least squares regression on doy**3 ==============
119 
120  x(1,:) = 1.0
121 
122  if ((di >= 3) .and. (di <= 72)) then
123  y(:) = eqt(di-2:di+2)
124  y2(:) = dec(di-2:di+2)
125 
126  x(2,:) = nday(di-2:di+2)**3
127  end if
128  if (di == 2) then
129  y(1) = eqt(73)
130  y(2:5) = eqt(di-1:di+2)
131  y2(1) = dec(73)
132  y2(2:5) = dec(di-1:di+2)
133 
134  x(2,1) = nday(73)**3
135  x(2,2:5) = (365.+nday(di-1:di+2))**3
136  end if
137  if (di == 1) then
138  y(1:2) = eqt(72:73)
139  y(3:5) = eqt(di:di+2)
140  y2(1:2) = dec(72:73)
141  y2(3:5) = dec(di:di+2)
142 
143  x(2,1:2) = nday(72:73)**3
144  x(2,3:5) = (365.+nday(di:di+2))**3
145  end if
146  if (di == 73) then
147  y(1:4) = eqt(di-2:di+1)
148  y(5) = eqt(2)
149  y2(1:4) = dec(di-2:di+1)
150  y2(5) = dec(2)
151 
152  x(2,1:4) = nday(di-2:di+1)**3
153  x(2,5) = (365.+nday(2))**3
154  end if
155  if (di == 74) then
156  y(1:3) = eqt(di-2:di)
157  y(4:5) = eqt(2:3)
158  y2(1:3) = dec(di-2:di)
159  y2(4:5) = dec(2:3)
160 
161  x(2,1:3) = nday(di-2:di)**3
162  x(2,4:5) = (365.+nday(2:3))**3
163  end if
164 
165 ! Tx = transpose(x)
166  tx(1:5,1)=x(1,1:5)
167  tx(1:5,2)=x(2,1:5)
168 ! xTx = MATMUL(x,Tx)
169  xtx(1,1)=x(1,1)*tx(1,1)+x(1,2)*tx(2,1)+x(1,3)*tx(3,1)+x(1,4)*tx(4,1)+x(1,5)*tx(5,1)
170  xtx(1,2)=x(1,1)*tx(1,2)+x(1,2)*tx(2,2)+x(1,3)*tx(3,2)+x(1,4)*tx(4,2)+x(1,5)*tx(5,2)
171  xtx(2,1)=x(2,1)*tx(1,1)+x(2,2)*tx(2,1)+x(2,3)*tx(3,1)+x(2,4)*tx(4,1)+x(2,5)*tx(5,1)
172  xtx(2,2)=x(2,1)*tx(1,2)+x(2,2)*tx(2,2)+x(2,3)*tx(3,2)+x(2,4)*tx(4,2)+x(2,5)*tx(5,2)
173 
174  det = xtx(1,1)*xtx(2,2) - xtx(1,2)*xtx(2,1)
175  a(1,1) = xtx(2,2)/det
176  a(1,2) = -xtx(1,2)/det
177  a(2,1) = -xtx(2,1)/det
178  a(2,2) = xtx(1,1)/det
179 
180 ! aTx = MATMUL(Tx,a)
181  atx(1,1)=tx(1,1)*a(1,1)+tx(1,2)*a(2,1)
182  atx(2,1)=tx(2,1)*a(1,1)+tx(2,2)*a(2,1)
183  atx(3,1)=tx(3,1)*a(1,1)+tx(3,2)*a(2,1)
184  atx(4,1)=tx(4,1)*a(1,1)+tx(4,2)*a(2,1)
185  atx(5,1)=tx(5,1)*a(1,1)+tx(5,2)*a(2,1)
186  atx(1,2)=tx(1,1)*a(1,2)+tx(1,2)*a(2,2)
187  atx(2,2)=tx(2,1)*a(1,2)+tx(2,2)*a(2,2)
188  atx(3,2)=tx(3,1)*a(1,2)+tx(3,2)*a(2,2)
189  atx(4,2)=tx(4,1)*a(1,2)+tx(4,2)*a(2,2)
190  atx(5,2)=tx(5,1)*a(1,2)+tx(5,2)*a(2,2)
191 
192 ! beta = MATMUL(y,aTx)
193  beta(1) = y(1)*atx(1,1)+y(2)*atx(2,1)+y(3)*atx(3,1)+y(4)*atx(4,1)+y(5)*atx(5,1)
194  beta(2) = y(1)*atx(1,2)+y(2)*atx(2,2)+y(3)*atx(3,2)+y(4)*atx(4,2)+y(5)*atx(5,2)
195 
196 ! beta2 = MATMUL(y2,aTx)
197  beta2(1) = y2(1)*atx(1,1)+y2(2)*atx(2,1)+y2(3)*atx(3,1)+y2(4)*atx(4,1)+y2(5)*atx(5,1)
198  beta2(2) = y2(1)*atx(1,2)+y2(2)*atx(2,2)+y2(3)*atx(3,2)+y2(4)*atx(4,2)+y2(5)*atx(5,2)
199 
200 !============== finished least squares regression on doy**3 ==============
201 
202  if ((di < 3) .or. (di > 72)) tt = tt + 365.
203 
204  eqtime=(beta(1) + beta(2)*tt**3)/60.
205  decang=beta2(1) + beta2(2)*tt**3
206  latsun=decang
207 
208  ut=time
209  noon=12.-lon/15. ! universal time of noon
210 
211  lonsun=-15.*(ut-12.+eqtime)
212 
213  t0=(90.-lat)*pi/180.
214  t1=(90.-latsun)*pi/180.
215 
216  p0=lon*pi/180.
217  p1=lonsun*pi/180.
218 
219  zz=cos(t0)*cos(t1)+sin(t0)*sin(t1)*cos(p1-p0)
220 ! zz2=sin(t0)*sin(t1)+cos(t0)*cos(t1)*cos(p1-p0)
221  xx=sin(t1)*sin(p1-p0)
222  yy=sin(t0)*cos(t1)-cos(t0)*sin(t1)*cos(p1-p0)
223 
224  sun_zenith=90-acos(zz)/(pi/180)
225  sun_azimuth=atan2(xx,yy)/(pi/180)
226 
227  return
228 end subroutine zensun
subroutine zensun(day, time, lat, lon, pi, sun_zenith, sun_azimuth)
This subroutine computes solar position information as a function of geographic coordinates, date and time.
Definition: ZENSUN.f:62