I've attached a few files that you can use as examples of how to convert fields from NetCDF files into the WPS intermediate format using Python.
Since the intermediate format consists of Fortran unformatted records, it's actually easiest to write fields from Fortran, which can be called from Python by compiling the Fortran code into a Python-callable module with f2py. You can first compile the attached "intermediate.F90" code into a Python module with f2py:
Code:
f2py -c -m WPSUtils intermediate.F90
Note that you'll probably need to use the GNU compilers (or have used the GNU compilers when installing NumPy), since there is GNU-specific code in the "intermediate.F90" file to ensure that records are written in big-endian byte order, which the WPS expects:
Code:
open(unit=output_unit, action='write', &
#ifdef __GNUC__
convert='big_endian', &
#endif
file=trim(met_out_filename), status='unknown', form='unformatted', iostat=io_status)
Then, you can import the 'WPSUtils' module from your Python code to call the Fortran functions for writing intermediate files.
The attached example Python script, "simple_example.py", would be a good starting point for learning how to call the resulting WPSUtils module. There are comments in the "simple_example.py" script that explain each function call.
Once you have created some test intermediate files with the "simple_example.py" script, you can use the "convert_pl.py" script as an example for converting your own NetCDF data. Because the NetCDF file format is flexible and datasets may be organized in one or more NetCDF files in various ways, you may find that you need to completely restructure the "convert_pl.py" example, which was developed for converting ERA5 reanalysis fields on isobaric levels from NCAR's Research Data Archive.