-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
547 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Make file for the resample demonstartion XIOS programme | ||
# Targets provided our detailed below... | ||
# | ||
# all: (default) Build the resample programme | ||
# clean: Delete all final products and working files | ||
# run: run the programme | ||
# | ||
# Environment Variables expected by this MakeFile: | ||
# | ||
# NETCDF_LIB_DIR: the directories for the netCDF lib files | ||
# encoded as a -L string, e.g. | ||
# "-L/dir1 -L/dir2" | ||
# NETCDF_INC_DIR: the directories for the netCDF include files | ||
# encoded as a -I string, e.g. | ||
# "-I/dir3 -I/dir4" | ||
# (note, this is for consistency with the XIOS build process | ||
# required for the CI build machine. | ||
# this is not required for other directories) | ||
# | ||
# XIOS_INCDIR: The directory for XIOS include files | ||
# XIOS_LIBDIR: The directory for XIOS lib files | ||
# XIOS_BINDIR: The directory for XIOS binary files | ||
|
||
FCFLAGS = -g -ffree-line-length-none | ||
|
||
FC = mpif90 # compiler driver for MPI programs | ||
|
||
# compiler flag, includes | ||
FCFLAGS += -I$(XIOS_INCDIR) $(NETCDF_INCDIR) | ||
|
||
# loader flags | ||
LDFLAGS = \ | ||
-L$(XIOS_LIBDIR) \ | ||
$(NETCDF_LIBDIR) \ | ||
-lxios \ | ||
-lnetcdf \ | ||
-lnetcdff \ | ||
-lstdc++ | ||
|
||
all: resample | ||
|
||
# fortran compilation | ||
%.o: %.F90 | ||
$(FC) $(FCFLAGS) -c $< | ||
|
||
# fortran linking | ||
resample: resample.o | ||
$(FC) -o resample.exe resample.o $(LDFLAGS) \ | ||
&& ln -fs $(XIOS_BINDIR)/xios_server.exe . | ||
|
||
run: | ||
mpiexec -n 1 ./resample.exe : -n 1 ./xios_server.exe | ||
|
||
# cleanup | ||
clean: | ||
rm -f *.exe *.o *.mod *.MOD *.out *.err *.nc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<context id="axis_check"> | ||
|
||
<calendar type="Gregorian"/> | ||
|
||
|
||
<grid_definition> | ||
<grid id="mlev_grid"> | ||
<axis id="xm" /> | ||
<axis id="ym" /> | ||
<axis id="mlev" /> | ||
</grid> | ||
|
||
<grid id="plev_grid"> | ||
<axis id="xp" /> | ||
<axis id="yp" /> | ||
<axis id="plev" /> | ||
</grid> | ||
|
||
</grid_definition> | ||
|
||
<file_definition type="one_file"> | ||
<file id="din" name="stratify_input_in_domain_1" output_freq="1ts" mode="read" enabled=".true."> | ||
<field id="pressure_in" name="pressure" grid_ref="mlev_grid" operation="instant" /> | ||
<field id="temperature_in" name="temperature" grid_ref="mlev_grid" operation="instant" /> | ||
<field id="temponp_in" name="temponP" grid_ref="plev_grid" operation="instant" /> | ||
|
||
</file> | ||
</file_definition> | ||
|
||
</context> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<simulation> | ||
|
||
<context id="main" src="main.xml"/> | ||
<context id="axis_check" src="axis_check.xml"/> | ||
|
||
<context id="xios" src="xios.xml"/> | ||
|
||
</simulation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<context id="main"> | ||
|
||
<calendar type="Gregorian"/> | ||
|
||
<axis_definition> | ||
<axis id="model_levels" unit="1" name="levels"/> | ||
<axis id="pressure_levels1" positive="down" long_name="Air Pressure" standard_name="air_pressure" unit="Pa"> | ||
<interpolate_axis type="polynomial" order="1" coordinate="pressure" /> | ||
</axis> | ||
|
||
</axis_definition> | ||
|
||
<domain_definition> | ||
<domain id="latlon_domain" type="rectilinear" nvertex="2"/> | ||
|
||
</domain_definition> | ||
|
||
<grid_definition> | ||
<grid id="model"> | ||
<domain domain_ref="latlon_domain" /> | ||
<axis axis_ref="model_levels" /> | ||
</grid> | ||
<grid id="model_plev"> | ||
<domain domain_ref="latlon_domain" /> | ||
<axis axis_ref="pressure_levels1" /> | ||
</grid> | ||
</grid_definition> | ||
|
||
<field_definition freq_op="1ts" enabled=".TRUE." operation="instant" > | ||
<field id="pressure" name="pressure" long_name="Air Pressure" standard_name="air_pressure" unit="Pa" grid_ref="model" /> | ||
<field id="temperature" name="temperature" long_name="Air Temperature" standard_name="air_temperature" unit="K" grid_ref="model" /> | ||
<field id="temperature_on_P" name="resampled_data" long_name="Air Temperature" standard_name="air_temperature" unit="K" field_ref="temperature" grid_ref="model_plev" /> | ||
<field id="expected" name="resample_data" long_name="Expected Air Temperature" standard_name="air_temperature" unit="K" grid_ref="model_plev" /> | ||
<field id="diff" name="resampled_minus_resample" long_name="Air Temperature difference" unit="K" grid_ref="model_plev">temperature_on_P - expected</field> | ||
|
||
</field_definition> | ||
|
||
|
||
<file_definition type="one_file"> | ||
<file id="pressure_stratify" output_freq="1ts"> | ||
<field_group operation="once"> | ||
<field field_ref="pressure" /> | ||
<field field_ref="temperature"/> | ||
<field field_ref="temperature_on_P"/> | ||
<field field_ref="expected"/> | ||
<field field_ref="diff"/> | ||
|
||
</field_group> | ||
</file> | ||
</file_definition> | ||
|
||
</context> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
!----------------------------------------------------------------------------- | ||
! (C) Crown copyright 2020 Met Office. All rights reserved. | ||
! The file LICENCE, distributed with this code, contains details of the terms | ||
! under which the code may be used. | ||
!----------------------------------------------------------------------------- | ||
!> Read 2D data on a domain and resample using the axis_input.nc file | ||
!> | ||
program resample | ||
use xios | ||
use mpi | ||
|
||
implicit none | ||
|
||
integer :: comm = -1 | ||
integer :: rank = -1 | ||
integer :: npar = 0 | ||
|
||
call initialise() | ||
call simulate() | ||
call finalise() | ||
contains | ||
|
||
subroutine initialise() | ||
|
||
type(xios_date) :: origin | ||
type(xios_date) :: start | ||
type(xios_duration) :: tstep | ||
integer :: mpi_error | ||
integer :: lenx | ||
integer :: lenrx | ||
integer :: leny | ||
integer :: lenry | ||
integer :: lenz | ||
integer :: lenrz | ||
double precision, dimension (:), allocatable :: latvals, lonvals, plvals, mlvals | ||
double precision, dimension (:,:), allocatable :: latb, lonb | ||
|
||
! Arbitrary datetime setup, required for XIOS but unused | ||
origin = xios_date(2022, 2, 2, 12, 0, 0) | ||
start = xios_date(2022, 12, 13, 12, 0, 0) | ||
tstep = xios_hour | ||
|
||
! Initialise MPI and XIOS | ||
call MPI_INIT(mpi_error) | ||
|
||
call xios_initialize('client', return_comm=comm) | ||
|
||
call MPI_Comm_rank(comm, rank, mpi_error) | ||
call MPI_Comm_size(comm, npar, mpi_error) | ||
|
||
! use the axis_check context to obtain sizing information on all arrays | ||
! for use in defining the main context interpretation | ||
call xios_context_initialize('axis_check', comm) | ||
call xios_set_time_origin(origin) | ||
call xios_set_start_date(start) | ||
call xios_set_timestep(tstep) | ||
|
||
call xios_close_context_definition() | ||
|
||
call xios_get_axis_attr('xm', n_glo=lenx) | ||
call xios_get_axis_attr('xp', n_glo=lenrx) | ||
call xios_get_axis_attr('ym', n_glo=leny) | ||
call xios_get_axis_attr('yp', n_glo=lenry) | ||
call xios_get_axis_attr('mlev', n_glo=lenz) | ||
call xios_get_axis_attr('plev', n_glo=lenrz) | ||
|
||
allocate ( mlvals(lenz) ) | ||
allocate ( plvals(lenrz) ) | ||
allocate ( lonvals(lenx) ) | ||
allocate ( latvals(leny) ) | ||
allocate ( lonb(2, lenx) ) | ||
allocate ( latb(2, leny) ) | ||
|
||
lonb = reshape((/-6.0, -3.0/), shape(lonb)) | ||
latb = reshape((/50.0, 53.0/), shape(latb)) | ||
|
||
|
||
call xios_get_axis_attr('xm', value=lonvals) | ||
call xios_get_axis_attr('ym', value=latvals) | ||
call xios_get_axis_attr('mlev', value=mlvals) | ||
call xios_get_axis_attr('plev', value=plvals) | ||
|
||
|
||
! initialize the main context for interacting with the data. | ||
call xios_context_initialize('main', comm) | ||
|
||
call xios_set_time_origin(origin) | ||
call xios_set_start_date(start) | ||
call xios_set_timestep(tstep) | ||
|
||
!call xios_set_axis_attr('model_levels', n_glo=lenz) | ||
call xios_set_axis_attr('model_levels', n_glo=lenz, value=mlvals) | ||
call xios_set_axis_attr('pressure_levels1', n_glo=lenrz, value=plvals) | ||
|
||
call xios_set_domain_attr('latlon_domain', ni_glo=lenx, nj_glo=leny, ni=lenx, nj=leny, ibegin=0, jbegin=0) | ||
call xios_set_domain_attr('latlon_domain', lonvalue_1d=lonvals, latvalue_1d=latvals, bounds_lon_1d=lonb, bounds_lat_1d=latb) | ||
|
||
|
||
call xios_close_context_definition() | ||
|
||
end subroutine initialise | ||
|
||
subroutine finalise() | ||
|
||
integer :: mpi_error | ||
|
||
! Finalise all XIOS contexts and MPI | ||
call xios_set_current_context('axis_check') | ||
call xios_context_finalize() | ||
call xios_set_current_context('main') | ||
call xios_context_finalize() | ||
call MPI_Comm_free(comm, mpi_error) | ||
call xios_finalize() | ||
call MPI_Finalize(mpi_error) | ||
|
||
end subroutine finalise | ||
|
||
subroutine simulate() | ||
|
||
type(xios_date) :: current | ||
integer :: ts | ||
integer :: lenx | ||
integer :: leny | ||
integer :: lenmlz | ||
integer :: lenplz | ||
|
||
! Allocatable arrays, size is taken from input file | ||
double precision, dimension (:,:,:), allocatable :: inpdata | ||
double precision, dimension (:,:,:), allocatable :: intdata | ||
double precision, dimension (:,:,:), allocatable :: intonpdata | ||
|
||
call xios_get_domain_attr('latlon_domain', ni_glo=lenx, nj_glo=leny) | ||
call xios_get_axis_attr('model_levels', n_glo=lenmlz) | ||
call xios_get_axis_attr('pressure_levels1', n_glo=lenplz) | ||
|
||
allocate ( inpdata(lenmlz, leny, lenx) ) | ||
allocate ( intdata(lenmlz, leny, lenx) ) | ||
allocate ( intonpdata(lenplz, leny, lenx) ) | ||
|
||
call xios_set_current_context('axis_check') | ||
|
||
|
||
! Load data from the input file | ||
call xios_recv_field('pressure_in', inpdata) | ||
call xios_recv_field('temperature_in', intdata) | ||
call xios_recv_field('temponp_in', intonpdata) | ||
|
||
call xios_set_current_context('main') | ||
|
||
do ts=1, 1 | ||
call xios_update_calendar(ts) | ||
call xios_get_current_date(current) | ||
! Send the pressure data to the output file. | ||
call xios_send_field('pressure', inpdata) | ||
! Send the pressure data to the output file. | ||
! The interpolate_axis and field-ref in main.xml will | ||
! also write the interpolated data into the output file. | ||
call xios_send_field('temperature', intdata) | ||
call xios_send_field('expected', intonpdata) | ||
enddo | ||
|
||
|
||
deallocate (inpdata) | ||
deallocate (intdata) | ||
deallocate (intonpdata) | ||
|
||
end subroutine simulate | ||
|
||
end program resample |
Oops, something went wrong.