Skip to content

Commit 03e4164

Browse files
authored
fix logic errors (#138)
1 parent 726af37 commit 03e4164

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

GFDL_tools/read_climate_nudge_data.F90

+19-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module read_climate_nudge_data_mod
2828
get_dimension_names, get_dimension_size, FmsNetcdfFile_t, &
2929
get_num_variables, get_variable_names, get_variable_size, &
3030
get_variable_num_dimensions, get_variable_units, &
31-
get_time_calendar, read_data, variable_att_exists
31+
get_time_calendar, read_data, variable_att_exists, &
32+
is_dimension_unlimited
3233
use mpp_mod, only: input_nml_file, mpp_npes, mpp_get_current_pelist
3334
use constants_mod, only: PI, GRAV, RDGAS, RVGAS
3435

@@ -107,6 +108,7 @@ subroutine read_climate_nudge_data_init (nlon, nlat, nlev, ntime)
107108
character(len=32), allocatable :: fields(:)
108109
type(FmsNetcdfFile_t) :: fileobj
109110
integer, allocatable, dimension(:) :: pes !< Array of ther pes in the current pelist
111+
character(len=128), dimension(:), allocatable :: names
110112

111113
if (module_is_initialized) return
112114
! initial file names to blanks
@@ -147,22 +149,32 @@ subroutine read_climate_nudge_data_init (nlon, nlat, nlev, ntime)
147149
if (open_file(fileobj, trim(filenames(n)), "read", pelist=pes)) then
148150
Files(n)%ndim=get_num_dimensions(fileobj)
149151

150-
allocate (Files(n)%length_axes(Files(n)%ndim))
152+
allocate(files(n)%length_axes(Files(n)%ndim))
153+
allocate(names(files(n)%ndim))
154+
call get_dimension_names(fileobj, names)
155+
files(n)%axes(:) = ""
151156

152157
! inquire dimension sizes
153158
do i = 1, Files(n)%ndim
154-
call get_dimension_names(fileobj, Files(n)%axes)
155159
do j = 1, NUM_REQ_AXES
156-
if (trim(Files(n)%axes(j)) .eq. trim(required_axis_names(j))) then
160+
if (trim(names(i)) .eq. trim(required_axis_names(j))) then
161+
files(n)%axes(j) = trim(names(i))
157162
call get_dimension_size(fileobj, Files(n)%axes(j), Files(n)%length_axes(j))
158163
call check_axis_size (j,Files(n)%length_axes(j))
159164
Files(n)%axis_index(j) = i
160165
exit
161166
endif
162167
enddo
168+
if (j .gt. num_req_axes) then
169+
if (is_dimension_unlimited(fileobj, trim(names(i)))) then
170+
! time axis indexing
171+
files(n)%axes(index_time) = trim(names(i))
172+
call get_dimension_size(fileobj, files(n)%axes(index_time), &
173+
files(n)%length_axes(index_time))
174+
endif
175+
endif
163176
enddo
164-
! time axis indexing
165-
call get_dimension_size(fileobj, Files(n)%axes(INDEX_TIME), Files(n)%length_axes(INDEX_TIME))
177+
deallocate(names)
166178
Files(n)%ntim = Files(n)%length_axes(INDEX_TIME)
167179
Files(n)%time_offset = numtime
168180
numtime = numtime + Files(n)%ntim
@@ -173,7 +185,7 @@ subroutine read_climate_nudge_data_init (nlon, nlat, nlev, ntime)
173185
Files(n)%field_index = 0
174186
do i = 1, Files(n)%nvar
175187
nd = get_variable_num_dimensions(fileobj, fields(i))
176-
call get_variable_size(fileobj, fields(i), siz)
188+
call get_variable_size(fileobj, fields(i), siz(1:nd))
177189
do j = 1, NUM_REQ_FLDS
178190
if (trim(fields(i)) .eq. trim(required_field_names(j))) then
179191
Files(n)%field_index(j) = i

0 commit comments

Comments
 (0)