Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions xios_examples/ugrid_projected/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Make file for the write demonstartion XIOS programme
# Targets provided our detailed below...
#
# all: (default) Build the write programme
# clean: Delete all final products and working files
# run: run the programme
#
# Environment Variables expected by this MakeFile:
#
# FC: mpif90
# FCFLAGS: -g & include files for netcdf & xios
# LD_FLAGS: for xios, netcdf, netcdff, stfc++
# LD_LIBRARY_PATH: for netCDF & XIOS libs
# XIOS_BINDIR: The directory for XIOS binary files

.PHONY: all, clean, run

all: write

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

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

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

# cleanup
clean:
rm -f *.exe *.o *.mod *.MOD *.out *.err
3 changes: 3 additions & 0 deletions xios_examples/ugrid_projected/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Demonstration of basic UGrid domain specification.

Read mesh from file then create output mesh to add data to.
Empty file.
45 changes: 45 additions & 0 deletions xios_examples/ugrid_projected/axis_check.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<context>

<calendar type="Gregorian"/>

<domain_definition>

<domain id="mesh_node_domain" type="unstructured" nvertex="1">
<generate_rectilinear_domain/>
</domain>

<domain id="mesh_face_domain" type="unstructured" nvertex="4">
<generate_rectilinear_domain/>
</domain>

<domain id="mesh_edge_domain" type="unstructured" nvertex="2">
<generate_rectilinear_domain/>
</domain>

</domain_definition>

<grid_definition>
<grid id="mfng" >
<axis id="fv" />
<domain domain_ref="mesh_face_domain" />
<!-- <axis id="nf" /> -->
</grid>
<grid id="meng" >
<axis id="ev" />
<domain domain_ref="mesh_edge_domain" />
<!-- <axis id="ne" /> -->
</grid>
</grid_definition>


<file_definition type="one_file">
<file id="din" name="cubedsphere_mesh" output_freq="1ts" mode="read" enabled=".true." convention="UGRID">
<field id="cndata" name="node_empty_data_container" domain_ref="mesh_node_domain" operation="once" read_access=".true." />
<field id="cfdata" name="face_empty_data_container" domain_ref="mesh_face_domain" operation="instant" read_access=".true." />
<field id="cedata" name="edge_empty_data_container" domain_ref="mesh_edge_domain" operation="instant" read_access=".true." />
<field id="mesh_face_nodes" grid_ref="mfng" name="mesh_face_nodes" operation="instant" read_access=".true." prec="2" />
<field id="mesh_edge_nodes" grid_ref="meng" name="mesh_edge_nodes" operation="instant" read_access=".true." prec="2" />
</file>
</file_definition>

</context>
9 changes: 9 additions & 0 deletions xios_examples/ugrid_projected/iodef.xml
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>
45 changes: 45 additions & 0 deletions xios_examples/ugrid_projected/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<context>

<calendar type="Gregorian"/>

<domain_definition>

<domain id="node_domain" name="cubedsphere" type="unstructured" nvertex="1">
<generate_rectilinear_domain/>
</domain>

<domain id="face_domain" name="cubedsphere" type="unstructured" nvertex="4">
<generate_rectilinear_domain/>
</domain>

<domain id="edge_domain" name="cubedsphere" type="unstructured" nvertex="2">
<generate_rectilinear_domain/>
</domain>

</domain_definition>


<field_definition prec="8" enabled=".TRUE." >
<field id="ndata" name="arbitrary_node_data" domain_ref="node_domain" long_name="Arbitrary data values" unit="1" />
<field id="fdata" name="arbitrary_face_data" domain_ref="face_domain" long_name="Arbitrary data values" unit="1" />
<field id="edata" name="arbitrary_edge_data" domain_ref="edge_domain" long_name="Arbitrary data values" unit="1" />
</field_definition>


<file_definition type="one_file">
<file id="data_output" convention="UGRID" enabled=".TRUE." output_freq="1ts">
<field_group operation="instant">
<field field_ref="ndata" >
</field>
<field field_ref="fdata" >
</field>
<field field_ref="edata" >
</field>

</field_group>


</file>
</file_definition>

</context>
170 changes: 170 additions & 0 deletions xios_examples/ugrid_projected/planar_mesh.cdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
netcdf planar_mesh {
dimensions:
One = 1 ;
Two = 2 ;
Four = 4 ;
nmesh_node = 21 ;
nmesh_edge = 32 ;
nmesh_face = 12 ;
variables:
int mesh ;
mesh:cf_role = "mesh_topology" ;
mesh:geometry = "planar" ;
mesh:topology = "non_periodic" ;
mesh:coord_sys = "xyz" ;
mesh:periodic_x = "F" ;
mesh:periodic_y = "F" ;
mesh:constructor_inputs = "geometry=planar;topology=non_periodic;coord_sys=xyz;edge_cells_x=6;edge_cells_y=2;periodic_x=F;periodic_y=F;domain_size=[6.00,2.00];domain_centre=[9000.00,7000.00]" ;
mesh:max_stencil_depth = 0 ;
mesh:n_mesh_maps = 0 ;
mesh:long_name = "Topology data of 2D unstructured mesh" ;
mesh:topology_dimension = 2 ;
mesh:node_coordinates = "mesh_node_x mesh_node_y" ;
mesh:face_coordinates = "mesh_face_x mesh_face_y" ;
mesh:face_node_connectivity = "mesh_face_nodes" ;
mesh:edge_node_connectivity = "mesh_edge_nodes" ;
mesh:face_edge_connectivity = "mesh_face_edges" ;
mesh:face_face_connectivity = "mesh_face_links" ;
mesh:domain_extents = "mesh_domain_extents" ;
mesh:npanels = 1 ;
int mesh_face_nodes(nmesh_face, Four) ;
mesh_face_nodes:cf_role = "face_node_connectivity" ;
mesh_face_nodes:long_name = "Maps every quadrilateral face to its four corner nodes." ;
mesh_face_nodes:start_index = 1 ;
int mesh_face_edges(nmesh_face, Four) ;
mesh_face_edges:cf_role = "face_edge_connectivity" ;
mesh_face_edges:long_name = "Maps every quadrilateral face to its four edges." ;
mesh_face_edges:start_index = 1 ;
int mesh_face_links(nmesh_face, Four) ;
mesh_face_links:cf_role = "face_face_connectivity" ;
mesh_face_links:long_name = "Indicates which other faces neighbour each face." ;
mesh_face_links:start_index = 1 ;
mesh_face_links:_FillValue = -9999 ;
int mesh_edge_nodes(nmesh_edge, Two) ;
mesh_edge_nodes:cf_role = "edge_node_connectivity" ;
mesh_edge_nodes:long_name = "Maps every edge to the two nodes that it connects." ;
mesh_edge_nodes:start_index = 1 ;
double mesh_node_x(nmesh_node) ;
mesh_node_x:standard_name = "projection_x_coordinate" ;
mesh_node_x:long_name = "x coordinate of 2D mesh nodes." ;
mesh_node_x:units = "m" ;
double mesh_node_y(nmesh_node) ;
mesh_node_y:standard_name = "projection_y_coordinate" ;
mesh_node_y:long_name = "y coordinate of 2D mesh nodes." ;
mesh_node_y:units = "m" ;
double mesh_face_x(nmesh_face) ;
mesh_face_x:standard_name = "projection_x_coordinate" ;
mesh_face_x:long_name = "x coordinate of 2D face centres" ;
mesh_face_x:units = "m" ;
double mesh_face_y(nmesh_face) ;
mesh_face_y:standard_name = "projection_y_coordinate" ;
mesh_face_y:long_name = "y coordinate of 2D face centres" ;
mesh_face_y:units = "m" ;
double mesh_domain_extents(Four, Two) ;
double node_empty_data_container(nmesh_node) ;
node_empty_data_container:coordinates = "mesh_node_y mesh_node_x" ;
double face_empty_data_container(nmesh_face) ;
face_empty_data_container:coordinates = "mesh_face_y mesh_face_x" ;
double edge_empty_data_container(nmesh_edge) ;

// global attributes:
:Conventions = "CF-1.6 UGRID-1.0" ;

data:

mesh = _ ;

mesh_face_nodes =
1, 2, 3, 4,
2, 5, 6, 3,
5, 7, 8, 6,
7, 9, 10, 8,
9, 11, 12, 10,
11, 13, 14, 12,
15, 16, 2, 1,
16, 17, 5, 2,
17, 18, 7, 5,
18, 19, 9, 7,
19, 20, 11, 9,
20, 21, 13, 11 ;

mesh_face_edges =
1, 2, 3, 4,
3, 5, 6, 7,
6, 8, 9, 10,
9, 11, 12, 13,
12, 14, 15, 16,
15, 17, 18, 19,
20, 21, 22, 2,
22, 23, 24, 5,
24, 25, 26, 8,
26, 27, 28, 11,
28, 29, 30, 14,
30, 31, 32, 17 ;

mesh_face_links =
_, 7, 2, _,
1, 8, 3, _,
2, 9, 4, _,
3, 10, 5, _,
4, 11, 6, _,
5, 12, _, _,
_, _, 8, 1,
7, _, 9, 2,
8, _, 10, 3,
9, _, 11, 4,
10, _, 12, 5,
11, _, _, 6 ;

mesh_edge_nodes =
4, 1,
1, 2,
3, 2,
4, 3,
2, 5,
6, 5,
3, 6,
5, 7,
8, 7,
6, 8,
7, 9,
10, 9,
8, 10,
9, 11,
12, 11,
10, 12,
11, 13,
14, 13,
12, 14,
1, 15,
15, 16,
2, 16,
16, 17,
5, 17,
17, 18,
7, 18,
18, 19,
9, 19,
19, 20,
11, 20,
20, 21,
13, 21 ;

mesh_node_x = 8997, 8998, 8998, 8997, 8999, 8999, 9000, 9000, 9001, 9001,
9002, 9002, 9003, 9003, 8997, 8998, 8999, 9000, 9001, 9002, 9003 ;

mesh_node_y = 7000, 7000, 7001, 7001, 7000, 7001, 7000, 7001, 7000, 7001,
7000, 7001, 7000, 7001, 6999, 6999, 6999, 6999, 6999, 6999, 6999 ;

mesh_face_x = 8997.5, 8998.5, 8999.5, 9000.5, 9001.5, 9002.5, 8997.5,
8998.5, 8999.5, 9000.5, 9001.5, 9002.5 ;

mesh_face_y = 7000.5, 7000.5, 7000.5, 7000.5, 7000.5, 7000.5, 6999.5,
6999.5, 6999.5, 6999.5, 6999.5, 6999.5 ;

mesh_domain_extents =
8997, 6999,
9003, 6999,
9003, 7001,
8997, 7001 ;
}
53 changes: 53 additions & 0 deletions xios_examples/ugrid_projected/test_write_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import copy
import glob
import netCDF4
import numpy as np
import os
import subprocess
import unittest

import xios_examples.shared_testing as xshared

this_path = os.path.realpath(__file__)
this_dir = os.path.dirname(this_path)

class TestWriteMetadata(xshared._TestCase):
test_dir = this_dir
transient_inputs = ['cubedsphere_mesh.nc']
transient_outputs = ['data_output.nc']
executable = './write.exe'
mesh_file_cdl = 'planar_mesh.cdl'

@classmethod
def make_a_write_test(cls, inf, nclients=1, nservers=1):
"""
this function makes a test case and returns it as a test function,
suitable to be dynamically added to a TestCase for running.

"""
# always copy for value, don't pass by reference.
infcp = copy.copy(inf)
# expected by the fortran XIOS program's main.xml
inputfile = cls.transient_inputs[0]
outputfile = cls.transient_outputs[0]
@unittest.skipIf(os.environ.get('MVER', '') != 'XIOS3/trunk',
"skipping for XIOS2 as XIOS3 syntax used")
def test_write_metadata(self):
# create a netCDF file using nc_method
cls.make_netcdf(infcp, inputfile)
cls.run_mpi_xios(nclients=nclients, nservers=nservers)

# load the result netCDF file
runfile = '{}/{}'.format(cls.test_dir, outputfile)
assert(os.path.exists(runfile))
return test_write_metadata

f = f'{this_dir}/planar_mesh.cdl'
# unique name for the test
tname = 'test_{}'.format(os.path.splitext(os.path.basename(f))[0])
# add the test as an attribute (function) to the test class

# !!! remove this limit on success
if os.environ.get('MVER', '').startswith('XIOS3/trunk'):
setattr(TestWriteMetadata, tname,
TestWriteMetadata.make_a_write_test(f, nclients=1))
Loading
Loading