


Child function to call the convsh program to convert the obscure 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 pp2nc.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).
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.
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 pp2nc(file, convsh, pp2nc_tcl) 0002 % Child function to call the convsh program to convert the obscure pp 0003 % format to a 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 pp2nc.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 % 0023 % OUTPUT: 0024 % NetCDF files in the same directory as the input PP files but with a .nc 0025 % file extension. 0026 % 0027 % USAGE (PWC): Convert the PP files to NetCDF. 0028 % files = {'/path/to/file1.pp', '/path/to/file2.pp', '/path/to/file3.pp'}; 0029 % convsh = '/users/modellers/pica/bin/convsh'; 0030 % tcl = '/users/modellers/pica/MATLAB/fvcom-toolbox/utilities/pp2nc.tcl'; 0031 % pp2nc(files, convsh, tcl); 0032 % 0033 % Author(s): 0034 % Pierre Cazenave (Plymouth Marine Laboratory) 0035 % Karen Amoudry (National Oceanography Centre, Liverpool) 0036 % Judith Wolf (National Oceanography Centre, Liverpool) 0037 % 0038 % PWC Revision history: 0039 % 2013-06-24 Extracted version from the get_MetUM_forcing.m script and 0040 % set as standalone version. 0041 % 0042 % KJA Revision history: 0043 % 2013-06-25 Added support for paths with spaces in. Also added support 0044 % for creation of NetCDF files in Windows (convsh will only take a .nc 0045 % filename, not a whole path). 0046 % 0047 % JW Revision history: 0048 % 2013-08-13 Problem for paths with spaces in, especially using Windows 0049 % Add backslash after pwd to define directory 0050 % Make sure convsh is pointing to right path (cannot use paths with 0051 % spaces in command, use relative paths from starting directory, 0052 % put output file in same working directory 0053 0054 nf = length(file); 0055 0056 for ff = 1:nf 0057 if ~isnan(file{ff}) 0058 if exist(file{ff}, 'file') ~= 2 0059 error('File %s not found', file) 0060 end 0061 0062 [pathname, filename, ext] = fileparts(file{ff}); 0063 out = [filename, '.nc']; 0064 % infile = [filename, '.pp']; % JW added clear definition of input file 0065 % goback = pwd; 0066 % goback = strcat(pwd,'\') % JW - add backslash (for Windows), 0067 % to define directory 0068 % cd(pathname) 0069 % Warn if it failed for some reason 0070 [res, msg] = system([convsh, ' "', pp2nc_tcl, '" -i "', file{ff}, '" -o "', out, '"']); 0071 % [res, msg] = system([convsh, ' "', pp2nc_tcl, '" -i "', infile, '" -o "', out, '"']); 0072 % cd(goback) 0073 if res ~= 0 0074 warning('Conversion of %s to NetCDF failed. Conversion output:\n%s', file{ff}, msg) 0075 end 0076 end 0077 end