Skip to content

Commit

Permalink
Merge pull request NOAA-EMC#74 from laurenchilutti/fms2_io_implementa…
Browse files Browse the repository at this point in the history
…tion

Fms2 io implementation
  • Loading branch information
laurenchilutti authored May 10, 2021
2 parents bbf67cd + 35ee073 commit 5d8ef5e
Show file tree
Hide file tree
Showing 23 changed files with 1,649 additions and 1,232 deletions.
97 changes: 53 additions & 44 deletions GFDL_tools/fv_ada_nudge.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ module fv_ada_nudge_mod
use external_sst_mod, only: i_sst, j_sst, sst_ncep, sst_anom, forecast_mode
use diag_manager_mod, only: register_diag_field, send_data
use constants_mod, only: pi, grav, rdgas, cp_air, kappa, cnst_radius=>radius, seconds_per_day
use fms_mod, only: write_version_number, open_namelist_file, &
check_nml_error, file_exist, close_file
!use fms_io_mod, only: field_size
use fms_mod, only: write_version_number, check_nml_error
use mpp_mod, only: mpp_error, FATAL, stdlog, get_unit, mpp_pe, input_nml_file
use mpp_mod, only: mpp_root_pe, stdout ! snz
use mpp_mod, only: mpp_clock_id, mpp_clock_begin, mpp_clock_end
Expand All @@ -63,8 +61,10 @@ module fv_ada_nudge_mod
get_var3_r4, get_var2_r4, get_var1_real
use fv_arrays_mod, only: fv_grid_type, fv_grid_bounds_type, fv_nest_type, R_GRID

use fms_io_mod, only: register_restart_field, restart_file_type, restore_state
use fms_io_mod, only: save_restart, get_mosaic_tile_file
use fms2_io_mod, only : register_restart_field, open_file, close_file, &
read_restart, register_field, &
register_variable_attribute, file_exists
use fv_io_mod, only : fv_io_register_axis
use axis_utils_mod, only : frac_index

#ifdef ENABLE_ADA
Expand Down Expand Up @@ -235,8 +235,9 @@ module fv_ada_nudge_mod
integer :: id_u_da, id_v_da, id_t_da, id_q_da, id_ps_da ! snz
integer :: id_ada

type(restart_file_type) :: ada_driver_restart ! snz
character(len=*), parameter :: restart_file="ada_driver.res.nc" ! snz
type(FmsNetcdfFile_t) :: ada_driver_restart ! snz
character(len=*), parameter :: restart_file="INPUT/ada_driver.res.nc" ! snz
character(len=8), dimension(4) :: dim_names_4d

#ifdef ENABLE_ADA ! snz
type(model_data_type) :: Atm_var
Expand Down Expand Up @@ -1482,7 +1483,6 @@ subroutine fv_ada_nudge_init(time, axes, npz, zvir, ak, bk, ts, phis, gridstruct

integer :: id_restart !< Currently not used for anything other than a return
!value.
character(len=256) :: restart_file_instance

real, pointer, dimension(:,:,:) :: agrid

Expand Down Expand Up @@ -1522,20 +1522,9 @@ subroutine fv_ada_nudge_init(time, axes, npz, zvir, ak, bk, ts, phis, gridstruct

track_file_name = "No_File_specified"

#ifdef INTERNAL_FILE_NML
read(input_nml_file, nml = fv_ada_nudge_nml, iostat = io)
ierr = check_nml_error(io,'fv_ada_nudge_nml')
#else
if( file_exist( 'input.nml' ) ) then
unit = open_namelist_file ()
io = 1
do while ( io .ne. 0 )
read( unit, nml = fv_ada_nudge_nml, iostat = io, end = 10 )
ierr = check_nml_error(io,'fv_ada_nudge_nml')
end do
10 call close_file ( unit )
end if
#endif
read(input_nml_file, nml = fv_ada_nudge_nml, iostat = io)
ierr = check_nml_error(io,'fv_ada_nudge_nml')

call write_version_number ( 'FV_ADA_NUDGE_MOD', version )
if ( master ) then
f_unit=stdlog()
Expand Down Expand Up @@ -1793,26 +1782,32 @@ subroutine fv_ada_nudge_init(time, axes, npz, zvir, ak, bk, ts, phis, gridstruct
'da ps', 'Pa', missing_value=missing_value )

! snz add the following lines for recording the return values from the previous assim run
call get_mosaic_tile_file(restart_file, restart_file_instance,&
& .FALSE., domain)

id_restart = register_restart_field(ada_driver_restart, restart_file_instance, &
& "u_adj", Atm_var%u_adj(:,:,:), domain=domain)
id_restart = register_restart_field(ada_driver_restart, restart_file_instance, &
& "v_adj", Atm_var%v_adj(:,:,:), domain=domain)
id_restart = register_restart_field(ada_driver_restart, restart_file_instance, &
& "t_adj", Atm_var%t_adj(:,:,:), domain=domain)
id_restart = register_restart_field(ada_driver_restart, restart_file_instance, &
& "q_adj", Atm_var%q_adj(:,:,:), domain=domain)
id_restart = register_restart_field(ada_driver_restart, restart_file_instance, &
& "ps_adj", Atm_var%ps_adj(:,:), domain=domain)

if ( file_exist('INPUT/'//trim(restart_file_instance), domain=domain) ) then
if ( mpp_pe() .eq. mpp_root_pe() ) then
write (stdout_unit,*) 'Reading ada restart information from ', 'INPUT/'//trim(restart_file_instance)
end if
call restore_state(ada_driver_restart, DIRECTORY='INPUT')
end if

! set dimensions for register restart
dim_names_4d(1) = "xaxis_1"
dim_names_4d(2) = "yaxis_1"
dim_names_4d(3) = "zaxis_1"
dim_names_4d(4) = "Time"

if (open_file(ada_driver_restart, restart_file, "read", domain, is_restart=.true.))
call fv_io_register_axis(ada_driver_restart, numx=1, numy=1, numz=1, zsize=(/size(Atm_var%u_adj,3)/))
call register_restart_field(ada_driver_restart, &
& "u_adj", Atm_var%u_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "v_adj", Atm_var%v_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "t_adj", Atm_var%t_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "q_adj", Atm_var%q_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "ps_adj", Atm_var%ps_adj(:,:), dim_names_4d)

if ( mpp_pe() .eq. mpp_root_pe() ) then
write (stdout_unit,*) 'Reading ada restart information from ', 'INPUT/'//trim(restart_file)
end if
call read_restart(ada_driver_restart)
call close_file(ada_driver_restart)
endif

#endif ! snz for ENABLE_ADA

Expand Down Expand Up @@ -1848,7 +1843,7 @@ subroutine get_ncep_analysis ( ps, u, v, t, q, zvir, ts, nfile, fname, bd, time
!! model run
integer :: is, ie, js, je

if( .not. file_exist(fname) ) then
if( .not. file_exists(fname) ) then
call mpp_error(FATAL,'==> Error from get_ncep_analysis: file not found')
else
call open_ncfile( fname, ncid ) ! open the file
Expand Down Expand Up @@ -2516,7 +2511,21 @@ subroutine fv_ada_nudge_end

#ifdef ENABLE_ADA ! snz

call save_restart(ada_driver_restart)
if (open_file(ada_driver_restart, restart_file, "overwrite", domain, is_restart=.true.)) then
call fv_io_register_axis(ada_driver_restart, numx=1, numy=1, numz=1, zsize=(/size(Atm_var%u_adj,3)/))
call register_restart_field(ada_driver_restart, &
& "u_adj", Atm_var%u_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "v_adj", Atm_var%v_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "t_adj", Atm_var%t_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "q_adj", Atm_var%q_adj(:,:,:), dim_names_4d)
call register_restart_field(ada_driver_restart, &
& "ps_adj", Atm_var%ps_adj(:,:), dim_names_4d)
call write_restart(ada_driver_restart)
call close_file(ada_driver_restart)
endif

deallocate ( Atm_var%u, Atm_var%v, Atm_var%t, Atm_var%u_adj, Atm_var%v_adj, Atm_var%t_adj)
deallocate ( Atm_var%q, Atm_var%ps, Atm_var%q_adj, Atm_var%ps_adj)
Expand Down
18 changes: 3 additions & 15 deletions GFDL_tools/fv_climate_nudge.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
!***********************************************************************
module fv_climate_nudge_mod

use fms_mod, only: open_namelist_file, check_nml_error, &
close_file, stdlog, mpp_pe, mpp_root_pe, &
use fms_mod, only: check_nml_error, &
stdlog, mpp_pe, mpp_root_pe, &
write_version_number, string, error_mesg, &
FATAL, WARNING, NOTE, file_exist
FATAL, WARNING, NOTE
use mpp_mod, only: input_nml_file
use diag_manager_mod, only: register_diag_field, send_data, &
register_static_field
Expand Down Expand Up @@ -129,20 +129,8 @@ subroutine fv_climate_nudge_init ( Time, axes, flag )
if (module_is_initialized) return

! read namelist
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=fv_climate_nudge_nml, iostat=io)
ierr = check_nml_error (io, 'fv_climate_nudge_nml')
#else
if (file_exist('input.nml') ) then
unit = open_namelist_file()
ierr=1
do while (ierr /= 0)
read (unit, nml=fv_climate_nudge_nml, iostat=io, end=10)
ierr = check_nml_error (io, 'fv_climate_nudge_nml')
enddo
10 call close_file (unit)
endif
#endif

!----- write version and namelist to log file -----

Expand Down
30 changes: 3 additions & 27 deletions GFDL_tools/fv_cmip_diag.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
module fv_cmip_diag_mod

use mpp_mod, only: input_nml_file
use fms_mod, only: open_namelist_file, check_nml_error, &
close_file, stdlog, mpp_pe, mpp_root_pe, &
write_version_number, file_exist, &
use fms_mod, only: check_nml_error, string, &
stdlog, mpp_pe, mpp_root_pe, &
write_version_number, &
error_mesg, FATAL, WARNING, NOTE
use fms_io_mod, only: set_domain, nullify_domain, string
use time_manager_mod, only: time_type
use mpp_domains_mod, only: domain2d
use diag_manager_mod, only: register_diag_field, diag_axis_init, &
Expand Down Expand Up @@ -120,31 +119,15 @@ subroutine fv_cmip_diag_init ( Atm, axes, Time )
endif

!----- read namelist -----
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=fv_cmip_diag_nml, iostat=io)
ierr = check_nml_error (io, 'fv_cmip_diag_nml')
#else
if (file_exist('input.nml') ) then
iunit = open_namelist_file()
ierr=1
do while (ierr /= 0)
read (iunit, nml=fv_cmip_diag_nml, iostat=io, end=10)
ierr = check_nml_error (io, 'fv_cmip_diag_nml')
enddo
10 call close_file (iunit)
endif
#endif

!----- write version and namelist to log file -----

iunit = stdlog()
call write_version_number ( 'FV_CMIP_DIAG_MOD', version )
if (mpp_pe() == mpp_root_pe()) write (iunit, nml=fv_cmip_diag_nml)


! Set domain so that diag_manager can access tile information
call set_domain(Atm(1)%domain)

! axis identifiers
area_id = get_diag_field_id ('dynamics', 'area')
if (area_id .eq. DIAG_FIELD_NOT_FOUND) call error_mesg &
Expand Down Expand Up @@ -411,7 +394,6 @@ subroutine fv_cmip_diag_init ( Atm, axes, Time )
call diag_field_add_attribute (id_zg1000, 'coordinates', 'p1000')

!--- done ---
call nullify_domain()
module_is_initialized=.true.

!-----------------------------------------------------------------------
Expand Down Expand Up @@ -455,8 +437,6 @@ subroutine fv_cmip_diag ( Atm, zvir, Time )
ngc = Atm(n)%ng
npz = Atm(n)%npz

call set_domain(Atm(n)%domain)

! set flags for computing quantities
compute_rh = .false.
compute_wa = .false.
Expand Down Expand Up @@ -688,10 +668,6 @@ subroutine fv_cmip_diag ( Atm, zvir, Time )
used = send_data (id_zg1000, dat3(:,:,1), Time)
endif

!----------------------------------------------------------------------

call nullify_domain()

!----------------------------------------------------------------------

end subroutine fv_cmip_diag
Expand Down
24 changes: 2 additions & 22 deletions GFDL_tools/fv_diag_column.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module fv_diag_column_mod
use fms_mod, only: write_version_number, lowercase
use mpp_mod, only: mpp_error, FATAL, stdlog, mpp_pe, mpp_root_pe, mpp_sum, &
mpp_max, NOTE, input_nml_file, get_unit
use mpp_io_mod, only: mpp_flush
use fv_sg_mod, only: qsmith

implicit none
Expand Down Expand Up @@ -79,20 +78,7 @@ subroutine fv_diag_column_init(Atm, yr_init, mo_init, dy_init, hr_init, do_diag_
diag_sonde_j(:) = -999
diag_sonde_tile(:) = -99

#ifdef INTERNAL_FILE_NML
read(input_nml_file, nml=fv_diag_column_nml,iostat=ios)
#else
inquire (file=trim(Atm%nml_filename), exist=exists)
if (.not. exists) then
write(errmsg,*) 'fv_diag_column_nml: namelist file ',trim(Atm%nml_filename),' does not exist'
call mpp_error(FATAL, errmsg)
else
open (unit=nlunit, file=Atm%nml_filename, READONLY, status='OLD', iostat=ios)
endif
rewind(nlunit)
read (nlunit, nml=fv_diag_column_nml, iostat=ios)
close (nlunit)
#endif

if (do_diag_debug .or. do_diag_sonde) then
call read_column_table
Expand Down Expand Up @@ -394,10 +380,8 @@ subroutine debug_column(pt, delp, delz, u, v, w, q, npz, ncnst, sphum, nwat, zvi

write(unit, *) '==================================================================='
write(unit, *)

call mpp_flush(unit)


flush(unit)

enddo

end subroutine debug_column
Expand Down Expand Up @@ -487,8 +471,6 @@ subroutine debug_column_dyn(pt, delp, delz, u, v, w, q, heat_source, cappa, akap
write(unit, *) '==================================================================='
write(unit, *)

call mpp_flush(unit)

enddo

end subroutine debug_column_dyn
Expand Down Expand Up @@ -582,8 +564,6 @@ subroutine sounding_column( pt, delp, delz, u, v, q, peln, pkz, thetae, phis, &
enddo
endif

call mpp_flush(unit)

enddo


Expand Down
Loading

0 comments on commit 5d8ef5e

Please sign in to comment.