Skip to content

Commit e189d01

Browse files
committed
Simplify klevel/remove kadd
1 parent 07f33e5 commit e189d01

File tree

6 files changed

+28
-91
lines changed

6 files changed

+28
-91
lines changed

src/common/bldp.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module bldpML
3939
subroutine bldp
4040
USE snapdimML, only: nx,ny,nk
4141
USE snaptabML, only: cp, g, pmult, pitab
42-
USE snapgrdML, only: ahalf, bhalf, vhalf, alevel, blevel, kadd
42+
USE snapgrdML, only: ahalf, bhalf, vhalf, alevel, blevel
4343
USE snapfldML, only: u2, v2, ps2, t2, hbl2, bl2
4444
USE ftestML, only: ftest
4545
USE snapdebug, only: iulog
@@ -80,7 +80,7 @@ subroutine bldp
8080
if(pblbot > p) pblbot=p
8181
kbltop=2
8282
kblbot=2
83-
nkk=min(nk-2,nk-kadd)
83+
nkk=min(nk-2,nk)
8484
do k=2,nkk
8585
p=ahalf(k)+bhalf(k)*psurf
8686
if(p > pbltop) kbltop=k+1

src/common/om2edot.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module om2edotML
5555
!> More than half of the model levels and the upper
5656
!> level are required.
5757
subroutine om2edot
58-
USE snapgrdML, only: ahalf, bhalf, vhalf, kadd, klevel, gparam
58+
USE snapgrdML, only: ahalf, bhalf, vhalf, klevel, gparam
5959
USE snapfldML, only: xm, ym, ps2, u2, v2, w2, field1, field2, field3, field4
6060
USE snapdimML, only: nx,ny,nk
6161
USE snapdebug, only: iulog
@@ -67,7 +67,7 @@ subroutine om2edot
6767

6868
write(iulog,*) 'OM2EDOT'
6969

70-
do k=2,nk-kadd
70+
do k=2,nk
7171

7272
deta=vhalf(k-1)-vhalf(k)
7373

@@ -85,11 +85,11 @@ subroutine om2edot
8585
!..check if required model levels are present for subr. edcomp
8686

8787
!..no. of present levels
88-
kk=(nk-kadd)-1
88+
kk=(nk)-1
8989
!..assuming that the lower model level is always present above surface level
9090
km=klevel(2)
9191

92-
if(kk > km/2 .AND. kadd == 0 .AND. klevel(nk) == 1) then
92+
if(kk > km/2 .AND. klevel(nk) == 1) then
9393

9494
d2hx=1./(gparam(7)*2.)
9595
d2hy=1./(gparam(8)*2.)

src/common/readfield_fi.f90

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ subroutine readfield_fi(istep, backward, itimei, ihr1, ihr2, itimefi, ierror)
7272
hlayer1, hlayer2, bl1, bl2, enspos, precip, t1_abs, t2_abs, &
7373
field1
7474
USE snapgrdML, only: alevel, blevel, vlevel, ahalf, bhalf, vhalf, &
75-
gparam, kadd, klevel, ivlevel, imslp, igtype, ivlayer, ivcoor
75+
gparam, klevel, ivlevel, imslp, igtype, ivlayer, ivcoor
7676
USE snapmetML, only: met_params, xy_wind_units, pressure_units, omega_units, &
7777
sigmadot_units, temp_units, requires_precip_deaccumulation
7878
USE snapdimML, only: nx, ny, nk, output_resolution_factor, hres_field
@@ -215,7 +215,7 @@ subroutine readfield_fi(istep, backward, itimei, ihr1, ihr2, itimefi, ierror)
215215
end if
216216

217217
ptop = 100.0
218-
do k = nk - kadd, 2, -1
218+
do k = nk , 2, -1
219219

220220
!..input model level no.
221221
ilevel = klevel(k)
@@ -269,7 +269,7 @@ subroutine readfield_fi(istep, backward, itimei, ihr1, ihr2, itimefi, ierror)
269269
end if
270270
end if
271271

272-
end do ! k=nk-kadd,2,-1
272+
end do ! k=nk,2,-1
273273

274274
!..surface pressure, 10m wind and possibly mean sea level pressure,
275275
!..precipitation
@@ -333,7 +333,7 @@ subroutine readfield_fi(istep, backward, itimei, ihr1, ihr2, itimefi, ierror)
333333
if (met_params%temp_is_abs) then
334334
if (allocated(t2_abs)) t2_abs(:,:,:) = t2
335335
!..abs.temp. -> pot.temp.
336-
do k = 2, nk - kadd
336+
do k = 2, nk
337337
do j = 1, ny
338338
do i = 1, nx
339339
p = alevel(k) + blevel(k)*ps2(i,j)
@@ -344,7 +344,7 @@ subroutine readfield_fi(istep, backward, itimei, ihr1, ihr2, itimefi, ierror)
344344
else
345345
if (allocated(t2_abs)) then
346346
! pot.temp -> abs.temp
347-
do k=2,nk-kadd
347+
do k=2,nk
348348
do j = 1, ny
349349
do i = 1, nx
350350
p = alevel(k) + blevel(k)*ps2(i,j)
@@ -370,19 +370,6 @@ subroutine readfield_fi(istep, backward, itimei, ihr1, ihr2, itimefi, ierror)
370370

371371
!..no temperature at or near surface (not used, yet)
372372
t2(:, :, 1) = -999.0
373-
if (kadd > 0) then
374-
!..levels added at the top
375-
dred = 0.5/float(kadd)
376-
red = 1.
377-
kk = nk - kadd
378-
do k = nk - kadd + 1, nk
379-
red = red - dred
380-
u2(:, :, k) = u2(:, :, kk)
381-
v2(:, :, k) = v2(:, :, kk)
382-
w2(:, :, k) = w2(:, :, kk)*red
383-
t2(:, :, k) = t2(:, :, kk)
384-
end do
385-
end if
386373

387374
if (backward) then
388375
! backward-calculation, switch sign of winds

src/common/readfield_nc.f90

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ subroutine readfield_nc(istep, backward, itimei, ihr1, ihr2, &
115115
hlayer1, hlayer2, bl1, bl2, enspos, precip, &
116116
t1_abs, t2_abs, field1
117117
USE snapgrdML, only: alevel, blevel, vlevel, ahalf, bhalf, vhalf, &
118-
gparam, kadd, klevel, ivlevel, imslp, igtype, ivlayer, ivcoor
118+
gparam, klevel, ivlevel, imslp, igtype, ivlayer, ivcoor
119119
USE snapmetML, only: met_params, requires_precip_deaccumulation
120120
USE snapdimML, only: nx, ny, nk, output_resolution_factor, hres_field
121121
USE datetime, only: datetime_t, duration_t
@@ -261,7 +261,7 @@ subroutine readfield_nc(istep, backward, itimei, ihr1, ihr2, &
261261
end if
262262

263263
ptop = 100.0
264-
do k=nk-kadd,2,-1
264+
do k=nk,2,-1
265265

266266
!..input model level no.
267267
ilevel=klevel(k)
@@ -318,7 +318,7 @@ subroutine readfield_nc(istep, backward, itimei, ihr1, ihr2, &
318318
start4d, count4d, w2(:,:,k))
319319
end if
320320

321-
end do ! k=nk-kadd,2,-1
321+
end do ! k=nk,2,-1
322322

323323

324324
!..surface pressure, 10m wind and possibly mean sea level pressure,
@@ -401,7 +401,7 @@ subroutine readfield_nc(istep, backward, itimei, ihr1, ihr2, &
401401
if (met_params%temp_is_abs) then
402402
if (allocated(t2_abs)) t2_abs(:,:,:) = t2
403403
!..abs.temp. -> pot.temp.
404-
do k=2,nk-kadd
404+
do k=2,nk
405405
do j = 1, ny
406406
do i = 1, nx
407407
p = alevel(k) + blevel(k)*ps2(i,j)
@@ -412,7 +412,7 @@ subroutine readfield_nc(istep, backward, itimei, ihr1, ihr2, &
412412
else
413413
if (allocated(t2_abs)) then
414414
! pot.temp -> abs.temp
415-
do k=2,nk-kadd
415+
do k=2,nk
416416
do j = 1, ny
417417
do i = 1, nx
418418
p = alevel(k) + blevel(k)*ps2(i,j)
@@ -438,19 +438,6 @@ subroutine readfield_nc(istep, backward, itimei, ihr1, ihr2, &
438438

439439
!..no temperature at or near surface (not used, yet)
440440
t2(:,:,1) = -999.0
441-
if(kadd > 0) then
442-
!..levels added at the top
443-
dred=0.5/float(kadd)
444-
red=1.
445-
kk=nk-kadd
446-
do k=nk-kadd+1,nk
447-
red=red-dred
448-
u2(:,:,k) = u2(:,:,kk)
449-
v2(:,:,k) = v2(:,:,kk)
450-
w2(:,:,k) = w2(:,:,kk)*red
451-
t2(:,:,k) = t2(:,:,kk)
452-
end do
453-
end if
454441

455442
if(backward) then
456443
! backward-calculation, switch sign of winds
@@ -916,7 +903,7 @@ end subroutine nfcheckload3d
916903

917904
subroutine compute_vertical_coords(alev, blev, ptop)
918905
use iso_fortran_env, only: error_unit
919-
use snapgrdML, only: alevel, blevel, vlevel, ivcoor, klevel, kadd, &
906+
use snapgrdML, only: alevel, blevel, vlevel, ivcoor, klevel, &
920907
ahalf, bhalf, vhalf
921908
use snapmetML, only: met_params
922909
use snapdimML, only: nk
@@ -929,38 +916,11 @@ subroutine compute_vertical_coords(alev, blev, ptop)
929916
real :: db, dp, p1, p2
930917
integer :: k
931918

932-
do k = 2, nk - kadd
919+
do k = 2, nk
933920
alevel(k) = alev(k)
934921
blevel(k) = blev(k)
935922
end do
936923

937-
if (kadd > 0) then
938-
if (ivcoor == 2) then
939-
!..sigma levels ... blevel=sigma
940-
db = blevel(nk - kadd - 1) - blevel(nk - kadd)
941-
db = max(db, blevel(nk - kadd)/float(kadd))
942-
do k = nk - kadd + 1, nk
943-
blevel(k) = max(blevel(k - 1) - db, 0.)
944-
end do
945-
elseif (ivcoor == 10) then
946-
!..eta (hybrid) levels
947-
p1 = alevel(nk - kadd) + blevel(nk - kadd)*1000.
948-
p2 = alevel(nk - kadd - 1) + blevel(nk - kadd - 1)*1000.
949-
dp = p2 - p1
950-
if (p1 - dp*kadd < 10.) dp = (p1 - 10.)/kadd
951-
db = blevel(nk - kadd - 1) - blevel(nk - kadd)
952-
db = max(db, blevel(nk - kadd)/float(kadd))
953-
do k = nk - kadd + 1, nk
954-
p1 = p1 - dp
955-
blevel(k) = max(blevel(k - 1) - db, 0.)
956-
alevel(k) = p1 - blevel(k)*1000.
957-
end do
958-
else
959-
write (error_unit, *) 'PROGRAM ERROR. ivcoor= ', ivcoor
960-
error stop 255
961-
end if
962-
end if
963-
964924
if (ivcoor == 2) then
965925
!..sigma levels (norlam)
966926
do k = 2, nk

src/common/snap.F90

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ PROGRAM bsnap
171171
ncomp, def_comp, nparnum, &
172172
time_profile
173173
USE snapposML, only: irelpos, nrelpos, release_positions
174-
USE snapgrdML, only: modleveldump, ivcoor, kadd, &
174+
USE snapgrdML, only: modleveldump, ivcoor, &
175175
klevel, imslp, itotcomp, gparam, &
176176
igtype, imodlevel, precipitation_in_output
177177
USE snaptabML, only: tabcon
@@ -232,7 +232,7 @@ PROGRAM bsnap
232232
integer :: nhrun = 0, nhrel = 0
233233
logical :: use_random_walk = .true.
234234
logical :: autodetect_grid_params = .false.
235-
integer :: m, np, npl, nlevel = 0, ifltim = 0
235+
integer :: m, np, npl, nlevel, ifltim = 0
236236
logical :: synoptic_output = .false.
237237
integer :: k, ierror, i, n
238238
integer :: ih
@@ -459,7 +459,6 @@ PROGRAM bsnap
459459

460460
!..information to log file
461461
write (iulog, *) 'nx,ny,nk: ', nx, ny, nk
462-
write (iulog, *) 'kadd: ', kadd
463462
write (iulog, *) 'klevel:'
464463
write (iulog, *) (klevel(i), i=1, nk)
465464
write (iulog, *) 'imslp: ', imslp
@@ -1584,25 +1583,21 @@ subroutine read_inputfile(snapinput_unit)
15841583
ivcoor = 10
15851584
case ('levels.input')
15861585
!..levels.input=<num_levels, 0,kk,k,k,k,....,1>
1587-
!..levels.input=<num_levels, 0,kk,k,k,k,....,18,0,0,...>
1586+
!..levels.input=<num_levels, 0,kk,k,k,k,....,18>
15881587
if (.not. has_value) goto 12
1589-
if (nlevel /= 0) then
1588+
if (allocated(klevel)) then
15901589
write (error_unit, *) "re-assigning levels"
15911590
DEALLOCATE(klevel, STAT=AllocateStatus)
15921591
end if
15931592
read (cinput(pname_start:pname_end), *, err=12) nlevel
15941593
nk = nlevel
1595-
ALLOCATE (klevel(nk), STAT=AllocateStatus)
1594+
ALLOCATE(klevel(nk), STAT=AllocateStatus)
15961595
IF (AllocateStatus /= 0) ERROR STOP AllocateErrorMessage
1597-
! ALLOCATE ( ipcount(mdefcomp, nk), STAT = AllocateStatus)
1598-
! IF (AllocateStatus /= 0) ERROR STOP AllocateErrorMessage
1599-
! ALLOCATE ( npcount(nk), STAT = AllocateStatus)
1600-
! IF (AllocateStatus /= 0) ERROR STOP AllocateErrorMessage
16011596

16021597
read (cinput(pname_start:pname_end), *, err=12) nlevel, (klevel(i), i=1, nlevel)
16031598
if (klevel(1) /= 0 .OR. klevel(2) == 0) goto 12
1604-
kadd = count(klevel(2:nk) == 0)
1605-
do i = nk - kadd - 1, 2, -1
1599+
1600+
do i = nk - 1, 2, -1
16061601
if (klevel(i) <= klevel(i + 1)) goto 12
16071602
end do
16081603
case ('forecast.hour.min')
@@ -1826,8 +1821,7 @@ subroutine conform_input(ierror)
18261821
endif
18271822
endif
18281823
end if
1829-
nlevel = size(klevel)
1830-
nk = nlevel
1824+
nk = size(klevel)
18311825
write (error_unit, *) "autodetection of grid-param: ", gparam
18321826
end if
18331827

@@ -1845,7 +1839,7 @@ subroutine conform_input(ierror)
18451839
write (error_unit, *) 'Input model level type (sigma,eta) not specified'
18461840
ierror = 1
18471841
end if
1848-
if (nlevel == 0) then
1842+
if (.not.allocated(klevel)) then
18491843
write (error_unit, *) 'Input model levels not specified'
18501844
ierror = 1
18511845
end if

src/common/snapgrdML.f90

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module snapgrdML
2222

2323
!> mapping from internal vertical coordinate to MET vertical coord
2424
!>
25-
!> sequence: bottom to top (kk,kk-1,....1)
25+
!> sequence: bottom to top (0,kk,kk-1,...,1)
2626
!>
2727
!> level no. 1 should be 0 (surface fields here)
2828
!>
@@ -113,10 +113,6 @@ module snapgrdML
113113
!> * 2=sigma (Norlam)
114114
!> * 10=eta/hybrid (Hirlam,...))
115115
integer, save, public :: ivcoor = 0
116-
!> levels added at the top (when missing upper model levels)
117-
!>
118-
!> (u,v copied up, w reduced, pot.temp. const.)
119-
integer, save, public :: kadd
120116
!> table of level numbers for interpolation
121117
!>
122118
!> (key is vlevel*10000)

0 commit comments

Comments
 (0)