--- trunk/libf/phylmd/Mobidic/regr_lat_time_coefoz.f90 2008/07/25 19:59:34 13 +++ trunk/phylmd/Mobidic/regr_lat_time_coefoz.f 2018/02/05 10:39:38 254 @@ -1,6 +1,5 @@ module regr_lat_time_coefoz_m - ! This module is clean: no C preprocessor directive, no include line. ! Author: Lionel GUEZ implicit none @@ -38,11 +37,10 @@ ! not use values of the input time coordinate). use dimens_m, only: jjm - use comgeom, only: rlatv - use comconst, only: pi - use regr1_step_av_m, only: regr1_step_av - use regr3_lint_m, only: regr3_lint - use netcdf95, only: nf95_open, nf95_get_coord, nf95_close, & + use dynetat0_m, only: rlatv + use nr_util, only: pi + use numer_rec_95, only: regr3_lint, regr1_conserv, slopes + use netcdf95, only: nf95_open, nf95_gw_var, nf95_close, & nf95_inq_varid, handle_err, nf95_put_var use netcdf, only: nf90_nowrite, nf90_get_var @@ -52,14 +50,14 @@ integer n_plev ! number of pressure levels in the input data integer n_lat! number of latitudes in the input data - real, pointer:: latitude(:) + real, allocatable:: latitude(:) ! (of input data, converted to rad, sorted in strictly increasing order) real, allocatable:: lat_in_edg(:) ! (edges of latitude intervals for input data, in rad, in strictly ! increasing order) - real, pointer:: plev(:) ! pressure level of input data + real, allocatable:: plev(:) ! pressure level of input data logical decr_lat ! decreasing latitude in the input file real, allocatable:: o3_par_in(:, :, :) ! (n_lat, n_plev, 12) @@ -98,7 +96,7 @@ ! (name of NetCDF primary variable in the output file) integer varid_in(n_o3_param), varid_out(n_o3_param), varid_plev, varid_time - integer ncerr + integer ncerr, varid ! (for NetCDF) real, parameter:: tmidmonth(0:13) = (/(-15. + 30. * j, j = 0, 13)/) @@ -127,7 +125,7 @@ name_out(i_v) = "a2" i_v = i_v + 1 - name_in(i_v) = "r" + name_in(i_v) = "tro3" name_out(i_v) = "r_Mob" i_v = i_v + 1 @@ -150,11 +148,12 @@ name_in(i_v) = "R_Het" name_out(i_v) = "R_Het" - call nf95_open("coefoz_v2_3.nc", nf90_nowrite, ncid_in) + call nf95_open("coefoz.nc", nf90_nowrite, ncid_in) ! Get coordinates from the input file: - call nf95_get_coord(ncid_in, "latitude", latitude) + call nf95_inq_varid(ncid_in, "latitude", varid) + call nf95_gw_var(ncid_in, varid, latitude) ! Convert from degrees to rad, because "rlatv" is in rad: latitude = latitude / 180. * pi n_lat = size(latitude) @@ -168,9 +167,9 @@ lat_in_edg(1) = - pi / 2 forall (j = 2:n_lat) lat_in_edg(j) = (latitude(j - 1) + latitude(j)) / 2 lat_in_edg(n_lat + 1) = pi / 2 - deallocate(latitude) ! pointer - call nf95_get_coord(ncid_in, "plev", plev) + call nf95_inq_varid(ncid_in, "plev", varid) + call nf95_gw_var(ncid_in, varid, plev) n_plev = size(plev) ! (We only need the pressure coordinate to copy it to the output file.) @@ -187,8 +186,6 @@ call nf95_put_var(ncid_out, varid_time, tmidday) call nf95_put_var(ncid_out, varid_plev, plev) - deallocate(plev) ! pointer - allocate(o3_par_in(n_lat, n_plev, 12)) allocate(v_regr_lat(jjm + 1, n_plev, 0:13)) allocate(o3_par_out(jjm + 1, n_plev, 360)) @@ -204,8 +201,10 @@ ! Regrid in latitude: ! We average with respect to sine of latitude, which is ! equivalent to weighting by cosine of latitude: - v_regr_lat(jjm+1:1:-1, :, 1:12) = regr1_step_av(o3_par_in, & - xs=sin(lat_in_edg), xt=sin((/- pi / 2, rlatv(jjm:1:-1), pi / 2/))) + call regr1_conserv(o3_par_in, & + xs = sin(lat_in_edg), xt = (/- 1., sin(rlatv(jjm:1:-1)), 1./), & + slope = slopes(o3_par_in, sin(lat_in_edg)), & + vt = v_regr_lat(jjm + 1:1:- 1, :, 1:12)) ! (invert order of indices in "v_regr_lat" because "rlatu" is ! decreasing) @@ -237,13 +236,11 @@ ! dimensions and variables, and writes one of the coordinate variables. use dimens_m, only: jjm - use comgeom, only: rlatu - use comconst, only: pi - use numer_rec, only: assert_eq - + use dynetat0_m, only: rlatu + use netcdf, only: nf90_clobber, nf90_float, nf90_copy_att, nf90_global use netcdf95, only: nf95_create, nf95_def_dim, nf95_def_var, & nf95_put_att, nf95_enddef, nf95_copy_att, nf95_put_var - use netcdf, only: nf90_clobber, nf90_float, nf90_copy_att, nf90_global + use nr_util, only: assert_eq, pi integer, intent(in):: ncid_in, varid_in(:), n_plev character(len=*), intent(in):: name_out(:) ! of NetCDF variables