Skip to content

Commit

Permalink
Add simple file splitting test (#33)
Browse files Browse the repository at this point in the history
* Add simple file splitting test framework

* Tweak test script slightly

* Add comparison files to simple file splitting test
  • Loading branch information
ricky-lv426 authored Jul 10, 2024
1 parent e370d06 commit ea19d2d
Show file tree
Hide file tree
Showing 12 changed files with 2,334 additions and 0 deletions.
58 changes: 58 additions & 0 deletions xios_examples/split_file_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Make file for the multiple time step demonstartion XIOS programme
# Targets provided our detailed below...
#
# all: (default) Build the multiple_timestep programme
# clean: Delete all final products and working files
# run: run the programme
#
# Environment Variables expected by this MakeFile:
#
# NETCDF_LIBDIR: the directories for the netCDF lib files
# encoded as a -L string, e.g.
# "-L/dir1 -L/dir2"
# NETCDF_INCDIR: 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

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++

.PHONY: all, clean, run

all: multiple_timestep

# fortran compilation
%.o: %.F90
$(FC) $(FCFLAGS) -c $<

# fortran linking
multiple_timestep: multiple_timestep.o
$(FC) -o multiple_timestep.exe multiple_timestep.o $(LDFLAGS) \
&& ln -fs $(XIOS_BINDIR)/xios_server.exe .

run:
mpiexec -n 1 ./multiple_timestep.exe : -n 1 ./xios_server.exe

# cleanup
clean:
rm -f *.exe *.o *.mod *.MOD *.out *.err *.nc
5 changes: 5 additions & 0 deletions xios_examples/split_file_test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
split_file_test
---------------

This example demonstrates XIOS split file output. It takes a canned dataset of temperature and pressure on 39 model levels at one lat-lon point and outputs
the temperature and pressure fields split across different files.
3 changes: 3 additions & 0 deletions xios_examples/split_file_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Enable this folder to be a module path, for imports and test discovery.
"""
7 changes: 7 additions & 0 deletions xios_examples/split_file_test/iodef.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<simulation>

<context id="main" src="main.xml"/>
<context id="xios" src="xios.xml"/>

</simulation>
39 changes: 39 additions & 0 deletions xios_examples/split_file_test/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<context>

<calendar type="Gregorian"/>

<axis_definition>
<axis id="model_levels" unit="1" name="levels" n_glo="39" value="(0,38)[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39]"/>
</axis_definition>

<domain_definition>
<domain id="latlon1_domain" ni_glo="1" nj_glo="1" type="rectilinear" nvertex="2">
</domain>
</domain_definition>

<grid_definition>
<grid id="model">
<domain domain_ref="latlon1_domain" />
<axis axis_ref="model_levels" />
</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_definition>

<field_definition freq_op="1ts" enabled=".TRUE." operation="instant" >
<field id="temperature" name="temperature" long_name="Air Temperature" standard_name="air_temperature" unit="K" grid_ref="model" />
</field_definition>


<file_definition type="one_file" enabled=".TRUE.">
<file id="split_file" name="split_file" output_freq="1ts" split_freq="5ts" enabled=".TRUE.">
<field_group operation="instant">
<field field_ref="pressure" />
<field field_ref="temperature"/>
</field_group>
</file>
</file_definition>

</context>
131 changes: 131 additions & 0 deletions xios_examples/split_file_test/multiple_timestep.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
!-----------------------------------------------------------------------------
! (C) Crown copyright 2024 Met Office. All rights reserved.
! The file LICENCE, distributed with this code, contains details of the terms
! under which the code may be used.
!-----------------------------------------------------------------------------
!> Resam on a 1D Pressure vertical axis using the supplied
!> Pressure and temperature on model levels

program multiple_timestep
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
double precision, dimension (1) :: lons = [-4.5]
double precision, dimension (1) :: lats = [51.5]
double precision, dimension (2,1) :: blons
double precision, dimension (2,1) :: blats

blons = reshape((/-6.0, -3.0/), shape(blons))
blats = reshape((/50.0, 53.0/), shape(blats))

! Arbitrary datetime setup, required for XIOS but unused
! in this example
origin = xios_date(2022, 12, 13, 01, 0, 0)
start = xios_date(2022, 12, 13, 01, 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)

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_domain_attr('latlon1_domain', ni=1, nj=1, ibegin=0, jbegin=0)
call xios_set_domain_attr('latlon1_domain', lonvalue_1d=lons, latvalue_1d=lats, bounds_lon_1d=blons, bounds_lat_1d=blats)

call xios_close_context_definition()

end subroutine initialise

subroutine finalise()

integer :: mpi_error

! Finalise XIOS and MPI
call xios_context_finalize()

call xios_finalize()
call MPI_Finalize(mpi_error)

end subroutine finalise

subroutine simulate()

type(xios_date) :: current
integer :: ts
integer :: lenz
integer :: lenrz
integer :: nlevs = 39

integer, parameter :: sim_period = 20

double precision, dimension (:), allocatable :: inpdata
double precision, dimension (:), allocatable :: intdata

allocate ( inpdata(nlevs) )
allocate ( intdata(nlevs) )

! create data
! pressure on model levels
inpdata = [&
99966.51733734, 99940.00334122, 99879.75646023, 99777.78684877,&
99635.30154044, 99451.57613718, 99227.03147757, 98960.87975741,&
98652.27529804, 98301.45813138, 97908.79783106, 97473.21205427,&
96994.06194264, 96470.87150873, 95901.78892901, 95284.84539213,&
94617.56355344, 93898.14972652, 93123.02534389, 92287.80902342,&
91391.57971605, 90430.9865711, 89403.66167799, 88321.39379902,&
87213.38301499, 86106.06396005, 84999.27014238, 83877.20722173,&
82723.67003746, 81516.40664914, 80240.47719038, 78881.30453228,&
77425.96195086, 75842.56242889, 74128.77364138, 72079.17018205,&
69945.02914929, 65667.62435439, 63427.28244824]

! temperature on model levels
intdata = [&
273.39701404, 273.14989444, 272.87913071, 272.50214011, 271.77289302,&
270.70622676, 269.60430231, 268.39273869, 266.90100832, 265.29298229,&
263.39088121, 261.48536033, 258.99438088, 256.21760745, 252.83385896,&
248.6965695, 243.8680557, 238.57359575, 232.80450043, 226.62957162,&
220.02910932, 213.47976457, 206.95727661, 205.63877024, 210.23499515,&
216.93309253, 221.44028771, 223.98930063, 224.66841468, 224.15347685,&
223.6943803, 223.15001293, 222.66638538, 222.80326535, 223.20642547,&
223.01865617, 227.3452969, 219.20421226, 266.77144776]

do ts=1, sim_period
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 + ts*1000000)
! Send the temperature data to the output file.
call xios_send_field('temperature', intdata + ts*1000000)
enddo

deallocate (inpdata)
deallocate (intdata)

end subroutine simulate

end program multiple_timestep
Loading

0 comments on commit ea19d2d

Please sign in to comment.