Skip to content

Commit

Permalink
Merge pull request mom-ocean#1327 from Hallberg-NOAA/add_file_type
Browse files Browse the repository at this point in the history
MOM6: +I/O interface changes, including a new file_type
  • Loading branch information
marshallward authored Feb 18, 2021
2 parents 4ea2f71 + 95f6711 commit 45b3366
Show file tree
Hide file tree
Showing 15 changed files with 621 additions and 483 deletions.
42 changes: 20 additions & 22 deletions config_src/ice_solo_driver/ice_shelf_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ program Shelf_main
use MOM_get_input, only : Get_MOM_Input, directories
use MOM_grid, only : ocean_grid_type, MOM_grid_init, MOM_grid_end
use MOM_hor_index, only : hor_index_type, hor_index_init
use MOM_io, only : MOM_io_init, file_exists, open_file, close_file
use MOM_io, only : MOM_io_init, file_exists, open_ASCII_file, close_file
use MOM_io, only : check_nml_error, io_infra_init, io_infra_end
use MOM_io, only : APPEND_FILE, ASCII_FILE, READONLY_FILE, SINGLE_FILE
use MOM_io, only : APPEND_FILE, READONLY_FILE, SINGLE_FILE
use MOM_open_boundary, only : ocean_OBC_type
use MOM_restart, only : save_restart
use MOM_string_functions,only : uppercase
Expand Down Expand Up @@ -176,7 +176,7 @@ program Shelf_main

if (file_exists('input.nml')) then
! Provide for namelist specification of the run length and calendar data.
call open_file(unit, 'input.nml', form=ASCII_FILE, action=READONLY_FILE)
call open_ASCII_file(unit, 'input.nml', action=READONLY_FILE)
read(unit, ice_solo_nml, iostat=io_status)
call close_file(unit)
ierr = check_nml_error(io_status,'ice_solo_nml')
Expand All @@ -187,15 +187,14 @@ program Shelf_main

! Read ocean_solo restart, which can override settings from the namelist.
if (file_exists(trim(dirs%restart_input_dir)//'ice_solo.res')) then
call open_file(unit,trim(dirs%restart_input_dir)//'ice_solo.res', &
form=ASCII_FILE,action=READONLY_FILE)
call open_ASCII_file(unit, trim(dirs%restart_input_dir)//'ice_solo.res', action=READONLY_FILE)
read(unit,*) calendar_type
read(unit,*) date_init
read(unit,*) date
call close_file(unit)
else
calendar = uppercase(calendar)
if (calendar(1:6) == 'JULIAN') then ; calendar_type = JULIAN
if (calendar(1:6) == 'JULIAN') then ; calendar_type = JULIAN
elseif (calendar(1:9) == 'GREGORIAN') then ; calendar_type = GREGORIAN
elseif (calendar(1:6) == 'NOLEAP') then ; calendar_type = NOLEAP
elseif (calendar(1:10)=='THIRTY_DAY') then ; calendar_type = THIRTY_DAY_MONTHS
Expand Down Expand Up @@ -341,15 +340,14 @@ program Shelf_main
call diag_mediator_close_registration(diag)

! Write out a time stamp file.
if (calendar_type /= NO_CALENDAR) then
call open_file(unit, 'time_stamp.out', form=ASCII_FILE, action=APPEND_FILE, &
threading=SINGLE_FILE)
if (is_root_pe() .and. (calendar_type /= NO_CALENDAR)) then
call open_ASCII_file(unit, 'time_stamp.out', action=APPEND_FILE)
call get_date(Time, date(1), date(2), date(3), date(4), date(5), date(6))
month = month_name(date(2))
if (is_root_pe()) write(unit,'(6i4,2x,a3)') date, month(1:3)
write(unit,'(6i4,2x,a3)') date, month(1:3)
call get_date(Time_end, date(1), date(2), date(3), date(4), date(5), date(6))
month = month_name(date(2))
if (is_root_pe()) write(unit,'(6i4,2x,a3)') date, month(1:3)
write(unit,'(6i4,2x,a3)') date, month(1:3)
call close_file(unit)
endif

Expand Down Expand Up @@ -428,19 +426,19 @@ program Shelf_main
dirs%restart_output_dir)

! Write ice shelf solo restart file.
call open_file(unit, trim(dirs%restart_output_dir)//'shelf.res', nohdrs=.true.)
if (is_root_pe())then
write(unit, '(i6,8x,a)') calendar_type, &
'(Calendar: no_calendar=0, thirty_day_months=1, julian=2, gregorian=3, noleap=4)'

call get_date(Start_time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Model start time: year, month, day, hour, minute, second'
call get_date(Time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Current model time: year, month, day, hour, minute, second'
call open_ASCII_file(unit, trim(dirs%restart_output_dir)//'shelf.res')
write(unit, '(i6,8x,a)') calendar_type, &
'(Calendar: no_calendar=0, thirty_day_months=1, julian=2, gregorian=3, noleap=4)'

call get_date(Start_time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Model start time: year, month, day, hour, minute, second'
call get_date(Time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Current model time: year, month, day, hour, minute, second'
call close_file(unit)
endif
call close_file(unit)
endif

if (is_root_pe()) then
Expand Down
44 changes: 21 additions & 23 deletions config_src/solo_driver/MOM_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ program MOM_main
use MOM_ice_shelf, only : shelf_calc_flux, add_shelf_forces, ice_shelf_save_restart
use MOM_ice_shelf, only : initialize_ice_shelf_fluxes, initialize_ice_shelf_forces
use MOM_interpolate, only : time_interp_external_init
use MOM_io, only : file_exists, open_file, close_file
use MOM_io, only : file_exists, open_ASCII_file, close_file
use MOM_io, only : check_nml_error, io_infra_init, io_infra_end
use MOM_io, only : APPEND_FILE, ASCII_FILE, READONLY_FILE, SINGLE_FILE
use MOM_io, only : APPEND_FILE, READONLY_FILE
use MOM_restart, only : MOM_restart_CS, save_restart
use MOM_string_functions,only : uppercase
use MOM_surface_forcing, only : set_forcing, forcing_save_restart
Expand Down Expand Up @@ -238,7 +238,7 @@ program MOM_main

if (file_exists('input.nml')) then
! Provide for namelist specification of the run length and calendar data.
call open_file(unit, 'input.nml', form=ASCII_FILE, action=READONLY_FILE)
call open_ASCII_file(unit, 'input.nml', action=READONLY_FILE)
read(unit, ocean_solo_nml, iostat=io_status)
call close_file(unit)
ierr = check_nml_error(io_status,'ocean_solo_nml')
Expand All @@ -252,15 +252,14 @@ program MOM_main

! Read ocean_solo restart, which can override settings from the namelist.
if (file_exists(trim(dirs%restart_input_dir)//'ocean_solo.res')) then
call open_file(unit,trim(dirs%restart_input_dir)//'ocean_solo.res', &
form=ASCII_FILE,action=READONLY_FILE)
call open_ASCII_file(unit, trim(dirs%restart_input_dir)//'ocean_solo.res', action=READONLY_FILE)
read(unit,*) calendar_type
read(unit,*) date_init
read(unit,*) date
call close_file(unit)
else
calendar = uppercase(calendar)
if (calendar(1:6) == 'JULIAN') then ; calendar_type = JULIAN
if (calendar(1:6) == 'JULIAN') then ; calendar_type = JULIAN
elseif (calendar(1:9) == 'GREGORIAN') then ; calendar_type = GREGORIAN
elseif (calendar(1:6) == 'NOLEAP') then ; calendar_type = NOLEAP
elseif (calendar(1:10)=='THIRTY_DAY') then ; calendar_type = THIRTY_DAY_MONTHS
Expand Down Expand Up @@ -432,15 +431,14 @@ program MOM_main
call diag_mediator_close_registration(diag)

! Write out a time stamp file.
if (calendar_type /= NO_CALENDAR) then
call open_file(unit, 'time_stamp.out', form=ASCII_FILE, action=APPEND_FILE, &
threading=SINGLE_FILE)
if (is_root_pe() .and. (calendar_type /= NO_CALENDAR)) then
call open_ASCII_file(unit, 'time_stamp.out', action=APPEND_FILE)
call get_date(Time, date(1), date(2), date(3), date(4), date(5), date(6))
month = month_name(date(2))
if (is_root_pe()) write(unit,'(6i4,2x,a3)') date, month(1:3)
write(unit,'(6i4,2x,a3)') date, month(1:3)
call get_date(Time_end, date(1), date(2), date(3), date(4), date(5), date(6))
month = month_name(date(2))
if (is_root_pe()) write(unit,'(6i4,2x,a3)') date, month(1:3)
write(unit,'(6i4,2x,a3)') date, month(1:3)
call close_file(unit)
endif

Expand Down Expand Up @@ -618,19 +616,19 @@ program MOM_main
if (use_ice_shelf) call ice_shelf_save_restart(ice_shelf_CSp, Time, &
dirs%restart_output_dir)
! Write ocean solo restart file.
call open_file(unit, trim(dirs%restart_output_dir)//'ocean_solo.res', nohdrs=.true.)
if (is_root_pe())then
write(unit, '(i6,8x,a)') calendar_type, &
'(Calendar: no_calendar=0, thirty_day_months=1, julian=2, gregorian=3, noleap=4)'

call get_date(Start_time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Model start time: year, month, day, hour, minute, second'
call get_date(Time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Current model time: year, month, day, hour, minute, second'
if (is_root_pe()) then
call open_ASCII_file(unit, trim(dirs%restart_output_dir)//'ocean_solo.res')
write(unit, '(i6,8x,a)') calendar_type, &
'(Calendar: no_calendar=0, thirty_day_months=1, julian=2, gregorian=3, noleap=4)'

call get_date(Start_time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Model start time: year, month, day, hour, minute, second'
call get_date(Time, yr, mon, day, hr, mins, sec)
write(unit, '(6i6,8x,a)') yr, mon, day, hr, mins, sec, &
'Current model time: year, month, day, hour, minute, second'
call close_file(unit)
endif
call close_file(unit)
endif

if (is_root_pe()) then
Expand Down
13 changes: 6 additions & 7 deletions src/ALE/MOM_ALE.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module MOM_ALE
use MOM_error_handler, only : callTree_enter, callTree_leave, callTree_waypoint
use MOM_file_parser, only : get_param, param_file_type, log_param
use MOM_io, only : vardesc, var_desc, fieldtype, SINGLE_FILE
use MOM_io, only : create_file, write_field, close_file
use MOM_io, only : create_file, write_field, close_file, file_type
use MOM_interface_heights,only : find_eta
use MOM_open_boundary, only : ocean_OBC_type, OBC_DIRECTION_E, OBC_DIRECTION_W
use MOM_open_boundary, only : OBC_DIRECTION_N, OBC_DIRECTION_S
Expand Down Expand Up @@ -1273,7 +1273,7 @@ subroutine ALE_writeCoordinateFile( CS, GV, directory )
character(len=240) :: filepath
type(vardesc) :: vars(2)
type(fieldtype) :: fields(2)
integer :: unit
type(file_type) :: IO_handle ! The I/O handle of the fileset
real :: ds(GV%ke), dsi(GV%ke+1)

filepath = trim(directory) // trim("Vertical_coordinate")
Expand All @@ -1287,14 +1287,13 @@ subroutine ALE_writeCoordinateFile( CS, GV, directory )
vars(2) = var_desc('ds_interface', getCoordinateUnits( CS%regridCS ), &
'Layer Center Coordinate Separation','1','i','1')

call create_file(unit, trim(filepath), vars, 2, fields, SINGLE_FILE, GV=GV)
call write_field(unit, fields(1), ds)
call write_field(unit, fields(2), dsi)
call close_file(unit)
call create_file(IO_handle, trim(filepath), vars, 2, fields, SINGLE_FILE, GV=GV)
call write_field(IO_handle, fields(1), ds)
call write_field(IO_handle, fields(2), dsi)
call close_file(IO_handle)

end subroutine ALE_writeCoordinateFile


!> Set h to coordinate values for fixed coordinate systems
subroutine ALE_initThicknessToCoord( CS, G, GV, h )
type(ALE_CS), intent(inout) :: CS !< module control structure
Expand Down
11 changes: 5 additions & 6 deletions src/diagnostics/MOM_PointAccel.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module MOM_PointAccel
use MOM_file_parser, only : get_param, log_param, log_version, param_file_type
use MOM_get_input, only : directories
use MOM_grid, only : ocean_grid_type
use MOM_io, only : open_file
use MOM_io, only : APPEND_FILE, ASCII_FILE, MULTIPLE, SINGLE_FILE
use MOM_io, only : open_ASCII_file, APPEND_FILE, MULTIPLE, SINGLE_FILE
use MOM_time_manager, only : time_type, get_time, get_date, set_date, operator(-)
use MOM_unit_scaling, only : unit_scale_type
use MOM_variables, only : ocean_internal_state, accel_diag_ptrs, cont_diag_ptrs
Expand Down Expand Up @@ -120,8 +119,8 @@ subroutine write_u_accel(I, j, um, hin, ADp, CDp, dt_in_T, G, GV, US, CS, vel_rp
! Open up the file for output if this is the first call.
if (CS%u_file < 0) then
if (len_trim(CS%u_trunc_file) < 1) return
call open_file(CS%u_file, trim(CS%u_trunc_file), action=APPEND_FILE, &
form=ASCII_FILE, threading=MULTIPLE, fileset=SINGLE_FILE)
call open_ASCII_file(CS%u_file, trim(CS%u_trunc_file), action=APPEND_FILE, &
threading=MULTIPLE, fileset=SINGLE_FILE)
if (CS%u_file < 0) then
call MOM_error(NOTE, 'Unable to open file '//trim(CS%u_trunc_file)//'.')
return
Expand Down Expand Up @@ -453,8 +452,8 @@ subroutine write_v_accel(i, J, vm, hin, ADp, CDp, dt_in_T, G, GV, US, CS, vel_rp
! Open up the file for output if this is the first call.
if (CS%v_file < 0) then
if (len_trim(CS%v_trunc_file) < 1) return
call open_file(CS%v_file, trim(CS%v_trunc_file), action=APPEND_FILE, &
form=ASCII_FILE, threading=MULTIPLE, fileset=SINGLE_FILE)
call open_ASCII_file(CS%v_file, trim(CS%v_trunc_file), action=APPEND_FILE, &
threading=MULTIPLE, fileset=SINGLE_FILE)
if (CS%v_file < 0) then
call MOM_error(NOTE, 'Unable to open file '//trim(CS%v_trunc_file)//'.')
return
Expand Down
Loading

0 comments on commit 45b3366

Please sign in to comment.