1 | program angmom |
---|
2 | |
---|
3 | ! SL 12/2009: |
---|
4 | ! This program reads 4D (lon-lat-alt-time) fields directly from LMD (or CAM) outputs |
---|
5 | ! without regrid : histmth OR from files recast in log P coordinates (_P) |
---|
6 | ! (+ dynzon for LMD if present, but beware of recast consistency) |
---|
7 | ! |
---|
8 | ! it computes: |
---|
9 | ! dmass -- 4D -- mass of each cell |
---|
10 | ! osam -- 4D -- specific angular momentum (omega term) |
---|
11 | ! rsam -- 4D -- specific angular momentum (zonal wind term) |
---|
12 | ! oaam -- 1D -- integrated angular momentum (omega term) |
---|
13 | ! raam -- 1D -- integrated angular momentum (zonal wind term) |
---|
14 | ! tmou -- 1D -- Mountain torque |
---|
15 | ! tbls -- 1D -- Surface friction torque IF duvdf is present |
---|
16 | ! or if simple friction |
---|
17 | ! tdyn -- 1D -- Dynamics torque IF dudyn is present |
---|
18 | ! tgwo -- 1D -- Orographic GW torque IF dugwo is present |
---|
19 | ! tgwno -- 1D -- Non-Orographic GW torque IF dugwno is present |
---|
20 | ! |
---|
21 | ! Minimal requirements and dependencies: |
---|
22 | ! The dataset must include the following data: |
---|
23 | ! - surface pressure and surface geopotential |
---|
24 | ! - zonal wind |
---|
25 | ! Optional: dudyn, duvdf, dugwo, dugwno (acceleration terms from physiq param) |
---|
26 | |
---|
27 | implicit none |
---|
28 | |
---|
29 | include "netcdf.inc" ! NetCDF definitions |
---|
30 | |
---|
31 | character (len=128) :: infile ! input file name |
---|
32 | character (len=128) :: dzfile ! input dynzon file name |
---|
33 | character (len=128) :: outfile ! output file name |
---|
34 | |
---|
35 | character (len=64) :: text ! to store some text |
---|
36 | integer infid ! NetCDF input file ID |
---|
37 | integer dzfid ! NetCDF input dynzon file ID |
---|
38 | integer outfid ! NetCDF output file ID |
---|
39 | integer lon_dimid,lat_dimid,alt_dimid,time_dimid ! NetCDF dimension IDs |
---|
40 | integer latdz_dimid,altdz_dimid,timedz_dimid ! NetCDF dimension IDs |
---|
41 | integer lon_varid,lat_varid,alt_varid,time_varid, tmpvarid |
---|
42 | integer latdz_varid,altdz_varid,timedz_varid |
---|
43 | integer :: datashape1d ! shape of 1D datasets |
---|
44 | integer,dimension(2) :: datashape2d ! shape of 2D datasets |
---|
45 | integer,dimension(3) :: datashape3d ! shape of 3D datasets |
---|
46 | integer,dimension(4) :: datashape4d ! shape of 4D datasets |
---|
47 | |
---|
48 | real :: miss_val=9.99e+33 ! special "missing value" to specify missing data |
---|
49 | real,parameter :: miss_val_def=9.99e+33 ! default value for "missing value" |
---|
50 | real :: pi |
---|
51 | real,dimension(:),allocatable :: lon ! longitude |
---|
52 | integer lonlength ! # of grid points along longitude |
---|
53 | real,dimension(:),allocatable :: lat ! latitude |
---|
54 | real,dimension(:),allocatable :: latrad ! latitude in radian |
---|
55 | integer latlength ! # of grid points along latitude |
---|
56 | real,dimension(:),allocatable :: plev ! Pressure levels (Pa) |
---|
57 | integer altlength ! # of grid point along presnivs (of input datasets) |
---|
58 | real,dimension(:),allocatable :: time ! time |
---|
59 | integer timelength ! # of points along time |
---|
60 | real,dimension(:,:,:),allocatable :: ps ! surface pressure |
---|
61 | real,dimension(:,:,:),allocatable :: phis3d ! surface geopotential |
---|
62 | real,dimension(:,:),allocatable :: phis ! surface geopotential |
---|
63 | real,dimension(:,:,:,:),allocatable :: temp ! atmospheric temperature |
---|
64 | real,dimension(:,:,:,:),allocatable :: vitu ! zonal wind (in m/s) |
---|
65 | real,dimension(:,:,:,:),allocatable :: vitv ! meridional wind (in m/s) |
---|
66 | |
---|
67 | real,dimension(:,:,:,:),allocatable :: duvdf ! Friction in BL |
---|
68 | real,dimension(:,:,:,:),allocatable :: dudyn ! Dynamics |
---|
69 | real,dimension(:,:,:,:),allocatable :: dugwo ! Orographic Gravity Waves |
---|
70 | real,dimension(:,:,:,:),allocatable :: dugwno ! Non-Orographic Gravity Waves |
---|
71 | |
---|
72 | real,dimension(:,:,:),allocatable :: dmcdyn ! Dynamics dAM from dynzon |
---|
73 | real,dimension(:,:,:),allocatable :: dmcdis ! Dissip dAM from dynzon |
---|
74 | real,dimension(:,:,:),allocatable :: dmcspg ! Sponge dAM from dynzon |
---|
75 | real,dimension(:,:,:),allocatable :: dmcphy ! Physics dAM from dynzon |
---|
76 | |
---|
77 | real,dimension(:,:,:,:),allocatable :: rayon ! distance to center (m) |
---|
78 | real,dimension(:,:,:,:),allocatable :: grav ! gravity field (m s-2) |
---|
79 | real,dimension(:,:,:,:),allocatable :: dmass ! mass in cell (kg) |
---|
80 | real,dimension(:,:,:,:),allocatable :: osam ! planetary rotation specific ang (m2/s) |
---|
81 | real,dimension(:,:,:,:),allocatable :: rsam ! zonal wind specific ang (m2/s) |
---|
82 | real,dimension(:),allocatable :: oaam ! planetary rotation total ang (kg m2/s) |
---|
83 | real,dimension(:),allocatable :: raam ! zonal wind total ang (kg m2/s) |
---|
84 | real,dimension(:),allocatable :: tmou ! mountain torque (kg m2/s2) |
---|
85 | real,dimension(:),allocatable :: tdyn ! dynamics torque (kg m2/s2) |
---|
86 | real,dimension(:),allocatable :: tbls ! friction torque (kg m2/s2) |
---|
87 | real,dimension(:),allocatable :: tgwo ! oro GW torque (kg m2/s2) |
---|
88 | real,dimension(:),allocatable :: tgwno! non-oro GW torque (kg m2/s2) |
---|
89 | real,dimension(:),allocatable :: tdyndz ! dynamics torque (kg m2/s2) from dynzon |
---|
90 | real,dimension(:),allocatable :: tdisdz ! dissip torque (kg m2/s2) from dynzon |
---|
91 | real,dimension(:),allocatable :: tspgdz ! sponge torque (kg m2/s2) from dynzon |
---|
92 | real,dimension(:),allocatable :: tphydz ! physics torque (kg m2/s2) from dynzon |
---|
93 | |
---|
94 | ! for angular momentum budget normalisation |
---|
95 | real,parameter :: hadley=1.e18 |
---|
96 | real,parameter :: hadday=1.e25 |
---|
97 | |
---|
98 | integer ierr,ierr1,ierr2 ! NetCDF routines return codes |
---|
99 | integer i,j,ilon,ilat,ilev,itim ! for loops |
---|
100 | integer idlsurf ! for option ideal surface |
---|
101 | logical :: flag_duvdf,flag_dudyn,flag_dugwo,flag_dugwno,lmdflag,dzflag |
---|
102 | |
---|
103 | real :: deltalat,deltalon ! lat and lon intervals in radians |
---|
104 | real :: tmpp ! temporary pressure |
---|
105 | real :: dz ! altitude diff |
---|
106 | real :: signe ! orientation of lon axis for mountain torque computation |
---|
107 | real :: norm ! for dynzon |
---|
108 | |
---|
109 | include "planet.h" |
---|
110 | |
---|
111 | !=============================================================================== |
---|
112 | ! 1. Input parameters |
---|
113 | !=============================================================================== |
---|
114 | |
---|
115 | pi = 2.*asin(1.) |
---|
116 | |
---|
117 | write(*,*) "" |
---|
118 | write(*,*) "You are working on the atmosphere of ",planet |
---|
119 | |
---|
120 | !=============================================================================== |
---|
121 | ! 1.1 Input file |
---|
122 | !=============================================================================== |
---|
123 | |
---|
124 | write(*,*) "" |
---|
125 | write(*,*) " Program valid for Venus or Titan LMD, or Venus CAM output files" |
---|
126 | write(*,*) "Enter input file name:" |
---|
127 | |
---|
128 | read(*,'(a128)') infile |
---|
129 | write(*,*) "" |
---|
130 | |
---|
131 | ! open input file |
---|
132 | |
---|
133 | ierr = NF_OPEN(infile,NF_NOWRITE,infid) |
---|
134 | if (ierr.ne.NF_NOERR) then |
---|
135 | write(*,*) 'ERROR: Pb opening file ',trim(infile) |
---|
136 | stop "" |
---|
137 | endif |
---|
138 | |
---|
139 | !=============================================================================== |
---|
140 | ! 1.2 Get grids in lon,lat,alt(pressure),time |
---|
141 | !=============================================================================== |
---|
142 | |
---|
143 | call get_iddim(infid,lat_varid,latlength,lon_varid,lonlength,& |
---|
144 | alt_varid,altlength,time_varid,timelength,lmdflag ) |
---|
145 | |
---|
146 | allocate(lon(lonlength)) |
---|
147 | ierr=NF_GET_VAR_REAL(infid,lon_varid,lon) |
---|
148 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading longitude" |
---|
149 | if(lon(1).gt.lon(2)) then |
---|
150 | signe=-1. |
---|
151 | else |
---|
152 | signe=1. |
---|
153 | endif |
---|
154 | |
---|
155 | allocate(lat(latlength)) |
---|
156 | ierr=NF_GET_VAR_REAL(infid,lat_varid,lat) |
---|
157 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading lat" |
---|
158 | |
---|
159 | allocate(latrad(latlength)) |
---|
160 | latrad = lat*pi/180. |
---|
161 | |
---|
162 | ! Lat, lon pressure intervals |
---|
163 | deltalat = abs(latrad(2)-latrad(1)) |
---|
164 | deltalon = abs(lon(2)-lon(1))*pi/180. |
---|
165 | |
---|
166 | allocate(plev(altlength)) |
---|
167 | ierr=NF_GET_VAR_REAL(infid,alt_varid,plev) |
---|
168 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading pressure levels" |
---|
169 | if(.not.lmdflag) then |
---|
170 | ! in CAM files, pressure in mbar and reversed... |
---|
171 | call reverselev(altlength,plev) |
---|
172 | plev=plev*100. ! convertion to Pa |
---|
173 | endif |
---|
174 | |
---|
175 | allocate(time(timelength)) |
---|
176 | ierr=NF_GET_VAR_REAL(infid,time_varid,time) |
---|
177 | if (ierr.ne.NF_NOERR) stop "Error: Failed reading time" |
---|
178 | |
---|
179 | ! Time axis IN PLANET DAYS |
---|
180 | |
---|
181 | if(.not.lmdflag) then |
---|
182 | ! in CAM files, time in Earth days... |
---|
183 | ! => seconds |
---|
184 | time=time*86400. |
---|
185 | endif |
---|
186 | time=time/localday |
---|
187 | |
---|
188 | !=============================================================================== |
---|
189 | ! 1.3 dynzon file if present |
---|
190 | !=============================================================================== |
---|
191 | |
---|
192 | ! RAJOUTER UN TEST COHERENCE _P... |
---|
193 | |
---|
194 | dzflag=.false. |
---|
195 | |
---|
196 | if(lmdflag) then |
---|
197 | |
---|
198 | write(*,*) "Enter dynzon file name (<return> if not present):" |
---|
199 | |
---|
200 | read(*,'(a128)') dzfile |
---|
201 | write(*,*) "" |
---|
202 | |
---|
203 | if(dzfile.ne."") then |
---|
204 | |
---|
205 | ! open dynzon file |
---|
206 | ierr = NF_OPEN(dzfile,NF_NOWRITE,dzfid) |
---|
207 | if (ierr.ne.NF_NOERR) then |
---|
208 | write(*,*) 'ERROR: Pb opening file ',trim(dzfile) |
---|
209 | else |
---|
210 | dzflag=.true. |
---|
211 | endif |
---|
212 | |
---|
213 | endif ! dzfile.ne."" |
---|
214 | endif ! lmdflag |
---|
215 | |
---|
216 | !=============================================================================== |
---|
217 | ! 1.4 Get output file name |
---|
218 | !=============================================================================== |
---|
219 | write(*,*) "" |
---|
220 | !write(*,*) "Enter output file name" |
---|
221 | !read(*,*) outfile |
---|
222 | outfile=infile(1:len_trim(infile)-3)//"_GAM.nc" |
---|
223 | write(*,*) "Output file name is: "//trim(outfile) |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | !=============================================================================== |
---|
228 | ! 2.1 Store needed fields |
---|
229 | !=============================================================================== |
---|
230 | |
---|
231 | !=============================================================================== |
---|
232 | ! 2.1.1 Surface pressure and geopotential |
---|
233 | !=============================================================================== |
---|
234 | allocate(ps(lonlength,latlength,timelength)) |
---|
235 | allocate(phis3d(lonlength,latlength,timelength)) |
---|
236 | allocate(phis(lonlength,latlength)) |
---|
237 | |
---|
238 | if(lmdflag) then |
---|
239 | text="psol" |
---|
240 | else |
---|
241 | text="PS" |
---|
242 | endif |
---|
243 | call get_var3d(infid,lonlength,latlength,timelength,text,ps,ierr1,ierr2) |
---|
244 | if (ierr1.ne.NF_NOERR) then |
---|
245 | write(*,*) " looking for ps instead... " |
---|
246 | text="ps" |
---|
247 | call get_var3d(infid,lonlength,latlength,timelength,text,ps,ierr1,ierr2) |
---|
248 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get ps ID" |
---|
249 | endif |
---|
250 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading surface pressure" |
---|
251 | if((.not.lmdflag).and.(planet.eq."Venus")) call reverse3d(lonlength,latlength,timelength,ps) |
---|
252 | |
---|
253 | text="PHIS" |
---|
254 | call get_var3d(infid,lonlength,latlength,timelength,text,phis3d,ierr1,ierr2) |
---|
255 | if (ierr1.ne.NF_NOERR) then |
---|
256 | write(*,*) " Failed to get PHIS ID (3d), looking for phis (2d) instead... " |
---|
257 | text="phis" |
---|
258 | call get_var2d(infid,lonlength,latlength,text,phis,ierr1,ierr2) |
---|
259 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get phis ID" |
---|
260 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading surface geopotential" |
---|
261 | else |
---|
262 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading surface geopotential" |
---|
263 | phis(:,:)=phis3d(:,:,1) |
---|
264 | if((.not.lmdflag).and.(planet.eq."Venus")) call reverse2d(lonlength,latlength,phis) |
---|
265 | endif |
---|
266 | |
---|
267 | !=============================================================================== |
---|
268 | ! 2.1.3 Winds |
---|
269 | !=============================================================================== |
---|
270 | allocate(vitu(lonlength,latlength,altlength,timelength)) |
---|
271 | |
---|
272 | ! zonal wind vitu / U (in m/s) |
---|
273 | if(lmdflag) then |
---|
274 | text="vitu" |
---|
275 | else |
---|
276 | text="U" |
---|
277 | endif |
---|
278 | |
---|
279 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,vitu,ierr1,ierr2) |
---|
280 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get U ID" |
---|
281 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading zonal wind" |
---|
282 | |
---|
283 | if(.not.lmdflag) call reverse4d(lonlength,latlength,altlength,timelength,vitu) |
---|
284 | |
---|
285 | !=============================================================================== |
---|
286 | ! 2.1.4 Altitude above areoide |
---|
287 | !=============================================================================== |
---|
288 | ! Only needed if g(z) on Titan... |
---|
289 | |
---|
290 | !allocate(za(lonlength,latlength,altlength,timelength)) |
---|
291 | |
---|
292 | !text="zareoid" |
---|
293 | !call get_var4d(infid,lonlength,latlength,altlength,timelength,text,za,ierr1,ierr2) |
---|
294 | !if (ierr1.ne.NF_NOERR) stop "Error: Failed to get za ID" |
---|
295 | !if (ierr2.ne.NF_NOERR) stop "Error: Failed reading zareoid" |
---|
296 | |
---|
297 | !=============================================================================== |
---|
298 | ! 2.1.5 Friction in Boundary layer |
---|
299 | !=============================================================================== |
---|
300 | allocate(duvdf(lonlength,latlength,altlength,timelength)) |
---|
301 | |
---|
302 | if(lmdflag) then |
---|
303 | text="duvdf" |
---|
304 | else |
---|
305 | text="DUVDF" |
---|
306 | endif |
---|
307 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,duvdf,ierr1,ierr2) |
---|
308 | if (ierr1.ne.NF_NOERR) then |
---|
309 | write(*,*) "Failed to get duvdf ID" |
---|
310 | flag_duvdf = .false. |
---|
311 | |
---|
312 | if(.not.lmdflag) then |
---|
313 | ! IDEAL FRICTION ? |
---|
314 | write(*,*) "" |
---|
315 | write(*,*) " Is the friction at surface ideal ? 0 for no, 1 for yes" |
---|
316 | write(*,*) " duvdf = -u/(86400*30) in surface layer" |
---|
317 | write(*,*) " timescale hard-coded: 30 Edays" |
---|
318 | read(*,'(i1)') idlsurf |
---|
319 | !write(*,*) "" |
---|
320 | !write(*,*) " ASSUMED YES ! " |
---|
321 | !idlsurf=1 |
---|
322 | write(*,*) "" |
---|
323 | else |
---|
324 | idlsurf=0 |
---|
325 | endif |
---|
326 | |
---|
327 | if (idlsurf.eq.1) then |
---|
328 | flag_duvdf = .true. |
---|
329 | duvdf = 0. |
---|
330 | ilev=1 |
---|
331 | do ilon=1,lonlength |
---|
332 | do ilat=1,latlength |
---|
333 | do itim=1,timelength |
---|
334 | duvdf(ilon,ilat,ilev,itim) = vitu(ilon,ilat,ilev,itim) * (-1.)/(86400.*30.) |
---|
335 | enddo |
---|
336 | enddo |
---|
337 | enddo |
---|
338 | endif |
---|
339 | |
---|
340 | else !err1 |
---|
341 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading duvdf" |
---|
342 | if(.not.lmdflag) call reverse4d(lonlength,latlength,altlength,timelength,duvdf) |
---|
343 | flag_duvdf = .true. |
---|
344 | endif !err1 |
---|
345 | |
---|
346 | !=============================================================================== |
---|
347 | ! 2.1.6 Orographic and Non-orographic gravity waves |
---|
348 | !=============================================================================== |
---|
349 | allocate(dugwo(lonlength,latlength,altlength,timelength)) |
---|
350 | allocate(dugwno(lonlength,latlength,altlength,timelength)) |
---|
351 | |
---|
352 | if(lmdflag) then |
---|
353 | |
---|
354 | text="dugwo" |
---|
355 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,dugwo,ierr1,ierr2) |
---|
356 | if (ierr1.ne.NF_NOERR) then |
---|
357 | write(*,*) "Failed to get dugwo ID" |
---|
358 | flag_dugwo = .false. |
---|
359 | else |
---|
360 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading dugwo" |
---|
361 | flag_dugwo = .true. |
---|
362 | endif |
---|
363 | |
---|
364 | text="dugwno" |
---|
365 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,dugwno,ierr1,ierr2) |
---|
366 | if (ierr1.ne.NF_NOERR) then |
---|
367 | write(*,*) "Failed to get dugwno ID" |
---|
368 | flag_dugwno = .false. |
---|
369 | else |
---|
370 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading dugwno" |
---|
371 | flag_dugwno = .true. |
---|
372 | endif |
---|
373 | |
---|
374 | else ! lmdflag |
---|
375 | print*,"dugwo and dugwno not in CAM simulations" |
---|
376 | endif ! lmdflag |
---|
377 | |
---|
378 | !=============================================================================== |
---|
379 | ! 2.1.7 Dynamics (includes the mountain torque...) |
---|
380 | !=============================================================================== |
---|
381 | allocate(dudyn(lonlength,latlength,altlength,timelength)) |
---|
382 | |
---|
383 | if(lmdflag) then |
---|
384 | text="dudyn" |
---|
385 | else |
---|
386 | text="DUDYN" |
---|
387 | endif |
---|
388 | call get_var4d(infid,lonlength,latlength,altlength,timelength,text,dudyn,ierr1,ierr2) |
---|
389 | if (ierr1.ne.NF_NOERR) then |
---|
390 | write(*,*) "Failed to get dudyn ID" |
---|
391 | flag_dudyn = .false. |
---|
392 | else |
---|
393 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading dudyn" |
---|
394 | if(.not.lmdflag) call reverse4d(lonlength,latlength,altlength,timelength,dudyn) |
---|
395 | flag_dudyn = .true. |
---|
396 | endif |
---|
397 | |
---|
398 | !=============================================================================== |
---|
399 | ! 2.1.8 Dynzon dAM/dt |
---|
400 | !=============================================================================== |
---|
401 | if(dzflag) then |
---|
402 | |
---|
403 | allocate(dmcdyn(latlength-1,altlength,timelength)) |
---|
404 | allocate(dmcdis(latlength-1,altlength,timelength)) |
---|
405 | allocate(dmcspg(latlength-1,altlength,timelength)) |
---|
406 | allocate(dmcphy(latlength-1,altlength,timelength)) |
---|
407 | |
---|
408 | text="dmcdyn" |
---|
409 | call get_var3d(dzfid,latlength-1,altlength,timelength,text,dmcdyn,ierr1,ierr2) |
---|
410 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get dmcdyn ID" |
---|
411 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading dmcdyn" |
---|
412 | |
---|
413 | text="dmcdis" |
---|
414 | call get_var3d(dzfid,latlength-1,altlength,timelength,text,dmcdis,ierr1,ierr2) |
---|
415 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get dmcdis ID" |
---|
416 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading dmcdis" |
---|
417 | |
---|
418 | text="dmcspg" |
---|
419 | call get_var3d(dzfid,latlength-1,altlength,timelength,text,dmcspg,ierr1,ierr2) |
---|
420 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get dmcspg ID" |
---|
421 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading dmcspg" |
---|
422 | |
---|
423 | text="dmcphy" |
---|
424 | call get_var3d(dzfid,latlength-1,altlength,timelength,text,dmcphy,ierr1,ierr2) |
---|
425 | if (ierr1.ne.NF_NOERR) stop "Error: Failed to get dmcphy ID" |
---|
426 | if (ierr2.ne.NF_NOERR) stop "Error: Failed reading dmcphy" |
---|
427 | |
---|
428 | endif ! dzflag |
---|
429 | |
---|
430 | !=============================================================================== |
---|
431 | ! 2.2 Computations |
---|
432 | !=============================================================================== |
---|
433 | |
---|
434 | !=============================================================================== |
---|
435 | ! 2.2.2 Mass in cells |
---|
436 | !=============================================================================== |
---|
437 | allocate(rayon(lonlength,latlength,altlength,timelength)) |
---|
438 | allocate(grav(lonlength,latlength,altlength,timelength)) |
---|
439 | allocate(dmass(lonlength,latlength,altlength,timelength)) |
---|
440 | |
---|
441 | do itim=1,timelength |
---|
442 | do ilon=1,lonlength |
---|
443 | do ilat=1,latlength |
---|
444 | do ilev=1,altlength |
---|
445 | ! Need to be consistent with GCM computations |
---|
446 | ! if (za(ilon,ilat,ilev,itim).ne.miss_val) then |
---|
447 | rayon(ilon,ilat,ilev,itim) = a0 |
---|
448 | ! rayon(ilon,ilat,ilev,itim) = za(ilon,ilat,ilev,itim) + a0 |
---|
449 | grav(ilon,ilat,ilev,itim) = g0*a0*a0 & |
---|
450 | /(rayon(ilon,ilat,ilev,itim)*rayon(ilon,ilat,ilev,itim)) |
---|
451 | ! else |
---|
452 | ! rayon(ilon,ilat,ilev,itim) = miss_val |
---|
453 | ! grav(ilon,ilat,ilev,itim) = miss_val |
---|
454 | ! endif |
---|
455 | enddo |
---|
456 | enddo |
---|
457 | enddo |
---|
458 | enddo ! timelength |
---|
459 | |
---|
460 | call cellmass(infid,latlength,lonlength,altlength,timelength, & |
---|
461 | lmdflag,deltalon,deltalat,latrad,plev,ps,grav,rayon, & |
---|
462 | dmass ) |
---|
463 | |
---|
464 | !=============================================================================== |
---|
465 | ! 2.2.3 Specific angular momentum |
---|
466 | !=============================================================================== |
---|
467 | allocate(osam(lonlength,latlength,altlength,timelength)) |
---|
468 | allocate(rsam(lonlength,latlength,altlength,timelength)) |
---|
469 | |
---|
470 | do itim=1,timelength |
---|
471 | |
---|
472 | do ilon=1,lonlength |
---|
473 | do ilat=1,latlength |
---|
474 | do ilev=1,altlength |
---|
475 | if (rayon(ilon,ilat,ilev,itim).ne.miss_val) then |
---|
476 | osam(ilon,ilat,ilev,itim) = & |
---|
477 | rayon(ilon,ilat,ilev,itim)*rayon(ilon,ilat,ilev,itim) & |
---|
478 | * cos(latrad(ilat))*cos(latrad(ilat)) & |
---|
479 | * omega |
---|
480 | rsam(ilon,ilat,ilev,itim) = vitu(ilon,ilat,ilev,itim) & |
---|
481 | * rayon(ilon,ilat,ilev,itim)*cos(latrad(ilat)) |
---|
482 | else |
---|
483 | osam(ilon,ilat,ilev,itim) = miss_val |
---|
484 | rsam(ilon,ilat,ilev,itim) = miss_val |
---|
485 | endif |
---|
486 | enddo |
---|
487 | enddo |
---|
488 | enddo |
---|
489 | |
---|
490 | enddo ! timelength |
---|
491 | |
---|
492 | !=============================================================================== |
---|
493 | ! 2.2.4 Total angular momentum |
---|
494 | !=============================================================================== |
---|
495 | allocate(oaam(timelength)) |
---|
496 | allocate(raam(timelength)) |
---|
497 | |
---|
498 | do itim=1,timelength |
---|
499 | |
---|
500 | oaam(itim) = 0. |
---|
501 | raam(itim) = 0. |
---|
502 | do ilon=1,lonlength |
---|
503 | do ilat=1,latlength |
---|
504 | do ilev=1,altlength |
---|
505 | oaam(itim) = oaam(itim) & |
---|
506 | + osam(ilon,ilat,ilev,itim)/ hadday * dmass(ilon,ilat,ilev,itim) |
---|
507 | raam(itim) = raam(itim) & |
---|
508 | + rsam(ilon,ilat,ilev,itim)/ hadday * dmass(ilon,ilat,ilev,itim) |
---|
509 | enddo |
---|
510 | enddo |
---|
511 | enddo |
---|
512 | if (oaam(itim).eq.0.) then |
---|
513 | oaam(itim) = miss_val |
---|
514 | raam(itim) = miss_val |
---|
515 | endif |
---|
516 | |
---|
517 | enddo ! timelength |
---|
518 | |
---|
519 | !=============================================================================== |
---|
520 | ! 2.2.5 Mountain, friction, dynamics and GW torques |
---|
521 | !=============================================================================== |
---|
522 | allocate(tmou(timelength)) |
---|
523 | if (flag_dudyn) allocate(tdyn(timelength)) |
---|
524 | if (flag_duvdf) allocate(tbls(timelength)) |
---|
525 | if (flag_dugwo) allocate(tgwo(timelength)) |
---|
526 | if (flag_dugwno) allocate(tgwno(timelength)) |
---|
527 | |
---|
528 | do itim=1,timelength |
---|
529 | |
---|
530 | tmou(itim) = 0. |
---|
531 | do ilon=1,lonlength |
---|
532 | do ilat=2,latlength-1 |
---|
533 | if (ilon.eq.lonlength) then |
---|
534 | dz = (phis( 1,ilat) -phis(ilon,ilat))/g0 |
---|
535 | tmpp = (ps( 1,ilat,itim) +ps(ilon,ilat,itim))/2. |
---|
536 | else |
---|
537 | dz = (phis(ilon+1,ilat) -phis(ilon,ilat))/g0 |
---|
538 | tmpp = (ps(ilon+1,ilat,itim) +ps(ilon,ilat,itim))/2. |
---|
539 | endif |
---|
540 | tmou(itim) = tmou(itim) + a0*a0* deltalat*cos(latrad(ilat)) & |
---|
541 | * signe*dz*tmpp & |
---|
542 | / hadley |
---|
543 | enddo |
---|
544 | enddo |
---|
545 | |
---|
546 | if (flag_dudyn) then |
---|
547 | tdyn(itim) = 0. |
---|
548 | do ilon=1,lonlength |
---|
549 | do ilat=1,latlength |
---|
550 | do ilev=1,altlength |
---|
551 | if (rayon(ilon,ilat,ilev,itim).ne.miss_val) then |
---|
552 | tdyn(itim) = tdyn(itim) + dudyn(ilon,ilat,ilev,itim) & |
---|
553 | * rayon(ilon,ilat,ilev,itim)*cos(latrad(ilat)) & |
---|
554 | * dmass(ilon,ilat,ilev,itim) & |
---|
555 | / hadley |
---|
556 | endif |
---|
557 | enddo |
---|
558 | enddo |
---|
559 | enddo |
---|
560 | if (tdyn(itim).eq.0.) tdyn(itim) = miss_val |
---|
561 | endif |
---|
562 | |
---|
563 | if (flag_duvdf) then |
---|
564 | tbls(itim) = 0. |
---|
565 | do ilon=1,lonlength |
---|
566 | do ilat=1,latlength |
---|
567 | do ilev=1,altlength |
---|
568 | if (rayon(ilon,ilat,ilev,itim).ne.miss_val) then |
---|
569 | tbls(itim) = tbls(itim) + duvdf(ilon,ilat,ilev,itim) & |
---|
570 | * rayon(ilon,ilat,ilev,itim)*cos(latrad(ilat)) & |
---|
571 | * dmass(ilon,ilat,ilev,itim) & |
---|
572 | / hadley |
---|
573 | endif |
---|
574 | enddo |
---|
575 | enddo |
---|
576 | enddo |
---|
577 | if (tbls(itim).eq.0.) tbls(itim) = miss_val |
---|
578 | endif |
---|
579 | |
---|
580 | if (flag_dugwo) then |
---|
581 | tgwo(itim) = 0. |
---|
582 | do ilon=1,lonlength |
---|
583 | do ilat=1,latlength |
---|
584 | do ilev=1,altlength |
---|
585 | if (rayon(ilon,ilat,ilev,itim).ne.miss_val) then |
---|
586 | tgwo(itim) = tgwo(itim) + dugwo(ilon,ilat,ilev,itim) & |
---|
587 | * rayon(ilon,ilat,ilev,itim)*cos(latrad(ilat)) & |
---|
588 | * dmass(ilon,ilat,ilev,itim) & |
---|
589 | / hadley |
---|
590 | endif |
---|
591 | enddo |
---|
592 | enddo |
---|
593 | enddo |
---|
594 | if (tgwo(itim).eq.0.) tgwo(itim) = miss_val |
---|
595 | endif |
---|
596 | |
---|
597 | if (flag_dugwno) then |
---|
598 | tgwno(itim) = 0. |
---|
599 | do ilon=1,lonlength |
---|
600 | do ilat=1,latlength |
---|
601 | do ilev=1,altlength |
---|
602 | if (rayon(ilon,ilat,ilev,itim).ne.miss_val) then |
---|
603 | tgwno(itim) = tgwno(itim) + dugwno(ilon,ilat,ilev,itim) & |
---|
604 | * rayon(ilon,ilat,ilev,itim)*cos(latrad(ilat)) & |
---|
605 | * dmass(ilon,ilat,ilev,itim) & |
---|
606 | / hadley |
---|
607 | endif |
---|
608 | enddo |
---|
609 | enddo |
---|
610 | enddo |
---|
611 | if (tgwno(itim).eq.0.) tgwno(itim) = miss_val |
---|
612 | endif |
---|
613 | |
---|
614 | enddo ! timelength |
---|
615 | |
---|
616 | !=============================================================================== |
---|
617 | ! 2.2.6 Torques from dynzon |
---|
618 | !=============================================================================== |
---|
619 | if(dzflag) then |
---|
620 | |
---|
621 | allocate(tdyndz(timelength)) |
---|
622 | allocate(tdisdz(timelength)) |
---|
623 | allocate(tspgdz(timelength)) |
---|
624 | allocate(tphydz(timelength)) |
---|
625 | norm=2./3.*a0*a0*omega |
---|
626 | |
---|
627 | do itim=1,timelength |
---|
628 | |
---|
629 | tdyndz(itim) = 0. |
---|
630 | tdisdz(itim) = 0. |
---|
631 | tspgdz(itim) = 0. |
---|
632 | tphydz(itim) = 0. |
---|
633 | do ilon=1,lonlength |
---|
634 | do ilat=2,latlength |
---|
635 | do ilev=1,altlength |
---|
636 | tdyndz(itim) = tdyndz(itim) + & |
---|
637 | (dmcdyn(ilat-1,ilev,itim)+dmcdyn(ilat,ilev,itim))/(2*lonlength) & |
---|
638 | * norm * dmass(ilon,ilat,ilev,itim) / hadley |
---|
639 | tdisdz(itim) = tdisdz(itim) + & |
---|
640 | (dmcdis(ilat-1,ilev,itim)+dmcdis(ilat,ilev,itim))/(2*lonlength) & |
---|
641 | * norm * dmass(ilon,ilat,ilev,itim) / hadley |
---|
642 | tspgdz(itim) = tspgdz(itim) + & |
---|
643 | (dmcspg(ilat-1,ilev,itim)+dmcspg(ilat,ilev,itim))/(2*lonlength) & |
---|
644 | * norm * dmass(ilon,ilat,ilev,itim) / hadley |
---|
645 | tphydz(itim) = tphydz(itim) + & |
---|
646 | (dmcphy(ilat-1,ilev,itim)+dmcphy(ilat,ilev,itim))/(2*lonlength) & |
---|
647 | * norm * dmass(ilon,ilat,ilev,itim) / hadley |
---|
648 | enddo |
---|
649 | enddo |
---|
650 | enddo |
---|
651 | if (tdyndz(itim).eq.0.) tdyndz(itim) = miss_val |
---|
652 | if (tdisdz(itim).eq.0.) tdisdz(itim) = miss_val |
---|
653 | if (tspgdz(itim).eq.0.) tspgdz(itim) = miss_val |
---|
654 | if (tphydz(itim).eq.0.) tphydz(itim) = miss_val |
---|
655 | |
---|
656 | enddo ! timelength |
---|
657 | |
---|
658 | endif ! dzflag |
---|
659 | |
---|
660 | print*,"End of computations" |
---|
661 | |
---|
662 | !=============================================================================== |
---|
663 | ! 3. Create output file |
---|
664 | !=============================================================================== |
---|
665 | |
---|
666 | ! Create output file |
---|
667 | ierr=NF_CREATE(outfile,NF_CLOBBER,outfid) |
---|
668 | if (ierr.ne.NF_NOERR) then |
---|
669 | write(*,*)"Error: could not create file ",outfile |
---|
670 | stop |
---|
671 | endif |
---|
672 | |
---|
673 | !=============================================================================== |
---|
674 | ! 3.1. Define and write dimensions |
---|
675 | !=============================================================================== |
---|
676 | |
---|
677 | call write_dim(outfid,lonlength,latlength,altlength,timelength, & |
---|
678 | lon,lat,plev,time,lon_dimid,lat_dimid,alt_dimid,time_dimid) |
---|
679 | |
---|
680 | !=============================================================================== |
---|
681 | ! 3.2. Define and write variables |
---|
682 | !=============================================================================== |
---|
683 | |
---|
684 | ! 1D Variables |
---|
685 | |
---|
686 | datashape1d=time_dimid |
---|
687 | |
---|
688 | call write_var1d(outfid,datashape1d,timelength,& |
---|
689 | "oaam ", "Total rotation ang ","E25kgm2s-1",miss_val,& |
---|
690 | oaam ) |
---|
691 | |
---|
692 | call write_var1d(outfid,datashape1d,timelength,& |
---|
693 | "raam ", "Total wind ang ","E25kgm2s-1",miss_val,& |
---|
694 | raam ) |
---|
695 | |
---|
696 | call write_var1d(outfid,datashape1d,timelength,& |
---|
697 | "tmou ", "Mountain torque ","E18kgm2s-2",miss_val,& |
---|
698 | tmou ) |
---|
699 | |
---|
700 | if (flag_dudyn) then |
---|
701 | call write_var1d(outfid,datashape1d,timelength,& |
---|
702 | "tdyn ", "Dynamics torque ","E18kgm2s-2",miss_val,& |
---|
703 | tdyn ) |
---|
704 | endif |
---|
705 | |
---|
706 | if (flag_duvdf) then |
---|
707 | call write_var1d(outfid,datashape1d,timelength,& |
---|
708 | "tbls ", "Friction torque ","E18kgm2s-2",miss_val,& |
---|
709 | tbls ) |
---|
710 | endif |
---|
711 | |
---|
712 | if (flag_dugwo) then |
---|
713 | call write_var1d(outfid,datashape1d,timelength,& |
---|
714 | "tgwo ", "Orographic GW torque","E18kgm2s-2",miss_val,& |
---|
715 | tgwo ) |
---|
716 | endif |
---|
717 | |
---|
718 | if (flag_dugwno) then |
---|
719 | call write_var1d(outfid,datashape1d,timelength,& |
---|
720 | "tgwno ", "Non-orogr. GW torque","E18kgm2s-2",miss_val,& |
---|
721 | tgwno ) |
---|
722 | endif |
---|
723 | |
---|
724 | if(dzflag) then |
---|
725 | |
---|
726 | call write_var1d(outfid,datashape1d,timelength,& |
---|
727 | "tdyndz ", "Dynamics torque DZ ","E18kgm2s-2",miss_val,& |
---|
728 | tdyndz ) |
---|
729 | |
---|
730 | call write_var1d(outfid,datashape1d,timelength,& |
---|
731 | "tdisdz ", "Dissip torque DZ ","E18kgm2s-2",miss_val,& |
---|
732 | tdisdz ) |
---|
733 | |
---|
734 | call write_var1d(outfid,datashape1d,timelength,& |
---|
735 | "tspgdz ", "Sponge torque DZ ","E18kgm2s-2",miss_val,& |
---|
736 | tspgdz ) |
---|
737 | |
---|
738 | call write_var1d(outfid,datashape1d,timelength, & |
---|
739 | "tphydz ", "Physics torque DZ ","E18kgm2s-2",miss_val,& |
---|
740 | tphydz ) |
---|
741 | |
---|
742 | endif ! dzflag |
---|
743 | |
---|
744 | ! 2D variables |
---|
745 | |
---|
746 | datashape2d(1)=lon_dimid |
---|
747 | datashape2d(2)=lat_dimid |
---|
748 | |
---|
749 | call write_var2d(outfid,datashape2d,lonlength,latlength,& |
---|
750 | "phis ", "Surface geopot ","m2 s-2 ",miss_val,& |
---|
751 | phis ) |
---|
752 | |
---|
753 | ! 3D variables |
---|
754 | |
---|
755 | datashape3d(1)=lon_dimid |
---|
756 | datashape3d(2)=lat_dimid |
---|
757 | datashape3d(3)=time_dimid |
---|
758 | |
---|
759 | call write_var3d(outfid,datashape3d,lonlength,latlength,timelength,& |
---|
760 | "ps ", "Surface pressure ","Pa ",miss_val,& |
---|
761 | ps ) |
---|
762 | |
---|
763 | ! 4D variables |
---|
764 | |
---|
765 | datashape4d(1)=lon_dimid |
---|
766 | datashape4d(2)=lat_dimid |
---|
767 | datashape4d(3)=alt_dimid |
---|
768 | datashape4d(4)=time_dimid |
---|
769 | |
---|
770 | call write_var4d(outfid,datashape4d,lonlength,latlength,altlength,timelength,& |
---|
771 | "dmass ", "Mass ","kg ",miss_val,& |
---|
772 | dmass ) |
---|
773 | |
---|
774 | call write_var4d(outfid,datashape4d,lonlength,latlength,altlength,timelength,& |
---|
775 | "osam ", "Specific rotat ang ","E25m2s-1 ",miss_val,& |
---|
776 | osam ) |
---|
777 | |
---|
778 | call write_var4d(outfid,datashape4d,lonlength,latlength,altlength,timelength,& |
---|
779 | "rsam ", "Specific wind ang ","E25m2s-1 ",miss_val,& |
---|
780 | rsam ) |
---|
781 | |
---|
782 | !!!! Close output file |
---|
783 | ierr=NF_CLOSE(outfid) |
---|
784 | if (ierr.ne.NF_NOERR) then |
---|
785 | write(*,*) 'Error, failed to close output file ',outfile |
---|
786 | endif |
---|
787 | |
---|
788 | |
---|
789 | end program |
---|