


Child function to call the convsh program to convert the PP format to a
sensible NetCDF which we can more easily read.
This requires the convsh and xconv functions available from:
http://badc.nerc.ac.uk/help/software/xconv/index.html
Follow the installation instructions for your platform (Linux, Windows,
Mac etc.) prior to running this function.
This requires the subset.tcl script in the utilities subdirectory of the
MATLAB fvcom-toolbox.
INPUT:
file - cell array of PP file(s) to convert to NetCDF. Include
sub-directory in path, can include full path name or path relative
to working directory.
convsh - the path to the convsh binary (NB this can't contain spaces).
pp2nc_tcl - the path to the TCL script (in the utilities fvcom-toolbox
file).
xextents - [startx, endx, xinc] = start longitude coordinate, end
coordinate and grid increment (> 0.1degrees).
yextents - [starty, endy, yinc] = start longitude coordinate, end
coordinate and grid increment (> 0.1degrees).
OUTPUT:
NetCDF files in the same directory as the input PP files but with a .nc
file extension.
USAGE (PWC): Convert the PP files to NetCDF.
files = {'/path/to/file1.pp', '/path/to/file2.pp', '/path/to/file3.pp'};
convsh = '/users/modellers/pica/bin/convsh';
tcl = '/users/modellers/pica/MATLAB/fvcom-toolbox/utilities/pp2nc.tcl';
pp2nc(files, convsh, tcl);
Author(s):
Pierre Cazenave (Plymouth Marine Laboratory)
Karen Amoudry (National Oceanography Centre, Liverpool)
Judith Wolf (National Oceanography Centre, Liverpool)
PWC Revision history:
2013-06-24 Extracted version from the get_MetUM_forcing.m script and
set as standalone version.
2013-09-06 Modified pp2nc.m to use the subset.tcl script (which has
more options). Also returns a list of the converted netCDF files.
KJA Revision history:
2013-06-25 Added support for paths with spaces in. Also added support
for creation of NetCDF files in Windows (convsh will only take a .nc
filename, not a whole path).
JW Revision history:
2013-08-13 Problem for paths with spaces in, especially using Windows
Add backslash after pwd to define directory
Make sure convsh is pointing to right path (cannot use paths with
spaces in command, use relative paths from starting directory,
put output file in same working directory

0001 function met_files = pp2nc_subset(file, convsh, pp2nc_tcl, xextents, yextents) 0002 % Child function to call the convsh program to convert the PP format to a 0003 % sensible NetCDF which we can more easily read. 0004 % 0005 % This requires the convsh and xconv functions available from: 0006 % 0007 % http://badc.nerc.ac.uk/help/software/xconv/index.html 0008 % 0009 % Follow the installation instructions for your platform (Linux, Windows, 0010 % Mac etc.) prior to running this function. 0011 % 0012 % This requires the subset.tcl script in the utilities subdirectory of the 0013 % MATLAB fvcom-toolbox. 0014 % 0015 % INPUT: 0016 % file - cell array of PP file(s) to convert to NetCDF. Include 0017 % sub-directory in path, can include full path name or path relative 0018 % to working directory. 0019 % convsh - the path to the convsh binary (NB this can't contain spaces). 0020 % pp2nc_tcl - the path to the TCL script (in the utilities fvcom-toolbox 0021 % file). 0022 % xextents - [startx, endx, xinc] = start longitude coordinate, end 0023 % coordinate and grid increment (> 0.1degrees). 0024 % yextents - [starty, endy, yinc] = start longitude coordinate, end 0025 % coordinate and grid increment (> 0.1degrees). 0026 % 0027 % OUTPUT: 0028 % NetCDF files in the same directory as the input PP files but with a .nc 0029 % file extension. 0030 % 0031 % USAGE (PWC): Convert the PP files to NetCDF. 0032 % files = {'/path/to/file1.pp', '/path/to/file2.pp', '/path/to/file3.pp'}; 0033 % convsh = '/users/modellers/pica/bin/convsh'; 0034 % tcl = '/users/modellers/pica/MATLAB/fvcom-toolbox/utilities/pp2nc.tcl'; 0035 % pp2nc(files, convsh, tcl); 0036 % 0037 % Author(s): 0038 % Pierre Cazenave (Plymouth Marine Laboratory) 0039 % Karen Amoudry (National Oceanography Centre, Liverpool) 0040 % Judith Wolf (National Oceanography Centre, Liverpool) 0041 % 0042 % PWC Revision history: 0043 % 2013-06-24 Extracted version from the get_MetUM_forcing.m script and 0044 % set as standalone version. 0045 % 2013-09-06 Modified pp2nc.m to use the subset.tcl script (which has 0046 % more options). Also returns a list of the converted netCDF files. 0047 % 0048 % KJA Revision history: 0049 % 2013-06-25 Added support for paths with spaces in. Also added support 0050 % for creation of NetCDF files in Windows (convsh will only take a .nc 0051 % filename, not a whole path). 0052 % 0053 % JW Revision history: 0054 % 2013-08-13 Problem for paths with spaces in, especially using Windows 0055 % Add backslash after pwd to define directory 0056 % Make sure convsh is pointing to right path (cannot use paths with 0057 % spaces in command, use relative paths from starting directory, 0058 % put output file in same working directory 0059 0060 nf = length(file); 0061 0062 for ff = 1:nf 0063 if ~isnan(file{ff}) 0064 if exist(file{ff}, 'file') ~= 2 0065 error('File %s not found', file) 0066 end 0067 0068 [pathname, filename, ~] = fileparts(file{ff}); 0069 met_files{ff} = [filename, '.nc']; 0070 cd(pathname) 0071 % Warn if it failed for some reason 0072 [res, msg] = system([... 0073 convsh, ' "', pp2nc_tcl, '" -i "', file{ff}, '" -o "', met_files{ff}, ... 0074 '" -xs ', num2str(xextents(1)), ... 0075 ' -xe ', num2str(xextents(2)), ... 0076 ' -xi ', num2str(xextents(3)), ... 0077 ' -ys ', num2str(yextents(1)), ... 0078 ' -ye ', num2str(yextents(2)), ... 0079 ' -yi ',num2str( yextents(3))... 0080 ]); 0081 % [res, msg] = system([convsh, ' "', pp2nc_tcl, '" -i "', infile, '" -o "', out, '"']); 0082 cd(goback) 0083 if res ~= 0 0084 warning('Conversion of %s to NetCDF failed. Conversion output:\n%s', file{ff}, msg) 0085 end 0086 end 0087 end