/[lmdze]/trunk/Sources/phylmd/Mobidic/regr_pr_av.f
ViewVC logotype

Annotation of /trunk/Sources/phylmd/Mobidic/regr_pr_av.f

Parent Directory Parent Directory | Revision Log Revision Log


Revision 162 - (hide annotations)
Fri Jul 24 16:54:30 2015 UTC (8 years, 10 months ago) by guez
File size: 2993 byte(s)
Variable pls of module pressure_var was only modified by calfis but I
could not move it to module calfis_m because it was used by a
procedure called by calfis (it would have been a cyclic
dependency). In the same way, variable p3d of module pressure_var was
only modified by leapfrog but I could not move it to module
leapfrog_m. So removed module pressure_var. p3d becomes a local
variable of leapfrog and an argument of calfis. Use paprs and play in
regr_pr_int and regr_pr_av (following LMDZ). The idea in regr_pr_int
and regr_pr_av is to spread and pack before the regridding instead of
packing afterward. The cost in memory should only be a two-dimensional
temporary array created by spread. The cost in clarity is only the
transiting of paprs and pplay through regr_pr_comb_coefoz, but this is
more than compensated by removing the side effect on module variables.

1 guez 90 module regr_pr_av_m
2 guez 3
3     implicit none
4    
5     contains
6    
7 guez 162 subroutine regr_pr_av(ncid, name, julien, paprs, v3)
8 guez 3
9 guez 90 ! "regr_pr_av" stands for "regrid pressure averaging".
10    
11     ! This procedure reads a 2D latitude-pressure field from a NetCDF
12     ! file, at a given day, regrids this field in pressure to the LMDZ
13     ! vertical grid and packs it to the LMDZ horizontal "physics"
14     ! grid.
15    
16     ! We assume that, in the input file, the field has 3 dimensions:
17     ! latitude, pressure, julian day.
18    
19     ! We assume that the input field is already on the LMDZ "rlatu"
20     ! latitudes, except that latitudes are in ascending order in the
21     ! input file.
22    
23 guez 19 ! The target vertical LMDZ grid is the grid of layer boundaries.
24 guez 20 ! Regridding in pressure is done by averaging a step function of pressure.
25 guez 3
26     use dimens_m, only: iim, jjm, llm
27     use dimphy, only: klon
28 guez 52 use grid_change, only: dyn_phy
29 guez 90 use netcdf95, only: nf95_inq_varid, nf95_get_var
30 guez 36 use nr_util, only: assert
31 guez 61 use numer_rec_95, only: regr1_step_av
32 guez 17 use press_coefoz_m, only: press_in_edg
33 guez 3
34     integer, intent(in):: ncid ! NetCDF ID of the file
35     character(len=*), intent(in):: name ! of the NetCDF variable
36 guez 7 integer, intent(in):: julien ! jour julien, 1 <= julien <= 360
37 guez 3
38 guez 162 real, intent(in):: paprs(:, :) ! (klon, llm + 1)
39     ! (pression pour chaque inter-couche, en Pa)
40    
41 guez 7 real, intent(out):: v3(:, :) ! (klon, llm)
42 guez 90 ! regridded field on the partial "physics" grid
43     ! "v3(i, k)" is at longitude "xlon(i)", latitude "xlat(i)", in
44     ! layer "k".
45 guez 7
46     ! Variables local to the procedure:
47    
48 guez 105 integer varid ! for NetCDF
49 guez 20
50 guez 162 real v1(jjm + 1, size(press_in_edg) - 1)
51 guez 90 ! input field at day "julien"
52     ! "v1(j, k)" is at latitude "rlatu(j)" and for
53     ! pressure interval "[press_in_edg(k), press_in_edg(k+1)]".
54 guez 7
55 guez 162 real v2(klon, size(press_in_edg) - 1)
56     ! Field on the "physics" horizontal grid. "v2(i, k)" is at
57     ! longitude "xlon(i)", latitude "xlat(i)" and for pressure
58     ! interval "[press_in_edg(k), press_in_edg(k+1)]".)
59 guez 7
60 guez 162 integer i, k
61 guez 20
62 guez 7 !--------------------------------------------
63    
64 guez 162 call assert(shape(v3) == (/klon, llm/), "regr_pr_av klon llm")
65     call assert(shape(paprs) == (/klon, llm+1/), "regr_pr_av paprs")
66 guez 7
67     call nf95_inq_varid(ncid, name, varid)
68    
69     ! Get data at the right day from the input file:
70 guez 90 call nf95_get_var(ncid, varid, v1, start=(/1, 1, julien/))
71 guez 20 ! Latitudes are in ascending order in the input file while
72     ! "rlatu" is in descending order so we need to invert order:
73 guez 7 v1 = v1(jjm+1:1:-1, :)
74    
75 guez 162 forall (k = 1:size(press_in_edg) - 1) v2(:, k) = pack(spread(v1(:, k), &
76     dim = 1, ncopies = iim + 1), dyn_phy)
77    
78 guez 7 ! Regrid in pressure at each horizontal position:
79 guez 162 do i = 1, klon
80     v3(i, llm:1:-1) = regr1_step_av(v2(i, :), press_in_edg, &
81     paprs(i, llm+1:1:-1))
82     ! (invert order of indices because "paprs" is in descending order)
83 guez 19 end do
84 guez 7
85 guez 90 end subroutine regr_pr_av
86 guez 7
87 guez 90 end module regr_pr_av_m

  ViewVC Help
Powered by ViewVC 1.1.21