Skip to content

Commit 0f22d06

Browse files
committed
Merge branch 'czender/elm_mali/interpinic_netcdf_boz_fixes' into next (PR #6614)
This new feature allows `interpinic` to interpolate an ELM initial conditions file that require storage in `NC_FORMAT_64BIT_DATA` and other netCDF4 formats. [BFB] [Bugfix]
2 parents 985943f + ece56d1 commit 0f22d06

File tree

3 files changed

+81
-57
lines changed

3 files changed

+81
-57
lines changed

components/elm/tools/interpinic/src/fmain.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ program fmain
1414
character(len= 256) :: arg
1515
integer :: n !index
1616
integer :: nargs !number of arguments
17-
integer, external :: iargc !number of arguments function
17+
integer :: iargc !number of arguments function
1818
character(len=256) :: finidati !input initial dataset to read
1919
character(len=256) :: finidato !output initial dataset to create
2020
character(len=256) :: cmdline !input command line

components/elm/tools/interpinic/src/interpinic.F90

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,19 @@ subroutine interp_filei (fin, fout, cmdline)
146146
call check_ret (nf90_open(fin, NF90_NOWRITE, ncidi ))
147147
call check_ret (nf90_open(fout, NF90_NOWRITE, ncido ))
148148
call check_ret (nf_inq_format( ncido, ncformat ))
149-
if ( ncformat /= NF_FORMAT_64BIT )then
150-
write (6,*) 'error: output file is NOT in NetCDF large-file format!'
151-
stop
149+
150+
! Allow any format for output dataset
151+
152+
if ( ncformat == NF_FORMAT_CLASSIC )then
153+
write (6,*) 'info: output file is NF_FORMAT_CLASSIC'
154+
else if ( ncformat == NF_FORMAT_64BIT_OFFSET )then
155+
write (6,*) 'info: output file is NF_FORMAT_64BIT_OFFSET'
156+
else if ( ncformat == NF_FORMAT_64BIT_DATA )then
157+
write (6,*) 'info: output file is NF_FORMAT_64BIT_DATA'
158+
else if ( ncformat == NF_FORMAT_NETCDF4 )then
159+
write (6,*) 'info: output file is NF_FORMAT_NETCDF4'
160+
else if ( ncformat == NF_FORMAT_NETCDF4_CLASSIC )then
161+
write (6,*) 'info: output file is NF_FORMAT_NETCDF4_CLASSIC'
152162
end if
153163

154164
call check_ret (nf90_inq_dimid(ncidi, "column", dimidcols ))
@@ -214,12 +224,25 @@ subroutine interp_filei (fin, fout, cmdline)
214224
ret = nf90_inq_dimid(ncidi, "month", dimidmon)
215225
if (ret == NF90_NOERR) then
216226
call check_ret (nf90_inquire_dimension(ncidi, dimidmon, len=nlevmon))
217-
call check_ret (nf90_inq_dimid(ncido, "month", dimid ))
218-
call check_ret (nf90_inquire_dimension(ncido, dimid, len=dimlen))
219-
if (dimlen/=nlevmon) then
220-
write (6,*) 'error: input and output nlevmon values disagree'
221-
write (6,*) 'input nlevmon = ',nlevmon,' output nlevmon = ',dimlen
222-
stop
227+
228+
! Many restart files have "month" dimension in input dataset
229+
! It is only necessary that the output dataset contains "month" dimension
230+
! when a variable in the input dataset contains the "month" dimension
231+
! Otherwise, the "month" dimension will never be used
232+
! Warn rather than die when input has "month" and output does not
233+
234+
ret = nf90_inq_dimid(ncido, "month", dimid )
235+
if ( ret == nf_ebaddim ) then
236+
write (6,*) 'warning: input has "month" dimension and output does not'
237+
write (6,*) 'warning: interpolation will fail if any input variable uses "month" dimension'
238+
write (6,*) 'chill: many times the "month" dimension is superfluous so this might work...'
239+
else
240+
call check_ret (nf90_inquire_dimension(ncido, dimid, len=dimlen))
241+
if (dimlen/=nlevmon) then
242+
write (6,*) 'error: input and output nlevmon values disagree'
243+
write (6,*) 'input nlevmon = ',nlevmon,' output nlevmon = ',dimlen
244+
stop
245+
end if
223246
end if
224247
else
225248
write (6,*) 'month dimension does NOT exist on the input dataset'
@@ -321,7 +344,9 @@ subroutine interp_filei (fin, fout, cmdline)
321344
! OK now, open the output file for writing
322345
!
323346
call check_ret(nf90_close( ncido))
324-
call check_ret (nf90_open(fout, ior(NF90_WRITE, NF_64BIT_OFFSET), ncido ))
347+
348+
! Allow any format for output dataset
349+
call check_ret (nf90_open(fout, NF90_WRITE, ncido ))
325350

326351
call addglobal (ncido, cmdline)
327352

@@ -1503,8 +1528,7 @@ subroutine addglobal (ncid, cmdline)
15031528
character(len=10) :: time
15041529
character(len= 5) :: zone
15051530
character(len=18) :: datetime
1506-
character(len=256):: version = &
1507-
"$HeadURL: https://svn-ccsm-models.cgd.ucar.edu/clm2/trunk_tags/clm4_5_1_r085/models/lnd/clm/tools/clm4_5/interpinic/src/interpinic.F90 $"
1531+
character(len=256):: version = ""
15081532
character(len=256) :: revision_id = "$Id: interpinic.F90 54953 2013-11-06 16:29:45Z sacks $"
15091533
character(len=16) :: logname
15101534
character(len=16) :: hostname

components/elm/tools/interpinic/src/shr_infnan_mod.F90

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
module shr_infnan_mod
44

5-
!! Inf_NaN_Detection module
5+
!! Inf_NaN_Detection module
66
!! Copyright(c) 2003, Lahey Computer Systems, Inc.
7-
!! Copies of this source code, or standalone compiled files
7+
!! Copies of this source code, or standalone compiled files
88
!! derived from this source may not be sold without permission
9-
!! from Lahey Computers Systems. All or part of this module may be
9+
!! from Lahey Computers Systems. All or part of this module may be
1010
!! freely incorporated into executable programs which are offered
1111
!! for sale. Otherwise, distribution of all or part of this file is
1212
!! permitted, provided this copyright notice and header are included.
@@ -22,12 +22,12 @@ module shr_infnan_mod
2222
!! isneginf(x) - test for a negative "infinite" value
2323
!!
2424
!! Each function accepts a single or double precision real argument, and
25-
!! returns a true or false value to indicate the presence of the value
25+
!! returns a true or false value to indicate the presence of the value
2626
!! being tested for. If the argument is array valued, the function returns
2727
!! a conformable logical array, suitable for use with the ANY function, or
2828
!! as a logical mask.
2929
!!
30-
!! Each function operates by transferring the bit pattern from a real
30+
!! Each function operates by transferring the bit pattern from a real
3131
!! variable to an integer container. Unless testing for + or - infinity,
3232
!! the sign bit is cleared to zero. The value is exclusive ORed with
3333
!! the value being tested for. The integer result of the IEOR function is
@@ -48,14 +48,14 @@ module shr_infnan_mod
4848
integer, parameter :: Double = selected_int_kind(precision(1.0_r8))
4949

5050
! Single precision IEEE values
51-
integer(Single), parameter :: sNaN = Z"7FC00000"
52-
integer(Single), parameter :: sPosInf = Z"7F800000"
53-
integer(Single), parameter :: sNegInf = Z"FF800000"
51+
integer(Single), parameter :: sNaN = int(Z"7FC00000")
52+
integer(Single), parameter :: sPosInf = int(Z"7F800000")
53+
integer(Single), parameter :: sNegInf = int(Z"FF800000")
5454

5555
! Double precision IEEE values
56-
integer(Double), parameter :: dNaN = Z"7FF8000000000000"
57-
integer(Double), parameter :: dPosInf = Z"7FF0000000000000"
58-
integer(Double), parameter :: dNegInf = Z"FFF0000000000000"
56+
integer(Double), parameter :: dNaN = int(Z"7FF8000000000000")
57+
integer(Double), parameter :: dPosInf = int(Z"7FF0000000000000")
58+
integer(Double), parameter :: dNegInf = int(Z"FFF0000000000000")
5959

6060
! Locatation of single and double precision sign bit (Intel)
6161
! Subtract one because bit numbering starts at zero
@@ -84,30 +84,30 @@ module shr_infnan_mod
8484
module procedure sisnan
8585
module procedure disnan
8686
#endif
87-
end interface
87+
end interface
8888

8989
interface shr_infnan_isinf
9090
module procedure sisinf
9191
module procedure disinf
92-
end interface
93-
92+
end interface
93+
9494
interface shr_infnan_isposinf
9595
module procedure sisposinf
9696
module procedure disposinf
97-
end interface
98-
97+
end interface
98+
9999
interface shr_infnan_isneginf
100100
module procedure sisneginf
101101
module procedure disneginf
102-
end interface
102+
end interface
103103

104104

105105
integer :: shr_sisnan
106106
external :: shr_sisnan
107107
integer :: shr_disnan
108108
external :: shr_disnan
109109

110-
contains
110+
contains
111111

112112
!
113113
! If FORTRAN intrinsic's exist use them
@@ -134,7 +134,7 @@ elemental function sisnan(x) result(res)
134134
res = isnan(x)
135135
#endif
136136

137-
end function
137+
end function
138138

139139
! Double precision test for NaN
140140
elemental function disnan(d) result(res)
@@ -156,7 +156,7 @@ elemental function disnan(d) result(res)
156156
res = isnan(d)
157157
#endif
158158

159-
end function
159+
end function
160160

161161
!
162162
! Otherwise link to a C function call that either uses the C90 isnan function or a x != x check
@@ -176,13 +176,13 @@ function c_sisnan_1D(x) result(res)
176176
real(r4), intent(in) :: x(:)
177177
logical :: res(size(x))
178178

179-
integer :: i
179+
integer :: i
180180

181181
do i = 1, size(x)
182182
res(i) = (shr_sisnan(x(i)) /= 0)
183183
end do
184184
end function c_sisnan_1D
185-
185+
186186
function c_sisnan_2D(x) result(res)
187187
real(r4), intent(in) :: x(:,:)
188188
logical :: res(size(x,1),size(x,2))
@@ -195,7 +195,7 @@ function c_sisnan_2D(x) result(res)
195195
end do
196196
end do
197197
end function c_sisnan_2D
198-
198+
199199
function c_sisnan_3D(x) result(res)
200200
real(r4), intent(in) :: x(:,:,:)
201201
logical :: res(size(x,1),size(x,2),size(x,3))
@@ -210,7 +210,7 @@ function c_sisnan_3D(x) result(res)
210210
end do
211211
end do
212212
end function c_sisnan_3D
213-
213+
214214
function c_sisnan_4D(x) result(res)
215215
real(r4), intent(in) :: x(:,:,:,:)
216216
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4))
@@ -227,7 +227,7 @@ function c_sisnan_4D(x) result(res)
227227
end do
228228
end do
229229
end function c_sisnan_4D
230-
230+
231231
function c_sisnan_5D(x) result(res)
232232
real(r4), intent(in) :: x(:,:,:,:,:)
233233
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4),size(x,5))
@@ -246,7 +246,7 @@ function c_sisnan_5D(x) result(res)
246246
end do
247247
end do
248248
end function c_sisnan_5D
249-
249+
250250
function c_sisnan_6D(x) result(res)
251251
real(r4), intent(in) :: x(:,:,:,:,:,:)
252252
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4),size(x,5),size(x,6))
@@ -267,7 +267,7 @@ function c_sisnan_6D(x) result(res)
267267
end do
268268
end do
269269
end function c_sisnan_6D
270-
270+
271271
function c_sisnan_7D(x) result(res)
272272
real(r4), intent(in) :: x(:,:,:,:,:,:,:)
273273
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4),size(x,5),size(x,6),size(x,7))
@@ -290,7 +290,7 @@ function c_sisnan_7D(x) result(res)
290290
end do
291291
end do
292292
end function c_sisnan_7D
293-
293+
294294
function c_disnan_scalar(x) result(res)
295295
real(r8), intent(in) :: x
296296
logical :: res
@@ -302,13 +302,13 @@ function c_disnan_1D(x) result(res)
302302
real(r8), intent(in) :: x(:)
303303
logical :: res(size(x))
304304

305-
integer :: i
305+
integer :: i
306306

307307
do i = 1, size(x)
308308
res(i) = (shr_disnan(x(i)) /= 0)
309309
end do
310310
end function c_disnan_1D
311-
311+
312312
function c_disnan_2D(x) result(res)
313313
real(r8), intent(in) :: x(:,:)
314314
logical :: res(size(x,1),size(x,2))
@@ -321,7 +321,7 @@ function c_disnan_2D(x) result(res)
321321
end do
322322
end do
323323
end function c_disnan_2D
324-
324+
325325
function c_disnan_3D(x) result(res)
326326
real(r8), intent(in) :: x(:,:,:)
327327
logical :: res(size(x,1),size(x,2),size(x,3))
@@ -336,7 +336,7 @@ function c_disnan_3D(x) result(res)
336336
end do
337337
end do
338338
end function c_disnan_3D
339-
339+
340340
function c_disnan_4D(x) result(res)
341341
real(r8), intent(in) :: x(:,:,:,:)
342342
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4))
@@ -353,7 +353,7 @@ function c_disnan_4D(x) result(res)
353353
end do
354354
end do
355355
end function c_disnan_4D
356-
356+
357357
function c_disnan_5D(x) result(res)
358358
real(r8), intent(in) :: x(:,:,:,:,:)
359359
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4),size(x,5))
@@ -372,7 +372,7 @@ function c_disnan_5D(x) result(res)
372372
end do
373373
end do
374374
end function c_disnan_5D
375-
375+
376376
function c_disnan_6D(x) result(res)
377377
real(r8), intent(in) :: x(:,:,:,:,:,:)
378378
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4),size(x,5),size(x,6))
@@ -393,7 +393,7 @@ function c_disnan_6D(x) result(res)
393393
end do
394394
end do
395395
end function c_disnan_6D
396-
396+
397397
function c_disnan_7D(x) result(res)
398398
real(r8), intent(in) :: x(:,:,:,:,:,:,:)
399399
logical :: res(size(x,1),size(x,2),size(x,3),size(x,4),size(x,5),size(x,6),size(x,7))
@@ -418,48 +418,48 @@ function c_disnan_7D(x) result(res)
418418
end function c_disnan_7D
419419

420420
#endif
421-
421+
422422
! Single precision test for Inf
423423
elemental function sisinf(x) result(res)
424424
real(r4), intent(in) :: x
425425
logical :: res
426426
res = ieor(ibclr(transfer(x,sPosInf),SPSB), sPosInf) == 0
427-
end function
427+
end function
428428

429429
! Double precision test for Inf
430430
elemental function disinf(d) result(res)
431431
real(r8), intent(in) :: d
432432
logical :: res
433433
res = ieor(ibclr(transfer(d,dPosInf),DPSB), dPosInf) == 0
434-
end function
435-
434+
end function
435+
436436
! Single precision test for +Inf
437437
elemental function sisposinf(x) result(res)
438438
real(r4), intent(in) :: x
439439
logical :: res
440440
res = ieor(transfer(x,sPosInf), sPosInf) == 0
441-
end function
441+
end function
442442

443443
! Double precision test for +Inf
444444
elemental function disposinf(d) result(res)
445445
real(r8), intent(in) :: d
446446
logical :: res
447447
res = ieor(transfer(d,dPosInf), dPosInf) == 0
448-
end function
449-
448+
end function
449+
450450
! Single precision test for -Inf
451451
elemental function sisneginf(x) result(res)
452452
real(r4), intent(in) :: x
453453
logical :: res
454454
res = ieor(transfer(x,sNegInf), sNegInf) == 0
455-
end function
455+
end function
456456

457457
! Double precision test for -Inf
458458
elemental function disneginf(d) result(res)
459459
real(r8), intent(in) :: d
460460
logical :: res
461461
res = ieor(transfer(d,dNegInf), dNegInf) == 0
462-
end function
462+
end function
463463

464464
end module shr_infnan_mod
465465

0 commit comments

Comments
 (0)