-
Notifications
You must be signed in to change notification settings - Fork 28
Ensemble filename and stoch restart fixes #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ module MOM_io | |
| public :: file_exists, open_ASCII_file, close_file | ||
| public :: MOM_file, MOM_infra_file, MOM_netcdf_file | ||
| public :: field_exists, get_filename_appendix | ||
| public :: append_ensemble_appendix | ||
| public :: fieldtype, field_size, get_field_atts | ||
| public :: axistype, get_axis_data | ||
| public :: MOM_read_data, MOM_read_vector, read_field_chksum | ||
|
|
@@ -2997,6 +2998,48 @@ subroutine MOM_write_field_0d(IO_handle, field_md, field, tstamp, fill_value, sc | |
| call IO_handle%write_field(field_md, scaled_val, tstamp=tstamp) | ||
| end subroutine MOM_write_field_0d | ||
|
|
||
| !> Append the ensemble appendix to a filename. If provided, the appendix is appended after | ||
| !! the last occurrence of the append_after substring in the filename. | ||
| subroutine append_ensemble_appendix(filename, append_after) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we rename this function
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up renaming it as |
||
| character(len=*), intent(inout) :: filename !< The filename to which the appendix is appended | ||
| character(len=*), optional, intent(in) :: append_after !< The string after which the appendix is appended. | ||
| !! If not provided or found, the appendix is appended | ||
| !! at the end of the filename. | ||
| ! Local variables | ||
| character(len=32) :: filename_appendix_t ! trimmed ensemble id to be appended to the filename | ||
| character(len=:), allocatable :: filename_t ! trimmed filename | ||
| character(len=:), allocatable :: append_after_t ! trimmed append_after | ||
| integer :: pos ! The filename string index after which the appendix is to be appended | ||
|
|
||
| call get_filename_appendix(filename_appendix_t) | ||
| filename_appendix_t = trim(filename_appendix_t) | ||
| if (len(filename_appendix_t) == 0) return | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of trimming the string and then finding the length, you could just check
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, I actually switched from |
||
|
|
||
| filename_t = trim(filename) | ||
| pos = len(filename_t) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, you can just use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added
If you think (Just noticed that trim call in 3039 is unnecessary, so it needs to be removed at the least.)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I managed to miss that 3018 was |
||
|
|
||
| ! If append_after is provided, find the last occurrence of append_after in the filename and set pos accordingly. | ||
| if (present(append_after)) then | ||
| append_after_t = trim(append_after) | ||
| pos = index(filename_t, append_after_t, back=.true.) | ||
| if (pos == 0) then | ||
| call MOM_error(FATAL, "append_ensemble_appendix: The string "//trim(append_after)// & | ||
| " was not found in the filename "//trim(filename)) | ||
| endif | ||
| pos = pos + len_trim(append_after_t) - 1 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opposite comment time :) Since
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, this should be just
then changed
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| endif | ||
|
|
||
| ! Append the ensemble appendix to the filename. If the appendix is to be added to | ||
| ! the end of the filename, do so before the .nc extension if it exists. | ||
| if (pos>3 .and. pos == len(filename_t)) then | ||
| if (filename_t(pos-2:pos) == ".nc") then | ||
| pos = pos - 3 ! Position before the .nc extension | ||
| endif | ||
| endif | ||
| filename = filename_t(1:pos)//trim(filename_appendix_t)//filename_t(pos+1:) | ||
|
|
||
| end subroutine append_ensemble_appendix | ||
|
|
||
| !> Given filename and fieldname, this subroutine returns the size of the field in the file | ||
| subroutine field_size(filename, fieldname, sizes, field_found, no_domain, ndims, ncid_in) | ||
| character(len=*), intent(in) :: filename !< The name of the file to read | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like having this as a stand-alone function!