Hello!
I am trying to add a new input stream to the atmosphere_model that reads data from an .nc file. I have edited a standard MPAS static.nc file (it is the x1.10242.static.nc file generated in section 1.3 of the MPAS tutorial -> MPAS Tutorial — Practice Session Guide) that I am using to test with, called test_input.nc. I removed all vars aside from xtime and have added a variable 'test_var'. The dimensions and global attributes are identical to the original static file. The variables are now
and the data is
I chose to use dimension TWO as it seemed like the simplest choice and I didn't want a dimensionless variable.
To the atmosphere model registry (../MAS-Model/src/core_atmosphere/Registry.xml) I added the following:
A new stream named test_input:
A new var_struct test_input_struct which has a variable define: test_var
I wanted to try and use the test_var variable in some of the code, so in mpas_atm_core.F (../MPAS-Model/src/core_atmosphere/mpas_atm_core.F) I added the following to the atm_mpas_init_block subroutine.... (I have included some of the surrounding lines of code to help indicate where I have added my own).
Declare test_input_struct
Declare variables I will be using:
- test_var: array defined in test_input struct
- TWO: the dimension of test_var
- sum_test_var: a variable I will use to test some arithmetic with the elements of test_var
- i: used for looping
Call the test_input struct
Then, at the end of the subroutine, I have called test_var and TWO from their respective pools and tried to carry out some arithmetic with the elements of test_var in a do loop (sum the elements). I have also added some mpas_log_write_statements to see what's going on.
CORE=atmosphere compiles after making the above edits to the registry and mpas_atm_core.F.
I added the following input stream to streams.atmosphere:
After running atmosphere_model, the following is output to log.atmosphere.0000.out
So, it seems that MPAS is happy with the test_var I defined in test_input_struct, as I can call test_var and use its values. BUT they have not picked up the value I gave them in test_input.nc, i.e. the input stream has not assigned values to test_var, and instead are set to the default of zero!
What I would like to know is, how do I get the test_var variable defined in the atmosphere model to take the values assigned in the test_input stream?
One thing that very possibly is an issue is the test_input.nc file that I am using. I am a novice with the netCDF format and my generation of the stream input file was therefore not very sophisticated!
Some other questions that have arisen during my attempt at adding a new input streams:
- Can you define new dimensions and if so is it done as with variables in the registry?
- What does 'time_levs' in the registry represent?
Thanks in advance,
Laurents
I am trying to add a new input stream to the atmosphere_model that reads data from an .nc file. I have edited a standard MPAS static.nc file (it is the x1.10242.static.nc file generated in section 1.3 of the MPAS tutorial -> MPAS Tutorial — Practice Session Guide) that I am using to test with, called test_input.nc. I removed all vars aside from xtime and have added a variable 'test_var'. The dimensions and global attributes are identical to the original static file. The variables are now
Code:
variables:
int test_var(TWO) ;
test_var:units = "-" ;
test_var:long_name = "Test variable" ;
char xtime(Time, StrLen) ;
xtime:units = "YYYY-MM-DD_hh:mm:ss" ;
xtime:long_name = "Model valid time" ;
and the data is
Code:
data:
xtime =
"2014-09-10_00:00:00 " ;
test_var =
7777777, 666666 ;
To the atmosphere model registry (../MAS-Model/src/core_atmosphere/Registry.xml) I added the following:
A new stream named test_input:
Code:
<stream name="test_input"
type="input"
filename_template="test_input.nc"
input_interval="initial_only"
immutable="true">
<var name="test_var" />
</stream>
A new var_struct test_input_struct which has a variable define: test_var
Code:
<var_struct name="test_input_struct" time_levs="1">
<var name="test_var" type="integer" dimensions="TWO" units=""
description="Testing reading variables from a .nc file"/>
I wanted to try and use the test_var variable in some of the code, so in mpas_atm_core.F (../MPAS-Model/src/core_atmosphere/mpas_atm_core.F) I added the following to the atm_mpas_init_block subroutine.... (I have included some of the surrounding lines of code to help indicate where I have added my own).
Declare test_input_struct
Code:
type (mpas_pool_type), pointer :: state
type (mpas_pool_type), pointer :: diag
type (mpas_pool_type), pointer :: tend
type (mpas_pool_type), pointer :: sfc_input
type (mpas_pool_type), pointer :: diag_physics
type (mpas_pool_type), pointer :: atm_input
!-----------------Declaring-test_input-struct-------------
type (mpas_pool_type), pointer :: test_input_struct
Declare variables I will be using:
- test_var: array defined in test_input struct
- TWO: the dimension of test_var
- sum_test_var: a variable I will use to test some arithmetic with the elements of test_var
- i: used for looping
Code:
integer, pointer :: nThreads
integer, dimension(:), pointer :: cellThreadStart, cellThreadEnd
integer, dimension(:), pointer :: cellSolveThreadStart, cellSolveThreadEnd
integer, dimension(:), pointer :: edgeThreadStart, edgeThreadEnd
integer, dimension(:), pointer :: edgeSolveThreadStart, edgeSolveThreadEnd
integer, dimension(:), pointer :: vertexThreadStart, vertexThreadEnd
integer, dimension(:), pointer :: vertexSolveThreadStart, vertexSolveThreadEnd
logical, pointer :: config_do_restart, config_do_DAcycling
!-----------Declaring-vars-for-reading-.nc-files------
integer, dimension(:), pointer :: test_var
integer, pointer :: TWO
integer :: sum_test_var, i
Call the test_input struct
Code:
call mpas_pool_get_subpool(block % structs, 'diag', diag)
call mpas_pool_get_subpool(block % structs, 'state', state)
!--------------Call-test_input-struct-subpool------------------------------------------
call mpas_pool_get_subpool(block % structs, 'test_input_struct', test_input_struct)
call mpas_pool_get_config(block % configs, 'config_do_restart', config_do_restart)
call mpas_pool_get_config(block % configs, 'config_do_DAcycling', config_do_DAcycling)
Then, at the end of the subroutine, I have called test_var and TWO from their respective pools and tried to carry out some arithmetic with the elements of test_var in a do loop (sum the elements). I have also added some mpas_log_write_statements to see what's going on.
Code:
!-----------Using-test_var-------
call mpas_pool_get_array(test_input_struct, 'test_var', test_var)
call mpas_pool_get_dimension(mesh, 'TWO', TWO)
sum_test_var = 0
call mpas_log_write('sum_test_var initially set to $i.', intArgs=[sum_test_var])
do i=1,TWO
call mpas_log_write('Do loop, step $i', intArgs=[i])
sum_test_var = sum_test_var + test_var(i)
call mpas_log_write('test_var value is $i.',intArgs=[test_var(i)])
call mpas_log_write('sum_test_var value is $i.',intArgs=[test_var(i)])
end do
call mpas_log_write('sum_test_var finally set to $i.', intArgs=[sum_test_var])
end subroutine atm_mpas_init_block
CORE=atmosphere compiles after making the above edits to the registry and mpas_atm_core.F.
I added the following input stream to streams.atmosphere:
Code:
<immutable_stream name="test_input"
type="test_input"
filename_template="test_input.nc"
input_interval="initial_only" />
After running atmosphere_model, the following is output to log.atmosphere.0000.out
Code:
sum_test_var initially set to 0.
Do loop, step 1
test_var value is 0.
sum_test_var value is 0.
Do loop, step 2
test_var value is 0.
sum_test_var value is 0.
sum_test_var finally set to 0.
So, it seems that MPAS is happy with the test_var I defined in test_input_struct, as I can call test_var and use its values. BUT they have not picked up the value I gave them in test_input.nc, i.e. the input stream has not assigned values to test_var, and instead are set to the default of zero!
What I would like to know is, how do I get the test_var variable defined in the atmosphere model to take the values assigned in the test_input stream?
One thing that very possibly is an issue is the test_input.nc file that I am using. I am a novice with the netCDF format and my generation of the stream input file was therefore not very sophisticated!
Some other questions that have arisen during my attempt at adding a new input streams:
- Can you define new dimensions and if so is it done as with variables in the registry?
- What does 'time_levs' in the registry represent?
Thanks in advance,
Laurents