Skip to content

Commit a6d6289

Browse files
authored
Improve robustness of cam open/close file register code to fix issues with history output (#333)
Tag name (required for release branches): Originator(s): @jimmielin Description (include the issue title, and the keyword ['closes', 'fixes', 'resolves'] followed by the issue number): - Fixes #332 (`max_mdims` used before defined) - Fixes #331 (unassociated `of%file_desc` in `cam_register_open_file` leading to crash with >2 history files) Describe any changes made to build system: N/A Describe any changes made to the namelist: N/A List any changes to the defaults for the input datasets (e.g. boundary datasets): N/A List all files eliminated and why: N/A List all files added and what they do: N/A List all existing files that have been modified, and describe the changes: (Helpful git command: `git diff --name-status development...<your_branch_name>`) ``` Fixes #331 M src/history/cam_hist_file.F90 Fixes #332 M src/utils/cam_abortutils.F90 ``` If there are new failures (compared to the `test/existing-test-failures.txt` file), have them OK'd by the gatekeeper, note them here, and add them to the file. If there are baseline differences, include the test and the reason for the diff. What is the nature of the change? Roundoff? derecho/intel/aux_sima: derecho/gnu/aux_sima: If this changes climate describe any run(s) done to evaluate the new climate in enough detail that it(they) could be reproduced: CAM-SIMA date used for the baseline comparison tests if different than latest:
1 parent 2ed783a commit a6d6289

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/history/cam_hist_file.F90

+1
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ subroutine config_define_file(this, restart, logname, host, model_doi_url)
10151015
end do
10161016
end do
10171017
! Determine the maximum number of dimensions
1018+
max_mdims = 0
10181019
do field_index = 1, size(this%field_list)
10191020
max_mdims = max(max_mdims, size(this%field_list(field_index)%dimensions()))
10201021
end do

src/utils/cam_abortutils.F90

+13-7
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,31 @@ subroutine cam_register_open_file(file, file_name)
8080
end do
8181
! If we get here, go ahead and register the file
8282
if (associated(open_files_pool)) then
83+
! Reuse pooled structure and point to the next pool entry
8384
of_new => open_files_pool
85+
open_files_pool => open_files_pool%next
8486
allocate(of_new%file_desc, stat=ierr)
8587
call check_allocate(ierr, subname, 'of_file%file_desc', file=__FILE__, &
8688
line=__LINE__)
8789
of_new%file_desc = file
8890
of_new%file_name = file_name
89-
allocate(open_files_pool%next)
90-
open_files_pool%next => open_files_pool
91+
nullify(of_new%next)
9192
else
9293
allocate(of_new)
9394
allocate(of_new%file_desc)
9495
of_new%file_desc = file
9596
of_new%file_name = file_name
96-
open_files_pool => of_new
97-
end if
98-
open_files_tail => of_new
99-
if (.not. associated(open_files_head)) then
100-
open_files_head => of_new
97+
nullify(of_new%next)
10198
end if
99+
100+
! Add the registered file to the tail of the open files list
101+
if(associated(open_files_tail)) then
102+
open_files_tail%next => of_new
103+
open_files_tail => of_new
104+
else
105+
open_files_head => of_new
106+
open_files_tail => of_new
107+
endif
102108
end subroutine cam_register_open_file
103109

104110
subroutine cam_register_close_file(file, log_shutdown_in)

0 commit comments

Comments
 (0)