diff --git a/doc/fvcom_postproc/graph.dot b/doc/fvcom_postproc/graph.dot new file mode 100644 index 0000000000000000000000000000000000000000..317dcc4db15916805c5efe097b078fb7278cf0df --- /dev/null +++ b/doc/fvcom_postproc/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + + README [URL="README.html"]; + example_surface_plot [URL="example_surface_plot.html"]; +} \ No newline at end of file diff --git a/doc/fvcom_postproc/graph.html b/doc/fvcom_postproc/graph.html new file mode 100644 index 0000000000000000000000000000000000000000..a45007d6bc4d8d1edb67f9ee271f412bbf89a4b1 --- /dev/null +++ b/doc/fvcom_postproc/graph.html @@ -0,0 +1,29 @@ + + + + Dependency Graph for fvcom_postproc + + + + + + + + + + +
< Master indexIndex for fvcom_postproc >
+

Dependency Graph for fvcom_postproc

+ +
+Dependency Graph for fvcom_postproc + + + + +
+ +
Generated on Tue 04-Jun-2013 12:12:56 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/fvcom_postproc/graph.map b/doc/fvcom_postproc/graph.map new file mode 100644 index 0000000000000000000000000000000000000000..4da89abc7f216053d8d16ad71490665ea8cb525b --- /dev/null +++ b/doc/fvcom_postproc/graph.map @@ -0,0 +1,2 @@ + + diff --git a/doc/fvcom_postproc/graph.png b/doc/fvcom_postproc/graph.png new file mode 100644 index 0000000000000000000000000000000000000000..8e5fec85938e36597482c7cc8328a6b1e4d6b079 Binary files /dev/null and b/doc/fvcom_postproc/graph.png differ diff --git a/doc/fvcom_postproc/index.html b/doc/fvcom_postproc/index.html index b753f3d6a440786022e821531039db1790a9142d..5f169c14128cfead23a3a18650c2800fb4fd9f18 100755 --- a/doc/fvcom_postproc/index.html +++ b/doc/fvcom_postproc/index.html @@ -25,7 +25,10 @@

Subsequent directories:

- -
Generated on Mon 04-Feb-2013 14:22:26 by m2html © 2005
+

Dependency Graph

+ +
Generated on Tue 04-Jun-2013 12:12:54 by m2html © 2005
\ No newline at end of file diff --git a/doc/fvcom_prepro/add_river_nodes_list.html b/doc/fvcom_prepro/add_river_nodes_list.html index cd8febc118b5034d40aa687c74fb86bafa43bc5c..a72291e611e41c923457c864882495b2d398a26b 100755 --- a/doc/fvcom_prepro/add_river_nodes_list.html +++ b/doc/fvcom_prepro/add_river_nodes_list.html @@ -24,13 +24,13 @@
Add a set of river nodes comprising a single river to Mesh structure

SYNOPSIS ^

-
function [Mobj] = add_river_nodes(Mobj,Nlist,RiverName)
+
function [Mobj] = add_river_nodes_list(Mobj,Nlist,RiverName)

DESCRIPTION ^

 Add a set of river nodes comprising a single river to Mesh structure  
  Using a set of user-defined nodes
 
- [Mobj] = add_river_nodes(Mobj)
+ [Mobj] = add_river_nodes(Mobj,Nlist,RiverName)
 
  DESCRIPTION:
     Select using ginput the set of nodes comprising a river
@@ -43,7 +43,7 @@
     Mobj = Matlab mesh object with an additional river nodelist
 
  EXAMPLE USAGE
-    Mobj = add_river_nodes(Mobj,'Potomac')
+    Mobj = add_river_nodes(Mobj, [146, 3004], 'Potomac')
 
  Author(s):  
     Geoff Cowles (University of Massachusetts Dartmouth)
@@ -54,7 +54,7 @@
 
  Revision history
    
-==============================================================================
+==========================================================================

CROSS-REFERENCE INFORMATION ^

@@ -69,12 +69,12 @@ This function is called by:

SOURCE CODE ^

-
0001 function [Mobj]  = add_river_nodes(Mobj,Nlist,RiverName)
+
0001 function [Mobj] = add_river_nodes_list(Mobj,Nlist,RiverName)
 0002 
 0003 % Add a set of river nodes comprising a single river to Mesh structure
 0004 % Using a set of user-defined nodes
 0005 %
-0006 % [Mobj] = add_river_nodes(Mobj)
+0006 % [Mobj] = add_river_nodes(Mobj,Nlist,RiverName)
 0007 %
 0008 % DESCRIPTION:
 0009 %    Select using ginput the set of nodes comprising a river
@@ -87,7 +87,7 @@ This function is called by:
 0016 %    Mobj = Matlab mesh object with an additional river nodelist
 0017 %
 0018 % EXAMPLE USAGE
-0019 %    Mobj = add_river_nodes(Mobj,'Potomac')
+0019 %    Mobj = add_river_nodes(Mobj, [146, 3004], 'Potomac')
 0020 %
 0021 % Author(s):
 0022 %    Geoff Cowles (University of Massachusetts Dartmouth)
@@ -98,57 +98,57 @@ This function is called by:
 0027 %
 0028 % Revision history
 0029 %
-0030 %==============================================================================
-0031 subname = 'add_river_nodes';
+0030 %==========================================================================
+0031 subname = 'add_river_nodes_list';
 0032 global ftbverbose
-0033 if(ftbverbose)
-0034   fprintf('\n')
-0035   fprintf(['begin : ' subname '\n'])
-0036 end;
+0033 if ftbverbose
+0034     fprintf('\n')
+0035     fprintf(['begin : ' subname '\n'])
+0036 end
 0037 
-0038 %------------------------------------------------------------------------------
+0038 %--------------------------------------------------------------------------
 0039 % Get a unique list and make sure they are in the range of node numbers
-0040 %------------------------------------------------------------------------------
+0040 %--------------------------------------------------------------------------
 0041 Nlist = unique(Nlist);
 0042 
-0043 if(max(Nlist) > Mobj.nVerts);
-0044   fprintf('your river node number(s) exceed the total number of nodes in the domain\n');
-0045   fprintf('stop screwing around\n');
-0046   error('stopping...\n')
-0047 end;
+0043 if max(Nlist) > Mobj.nVerts
+0044     fprintf('your river node number(s) exceed the total number of nodes in the domain\n');
+0045     fprintf('stop screwing around\n');
+0046     error('stopping...\n')
+0047 end
 0048 
-0049 %------------------------------------------------------------------------------
+0049 %--------------------------------------------------------------------------
 0050 % Plot the mesh
-0051 %------------------------------------------------------------------------------
+0051 %--------------------------------------------------------------------------
 0052 
-0053 if(lower(Mobj.nativeCoords(1:3)) == 'car')
-0054         x = Mobj.x;
-0055         y = Mobj.y;
+0053 if strcmpi(Mobj.nativeCoords(1:3), 'car')
+0054     x = Mobj.x;
+0055     y = Mobj.y;
 0056 else
-0057         x = Mobj.lon;
-0058         y = Mobj.lat;
-0059 end;
+0057     x = Mobj.lon;
+0058     y = Mobj.lat;
+0059 end
 0060 
 0061 figure
-0062 patch('Vertices',[x,y],'Faces',Mobj.tri,...
-0063         'Cdata',Mobj.h,'edgecolor','k','facecolor','interp');
-0064 hold on;
+0062 patch('Vertices', [x,y], 'Faces', Mobj.tri,...
+0063         'Cdata', Mobj.h, 'edgecolor', 'k', 'facecolor', 'interp');
+0064 hold on
 0065 
-0066 plot(x(Nlist),y(Nlist),'ro');
-0067 title('river nodes');
+0066 plot(x(Nlist), y(Nlist), 'ro')
+0067 title('river nodes')
 0068 
 0069 % add to mesh object
 0070 npts = numel(Nlist);
 0071 Mobj.nRivers = Mobj.nRivers + 1;
 0072 Mobj.nRivNodes(Mobj.nRivers) = npts;
-0073 Mobj.riv_nodes(Mobj.nRivers,1:npts) = Nlist;
+0073 Mobj.riv_nodes(Mobj.nRivers, 1:npts) = Nlist;
 0074 Mobj.riv_name{Mobj.nRivers} = RiverName;
 0075 
 0076 
-0077 if(ftbverbose)
-0078   fprintf(['end   : ' subname '\n'])
-0079 end;
+0077 if ftbverbose
+0078     fprintf(['end   : ' subname '\n'])
+0079 end
 0080
-
Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
+
Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
\ No newline at end of file diff --git a/doc/fvcom_prepro/add_sponge_nodes_list.html b/doc/fvcom_prepro/add_sponge_nodes_list.html index 8fafa51738dbf292be08ec74e4dc7edddf7b4c8f..e630425ebe91400599ae410ec46ec6ff4929dfa5 100644 --- a/doc/fvcom_prepro/add_sponge_nodes_list.html +++ b/doc/fvcom_prepro/add_sponge_nodes_list.html @@ -159,7 +159,7 @@ This function is called by: 0084 Mobj.sponge_name{Mobj.nSponge} = SpongeName; 0085 Mobj.sponge_fac(Mobj.nSponge) = SpongeCoeff; 0086 -0087 if max(size(SpongeRadius))==1 % if you have a constant sponge radius +0087 if numel(unique(SpongeRadius)) == 1 % if you have a constant sponge radius 0088 Mobj.sponge_rad(Mobj.nSponge) = SpongeRadius; 0089 else % if you have a variable sponge radius 0090 Mobj.sponge_rad(Mobj.nSponge,1:npts) = SpongeRadius; @@ -169,6 +169,6 @@ This function is called by: 0094 fprintf(['end : ' subname '\n']) 0095 end 0096
-
Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
+
Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
\ No newline at end of file diff --git a/doc/fvcom_prepro/add_stations_list.html b/doc/fvcom_prepro/add_stations_list.html index 064b8501b986221e34ea652a024d4156ae58142f..5b3e0131caf624558b56af30d95337b0652e81fa 100644 --- a/doc/fvcom_prepro/add_stations_list.html +++ b/doc/fvcom_prepro/add_stations_list.html @@ -169,7 +169,14 @@ This function is called by: 0090 inc = inc + 1; 0091 end 0092 -0093 Mobj.stations = out; -
Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
+0093 if ~isempty(out) +0094 Mobj.stations = out; +0095 else +0096 Mobj.stations = []; +0097 if ftbverbose +0098 fprintf('No stations found within the model domain.\n') +0099 end +0100 end +
Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
\ No newline at end of file diff --git a/doc/fvcom_prepro/add_var_FVCOM_river.html b/doc/fvcom_prepro/add_var_FVCOM_river.html index 5103528f3426bcb31e398b77e0b11650252b6b1c..115a8a89b18c3b78ee213f5bf2cd451d1be9142a 100755 --- a/doc/fvcom_prepro/add_var_FVCOM_river.html +++ b/doc/fvcom_prepro/add_var_FVCOM_river.html @@ -105,7 +105,7 @@ This function is called by: 0031 % 0032 %============================================================================== 0033 -0034 warning off +0034 %warning off 0035 0036 subname = 'add_var_FVCOM_river'; 0037 global ftbverbose; @@ -172,6 +172,6 @@ This function is called by: 0098 fprintf(['end : ' subname '\n']) 0099 end; 0100 -
Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
+
Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
\ No newline at end of file diff --git a/doc/fvcom_prepro/example.html b/doc/fvcom_prepro/example.html index b9227939768f3fbd6bf8eb7347416431dd1491fb..675a47c7636fe0ccea2d07480aec2a5abb8ccc81 100755 --- a/doc/fvcom_prepro/example.html +++ b/doc/fvcom_prepro/example.html @@ -56,7 +56,7 @@

CROSS-REFERENCE INFORMATION ^

This function calls: +
  • add_coriolis Generate latitude used for FVCOM Coriolis file
  • add_obc_nodes_list Add a set of obc nodes comprising a single obc boundary to Mesh structure
  • add_river_nodes_list Add a set of river nodes comprising a single river to Mesh structure
  • elems2nodes Transfer a field from elements to vertices
  • estimate_ts Estimate time step at each node
  • example_FVCOM_river example file for dumping an FVCOM river file and adding sediment concentration
  • example_FVCOM_tsobc example file for dumping a file to force temperature and salinity at the open b.
  • example_FVCOM_wind_ts example file for FVCOM, time-varying/spatially constant wind forcing as stress
  • nodes2elems Transfer a field from vertices to elements
  • plot_field Plot the mesh, user defined field, open boundary nodes, and river points
  • read_sms_mesh Read sms mesh files into Matlab mesh object
  • set_spectide Setup spectral tides on the open boundary and dump a spectral file
  • setup_metrics Setup metrics for mesh object Mesh
  • smoothfield Smooth a vertex-based field using averages
  • write_FVCOM_bath Write bathymetry to FVCOM format bathymetry file
  • write_FVCOM_bedflag Dump spatially-variable flag (bedflag) to FVCOM forcing file
  • write_FVCOM_cor Write coriolis to FVCOM format coriolis file
  • write_FVCOM_grid Write grid and connectivity to FVCOM format grid file
  • write_FVCOM_obc Write FVCOM format open boundary node list file
  • write_FVCOM_sponge Write FVCOM format sponge layer file
  • write_FVCOM_z0 Dump spatially-variable or uniform bottom roughness (z0) to FVCOM forcing
  • This function is called by: @@ -119,7 +119,7 @@ This function is called by: 0052 plot_field(Mobj,Mobj.h,'title','smoothed bathymetry'); 0053 0054 % setup spatially variable bottom roughness and dump to file -0055 hc = nodes2elems(Mobj.h,Mobj); +0055 hc = nodes2elems(Mobj.h,Mobj); 0056 z0 = .008*ones(Mobj.nElems,1); 0057 deep = find(hc > 5.); 0058 z0(deep) = .004; @@ -129,7 +129,7 @@ This function is called by: 0062 0063 % add a river to the domain 0064 %[Mobj] = add_river_nodes_graphic(Mobj,'tstRiver'); -0065 [Mobj] = add_river_nodes_list(Mobj,[838,844,845],'tstRiver'); +0065 [Mobj] = add_river_nodes_list(Mobj,[838,844,845],'tstRiver'); 0066 0067 % add an open boundary to the Mesh 0068 [Mobj] = add_obc_nodes_list(Mobj,[1:25],'OpenOcean',1); @@ -185,6 +185,6 @@ This function is called by: 0118 write_FVCOM_cor(Mobj,'tst_cor.dat') 0119 0120 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/example_FVCOM_river.html b/doc/fvcom_prepro/example_FVCOM_river.html index 544247d7d5f04e7db594a6399edff79505196623..617bdde93e294349f494199a92388b632dc5bc42 100755 --- a/doc/fvcom_prepro/example_FVCOM_river.html +++ b/doc/fvcom_prepro/example_FVCOM_river.html @@ -50,7 +50,7 @@

    CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • add_var_FVCOM_river add time dependent scalar variable to a Riverfile
  • write_FVCOM_river Write FVCOM 3.x NetCDF river file
  • This function is called by: @@ -103,7 +103,7 @@ This function is called by: 0042 RiverName = 'tstRiver'; 0043 0044 -0045 write_FVCOM_river(RiverFile,RiverName,nRivnodes,time,flux,temp,salt,RiverInfo1,RiverInfo2) +0045 write_FVCOM_river(RiverFile,RiverName,nRivnodes,time,flux,temp,salt,RiverInfo1,RiverInfo2) 0046 0047 % add sediment to the file 0048 VarName = 'fine_sand'; @@ -123,6 +123,6 @@ This function is called by: 0062 VarUnits = 'kgm^-3'; 0063 VarData = .333*sedload; 0064 add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData) -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/example_FVCOM_tsobc.html b/doc/fvcom_prepro/example_FVCOM_tsobc.html index 0d1b1a641c99ac59e5fe3bab5a3527e2211c1078..100a90af46a1f70cc3c1965b77ec6a88df8276b5 100755 --- a/doc/fvcom_prepro/example_FVCOM_tsobc.html +++ b/doc/fvcom_prepro/example_FVCOM_tsobc.html @@ -97,7 +97,7 @@ This function is called by: 0027 % 0028 %============================================================================== 0029 -0030 warning off; +0030 %warning off; 0031 0032 0033 subname = 'example_FVCOM_tsobc'; @@ -197,7 +197,7 @@ This function is called by: 0127 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'type','FVCOM RIVER FORCING FILE') 0128 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title','simple open boundary hydrography test') 0129 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'type','FVCOM TIME SERIES OBC TS FILE') -0130 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','generated using the fvcom-toolbox') +0130 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','File generated using example_FVCOM_tsobc.m from the MATLAB fvcom-toolbox') 0131 0132 0133 % define dimensions @@ -276,6 +276,6 @@ This function is called by: 0206 netcdf.close(nc); 0207 0208 if(ftbverbose); fprintf(['end : ' subname '\n']);end; -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/example_FVCOM_wind_ts.html b/doc/fvcom_prepro/example_FVCOM_wind_ts.html index f7e770d5a5ee0d772d2140d4ad6f025096f74e91..49209e51d9268eb93400c8139d089cfb112dde34 100755 --- a/doc/fvcom_prepro/example_FVCOM_wind_ts.html +++ b/doc/fvcom_prepro/example_FVCOM_wind_ts.html @@ -50,7 +50,8 @@ Revision history -============================================================================== +============================================================================== +warning off

    CROSS-REFERENCE INFORMATION ^

    @@ -91,7 +92,7 @@ This function is called by: 0024 % Revision history 0025 % 0026 %============================================================================== -0027 warning off +0027 %warning off 0028 subname = 'example_FVCOM_wind_ts'; 0029 global ftbverbose; 0030 if(ftbverbose); @@ -181,6 +182,6 @@ This function is called by: 0114 0115 0116 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/example_FVCOM_wind_ts_speed.html b/doc/fvcom_prepro/example_FVCOM_wind_ts_speed.html index 079211b8474339efd5b67f4a0f94b21944c109f7..937b79b0de145891eb062375aeceea94d1dea0cd 100755 --- a/doc/fvcom_prepro/example_FVCOM_wind_ts_speed.html +++ b/doc/fvcom_prepro/example_FVCOM_wind_ts_speed.html @@ -50,7 +50,8 @@ Revision history -============================================================================== +============================================================================== +warning off

    CROSS-REFERENCE INFORMATION ^

    @@ -91,7 +92,7 @@ This function is called by: 0024 % Revision history 0025 % 0026 %============================================================================== -0027 warning off +0027 %warning off 0028 subname = 'example_FVCOM_wind_ts'; 0029 fprintf('\n') 0030 fprintf(['begin : ' subname '\n']) @@ -170,6 +171,6 @@ This function is called by: 0103 0104 0105 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/example_init_lag.html b/doc/fvcom_prepro/example_init_lag.html new file mode 100644 index 0000000000000000000000000000000000000000..2947da01f2078e4f303c2c37082cfbc937758d90 --- /dev/null +++ b/doc/fvcom_prepro/example_init_lag.html @@ -0,0 +1,159 @@ + + + + Description of example_init_lag + + + + + + + + + +
    Home > fvcom_prepro > example_init_lag.m
    + + + +

    example_init_lag +

    + +

    PURPOSE ^

    +
    + +

    SYNOPSIS ^

    +
    This is a script file.
    + +

    DESCRIPTION ^

    +
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 clear all; close all;
    +0002 
    +0003 % example script:
    +0004 % initialize the online Lagrangian tracking for Julian day (realtime) forcing
    +0005 %
    +0006 % Author(s):
    +0007 %    Geoff Cowles (University of Massachusetts Dartmouth)
    +0008 %
    +0009 % Revision history
    +0010 %
    +0011 %==============================================================================
    +0012 %warning off
    +0013 type = 2;
    +0014 
    +0015 % set mesh/bathymetry files
    +0016 meshfile = '../Model_Maker/coos01_grd.dat';
    +0017 bathfile = '../Model_Maker/coos01_dep.dat'; 
    +0018 lagfile  = 'test_lag.nc';
    +0019 
    +0020 % start/end time for particles
    +0021 tbeg = greg2mjulian(2008,01,01,0,0,0); 
    +0022 tend = greg2mjulian(2008,02,01,0,0,0); 
    +0023 
    +0024 % read in mesh and bathymetry
    +0025 Mobj = read_fvcom_mesh(meshfile);
    +0026 Mobj.h = read_fvcom_bath(bathfile); Mobj.have_bath = true;
    +0027 Mobj = setup_metrics(Mobj);
    +0028 
    +0029 
    +0030 if(type==1) %initialize at all elements
    +0031 
    +0032 xc   = Mobj.xc;
    +0033 yc   = Mobj.yc;
    +0034 nLag = Mobj.nElems;
    +0035 
    +0036 elseif(type==2) %initialize along a line of interest
    +0037 nLag = 10;  
    +0038 p1 = [1.188363e6,194497];
    +0039 p2 = [1.188548e6,194996];
    +0040 xp = p1(1):(p2(1)-p1(1))/(nLag-1):p2(1);
    +0041 yp = p1(2):(p2(2)-p1(2))/(nLag-1):p2(2);
    +0042 
    +0043 end;
    +0044 
    +0045 
    +0046 % plot to check
    +0047 plot_field(Mobj,Mobj.h,'title','domain','withextra',false,'showgrid',false); hold on;
    +0048 plot(xp,yp,'ro');
    +0049 
    +0050 
    +0051 % dump the initial particle position file
    +0052 nc = netcdf(lagfile,'clobber');
    +0053 nc.references = 'http://fvcom.smast.umassd.edu';
    +0054 nc.source = 'lag_init.m';
    +0055 nc.info = 'debugging ';
    +0056 
    +0057 
    +0058 
    +0059 
    +0060 
    +0061   
    +0062 % dimensions
    +0063 nc('nparticles') = nLag;
    +0064 
    +0065 % particle  vars
    +0066 nc{'x'} = ncfloat('nparticles');
    +0067 nc{'x'}.long_name = 'particle x position';
    +0068 nc{'x'}.units = 'm'; 
    +0069 
    +0070 nc{'y'} = ncfloat('nparticles');
    +0071 nc{'y'}.long_name = 'particle y position';
    +0072 nc{'y'}.units = 'm'; 
    +0073 
    +0074 nc{'z'} = ncfloat('nparticles');
    +0075 nc{'z'}.long_name = 'particle z position';
    +0076 nc{'z'}.units = 'm'; 
    +0077 
    +0078 nc{'pathlength'} = ncfloat('nparticles');
    +0079 nc{'pathlength'}.long_name = 'particle integrated path length'; 
    +0080 nc{'pathlength'}.units = 'm'; 
    +0081 
    +0082 nc{'tbeg'} = ncfloat('nparticles');
    +0083 nc{'tbeg'}.long_name = 'particle release time';
    +0084 nc{'tbeg'}.units = 'days since 1858-11-17 00:00:00';
    +0085 nc{'tbeg'}.format = 'modified julian day (MJD)';
    +0086 nc{'tbeg'}.time_zone = 'UTC';
    +0087 
    +0088 nc{'tend'} = ncfloat('nparticles');
    +0089 nc{'tend'}.long_name = 'particle freeze time';
    +0090 nc{'tend'}.units = 'days since 1858-11-17 00:00:00';
    +0091 nc{'tend'}.format = 'modified julian day (MJD)';
    +0092 nc{'tend'}.time_zone = 'UTC';
    +0093 
    +0094 
    +0095 nc{'group'} = ncint('nparticles');
    +0096 nc{'group'}.long_name = 'particle group'; 
    +0097 nc{'group'}.units = '-'; 
    +0098 
    +0099 nc{'mark'} = ncint('nparticles');
    +0100 nc{'mark'}.long_name = 'particle mark'; 
    +0101 nc{'mark'}.units = '-'; 
    +0102 
    +0103 % dump vars
    +0104 nc{'x'}(:) = xp;
    +0105 nc{'y'}(:) = yp;
    +0106 nc{'z'}(:) = 0.0;
    +0107 nc{'tbeg'}(:) = tbeg;
    +0108 nc{'tend'}(:) = tend;
    +0109 nc{'group'}(:) = 1;
    +0110 nc{'mark'}(:) = 0;
    +0111 nc{'pathlength'}(:) = 0.0;
    +0112 close(nc);
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/get_FVCOM_rivers.html b/doc/fvcom_prepro/get_FVCOM_rivers.html new file mode 100644 index 0000000000000000000000000000000000000000..02a2900698386549b6c5b6db801aab437a9ecd73 --- /dev/null +++ b/doc/fvcom_prepro/get_FVCOM_rivers.html @@ -0,0 +1,394 @@ + + + + Description of get_FVCOM_rivers + + + + + + + + + +
    Home > fvcom_prepro > get_FVCOM_rivers.m
    + + + +

    get_FVCOM_rivers +

    + +

    PURPOSE ^

    +
    Extract river discharges from the supplied river positions for the FVCOM
    + +

    SYNOPSIS ^

    +
    function Mobj = get_FVCOM_rivers(Mobj, dist_thresh)
    + +

    DESCRIPTION ^

    +
     Extract river discharges from the supplied river positions for the FVCOM
    + grid in Mobj.
    +
    + get_FVCOM_rivers(Mobj, rivers, dist_thresh)
    +
    + DESCRIPTION:
    +   For the positioins in fvcom_xy, find the nearest unstructured grid node
    +   and extract the river discharge from polcoms_flow. If dist_thresh is
    +   specified, the river positions must fall within the specified distance.
    +   If multiple rivers are assigned to the same node, their discharges are
    +   summed. The resulting river name is generated from the contributing
    +   rives, separated by a hyphen.
    +
    + INPUT:
    +   Mobj - MATLAB mesh object containing:
    +       * have_lonlat - boolean to check for spherical coordinates.
    +       * lon, lat - positions for the unstructured grid.
    +       * tri - triangulation table for the unstructured grid.
    +       * nVerts - number of nodes in the grid.
    +       * read_obc_nodes - open boundary node IDs.
    +       * rivers - river data struct with the following fields:
    +           - year - start year of the river data time series.
    +           - positions - river positions in lon, lat.
    +           - names - list of river names (whose order must match the
    +               positions in xy).
    +           - discharge - river discharge data (again, order of columns
    +               must match the positions in Mobj.rivers.positions).
    +   dist_thresh - [optional] maximum distance away from a river node beyond
    +       which the search for an FVCOM node is abandoned. Units in degrees.
    +
    + OUTPUT:
    +   Mobj.river_flux - volume flux at the nodes within the model domain.
    +   Mobj.river_nodes - node IDs for the rivers. At the moment, these are
    +       point sources only. Eventually, some rivers may have to be split
    +       over several nodes.
    +   Mobj.river_names - river names which fall within the model domain. For
    +       rivers where the discharge has been summed, the name is compoud,
    +       with each contributing name separated by a hyphen (-).
    +   Mobj.river_time - time series for the river discharge data
    +
    + EXAMPLE USAGE:
    +   Mobj = get_FVCOM_rivers(Mobj, Mobj.rivers, 0.025)
    +
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2013-03-27 - First version.
    +   2013-04-15 - Removed the code to load the positions and discharge data
    +   into separate functions so that this function can be purely about
    +   finding the closest locations and the summing of discharges (if
    +   necessary). The downside is the order of the discharges (columns) must
    +   match the position arrays.
    +   2013-05-21 - Add check to avoid setting nodes as river nodes when that
    +   node is part of only one element. If this is not added, then the model
    +   fills up the element without moving the water out of that element,
    +   eventually leading to a crash, which is obviously not ideal. The fix
    +   searches for another node in the element which is part of at least two
    +   elements, thereby avoiding the "element filling" issue. Also updated
    +   the help to list all the required fields in the Mobj.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function Mobj = get_FVCOM_rivers(Mobj, dist_thresh)
    +0002 % Extract river discharges from the supplied river positions for the FVCOM
    +0003 % grid in Mobj.
    +0004 %
    +0005 % get_FVCOM_rivers(Mobj, rivers, dist_thresh)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %   For the positioins in fvcom_xy, find the nearest unstructured grid node
    +0009 %   and extract the river discharge from polcoms_flow. If dist_thresh is
    +0010 %   specified, the river positions must fall within the specified distance.
    +0011 %   If multiple rivers are assigned to the same node, their discharges are
    +0012 %   summed. The resulting river name is generated from the contributing
    +0013 %   rives, separated by a hyphen.
    +0014 %
    +0015 % INPUT:
    +0016 %   Mobj - MATLAB mesh object containing:
    +0017 %       * have_lonlat - boolean to check for spherical coordinates.
    +0018 %       * lon, lat - positions for the unstructured grid.
    +0019 %       * tri - triangulation table for the unstructured grid.
    +0020 %       * nVerts - number of nodes in the grid.
    +0021 %       * read_obc_nodes - open boundary node IDs.
    +0022 %       * rivers - river data struct with the following fields:
    +0023 %           - year - start year of the river data time series.
    +0024 %           - positions - river positions in lon, lat.
    +0025 %           - names - list of river names (whose order must match the
    +0026 %               positions in xy).
    +0027 %           - discharge - river discharge data (again, order of columns
    +0028 %               must match the positions in Mobj.rivers.positions).
    +0029 %   dist_thresh - [optional] maximum distance away from a river node beyond
    +0030 %       which the search for an FVCOM node is abandoned. Units in degrees.
    +0031 %
    +0032 % OUTPUT:
    +0033 %   Mobj.river_flux - volume flux at the nodes within the model domain.
    +0034 %   Mobj.river_nodes - node IDs for the rivers. At the moment, these are
    +0035 %       point sources only. Eventually, some rivers may have to be split
    +0036 %       over several nodes.
    +0037 %   Mobj.river_names - river names which fall within the model domain. For
    +0038 %       rivers where the discharge has been summed, the name is compoud,
    +0039 %       with each contributing name separated by a hyphen (-).
    +0040 %   Mobj.river_time - time series for the river discharge data
    +0041 %
    +0042 % EXAMPLE USAGE:
    +0043 %   Mobj = get_FVCOM_rivers(Mobj, Mobj.rivers, 0.025)
    +0044 %
    +0045 % Author(s):
    +0046 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0047 %
    +0048 % Revision history:
    +0049 %   2013-03-27 - First version.
    +0050 %   2013-04-15 - Removed the code to load the positions and discharge data
    +0051 %   into separate functions so that this function can be purely about
    +0052 %   finding the closest locations and the summing of discharges (if
    +0053 %   necessary). The downside is the order of the discharges (columns) must
    +0054 %   match the position arrays.
    +0055 %   2013-05-21 - Add check to avoid setting nodes as river nodes when that
    +0056 %   node is part of only one element. If this is not added, then the model
    +0057 %   fills up the element without moving the water out of that element,
    +0058 %   eventually leading to a crash, which is obviously not ideal. The fix
    +0059 %   searches for another node in the element which is part of at least two
    +0060 %   elements, thereby avoiding the "element filling" issue. Also updated
    +0061 %   the help to list all the required fields in the Mobj.
    +0062 %
    +0063 %==========================================================================
    +0064 
    +0065 subname = 'get_FVCOM_rivers';
    +0066 
    +0067 global ftbverbose;
    +0068 if ftbverbose
    +0069     fprintf(['\nbegin : ' subname '\n'])
    +0070 end
    +0071 
    +0072 % Check inputs
    +0073 if ~Mobj.have_lonlat
    +0074     error('Require unstructured grid positions in lon/lat format to compare against supplied river positions.')
    +0075 end
    +0076 
    +0077 % Separate the inputs into separate arrays.
    +0078 fvcom_name = Mobj.rivers.names;
    +0079 fvcom_xy = Mobj.rivers.positions;
    +0080 polcoms_flow = Mobj.rivers.discharge;
    +0081 
    +0082 % We have to be careful because POLCOMS has duplicate river names.
    +0083 %
    +0084 %   "This has made a lot of people very angry and has been widely regarded
    +0085 %   as a bad move."
    +0086 %
    +0087 % For duplicates, we need, therefore, to work out a way to handle them
    +0088 % elegantly. We will assume that rivers with the same name are close to one
    +0089 % another. As such, we'll sum their discharges.
    +0090 [~, di] = unique(fvcom_name, 'first');
    +0091 fv_dupes = 1:length(fvcom_name);
    +0092 fv_dupes(di) = []; % index of duplicates (does this work with more than two?)
    +0093 
    +0094 % Iterate through the list of duplicates and clear them out in the names,
    +0095 % positions and discharge. We have to ensure that the order of the
    +0096 % deduplicated positions and discharge are the same, otherwise we'll end up
    +0097 % with the wrong discharge for a given river position, which would be bad.
    +0098 for i = 1:length(fv_dupes)
    +0099     dup_name = fvcom_name(fv_dupes(i));
    +0100     didx = strmatch(dup_name, fvcom_name, 'exact');
    +0101     
    +0102     % Sum the duplicate rivers' data.
    +0103     dup_discharge = sum(polcoms_flow(:, didx), 2);
    +0104     
    +0105     % Remove the original values and put the summed data at the end.
    +0106     polcoms_flow(:, didx) = [];
    +0107     polcoms_flow = [polcoms_flow, dup_discharge];
    +0108     
    +0109     % Now remove the duplicates from the FVCOM data.
    +0110     fvcom_name{length(fvcom_name) + 1} = fvcom_name{fv_dupes(i)};
    +0111     fvcom_name(didx) = [];
    +0112     fvcom_xy = [fvcom_xy; fvcom_xy(fv_dupes(i), :)];
    +0113     fvcom_xy(didx, :) = [];
    +0114 end
    +0115 
    +0116 % Get number of times and rivers from the deduplicated data.
    +0117 fv_nr = length(fvcom_name);
    +0118 [pc_nt, ~] = size(polcoms_flow);
    +0119 
    +0120 clear didx dup_discharge
    +0121 
    +0122 
    +0123 % Check each location in the FVCOM rivers file against the grid in Mobj and
    +0124 % for the indices within the dist_thresh, extract the relevant time series
    +0125 % data.
    +0126 
    +0127 vc = 0; % valid FVCOM boundary node counter
    +0128 
    +0129 % We need to find the unstructured grid boundary nodes and exclude the open
    +0130 % boundary nodes from them. This will be our list of potential candidates
    +0131 % for the river nodes (i.e. the land coastline).
    +0132 [~, ~, ~, bnd] = connectivity([Mobj.lon, Mobj.lat], Mobj.tri);
    +0133 boundary_nodes = 1:Mobj.nVerts;
    +0134 boundary_nodes = boundary_nodes(bnd);
    +0135 coast_nodes = boundary_nodes(~ismember(boundary_nodes, [Mobj.read_obc_nodes{:}]));
    +0136 tlon = Mobj.lon(coast_nodes);
    +0137 tlat = Mobj.lat(coast_nodes);
    +0138 
    +0139 fv_obc = nan;
    +0140 fvcom_names = cell(0);
    +0141 fv_riv_idx = nan;
    +0142 
    +0143 for ff = 1:fv_nr
    +0144     % Find the open boundary node closest to this river.
    +0145     fv_dist = sqrt( ...
    +0146         (fvcom_xy(ff, 1) - Mobj.lon(coast_nodes)).^2 + ...
    +0147         (fvcom_xy(ff, 2) - Mobj.lat(coast_nodes)).^2);
    +0148     [c, idx] = min(fv_dist);
    +0149     if c > dist_thresh && dist_thresh ~= -1 % -1 is for no distance check
    +0150         if ftbverbose
    +0151             fprintf('\tskipping river %s (%f, %f)\n', fvcom_name{ff}, fvcom_xy(ff, 1), fvcom_xy(ff, 2))
    +0152         end
    +0153         continue
    +0154     else
    +0155         if ftbverbose
    +0156             fprintf('candidate river %s found (%f, %f)... ', fvcom_name{ff}, fvcom_xy(ff, 1), fvcom_xy(ff, 2))
    +0157         end
    +0158     end
    +0159 
    +0160     vc = vc + 1;
    +0161 
    +0162     % We need to make sure the element in which this node occurs does not
    +0163     % have two land boundaries (otherwise the model sometimes just fills up
    +0164     % that element without releasing the water into the adjacent element).
    +0165     
    +0166     % Find the other nodes which are joined to the node we've just found.
    +0167     % We don't need the column to get the other nodes in the element, only
    +0168     % the row is required.
    +0169     [row, ~] = find(Mobj.tri == coast_nodes(idx));
    +0170     
    +0171     if length(row) == 1
    +0172         % This is a bad node because it is a part of only one element. The
    +0173         % rivers need two adjacent elements to work reliably (?). So, we
    +0174         % need to repeat the process above until we find a node that's
    +0175         % connected to two elements. We'll try the other nodes in the
    +0176         % current element before searching the rest of the coastline (which
    +0177         % is computationally expensive).
    +0178         
    +0179         % Remove the current node index from the list of candidates (i.e.
    +0180         % leave only the two other nodes in the element).
    +0181         mask = Mobj.tri(row, :) ~= coast_nodes(idx);
    +0182         n_tri = Mobj.tri(row, mask);
    +0183         
    +0184         % Remove values which aren't coastline values (we don't want to set
    +0185         % the river node to an open water node).
    +0186         n_tri = intersect(n_tri, coast_nodes);
    +0187 
    +0188         % Of the remaining nodes in the element, find the closest one to
    +0189         % the original river location (in fvcom_xy).
    +0190         [~, n_idx] = sort(sqrt( ...
    +0191             (fvcom_xy(ff, 1) - tlon(n_tri)).^2 ...
    +0192             + (fvcom_xy(ff, 2) - tlat(n_tri)).^2));
    +0193 
    +0194         [row_2, ~] = find(Mobj.tri == n_tri(n_idx(1)));
    +0195         if length(n_idx) > 1
    +0196             [row_3, ~] = find(Mobj.tri == n_tri(n_idx(2)));
    +0197         end
    +0198         % Closest first
    +0199         if length(row_2) > 1
    +0200             idx = find(coast_nodes == n_tri(n_idx(1)));
    +0201         % The other one (only if we have more than one node to consider).
    +0202         elseif length(n_idx) > 1 && length(row_3) > 1
    +0203             idx = find(coast_nodes == n_tri(n_idx(2)));
    +0204         % OK, we need to search across all the other coastline nodes.
    +0205         else
    +0206             % TODO: Implement a search of all the other coastline nodes.
    +0207             % My testing indicates that we never get here (at least for the
    +0208             % grids I've tested). I'd be interested to see the mesh which
    +0209             % does get here...
    +0210             continue
    +0211         end
    +0212         
    +0213     end
    +0214 
    +0215     % Add it to the list of valid rivers
    +0216     fv_obc(vc) = coast_nodes(idx);
    +0217 
    +0218     % We are assuming that the river discharge data array y-dimension is
    +0219     % ordered the same as the positions in fvcom_xy. If they are not, then
    +0220     % the discharges for the rivers will be incorrect (i.e. you might put
    +0221     % the Severn discharge somewhere in the Baltic).
    +0222     fvcom_names{vc} = fvcom_name{ff};
    +0223     fv_riv_idx(vc) = ff;
    +0224     fv_flow(:, vc) = polcoms_flow(:, ff);
    +0225     if ftbverbose
    +0226         fprintf('added (%f, %f).\n', Mobj.lon(fv_obc(vc)), Mobj.lat(fv_obc(vc)))
    +0227     end
    +0228 end
    +0229 
    +0230 % Now we've got a list and some of the nodes will be duplicates. Sum the
    +0231 % discharge values assigned to those nodes.
    +0232 fv_uniq_obc = unique(fv_obc);
    +0233 
    +0234 fv_uniq_flow = nan(pc_nt, length(fv_uniq_obc));
    +0235 fv_uniq_names = cell(length(fv_uniq_obc), 1);
    +0236 
    +0237 fv_idx = 1:length(fvcom_names);
    +0238 for nn = 1:length(fv_uniq_obc)
    +0239     
    +0240     dn = fv_idx(fv_obc == fv_uniq_obc(nn));
    +0241     
    +0242     fv_uniq_flow(:, nn) = sum(fv_flow(:, dn), 2);
    +0243     % Concatenate the river names so we know at least which rivers'
    +0244     % discharges have been summed.
    +0245     s = fvcom_names(dn);
    +0246     s = [sprintf('%s-', s{1:end-1}, s{end})];
    +0247     fv_uniq_names{nn} = s(1:end-1); % lose the trailing -.
    +0248 
    +0249 end
    +0250 
    +0251 % Assign the relevant arrays to the Mobj.
    +0252 Mobj.river_nodes = fv_uniq_obc;
    +0253 Mobj.river_flux = fv_uniq_flow;
    +0254 Mobj.river_names = fv_uniq_names;
    +0255 
    +0256 % Create a Modified Julian Day time series starting at January 1st for the
    +0257 % year in Mobj.rivers.year.
    +0258 rtimes = datevec( ...
    +0259     datenum([Mobj.rivers.year, 1, 1, 0, 0, 0]): ...
    +0260     datenum([Mobj.rivers.year, 1, 1, 0, 0, 0]) + pc_nt - 1 ...
    +0261     );
    +0262 Mobj.river_time = nan(pc_nt, 1);
    +0263 for tt = 1:pc_nt
    +0264     Mobj.river_time(tt) = greg2mjulian( ...
    +0265         rtimes(tt, 1), rtimes(tt, 2), rtimes(tt, 3), ...
    +0266         rtimes(tt, 4), rtimes(tt, 5), rtimes(tt, 6) ...
    +0267         );
    +0268 end
    +0269 
    +0270 % Figure to check what's going on with identifying river nodes
    +0271 % figure
    +0272 % plot(fvcom_xy(:, 1), fvcom_xy(:, 2), 'o', 'MarkerFaceColor', 'b')
    +0273 % hold on
    +0274 % plot(Mobj.lon(bnd), Mobj.lat(bnd), 'go', 'MarkerFaceColor', 'g')
    +0275 % axis('equal', 'tight')
    +0276 % plot(Mobj.lon(coast_nodes), Mobj.lat(coast_nodes), 'ro')
    +0277 % plot(Mobj.lon(Mobj.river_nodes), Mobj.lat(Mobj.river_nodes), 'ko', 'MarkerFaceColor', 'k')
    +0278 % text(Mobj.lon(Mobj.river_nodes) + 0.025, Mobj.lat(Mobj.river_nodes) + 0.025, Mobj.river_names)
    +0279 % axis([min(Mobj.lon), max(Mobj.lon), min(Mobj.lat), max(Mobj.lat)])
    +0280 % legend('POLCOMS nodes', 'Grid boundary', 'Land nodes', 'Selected nodes', 'Location', 'NorthOutside', 'Orientation', 'Horizontal')
    +0281 % legend('BoxOff')
    +0282 
    +0283 
    +0284 if ftbverbose
    +0285     fprintf(['end   : ' subname '\n'])
    +0286 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/get_MetUM_forcing.html b/doc/fvcom_prepro/get_MetUM_forcing.html new file mode 100644 index 0000000000000000000000000000000000000000..ea28ad322e351b5bf43e8c8ad4097a788ccac7f4 --- /dev/null +++ b/doc/fvcom_prepro/get_MetUM_forcing.html @@ -0,0 +1,381 @@ + + + + Description of get_MetUM_forcing + + + + + + + + + +
    Home > fvcom_prepro > get_MetUM_forcing.m
    + + + +

    get_MetUM_forcing +

    + +

    PURPOSE ^

    +
    Get the required parameters from the Met Office Unified Model (TM)
    + +

    SYNOPSIS ^

    +
    function data = get_MetUM_forcing(Mobj, modelTime, credentials)
    + +

    DESCRIPTION ^

    +
     Get the required parameters from the Met Office Unified Model (TM)
    + (hereafter MetUM) to use in FVCOM surface forcing.
    +
    + data = get_MetUM_forcing(Mobj, modelTime, credentials)
    +
    + DESCRIPTION:
    +   Using FTP access, extract the necessary parameters to create an FVCOM
    +   forcing file. Requires the air_sea toolbox (see below for where to get
    +   it). Data are sampled four times daily.
    +
    + INPUT:
    +   Mobj - MATLAB mesh object
    +   modelTime - Modified Julian Date start and end times
    +   credentials - struct with fields username and password to access the
    +   FTP server.
    +
    + OUTPUT:
    +   data - struct of the data necessary to force FVCOM. These can be
    +   interpolated onto an unstructured grid in Mobj using grid2fvcom.m.
    +
    + The required parameters which can be obtained are:
    +     - surface_net_downward_shortwave_flux (W m-2)
    +     - surface_downwelling_shortwave_flux_in_air (W m-2)
    +     - surface_net_downward_longwave_flux (W m-2)
    +     - surface_downwelling_longwave_flux_in_air (W m-2)
    +     - surface_upward_sensible_heat_flux (W m-2)
    +     - eastward_wind / x_wind (m s-1)
    +     - northward_wind / y_wind (m s-1)
    +     - surface_upward_latent_heat_flux  (W m-2)
    +     - air_temperature (K)
    +     - relative_humidity (%)
    +     - precipitation_flux (kg m-2 s-1)
    +     - air_pressure_at_sea_level (Pa)
    +
    + In addition to these, the momentum flux is calculated from wind data.
    + Precipitation is converted from kg/m^2/s to m/s. Evaporation is
    + calculated from the mean daily latent heat net flux (lhtfl) at the
    + surface.
    +
    + REQUIRES:
    +   The air_sea toolbox:
    +       http://woodshole.er.usgs.gov/operations/sea-mat/air_sea-html/index.html
    +
    + Author(s)
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2013-05-07 First version.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + +

    SUBFUNCTIONS ^

    + + +

    SOURCE CODE ^

    +
    0001 function data = get_MetUM_forcing(Mobj, modelTime, credentials)
    +0002 % Get the required parameters from the Met Office Unified Model (TM)
    +0003 % (hereafter MetUM) to use in FVCOM surface forcing.
    +0004 %
    +0005 % data = get_MetUM_forcing(Mobj, modelTime, credentials)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %   Using FTP access, extract the necessary parameters to create an FVCOM
    +0009 %   forcing file. Requires the air_sea toolbox (see below for where to get
    +0010 %   it). Data are sampled four times daily.
    +0011 %
    +0012 % INPUT:
    +0013 %   Mobj - MATLAB mesh object
    +0014 %   modelTime - Modified Julian Date start and end times
    +0015 %   credentials - struct with fields username and password to access the
    +0016 %   FTP server.
    +0017 %
    +0018 % OUTPUT:
    +0019 %   data - struct of the data necessary to force FVCOM. These can be
    +0020 %   interpolated onto an unstructured grid in Mobj using grid2fvcom.m.
    +0021 %
    +0022 % The required parameters which can be obtained are:
    +0023 %     - surface_net_downward_shortwave_flux (W m-2)
    +0024 %     - surface_downwelling_shortwave_flux_in_air (W m-2)
    +0025 %     - surface_net_downward_longwave_flux (W m-2)
    +0026 %     - surface_downwelling_longwave_flux_in_air (W m-2)
    +0027 %     - surface_upward_sensible_heat_flux (W m-2)
    +0028 %     - eastward_wind / x_wind (m s-1)
    +0029 %     - northward_wind / y_wind (m s-1)
    +0030 %     - surface_upward_latent_heat_flux  (W m-2)
    +0031 %     - air_temperature (K)
    +0032 %     - relative_humidity (%)
    +0033 %     - precipitation_flux (kg m-2 s-1)
    +0034 %     - air_pressure_at_sea_level (Pa)
    +0035 %
    +0036 % In addition to these, the momentum flux is calculated from wind data.
    +0037 % Precipitation is converted from kg/m^2/s to m/s. Evaporation is
    +0038 % calculated from the mean daily latent heat net flux (lhtfl) at the
    +0039 % surface.
    +0040 %
    +0041 % REQUIRES:
    +0042 %   The air_sea toolbox:
    +0043 %       http://woodshole.er.usgs.gov/operations/sea-mat/air_sea-html/index.html
    +0044 %
    +0045 % Author(s)
    +0046 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0047 %
    +0048 % Revision history:
    +0049 %   2013-05-07 First version.
    +0050 %
    +0051 %==========================================================================
    +0052 subname = 'get_MetUM_forcing';
    +0053 
    +0054 global ftbverbose;
    +0055 if ftbverbose;
    +0056     fprintf('\nbegin : %s \n', subname)
    +0057 end
    +0058 
    +0059 % Get the extent of the model domain (in spherical)
    +0060 if ~Mobj.have_lonlat
    +0061     error('Need spherical coordinates to extract the forcing data')
    +0062 else
    +0063     % Add a 1 degree buffer to make sure the model domain is fully covered
    +0064     % by the extracted data.
    +0065     [dx, dy] = deal(1, 1);
    +0066     extents = [min(Mobj.lon(:))-(2*dx), max(Mobj.lon(:))+(2*dx), min(Mobj.lat(:))-dy, max(Mobj.lat(:))+dy];
    +0067 end
    +0068 
    +0069 nt = modelTime(end) - modelTime(1);
    +0070 if nt > 365
    +0071     error('Can''t (yet) process more than a year at a time.')
    +0072 end
    +0073 
    +0074 [yearStart, monthStart, dayStart] = mjulian2greg(modelTime(1));
    +0075 [yearEnd, monthEnd, dayEnd] = mjulian2greg(modelTime(end));
    +0076 t = modelTime(1):1/4:modelTime(end);
    +0077 
    +0078 if yearEnd ~= yearStart
    +0079     error('Can''t (yet) process across a year boundary.')
    +0080 end
    +0081 
    +0082 if yearStart < 2006 || yearEnd > 2012
    +0083     error('The MetUM repository does not contain data earlier than 2006 and later than 2012')
    +0084 end
    +0085 
    +0086 % For the pre-2006 data, we need to download several files with unique
    +0087 % names. The names are based on the STASH numbers and the date:
    +0088 %   naamYYYYMMDDHH_STASH#_00.pp
    +0089 % The numbers we're interested in are stored in stash.
    +0090 stash = [2, 3, 407, 408, 409, 4222, 9229, 16004];
    +0091 vars = {'uwnd', 'uwnd', 'vwnd', 'vwnd', 'slp_rho', 'slp_theta', ...
    +0092     'surface_air_pressure', 'air_sw', 'air_lw', ...
    +0093     'rhum', 'prate', 'temp_model', 'temp_press'};
    +0094 
    +0095 ns = length(stash);
    +0096 
    +0097 % From where will we be downloading the data?
    +0098 site = 'ftp.ceda.ac.uk';
    +0099 basePath = 'badc/ukmo-um/data/nae/';
    +0100 
    +0101 % Open a remote connection to the FTP site
    +0102 remote = ftp(site, credentials(1), credentials(2));
    +0103 
    +0104 % Depending on the year we're extracting, we need to append different
    +0105 % directories to get the data.
    +0106 for i = 1:nt * 4 % four files per day (at 0000, 0600, 1200 and 1800).
    +0107 
    +0108     [year, month, day, hour] = mjulian2greg(t(i));
    +0109 
    +0110     % Cell array for the files to download.
    +0111     files = cell(0);
    +0112 
    +0113     % Do 2010 first because it straddles the two directories.
    +0114     if year == 2010
    +0115         if month < 11 && day < 4
    +0116             % Use the am data
    +0117             prefix = 'am';
    +0118             URL = sprintf('%sna/%s/%04d/%02d/%02d', basePath, ...
    +0119                 prefix, ...
    +0120                 year, ...
    +0121                 month, ...
    +0122                 day);
    +0123             for f = 1:ns
    +0124                 files{f} = sprintf('na%s%04d%02d%02d%02d_%05d_00.pp', ...
    +0125                     prefix, ...
    +0126                     year, ...
    +0127                     month, ...
    +0128                     day, ...
    +0129                     hour, ...
    +0130                     stash(f));
    +0131             end
    +0132         elseif month > 11 && day > 3
    +0133             % Use the mn data
    +0134             prefix = 'mn';
    +0135             URL = sprintf('%sna/%s/%04d/%02d/%02d', basePath, ...
    +0136                 prefix, ...
    +0137                 year, ...
    +0138                 month, ...
    +0139                 day);
    +0140             files = sprintf('%s_%04d%02d%02d%02d_s00.pp', ...
    +0141                 prefix, ...
    +0142                 year, ...
    +0143                 month, ...
    +0144                 day, ...
    +0145                 hour);
    +0146         end
    +0147 
    +0148     % Check the 2006 data are from the 7th November onwards.
    +0149     elseif year == 2006
    +0150         if month < 11 
    +0151             if day < 7
    +0152                 error('The MetUM repository does not contain data earlier than 7th November, 2006')
    +0153             else
    +0154                 prefix = 'am';
    +0155                 URL = sprintf('%sna/%s/%04d/%02d/%02d', basePath, ...
    +0156                     prefix, ...
    +0157                     year, ...
    +0158                     month, ...
    +0159                     day);
    +0160                 for f = 1:ns
    +0161                     files{f} = sprintf('na%s%04d%02d%02d%02d_%05d_00.pp', ...
    +0162                         prefix, ...
    +0163                         year, ...
    +0164                         month, ...
    +0165                         day, ...
    +0166                         hour, ...
    +0167                         stash(f));
    +0168                 end
    +0169             end
    +0170         end
    +0171 
    +0172     % Check the 2012 data are from before the 17th January, 2012.
    +0173     elseif year == 2012
    +0174         if month > 1
    +0175             error('The MetUM repository does not contain data later than 17th January, 2012')
    +0176         elseif month == 1
    +0177             if day > 17
    +0178                 error('The MetUM repository does not contain data later than 17th January, 2012')
    +0179             else
    +0180                 prefix = 'mn';
    +0181             URL = sprintf('%sna/%s/%04d/%02d/%02d', basePath, ...
    +0182                     prefix, ...
    +0183                     year, ...
    +0184                     month, ...
    +0185                     day);
    +0186                 files = sprintf('%s_%04d%02d%02d%02d_s00.pp', ...
    +0187                     prefix, ...
    +0188                     year, ...
    +0189                     month, ...
    +0190                     day, ...
    +0191                     hour);
    +0192             end
    +0193         end
    +0194 
    +0195     % Pre-2010 files.
    +0196     elseif year < 2010
    +0197         % Use the am data.
    +0198         prefix = 'am';
    +0199             URL = sprintf('%sna/%s/%04d/%02d/%02d', basePath, ...
    +0200             prefix, ...
    +0201             year, ...
    +0202             month, ...
    +0203             day);
    +0204             for f = 1:ns
    +0205                 files{f} = sprintf('na%s%04d%02d%02d%02d_%05d_00.pp', ...
    +0206                     prefix, ...
    +0207                     year, ...
    +0208                     month, ...
    +0209                     day, ...
    +0210                     hour, ...
    +0211                     stash(f));
    +0212             end
    +0213 
    +0214     % Post-2010 files.
    +0215     elseif year > 2010
    +0216         % Use the mn data.
    +0217         prefix = 'mn';
    +0218             URL = sprintf('%sna/%s/%04d/%02d/%02d', basePath, ...
    +0219             prefix, ...
    +0220             year, ...
    +0221             month, ...
    +0222             day);
    +0223         files = sprintf('%s_%04d%02d%02d%02d_s00.pp', ...
    +0224             prefix, ...
    +0225             year, ...
    +0226             month, ...
    +0227             day, ...
    +0228             hour);
    +0229     end
    +0230 
    +0231     fprintf('%s: %s\n', URL, files{1})
    +0232 end
    +0233 
    +0234 % Close the connection to the FTP server.
    +0235 close(remote)
    +0236 
    +0237 if ftbverbose
    +0238     fprintf('end   : %s \n', subname)
    +0239 end
    +0240 
    +0241 
    +0242 function ftpdata = get_badc_data(remote, URL, files)
    +0243 % Child function to do the actual downloading from the BADC site via FTP.
    +0244 %
    +0245 % Inputs:
    +0246 %
    +0247 %   remote - FTP object
    +0248 %   URL - path to the files to download
    +0249 %   files - cell array of a file or files to download
    +0250 %
    +0251 % Outputs:
    +0252 %
    +0253 %   noidea...
    +0254 
    +0255 if ~iscell(files)
    +0256     error('Provide a cell array of files to download')
    +0257 end
    +0258 
    +0259 cd(remote, URL);
    +0260 nf = length(files);
    +0261 for i = 1:nf
    +0262     tmpdata = mget(remote, files{i});
    +0263     ftpdata.(vars{i}).data = 
    +0264 end
    +0265 
    +0266 
    +0267 function pp2nc(file, convsh)
    +0268 % Child function to call the convsh program to convert the obscure pp
    +0269 % format to a sensible NetCDF which we can more easily read.
    +0270 
    +0271 % Assume convsh is in /usr/local unless otherwise told.
    +0272 if nargin == 1
    +0273     convsh = '/usr/local/bin/convsh';
    +0274 end
    +0275 
    +0276 if exist(file, 'file') ~= 2
    +0277     error('File %s not found', file)
    +0278 end
    +0279 
    +0280 [path, name, ext] = fileparts(file);
    +0281 out = fullfile(path, [name, '.nc']);
    +0282 
    +0283 system([convsh, '-i ',
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/get_NCEP_forcing.html b/doc/fvcom_prepro/get_NCEP_forcing.html index a0baa8dbff65cd059c9c7400c5535146c03f2538..e4654c54af7d9e544531ffacbc4d9543553b8ff4 100644 --- a/doc/fvcom_prepro/get_NCEP_forcing.html +++ b/doc/fvcom_prepro/get_NCEP_forcing.html @@ -39,13 +39,15 @@ below for where to get them). INPUT: - Mobj - MATLAB mesh object + Mobj - MATLAB mesh object. Must contain fields: + lon, lat - array of longitude and latitudes. + have_lonlat - boolean to signify whether coordinates are spherical + or cartesian. modelTime - Modified Julian Date start and end times OUTPUT: data - struct of the data necessary to force FVCOM. These can be - interpolated onto an unstructured grid in Mobj using - grid2fvcom_U10V10.m. + interpolated onto an unstructured grid in Mobj using grid2fvcom.m. The parameters which can be obtained from the NCEP data are: - u wind component (uwnd) @@ -55,6 +57,7 @@ - Air temperature (air) - Relative humidity (rhum) - Precipitation rate (prate) + - Evaporation rate (pevpr) - Sea level pressure (slp) - Latent heat flux (lhtfl) - Surface heat flux (shtfl) @@ -65,19 +68,28 @@ calculated from the mean daily latent heat net flux (lhtfl) at the surface. + EXAMPLE USAGE: + forcing = get_NCEP_forcing(Mobj, [51345, 51376]); + REQUIRES: The air_sea toolbox: http://woodshole.er.usgs.gov/operations/sea-mat/air_sea-html/index.html The OPeNDAP toolbox: http://www.opendap.org/pub/contributed/source/ml-toolbox/ - Author(s) Pierre Cazenave (Plymouth Marine Laboratory) Ricardo Torres (Plymouth Marine Laboratory) Revision history: 2012-10-31 First version based on get_NCEP_L4.m. + 2013-02-14 Add support for the native OPeNDAP functions in the MATLAB + netcdf tools. Also fix the value of data.P_E.data to be only the + evaporation. The evaporation available from NCEP in prate is in units + of W m^{-2} whereas FVCOM expects ms^{-1}. Rather than convert from W + m^{-2} to ms^{-1}, use the latent heat flux at the surface with the + density of water and the latent heat of vaporisation to estimate + evaporation rate in ms^{-1}. ========================================================================== @@ -107,259 +119,355 @@ This function is called by: 0011 % below for where to get them). 0012 % 0013 % INPUT: -0014 % Mobj - MATLAB mesh object -0015 % modelTime - Modified Julian Date start and end times -0016 % -0017 % OUTPUT: -0018 % data - struct of the data necessary to force FVCOM. These can be -0019 % interpolated onto an unstructured grid in Mobj using -0020 % grid2fvcom_U10V10.m. -0021 % -0022 % The parameters which can be obtained from the NCEP data are: -0023 % - u wind component (uwnd) -0024 % - v wind component (vwnd) -0025 % - Net longwave radiation surface (nlwrs) -0026 % - Net shortwave radiation surface (nswrs) -0027 % - Air temperature (air) -0028 % - Relative humidity (rhum) -0029 % - Precipitation rate (prate) -0030 % - Sea level pressure (slp) -0031 % - Latent heat flux (lhtfl) -0032 % - Surface heat flux (shtfl) -0033 % - Potential evaporation rate (pevpr) -0034 % -0035 % In addition to these, the momentum flux is calculated from wind data. -0036 % Precipitation is converted from kg/m^2/s to m/s. Evaporation is -0037 % calculated from the mean daily latent heat net flux (lhtfl) at the -0038 % surface. -0039 % -0040 % REQUIRES: -0041 % The air_sea toolbox: -0042 % http://woodshole.er.usgs.gov/operations/sea-mat/air_sea-html/index.html -0043 % The OPeNDAP toolbox: -0044 % http://www.opendap.org/pub/contributed/source/ml-toolbox/ +0014 % Mobj - MATLAB mesh object. Must contain fields: +0015 % lon, lat - array of longitude and latitudes. +0016 % have_lonlat - boolean to signify whether coordinates are spherical +0017 % or cartesian. +0018 % modelTime - Modified Julian Date start and end times +0019 % +0020 % OUTPUT: +0021 % data - struct of the data necessary to force FVCOM. These can be +0022 % interpolated onto an unstructured grid in Mobj using grid2fvcom.m. +0023 % +0024 % The parameters which can be obtained from the NCEP data are: +0025 % - u wind component (uwnd) +0026 % - v wind component (vwnd) +0027 % - Net longwave radiation surface (nlwrs) +0028 % - Net shortwave radiation surface (nswrs) +0029 % - Air temperature (air) +0030 % - Relative humidity (rhum) +0031 % - Precipitation rate (prate) +0032 % - Evaporation rate (pevpr) +0033 % - Sea level pressure (slp) +0034 % - Latent heat flux (lhtfl) +0035 % - Surface heat flux (shtfl) +0036 % - Potential evaporation rate (pevpr) +0037 % +0038 % In addition to these, the momentum flux is calculated from wind data. +0039 % Precipitation is converted from kg/m^2/s to m/s. Evaporation is +0040 % calculated from the mean daily latent heat net flux (lhtfl) at the +0041 % surface. +0042 % +0043 % EXAMPLE USAGE: +0044 % forcing = get_NCEP_forcing(Mobj, [51345, 51376]); 0045 % -0046 % -0047 % Author(s) -0048 % Pierre Cazenave (Plymouth Marine Laboratory) -0049 % Ricardo Torres (Plymouth Marine Laboratory) -0050 % -0051 % Revision history: -0052 % 2012-10-31 First version based on get_NCEP_L4.m. -0053 % -0054 %========================================================================== -0055 -0056 subname = 'get_NCEP_forcing'; -0057 -0058 global ftbverbose; -0059 if(ftbverbose); -0060 fprintf('\n') -0061 fprintf(['begin : ' subname '\n']) -0062 end -0063 -0064 % Get the extent of the model domain (in spherical) -0065 if ~Mobj.have_lonlat -0066 error('Need spherical coordinates to extract the forcing data') -0067 else -0068 % Add a buffer of one grid cell in latitude and two in longitude to -0069 % make sure the model domain is fully covered by the extracted data. -0070 [dx, dy] = deal(2.5, 2.5); % NCEP resolution in degrees -0071 extents = [min(Mobj.lon(:))-(2*dx), max(Mobj.lon(:))+(2*dx), min(Mobj.lat(:))-dy, max(Mobj.lat(:))+dy]; -0072 end -0073 -0074 if modelTime(end) - modelTime(1) > 365 -0075 error('Can''t (yet) process more than a year at a time.') -0076 end -0077 -0078 yearStart = mjulian2greg(modelTime(1)); -0079 yearEnd = mjulian2greg(modelTime(end)); -0080 if yearEnd ~= yearStart -0081 error('Can''t (yet) process across a year boundary.') -0082 else -0083 year = yearEnd; -0084 end -0085 -0086 % Set up a struct of the NCEP remote locations in which we're interested. -0087 ncep.uwnd = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/uwnd.10m.gauss.',num2str(year),'.nc']; -0088 ncep.vwnd = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/vwnd.10m.gauss.',num2str(year),'.nc']; -0089 ncep.nlwrs = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/nlwrs.sfc.gauss.',num2str(year),'.nc']; -0090 ncep.nswrs = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/nswrs.sfc.gauss.',num2str(year),'.nc']; -0091 ncep.air = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/air.2m.gauss.',num2str(year),'.nc']; -0092 ncep.rhum = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface/rhum.sig995.',num2str(year),'.nc']; -0093 ncep.prate = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/prate.sfc.gauss.',num2str(year),'.nc']; -0094 ncep.slp = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface/slp.',num2str(year),'.nc']; -0095 ncep.lhtfl = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/lhtfl.sfc.gauss.',num2str(year),'.nc']; -0096 ncep.shtfl = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/shtfl.sfc.gauss.',num2str(year),'.nc']; -0097 ncep.pevpr = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/pevpr.sfc.gauss.',num2str(year),'.nc']; -0098 -0099 fields = fieldnames(ncep); -0100 -0101 for aa=1:length(fields) -0102 data.(fields{aa}).data = []; -0103 data.(fields{aa}).time = []; -0104 data.(fields{aa}).lat = []; -0105 data.(fields{aa}).lon = []; -0106 data_attributes.(fields{aa}) = []; -0107 -0108 % Get the data time and convert to Modified Julian Day. -0109 data_time = loaddap([ncep.(fields{aa}),'?time']); -0110 data_attributes.(fields{aa}) = loaddap('-A',[ncep.(fields{aa})]); -0111 timevec = datevec((data_time.time)/24+365); -0112 data.time = greg2mjulian(timevec(:,1), timevec(:,2), timevec(:,3), ... -0113 timevec(:,4), timevec(:,5), timevec(:,6)); -0114 % Clip the time to the given range -0115 data_time_mask = data.time >= modelTime(1) & data.time <= modelTime(end); -0116 data_time_idx = 1:size(data.time,1); -0117 data_time_idx = data_time_idx(data_time_mask); -0118 data.time = data.time(data_time_mask); +0046 % REQUIRES: +0047 % The air_sea toolbox: +0048 % http://woodshole.er.usgs.gov/operations/sea-mat/air_sea-html/index.html +0049 % The OPeNDAP toolbox: +0050 % http://www.opendap.org/pub/contributed/source/ml-toolbox/ +0051 % +0052 % Author(s) +0053 % Pierre Cazenave (Plymouth Marine Laboratory) +0054 % Ricardo Torres (Plymouth Marine Laboratory) +0055 % +0056 % Revision history: +0057 % 2012-10-31 First version based on get_NCEP_L4.m. +0058 % 2013-02-14 Add support for the native OPeNDAP functions in the MATLAB +0059 % netcdf tools. Also fix the value of data.P_E.data to be only the +0060 % evaporation. The evaporation available from NCEP in prate is in units +0061 % of W m^{-2} whereas FVCOM expects ms^{-1}. Rather than convert from W +0062 % m^{-2} to ms^{-1}, use the latent heat flux at the surface with the +0063 % density of water and the latent heat of vaporisation to estimate +0064 % evaporation rate in ms^{-1}. +0065 % +0066 %========================================================================== +0067 +0068 subname = 'get_NCEP_forcing'; +0069 +0070 global ftbverbose; +0071 if ftbverbose +0072 fprintf('\nbegin : %s\n', subname) +0073 end +0074 +0075 % Get the extent of the model domain (in spherical) +0076 if ~Mobj.have_lonlat +0077 error('Need spherical coordinates to extract the forcing data') +0078 else +0079 % Add a buffer of one grid cell in latitude and two in longitude to +0080 % make sure the model domain is fully covered by the extracted data. +0081 [dx, dy] = deal(2.5, 2.5); % NCEP resolution in degrees +0082 extents = [min(Mobj.lon(:))-(2*dx), max(Mobj.lon(:))+(2*dx), min(Mobj.lat(:))-dy, max(Mobj.lat(:))+dy]; +0083 end +0084 +0085 if modelTime(end) - modelTime(1) > 365 +0086 error('Can''t (yet) process more than a year at a time.') +0087 end +0088 +0089 yearStart = mjulian2greg(modelTime(1)); +0090 yearEnd = mjulian2greg(modelTime(end)); +0091 if yearEnd ~= yearStart +0092 error('Can''t (yet) process across a year boundary.') +0093 else +0094 year = yearEnd; +0095 end +0096 +0097 % Set up a struct of the NCEP remote locations in which we're interested. +0098 ncep.uwnd = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/uwnd.10m.gauss.',num2str(year),'.nc']; +0099 ncep.vwnd = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/vwnd.10m.gauss.',num2str(year),'.nc']; +0100 ncep.nlwrs = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/nlwrs.sfc.gauss.',num2str(year),'.nc']; +0101 ncep.nswrs = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/nswrs.sfc.gauss.',num2str(year),'.nc']; +0102 ncep.air = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/air.2m.gauss.',num2str(year),'.nc']; +0103 ncep.rhum = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface/rhum.sig995.',num2str(year),'.nc']; +0104 ncep.prate = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/prate.sfc.gauss.',num2str(year),'.nc']; +0105 ncep.slp = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface/slp.',num2str(year),'.nc']; +0106 ncep.lhtfl = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/lhtfl.sfc.gauss.',num2str(year),'.nc']; +0107 ncep.shtfl = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/shtfl.sfc.gauss.',num2str(year),'.nc']; +0108 ncep.pevpr = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/pevpr.sfc.gauss.',num2str(year),'.nc']; +0109 +0110 % The fields below can be used to create the net shortwave and longwave +0111 % fluxes if the data you're using don't include net fluxes. Subtract the +0112 % downward from upward fluxes to get net fluxes. +0113 % ncep.dswrf = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/dswrf.sfc.gauss.',num2str(year),'.nc']; +0114 % ncep.uswrf = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/uswrf.sfc.gauss.',num2str(year),'.nc']; +0115 % ncep.dlwrf = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/dlwrf.sfc.gauss.',num2str(year),'.nc']; +0116 % ncep.ulwrf = ['http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface_gauss/ulwrf.sfc.gauss.',num2str(year),'.nc']; +0117 +0118 fields = fieldnames(ncep); 0119 -0120 % Check the times -0121 %[yyyy,mm,dd,hh,MM,ss] = mjulian2greg(data.time(1)) -0122 %[yyyy,mm,dd,hh,MM,ss] = mjulian2greg(data.time(end)) -0123 -0124 % Clip the data to the model domain -0125 data_lon = loaddap([ncep.(fields{aa}),'?lon']); -0126 % If the extents are negative in longitude, we need to extract the NCEP -0127 % data in two goes, once for the end of the grid (west of Greenwich), -0128 % once for the beginning (east of Greenwich), and then stick the two -0129 % bits together. -0130 clear index_lon index_lat -0131 if extents(1) < 0 && extents(2) < 0 -0132 % This is OK, we can just shunt the values by 360. -0133 extents(1) = extents(1) + 360; -0134 extents(2) = extents(2) + 360; -0135 index_lon = find(data_lon.lon > extents(1) & data_lon.lon < extents(2)); -0136 elseif extents(1) < 0 && extents(2) > 0 -0137 % This is the tricky one. We'll do two passes to extract the -0138 % western chunk first (extents(1)+360 to 360), then the eastern -0139 % chunk (0-extents(2)) -0140 index_lon{1} = find(data_lon.lon >= extents(1) + 360); -0141 index_lon{2} = find(data_lon.lon <= extents(2)); -0142 else -0143 % Dead easy, we're in the eastern hemisphere, so nothing too -0144 % strenuous here -0145 index_lon = find(data_lon.lon > extents(1) & data_lon.lon < extents(2)); -0146 end -0147 -0148 % Latitude is much more straightforward -0149 data_lat = loaddap([ncep.(fields{aa}),'?lat']); -0150 index_lat = find(data_lat.lat > extents(3) & data_lat.lat < extents(4)); +0120 for aa = 1:length(fields) +0121 data.(fields{aa}).data = []; +0122 data.(fields{aa}).time = []; +0123 data.(fields{aa}).lat = []; +0124 data.(fields{aa}).lon = []; +0125 data_attributes.(fields{aa}) = []; +0126 +0127 % Depending on the MATLAB version, either use the native netcdf +0128 % libraries to load the OPeNDAP data, otherwise we need the relevant +0129 % third-party toolbox. +0130 out = ver('MATLAB'); +0131 if str2double(out.Version) > 7.13 +0132 +0133 %ncid_info = ncinfo(ncep.(fields{aa})); +0134 ncid = netcdf.open(ncep.(fields{aa})); +0135 +0136 % If you don't know what it contains, start by using the +0137 % 'netcdf.inq' operation: +0138 %[numdims,numvars,numglobalatts,unlimdimid] = netcdf.inq(ncid); +0139 varid = netcdf.inqVarID(ncid, 'time'); +0140 data_time.time = netcdf.getVar(ncid, varid, 'double'); +0141 varid = netcdf.inqVarID(ncid, (fields{aa})); +0142 +0143 data_attributes.(fields{aa}).(fields{aa}).scale_factor = ... +0144 netcdf.getAtt(ncid,varid,'scale_factor','double'); +0145 data_attributes.(fields{aa}).(fields{aa}).add_offset = ... +0146 netcdf.getAtt(ncid,varid,'add_offset','double'); +0147 varid = netcdf.inqVarID(ncid,'lon'); +0148 data_lon.lon = netcdf.getVar(ncid,varid,'double'); +0149 varid = netcdf.inqVarID(ncid,'lat'); +0150 data_lat.lat = netcdf.getVar(ncid,varid,'double'); 0151 -0152 % Get the data -0153 if iscell(index_lon) -0154 % We need to do each half and merge them -0155 eval(['data1_west.(fields{aa}) = loaddap(''', ncep.(fields{aa}),'?',... -0156 fields{aa},'[', num2str(min(data_time_idx)-1),':',... -0157 num2str(max(data_time_idx)-1), '][',... -0158 num2str(min(index_lat)-1), ':', num2str(max(index_lat)-1),... -0159 '][', num2str(min(index_lon{1})-1), ':',... -0160 num2str(length(data_lon.lon)-1), ']'');']); -0161 eval(['data1_east.(fields{aa}) = loaddap(''', ncep.(fields{aa}),'?',... -0162 fields{aa}, '[', num2str(min(data_time_idx)-1),':',... -0163 num2str(max(data_time_idx)-1), '][',... -0164 num2str(min(index_lat)-1), ':', num2str(max(index_lat)-1),... -0165 '][', '0', ':', num2str(max(index_lon{2})-1), ']'');']); -0166 % Merge the two sets of data together -0167 structfields = fieldnames(data1_west.(fields{aa}).(fields{aa})); -0168 for ii=1:length(structfields) -0169 switch structfields{ii} -0170 case 'lon' -0171 % Only the longitude and the actual data need sticking -0172 % together, but each must be done along a different -0173 % axis (lon is a vector, the data is an array). -0174 data1.(fields{aa}).(fields{aa}).(structfields{ii}) = ... -0175 [data1_west.(fields{aa}).(fields{aa}).(structfields{ii});data1_east.(fields{aa}).(fields{aa}).(structfields{ii})]; -0176 case fields{aa} -0177 % This is the actual data -0178 data1.(fields{aa}).(fields{aa}).(structfields{ii}) = ... -0179 [data1_west.(fields{aa}).(fields{aa}).(structfields{ii}),data1_east.(fields{aa}).(fields{aa}).(structfields{ii})]; -0180 otherwise -0181 % Assume the data are the same in both arrays. A simple -0182 % check of the range of values in the difference -0183 % between the two arrays should show whether they're -0184 % the same or not. If they are, use the western values, -0185 % otherwise, warn about the differences. It might be -0186 % the data are relatively unimportant anyway (i.e. not -0187 % used later on). -0188 try -0189 tdata = data1_west.(fields{aa}).(fields{aa}).(structfields{ii}) - data1_east.(fields{aa}).(fields{aa}).(structfields{ii}); -0190 if range(tdata(:)) == 0 -0191 % They're the same data -0192 data1.(fields{aa}).(fields{aa}).(structfields{ii}) = ... -0193 data1_west.(fields{aa}).(fields{aa}).(structfields{ii}); -0194 else -0195 warning('Unexpected data field and the west and east halves don''t match. Skipping.') -0196 end -0197 catch -0198 warning('Unexpected data field and the west and east halves don''t match. Skipping.') -0199 end -0200 clear tdata -0201 end -0202 end -0203 else -0204 % We have a straightforward data extraction -0205 eval(['data1.(fields{aa}) = loaddap(''', ncep.(fields{aa}),'?',... -0206 fields{aa}, '[', num2str(min(data_time_idx)-1),':',... -0207 num2str(max(data_time_idx)-1), '][',... -0208 num2str(min(index_lat)-1), ':', num2str(max(index_lat)-1),... -0209 '][', num2str(min(index_lon)-1), ':',... -0210 num2str(max(index_lon)-1), ']'');']); -0211 end -0212 -0213 datatmp = squeeze(data1.(fields{aa}).(fields{aa}).(fields{aa})); -0214 datatmp = (datatmp * data_attributes.(fields{aa}).(fields{aa}).scale_factor) + data_attributes.(fields{aa}).(fields{aa}).add_offset; -0215 -0216 data.(fields{aa}).data = cat(1, data.(fields{aa}).data, datatmp); -0217 data.(fields{aa}).time = cat(1, data.(fields{aa}).time, squeeze(data1.(fields{aa}).(fields{aa}).time)); -0218 data.(fields{aa}).lat = squeeze(data1.(fields{aa}).(fields{aa}).lat); -0219 data.(fields{aa}).lon = squeeze(data1.(fields{aa}).(fields{aa}).lon); -0220 end -0221 -0222 % Now we have some data, we need to create some additional parameters -0223 % required by FVCOM. +0152 timevec = datevec((data_time.time)/24+365); +0153 +0154 else +0155 % We'll use the third-party OPeNDAP toolbox. +0156 data_time = loaddap([ncep.(fields{aa}),'?time']); +0157 data_attributes.(fields{aa}) = loaddap('-A',[ncep.(fields{aa})]); +0158 timevec = datevec((data_time.time)/24+365); +0159 +0160 % Clip the data to the model domain +0161 data_lon = loaddap([ncep.(fields{aa}),'?lon']); +0162 % If the extents are negative in longitude, we need to extract the NCEP +0163 data_lat = loaddap([ncep.(fields{aa}),'?lat']); +0164 end +0165 +0166 % Get the data time and convert to Modified Julian Day. +0167 data.time = greg2mjulian(timevec(:,1), timevec(:,2), timevec(:,3), ... +0168 timevec(:,4), timevec(:,5), timevec(:,6)); +0169 % Clip the time to the given range +0170 data_time_mask = data.time >= modelTime(1) & data.time <= modelTime(end); +0171 data_time_idx = 1:size(data.time,1); +0172 data_time_idx = data_time_idx(data_time_mask); +0173 data.time = data.time(data_time_mask); +0174 +0175 % Check the times +0176 %[yyyy,mm,dd,hh,MM,ss] = mjulian2greg(data.time(1)) +0177 %[yyyy,mm,dd,hh,MM,ss] = mjulian2greg(data.time(end)) +0178 % Get the data in two goes, once for the end of the grid (west of +0179 % Greenwich), once for the beginning (east of Greenwich), and then +0180 % stick the two bits together. +0181 clear index_lon index_lat +0182 if extents(1) < 0 && extents(2) < 0 +0183 % This is OK, we can just shunt the values by 360. +0184 extents(1) = extents(1) + 360; +0185 extents(2) = extents(2) + 360; +0186 index_lon = find(data_lon.lon > extents(1) & data_lon.lon < extents(2)); +0187 elseif extents(1) < 0 && extents(2) > 0 +0188 % This is the tricky one. We'll do two passes to extract the +0189 % western chunk first (extents(1)+360 to 360), then the eastern +0190 % chunk (0-extents(2)) +0191 index_lon{1} = find(data_lon.lon >= extents(1) + 360); +0192 index_lon{2} = find(data_lon.lon <= extents(2)); +0193 else +0194 % Dead easy, we're in the eastern hemisphere, so nothing too +0195 % strenuous here +0196 index_lon = find(data_lon.lon > extents(1) & data_lon.lon < extents(2)); +0197 end +0198 +0199 % Latitude is much more straightforward +0200 index_lat = find(data_lat.lat > extents(3) & data_lat.lat < extents(4)); +0201 data.(fields{aa}).lat = data_lat.lat(index_lat); +0202 +0203 % Get the data +0204 if iscell(index_lon) +0205 data.(fields{aa}).lon = data_lon.lon(cat(1,index_lon{:})); +0206 +0207 if str2double(out.Version) > 7.13 +0208 % varidlon = netcdf.inqVarID(ncid,'lon'); +0209 % varidtime = netcdf.inqVarID(ncid,'time'); +0210 % varidlat = netcdf.inqVarID(ncid,'lat'); +0211 +0212 varid = netcdf.inqVarID(ncid,(fields{aa})); +0213 % [varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varid); +0214 % [~,length1] = netcdf.inqDim(ncid,dimids(1)) +0215 % [~,length2] = netcdf.inqDim(ncid,dimids(2)) +0216 % [~,length3] = netcdf.inqDim(ncid,dimids(3)) +0217 start=[min(index_lon{1})-1,min(index_lat)-1,min(data_time_idx)-1]; +0218 count=[length(index_lon{1}),length(index_lat),length(data_time_idx)]; +0219 data1_west.(fields{aa}).(fields{aa}) = netcdf.getVar(ncid,varid,start,count,'double'); +0220 start=[min(index_lon{2})-1,min(index_lat)-1,min(data_time_idx)-1]; +0221 count=[length(index_lon{2}),length(index_lat),length(data_time_idx)]; +0222 data1_east.(fields{aa}).(fields{aa}) = netcdf.getVar(ncid,varid,start,count,'double'); +0223 data1.(fields{aa}).(fields{aa}).(fields{aa})=cat(1,data1_west.(fields{aa}).(fields{aa}), data1_east.(fields{aa}).(fields{aa})); 0224 -0225 % Convert precipitation from kg/m^2/s to m/s (required by FVCOM) by -0226 % dividing by freshwater density (kg/m^3). -0227 data.prate.data = data.prate.data/1000; -0228 -0229 % Evaporation can be approximated by: -0230 % -0231 % E(m/s) = lhtfl/Llv/rho -0232 % -0233 % where: -0234 % -0235 % lhtfl = "Mean daily latent heat net flux at the surface" -0236 % Llv = Latent heat of vaporization (approx to 2.5*10^6 J kg^-1) -0237 % rho = 1025 kg/m^3 -0238 % -0239 Llv = 2.5*10^6; -0240 rho = 1025; % using a typical value for seawater. -0241 Et = data.lhtfl.data/Llv/rho; -0242 data.P_E.data = data.prate.data-Et; -0243 -0244 % Calculate the momentum flux -0245 WW = data.uwnd.data + data.vwnd.data * 1i; -0246 data.tau.data = stresslp(abs(WW),10); -0247 [data.tx.data,data.ty.data] = wstress(data.uwnd.data,data.vwnd.data,10); -0248 data.tx.data=reshape(data.tx.data*0.1, size(data.uwnd.data)); % dyn/cm^2 to N/m^2 -0249 data.ty.data=reshape(data.ty.data*0.1, size(data.uwnd.data)); % dyn/cm^2 to N/m^2 -0250 -0251 % Get the fields we need for the subsequent interpolation -0252 data.lon = data.uwnd.lon; -0253 data.lon(data.lon > 180) = data.lon(data.lon > 180) - 360; -0254 data.lat = data.uwnd.lat; -0255 -0256 % Have a look at some data. -0257 % [X, Y] = meshgrid(data.lon, data.lat); -0258 % for i=1:size(data.uwnd.data, 3) -0259 % figure(1) -0260 % clf -0261 % uv = sqrt(data.uwnd.data(:, :, i).^2 + data.vwnd.data(:, :, i).^2); -0262 % pcolor(X, Y, uv) -0263 % shading flat -0264 % axis('equal','tight') -0265 % pause(0.1) -0266 % end -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +0225 else +0226 % We need to do each half and merge them +0227 eval(['data1_west.(fields{aa}) = loaddap(''', ncep.(fields{aa}),'?',... +0228 fields{aa},'[', num2str(min(data_time_idx)-1),':',... +0229 num2str(max(data_time_idx)-1), '][',... +0230 num2str(min(index_lat)-1), ':', num2str(max(index_lat)-1),... +0231 '][', num2str(min(index_lon{1})-1), ':',... +0232 num2str(length(data_lon.lon)-1), ']'');']); +0233 eval(['data1_east.(fields{aa}) = loaddap(''', ncep.(fields{aa}),'?',... +0234 fields{aa}, '[', num2str(min(data_time_idx)-1),':',... +0235 num2str(max(data_time_idx)-1), '][',... +0236 num2str(min(index_lat)-1), ':', num2str(max(index_lat)-1),... +0237 '][', '0', ':', num2str(max(index_lon{2})-1), ']'');']); +0238 % Merge the two sets of data together +0239 structfields = fieldnames(data1_west.(fields{aa}).(fields{aa})); +0240 for ii=1:length(structfields) +0241 switch structfields{ii} +0242 case 'lon' +0243 % Only the longitude and the actual data need +0244 % sticking together, but each must be done along a +0245 % different axis (lon is a vector, the data is an +0246 % array). +0247 data1.(fields{aa}).(fields{aa}).(structfields{ii}) = ... +0248 [data1_west.(fields{aa}).(fields{aa}).(structfields{ii});data1_east.(fields{aa}).(fields{aa}).(structfields{ii})]; +0249 case fields{aa} +0250 % This is the actual data +0251 data1.(fields{aa}).(fields{aa}).(structfields{ii}) = ... +0252 [data1_west.(fields{aa}).(fields{aa}).(structfields{ii}),data1_east.(fields{aa}).(fields{aa}).(structfields{ii})]; +0253 otherwise +0254 % Assume the data are the same in both arrays. A +0255 % simple check of the range of values in the +0256 % difference between the two arrays should show +0257 % whether they're the same or not. If they are, use +0258 % the western values, otherwise, warn about the +0259 % differences. It might be the data are relatively +0260 % unimportant anyway (i.e. not used later on). +0261 try +0262 tdata = data1_west.(fields{aa}).(fields{aa}).(structfields{ii}) - data1_east.(fields{aa}).(fields{aa}).(structfields{ii}); +0263 if range(tdata(:)) == 0 +0264 % They're the same data +0265 data1.(fields{aa}).(fields{aa}).(structfields{ii}) = ... +0266 data1_west.(fields{aa}).(fields{aa}).(structfields{ii}); +0267 else +0268 warning('Unexpected data field and the west and east halves don''t match. Skipping.') +0269 end +0270 catch +0271 warning('Unexpected data field and the west and east halves don''t match. Skipping.') +0272 end +0273 clear tdata +0274 end +0275 end +0276 end +0277 else +0278 % We have a straightforward data extraction +0279 data.(fields{aa}).lon = data_lon.lon(index_lon); +0280 +0281 if str2double(out.Version) > 7.13 +0282 varid = netcdf.inqVarID(ncid,(fields{aa})); +0283 % [varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varid); +0284 % [~,length1] = netcdf.inqDim(ncid,dimids(1)) +0285 % [~,length2] = netcdf.inqDim(ncid,dimids(2)) +0286 % [~,length3] = netcdf.inqDim(ncid,dimids(3)) +0287 start=[min(index_lon)-1,min(index_lat)-1,min(data_time_idx)-1]; +0288 count=[length(index_lon),length(index_lat),length(data_time_idx)]; +0289 data1.(fields{aa}).(fields{aa}).(fields{aa}) = netcdf.getVar(ncid,varid,start,count,'double'); +0290 +0291 else +0292 eval(['data1.(fields{aa}) = loaddap(''', ncep.(fields{aa}),'?',... +0293 fields{aa}, '[', num2str(min(data_time_idx)-1),':',... +0294 num2str(max(data_time_idx)-1), '][',... +0295 num2str(min(index_lat)-1), ':', num2str(max(index_lat)-1),... +0296 '][', num2str(min(index_lon)-1), ':',... +0297 num2str(max(index_lon)-1), ']'');']); +0298 end +0299 end +0300 +0301 datatmp = squeeze(data1.(fields{aa}).(fields{aa}).(fields{aa})); +0302 datatmp = (datatmp * data_attributes.(fields{aa}).(fields{aa}).scale_factor) + data_attributes.(fields{aa}).(fields{aa}).add_offset; +0303 +0304 data.(fields{aa}).data = datatmp; +0305 data.(fields{aa}).time = data.time; +0306 % data.(fields{aa}).time = cat(1, data.(fields{aa}).time, squeeze(data1.(fields{aa}).(fields{aa}).time)); +0307 % data.(fields{aa}).lat = squeeze(data1.(fields{aa}).(fields{aa}).lat); +0308 % data.(fields{aa}).lon = squeeze(data1.(fields{aa}).(fields{aa}).lon); +0309 end +0310 +0311 % Now we have some data, we need to create some additional parameters +0312 % required by FVCOM. +0313 +0314 % Convert precipitation from kg/m^2/s to m/s (required by FVCOM) by +0315 % dividing by freshwater density (kg/m^3). +0316 data.prate.data = data.prate.data/1000; +0317 +0318 % Evaporation can be approximated by: +0319 % +0320 % E(m/s) = lhtfl/Llv/rho +0321 % +0322 % where: +0323 % +0324 % lhtfl = "Mean daily latent heat net flux at the surface" +0325 % Llv = Latent heat of vaporization (approx to 2.5*10^6 J kg^-1) +0326 % rho = 1025 kg/m^3 +0327 % +0328 Llv = 2.5*10^6; +0329 rho = 1025; % using a typical value for seawater. +0330 Et = data.lhtfl.data/Llv/rho; +0331 data.P_E.data = data.prate.data - Et; +0332 data.Et.data = Et; +0333 +0334 % Calculate the momentum flux +0335 WW = data.uwnd.data + data.vwnd.data * 1i; +0336 data.tau.data = stresslp(abs(WW),10); +0337 [data.tx.data,data.ty.data] = wstress(data.uwnd.data,data.vwnd.data,10); +0338 data.tx.data=reshape(data.tx.data*0.1, size(data.uwnd.data)); % dyn/cm^2 to N/m^2 +0339 data.ty.data=reshape(data.ty.data*0.1, size(data.uwnd.data)); % dyn/cm^2 to N/m^2 +0340 +0341 % Get the fields we need for the subsequent interpolation +0342 data.lon = data.(fields{1}).lon; +0343 data.lon(data.lon > 180) = data.lon(data.lon > 180) - 360; +0344 data.lat = data.(fields{1}).lat; +0345 +0346 % Have a look at some data. +0347 % [X, Y] = meshgrid(data.lon, data.lat); +0348 % for i=1:size(data.uwnd.data, 3) +0349 % figure(1) +0350 % clf +0351 % uv = sqrt(data.uwnd.data(:, :, i).^2 + data.vwnd.data(:, :, i).^2); +0352 % pcolor(X, Y, uv) +0353 % shading flat +0354 % axis('equal','tight') +0355 % pause(0.1) +0356 % end +0357 +0358 if ftbverbose +0359 fprintf(['end : ' subname '\n']) +0360 end +0361 +0362 return +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/get_POLCOMS_meanflow.html b/doc/fvcom_prepro/get_POLCOMS_meanflow.html new file mode 100644 index 0000000000000000000000000000000000000000..64831e2a727948485d24e2bb44289337a473324f --- /dev/null +++ b/doc/fvcom_prepro/get_POLCOMS_meanflow.html @@ -0,0 +1,492 @@ + + + + Description of get_POLCOMS_meanflow + + + + + + + + + +
    Home > fvcom_prepro > get_POLCOMS_meanflow.m
    + + + +

    get_POLCOMS_meanflow +

    + +

    PURPOSE ^

    +
    Read mean flow from the PML POLCOMS-ERSEM NetCDF AMM model output files
    + +

    SYNOPSIS ^

    +
    function Mobj = get_POLCOMS_meanflow(Mobj, files)
    + +

    DESCRIPTION ^

    +
     Read mean flow from the PML POLCOMS-ERSEM NetCDF AMM model output files
    + and interpolate onto the open boundaries in Mobj.
    +
    + function Mobj = get_POLCOMS_meanflow(Mobj, ts, polcoms_bathy, varlist)
    +
    + DESCRIPTION:
    +    Interpolate u and v flow vectors to calculate daily mean flow at the
    +    FVCOM open boundaries at all sigma levels.
    +
    + INPUT:
    +   Mobj    = MATLAB mesh structure which must contain:
    +               - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    +               - Mobj.obc_elements - list of open boundary element
    +               inidices.
    +               - Mobj.nObcElements - number of elements in each open boundary.
    +   files   = Cell array of PML POLCOMS-ERSEM NetCDF file(s) in which 4D
    +             variables of u and v velocity components (called 'ucurD' and
    +             'vcurD') exist. Their shape should be (y, x, sigma, time).
    +
    + NOTES:
    +
    +   - If you supply multiple files in files, there are a few assumptions:
    +
    +       - Variables are only appended if there are 4 dimensions; fewer than
    +       that, and the values are assumed to be static across all the given
    +       files (e.g. longitude, latitude etc.). The fourth dimension is
    +       time.
    +       - The order of the files given should be chronological.
    + 
    +   - The NetCDF files used here are those from the PML POLCOMS-ERSEM model
    +   output.
    +
    + OUTPUT:
    +    Mobj = MATLAB structure in which six new fields (mf_time, meanflow_u,
    +           meanflow_v, meanflow_ubar, meanflow_ubar and velocity).
    +           meanflow_ubar, meanflow_vbar and velocity have sizes of
    +           (sum(Mobj.nObcNodes), time); meanflow_u and meanflow_v have
    +           sizes (sum(Mobj.nObcNodes), siglay, time). The time dimension
    +           is determined based on the input NetCDF file. The mf_times
    +           variable is just the input file times in Modified Julian Day.
    +
    + EXAMPLE USAGE
    +    Mobj = get_POLCOMS_meanflow(Mobj, files)
    +
    + Author(s):
    +    Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +    2013-02-20 First version.
    +    2013-02-26 Add interpolation of the u and v vectors separately and
    +    then calculate the interpolated velocity at the end.
    +    2013-02-27 Change the vertical interpolation to be scaled within the
    +    POLCOMS-ERSEM depth range for the current node. The net result is that
    +    the vertical profiles are squashed or stretched to fit within the
    +    FVCOM depths. This means the full profile structure is maintained in
    +    the resulting FVCOM boundary input despite the differing depths at the
    +    FVCOM boundary node.
    +    2013-02-28 Change the interpolation to occur on the open boundary
    +    elements rather than on the open boundary nodes. This requires a
    +    couple of extra steps in the pre-processing (notably running
    +    find_boundary_elements) as well as transferring the sigma depths to
    +    the element centres.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function Mobj = get_POLCOMS_meanflow(Mobj, files)
    +0002 % Read mean flow from the PML POLCOMS-ERSEM NetCDF AMM model output files
    +0003 % and interpolate onto the open boundaries in Mobj.
    +0004 %
    +0005 % function Mobj = get_POLCOMS_meanflow(Mobj, ts, polcoms_bathy, varlist)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %    Interpolate u and v flow vectors to calculate daily mean flow at the
    +0009 %    FVCOM open boundaries at all sigma levels.
    +0010 %
    +0011 % INPUT:
    +0012 %   Mobj    = MATLAB mesh structure which must contain:
    +0013 %               - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    +0014 %               - Mobj.obc_elements - list of open boundary element
    +0015 %               inidices.
    +0016 %               - Mobj.nObcElements - number of elements in each open boundary.
    +0017 %   files   = Cell array of PML POLCOMS-ERSEM NetCDF file(s) in which 4D
    +0018 %             variables of u and v velocity components (called 'ucurD' and
    +0019 %             'vcurD') exist. Their shape should be (y, x, sigma, time).
    +0020 %
    +0021 % NOTES:
    +0022 %
    +0023 %   - If you supply multiple files in files, there are a few assumptions:
    +0024 %
    +0025 %       - Variables are only appended if there are 4 dimensions; fewer than
    +0026 %       that, and the values are assumed to be static across all the given
    +0027 %       files (e.g. longitude, latitude etc.). The fourth dimension is
    +0028 %       time.
    +0029 %       - The order of the files given should be chronological.
    +0030 %
    +0031 %   - The NetCDF files used here are those from the PML POLCOMS-ERSEM model
    +0032 %   output.
    +0033 %
    +0034 % OUTPUT:
    +0035 %    Mobj = MATLAB structure in which six new fields (mf_time, meanflow_u,
    +0036 %           meanflow_v, meanflow_ubar, meanflow_ubar and velocity).
    +0037 %           meanflow_ubar, meanflow_vbar and velocity have sizes of
    +0038 %           (sum(Mobj.nObcNodes), time); meanflow_u and meanflow_v have
    +0039 %           sizes (sum(Mobj.nObcNodes), siglay, time). The time dimension
    +0040 %           is determined based on the input NetCDF file. The mf_times
    +0041 %           variable is just the input file times in Modified Julian Day.
    +0042 %
    +0043 % EXAMPLE USAGE
    +0044 %    Mobj = get_POLCOMS_meanflow(Mobj, files)
    +0045 %
    +0046 % Author(s):
    +0047 %    Pierre Cazenave (Plymouth Marine Laboratory)
    +0048 %
    +0049 % Revision history
    +0050 %    2013-02-20 First version.
    +0051 %    2013-02-26 Add interpolation of the u and v vectors separately and
    +0052 %    then calculate the interpolated velocity at the end.
    +0053 %    2013-02-27 Change the vertical interpolation to be scaled within the
    +0054 %    POLCOMS-ERSEM depth range for the current node. The net result is that
    +0055 %    the vertical profiles are squashed or stretched to fit within the
    +0056 %    FVCOM depths. This means the full profile structure is maintained in
    +0057 %    the resulting FVCOM boundary input despite the differing depths at the
    +0058 %    FVCOM boundary node.
    +0059 %    2013-02-28 Change the interpolation to occur on the open boundary
    +0060 %    elements rather than on the open boundary nodes. This requires a
    +0061 %    couple of extra steps in the pre-processing (notably running
    +0062 %    find_boundary_elements) as well as transferring the sigma depths to
    +0063 %    the element centres.
    +0064 %
    +0065 %==========================================================================
    +0066 
    +0067 subname = 'get_POLCOMS_meanflow';
    +0068 
    +0069 global ftbverbose;
    +0070 if ftbverbose
    +0071     fprintf('\n')
    +0072     fprintf(['begin : ' subname '\n'])
    +0073 end
    +0074 
    +0075 varlist = {'lon', 'lat', 'ucurD', 'vcurD', 'time', 'depth', 'pdepthD'};
    +0076 
    +0077 pc = get_POLCOMS_netCDF(files, varlist);
    +0078 
    +0079 [~, ~, nz, nt] = size(pc.ucurD.data);
    +0080 
    +0081 [lon, lat] = meshgrid(pc.lon.data, pc.lat.data);
    +0082 
    +0083 % We need positions of the open boundary element centroids (i.e. the MCE
    +0084 % centroid) at which to calculate the mean flow velocity. As such, we need
    +0085 % to first calculate a number of parameters at the element centres from the
    +0086 % nodal values we typically collect (e.g. positions, sigma layers etc.). Do
    +0087 % all that here.
    +0088 lonc = nodes2elems(Mobj.lon, Mobj);
    +0089 latc = nodes2elems(Mobj.lat, Mobj);
    +0090 % For the sigma levels, we need to wrap the conversion in a loop.
    +0091 siglayzc = nan([Mobj.nElems, size(Mobj.siglayz, 2)]);
    +0092 for zz = 1:size(Mobj.siglayz, 2)
    +0093     siglayzc(:, zz) = nodes2elems(Mobj.siglayz(:, zz), Mobj);
    +0094 end
    +0095 
    +0096 oElements = [Mobj.read_obc_elements{:}];
    +0097 
    +0098 % Find the FVCOM positions for all the open boundary elements.
    +0099 fvlon = lonc(oElements);
    +0100 fvlat = latc(oElements);
    +0101 
    +0102 % Number of open boundary elements
    +0103 ne = sum(Mobj.nObcElements);
    +0104 % Number of sigma layers.
    +0105 fz = size(siglayzc, 2);
    +0106 
    +0107 fvmfu = nan(ne, fz, nt); % FVCOM interpolated flow vector components
    +0108 fvmfv = nan(ne, fz, nt); % FVCOM interpolated flow vector components
    +0109 
    +0110 if ftbverbose
    +0111     tic
    +0112 end
    +0113 
    +0114 for t = 1:nt
    +0115     if ftbverbose
    +0116         fprintf('%s : %i of %i timesteps... ', subname, t, nt)
    +0117     end
    +0118     % Get the current 3D array of PML POLCOMS-ERSEM results.
    +0119     pcu3 = pc.ucurD.data(:, :, :, t);
    +0120     pcv3 = pc.vcurD.data(:, :, :, t);
    +0121     pcz3 = pc.depth.data(:, :, :, t);
    +0122 
    +0123     % Preallocate the intermediate results arrays.
    +0124     iuz = nan(ne, nz);
    +0125     ivz = nan(ne, nz);
    +0126     izz = nan(ne, nz);
    +0127 
    +0128     % We need to create a mask to eliminate land values and apply it to the
    +0129     % depth averaged values.
    +0130     mask = squeeze(pc.depth.data(:, :, end, t))' >= 0;
    +0131 
    +0132     % Mask the longitude and latitude here (since it's depth independent,
    +0133     % there's no point doing it inside the next loop).
    +0134     tlon = lon;
    +0135     tlat = lat;
    +0136     tlon(mask) = [];
    +0137     tlat(mask) = [];
    +0138 
    +0139     for z = 1:nz
    +0140         % Turns out we do need vertical velocity for the mean flow, so
    +0141         % iterate through each vertical layer before interpolating
    +0142         % horizontally. The vertical interpolation happens after the
    +0143         % horizontal has been completed. Transpose the arrays to be (x, y)
    +0144         % rather than (y, x).
    +0145         pcu2 = pcu3(:, :, z)';
    +0146         pcv2 = pcv3(:, :, z)';
    +0147         pcz2 = pcz3(:, :, z)';
    +0148 
    +0149         % Flatten the arrays through the masking.
    +0150         pcu2(mask) = [];
    +0151         pcv2(mask) = [];
    +0152         pcz2(mask) = [];
    +0153 
    +0154         % Preallocate the intermediate results arrays.
    +0155         iuobc = nan(ne, 1);
    +0156         ivobc = nan(ne, 1);
    +0157         izobc = nan(ne, 1);
    +0158 
    +0159         % Speed up the tightest loops with a parallelized loop.
    +0160         parfor i = 1:ne
    +0161             % Now we can do each position within the current depth layer.
    +0162 
    +0163             fx = fvlon(i);
    +0164             fy = fvlat(i);
    +0165 
    +0166             [~, ii] = sort(sqrt((tlon - fx).^2 + (tlat - fy).^2));
    +0167             % Get the n nearest elements from PML POLCOMS-ERSEM data (more?
    +0168             % fewer?).
    +0169             ixy = ii(1:16);
    +0170 
    +0171             % Get the variables into static variables for the
    +0172             % parallelisation.
    +0173             plon = tlon(ixy);
    +0174             plat = tlat(ixy);
    +0175             pu = pcu2(ixy);
    +0176             pv = pcv2(ixy);
    +0177             pz = pcz2(ixy);
    +0178 
    +0179             % Use a triangulation to do the horizontal interpolation.
    +0180             triu = TriScatteredInterp(plon', plat', pu', 'natural');
    +0181             triv = TriScatteredInterp(plon', plat', pv', 'natural');
    +0182             triz = TriScatteredInterp(plon', plat', pz', 'natural');
    +0183             iuobc(i) = triu(fx, fy);
    +0184             ivobc(i) = triv(fx, fy);
    +0185             izobc(i) = triz(fx, fy);
    +0186 
    +0187             % Check if we have NaNs (mostly if the position is outside the
    +0188             % model domain).
    +0189             if isnan(iuobc(i)) || isnan(ivobc(i))
    +0190                 warning('FVCOM boundary element at %f, %f is outside the PML POLCOMS-ERSEM domain. Setting to the closest PML POLCOMS-ERSEM value.', fx, fy)
    +0191                 iuobc(i) = pcu2(ii(1));
    +0192                 ivobc(i) = pcv2(ii(1));
    +0193                 izobc(i) = pcz2(ii(1));
    +0194             end
    +0195         end
    +0196 
    +0197         % Put the results in this intermediate array.
    +0198         iuz(:, z) = iuobc;
    +0199         ivz(:, z) = ivobc;
    +0200         izz(:, z) = izobc;
    +0201     end
    +0202 
    +0203     % Now we've interpolated in space, we can interpolate the z-values
    +0204     % to the sigma depths.
    +0205 
    +0206     % Preallocate the output arrays
    +0207     fvuz = nan(ne, fz);
    +0208     fvvz = nan(ne, fz);
    +0209 
    +0210     for pp = 1:ne
    +0211         % Get the FVCOM depths at this element
    +0212         tfz = siglayzc(oElements(pp), :);
    +0213         % Now get the interpolated PML POLCOMS-ERSEM depth at this element
    +0214         tpz = izz(pp, :);
    +0215 
    +0216         % To ensure we get the full vertical expression of the vertical
    +0217         % profiles, we need to normalise the POLCOMS-ERSEM depths to the
    +0218         % FVCOM range for the current element. This is because in instances
    +0219         % where FVCOM depths are shallower (e.g. in coastal regions), if we
    +0220         % don't normalise the depths, we end up truncating the vertical
    +0221         % profile. This approach ensures we always use the full vertical
    +0222         % profile, but we're potentially squeezing it into a smaller depth.
    +0223         A = max(tpz);
    +0224         B = min(tpz);
    +0225         C = max(tfz);
    +0226         D = min(tfz);
    +0227         norm_tpz = (((D - C) * (tpz - A)) / (B - A)) + C;
    +0228 
    +0229         % Get the u and v velocity values for this elment and interpolate
    +0230         % down the water column (from PML POLCOMS-ERSEM to FVCOM). I
    +0231         % had originally planned to use csaps for the vertical
    +0232         % interplation/subsampling at each location. However, the demo
    +0233         % of csaps in the MATLAB documentation makes the interpolation
    +0234         % look horrible (shaving off extremes). interp1 provides a
    +0235         % range of interpolation schemes, of which pchip seems to do a
    +0236         % decent job of the interpolation (at least qualitatively).
    +0237         if ~isnan(tpz)
    +0238             fvuz(pp, :) = interp1(norm_tpz, iuz(pp, :), tfz, 'linear', 'extrap');
    +0239             fvvz(pp, :) = interp1(norm_tpz, ivz(pp, :), tfz, 'linear', 'extrap');
    +0240         else
    +0241             warning('Should never see this... ') % because we test for NaNs when fetching the values.
    +0242             warning('FVCOM boundary element at %f, %f is outside the PML POLCOMS-ERSEM domain. Skipping.', fvlon(pp), fvlat(pp))
    +0243             continue
    +0244         end
    +0245     end
    +0246 
    +0247     % The horizontally- and vertically-interpolated values in the final
    +0248     % FVCOM results array.
    +0249     fvmfu(:, :, t) = fvuz;
    +0250     fvmfv(:, :, t) = fvvz;
    +0251 
    +0252     if ftbverbose
    +0253         fprintf('done.\n')
    +0254     end
    +0255 end
    +0256 if ftbverbose
    +0257     toc
    +0258 end
    +0259 
    +0260 % Stick the values in the mesh structure.
    +0261 Mobj.meanflow_u = fvmfu;
    +0262 Mobj.meanflow_v = fvmfv;
    +0263 
    +0264 % Now we have the 3D arrays, create depth averaged velocities too
    +0265 Mobj.meanflow_ubar = squeeze(mean(Mobj.meanflow_u, 2));
    +0266 Mobj.meanflow_vbar = squeeze(mean(Mobj.meanflow_v, 2));
    +0267 
    +0268 % Depth averaged velocity
    +0269 Mobj.velocity = squeeze(mean(sqrt(Mobj.meanflow_u.^2 + Mobj.meanflow_v.^2), 2));
    +0270 
    +0271 % Convert the current times to Modified Julian Day (this is a bit ugly).
    +0272 pc.time.all = strtrim(regexp(pc.time.units, 'since', 'split'));
    +0273 pc.time.datetime = strtrim(regexp(pc.time.all{end}, ' ', 'split'));
    +0274 pc.time.ymd = str2double(strtrim(regexp(pc.time.datetime{1}, '-', 'split')));
    +0275 pc.time.hms = str2double(strtrim(regexp(pc.time.datetime{2}, ':', 'split')));
    +0276 
    +0277 Mobj.mf_times = greg2mjulian(...
    +0278     pc.time.ymd(1), ...
    +0279     pc.time.ymd(2), ...
    +0280     pc.time.ymd(3), ...
    +0281     pc.time.hms(1), ...
    +0282     pc.time.hms(2), ...
    +0283     pc.time.hms(3)) + (pc.time.data / 3600 / 24);
    +0284 
    +0285 if ftbverbose
    +0286     fprintf(['end   : ' subname '\n'])
    +0287 end
    +0288 
    +0289 % Check the interpolation along the boundary at the last time step. N.B.
    +0290 % Since the depths are scaled from the POLCOMS range to the FVCOM range,
    +0291 % the profiles won't match perfectly in these plots. This is because the
    +0292 % interpolated FVCOM profiles use the full water column from the POLCOMS
    +0293 % data rather than truncating it at the FVCOM depth.
    +0294 
    +0295 % % Map the open boundaries with the depth averaged velocity as a background
    +0296 % figure(1)
    +0297 % clf
    +0298 % imagesc(pc.lon.data, pc.lat.data, mean(sqrt(pcu3.^2 + pcv3.^2), 3)')
    +0299 % shading flat
    +0300 % axis('equal', 'tight')
    +0301 % set(gca,'YDir','normal')
    +0302 % colorbar
    +0303 % caxis([0, 0.05])
    +0304 % hold on
    +0305 % plot(fvlon, fvlat, 'wo')
    +0306 % axis([min(fvlon) - 0.1, max(fvlon) + 0.1, min(fvlat) - 0.1, max(fvlat) + 0.1])
    +0307 %
    +0308 % for i = 1:ne
    +0309 %
    +0310 %     % Add the current element's position and value as a scatter point to
    +0311 %     % the map plot.
    +0312 %     scatter(fvlon(i), fvlat(i), 50, Mobj.velocity(i, end), 'filled')
    +0313 %
    +0314 %     % Do vertical profiles of u, v and velocity.
    +0315 %     figure(2)
    +0316 %     clf
    +0317 %
    +0318 %     subplot(3,1,1)
    +0319 %     % FVCOM vertical profile. Has to be (i, :, end) because the
    +0320 %     % corresponding POLCOMS data isn't stored as a function of time (i.e.
    +0321 %     % iuz, ivz and izz are all for the last time step only).
    +0322 %     fvuz = Mobj.meanflow_u(i, :, end);
    +0323 %     fvz = siglayzc(oElements(i), :);
    +0324 %     plot(fvuz, fvz)
    +0325 %     hold on
    +0326 %     % The interpolated POLCOMS vertical profile (last time step only)
    +0327 %     plot(iuz(i, :), izz(i, :), 'g')
    +0328 %     % The depth-averaged velocity (again, last time step only)
    +0329 %     fvubar = Mobj.meanflow_ubar(i, end);
    +0330 %     plot([fvubar, fvubar], [min(fvz), max(fvz)], 'k')
    +0331 %     xlim([-0.1, 0.2])
    +0332 %     ylim([-100, 0])
    +0333 %     xlabel('Mean flow u-velocity (m^{3}s^{-1})')
    +0334 %     ylabel('Depth (m)')
    +0335 %     title('u-component')
    +0336 %     legend('FVCOM', 'POLCOMS', 'Mean FVCOM', 'Location', 'SouthEast')
    +0337 %     legend('boxoff')
    +0338 %
    +0339 %     subplot(3,1,2)
    +0340 %     % FVCOM vertical profile. Has to be (i, :, end) because the
    +0341 %     % corresponding POLCOMS data isn't stored as a function of time (i.e.
    +0342 %     % iuz, ivz and izz are all for the last time step only).
    +0343 %     fvvz = Mobj.meanflow_v(i, :, end);
    +0344 %     fvz = siglayzc(oElements(i), :);
    +0345 %     plot(fvvz, fvz)
    +0346 %     hold on
    +0347 %     % The interpolated POLCOMS vertical profile (last time step only)
    +0348 %     plot(ivz(i, :), izz(i, :), 'g')
    +0349 %     % The depth-averaged velocity (again, last time step only)
    +0350 %     fvvbar = Mobj.meanflow_vbar(i, end);
    +0351 %     plot([fvvbar, fvvbar], [min(fvz), max(fvz)], 'k')
    +0352 %     xlim([-0.1, 0.2])
    +0353 %     ylim([-100, 0])
    +0354 %     xlabel('Mean flow v-velocity (m^{3}s^{-1})')
    +0355 %     ylabel('Depth (m)')
    +0356 %     title('v-component')
    +0357 %     legend('FVCOM', 'POLCOMS', 'Mean FVCOM', 'Location', 'SouthEast')
    +0358 %     legend('boxoff')
    +0359 %
    +0360 %     subplot(3,1,3)
    +0361 %     % FVCOM vertical profile. Has to be (i, :, end) because the
    +0362 %     % corresponding POLCOMS data isn't stored as a function of time (i.e.
    +0363 %     % iuz, ivz and izz are all for the last time step only).
    +0364 %     fvvelz = sqrt(Mobj.meanflow_u(i, :, end).^2 + Mobj.meanflow_v(i, :, end).^2);
    +0365 %     fvz = siglayzc(oElements(i), :);
    +0366 %     plot(fvvelz, fvz)
    +0367 %     hold on
    +0368 %     % The interpolated POLCOMS vertical profile (last time step only)
    +0369 %     plot(sqrt(iuz(i, :).^2 + ivz(i, :).^2), izz(i, :), 'g')
    +0370 %     % The depth-averaged velocity (again, last time step only)
    +0371 %     fvvelbar = Mobj.velocity(i, end);
    +0372 %     plot([fvvelbar, fvvelbar], [min(fvz), max(fvz)], 'k')
    +0373 %     xlim([-0.1, 0.2])
    +0374 %     ylim([-100, 0])
    +0375 %     xlabel('Mean flow velocity (m^{3}s^{-1})')
    +0376 %     ylabel('Depth (m)')
    +0377 %     title('velocity')
    +0378 %     legend('FVCOM', 'POLCOMS', 'Mean FVCOM', 'Location', 'SouthEast')
    +0379 %     legend('boxoff')
    +0380 %     pause(0.1)
    +0381 % end
    +0382
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/get_POLCOMS_netCDF.html b/doc/fvcom_prepro/get_POLCOMS_netCDF.html new file mode 100644 index 0000000000000000000000000000000000000000..87933ac9ed90296c57befa5c799412d8876cd7f4 --- /dev/null +++ b/doc/fvcom_prepro/get_POLCOMS_netCDF.html @@ -0,0 +1,233 @@ + + + + Description of get_POLCOMS_netCDF + + + + + + + + + +
    Home > fvcom_prepro > get_POLCOMS_netCDF.m
    + + + +

    get_POLCOMS_netCDF +

    + +

    PURPOSE ^

    +
    Read temperature and salinity from NetCDF model output files and
    + +

    SYNOPSIS ^

    +
    function ncdata = get_POLCOMS_netCDF(files, varlist)
    + +

    DESCRIPTION ^

    +
     Read temperature and salinity from NetCDF model output files and
    + interpolate onto the open boundaries in Mobj.
    +
    + function struct = get_POLCOMS_netCDF(Mobj, files, varlist)
    +
    + DESCRIPTION:
    +    Extract variables in varlist to a struct from the files given in
    +    files.
    +
    + INPUT:
    +   files   = Cell array of NetCDF file(s).
    +   varlist = Cell array of variables names.
    +
    + OUTPUT:
    +    Struct in which the field names are the variable names supplied in var
    +    list. Each field has a data and units array which contain the data and
    +    units variables from the NetCDF. If no units are found, it is left
    +    blank for that variable.
    +
    + EXAMPLE USAGE
    +    S = get_POLCOMS_netCDF({'/tmp/2000.nc', '/tmp/2001.nc', {'temp', 'salt'})
    +
    + NOTES:
    +
    +   - If you supply multiple files, there are a few assumptions:
    +
    +       - Variables are only appended if there are 3 or 4 dimensions; fewer
    +       than that, and the values are assumed to be static across all the
    +       given files (e.g. longitude, latitude etc.). The last dimension
    +       is assumed to be time.
    +       - The order of the files given should be chronological.
    + 
    +   - This has been tested on NetCDF files generated from the PML
    +   POLCOMS-ERSEM daily mean model output
    +
    + Author(s):
    +    Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +    2013-02-08 First version based on restart_FVCOM_AMM.m and
    +    get_AMM_tsobc.m.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function ncdata = get_POLCOMS_netCDF(files, varlist)
    +0002 % Read temperature and salinity from NetCDF model output files and
    +0003 % interpolate onto the open boundaries in Mobj.
    +0004 %
    +0005 % function struct = get_POLCOMS_netCDF(Mobj, files, varlist)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %    Extract variables in varlist to a struct from the files given in
    +0009 %    files.
    +0010 %
    +0011 % INPUT:
    +0012 %   files   = Cell array of NetCDF file(s).
    +0013 %   varlist = Cell array of variables names.
    +0014 %
    +0015 % OUTPUT:
    +0016 %    Struct in which the field names are the variable names supplied in var
    +0017 %    list. Each field has a data and units array which contain the data and
    +0018 %    units variables from the NetCDF. If no units are found, it is left
    +0019 %    blank for that variable.
    +0020 %
    +0021 % EXAMPLE USAGE
    +0022 %    S = get_POLCOMS_netCDF({'/tmp/2000.nc', '/tmp/2001.nc', {'temp', 'salt'})
    +0023 %
    +0024 % NOTES:
    +0025 %
    +0026 %   - If you supply multiple files, there are a few assumptions:
    +0027 %
    +0028 %       - Variables are only appended if there are 3 or 4 dimensions; fewer
    +0029 %       than that, and the values are assumed to be static across all the
    +0030 %       given files (e.g. longitude, latitude etc.). The last dimension
    +0031 %       is assumed to be time.
    +0032 %       - The order of the files given should be chronological.
    +0033 %
    +0034 %   - This has been tested on NetCDF files generated from the PML
    +0035 %   POLCOMS-ERSEM daily mean model output
    +0036 %
    +0037 % Author(s):
    +0038 %    Pierre Cazenave (Plymouth Marine Laboratory)
    +0039 %
    +0040 % Revision history
    +0041 %    2013-02-08 First version based on restart_FVCOM_AMM.m and
    +0042 %    get_AMM_tsobc.m.
    +0043 %
    +0044 %==========================================================================
    +0045 
    +0046 subname = 'get_POLCOMS_netCDF';
    +0047 
    +0048 global ftbverbose;
    +0049 if ftbverbose
    +0050     fprintf('\nbegin : %s\n', subname)
    +0051 end
    +0052 
    +0053 % Get the results. Check we have a cell array, and if we don't, assume it's
    +0054 % a file name.
    +0055 if iscell(files)
    +0056     todo = length(files);
    +0057 else
    +0058     todo = 1;
    +0059 end
    +0060 
    +0061 for ii = 1:todo
    +0062 
    +0063     if iscell(files)
    +0064         ftn = files{ii};
    +0065     else
    +0066         ftn = files;
    +0067     end
    +0068 
    +0069     if ftbverbose
    +0070         % Strip path from filename for the verbose output.
    +0071         [~, basename, ext] = fileparts(ftn);
    +0072         tmp_fn = [basename, ext];
    +0073 
    +0074         if todo == 1
    +0075             fprintf('%s: extracting file %s... ', subname, tmp_fn)
    +0076         else
    +0077             fprintf('%s: extracting file %s (%i of %i)... ', subname, tmp_fn, ii, todo)
    +0078         end
    +0079     end
    +0080 
    +0081     nc = netcdf.open(ftn, 'NOWRITE');
    +0082 
    +0083     for var = 1:numel(varlist)
    +0084 
    +0085         getVar = varlist{var};
    +0086         varid = netcdf.inqVarID(nc, getVar);
    +0087 
    +0088         data = double(netcdf.getVar(nc, varid, 'single'));
    +0089         if ii == 1
    +0090             ncdata.(getVar).data = data;
    +0091         else
    +0092             if ndims(data) < 3
    +0093                 if strcmpi(varlist{var}, 'time')
    +0094                     % If the dimension is time, we need to be a bit more
    +0095                     % clever since we'll need a concatenated time series
    +0096                     % (in which values are continuous and from which we
    +0097                     % can extract a sensible time). As such, we need to add
    +0098                     % the maximum of the existing time. On the first
    +0099                     % iteration, we should save ourselves the base time
    +0100                     % (from the units of the time variable).
    +0101                     ncdata.(getVar).data = [ncdata.(getVar).data; data + max(ncdata.(getVar).data)];
    +0102                 else
    +0103                     % This should be a fixed set of values (probably lon or
    +0104                     % lat) in which case we don't need to append them, so
    +0105                     % just replace the existing values with those in the
    +0106                     % current NetCDF file.
    +0107                     ncdata.(getVar).data = data;
    +0108                 end
    +0109             elseif ndims(data) == 3 || ndims(data) == 4
    +0110                 % Concatenate along the last dimension and hope/assume it's
    +0111                 % a time dimension.
    +0112                 ncdata.(getVar).data = cat(ndims(data), ncdata.(getVar).data, data);
    +0113             else
    +0114                 error('Unsupported number of dimensions in PML POLCOMS-ERSEM data')
    +0115             end
    +0116         end
    +0117         % Try to get some units (important for the calculation of MJD).
    +0118         try
    +0119             if ii == 1
    +0120                 units = netcdf.getAtt(nc, varid, 'units');
    +0121             else
    +0122                 % Leave the units values alone so we always use the values
    +0123                 % from the first file. This is particularly important for
    +0124                 % the time calculation later on which is dependent on
    +0125                 % knowing the time origin of the first file.
    +0126                 continue
    +0127             end
    +0128         catch
    +0129             units = [];
    +0130         end
    +0131         ncdata.(getVar).units = units;
    +0132     end
    +0133 
    +0134     netcdf.close(nc)
    +0135 
    +0136     if ftbverbose
    +0137         fprintf('done.\n')
    +0138     end
    +0139 
    +0140 end
    +0141 
    +0142 if ftbverbose
    +0143     fprintf(['end   : ' subname '\n'])
    +0144 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/get_POLCOMS_river_discharge.html b/doc/fvcom_prepro/get_POLCOMS_river_discharge.html new file mode 100644 index 0000000000000000000000000000000000000000..b83ced85aaf255f3b7b0d48c3d1e6dc7d3974ae0 --- /dev/null +++ b/doc/fvcom_prepro/get_POLCOMS_river_discharge.html @@ -0,0 +1,137 @@ + + + + Description of get_POLCOMS_river_discharge + + + + + + + + + +
    Home > fvcom_prepro > get_POLCOMS_river_discharge.m
    + + + +

    get_POLCOMS_river_discharge +

    + +

    PURPOSE ^

    +
    Parse the POLCOMS rivers data file.
    + +

    SYNOPSIS ^

    +
    function Mobj = get_POLCOMS_river_discharge(Mobj, polcoms_flow)
    + +

    DESCRIPTION ^

    +
     Parse the POLCOMS rivers data file.
    +
    + get_POLCOMS_rivers(Mobj, polcoms_file, polcoms_grid, polcoms_ij)
    +
    + DESCRIPTION:
    +   Takes POLCOMS grid and index files and returns the positions and names
    +   of the rivers within the index file.
    +
    + INPUT:
    +   Mobj - MATLAB mesh object into which the outputs will be added.
    +   polcoms_flow - flow data file(s) from POLCOMS. For multiple files, give
    +       in chronological order as a cell array of file names.
    + 
    + OUTPUT:
    +   Mobj.river_discharge - array of discharges for the rivers in the
    +   POLCOMS river flow file(s).
    +
    + EXAMPLE USAGE:
    +   Mobj = get_POLCOMS_river_discharge(Mobj, 'polcoms.flw')
    + 
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2013-04-15 - First version from the original get_POLCOMS_rivers.m.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function Mobj = get_POLCOMS_river_discharge(Mobj, polcoms_flow)
    +0002 % Parse the POLCOMS rivers data file.
    +0003 %
    +0004 % get_POLCOMS_rivers(Mobj, polcoms_file, polcoms_grid, polcoms_ij)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Takes POLCOMS grid and index files and returns the positions and names
    +0008 %   of the rivers within the index file.
    +0009 %
    +0010 % INPUT:
    +0011 %   Mobj - MATLAB mesh object into which the outputs will be added.
    +0012 %   polcoms_flow - flow data file(s) from POLCOMS. For multiple files, give
    +0013 %       in chronological order as a cell array of file names.
    +0014 %
    +0015 % OUTPUT:
    +0016 %   Mobj.river_discharge - array of discharges for the rivers in the
    +0017 %   POLCOMS river flow file(s).
    +0018 %
    +0019 % EXAMPLE USAGE:
    +0020 %   Mobj = get_POLCOMS_river_discharge(Mobj, 'polcoms.flw')
    +0021 %
    +0022 % Author(s):
    +0023 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0024 %
    +0025 % Revision history:
    +0026 %   2013-04-15 - First version from the original get_POLCOMS_rivers.m.
    +0027 %
    +0028 %==========================================================================
    +0029 
    +0030 subname = 'get_POLCOMS_river_discharge';
    +0031 
    +0032 global ftbverbose;
    +0033 if ftbverbose
    +0034     fprintf(['\nbegin : ' subname '\n'])
    +0035 end
    +0036 
    +0037 % Check inputs
    +0038 if exist(polcoms_flow, 'file') ~= 2
    +0039     error('file: %s does not exist or is not readable.', polcoms_grid)
    +0040 end
    +0041 
    +0042 % The POLCOMS river file has a pretty straightforward format of a 2D array
    +0043 % of river along x and time along y. Since it's a simple text file with no
    +0044 % weird format, we'll just read it in with load.
    +0045 if iscell(polcoms_flow)
    +0046     pc_riv = [];
    +0047     for rr = 1:length(polcoms_flow)
    +0048         pc_riv = [pc_riv; load(polcoms_flow{rr})];
    +0049     end
    +0050     clear rr
    +0051 else
    +0052     pc_riv = load(polcoms_flow);
    +0053 end
    +0054 [pc_nt, pc_nr] = size(pc_riv);
    +0055 
    +0056 % Return the number of river and the number of times along with the actual
    +0057 % discharge data.
    +0058 Mobj.rivers.num = pc_nr;
    +0059 Mobj.rivers.num_time = pc_nt;
    +0060 Mobj.rivers.discharge = pc_riv;
    +0061 
    +0062 if ftbverbose
    +0063     fprintf(['end   : ' subname '\n'])
    +0064 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/get_POLCOMS_river_positions.html b/doc/fvcom_prepro/get_POLCOMS_river_positions.html new file mode 100644 index 0000000000000000000000000000000000000000..41ab6b58dfdbe67d1b3ff495e4b039f6f79b3bf3 --- /dev/null +++ b/doc/fvcom_prepro/get_POLCOMS_river_positions.html @@ -0,0 +1,205 @@ + + + + Description of get_POLCOMS_river_positions + + + + + + + + + +
    Home > fvcom_prepro > get_POLCOMS_river_positions.m
    + + + +

    get_POLCOMS_river_positions +

    + +

    PURPOSE ^

    +
    Parse the POLCOMS rivers data file.
    + +

    SYNOPSIS ^

    +
    function Mobj = get_POLCOMS_river_positions(Mobj, polcoms_grid, polcoms_ij)
    + +

    DESCRIPTION ^

    +
     Parse the POLCOMS rivers data file.
    +
    + get_POLCOMS_rivers(Mobj, polcoms_file, polcoms_grid, polcoms_ij)
    +
    + DESCRIPTION:
    +   Takes POLCOMS grid and index files and returns the positions and names
    +   of the rivers within the index file.
    +
    + INPUT:
    +   Mobj - MATLAB mesh object into which the outputs will be added.
    +   polcoms_grid - NetCDF file of the POLCOMS grid.
    +   polcoms_ij - indices in the POLCOMS grid at which each river is
    +       located.
    + 
    + OUTPUT:
    +   Mobj.river_xy - array of lon/lat positions of the POLCOMS rivers.
    +   Mobj.river_polcoms_names - names for the rivers in the positions array.
    +
    + EXAMPLE USAGE:
    +   Mobj = get_POLCOMS_rivers(Mobj, 'polcoms.nc', 'polcoms.index')
    + 
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2013-04-15 - First version from the original get_POLCOMS_rivers.m.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function Mobj = get_POLCOMS_river_positions(Mobj, polcoms_grid, polcoms_ij)
    +0002 % Parse the POLCOMS rivers data file.
    +0003 %
    +0004 % get_POLCOMS_rivers(Mobj, polcoms_file, polcoms_grid, polcoms_ij)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Takes POLCOMS grid and index files and returns the positions and names
    +0008 %   of the rivers within the index file.
    +0009 %
    +0010 % INPUT:
    +0011 %   Mobj - MATLAB mesh object into which the outputs will be added.
    +0012 %   polcoms_grid - NetCDF file of the POLCOMS grid.
    +0013 %   polcoms_ij - indices in the POLCOMS grid at which each river is
    +0014 %       located.
    +0015 %
    +0016 % OUTPUT:
    +0017 %   Mobj.river_xy - array of lon/lat positions of the POLCOMS rivers.
    +0018 %   Mobj.river_polcoms_names - names for the rivers in the positions array.
    +0019 %
    +0020 % EXAMPLE USAGE:
    +0021 %   Mobj = get_POLCOMS_rivers(Mobj, 'polcoms.nc', 'polcoms.index')
    +0022 %
    +0023 % Author(s):
    +0024 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0025 %
    +0026 % Revision history:
    +0027 %   2013-04-15 - First version from the original get_POLCOMS_rivers.m.
    +0028 %
    +0029 %==========================================================================
    +0030 
    +0031 subname = 'get_POLCOMS_river_positions';
    +0032 
    +0033 global ftbverbose;
    +0034 if ftbverbose
    +0035     fprintf(['\nbegin : ' subname '\n'])
    +0036 end
    +0037 
    +0038 % Check inputs
    +0039 if exist(polcoms_grid, 'file') ~= 2
    +0040     error('file: %s does not exist or is not readable.', polcoms_grid)
    +0041 end
    +0042 if exist(polcoms_ij, 'file') ~= 2
    +0043     error('file: %s does not exist or is not readable.', polcoms_ij)
    +0044 end
    +0045 
    +0046 % Get the positions for each river from the NetCDF grid and the index file.
    +0047 % Format is:
    +0048 %
    +0049 % n
    +0050 %   id1 i j Name1
    +0051 %   id2 i j Name2
    +0052 %   ...
    +0053 %   idn i j Namen
    +0054 fidx = fopen(polcoms_ij, 'r');
    +0055 if fidx < 0
    +0056     error('Error opening index file (%s).', polcoms_ij);
    +0057 end
    +0058 
    +0059 c = 0; % line counter
    +0060 while ~feof(fidx)
    +0061     line = fgetl(fidx);
    +0062     if isempty(line) || ~ischar(line)
    +0063         continue
    +0064     else
    +0065         c = c + 1;
    +0066     end
    +0067     
    +0068     if c == 1
    +0069         % First (valid) line should be number of rivers
    +0070         nridx = str2double(strtrim(line));
    +0071         % Preallocate the output arrays on the basis of this value. If the
    +0072         % file happens to have more lines, that shouldn't matter. Too few,
    +0073         % however, and you'll end up with NaNs at the end of your array. I
    +0074         % should probably remove them later...
    +0075         pc_idx = nan(nridx, 3);
    +0076         pc_name = cell(nridx, 1);
    +0077     else
    +0078         % We're in the data.
    +0079         S = regexpi(strtrim(line), ' +', 'split');
    +0080         pc_idx(c - 1, :) = [str2double(S{1}), str2double(S{2}), str2double(S{3})];
    +0081         pc_name{c - 1} = S{end};
    +0082     end
    +0083 end
    +0084 clear S line c
    +0085 
    +0086 fclose(fidx);
    +0087 
    +0088 % Now read in the NetCDF file and grab the real coordinates of those
    +0089 % positions.
    +0090 nc = netcdf.open(polcoms_grid, 'NOWRITE');
    +0091 [~, numvars, ~, ~] = netcdf.inq(nc);
    +0092 
    +0093 for ii = 1:numvars
    +0094     
    +0095     [varname, ~, ~, ~] = netcdf.inqVar(nc, ii - 1);
    +0096     varid = netcdf.inqVarID(nc, varname);
    +0097 
    +0098     if ftbverbose
    +0099         fprintf('\tvariable %s... ', varname)
    +0100     end
    +0101  
    +0102     switch varname
    +0103         case 'lon'
    +0104             pc_lon = netcdf.getVar(nc, varid);
    +0105             
    +0106         case 'lat'
    +0107             pc_lat = netcdf.getVar(nc, varid);
    +0108 
    +0109     end
    +0110     
    +0111     if ftbverbose
    +0112         fprintf('done.\n')
    +0113     end
    +0114 
    +0115 end
    +0116 
    +0117 clear numdims numvars dimnames 
    +0118 
    +0119 netcdf.close(nc)
    +0120 
    +0121 % Use the indices from the polcoms_ij file to get the real positions of the
    +0122 % river nodes.
    +0123 pc_riv_lonlat = [pc_lon(pc_idx(:, 2), 1), pc_lat(1, pc_idx(:, 3))'];
    +0124 
    +0125 % Return the positions and names to the Mobj.
    +0126 Mobj.rivers.positions = pc_riv_lonlat;
    +0127 Mobj.rivers.names = pc_name;
    +0128 
    +0129 if ftbverbose
    +0130     fprintf(['end   : ' subname '\n'])
    +0131 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/get_POLCOMS_tsobc.html b/doc/fvcom_prepro/get_POLCOMS_tsobc.html index 52ffca52739ef86f628703917d1b3bf4fc051e7f..136290e65cf043e3891369869ffdf9ee66563550 100644 --- a/doc/fvcom_prepro/get_POLCOMS_tsobc.html +++ b/doc/fvcom_prepro/get_POLCOMS_tsobc.html @@ -4,7 +4,7 @@ Description of get_POLCOMS_tsobc - + @@ -21,52 +21,72 @@

    PURPOSE ^

    -
    Read temperature and salinity from POLCOMS NetCDF model output files and
    +
    Read temperature and salinity from the PML POLCOMS-ERSEM NetCDF model

    SYNOPSIS ^

    -
    function Mobj = get_POLCOMS_tsobc(Mobj, polcoms_ts, polcoms_z)
    +
    function Mobj = get_POLCOMS_tsobc(Mobj, ts)

    DESCRIPTION ^

    -
     Read temperature and salinity from POLCOMS NetCDF model output files and
    - interpolate onto the open boundaries in Mobj.
    +
     Read temperature and salinity from the PML POLCOMS-ERSEM NetCDF model
    + output files and interpolate onto the open boundaries in Mobj.
     
    - function Mobj = get_POLCOMS_tsobc(Mobj, polcoms_ts, polcoms_bathy, varlist)
    + function Mobj = get_POLCOMS_tsobc(Mobj, ts, polcoms_bathy, varlist)
     
      DESCRIPTION:
         Interpolate temperature and salinity values onto the FVCOM open
         boundaries at all sigma levels.
     
      INPUT:
    -   Mobj        = MATLAB mesh structure which must contain:
    -                   - Mobj.siglayz - sigma layer depths for all model
    -                   nodes.
    -                   - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    -                   - Mobj.obc_nodes - list of open boundary node inidices.
    -                   - Mobj.nObcNodes - number of nodes in each open
    -                   boundary.
    -   polcoms_ts  = POLCOMS NetCDF file in which 4D variables of temperature 
    -                 and salinity (called 'ETW' and 'x1X') exist. Their shape
    -                 should be (y, x, sigma, time).
    -   polcoms_z   = POLCOMS NetCDF file in which 4D variables of bathymetry
    -                 and sigma layer thickness can be found. They should be
    -                 called 'depth' and 'pdepth' respectively.
    +   Mobj    = MATLAB mesh structure which must contain:
    +               - Mobj.siglayz - sigma layer depths for all model nodes.
    +               - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    +               - Mobj.obc_nodes - list of open boundary node inidices.
    +               - Mobj.nObcNodes - number of nodes in each open boundary.
    +   ts      = Cell array of PML POLCOMS-ERSEM NetCDF file(s) in which 4D
    +             variables of temperature and salinity (called 'ETWD' and
    +             'x1XD') exist. Their shape should be (y, x, sigma, time).
    +
    + NOTES:
    +
    +   - If you supply multiple files in ts, there are a few assumptions:
    +
    +       - Variables are only appended if there are 4 dimensions; fewer than
    +       that, and the values are assumed to be static across all the given
    +       files (e.g. longitude, latitude). The fourth dimension is time.
    +       - The order of the files given should be chronological.
      
    +   - The NetCDF files used here are those from the PML POLCOMS-ERSEM model
    +   output.
    +
      OUTPUT:
         Mobj = MATLAB structure in which three new fields (called temperature,
    -           salinity and ts_time). temperature and salinity have sizes
    +           salinity and ts_times). temperature and salinity have sizes
                (sum(Mobj.nObcNodes), sigma, time). The time dimension is
                determined based on the input NetCDF file. The ts_time variable
                is just the input file times in Modified Julian Day.
     
      EXAMPLE USAGE
    -    Mobj = get_POLCOMS_forcing(Mobj, polcoms_ts, polcoms_z)
    +    Mobj = get_POLCOMS_tsobc(Mobj, ts)
     
      Author(s):
         Pierre Cazenave (Plymouth Marine Laboratory)
     
      Revision history
    -    2013-01-09 First version based on the FVCOM shelf model
    -    get_POLCOMS_forcing.m script (i.e. not a function but a plain script).
    +    2013-02-07 First version.
    +    2013-02-27 Change the vertical interpolation to be scaled within the
    +    POLCOMS-ERSEM depth range for the current node. The net result is that
    +    the vertical profiles are squashed or stretched to fit within the
    +    FVCOM depths. This means the full profile structure is maintained in
    +    the resulting FVCOM boundary input despite the differing depths at the
    +    FVCOM boundary node.
    +    2013-06-03 Fix some bugs in the way the open boundary node values were
    +    stored (the order in which they were stored did not match the order of
    +    the nodes in Casename_obc.dat). Also fix the order of the vertically
    +    interpolated values so that FVCOM starts at the surface instead of
    +    mirroring POLCOMS' approach (where the first value is the seabed). The
    +    effect of these two fixes (nodes and vertical) should match what FVCOM
    +    expects. Also add a set of figures (commented out) at the end for
    +    diagnostic purposes.
     
     ==========================================================================
    @@ -74,7 +94,7 @@

    CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • get_POLCOMS_netCDF Read temperature and salinity from NetCDF model output files and
  • This function is called by: @@ -83,287 +103,369 @@ This function is called by:

    SOURCE CODE ^

    -
    0001 function Mobj = get_POLCOMS_tsobc(Mobj, polcoms_ts, polcoms_z)
    -0002 % Read temperature and salinity from POLCOMS NetCDF model output files and
    -0003 % interpolate onto the open boundaries in Mobj.
    +
    0001 function Mobj = get_POLCOMS_tsobc(Mobj, ts)
    +0002 % Read temperature and salinity from the PML POLCOMS-ERSEM NetCDF model
    +0003 % output files and interpolate onto the open boundaries in Mobj.
     0004 %
    -0005 % function Mobj = get_POLCOMS_tsobc(Mobj, polcoms_ts, polcoms_bathy, varlist)
    +0005 % function Mobj = get_POLCOMS_tsobc(Mobj, ts, polcoms_bathy, varlist)
     0006 %
     0007 % DESCRIPTION:
     0008 %    Interpolate temperature and salinity values onto the FVCOM open
     0009 %    boundaries at all sigma levels.
     0010 %
     0011 % INPUT:
    -0012 %   Mobj        = MATLAB mesh structure which must contain:
    -0013 %                   - Mobj.siglayz - sigma layer depths for all model
    -0014 %                   nodes.
    -0015 %                   - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    -0016 %                   - Mobj.obc_nodes - list of open boundary node inidices.
    -0017 %                   - Mobj.nObcNodes - number of nodes in each open
    -0018 %                   boundary.
    -0019 %   polcoms_ts  = POLCOMS NetCDF file in which 4D variables of temperature
    -0020 %                 and salinity (called 'ETW' and 'x1X') exist. Their shape
    -0021 %                 should be (y, x, sigma, time).
    -0022 %   polcoms_z   = POLCOMS NetCDF file in which 4D variables of bathymetry
    -0023 %                 and sigma layer thickness can be found. They should be
    -0024 %                 called 'depth' and 'pdepth' respectively.
    -0025 %
    -0026 % OUTPUT:
    -0027 %    Mobj = MATLAB structure in which three new fields (called temperature,
    -0028 %           salinity and ts_time). temperature and salinity have sizes
    -0029 %           (sum(Mobj.nObcNodes), sigma, time). The time dimension is
    -0030 %           determined based on the input NetCDF file. The ts_time variable
    -0031 %           is just the input file times in Modified Julian Day.
    +0012 %   Mobj    = MATLAB mesh structure which must contain:
    +0013 %               - Mobj.siglayz - sigma layer depths for all model nodes.
    +0014 %               - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    +0015 %               - Mobj.obc_nodes - list of open boundary node inidices.
    +0016 %               - Mobj.nObcNodes - number of nodes in each open boundary.
    +0017 %   ts      = Cell array of PML POLCOMS-ERSEM NetCDF file(s) in which 4D
    +0018 %             variables of temperature and salinity (called 'ETWD' and
    +0019 %             'x1XD') exist. Their shape should be (y, x, sigma, time).
    +0020 %
    +0021 % NOTES:
    +0022 %
    +0023 %   - If you supply multiple files in ts, there are a few assumptions:
    +0024 %
    +0025 %       - Variables are only appended if there are 4 dimensions; fewer than
    +0026 %       that, and the values are assumed to be static across all the given
    +0027 %       files (e.g. longitude, latitude). The fourth dimension is time.
    +0028 %       - The order of the files given should be chronological.
    +0029 %
    +0030 %   - The NetCDF files used here are those from the PML POLCOMS-ERSEM model
    +0031 %   output.
     0032 %
    -0033 % EXAMPLE USAGE
    -0034 %    Mobj = get_POLCOMS_forcing(Mobj, polcoms_ts, polcoms_z)
    -0035 %
    -0036 % Author(s):
    -0037 %    Pierre Cazenave (Plymouth Marine Laboratory)
    -0038 %
    -0039 % Revision history
    -0040 %    2013-01-09 First version based on the FVCOM shelf model
    -0041 %    get_POLCOMS_forcing.m script (i.e. not a function but a plain script).
    +0033 % OUTPUT:
    +0034 %    Mobj = MATLAB structure in which three new fields (called temperature,
    +0035 %           salinity and ts_times). temperature and salinity have sizes
    +0036 %           (sum(Mobj.nObcNodes), sigma, time). The time dimension is
    +0037 %           determined based on the input NetCDF file. The ts_time variable
    +0038 %           is just the input file times in Modified Julian Day.
    +0039 %
    +0040 % EXAMPLE USAGE
    +0041 %    Mobj = get_POLCOMS_tsobc(Mobj, ts)
     0042 %
    -0043 %==========================================================================
    -0044 
    -0045 subname = 'get_POLCOMS_forcing';
    -0046 
    -0047 global ftbverbose;
    -0048 if ftbverbose
    -0049     fprintf('\n')
    -0050     fprintf(['begin : ' subname '\n'])
    -0051 end
    -0052 
    -0053 varlist = {'lon', 'lat', 'ETW', 'x1X', 'time'};
    -0054 
    -0055 % Get the results
    -0056 nc = netcdf.open(polcoms_ts, 'NOWRITE');
    -0057 
    -0058 for var=1:numel(varlist)
    -0059     
    -0060     getVar = varlist{var};
    -0061     varid_pc = netcdf.inqVarID(nc, getVar);
    -0062     
    -0063     data = netcdf.getVar(nc, varid_pc, 'single');
    -0064     pc.(getVar).data = double(data);
    -0065     % Try to get some units (important for the calculation of MJD).
    -0066     try
    -0067         units = netcdf.getAtt(nc,varid_pc,'units');
    -0068     catch
    -0069         units = [];
    -0070     end
    -0071     pc.(getVar).units = units;
    -0072 end
    -0073 
    -0074 netcdf.close(nc)
    -0075 
    -0076 % Extract the bathymetry ('pdepth' is cell thickness, 'depth' is cell
    -0077 % centre depth).
    -0078 nc = netcdf.open(polcoms_z, 'NOWRITE');
    -0079 varid_pc = netcdf.inqVarID(nc, 'depth'); 
    -0080 pc.depth.data = double(netcdf.getVar(nc, varid_pc, 'single'));
    -0081 try
    -0082     pc.depth.units = netcdf.getAtt(nc, varid_pc, 'units');
    -0083 catch
    -0084     pc.depth.units = [];
    -0085 end
    -0086 varid_pc = netcdf.inqVarID(nc, 'pdepth'); 
    -0087 pc.pdepth.data = double(netcdf.getVar(nc, varid_pc, 'single'));
    -0088 try
    -0089     pc.pdepth.units = netcdf.getAtt(nc, varid_pc, 'units');
    -0090 catch
    -0091     pc.pdepth.units = [];
    -0092 end
    -0093 netcdf.close(nc)
    -0094 
    -0095 % Data format:
    -0096 %
    -0097 %   pc.ETW.data and pc.x1X.data are y, x, sigma, time
    -0098 %
    -0099 [~, ~, nz, nt] = size(pc.ETW.data);
    -0100 
    -0101 % Make rectangular arrays for the nearest point lookup.
    -0102 [lon, lat] = meshgrid(pc.lon.data, pc.lat.data);
    -0103 
    -0104 % Find the nearest POLCOMS point to each point in the FVCOM open boundaries
    -0105 fvlon = Mobj.lon(Mobj.obc_nodes(Mobj.obc_nodes ~= 0));
    -0106 fvlat = Mobj.lat(Mobj.obc_nodes(Mobj.obc_nodes ~= 0));
    -0107 
    -0108 % Number of boundary nodes
    -0109 nf = sum(Mobj.nObcNodes);
    -0110 % Number of sigma layers.
    -0111 fz = size(Mobj.siglayz, 2);
    +0043 % Author(s):
    +0044 %    Pierre Cazenave (Plymouth Marine Laboratory)
    +0045 %
    +0046 % Revision history
    +0047 %    2013-02-07 First version.
    +0048 %    2013-02-27 Change the vertical interpolation to be scaled within the
    +0049 %    POLCOMS-ERSEM depth range for the current node. The net result is that
    +0050 %    the vertical profiles are squashed or stretched to fit within the
    +0051 %    FVCOM depths. This means the full profile structure is maintained in
    +0052 %    the resulting FVCOM boundary input despite the differing depths at the
    +0053 %    FVCOM boundary node.
    +0054 %    2013-06-03 Fix some bugs in the way the open boundary node values were
    +0055 %    stored (the order in which they were stored did not match the order of
    +0056 %    the nodes in Casename_obc.dat). Also fix the order of the vertically
    +0057 %    interpolated values so that FVCOM starts at the surface instead of
    +0058 %    mirroring POLCOMS' approach (where the first value is the seabed). The
    +0059 %    effect of these two fixes (nodes and vertical) should match what FVCOM
    +0060 %    expects. Also add a set of figures (commented out) at the end for
    +0061 %    diagnostic purposes.
    +0062 %
    +0063 %==========================================================================
    +0064 
    +0065 subname = 'get_POLCOMS_tsobc';
    +0066 
    +0067 global ftbverbose;
    +0068 if ftbverbose
    +0069     fprintf('\n')
    +0070     fprintf(['begin : ' subname '\n'])
    +0071 end
    +0072 
    +0073 wasOpened = false;
    +0074 if license('test', 'Distrib_Computing_Toolbox')
    +0075     % We have the Parallel Computing Toolbox, so launch a bunch of workers.
    +0076     if matlabpool('size') == 0
    +0077         % Force pool to be local in case we have remote pools available.
    +0078         matlabpool open local
    +0079         wasOpened = true;
    +0080     end
    +0081 end
    +0082 
    +0083 varlist = {'lon', 'lat', 'ETWD', 'x1XD', 'time', 'depth', 'pdepthD'};
    +0084 
    +0085 % Data format:
    +0086 %
    +0087 %   pc.ETWD.data and pc.x1XD.data are y, x, sigma, time
    +0088 %
    +0089 pc = get_POLCOMS_netCDF(ts, varlist);
    +0090 
    +0091 [~, ~, nz, nt] = size(pc.ETWD.data);
    +0092 
    +0093 % Make rectangular arrays for the nearest point lookup.
    +0094 [lon, lat] = meshgrid(pc.lon.data, pc.lat.data);
    +0095 
    +0096 %oNodes = Mobj.obc_nodes(Mobj.obc_nodes ~= 0);
    +0097 % Change the way the nodes are listed to match the order in the
    +0098 % Casename_obc.dat file.
    +0099 tmpObcNodes = Mobj.obc_nodes';
    +0100 oNodes = tmpObcNodes(tmpObcNodes ~= 0)';
    +0101 
    +0102 fvlon = Mobj.lon(oNodes);
    +0103 fvlat = Mobj.lat(oNodes);
    +0104 
    +0105 % Number of boundary nodes
    +0106 nf = sum(Mobj.nObcNodes);
    +0107 % Number of sigma layers.
    +0108 fz = size(Mobj.siglayz, 2);
    +0109 
    +0110 fvtemp = nan(nf, fz, nt); % FVCOM interpolated temperatures
    +0111 fvsal = nan(nf, fz, nt); % FVCOM interpolated salinities
     0112 
    -0113 % itemp = nan(nf, nz, nt); % POLCOMS interpolated temperatures
    -0114 % isal = nan(nf, nz, nt); % POLCOMS interpolated salinities
    -0115 fvtemp = nan(nf, fz, nt); % FVCOM interpolated temperatures
    -0116 fvsal = nan(nf, fz, nt); % FVCOM interpolated salinities
    -0117 
    -0118 if ftbverbose
    -0119     tic
    -0120 end
    -0121 for t = 1:nt
    -0122     % Get the current 3D array of POLCOMS results.
    -0123     pctemp3 = pc.ETW.data(:, :, :, t);
    -0124     pcsal3 = pc.x1X.data(:, :, :, t);
    -0125     
    -0126     % Preallocate the intermediate results arrays.
    -0127     itempz = nan(nf, nz);
    -0128     isalz = nan(nf, nz);
    -0129     idepthz = nan(nf, nz);
    -0130     
    -0131     for j = 1:nz
    -0132         % Now extract the relevant layer from the 3D subsets. Transpose the
    -0133         % data to be (x, y) rather than (y, x).
    -0134         pctemp2 = pctemp3(:, :, j)';
    -0135         pcsal2 = pcsal3(:, :, j)';
    -0136         pcdepth2 = squeeze(pc.depth.data(:, :, j, t))';
    -0137        
    -0138         % Create new arrays which will be flattened when masking (below).
    -0139         tpctemp2 = pctemp2;
    -0140         tpcsal2 = pcsal2;
    -0141         tpcdepth2 = pcdepth2;
    -0142         tlon = lon;
    -0143         tlat = lat;
    -0144         
    -0145         % Create and apply a mask to remove values outside the domain. This
    -0146         % inevitably flattens the arrays, but it shouldn't be a problem
    -0147         % since we'll be searching for the closest values in such a manner
    -0148         % as is appropriate for an unstructured grid (i.e. we're assuming
    -0149         % the POLCOMS data is irregularly spaced).
    -0150         mask = tpcdepth2 < -20000;
    -0151         tpctemp2(mask) = [];
    -0152         tpcsal2(mask) = [];
    -0153         tpcdepth2(mask) = [];
    -0154         % Also apply the masks to the position arrays so we can't even find
    -0155         % positions outside the domain, effectively meaning if a value is
    -0156         % outside the domain, the nearest value to the boundary node will
    -0157         % be used.
    -0158         tlon(mask) = [];
    -0159         tlat(mask) = [];
    -0160         
    -0161         % Preallocate the intermediate results arrays.
    -0162         itempobc = nan(nf, 1);
    -0163         isalobc = nan(nf, 1);
    -0164         idepthobc = nan(nf, 1);
    -0165         
    -0166         % Speed up the tightest loop with a parallelized loop.
    -0167         parfor i = 1:nf
    -0168             % Now we can do each position within the 2D layer.
    +0113 if ftbverbose
    +0114     tic
    +0115 end
    +0116 for t = 1:nt
    +0117     if ftbverbose
    +0118         fprintf('%s : %i of %i timesteps... ', subname, t, nt)
    +0119     end
    +0120     % Get the current 3D array of PML POLCOMS-ERSEM results.
    +0121     pctemp3 = pc.ETWD.data(:, :, :, t);
    +0122     pcsalt3 = pc.x1XD.data(:, :, :, t);
    +0123     
    +0124     % Flip the vertical layer dimension to make the POLCOMS data go from
    +0125     % surface to seabed to match its depth data and to match how FVCOM
    +0126     % works.
    +0127     pctemp3 = flipdim(pctemp3, 3);
    +0128     pcsalt3 = flipdim(pcsalt3, 3);
    +0129 
    +0130     % Preallocate the intermediate results arrays.
    +0131     itempz = nan(nf, nz);
    +0132     isalz = nan(nf, nz);
    +0133     idepthz = nan(nf, nz);
    +0134 
    +0135     for j = 1:nz
    +0136         % Now extract the relevant layer from the 3D subsets. Transpose the
    +0137         % data to be (x, y) rather than (y, x).
    +0138         pctemp2 = pctemp3(:, :, j)';
    +0139         pcsalt2 = pcsalt3(:, :, j)';
    +0140         pcdepth2 = squeeze(pc.depth.data(:, :, j, t))';
    +0141 
    +0142         % Create new arrays which will be flattened when masking (below).
    +0143         tpctemp2 = pctemp2;
    +0144         tpcsalt2 = pcsalt2;
    +0145         tpcdepth2 = pcdepth2;
    +0146         tlon = lon;
    +0147         tlat = lat;
    +0148 
    +0149         % Create and apply a mask to remove values outside the domain. This
    +0150         % inevitably flattens the arrays, but it shouldn't be a problem
    +0151         % since we'll be searching for the closest values in such a manner
    +0152         % as is appropriate for an unstructured grid (i.e. we're assuming
    +0153         % the PML POLCOMS-ERSEM data is irregularly spaced).
    +0154         mask = tpcdepth2 > 20000;
    +0155         tpctemp2(mask) = [];
    +0156         tpcsalt2(mask) = [];
    +0157         tpcdepth2(mask) = [];
    +0158         % Also apply the masks to the position arrays so we can't even find
    +0159         % positions outside the domain, effectively meaning if a value is
    +0160         % outside the domain, the nearest value to the boundary node will
    +0161         % be used.
    +0162         tlon(mask) = [];
    +0163         tlat(mask) = [];
    +0164 
    +0165         % Preallocate the intermediate results arrays.
    +0166         itempobc = nan(nf, 1);
    +0167         isalobc = nan(nf, 1);
    +0168         idepthobc = nan(nf, 1);
     0169 
    -0170             fx = fvlon(i);
    -0171             fy = fvlat(i);
    -0172 
    -0173             [~, ii] = sort(sqrt((tlon - fx).^2 + (tlat - fy).^2));
    -0174             % Get the n nearest nodes from POLCOMS (more? fewer?).
    -0175             ixy = ii(1:16);
    +0170         % Speed up the tightest loop with a parallelized loop.
    +0171         parfor i = 1:nf
    +0172             % Now we can do each position within the 2D layer.
    +0173 
    +0174             fx = fvlon(i);
    +0175             fy = fvlat(i);
     0176 
    -0177             % Get the variables into static variables for the
    -0178             % parallelisation.
    -0179             plon = tlon(ixy);
    -0180             plat = tlat(ixy);
    -0181             ptemp = tpctemp2(ixy);
    -0182             psal = tpcsal2(ixy);
    -0183             pdepth = tpcdepth2(ixy);
    -0184             
    -0185             % Use a triangulation to do the horizontal interpolation.
    -0186             tritemp = TriScatteredInterp(plon', plat', ptemp', 'natural');
    -0187             trisal = TriScatteredInterp(plon', plat', psal', 'natural');
    -0188             triz = TriScatteredInterp(plon', plat', pdepth', 'natural');
    -0189             itempobc(i) = tritemp(fx, fy);
    -0190             isalobc(i) = trisal(fx, fy);
    -0191             idepthobc(i) = triz(fx, fy);
    -0192             
    -0193             % Check all three, though if one is NaN, they all will be.
    -0194             if isnan(itempobc(i)) || isnan(isalobc(i)) || isnan(idepthobc(i))
    -0195                 warning('FVCOM boundary node at %f, %f is outside the POLCOMS domain. Setting to the closest POLCOMS value.', fx, fy)
    -0196                 itempobc(i) = tpctemp2(ii(1));
    -0197                 isalobc(i) = tpcsal2(ii(1));
    -0198                 idepthobc(i) = tpcdepth2(ii(1));
    -0199             end
    -0200         end
    -0201         
    -0202         % Put the results in this intermediate array.
    -0203         itempz(:, j) = itempobc;
    -0204         isalz(:, j) = isalobc;
    -0205         idepthz(:, j) = idepthobc;
    -0206     end
    -0207 
    -0208     % Now we've interpolated in space, we can interpolate the z-values
    -0209     % to the sigma depths.
    -0210     oNodes = Mobj.obc_nodes(Mobj.obc_nodes ~= 0);
    -0211     for zi = 1:fz
    -0212 
    -0213         % Preallocate the output arrays
    -0214         fvtempz = nan(nf, fz);
    -0215         fvsalz = nan(nf, fz);
    +0177             [~, ii] = sort(sqrt((tlon - fx).^2 + (tlat - fy).^2));
    +0178             % Get the n nearest nodes from PML POLCOMS-ERSEM data (more?
    +0179             % fewer?).
    +0180             ixy = ii(1:16);
    +0181 
    +0182             % Get the variables into static variables for the
    +0183             % parallelisation.
    +0184             plon = tlon(ixy);
    +0185             plat = tlat(ixy);
    +0186             ptemp = tpctemp2(ixy);
    +0187             psal = tpcsalt2(ixy);
    +0188             pdepth = tpcdepth2(ixy);
    +0189 
    +0190             % Use a triangulation to do the horizontal interpolation.
    +0191             tritemp = TriScatteredInterp(plon', plat', ptemp', 'natural');
    +0192             trisal = TriScatteredInterp(plon', plat', psal', 'natural');
    +0193             triz = TriScatteredInterp(plon', plat', pdepth', 'natural');
    +0194             itempobc(i) = tritemp(fx, fy);
    +0195             isalobc(i) = trisal(fx, fy);
    +0196             idepthobc(i) = triz(fx, fy);
    +0197 
    +0198             % Check all three, though if one is NaN, they all will be.
    +0199             if isnan(itempobc(i)) || isnan(isalobc(i)) || isnan(idepthobc(i))
    +0200                 warning('FVCOM boundary node at %f, %f is outside the PML POLCOMS-ERSEM domain. Setting to the closest PML POLCOMS-ERSEM value.', fx, fy)
    +0201                 itempobc(i) = tpctemp2(ii(1));
    +0202                 isalobc(i) = tpcsalt2(ii(1));
    +0203                 idepthobc(i) = tpcdepth2(ii(1));
    +0204             end
    +0205         end
    +0206 
    +0207         % Put the results in the intermediate array.
    +0208         itempz(:, j) = itempobc;
    +0209         isalz(:, j) = isalobc;
    +0210         idepthz(:, j) = idepthobc;
    +0211 
    +0212     end
    +0213 
    +0214     % Now we've interpolated in space, we can interpolate the z-values
    +0215     % to the sigma depths.
     0216 
    -0217         for pp = 1:nf
    -0218             % Get the FVCOM depths at this node
    -0219             tfz = Mobj.siglayz(oNodes(pp), :);
    -0220             % Now get the interpolated POLCOMS depth at this node
    -0221             tpz = idepthz(pp, :);
    -0222 
    -0223             % Get the temperature and salinity values for this node and
    -0224             % interpolate down the water column (from POLCOMS to FVCOM).
    -0225             % TODO: Use csaps for the vertical interplation/subsampling at
    -0226             % each location. Alternatively, the pchip interp1 method seems
    -0227             % to do a decent job of the interpolation; it might be a more
    -0228             % suitable candidate in the absence of csaps. In fact, the demo
    -0229             % of csaps in the MATLAB documentation makes the interpolation
    -0230             % look horrible (shaving off extremes). I think pchip is
    -0231             % better.
    -0232             if ~isnan(tpz)
    -0233                 fvtempz(pp, :) = interp1(tpz, itempz(pp, :), tfz, 'linear', 'extrap');
    -0234                 fvsalz(pp, :) = interp1(tpz, isalz(pp, :), tfz, 'linear', 'extrap');
    -0235             else
    -0236                 warning('Should never see this... ') % because we test for NaNs when fetching the values.
    -0237                 warning('FVCOM boundary node at %f, %f is outside the POLCOMS domain. Skipping.', fvlon(pp), fvlat(pp))
    -0238                 continue
    -0239             end
    -0240         end
    -0241     end
    -0242     
    -0243     % The horizontally-interpolated values in the final results array.
    -0244 %     itemp(:, :, t) = itempz;
    -0245 %     isal(:, :, t) = isalz;
    -0246     % The horizontally- and vertically-interpolated values in the final
    -0247     % FVCOM results array.
    -0248     fvtemp(:, :, t) = fvtempz;
    -0249     fvsal(:, :, t) = fvsalz;
    -0250 end
    -0251 if ftbverbose
    -0252     toc
    -0253 end
    -0254 
    -0255 Mobj.temperature = fvtemp;
    -0256 Mobj.salt = fvsal;
    -0257 
    -0258 % Do we have to interpolate to the FVCOM time series? Looking at page 325
    -0259 % of the FVCOM manual, it looks like the temperature and salinity are on a
    -0260 % different time sampling from the other example files (14 time steps vs.
    -0261 % 3625 for _wnd.nc or 43922 for _julain_obc.nc (i.e. surface elevation at
    -0262 % the boundary)). That's not to say those files were all used in the same
    -0263 % model run... In the interim, just convert the current times to Modified
    -0264 % Julian Day (this is a bit ugly).
    -0265 % pc.time.yyyymmdd = strtrim(regexp(pc.time.units, 'since', 'split'));
    -0266 % pc.time.yyyymmdd = str2double(regexp(pc.time.yyyymmdd{end}, '-', 'split'));
    -0267 % Mobj.ts_times = greg2mjulian(pc.time.yyyymmdd(1), pc.time.yyyymmdd(2), pc.time.yyyymmdd(3), 0, 0, 0) + (pc.time.data / 3600 / 24);
    -0268 
    -0269 % Convert the POLCOMS times to Modified Julian Day (this is a very ugly).
    -0270 pc.time.yyyymmdd = strtrim(regexp(pc.time.units, 'since', 'split'));
    -0271 pc.time.strtime = regexp(pc.time.yyyymmdd{end}, '-', 'split');
    -0272 % This new version of the time has the year in a weird format (yr.#). We
    -0273 % thus need to split it again to get the decimal year (post-2000 only?).
    -0274 pc.time.strtimeyr = regexp(pc.time.strtime, '\.', 'split');
    -0275 pc.time.yyyymmdd = str2double([pc.time.strtimeyr{1}(2), pc.time.strtime{2:3}]);
    -0276 pc.time.yyyymmdd(1) = pc.time.yyyymmdd(1) + 2000; % add full year.
    -0277 Mobj.ts_times = greg2mjulian(pc.time.yyyymmdd(1), pc.time.yyyymmdd(2), pc.time.yyyymmdd(3), 0, 0, 0) + (pc.time.data / 3600 / 24);
    -0278 
    -0279 if ftbverbose
    -0280     fprintf(['end   : ' subname '\n'])
    -0281 end
    -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +0217 % Preallocate the output arrays +0218 fvtempz = nan(nf, fz); +0219 fvsalz = nan(nf, fz); +0220 +0221 for pp = 1:nf +0222 % Get the FVCOM depths at this node +0223 tfz = Mobj.siglayz(oNodes(pp), :); +0224 % Now get the interpolated PML POLCOMS-ERSEM depth at this node +0225 tpz = idepthz(pp, :); +0226 +0227 % To ensure we get the full vertical expression of the vertical +0228 % profiles, we need to normalise the POLCOMS-ERSEM and FVCOM +0229 % depths to the same range. This is because in instances where +0230 % FVCOM depths are shallower (e.g. in coastal regions), if we +0231 % don't normalise the depths, we end up truncating the vertical +0232 % profile. This approach ensures we always use the full +0233 % vertical profile, but we're potentially squeezing it into a +0234 % smaller depth. +0235 A = max(tpz); +0236 B = min(tpz); +0237 C = max(tfz); +0238 D = min(tfz); +0239 norm_tpz = (((D - C) * (tpz - A)) / (B - A)) + C; +0240 +0241 % Get the temperature and salinity values for this node and +0242 % interpolate down the water column (from PML POLCOMS-ERSEM to +0243 % FVCOM). I had originally planned to use csaps for the +0244 % vertical interplation/subsampling at each location. However, +0245 % the demo of csaps in the MATLAB documentation makes the +0246 % interpolation look horrible (shaving off extremes). interp1 +0247 % provides a range of interpolation schemes, of which pchip +0248 % seems to do a decent job of the interpolation (at least +0249 % qualitatively). +0250 if ~isnan(tpz) +0251 fvtempz(pp, :) = interp1(norm_tpz, itempz(pp, :), tfz, 'pchip', 'extrap'); +0252 fvsalz(pp, :) = interp1(norm_tpz, isalz(pp, :), tfz, 'pchip', 'extrap'); +0253 else +0254 warning('Should never see this... ') % because we test for NaNs when fetching the values. +0255 warning('FVCOM boundary node at %f, %f is outside the PML POLCOMS-ERSEM domain. Skipping.', fvlon(pp), fvlat(pp)) +0256 continue +0257 end +0258 end +0259 +0260 % The horizontally- and vertically-interpolated values in the final +0261 % FVCOM results array. +0262 fvtemp(:, :, t) = fvtempz; +0263 fvsal(:, :, t) = fvsalz; +0264 +0265 if ftbverbose +0266 fprintf('done.\n') +0267 end +0268 end +0269 if ftbverbose +0270 toc +0271 end +0272 +0273 Mobj.temperature = fvtemp; +0274 Mobj.salt = fvsal; +0275 +0276 % Convert the current times to Modified Julian Day (this is a bit ugly). +0277 pc.time.all = strtrim(regexp(pc.time.units, 'since', 'split')); +0278 pc.time.datetime = strtrim(regexp(pc.time.all{end}, ' ', 'split')); +0279 pc.time.ymd = str2double(strtrim(regexp(pc.time.datetime{1}, '-', 'split'))); +0280 pc.time.hms = str2double(strtrim(regexp(pc.time.datetime{2}, ':', 'split'))); +0281 +0282 Mobj.ts_times = greg2mjulian(... +0283 pc.time.ymd(1), ... +0284 pc.time.ymd(2), ... +0285 pc.time.ymd(3), ... +0286 pc.time.hms(1), ... +0287 pc.time.hms(2), ... +0288 pc.time.hms(3)) + (pc.time.data / 3600 / 24); +0289 +0290 % Close the MATLAB pool if we opened it. +0291 if wasOpened +0292 matlabpool close +0293 end +0294 +0295 if ftbverbose +0296 fprintf(['end : ' subname '\n']) +0297 end +0298 +0299 +0300 %% +0301 % % Plot a vertical profile for a boundary node (for my Irish Sea case, this +0302 % % is one of the ones along the Celtic Sea boundary). Also plot the +0303 % % distribution of interpolated values over the POLCOMS data. Add the +0304 % % location of the vertical profile (both FVCOM and POLCOMS) to the plot. +0305 % nn = 55; % open boundary index +0306 % tt = 1; % time index +0307 % +0308 % % Get the corresponding indices for the POLCOMS data +0309 % [~, xidx] = min(abs(lon(1, :) - fvlon(nn))); +0310 % [~, yidx] = min(abs(lat(:, 1) - fvlat(nn))); +0311 % +0312 % % close all +0313 % +0314 % figure +0315 % clf +0316 % subplot(2,2,1) +0317 % plot(Mobj.temperature(nn, :, 1), Mobj.siglayz(oNodes(nn), :), 'x-') +0318 % xlabel('Temperature (^{\circ}C)') +0319 % ylabel('Depth (m)') +0320 % title('FVCOM') +0321 % +0322 % subplot(2,2,2) +0323 % % Although POLCOMS stores its temperature values from seabed to surface, +0324 % % the depths are stored surface to seabed. Nice. +0325 % plot(squeeze(pc.ETWD.data(xidx, yidx, :, 1)), flipud(squeeze(pc.depth.data(xidx, yidx, :, 1))), 'rx-') +0326 % xlabel('Temperature (^{\circ}C)') +0327 % ylabel('Depth (m)') +0328 % title('POLCOMS') +0329 % +0330 % subplot(2,2,3) +0331 % plot(Mobj.temperature(nn, :, tt), 1:fz, 'x-') +0332 % xlabel('Temperature (^{\circ}C)') +0333 % ylabel('Array index') +0334 % title('FVCOM') +0335 % +0336 % subplot(2,2,4) +0337 % plot(squeeze(pc.ETWD.data(xidx, yidx, :, tt)), 1:nz, 'rx-') +0338 % xlabel('Temperature (^{\circ}C)') +0339 % ylabel('Array index') +0340 % title('POLCOMS') +0341 % +0342 % % Figure to check everything's as we'd expect. Plot first time step with +0343 % % the POLCOMS surface temperature as a background with the interpolated +0344 % % boundary node surface values on top. +0345 % +0346 % figure +0347 % clf +0348 % % Plot POLCOMS surface data (last sigma layer) +0349 % dx = mean(diff(pc.lon.data)); +0350 % dy = mean(diff(pc.lat.data)); +0351 % pcolor(pc.lon.data - (dx / 2), pc.lat.data - (dy / 2), ... +0352 % squeeze(pc.ETWD.data(:, :, end, tt))') +0353 % shading flat +0354 % axis('equal', 'tight') +0355 % daspect([1.5, 1, 1]) +0356 % hold on +0357 % % Add the interpolated surface data (first sigma layer) +0358 % scatter(Mobj.lon(oNodes), Mobj.lat(oNodes), repmat(40, size(Mobj.lon(oNodes))), Mobj.temperature(:, 1, tt), 'filled', 'MarkerEdgeColor', 'k') +0359 % axis([min(Mobj.lon(oNodes)), max(Mobj.lon(oNodes)), min(Mobj.lat(oNodes)), max(Mobj.lat(oNodes))]) +0360 % caxis([6, 12]) +0361 % plot(lon(yidx, xidx), lat(yidx, xidx), 'rs') % polcoms is all backwards +0362 % plot(Mobj.lon(oNodes(nn)), Mobj.lat(oNodes(nn)), 'wo') +0363 % colorbar
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/get_POLCOMS_tsobc_gcoms.html b/doc/fvcom_prepro/get_POLCOMS_tsobc_gcoms.html new file mode 100644 index 0000000000000000000000000000000000000000..58d7085373083da8803e6e67ee5a9c9a4a3adccb --- /dev/null +++ b/doc/fvcom_prepro/get_POLCOMS_tsobc_gcoms.html @@ -0,0 +1,365 @@ + + + + Description of get_POLCOMS_tsobc_gcoms + + + + + + + + + +
    Home > fvcom_prepro > get_POLCOMS_tsobc_gcoms.m
    + + + +

    get_POLCOMS_tsobc_gcoms +

    + +

    PURPOSE ^

    +
    Read temperature and salinity from the PML POLCOMS-ERSEM NetCDF model
    + +

    SYNOPSIS ^

    +
    function Mobj = get_POLCOMS_tsobc_gcoms(Mobj, ts)
    + +

    DESCRIPTION ^

    +
     Read temperature and salinity from the PML POLCOMS-ERSEM NetCDF model
    + output files and interpolate onto the open boundaries in Mobj.
    +
    + function Mobj = get_POLCOMS_tsobc(Mobj, ts, polcoms_bathy, varlist)
    +
    + DESCRIPTION:
    +    Interpolate temperature and salinity values onto the FVCOM open
    +    boundaries at all sigma levels.
    +
    + INPUT:
    +   Mobj    = MATLAB mesh structure which must contain:
    +               - Mobj.siglayz - sigma layer depths for all model nodes.
    +               - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    +               - Mobj.obc_nodes - list of open boundary node inidices.
    +               - Mobj.nObcNodes - number of nodes in each open boundary.
    +   ts      = Cell array of PML POLCOMS-ERSEM NetCDF file(s) in which 4D
    +             variables of temperature and salinity (called 'ETWD' and
    +             'x1XD') exist. Their shape should be (y, x, sigma, time).
    +
    + NOTES:
    +
    +   - If you supply multiple files in ts, there are a few assumptions:
    +
    +       - Variables are only appended if there are 4 dimensions; fewer than
    +       that, and the values are assumed to be static across all the given
    +       files (e.g. longitude, latitude etc.). The fourth dimension is
    +       time.
    +       - The order of the files given should be chronological.
    + 
    +   - The NetCDF files used here are those from the PML POLCOMS-ERSEM model
    +   output.
    +
    + OUTPUT:
    +    Mobj = MATLAB structure in which three new fields (called temperature,
    +           salinity and ts_time). temperature and salinity have sizes
    +           (sum(Mobj.nObcNodes), sigma, time). The time dimension is
    +           determined based on the input NetCDF file. The ts_time variable
    +           is just the input file times in Modified Julian Day.
    +
    + EXAMPLE USAGE
    +    Mobj = get_POLCOMS_tsobc(Mobj, ts, depth)
    +
    + Author(s):
    +    Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +    2013-02-07 First version based on get_POLCOMS_tsobc.m.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function Mobj = get_POLCOMS_tsobc_gcoms(Mobj, ts)
    +0002 % Read temperature and salinity from the PML POLCOMS-ERSEM NetCDF model
    +0003 % output files and interpolate onto the open boundaries in Mobj.
    +0004 %
    +0005 % function Mobj = get_POLCOMS_tsobc(Mobj, ts, polcoms_bathy, varlist)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %    Interpolate temperature and salinity values onto the FVCOM open
    +0009 %    boundaries at all sigma levels.
    +0010 %
    +0011 % INPUT:
    +0012 %   Mobj    = MATLAB mesh structure which must contain:
    +0013 %               - Mobj.siglayz - sigma layer depths for all model nodes.
    +0014 %               - Mobj.lon, Mobj.lat - node coordinates (lat/long).
    +0015 %               - Mobj.obc_nodes - list of open boundary node inidices.
    +0016 %               - Mobj.nObcNodes - number of nodes in each open boundary.
    +0017 %   ts      = Cell array of PML POLCOMS-ERSEM NetCDF file(s) in which 4D
    +0018 %             variables of temperature and salinity (called 'ETWD' and
    +0019 %             'x1XD') exist. Their shape should be (y, x, sigma, time).
    +0020 %
    +0021 % NOTES:
    +0022 %
    +0023 %   - If you supply multiple files in ts, there are a few assumptions:
    +0024 %
    +0025 %       - Variables are only appended if there are 4 dimensions; fewer than
    +0026 %       that, and the values are assumed to be static across all the given
    +0027 %       files (e.g. longitude, latitude etc.). The fourth dimension is
    +0028 %       time.
    +0029 %       - The order of the files given should be chronological.
    +0030 %
    +0031 %   - The NetCDF files used here are those from the PML POLCOMS-ERSEM model
    +0032 %   output.
    +0033 %
    +0034 % OUTPUT:
    +0035 %    Mobj = MATLAB structure in which three new fields (called temperature,
    +0036 %           salinity and ts_time). temperature and salinity have sizes
    +0037 %           (sum(Mobj.nObcNodes), sigma, time). The time dimension is
    +0038 %           determined based on the input NetCDF file. The ts_time variable
    +0039 %           is just the input file times in Modified Julian Day.
    +0040 %
    +0041 % EXAMPLE USAGE
    +0042 %    Mobj = get_POLCOMS_tsobc(Mobj, ts, depth)
    +0043 %
    +0044 % Author(s):
    +0045 %    Pierre Cazenave (Plymouth Marine Laboratory)
    +0046 %
    +0047 % Revision history
    +0048 %    2013-02-07 First version based on get_POLCOMS_tsobc.m.
    +0049 %
    +0050 %==========================================================================
    +0051 
    +0052 subname = 'get_POLCOMS_tsobc_gcoms';
    +0053 
    +0054 global ftbverbose;
    +0055 if ftbverbose
    +0056     fprintf('\n')
    +0057     fprintf(['begin : ' subname '\n'])
    +0058     fprintf(['Expecting two files  : ' ts{1} '\n' ts{2} '\n'])
    +0059 end
    +0060 
    +0061 varlist = {'lon', 'lat', 'ETW', 'x1X', 'time'};
    +0062 
    +0063 varlistdmeaneco3d = {'depth', 'pdepth'};
    +0064 
    +0065 % Data format:
    +0066 %
    +0067 %   pc.ETWD.data and pc.x1XD.data are y, x, sigma, time
    +0068 %
    +0069 dd = 1;
    +0070 catstr = 'pc=catstruct(';
    +0071 for ff = 1:2:length(ts)-1
    +0072     pc = get_POLCOMS_netCDF(ts{ff}, varlist);
    +0073     pcdmean = get_POLCOMS_netCDF(ts{ff+1}, varlistdmeaneco3d);
    +0074     eval(['dump',num2str(dd),'=catstruct(pc,pcdmean);'])
    +0075     dd = dd+1;
    +0076     catstr = [catstr,'dump',num2str(dd),','];
    +0077 end
    +0078 eval([catstr(1:end-1),');'])
    +0079 clear pcdmean dump*
    +0080 [~, ~, nz, nt] = size(pc.ETW.data);
    +0081 
    +0082 % Make rectangular arrays for the nearest point lookup.
    +0083 [lon, lat] = meshgrid(pc.lon.data, pc.lat.data);
    +0084 
    +0085 fvlon = Mobj.lon(Mobj.obc_nodes(Mobj.obc_nodes ~= 0));
    +0086 fvlat = Mobj.lat(Mobj.obc_nodes(Mobj.obc_nodes ~= 0));
    +0087 
    +0088 % Number of boundary nodes
    +0089 nf = sum(Mobj.nObcNodes);
    +0090 % Number of sigma layers.
    +0091 fz = size(Mobj.siglayz, 2);
    +0092 
    +0093 fvtemp = nan(nf, fz, nt); % FVCOM interpolated temperatures
    +0094 fvsal = nan(nf, fz, nt); % FVCOM interpolated salinities
    +0095 
    +0096 if ftbverbose
    +0097     tic
    +0098 end
    +0099 for t = 1:nt
    +0100     if ftbverbose
    +0101         fprintf('%s : %i of %i timesteps... ', subname, t, nt)
    +0102     end
    +0103     % Get the current 3D array of PML POLCOMS-ERSEM results.
    +0104     pctemp3 = pc.ETW.data(:, :, :, t);
    +0105     pcsalt3 = pc.x1X.data(:, :, :, t);
    +0106     
    +0107     % Preallocate the intermediate results arrays.
    +0108     itempz = nan(nf, nz);
    +0109     isalz = nan(nf, nz);
    +0110     idepthz = nan(nf, nz);
    +0111     
    +0112     for j = 1:nz
    +0113         % Now extract the relevant layer from the 3D subsets. Transpose the
    +0114         % data to be (x, y) rather than (y, x).
    +0115         pctemp2 = pctemp3(:, :, j)';
    +0116         pcsalt2 = pcsalt3(:, :, j)';
    +0117         pcdepth2 = squeeze(pc.depth.data(:, :, j, t))';
    +0118        
    +0119         % Create new arrays which will be flattened when masking (below).
    +0120         tpctemp2 = pctemp2;
    +0121         tpcsalt2 = pcsalt2;
    +0122         tpcdepth2 = pcdepth2;
    +0123         tlon = lon;
    +0124         tlat = lat;
    +0125         
    +0126         % Create and apply a mask to remove values outside the domain. This
    +0127         % inevitably flattens the arrays, but it shouldn't be a problem
    +0128         % since we'll be searching for the closest values in such a manner
    +0129         % as is appropriate for an unstructured grid (i.e. we're assuming
    +0130         % the PML POLCOMS-ERSEM data is irregularly spaced).
    +0131         mask = tpcdepth2 < -10e+10;
    +0132         tpctemp2(mask) = [];
    +0133         tpcsalt2(mask) = [];
    +0134         tpcdepth2(mask) = [];
    +0135         % Also apply the masks to the position arrays so we can't even find
    +0136         % positions outside the domain, effectively meaning if a value is
    +0137         % outside the domain, the nearest value to the boundary node will
    +0138         % be used.
    +0139         tlon(mask) = [];
    +0140         tlat(mask) = [];
    +0141         
    +0142         % Preallocate the intermediate results arrays.
    +0143         itempobc = nan(nf, 1);
    +0144         isalobc = nan(nf, 1);
    +0145         idepthobc = nan(nf, 1);
    +0146         
    +0147         % Speed up the tightest loop with a parallelized loop.
    +0148         parfor i = 1:nf
    +0149 %        for i = 1:nf
    +0150             % Now we can do each position within the 2D layer.
    +0151 
    +0152             fx = fvlon(i);
    +0153             fy = fvlat(i);
    +0154 
    +0155             [~, ii] = sort(sqrt((tlon - fx).^2 + (tlat - fy).^2));
    +0156             % Get the n nearest nodes from PML POLCOMS-ERSEM data (more?
    +0157             % fewer?).
    +0158             ixy = ii(1:16);
    +0159 
    +0160             % Get the variables into static variables for the
    +0161             % parallelisation.
    +0162             plon = tlon(ixy);
    +0163             plat = tlat(ixy);
    +0164             ptemp = tpctemp2(ixy);
    +0165             psal = tpcsalt2(ixy);
    +0166             pdepth = tpcdepth2(ixy);
    +0167             
    +0168             % Use a triangulation to do the horizontal interpolation.
    +0169             tritemp = TriScatteredInterp(plon', plat', ptemp', 'natural');
    +0170             trisal = TriScatteredInterp(plon', plat', psal', 'natural');
    +0171             triz = TriScatteredInterp(plon', plat', pdepth', 'natural');
    +0172             itempobc(i) = tritemp(fx, fy);
    +0173             isalobc(i) = trisal(fx, fy);
    +0174             idepthobc(i) = triz(fx, fy);
    +0175             
    +0176             % Check all three, though if one is NaN, they all will be.
    +0177             if isnan(itempobc(i)) || isnan(isalobc(i)) || isnan(idepthobc(i))
    +0178                 warning('FVCOM boundary node at %f, %f is outside the PML POLCOMS-ERSEM domain. Setting to the closest PML POLCOMS-ERSEM value.', fx, fy)
    +0179                 itempobc(i) = tpctemp2(ii(1));
    +0180                 isalobc(i) = tpcsalt2(ii(1));
    +0181                 idepthobc(i) = tpcdepth2(ii(1));
    +0182             end
    +0183         end
    +0184         
    +0185         % Put the results in this intermediate array.
    +0186         itempz(:, j) = itempobc;
    +0187         isalz(:, j) = isalobc;
    +0188         idepthz(:, j) = idepthobc;
    +0189     end
    +0190 
    +0191     % Now we've interpolated in space, we can interpolate the z-values
    +0192     % to the sigma depths.
    +0193     oNodes = Mobj.obc_nodes(Mobj.obc_nodes ~= 0);
    +0194 
    +0195         % Preallocate the output arrays
    +0196         fvtempz = nan(nf, fz);
    +0197         fvsalz = nan(nf, fz);
    +0198 
    +0199         for pp = 1:nf
    +0200             % Get the FVCOM depths at this node
    +0201             tfz = Mobj.siglayz(oNodes(pp), :);
    +0202             % Now get the interpolated PML POLCOMS-ERSEM depth at this node
    +0203             tpz = idepthz(pp, :);
    +0204 
    +0205         % To ensure we get the full vertical expression of the vertical
    +0206         % profiles, we need to normalise the POLCOMS-ERSEM and FVCOM
    +0207         % depths to the same range. This is because in instances where
    +0208         % FVCOM depths are shallower (e.g. in coastal regions), if we
    +0209         % don't normalise the depths, we end up truncating the vertical
    +0210         % profile. This approach ensures we always use the full
    +0211         % vertical profile, but we're potentially squeezing it into a
    +0212         % smaller depth.
    +0213         A = max(tpz);
    +0214         B = min(tpz);
    +0215         C = max(tfz);
    +0216         D = min(tfz);
    +0217         norm_tpz = (((D - C) * (tpz - A)) / (B - A)) + C;
    +0218 
    +0219         % Get the temperature and salinity values for this node and
    +0220         % interpolate down the water column (from PML POLCOMS-ERSEM to
    +0221         % FVCOM). I had originally planned to use csaps for the
    +0222         % vertical interplation/subsampling at each location. However,
    +0223         % the demo of csaps in the MATLAB documentation makes the
    +0224         % interpolation look horrible (shaving off extremes). interp1
    +0225         % provides a range of interpolation schemes, of which pchip
    +0226         % seems to do a decent job of the interpolation (at least
    +0227         % qualitatively).
    +0228         if ~isnan(tpz)
    +0229             fvtempz(pp, :) = interp1(norm_tpz, itempz(pp, :), tfz, 'linear', 'extrap');
    +0230             fvsalz(pp, :) = interp1(norm_tpz, isalz(pp, :), tfz, 'linear', 'extrap');
    +0231         else
    +0232             warning('Should never see this... ') % because we test for NaNs when fetching the values.
    +0233             warning('FVCOM boundary node at %f, %f is outside the PML POLCOMS-ERSEM domain. Skipping.', fvlon(pp), fvlat(pp))
    +0234             continue
    +0235         end
    +0236     end
    +0237     
    +0238     % The horizontally- and vertically-interpolated values in the final
    +0239     % FVCOM results array.
    +0240     fvtemp(:, :, t) = fvtempz;
    +0241     fvsal(:, :, t) = fvsalz;
    +0242     
    +0243     if ftbverbose
    +0244         fprintf('done.\n')
    +0245     end
    +0246 end
    +0247 if ftbverbose
    +0248     toc
    +0249 end
    +0250 
    +0251 Mobj.temperature = fvtemp;
    +0252 Mobj.salt = fvsal;
    +0253 
    +0254 % Convert the current times to Modified Julian Day (this is a bit ugly).
    +0255 pc.time.all = strtrim(regexp(pc.time.units, 'since', 'split'));
    +0256 pc.time.datetime = strtrim(regexp(pc.time.all{end}, ' ', 'split'));
    +0257 pc.time.ymd = str2double(strtrim(regexp(pc.time.datetime{1}, '-', 'split')));
    +0258 pc.time.hms = str2double(strtrim(regexp(datestr(datenum(pc.time.ymd),'HH:MM:SS'), ':', 'split')));
    +0259 
    +0260 Mobj.ts_times = greg2mjulian(...
    +0261     pc.time.ymd(1), ...
    +0262     pc.time.ymd(2), ...
    +0263     pc.time.ymd(3), ...
    +0264     pc.time.hms(1), ...
    +0265     pc.time.hms(2), ...
    +0266     pc.time.hms(3)) + (pc.time.data / 3600 / 24);
    +0267 
    +0268 if ftbverbose
    +0269     fprintf(['end   : ' subname '\n'])
    +0270 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/graph.dot b/doc/fvcom_prepro/graph.dot new file mode 100644 index 0000000000000000000000000000000000000000..6871d282047f12690f4a841f4a8ea3e5c0ca8246 --- /dev/null +++ b/doc/fvcom_prepro/graph.dot @@ -0,0 +1,137 @@ +/* Created by mdot for Matlab */ +digraph m2html { + add_obc_nodes_graphic -> find_nearest_pt; + add_river_nodes_graphic -> find_nearest_pt; + add_sponge_nodes -> find_nearest_pt; + add_stations_list -> find_nearest_pt; + example -> add_coriolis; + example -> add_obc_nodes_list; + example -> add_river_nodes_list; + example -> elems2nodes; + example -> estimate_ts; + example -> example_FVCOM_river; + example -> example_FVCOM_tsobc; + example -> example_FVCOM_wind_ts; + example -> nodes2elems; + example -> plot_field; + example -> read_sms_mesh; + example -> set_spectide; + example -> setup_metrics; + example -> smoothfield; + example -> write_FVCOM_bath; + example -> write_FVCOM_bedflag; + example -> write_FVCOM_cor; + example -> write_FVCOM_grid; + example -> write_FVCOM_obc; + example -> write_FVCOM_sponge; + example -> write_FVCOM_z0; + example2 -> plot_field; + example2 -> read_fvcom_bath; + example2 -> read_fvcom_mesh; + example2 -> setup_metrics; + example2 -> smoothfield; + example2 -> write_FVCOM_bath; + example_FVCOM_river -> add_var_FVCOM_river; + example_FVCOM_river -> write_FVCOM_river; + example_init_lag -> plot_field; + example_init_lag -> read_fvcom_bath; + example_init_lag -> read_fvcom_mesh; + example_init_lag -> setup_metrics; + gen_semistructured_mesh -> make_blank_mesh; + gen_unstructured_mesh -> make_blank_mesh; + get_POLCOMS_meanflow -> get_POLCOMS_netCDF; + get_POLCOMS_meanflow -> nodes2elems; + get_POLCOMS_tsobc -> get_POLCOMS_netCDF; + get_POLCOMS_tsobc_gcoms -> get_POLCOMS_netCDF; + interp_POLCOMS2FVCOM -> get_POLCOMS_netCDF; + read_fvcom_mesh -> make_blank_mesh; + read_sms_mesh -> make_blank_mesh; + read_sms_mesh -> my_project; + set_elevtide -> write_FVCOM_elevtide; + set_spectide -> write_FVCOM_spectide; + wrf2fvcom_U10V10 -> my_project; + wrf2fvcom_U10V10 -> read_fvcom_mesh; + write_FVCOM_forcing -> nodes2elems; + + README [URL="README.html"]; + add_coriolis [URL="add_coriolis.html"]; + add_obc_nodes_graphic [URL="add_obc_nodes_graphic.html"]; + add_obc_nodes_list [URL="add_obc_nodes_list.html"]; + add_river_nodes_graphic [URL="add_river_nodes_graphic.html"]; + add_river_nodes_list [URL="add_river_nodes_list.html"]; + add_sigma_forDT [URL="add_sigma_forDT.html"]; + add_sponge_nodes [URL="add_sponge_nodes.html"]; + add_sponge_nodes_list [URL="add_sponge_nodes_list.html"]; + add_stations_list [URL="add_stations_list.html"]; + add_var_FVCOM_river [URL="add_var_FVCOM_river.html"]; + calc_sponge_radius [URL="calc_sponge_radius.html"]; + elems2nodes [URL="elems2nodes.html"]; + estimate_ts [URL="estimate_ts.html"]; + example [URL="example.html"]; + example2 [URL="example2.html"]; + example_FVCOM_river [URL="example_FVCOM_river.html"]; + example_FVCOM_tsobc [URL="example_FVCOM_tsobc.html"]; + example_FVCOM_wind_ts [URL="example_FVCOM_wind_ts.html"]; + example_FVCOM_wind_ts_speed [URL="example_FVCOM_wind_ts_speed.html"]; + example_init_lag [URL="example_init_lag.html"]; + example_my_project [URL="example_my_project.html"]; + find_nearest_pt [URL="find_nearest_pt.html"]; + gen_semistructured_mesh [URL="gen_semistructured_mesh.html"]; + gen_unstructured_mesh [URL="gen_unstructured_mesh.html"]; + generate_mjd [URL="generate_mjd.html"]; + get_AMM [URL="get_AMM.html"]; + get_FVCOM_rivers [URL="get_FVCOM_rivers.html"]; + get_HYCOM_forcing [URL="get_HYCOM_forcing.html"]; + get_MetUM_forcing [URL="get_MetUM_forcing.html"]; + get_NAE2_forcing [URL="get_NAE2_forcing.html"]; + get_NCEP_forcing [URL="get_NCEP_forcing.html"]; + get_POLCOMS_meanflow [URL="get_POLCOMS_meanflow.html"]; + get_POLCOMS_netCDF [URL="get_POLCOMS_netCDF.html"]; + get_POLCOMS_river_discharge [URL="get_POLCOMS_river_discharge.html"]; + get_POLCOMS_river_positions [URL="get_POLCOMS_river_positions.html"]; + get_POLCOMS_tsobc [URL="get_POLCOMS_tsobc.html"]; + get_POLCOMS_tsobc_gcoms [URL="get_POLCOMS_tsobc_gcoms.html"]; + get_POLPRED_spectide [URL="get_POLPRED_spectide.html"]; + get_zeta_xtide [URL="get_zeta_xtide.html"]; + inCell [URL="inCell.html"]; + interp_POLCOMS2FVCOM [URL="interp_POLCOMS2FVCOM.html"]; + make_blank_mesh [URL="make_blank_mesh.html"]; + my_project [URL="my_project.html"]; + nodes2elems [URL="nodes2elems.html"]; + plot_field [URL="plot_field.html"]; + read_ERA_wind [URL="read_ERA_wind.html"]; + read_NCEP_wind [URL="read_NCEP_wind.html"]; + read_fvcom_bath [URL="read_fvcom_bath.html"]; + read_fvcom_mesh [URL="read_fvcom_mesh.html"]; + read_sigma [URL="read_sigma.html"]; + read_sms_map [URL="read_sms_map.html"]; + read_sms_mesh [URL="read_sms_mesh.html"]; + set_elevtide [URL="set_elevtide.html"]; + set_spectide [URL="set_spectide.html"]; + setup_metrics [URL="setup_metrics.html"]; + smoothfield [URL="smoothfield.html"]; + smoothfield2 [URL="smoothfield2.html"]; + truncfield [URL="truncfield.html"]; + wrf2fvcom_U10V10 [URL="wrf2fvcom_U10V10.html"]; + write_FVCOM_bath [URL="write_FVCOM_bath.html"]; + write_FVCOM_bedflag [URL="write_FVCOM_bedflag.html"]; + write_FVCOM_cor [URL="write_FVCOM_cor.html"]; + write_FVCOM_elevtide [URL="write_FVCOM_elevtide.html"]; + write_FVCOM_forcing [URL="write_FVCOM_forcing.html"]; + write_FVCOM_grid [URL="write_FVCOM_grid.html"]; + write_FVCOM_meanflow [URL="write_FVCOM_meanflow.html"]; + write_FVCOM_meanflow_ascii [URL="write_FVCOM_meanflow_ascii.html"]; + write_FVCOM_obc [URL="write_FVCOM_obc.html"]; + write_FVCOM_obs_TS [URL="write_FVCOM_obs_TS.html"]; + write_FVCOM_restart [URL="write_FVCOM_restart.html"]; + write_FVCOM_river [URL="write_FVCOM_river.html"]; + write_FVCOM_river_nml [URL="write_FVCOM_river_nml.html"]; + write_FVCOM_spectide [URL="write_FVCOM_spectide.html"]; + write_FVCOM_sponge [URL="write_FVCOM_sponge.html"]; + write_FVCOM_stations [URL="write_FVCOM_stations.html"]; + write_FVCOM_tsobc [URL="write_FVCOM_tsobc.html"]; + write_FVCOM_wind_ts_speed [URL="write_FVCOM_wind_ts_speed.html"]; + write_FVCOM_z0 [URL="write_FVCOM_z0.html"]; + write_dtank [URL="write_dtank.html"]; + write_river_info [URL="write_river_info.html"]; +} \ No newline at end of file diff --git a/doc/fvcom_prepro/graph.html b/doc/fvcom_prepro/graph.html new file mode 100644 index 0000000000000000000000000000000000000000..5402331b0abd3cfaa77a1e9ae323ba7d4658d564 --- /dev/null +++ b/doc/fvcom_prepro/graph.html @@ -0,0 +1,108 @@ + + + + Dependency Graph for fvcom_prepro + + + + + + + + + + +
    < Master indexIndex for fvcom_prepro >
    +

    Dependency Graph for fvcom_prepro

    + +
    +Dependency Graph for fvcom_prepro + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    Generated on Tue 04-Jun-2013 12:12:56 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/graph.map b/doc/fvcom_prepro/graph.map new file mode 100644 index 0000000000000000000000000000000000000000..594255e29962b5a123f41040ed954dfc391066c1 --- /dev/null +++ b/doc/fvcom_prepro/graph.map @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/fvcom_prepro/graph.png b/doc/fvcom_prepro/graph.png new file mode 100644 index 0000000000000000000000000000000000000000..017cc1e8050d4e68f1186b4dbd35528ee75ad081 Binary files /dev/null and b/doc/fvcom_prepro/graph.png differ diff --git a/doc/fvcom_prepro/index.html b/doc/fvcom_prepro/index.html index c5199608797532ed2af969d3b7947c6c16495b09..98a0d2cdda885f072ed6f8a09a59142b27266521 100755 --- a/doc/fvcom_prepro/index.html +++ b/doc/fvcom_prepro/index.html @@ -19,13 +19,16 @@

    Matlab files in this directory:

    -
     READMEREADME for the FVCOM preprocessing toolbox
     add_coriolisGenerate latitude used for FVCOM Coriolis file
     add_obc_nodes_graphicAdd a set of obc nodes comprising a single obc boundary to Mesh structure
     add_obc_nodes_listAdd a set of obc nodes comprising a single obc boundary to Mesh structure
     add_river_nodes_graphicAdd a set of river nodes comprising a single river to Mesh structure
     add_river_nodes_listAdd a set of river nodes comprising a single river to Mesh structure
     add_sigma_forDT! this program adds sigma levels/layers and shifted layers to a netcdf file
     add_sponge_nodesAdd a set of sponge nodes comprising a single sponge layer to Mesh structure
     add_sponge_nodes_listAdd a set of sponge nodes comprising a single sponge layer to Mesh structure
     add_stations_listAdd a set of stations at which FVCOM will output time series.
     add_var_FVCOM_riveradd time dependent scalar variable to a Riverfile
     calc_sponge_radiusCalculate a variable sponge radius based on distance to the boundary
     elems2nodesTransfer a field from elements to vertices
     estimate_tsEstimate time step at each node
     exampleexample demonstrating reading in a 2DM file and constructing a model
     example2example demonstrating reading in an FVCOM mesh and smoothing the bathymetry
     example_FVCOM_riverexample file for dumping an FVCOM river file and adding sediment concentration
     example_FVCOM_tsobcexample file for dumping a file to force temperature and salinity at the open b.
     example_FVCOM_wind_tsexample file for FVCOM, time-varying/spatially constant wind forcing as stress
     example_FVCOM_wind_ts_speedexample file for FVCOM, time-varying/spatially constant wind forcing as speed
     example_my_projectfunction [out_east,out_north] = my_project(in_east,in_north,direction)
     find_nearest_ptFind nearest point in Mesh structure to (x,y)
     gen_semistructured_meshGenerate a semistructured mesh
     gen_unstructured_meshfunction gen_unstructured_mesh(lx,ly,res,cornermod)
     generate_mjd--------------------------------------------------------------
     get_AMMExtract boundary forcing information from NOC Operational Tide Surge
     get_HYCOM_forcingGet mean flow, temperature and salinity data from HYCOM model outputs
     get_NAE2_forcingGet the required parameters from NAE2 data to force FVCOM (through
     get_NCEP_forcingGet the required parameters from NCEP OPeNDAP data to force FVCOM
     get_POLCOMS_tsobcRead temperature and salinity from POLCOMS NetCDF model output files and
     get_POLPRED_spectideExtract tidal harmonic phases and amplitudes from POLPRED ASCII files.
     get_zeta_xtideExtract an elevation time series from a location using Xtide
     grid2fvcomInterpolate regularly gridded surface forcing data onto a given FVCOM
     inCellFind cell in mesh Mobj containing point (xpt,ypt)
     make_blank_meshMake a blank mesh object with default params
     my_projectSample user-defined projection and inverse projection of (lon,lat) to (x,y)
     nodes2elemsTransfer a field from vertices to elements
     plot_fieldPlot the mesh, user defined field, open boundary nodes, and river points
     read_ERA_windReads in ERA Interim files and outputs a struct containing the requested
     read_NCEP_windReads in two NCEP wind vector files (U and V) and outputs four arrays of
     read_fvcom_bathRead fvcom bathymetry file
     read_fvcom_meshRead fvcom mesh file into Matlab mesh object
     read_sigmaRead an FVCOM sigma layers file and output z values into Mobj.
     read_sms_meshRead sms mesh files into Matlab mesh object
     replace_FVCOM_restart_varsUse an FVCOM restart file to seed a model run with spatially varying
     set_elevtideSetup surface elevation tides on the open boundary and dump an
     set_spectideSetup spectral tides on the open boundary and dump a spectral file
     setup_metricsSetup metrics for mesh object Mesh
     smoothfieldSmooth a vertex-based field using averages
     smoothfield2Smooth a vertex-based field using minimum value of surrounding nodes
     truncfieldSmooth a vertex-based field using averages
     wrf2fvcom_U10V10function wrf2fvcom_U10V10(wrf_file,fvcom_grid_file,fvcom_forcing_file,infos)
     write_FVCOM_bathWrite bathymetry to FVCOM format bathymetry file
     write_FVCOM_bedflagDump spatially-variable flag (bedflag) to FVCOM forcing file
     write_FVCOM_corWrite coriolis to FVCOM format coriolis file
     write_FVCOM_elevtideWrite an FVCOM surface elevation time series forcing file
     write_FVCOM_forcingWrite data out to FVCOM NetCDF forcing file.
     write_FVCOM_gridWrite grid and connectivity to FVCOM format grid file
     write_FVCOM_obcWrite FVCOM format open boundary node list file
     write_FVCOM_obs_TSDump observation profile of T/S to netcdf file to initialize
     write_FVCOM_riverwrite FVCOM 3.x NetCDF river file
     write_FVCOM_spectideWrite an FVCOM spectral tidal elevation forcing file
     write_FVCOM_spongeWrite FVCOM format sponge layer file
     write_FVCOM_stationsAdd a set of stations at which FVCOM will output time series.
     write_FVCOM_tsobcexample file for dumping a file to force temperature and salinity at the open b.
     write_FVCOM_wind_ts_speedWrite out time-varying/spatially constant wind forcing as speed.
     write_FVCOM_z0Dump spatially-variable or uniform bottom roughness (z0) to FVCOM forcing
     write_dtankDump mesh to datatank file
     write_river_infoWrite information on the rivers
    + READMEREADME for the FVCOM preprocessing toolbox  add_coriolisGenerate latitude used for FVCOM Coriolis file  add_obc_nodes_graphicAdd a set of obc nodes comprising a single obc boundary to Mesh structure  add_obc_nodes_listAdd a set of obc nodes comprising a single obc boundary to Mesh structure  add_river_nodes_graphicAdd a set of river nodes comprising a single river to Mesh structure  add_river_nodes_listAdd a set of river nodes comprising a single river to Mesh structure  add_sigma_forDT! this program adds sigma levels/layers and shifted layers to a netcdf file  add_sponge_nodesAdd a set of sponge nodes comprising a single sponge layer to Mesh structure  add_sponge_nodes_listAdd a set of sponge nodes comprising a single sponge layer to Mesh structure  add_stations_listAdd a set of stations at which FVCOM will output time series.  add_var_FVCOM_riveradd time dependent scalar variable to a Riverfile  calc_sponge_radiusCalculate a variable sponge radius based on distance to the boundary  elems2nodesTransfer a field from elements to vertices  estimate_tsEstimate time step at each node  exampleexample demonstrating reading in a 2DM file and constructing a model  example2example demonstrating reading in an FVCOM mesh and smoothing the bathymetry  example_FVCOM_riverexample file for dumping an FVCOM river file and adding sediment concentration  example_FVCOM_tsobcexample file for dumping a file to force temperature and salinity at the open b.  example_FVCOM_wind_tsexample file for FVCOM, time-varying/spatially constant wind forcing as stress  example_FVCOM_wind_ts_speedexample file for FVCOM, time-varying/spatially constant wind forcing as speed  example_init_lag  example_my_projectfunction [out_east,out_north] = my_project(in_east,in_north,direction)  find_nearest_ptFind nearest point in Mesh structure to (x,y)  gen_semistructured_meshGenerate a semistructured mesh  gen_unstructured_meshfunction gen_unstructured_mesh(lx,ly,res,cornermod)  generate_mjd--------------------------------------------------------------  get_AMMExtract boundary forcing information from NOC Operational Tide Surge  get_FVCOM_riversExtract river discharges from the supplied river positions for the FVCOM  get_HYCOM_forcingGet mean flow, temperature and salinity data from HYCOM model outputs  get_MetUM_forcingGet the required parameters from the Met Office Unified Model (TM)  get_NAE2_forcingGet the required parameters from NAE2 data to force FVCOM (through  get_NCEP_forcingGet the required parameters from NCEP OPeNDAP data to force FVCOM  get_POLCOMS_meanflowRead mean flow from the PML POLCOMS-ERSEM NetCDF AMM model output files  get_POLCOMS_netCDFRead temperature and salinity from NetCDF model output files and  get_POLCOMS_river_dischargeParse the POLCOMS rivers data file.  get_POLCOMS_river_positionsParse the POLCOMS rivers data file.  get_POLCOMS_tsobcRead temperature and salinity from the PML POLCOMS-ERSEM NetCDF model  get_POLCOMS_tsobc_gcomsRead temperature and salinity from the PML POLCOMS-ERSEM NetCDF model  get_POLPRED_spectideExtract tidal harmonic phases and amplitudes from POLPRED ASCII files.  get_zeta_xtideExtract an elevation time series from a location using Xtide  inCellFind cell in mesh Mobj containing point (xpt,ypt)  interp_POLCOMS2FVCOMUse an FVCOM restart file to seed a model run with spatially varying  make_blank_meshMake a blank mesh object with default params  my_projectSample user-defined projection and inverse projection of (lon,lat) to (x,y)  nodes2elemsTransfer a field from vertices to elements  plot_fieldPlot the mesh, user defined field, open boundary nodes, and river points  read_ERA_windReads in ERA Interim files and outputs a struct containing the requested  read_NCEP_windReads in two NCEP wind vector files (U and V) and outputs four arrays of  read_fvcom_bathRead fvcom bathymetry file  read_fvcom_meshRead fvcom mesh file into Matlab mesh object  read_sigmaRead an FVCOM sigma layers file and output z values into Mobj.  read_sms_mapReads a .map file from SMS  read_sms_meshRead sms mesh files into Matlab mesh object  set_elevtideSetup surface elevation tides on the open boundary and dump an  set_spectideSetup spectral tides on the open boundary and dump a spectral file  setup_metricsSetup metrics for mesh object Mesh  smoothfieldSmooth a vertex-based field using averages  smoothfield2Smooth a vertex-based field using minimum value of surrounding nodes  truncfieldSmooth a vertex-based field using averages  wrf2fvcom_U10V10function wrf2fvcom_U10V10(wrf_file,fvcom_grid_file,fvcom_forcing_file,infos)  write_FVCOM_bathWrite bathymetry to FVCOM format bathymetry file  write_FVCOM_bedflagDump spatially-variable flag (bedflag) to FVCOM forcing file  write_FVCOM_corWrite coriolis to FVCOM format coriolis file  write_FVCOM_elevtideWrite an FVCOM surface elevation time series forcing file  write_FVCOM_forcingWrite data out to FVCOM NetCDF forcing file.  write_FVCOM_gridWrite grid and connectivity to FVCOM format grid file  write_FVCOM_meanflowExport mean flow forcing at the open boundary to NetCDF.  write_FVCOM_meanflow_asciiExport mean flow forcing files hard-coded into mod_obcs2.F.  write_FVCOM_obcWrite FVCOM format open boundary node list file  write_FVCOM_obs_TSDump observation profile of T/S to netcdf file to initialize  write_FVCOM_restartDuplicate an FVCOM restart file, replacing variable values with those  write_FVCOM_riverWrite FVCOM 3.x NetCDF river file  write_FVCOM_river_nmlWrite a namelist for the river nodes.  write_FVCOM_spectideWrite an FVCOM spectral tidal elevation forcing file  write_FVCOM_spongeWrite FVCOM format sponge layer file  write_FVCOM_stationsAdd a set of stations at which FVCOM will output time series.  write_FVCOM_tsobcExport temperature and salinity forcing at the open boundary.  write_FVCOM_wind_ts_speedWrite out time-varying/spatially constant wind forcing as speed.  write_FVCOM_z0Dump spatially-variable or uniform bottom roughness (z0) to FVCOM forcing  write_dtankDump mesh to datatank file  write_river_infoWrite information on the rivers

    Subsequent directories:

    - -
    Generated on Mon 04-Feb-2013 14:22:26 by m2html © 2005
    +

    Dependency Graph

    + +
    Generated on Tue 04-Jun-2013 12:12:54 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/interp_POLCOMS2FVCOM.html b/doc/fvcom_prepro/interp_POLCOMS2FVCOM.html new file mode 100644 index 0000000000000000000000000000000000000000..70c10616eff9276b2f749b01041773c3c90e710c --- /dev/null +++ b/doc/fvcom_prepro/interp_POLCOMS2FVCOM.html @@ -0,0 +1,285 @@ + + + + Description of interp_POLCOMS2FVCOM + + + + + + + + + +
    Home > fvcom_prepro > interp_POLCOMS2FVCOM.m
    + + + +

    interp_POLCOMS2FVCOM +

    + +

    PURPOSE ^

    +
    Use an FVCOM restart file to seed a model run with spatially varying
    + +

    SYNOPSIS ^

    +
    function Mobj = interp_POLCOMS2FVCOM(Mobj, ts, start_date, varlist)
    + +

    DESCRIPTION ^

    +
     Use an FVCOM restart file to seed a model run with spatially varying
    + versions of otherwise constant variables (temperature and salinity only
    + for the time being).
    +
    + function interp_POLCOMS2FVCOM(Mobj, ts, start_date, fv_restart, varlist)
    +
    + DESCRIPTION:
    +    FVCOM does not yet support spatially varying temperature and salinity
    +    inputs as initial conditions. To avoid having to run a model for a
    +    long time in order for temperature and salinity to settle within the
    +    model from the atmospheric and boundary forcing, we can use a restart
    +    file to cheat. For this, we need temperature and salinity
    +    (potentially other variables too) interpolated onto the unstructured
    +    grid. The interpolated data can then be written out with
    +    write_FVCOM_restart.m.
    +
    + INPUT:
    +   Mobj        = MATLAB mesh structure which must contain:
    +                   - Mobj.siglayz - sigma layer depths for all model
    +                   nodes.
    +                   - Mobj.lon, Mobj.lat - node coordinates (long/lat).
    +   ts          = Cell array of POLCOMS AMM NetCDF file(s) in which 4D
    +   variables of temperature and salinity (called 'ETWD' and 'x1XD') exist.
    +   Its/their shape should be (y, x, sigma, time).
    +   start_date  = Gregorian start date array (YYYY, MM, DD, hh, mm, ss).
    +   varlist     = cell array of variables to extract from the NetCDF files.
    + 
    + OUTPUT:
    +   Mobj.restart = struct whose field names are the variables which have
    +   been interpolated (e.g. Mobj.restart.ETWD for POLCOMS daily mean
    +   temperature).
    +
    + EXAMPLE USAGE
    +   interp_POLCOMS2FVCOM(Mobj, '/tmp/ts.nc', '2006-01-01 00:00:00', ...
    +       {'lon', 'lat', 'ETWD', 'x1XD', 'time'})
    +
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +   2013-02-08 First version.
    +   2013-05-16 Add support for parallel for-loops (not mandatory, but
    +   enabled if the Parallel Computing Toolbox is available).
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function Mobj = interp_POLCOMS2FVCOM(Mobj, ts, start_date, varlist)
    +0002 % Use an FVCOM restart file to seed a model run with spatially varying
    +0003 % versions of otherwise constant variables (temperature and salinity only
    +0004 % for the time being).
    +0005 %
    +0006 % function interp_POLCOMS2FVCOM(Mobj, ts, start_date, fv_restart, varlist)
    +0007 %
    +0008 % DESCRIPTION:
    +0009 %    FVCOM does not yet support spatially varying temperature and salinity
    +0010 %    inputs as initial conditions. To avoid having to run a model for a
    +0011 %    long time in order for temperature and salinity to settle within the
    +0012 %    model from the atmospheric and boundary forcing, we can use a restart
    +0013 %    file to cheat. For this, we need temperature and salinity
    +0014 %    (potentially other variables too) interpolated onto the unstructured
    +0015 %    grid. The interpolated data can then be written out with
    +0016 %    write_FVCOM_restart.m.
    +0017 %
    +0018 % INPUT:
    +0019 %   Mobj        = MATLAB mesh structure which must contain:
    +0020 %                   - Mobj.siglayz - sigma layer depths for all model
    +0021 %                   nodes.
    +0022 %                   - Mobj.lon, Mobj.lat - node coordinates (long/lat).
    +0023 %   ts          = Cell array of POLCOMS AMM NetCDF file(s) in which 4D
    +0024 %   variables of temperature and salinity (called 'ETWD' and 'x1XD') exist.
    +0025 %   Its/their shape should be (y, x, sigma, time).
    +0026 %   start_date  = Gregorian start date array (YYYY, MM, DD, hh, mm, ss).
    +0027 %   varlist     = cell array of variables to extract from the NetCDF files.
    +0028 %
    +0029 % OUTPUT:
    +0030 %   Mobj.restart = struct whose field names are the variables which have
    +0031 %   been interpolated (e.g. Mobj.restart.ETWD for POLCOMS daily mean
    +0032 %   temperature).
    +0033 %
    +0034 % EXAMPLE USAGE
    +0035 %   interp_POLCOMS2FVCOM(Mobj, '/tmp/ts.nc', '2006-01-01 00:00:00', ...
    +0036 %       {'lon', 'lat', 'ETWD', 'x1XD', 'time'})
    +0037 %
    +0038 % Author(s):
    +0039 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0040 %
    +0041 % Revision history
    +0042 %   2013-02-08 First version.
    +0043 %   2013-05-16 Add support for parallel for-loops (not mandatory, but
    +0044 %   enabled if the Parallel Computing Toolbox is available).
    +0045 %
    +0046 %==========================================================================
    +0047 
    +0048 subname = 'interp_POLCOMS2FVCOM';
    +0049 
    +0050 global ftbverbose;
    +0051 if ftbverbose
    +0052     fprintf('\nbegin : %s\n', subname)
    +0053 end
    +0054 
    +0055 % Run jobs on multiple workers if we have that functionality. Not sure if
    +0056 % it's necessary, but check we have the Parallel Toolbox first.
    +0057 wasOpened = false;
    +0058 if license('test', 'Distrib_Computing_Toolbox')
    +0059     % We have the Parallel Computing Toolbox, so launch a bunch of workers.
    +0060     if matlabpool('size') == 0
    +0061         % Force pool to be local in case we have remote pools available.
    +0062         matlabpool open local
    +0063         wasOpened = true;
    +0064     end
    +0065 end
    +0066 
    +0067 %--------------------------------------------------------------------------
    +0068 % Extract the NetCDF data specified in varlist
    +0069 %--------------------------------------------------------------------------
    +0070 
    +0071 % Data format:
    +0072 %
    +0073 %   pc.ETWD.data and pc.x1XD.data are y, x, sigma, time
    +0074 %
    +0075 pc = get_POLCOMS_netCDF(ts, varlist);
    +0076 
    +0077 % Number of sigma layers.
    +0078 [fn, fz] = size(Mobj.siglayz);
    +0079 
    +0080 % Make rectangular arrays for the nearest point lookup.
    +0081 [lon, lat] = meshgrid(pc.lon.data, pc.lat.data);
    +0082 
    +0083 % Convert the current times to Modified Julian Day (this is a bit ugly).
    +0084 pc.time.all = strtrim(regexp(pc.time.units, 'since', 'split'));
    +0085 pc.time.datetime = strtrim(regexp(pc.time.all{end}, ' ', 'split'));
    +0086 pc.time.ymd = str2double(strtrim(regexp(pc.time.datetime{1}, '-', 'split')));
    +0087 pc.time.hms = str2double(strtrim(regexp(pc.time.datetime{2}, ':', 'split')));
    +0088 
    +0089 Mobj.ts_times = greg2mjulian(...
    +0090     pc.time.ymd(1), ...
    +0091     pc.time.ymd(2), ...
    +0092     pc.time.ymd(3), ...
    +0093     pc.time.hms(1), ...
    +0094     pc.time.hms(2), ...
    +0095     pc.time.hms(3)) + (pc.time.data / 3600 / 24);
    +0096 
    +0097 % Given our intput time (in start_date), find the nearest time
    +0098 % index for the regularly gridded data.
    +0099 stime = greg2mjulian(start_date(1), start_date(2), ...
    +0100     start_date(3), start_date(4), ...
    +0101     start_date(5), start_date(6));
    +0102 [~, tidx] = min(abs(Mobj.ts_times - stime));
    +0103 
    +0104 %--------------------------------------------------------------------------
    +0105 % Interpolate the regularly gridded data onto the FVCOM grid (vertical grid
    +0106 % first).
    +0107 %--------------------------------------------------------------------------
    +0108 
    +0109 if ftbverbose
    +0110     fprintf('%s : interpolate POLCOMS onto FVCOM''s vertical grid... ', subname)
    +0111 end
    +0112 
    +0113 % Permute the arrays to be x by y rather than y by x.
    +0114 temperature = permute(squeeze(pc.ETWD.data(:, :, :, tidx)), [2, 1, 3]);
    +0115 salinity = permute(squeeze(pc.x1XD.data(:, :, :, tidx)), [2, 1, 3]);
    +0116 depth = permute(squeeze(pc.depth.data(:, :, :, tidx)), [2, 1, 3]);
    +0117 mask = depth(:, :, end) >= 0; % land is positive.
    +0118 
    +0119 pc.tempz = grid_vert_interp(Mobj, lon, lat, temperature, depth, mask);
    +0120 pc.salz = grid_vert_interp(Mobj, lon, lat, salinity, depth, mask);
    +0121 
    +0122 if ftbverbose
    +0123     fprintf('done.\n') 
    +0124 end
    +0125 
    +0126 %--------------------------------------------------------------------------
    +0127 % Now we have vertically interpolated data, we can interpolate each sigma
    +0128 % layer onto the FVCOM unstructured grid ready to write out to NetCDF.
    +0129 % We'll use the triangular interpolation in MATLAB with the natural method
    +0130 % (gives pretty good results, at least qualitatively).
    +0131 %--------------------------------------------------------------------------
    +0132 
    +0133 if ftbverbose
    +0134     fprintf('%s : interpolate POLCOMS onto FVCOM''s horizontal grid... ', subname)
    +0135 end
    +0136 
    +0137 fvtemp = nan(fn, fz);
    +0138 fvsalt = nan(fn, fz);
    +0139 
    +0140 tic
    +0141 parfor zi = 1:fz
    +0142     % Set up the interpolation objects.
    +0143     ft = TriScatteredInterp(lon(:), lat(:), reshape(pc.tempz(:, :, zi), [], 1), 'natural');
    +0144     fs = TriScatteredInterp(lon(:), lat(:), reshape(pc.salz(:, :, zi), [], 1), 'natural');
    +0145     % Interpolate temperature and salinity onto the unstructured grid.
    +0146     fvtemp(:, zi) = ft(Mobj.lon, Mobj.lat);
    +0147     fvsalt(:, zi) = fs(Mobj.lon, Mobj.lat);
    +0148 end
    +0149 
    +0150 % Unfortunately, TriScatteredInterp won't extrapolate, returning instead
    +0151 % NaNs outside the original data's extents. So, for each NaN position, find
    +0152 % the nearest non-NaN value and use that instead. The order in which the
    +0153 % NaN-nodes are found will determine the spatial pattern of the
    +0154 % extrapolation.
    +0155 
    +0156 % We can assume that all layers will have NaNs in the same place
    +0157 % (horizontally), so just use the surface layer (1) for the identification
    +0158 % of NaNs. Also store the finite values so we can find the nearest real
    +0159 % value to the current NaN node and use its temperature and salinity
    +0160 % values.
    +0161 fvidx = 1:fn;
    +0162 fvnanidx = fvidx(isnan(fvtemp(:, 1)));
    +0163 fvfinidx = fvidx(~isnan(fvtemp(:, 1)));
    +0164 
    +0165 % Can't parallelise this one (easily). It shouldn't be a big part of the
    +0166 % run time if your source data covers the domain sufficiently.
    +0167 for ni = 1:length(fvnanidx)
    +0168     % Current position
    +0169     xx = Mobj.lon(fvnanidx(ni));
    +0170     yy = Mobj.lat(fvnanidx(ni));
    +0171     % Find the nearest non-nan temperature and salinity value.
    +0172     [~, di] = min(sqrt((Mobj.lon(fvfinidx) - xx).^2 + (Mobj.lat(fvfinidx) - yy).^2));
    +0173     % Replace the temperature and salinity values at all depths at the
    +0174     % current NaN position with the closest non-nan value.
    +0175     fvtemp(fvnanidx(ni), :) = fvtemp(fvfinidx(di), :);
    +0176     fvsalt(fvnanidx(ni), :) = fvsalt(fvfinidx(di), :);
    +0177 end
    +0178 
    +0179 if ftbverbose
    +0180     fprintf('done.\n') 
    +0181     toc
    +0182 end
    +0183 
    +0184 Mobj.restart.temp = fvtemp;
    +0185 Mobj.restart.salinity = fvsalt;
    +0186 
    +0187 % Close the MATLAB pool if we opened it.
    +0188 if wasOpened
    +0189     matlabpool close
    +0190 end
    +0191 
    +0192 if ftbverbose
    +0193     fprintf('end   : %s\n', subname)
    +0194 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/nodes2elems.html b/doc/fvcom_prepro/nodes2elems.html index 09f0f8d1c0bd24af9791bd67fab96721476f6e5d..5e3965dec772ea4d00eb2d08676b0a0c61c664cf 100755 --- a/doc/fvcom_prepro/nodes2elems.html +++ b/doc/fvcom_prepro/nodes2elems.html @@ -24,15 +24,15 @@
    Transfer a field from vertices to elements

    SYNOPSIS ^

    -
    function [fieldout] = nodes2elems(fieldin,Mobj)
    +
    function [fieldout] = nodes2elems(fieldin,Mobj)

    DESCRIPTION ^

     Transfer a field from vertices to elements
     
    - function [fieldout] = nodes2elems(fieldin,Mobj)  
    + function [fieldout] = nodes2elems(fieldin, Mobj)  
     
      DESCRIPTION:
    -    Smooth a vertex based field 
    +    Transfer a field from vertices (nodes) to elements
     
      INPUT
         Mobj         = Matlab mesh object
    @@ -42,14 +42,14 @@
         fieldout = element-based field
     
      EXAMPLE USAGE
    -    f = smoothfield(fv,Mobj)
    +    f = smoothfield(fv, Mobj)
     
      Author(s):  
         Geoff Cowles (University of Massachusetts Dartmouth)
     
      Revision history
        
    -==============================================================================
    +==========================================================================

    CROSS-REFERENCE INFORMATION ^

    @@ -58,70 +58,69 @@ This function calls: This function is called by: +
  • example example demonstrating reading in a 2DM file and constructing a model
  • get_POLCOMS_meanflow Read mean flow from the PML POLCOMS-ERSEM NetCDF AMM model output files
  • write_FVCOM_forcing Write data out to FVCOM NetCDF forcing file.
  • SOURCE CODE ^

    -
    0001 function [fieldout]  = nodes2elems(fieldin,Mobj)
    -0002 
    -0003 % Transfer a field from vertices to elements
    -0004 %
    -0005 % function [fieldout] = nodes2elems(fieldin,Mobj)
    -0006 %
    -0007 % DESCRIPTION:
    -0008 %    Smooth a vertex based field
    -0009 %
    -0010 % INPUT
    -0011 %    Mobj         = Matlab mesh object
    -0012 %    fieldin      = vertex-based field
    -0013 %
    -0014 % OUTPUT:
    -0015 %    fieldout = element-based field
    -0016 %
    -0017 % EXAMPLE USAGE
    -0018 %    f = smoothfield(fv,Mobj)
    -0019 %
    -0020 % Author(s):
    -0021 %    Geoff Cowles (University of Massachusetts Dartmouth)
    -0022 %
    -0023 % Revision history
    -0024 %
    -0025 %==============================================================================
    -0026 subname = 'nodes2elems';
    -0027 global ftbverbose;
    -0028 if(ftbverbose);
    -0029   fprintf('\n')
    -0030   fprintf(['begin : ' subname '\n'])
    -0031 end;
    -0032 
    -0033 %------------------------------------------------------------------------------
    -0034 % Parse input
    -0035 %------------------------------------------------------------------------------
    -0036 
    -0037 if(exist('fieldin')*exist('Mobj') == 0)
    -0038     error('arguments to nodes2elems are missing')
    -0039 end;
    -0040 
    -0041 if(length(fieldin) ~= Mobj.nVerts)
    -0042     error('field size in nodes2elems is not the same as number of nodes in Mesh')
    -0043 end;
    -0044 
    -0045 %------------------------------------------------------------------------------
    -0046 % Tranfser
    -0047 %------------------------------------------------------------------------------
    -0048 fieldout = zeros(Mobj.nElems,1);
    -0049 
    -0050 for i=1:Mobj.nElems
    -0051     fieldout(i) = sum(fieldin(Mobj.tri(i,1:3)))/3.; 
    -0052 end;
    +
    0001 function [fieldout] = nodes2elems(fieldin,Mobj)
    +0002 % Transfer a field from vertices to elements
    +0003 %
    +0004 % function [fieldout] = nodes2elems(fieldin, Mobj)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %    Transfer a field from vertices (nodes) to elements
    +0008 %
    +0009 % INPUT
    +0010 %    Mobj         = Matlab mesh object
    +0011 %    fieldin      = vertex-based field
    +0012 %
    +0013 % OUTPUT:
    +0014 %    fieldout = element-based field
    +0015 %
    +0016 % EXAMPLE USAGE
    +0017 %    f = smoothfield(fv, Mobj)
    +0018 %
    +0019 % Author(s):
    +0020 %    Geoff Cowles (University of Massachusetts Dartmouth)
    +0021 %
    +0022 % Revision history
    +0023 %
    +0024 %==========================================================================
    +0025 subname = 'nodes2elems';
    +0026 global ftbverbose;
    +0027 if ftbverbose;
    +0028     fprintf('\n')
    +0029     fprintf(['begin : ' subname '\n'])
    +0030 end
    +0031 
    +0032 %--------------------------------------------------------------------------
    +0033 % Parse input
    +0034 %--------------------------------------------------------------------------
    +0035 
    +0036 if exist('fieldin', 'var') ~= 1 || exist('Mobj', 'var') ~= 1
    +0037     error('arguments to nodes2elems are missing')
    +0038 end
    +0039 
    +0040 if length(fieldin) ~= Mobj.nVerts
    +0041     error('field size in nodes2elems is not the same as number of nodes in Mesh')
    +0042 end
    +0043 
    +0044 %--------------------------------------------------------------------------
    +0045 % Tranfser
    +0046 %--------------------------------------------------------------------------
    +0047 fieldout = zeros(Mobj.nElems,1);
    +0048 
    +0049 for i=1:Mobj.nElems
    +0050     fieldout(i) = sum(fieldin(Mobj.tri(i,1:3)))/3.; 
    +0051 end;
    +0052 
     0053 
    -0054 
    -0055 if(ftbverbose);
    -0056   fprintf(['end   : ' subname '\n'])
    -0057 end;
    -0058
    -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +0054 if ftbverbose +0055 fprintf(['end : ' subname '\n']) +0056 end +0057
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/plot_field.html b/doc/fvcom_prepro/plot_field.html index 04f4d0091cd2b518b809a9ba88352bbb9f92a270..354b5c782241ea236fefffb57a5e69797501309f 100755 --- a/doc/fvcom_prepro/plot_field.html +++ b/doc/fvcom_prepro/plot_field.html @@ -66,7 +66,7 @@ This function calls: This function is called by: +
  • example example demonstrating reading in a 2DM file and constructing a model
  • example2 example demonstrating reading in an FVCOM mesh and smoothing the bathymetry
  • example_init_lag
  • @@ -223,6 +223,6 @@ This function is called by: 0149 end; 0150 0151 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/read_ERA_wind.html b/doc/fvcom_prepro/read_ERA_wind.html index d1f67bf086607cc170d7ea7068dd298479328fff..236846343635b7aa9a5715ce202ea27da19b399f 100644 --- a/doc/fvcom_prepro/read_ERA_wind.html +++ b/doc/fvcom_prepro/read_ERA_wind.html @@ -104,7 +104,7 @@ This function is called by: 0033 % datadir = '/users/modellers/pica/Data/ECMWF/2006'; 0034 % varlist = {'u10', 'v10'}; 0035 -0036 warning off +0036 %warning off 0037 0038 if nargin ~= 3 0039 error('Incorrect number of arguments') @@ -188,6 +188,6 @@ This function is called by: 0117 if ftbverbose; 0118 fprintf(['end : ' subname '\n']) 0119 end -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/read_NCEP_wind.html b/doc/fvcom_prepro/read_NCEP_wind.html index c9cef23572578c6d5a05df6d23be3dd5da76b40a..13e304ec6bc762af7f6801d4f0fd5bc0709ead80 100644 --- a/doc/fvcom_prepro/read_NCEP_wind.html +++ b/doc/fvcom_prepro/read_NCEP_wind.html @@ -93,7 +93,7 @@ This function is called by: 0025 % 0026 %========================================================================== 0027 -0028 warning off +0028 %warning off 0029 0030 if nargin ~= 2 0031 error('Incorrect number of arguments') @@ -180,6 +180,6 @@ This function is called by: 0112 0113 netcdf.close(nc_u10) 0114 netcdf.close(nc_v10) -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/read_fvcom_bath.html b/doc/fvcom_prepro/read_fvcom_bath.html index 2cf8bcea7017e369eb20e1341013c2c410adcd25..b02a7767a7d40b99e1b16bc6b3f89731927d0147 100755 --- a/doc/fvcom_prepro/read_fvcom_bath.html +++ b/doc/fvcom_prepro/read_fvcom_bath.html @@ -57,7 +57,7 @@ This function calls: This function is called by: +
  • example2 example demonstrating reading in an FVCOM mesh and smoothing the bathymetry
  • example_init_lag
  • @@ -122,6 +122,6 @@ This function is called by: 0057 end; 0058 0059 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/read_fvcom_mesh.html b/doc/fvcom_prepro/read_fvcom_mesh.html index 61f1e169ed612bde1c2759d89160f0f684294c79..58bf62619c545bbb57e3fe79d05f50b0a1b358b1 100755 --- a/doc/fvcom_prepro/read_fvcom_mesh.html +++ b/doc/fvcom_prepro/read_fvcom_mesh.html @@ -58,7 +58,7 @@ This function calls:
  • make_blank_mesh Make a blank mesh object with default params
  • This function is called by: +
  • example2 example demonstrating reading in an FVCOM mesh and smoothing the bathymetry
  • example_init_lag
  • wrf2fvcom_U10V10 function wrf2fvcom_U10V10(wrf_file,fvcom_grid_file,fvcom_forcing_file,infos)
  • @@ -179,6 +179,6 @@ This function is called by: 0113 end; 0114 0115 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/read_sigma.html b/doc/fvcom_prepro/read_sigma.html index ecdfeae39903156a3eb6f317cd95da9405449d07..ef36146b4091e031fa2de2cb6af615af3f139735 100644 --- a/doc/fvcom_prepro/read_sigma.html +++ b/doc/fvcom_prepro/read_sigma.html @@ -56,7 +56,12 @@ sigma layers along a user-defined line, the depths are calculated for each node in the unstructured grid. 2013-01-10 Added two new outputs to the returned Mobj (siglay and - siglev). They're useful in write_FVCOM_tsobc.m. + siglev). They're useful in write_FVCOM_tsobc.m. + 2013-04-23 Add support for geometric sigma distributions as well as + slightly more robust reading of and checks on the parameters in the + input file. Also changed the way the uniform distribution is calculated + (by using a P_SIGMA value of 1 and the sigma_geo.m function rather than + fiddling around with ranges, although the output is the same).

    CROSS-REFERENCE INFORMATION ^

    @@ -102,93 +107,126 @@ This function is called by: 0029 % each node in the unstructured grid. 0030 % 2013-01-10 Added two new outputs to the returned Mobj (siglay and 0031 % siglev). They're useful in write_FVCOM_tsobc.m. -0032 -0033 subname = 'read_sigma'; -0034 -0035 global ftbverbose; -0036 if ftbverbose -0037 fprintf('\n') -0038 fprintf(['begin : ' subname '\n']) -0039 end -0040 -0041 fid = fopen(sigmafile,'r'); -0042 if(fid < 0) -0043 error(['file: ' sigmafile ' does not exist']); -0044 end -0045 -0046 while ~feof(fid) -0047 line = fgetl(fid); -0048 if isempty(line) || strncmp(line, '!', 1) || ~ischar(line) -0049 continue -0050 end -0051 key = lower(line(1:3)); -0052 C = strtrim(regexpi(line, '=', 'split')); -0053 switch key -0054 case 'num' -0055 nlev = str2double(C{2}); -0056 case 'sig' -0057 sigtype = C{2}; -0058 case 'du ' -0059 du = str2double(C{2}); -0060 case 'dl ' -0061 dl = str2double(C{2}); -0062 case 'min' -0063 min_constant_depth = str2double(C{2}); -0064 case 'ku ' -0065 ku = str2double(C{2}); -0066 case 'kl ' -0067 kl = str2double(C{2}); -0068 case 'zku' -0069 s = str2double(regexp(C{2}, ' ', 'split')); -0070 zku = zeros(ku, 1); -0071 for i = 1:ku -0072 zku(i) = s(i); -0073 end -0074 case 'zkl' -0075 s = str2double(regexp(C{2}, ' ', 'split')); -0076 zkl = zeros(kl, 1); -0077 for i = 1:kl -0078 zkl(i) = s(i); -0079 end -0080 end -0081 end -0082 -0083 if ftbverbose -0084 fprintf('nlev %d\n',nlev) -0085 fprintf('sigtype %s\n',sigtype) -0086 fprintf('du %d\n',du) -0087 fprintf('dl %d\n',dl) -0088 fprintf('min_constant_depth %f\n',min_constant_depth) -0089 fprintf('ku %d\n',ku) -0090 fprintf('kl %d\n',kl) -0091 fprintf('zku %d\n',zku) -0092 fprintf('zkl %d\n',zkl) -0093 end -0094 -0095 % calculate the sigma distributions at each grid node -0096 switch lower(sigtype) -0097 case 'generalized' -0098 z = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, ... -0099 Mobj.z(i), min_constant_depth); -0100 case 'uniform' -0101 z = 0:-1/double(nlev-1):-1; -0102 otherwise -0103 error('Can''t do that sigtype') -0104 end -0105 -0106 % Create a siglay variable (i.e. midpoint in the sigma levels). -0107 zlay = z(1:end-1) + (diff(z)/2); -0108 -0109 Mobj.siglevz = repmat(Mobj.h, 1, nlev) .* repmat(z, Mobj.nVerts, 1); -0110 Mobj.siglayz = repmat(Mobj.h, 1, nlev-1) .* repmat(zlay, Mobj.nVerts, 1); -0111 -0112 % Add the sigma levels and layers to the Mobj. -0113 Mobj.siglev = z; -0114 Mobj.siglay = zlay; -0115 -0116 if ftbverbose; -0117 fprintf(['end : ' subname '\n']) -0118 end -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +0032 % 2013-04-23 Add support for geometric sigma distributions as well as +0033 % slightly more robust reading of and checks on the parameters in the +0034 % input file. Also changed the way the uniform distribution is calculated +0035 % (by using a P_SIGMA value of 1 and the sigma_geo.m function rather than +0036 % fiddling around with ranges, although the output is the same). +0037 +0038 subname = 'read_sigma'; +0039 +0040 global ftbverbose; +0041 if ftbverbose +0042 fprintf(['\nbegin : ' subname '\n']) +0043 end +0044 +0045 fid = fopen(sigmafile,'r'); +0046 if(fid < 0) +0047 error(['file: ' sigmafile ' does not exist']); +0048 end +0049 +0050 while ~feof(fid) +0051 line = fgetl(fid); +0052 if isempty(line) || strncmp(line, '!', 1) || ~ischar(line) +0053 continue +0054 end +0055 +0056 % Clean up the input string to make matching a bit easier (trim +0057 % whitespace and remove duplicate spaces in the keywords). +0058 C = strtrim(regexpi(regexprep(line, '\s+', ' '), '=', 'split')); +0059 +0060 switch lower(C{1}) +0061 case 'number of sigma levels' +0062 nlev = str2double(C{2}); +0063 case 'sigma coordinate type' +0064 sigtype = C{2}; +0065 case 'sigma power' +0066 sigpow = str2double(C{2}); +0067 case 'du' +0068 du = str2double(C{2}); +0069 case 'dl' +0070 dl = str2double(C{2}); +0071 case 'min constant depth' +0072 min_constant_depth = str2double(C{2}); +0073 case 'ku' +0074 ku = str2double(C{2}); +0075 case 'kl' +0076 kl = str2double(C{2}); +0077 case 'zku' +0078 s = str2double(regexp(C{2}, ' ', 'split')); +0079 zku = zeros(ku, 1); +0080 for i = 1:ku +0081 zku(i) = s(i); +0082 end +0083 case 'zkl' +0084 s = str2double(regexp(C{2}, ' ', 'split')); +0085 zkl = zeros(kl, 1); +0086 for i = 1:kl +0087 zkl(i) = s(i); +0088 end +0089 end +0090 end +0091 +0092 % Do some checks if we've got uniform or generalised coordinates to make +0093 % sure the input is correct. +0094 if strcmpi(sigtype, 'GENERALIZED') || strcmpi(sigtype, 'UNIFORM') +0095 if numel(zku) ~= ku +0096 warning('Number of zku values does not match the number specified in ku') +0097 end +0098 if numel(zkl) ~= kl +0099 warning('Number of zkl values does not match the number specified in kl') +0100 end +0101 end +0102 +0103 if ftbverbose +0104 % Should be present in all sigma files. +0105 fprintf('nlev\t%d\n', nlev) +0106 fprintf('sigtype\t%s\n', sigtype) +0107 +0108 % Only present in geometric sigma files. +0109 if strcmpi(sigtype, 'GEOMETRIC') +0110 fprintf('sigpow\t%d\n', sigpow) +0111 end +0112 +0113 % Only in the generalised or uniform sigma files. +0114 if strcmpi(sigtype, 'GENERALIZED') || strcmpi(sigtype, 'UNIFORM') +0115 fprintf('du\t%d\n', du) +0116 fprintf('dl\t%d\n', dl) +0117 fprintf('min_constant_depth\t%f\n', min_constant_depth) +0118 fprintf('ku\t%d\n', ku) +0119 fprintf('kl\t%d\n', kl) +0120 fprintf('zku\t%d\n', zku) +0121 fprintf('zkl\t%d\n', zkl) +0122 end +0123 end +0124 +0125 % Calculate the sigma distributions at each grid node +0126 switch lower(sigtype) +0127 case 'generalized' +0128 z = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, ... +0129 Mobj.z(i), min_constant_depth); +0130 case 'uniform' +0131 z = sigma_geo(nlev, 1); +0132 % z = 0:-1/double(nlev-1):-1; +0133 case 'geometric' +0134 z = sigma_geo(nlev, sigpow); +0135 otherwise +0136 error('Don''t know sigtype %s (is it supported?)', sigtype) +0137 end +0138 +0139 % Create a siglay variable (i.e. midpoint in the sigma levels). +0140 zlay = z(1:end-1) + (diff(z)/2); +0141 +0142 Mobj.siglevz = repmat(Mobj.h, 1, nlev) .* repmat(z, Mobj.nVerts, 1); +0143 Mobj.siglayz = repmat(Mobj.h, 1, nlev-1) .* repmat(zlay, Mobj.nVerts, 1); +0144 +0145 % Add the sigma levels and layers to the Mobj. +0146 Mobj.siglev = z; +0147 Mobj.siglay = zlay; +0148 +0149 if ftbverbose; +0150 fprintf(['end : ' subname '\n']) +0151 end +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/read_sms_map.html b/doc/fvcom_prepro/read_sms_map.html new file mode 100644 index 0000000000000000000000000000000000000000..6daf8a48b4a3067fe3ece1aebbe19495f0e70319 --- /dev/null +++ b/doc/fvcom_prepro/read_sms_map.html @@ -0,0 +1,163 @@ + + + + Description of read_sms_map + + + + + + + + + +
    Home > fvcom_prepro > read_sms_map.m
    + + + +

    read_sms_map +

    + +

    PURPOSE ^

    +
    Reads a .map file from SMS
    + +

    SYNOPSIS ^

    +
    function data = read_sms_map(file)
    + +

    DESCRIPTION ^

    +
     Reads a .map file from SMS
    +
    +  data = read_sms_map(filename)
    +
    + DESCRIPTION:
    +   Reads a map file from SMS consisting of node coordinates for boundary
    +   lines. Each different arc is read into a different cell array (e.g. if
    +   you have multiple islands). Ensure that the polygons are built in SMS 
    +   to make handling islands easier.
    +
    + INPUT:
    +   file - file name to read from.
    +
    + OUTPUT:
    +   data.arc - cell array of coordinate pairs for the boundaries and
    +       elevation
    +   data.arcID - cell array of SMS ARC IDs
    +   data.arcN - cell array of number of nodes in each arc cell array
    +
    + EXAMPLE USAGE:
    +  arc = read_sms_map('/home/user/data/sms_project_v1.map')
    +
    + Author(s):
    +   Ricardo Torres (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2013-05-03 First version.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function data = read_sms_map(file)
    +0002 % Reads a .map file from SMS
    +0003 %
    +0004 %  data = read_sms_map(filename)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Reads a map file from SMS consisting of node coordinates for boundary
    +0008 %   lines. Each different arc is read into a different cell array (e.g. if
    +0009 %   you have multiple islands). Ensure that the polygons are built in SMS
    +0010 %   to make handling islands easier.
    +0011 %
    +0012 % INPUT:
    +0013 %   file - file name to read from.
    +0014 %
    +0015 % OUTPUT:
    +0016 %   data.arc - cell array of coordinate pairs for the boundaries and
    +0017 %       elevation
    +0018 %   data.arcID - cell array of SMS ARC IDs
    +0019 %   data.arcN - cell array of number of nodes in each arc cell array
    +0020 %
    +0021 % EXAMPLE USAGE:
    +0022 %  arc = read_sms_map('/home/user/data/sms_project_v1.map')
    +0023 %
    +0024 % Author(s):
    +0025 %   Ricardo Torres (Plymouth Marine Laboratory)
    +0026 %
    +0027 % Revision history:
    +0028 %   2013-05-03 First version.
    +0029 %
    +0030 %==========================================================================
    +0031 
    +0032 subname = 'read_sms_map';
    +0033 
    +0034 global ftbverbose
    +0035 if ftbverbose
    +0036     fprintf('\n'); fprintf(['begin : ' subname '\n']);
    +0037 end
    +0038 f = fopen(file, 'rt');
    +0039 if f < 0
    +0040     error('Unable to open output file (check permissions?)')
    +0041 end
    +0042 frewind(f)
    +0043 loopnode = 0;
    +0044 looparc = 0;
    +0045 data = [];
    +0046 while ~feof(f)
    +0047     % Read NODES found
    +0048     line=fgetl(f);
    +0049     while ~(strcmpi(line,'ARC') | strcmpi(line,'NODE'))
    +0050         
    +0051         line=fgetl(f);
    +0052         if  feof(f);fclose (f); return; end
    +0053     end
    +0054     switch line
    +0055         case 'NODE'
    +0056             
    +0057             loopnode = loopnode + 1;
    +0058             line = fgetl(f);
    +0059             data.node(loopnode) = textscan(line, '%*s %f %f %*f', 'CollectOutput', 1);
    +0060             line = fgetl(f);
    +0061             data.nodeID(loopnode) = textscan(line, '%*s %u');
    +0062             line = fgetl(f);
    +0063             
    +0064         case 'ARC'
    +0065 
    +0066             looparc = looparc + 1;
    +0067             
    +0068             line=fgetl(f);
    +0069             data.arcID{looparc} = textscan(line, '%*s %u');
    +0070             % skip two lines
    +0071             dump = fgetl(f); line = fgetl(f);
    +0072             data.arcnode(looparc) = textscan(line, '%*s %u %u', 'CollectOutput', 1);
    +0073             line = fgetl(f);
    +0074             if strcmpi(line, 'END') ; break; end
    +0075             % read number of vertices in ARC
    +0076             data.arcN(looparc) = textscan(line, '%*s %u');
    +0077             data.arc(looparc) = textscan(f, '%f %f %*f', data.arcN{looparc}, 'CollectOutput', 1, 'Delimiter', '\n');
    +0078         otherwise
    +0079             
    +0080     end
    +0081 end
    +0082 fclose(f)
    +0083 
    +0084 if ftbverbose;
    +0085     fprintf(['end   : ' subname '\n'])
    +0086 end
    +0087 
    +0088 return
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/setup_metrics.html b/doc/fvcom_prepro/setup_metrics.html index 59c7119279a8041bffd41497540bdcb93f38753a..988349e8ba05ef4e95918b3d854ec1eae21a3b0a 100755 --- a/doc/fvcom_prepro/setup_metrics.html +++ b/doc/fvcom_prepro/setup_metrics.html @@ -57,7 +57,7 @@ This function calls: This function is called by: +
  • example example demonstrating reading in a 2DM file and constructing a model
  • example2 example demonstrating reading in an FVCOM mesh and smoothing the bathymetry
  • example_init_lag
  • @@ -156,6 +156,6 @@ This function is called by: 0091 fprintf(['end : ' subname '\n']) 0092 end; 0093 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_bedflag.html b/doc/fvcom_prepro/write_FVCOM_bedflag.html index fad1b32b52c2ca4f2979c5f5ac9ff856c3d231f6..0ce7d0372a61e50ddffa0f1b7d945411dcad3d76 100755 --- a/doc/fvcom_prepro/write_FVCOM_bedflag.html +++ b/doc/fvcom_prepro/write_FVCOM_bedflag.html @@ -51,7 +51,8 @@ Revision history -============================================================================== +============================================================================== +warning off

    CROSS-REFERENCE INFORMATION ^

    @@ -93,7 +94,7 @@ This function is called by: 0025 % Revision history 0026 % 0027 %============================================================================== -0028 warning off +0028 %warning off 0029 global ftbverbose; 0030 if(ftbverbose); 0031 subname = 'write_FVCOM_bedflag'; @@ -140,6 +141,6 @@ This function is called by: 0072 if(ftbverbose); fprintf(['end : ' subname '\n']); end; 0073 0074 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_elevtide.html b/doc/fvcom_prepro/write_FVCOM_elevtide.html index 1d50ceab36653eb5041a471c2305b06c978f52e6..498a03e46823294e76dda6c586101f28ce3f4ade 100644 --- a/doc/fvcom_prepro/write_FVCOM_elevtide.html +++ b/doc/fvcom_prepro/write_FVCOM_elevtide.html @@ -29,23 +29,23 @@

    DESCRIPTION ^

     Write an FVCOM surface elevation time series forcing file 
     
    - write_FVCOM_elevtide(Mobj,MJD,ElevationFile,MyTitle)
    + write_FVCOM_elevtide(Mobj, MJD, ElevationFile, MyTitle)
     
      DESCRIPTION:
         Write an FVCOM NetCDF surface elevation forcing file
     
      INPUT:
    -   Mobj         = Matlab mesh object.
    -   MJD          = list of modified Modified Julian Dates of size [times]
    -                   (defined as unlimited in the NetCDF file).
    -   ElevationFile    = name of NetCDF file.
    -   MyTitle      = casename title, written as global attribute of NetCDF file.
    +   Mobj = Matlab mesh object.
    +   MJD = list of modified Modified Julian Dates of size [times] (defined 
    +         as unlimited in the NetCDF file).
    +   ElevationFile = name of NetCDF file.
    +   MyTitle = casename title, written as global attribute of NetCDF file.
     
      OUTPUT:
         ElevationFile, A NetCDF FVCOM surface elevations tide forcing file
     
      EXAMPLE USAGE
    -    write_FVCOM_elevtide(Mobj,MJD,ElevationFile,MyTitle)
    +    write_FVCOM_elevtide(Mobj, MJD, '/tmp/elevtide.nc, 'Shelf tides')
     
      Author(s):  
         Pierre Cazenave (Plymouth Marine Laboratory)
    @@ -53,13 +53,13 @@
      
      Revision history
         2012-08-08 (PWC) First version.
    -    2012-11-14 (PWC) Updated to expect Modified Julian Day rather than doing 
    -    the conversion in here. Also put the pieces in set_elevtide in here to
    -    simplify the process of writing out an elevation input file.
    +    2012-11-14 (PWC) Updated to expect Modified Julian Day rather than
    +    doing the conversion in here. Also put the pieces in set_elevtide in
    +    here to simplify the process of writing out an elevation input file.
         2012-12-04 (KJT) Updated to use surface elevation and open boundary 
         nodes from Mobj.
        
    -==============================================================================
    +==========================================================================

    CROSS-REFERENCE INFORMATION ^

    @@ -77,23 +77,23 @@ This function is called by:
    0001 function write_FVCOM_elevtide(Mobj,MJD,ElevationFile,MyTitle)
     0002 % Write an FVCOM surface elevation time series forcing file
     0003 %
    -0004 % write_FVCOM_elevtide(Mobj,MJD,ElevationFile,MyTitle)
    +0004 % write_FVCOM_elevtide(Mobj, MJD, ElevationFile, MyTitle)
     0005 %
     0006 % DESCRIPTION:
     0007 %    Write an FVCOM NetCDF surface elevation forcing file
     0008 %
     0009 % INPUT:
    -0010 %   Mobj         = Matlab mesh object.
    -0011 %   MJD          = list of modified Modified Julian Dates of size [times]
    -0012 %                   (defined as unlimited in the NetCDF file).
    -0013 %   ElevationFile    = name of NetCDF file.
    -0014 %   MyTitle      = casename title, written as global attribute of NetCDF file.
    +0010 %   Mobj = Matlab mesh object.
    +0011 %   MJD = list of modified Modified Julian Dates of size [times] (defined
    +0012 %         as unlimited in the NetCDF file).
    +0013 %   ElevationFile = name of NetCDF file.
    +0014 %   MyTitle = casename title, written as global attribute of NetCDF file.
     0015 %
     0016 % OUTPUT:
     0017 %    ElevationFile, A NetCDF FVCOM surface elevations tide forcing file
     0018 %
     0019 % EXAMPLE USAGE
    -0020 %    write_FVCOM_elevtide(Mobj,MJD,ElevationFile,MyTitle)
    +0020 %    write_FVCOM_elevtide(Mobj, MJD, '/tmp/elevtide.nc, 'Shelf tides')
     0021 %
     0022 % Author(s):
     0023 %    Pierre Cazenave (Plymouth Marine Laboratory)
    @@ -101,15 +101,15 @@ This function is called by:
     0025 %
     0026 % Revision history
     0027 %    2012-08-08 (PWC) First version.
    -0028 %    2012-11-14 (PWC) Updated to expect Modified Julian Day rather than doing
    -0029 %    the conversion in here. Also put the pieces in set_elevtide in here to
    -0030 %    simplify the process of writing out an elevation input file.
    +0028 %    2012-11-14 (PWC) Updated to expect Modified Julian Day rather than
    +0029 %    doing the conversion in here. Also put the pieces in set_elevtide in
    +0030 %    here to simplify the process of writing out an elevation input file.
     0031 %    2012-12-04 (KJT) Updated to use surface elevation and open boundary
     0032 %    nodes from Mobj.
     0033 %
    -0034 %==============================================================================
    +0034 %==========================================================================
     0035 
    -0036 global ftbverbose 
    +0036 global ftbverbose
     0037 report = false;
     0038 if(ftbverbose); report = true; end
     0039 subname = 'write_FVCOM_elevtide';
    @@ -123,9 +123,9 @@ This function is called by:
     0047 % code.
     0048 ObcNodes = tmpObcNodes(tmpObcNodes~=0)';
     0049 
    -0050 %------------------------------------------------------------------------------
    +0050 %--------------------------------------------------------------------------
     0051 % Sanity check on input and dimensions
    -0052 %------------------------------------------------------------------------------
    +0052 %--------------------------------------------------------------------------
     0053 nTimes = numel(MJD);
     0054 if(report); fprintf('Number of time steps %d\n',nTimes); end
     0055 
    @@ -142,16 +142,16 @@ This function is called by:
     0066 end
     0067 
     0068 %%
    -0069 %------------------------------------------------------------------------------
    +0069 %--------------------------------------------------------------------------
     0070 % Dump the file
    -0071 %------------------------------------------------------------------------------
    +0071 %--------------------------------------------------------------------------
     0072 
     0073 nc=netcdf.create(ElevationFile,'clobber');
     0074 
     0075 % define global attributes
     0076 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'type','FVCOM TIME SERIES ELEVATION FORCING FILE')
     0077 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title',MyTitle)
    -0078 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','FILE CREATED using write_FVCOM_elevtide')
    +0078 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','File created using write_FVCOM_elevtide from the MATLAB fvcom-toolbox')
     0079 
     0080 % define dimensions
     0081 nobc_dimid=netcdf.defDim(nc,'nobc',nObcs);
    @@ -223,6 +223,6 @@ This function is called by:
     0147 
     0148 if(report); fprintf(['end   : ' subname '\n']); end;
     0149
    -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_forcing.html b/doc/fvcom_prepro/write_FVCOM_forcing.html index 1df97ca56f7d58eaa74c8b1e6f6f6b23212cb55c..422b53be1bed054771b34786316b834a6a768eeb 100644 --- a/doc/fvcom_prepro/write_FVCOM_forcing.html +++ b/doc/fvcom_prepro/write_FVCOM_forcing.html @@ -29,14 +29,19 @@

    DESCRIPTION ^

     Write data out to FVCOM NetCDF forcing file.
     
    - write_FVCOM_forcing(fvcom_forcing_file, data, infos, fver)
    + write_FVCOM_forcing(Mobj, fvcom_forcing_file, data, infos, fver)
     
      DESCRIPTION:
        Takes the given interpolated data (e.g. from grid2fvcom) and writes out
        to a NetCDF file.
     
      INPUT:
    -   Mobj - MATLAB mesh object
    +   Mobj - MATLAB mesh object containing fields:
    +       tri - triangulation table for the unstructured grid
    +       nVerts - number of grid vertices (nodes)
    +       nElems - number of grid elements
    +       nativeCoords - model coordinate type ('cartesian' or 'spherical')
    +       x, y or lon, lat - node positions (depending on nativeCoords value)
        fileprefix - Output NetCDF file prefix (plus path) will be
            fileprefix_{wnd,hfx,evap}.nc if fver is '3.1.0', otherwise output
            files will be fileprefix_wnd.nc.
    @@ -49,21 +54,37 @@
      The fields in data may be called any of:
          - 'u10', 'v10', 'uwnd', 'vwnd' - wind components
          - 'slp'       - sea level pressure
    -     - 'P_E'       - evaporation
    +     - 'pevpr'     - evaporation
          - 'prate'     - precipitation
    -     - 'nswrs'     - short wave radiation
    -     - 'shtfl'\
    -     - 'lhtfl' >   - combine to form "surface net heat flux"
    -     - 'nlwrs'/
    -     - 'time'
    -     - 'lon'
    -     - 'lat'
    -     - 'x'
    -     - 'y'
    +     - 'slp'       - sea level pressure
    +     - 'nlwrs'     - net longwave radiation*,**
    +     - 'nswrs'     - net shortwave radiation*,**
    +     - 'shtfl'     - sensible heat net flux*,**
    +     - 'lhtfl'     - latent heat net flux*,**
    +     - 'lon'       - longitude (vector)
    +     - 'lat'       - latitude (vector)
    +     - 'x'         - eastings (vector)
    +     - 'y'         - northings (vector)
    +     - 'nshf'      - pre-computed net surface heat flux**
    +
    + Fields marked with an * are combined to form the "surface net heat flux"
    + (nshf) as follows:
    +
    +   nshf = -nlwrs + -nswrs - lhtfl - shtfl;
    +
    + ** Alternatively, a new field 'nshf' (net surface heat flux) can be
    + supplied, in which case shtfl and lhtfl are not necessary as their only
    + function is in the calculation of net surface heat flux. This approach
    + eliminates the need to interpolate so many variables onto the FVCOM grid,
    + thus decreasing the time needed to generate the FVCOM input files.
     
      OUTPUT:
        FVCOM wind speed forcing NetCDF file(s)
     
    + EXAMPLE USAGE:
    +   windBase = '/path/to/output/casename_wnd.nc';
    +   write_FVCOM_forcing(Mobj, windBase, data, ...
    +       'FVCOM atmospheric forcing data', '3.1.6');
     
      Author(s):
        Pierre Cazenave (Plymouth Marine Laboratory)
    @@ -73,7 +94,18 @@
        2012-11-01 - First version based on the parts of grid2fvcom_U10V10.m
        which dealt with writing the NetCDF file. This version now dynamically
        deals with varying numbers of forcing data.
    -   2012-11-09 - Add the correct calculation for the surface net heat flux.
    +   2012-11-09 - Add the correct calculation for the net surface heat flux.
    +   2013-02-14 - Fix the surface net heat flux sign convention, include the
    +   longwave radiation variable and add support for a new field in the
    +   input struct ('nshf') which contains the pre-computed net surface heat
    +   flux.
    +   2013-05-13 - Fix the evaporation to use the correct variable from NCEP
    +   (pevpr rather than P_E which is actually the precipitation minus the
    +   evaporation in Et). The data in Et are calcaulated from lhtfl whereas
    +   pevpr comes directly from NCEP and to me it seems more sensible to use
    +   that to maintain consistency.
    +   2013-05-14 - Add example usage to the help and specify which fields are
    +   required in Mobj.
     
      KJT Revision history:
        2013-01-16 - Added support for output of sea level pressure.
    @@ -84,7 +116,7 @@
     

    CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • nodes2elems Transfer a field from vertices to elements
  • This function is called by: @@ -96,378 +128,482 @@ This function is called by:
    0001 function write_FVCOM_forcing(Mobj, fileprefix, data, infos, fver)
     0002 % Write data out to FVCOM NetCDF forcing file.
     0003 %
    -0004 % write_FVCOM_forcing(fvcom_forcing_file, data, infos, fver)
    +0004 % write_FVCOM_forcing(Mobj, fvcom_forcing_file, data, infos, fver)
     0005 %
     0006 % DESCRIPTION:
     0007 %   Takes the given interpolated data (e.g. from grid2fvcom) and writes out
     0008 %   to a NetCDF file.
     0009 %
     0010 % INPUT:
    -0011 %   Mobj - MATLAB mesh object
    -0012 %   fileprefix - Output NetCDF file prefix (plus path) will be
    -0013 %       fileprefix_{wnd,hfx,evap}.nc if fver is '3.1.0', otherwise output
    -0014 %       files will be fileprefix_wnd.nc.
    -0015 %   data - Struct of the data to be written out.
    -0016 %   infos - Additional remarks to be written to the "infos" NetCDF variable
    -0017 %   fver - Output for version 3.1.0 or 3.1.6. The latter means all the
    -0018 %       forcing can go in a single file, the former needs separate files
    -0019 %       for specific forcing data (wind, heating and precipitation).
    -0020 %
    -0021 % The fields in data may be called any of:
    -0022 %     - 'u10', 'v10', 'uwnd', 'vwnd' - wind components
    -0023 %     - 'slp'       - sea level pressure
    -0024 %     - 'P_E'       - evaporation
    -0025 %     - 'prate'     - precipitation
    -0026 %     - 'nswrs'     - short wave radiation
    -0027 %     - 'shtfl'\
    -0028 %     - 'lhtfl' >   - combine to form "surface net heat flux"
    -0029 %     - 'nlwrs'/
    -0030 %     - 'time'
    -0031 %     - 'lon'
    -0032 %     - 'lat'
    -0033 %     - 'x'
    -0034 %     - 'y'
    -0035 %
    -0036 % OUTPUT:
    -0037 %   FVCOM wind speed forcing NetCDF file(s)
    -0038 %
    -0039 %
    -0040 % Author(s):
    -0041 %   Pierre Cazenave (Plymouth Marine Laboratory)
    -0042 %   Karen Thurston (National Oceanography Centre, Liverpool)
    -0043 %
    -0044 % PWC Revision history:
    -0045 %   2012-11-01 - First version based on the parts of grid2fvcom_U10V10.m
    -0046 %   which dealt with writing the NetCDF file. This version now dynamically
    -0047 %   deals with varying numbers of forcing data.
    -0048 %   2012-11-09 - Add the correct calculation for the surface net heat flux.
    -0049 %
    -0050 % KJT Revision history:
    -0051 %   2013-01-16 - Added support for output of sea level pressure.
    +0011 %   Mobj - MATLAB mesh object containing fields:
    +0012 %       tri - triangulation table for the unstructured grid
    +0013 %       nVerts - number of grid vertices (nodes)
    +0014 %       nElems - number of grid elements
    +0015 %       nativeCoords - model coordinate type ('cartesian' or 'spherical')
    +0016 %       x, y or lon, lat - node positions (depending on nativeCoords value)
    +0017 %   fileprefix - Output NetCDF file prefix (plus path) will be
    +0018 %       fileprefix_{wnd,hfx,evap}.nc if fver is '3.1.0', otherwise output
    +0019 %       files will be fileprefix_wnd.nc.
    +0020 %   data - Struct of the data to be written out.
    +0021 %   infos - Additional remarks to be written to the "infos" NetCDF variable
    +0022 %   fver - Output for version 3.1.0 or 3.1.6. The latter means all the
    +0023 %       forcing can go in a single file, the former needs separate files
    +0024 %       for specific forcing data (wind, heating and precipitation).
    +0025 %
    +0026 % The fields in data may be called any of:
    +0027 %     - 'u10', 'v10', 'uwnd', 'vwnd' - wind components
    +0028 %     - 'slp'       - sea level pressure
    +0029 %     - 'pevpr'     - evaporation
    +0030 %     - 'prate'     - precipitation
    +0031 %     - 'slp'       - sea level pressure
    +0032 %     - 'nlwrs'     - net longwave radiation*,**
    +0033 %     - 'nswrs'     - net shortwave radiation*,**
    +0034 %     - 'shtfl'     - sensible heat net flux*,**
    +0035 %     - 'lhtfl'     - latent heat net flux*,**
    +0036 %     - 'lon'       - longitude (vector)
    +0037 %     - 'lat'       - latitude (vector)
    +0038 %     - 'x'         - eastings (vector)
    +0039 %     - 'y'         - northings (vector)
    +0040 %     - 'nshf'      - pre-computed net surface heat flux**
    +0041 %
    +0042 % Fields marked with an * are combined to form the "surface net heat flux"
    +0043 % (nshf) as follows:
    +0044 %
    +0045 %   nshf = -nlwrs + -nswrs - lhtfl - shtfl;
    +0046 %
    +0047 % ** Alternatively, a new field 'nshf' (net surface heat flux) can be
    +0048 % supplied, in which case shtfl and lhtfl are not necessary as their only
    +0049 % function is in the calculation of net surface heat flux. This approach
    +0050 % eliminates the need to interpolate so many variables onto the FVCOM grid,
    +0051 % thus decreasing the time needed to generate the FVCOM input files.
     0052 %
    -0053 %==========================================================================
    -0054 
    -0055 multi_out = false; % default to 3.1.6, single output file
    -0056 if nargin < 4 || nargin > 5
    -0057     error('Incorrect number of arguments')
    -0058 elseif nargin == 5
    -0059     if strcmpi(fver, '3.1.0')
    -0060         multi_out = true;
    -0061     end
    -0062 end
    -0063 
    -0064 subname = 'write_FVCOM_forcing';
    -0065 
    -0066 global ftbverbose;
    -0067 if(ftbverbose)
    -0068   fprintf('\n')
    -0069   fprintf(['begin : ' subname '\n'])
    -0070 end
    -0071 
    -0072 tri = Mobj.tri;
    -0073 nNodes = Mobj.nVerts;
    -0074 nElems = Mobj.nElems;
    -0075 ntimes = numel(data.time);
    -0076 
    -0077 if strcmpi(Mobj.nativeCoords,'cartesian')
    -0078     x = Mobj.x;
    -0079     y = Mobj.y;
    -0080 else
    -0081     x = Mobj.lon;
    -0082     y = Mobj.lat;
    -0083 end
    -0084 
    -0085 % Create element vertices positions
    -0086 xc = nodes2elems(x, Mobj);
    -0087 yc = nodes2elems(y, Mobj);
    -0088 
    -0089 %--------------------------------------------------------------------------
    -0090 % Create the NetCDF header for the FVCOM forcing file
    -0091 %--------------------------------------------------------------------------
    -0092 
    -0093 if multi_out
    -0094     suffixes = {'_wnd', '_hfx', '_evap', '_air_press'};
    -0095 else
    -0096     suffixes = {'_wnd'};
    -0097 end
    -0098 
    -0099 for i=1:length(suffixes)
    -0100     nc = netcdf.create([fileprefix, suffixes{i}, '.nc'], 'clobber');
    -0101 
    -0102 %     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'type','FVCOM Forcing File')
    -0103     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title','FVCOM Forcing File')
    -0104     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'institution','Plymouth Marine Laboratory')
    -0105     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'source','FVCOM grid (unstructured) surface forcing')
    -0106     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history',['File created on ', datestr(now, 'yyyy-mm-dd HH:MM:SS'), ' with write_FVCOM_forcing.m from the fvcom-toolbox (https://github.com/pwcazenave/fvcom-toolbox)'])
    -0107     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'references','http://fvcom.smast.umassd.edu, http://codfish.smast.umassd.edu')
    -0108     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'Conventions','CF-1.0')
    -0109 %     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'infos',infos)
    -0110     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CoordinateSystem',Mobj.nativeCoords)
    -0111     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CoordinateProjection','init=epsg:4326') % WGS84?
    -0112 
    -0113     % Dimensions
    -0114     nele_dimid=netcdf.defDim(nc,'nele',nElems);
    -0115     node_dimid=netcdf.defDim(nc,'node',nNodes);
    -0116     three_dimid=netcdf.defDim(nc,'three',3);
    -0117     time_dimid=netcdf.defDim(nc,'time',netcdf.getConstant('NC_UNLIMITED'));
    -0118     datestrlen_dimid=netcdf.defDim(nc,'DateStrLen',26);
    -0119 
    -0120     % Space variables
    -0121     x_varid=netcdf.defVar(nc,'x','NC_FLOAT',node_dimid);
    -0122     netcdf.putAtt(nc,x_varid,'long_name','nodal x-coordinate');
    -0123     netcdf.putAtt(nc,x_varid,'units','meters');
    -0124 
    -0125     y_varid=netcdf.defVar(nc,'y','NC_FLOAT',node_dimid);
    -0126     netcdf.putAtt(nc,y_varid,'long_name','nodal y-coordinate');
    -0127     netcdf.putAtt(nc,y_varid,'units','meters');
    -0128 
    -0129     xc_varid=netcdf.defVar(nc,'xc','NC_FLOAT',nele_dimid);
    -0130     netcdf.putAtt(nc,xc_varid,'long_name','zonal x-coordinate');
    -0131     netcdf.putAtt(nc,xc_varid,'units','meters');
    -0132 
    -0133     yc_varid=netcdf.defVar(nc,'yc','NC_FLOAT',nele_dimid);
    -0134     netcdf.putAtt(nc,yc_varid,'long_name','zonal y-coordinate');
    -0135     netcdf.putAtt(nc,yc_varid,'units','meters');
    -0136 
    -0137     nv_varid=netcdf.defVar(nc,'nv','NC_INT',[nele_dimid, three_dimid]);
    -0138     netcdf.putAtt(nc,nv_varid,'long_name','nodes surrounding element');
    -0139 
    -0140     % Time variables
    -0141     time_varid=netcdf.defVar(nc,'time','NC_FLOAT',time_dimid);
    -0142     netcdf.putAtt(nc,time_varid,'long_name','time');
    -0143     netcdf.putAtt(nc,time_varid,'units','days since 1858-11-17 00:00:00');
    -0144     netcdf.putAtt(nc,time_varid,'format','modified julian day (MJD)');
    -0145     netcdf.putAtt(nc,time_varid,'time_zone','UTC');
    -0146 
    -0147     itime_varid=netcdf.defVar(nc,'Itime','NC_INT',time_dimid);
    -0148     netcdf.putAtt(nc,itime_varid,'units','days since 1858-11-17 00:00:00');
    -0149     netcdf.putAtt(nc,itime_varid,'format','modified julian day (MJD)');
    -0150     netcdf.putAtt(nc,itime_varid,'time_zone','UTC');
    -0151 
    -0152     itime2_varid=netcdf.defVar(nc,'Itime2','NC_INT',time_dimid);
    -0153     netcdf.putAtt(nc,itime2_varid,'units','msec since 00:00:00');
    -0154     netcdf.putAtt(nc,itime2_varid,'time_zone','UTC');
    -0155 
    -0156     % Since we have a dynamic number of variables in the struct, try to be a
    -0157     % bit clever about how to create the output variables.
    -0158     fnames = fieldnames(data);
    -0159     used_varids = cell(0);
    -0160     used_fnames = cell(0);
    -0161     used_dims = cell(0); % exclude time (assume all variables vary in time)
    -0162 
    -0163     for vv=1:length(fnames)
    -0164         % Need to check both whether we have the data but also whether
    -0165         % we're outputting to several NetCDF files. If so, we drop some
    -0166         % variables if we're in the wrong file loop.
    -0167         switch fnames{vv}
    -0168             case {'uwnd', 'u10'}
    -0169                 if strcmpi(suffixes{i}, '_wnd') || ~multi_out
    -0170                     % wind components (assume we have v if we have u)
    -0171 
    -0172                     % On the elements
    -0173                     u10_varid=netcdf.defVar(nc,'U10','NC_FLOAT',[nele_dimid, time_dimid]);
    -0174                     netcdf.putAtt(nc,u10_varid,'long_name','Eastward Wind Speed');
    -0175 %                     netcdf.putAtt(nc,u10_varid,'standard_name','Eastward Wind Speed');
    -0176                     netcdf.putAtt(nc,u10_varid,'units','m/s');
    -0177                     netcdf.putAtt(nc,u10_varid,'grid','fvcom_grid');
    -0178                     netcdf.putAtt(nc,u10_varid,'coordinates','');
    -0179                     netcdf.putAtt(nc,u10_varid,'type','data');
    -0180 
    -0181                     v10_varid=netcdf.defVar(nc,'V10','NC_FLOAT',[nele_dimid, time_dimid]);
    -0182                     netcdf.putAtt(nc,v10_varid,'long_name','Northward Wind Speed');
    -0183 %                     netcdf.putAtt(nc,v10_varid,'standard_name','Northward Wind Speed');
    -0184                     netcdf.putAtt(nc,v10_varid,'units','m/s');
    -0185                     netcdf.putAtt(nc,v10_varid,'grid','fvcom_grid');
    -0186                     netcdf.putAtt(nc,v10_varid,'coordinates','');
    -0187                     netcdf.putAtt(nc,v10_varid,'type','data');
    +0053 % OUTPUT:
    +0054 %   FVCOM wind speed forcing NetCDF file(s)
    +0055 %
    +0056 % EXAMPLE USAGE:
    +0057 %   windBase = '/path/to/output/casename_wnd.nc';
    +0058 %   write_FVCOM_forcing(Mobj, windBase, data, ...
    +0059 %       'FVCOM atmospheric forcing data', '3.1.6');
    +0060 %
    +0061 % Author(s):
    +0062 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0063 %   Karen Thurston (National Oceanography Centre, Liverpool)
    +0064 %
    +0065 % PWC Revision history:
    +0066 %   2012-11-01 - First version based on the parts of grid2fvcom_U10V10.m
    +0067 %   which dealt with writing the NetCDF file. This version now dynamically
    +0068 %   deals with varying numbers of forcing data.
    +0069 %   2012-11-09 - Add the correct calculation for the net surface heat flux.
    +0070 %   2013-02-14 - Fix the surface net heat flux sign convention, include the
    +0071 %   longwave radiation variable and add support for a new field in the
    +0072 %   input struct ('nshf') which contains the pre-computed net surface heat
    +0073 %   flux.
    +0074 %   2013-05-13 - Fix the evaporation to use the correct variable from NCEP
    +0075 %   (pevpr rather than P_E which is actually the precipitation minus the
    +0076 %   evaporation in Et). The data in Et are calcaulated from lhtfl whereas
    +0077 %   pevpr comes directly from NCEP and to me it seems more sensible to use
    +0078 %   that to maintain consistency.
    +0079 %   2013-05-14 - Add example usage to the help and specify which fields are
    +0080 %   required in Mobj.
    +0081 %
    +0082 % KJT Revision history:
    +0083 %   2013-01-16 - Added support for output of sea level pressure.
    +0084 %
    +0085 %==========================================================================
    +0086 
    +0087 multi_out = false; % default to 3.1.6, single output file
    +0088 if nargin < 4 || nargin > 5
    +0089     error('Incorrect number of arguments')
    +0090 elseif nargin == 5
    +0091     if strcmpi(fver, '3.1.0')
    +0092         multi_out = true;
    +0093     end
    +0094 end
    +0095 
    +0096 subname = 'write_FVCOM_forcing';
    +0097 
    +0098 global ftbverbose;
    +0099 if ftbverbose
    +0100     fprintf('\nbegin : %s \n', subname)
    +0101 end
    +0102 
    +0103 tri = Mobj.tri;
    +0104 nNodes = Mobj.nVerts;
    +0105 nElems = Mobj.nElems;
    +0106 ntimes = numel(data.time);
    +0107 
    +0108 if strcmpi(Mobj.nativeCoords, 'cartesian')
    +0109     x = Mobj.x;
    +0110     y = Mobj.y;
    +0111 else
    +0112     x = Mobj.lon;
    +0113     y = Mobj.lat;
    +0114 end
    +0115 % Create a string for each variable's coordinate attribute
    +0116 coordString = sprintf('FVCOM %s coordinates', Mobj.nativeCoords);
    +0117 
    +0118 % Create element vertices positions
    +0119 xc = nodes2elems(x, Mobj);
    +0120 yc = nodes2elems(y, Mobj);
    +0121 
    +0122 %--------------------------------------------------------------------------
    +0123 % Create the NetCDF header for the FVCOM forcing file
    +0124 %--------------------------------------------------------------------------
    +0125 
    +0126 if multi_out
    +0127     suffixes = {'_wnd', '_hfx', '_evap', '_air_press'};
    +0128 else
    +0129     suffixes = {'_wnd'};
    +0130 end
    +0131 
    +0132 % We use this variable to indicate whether we were given precalculated net
    +0133 % surface heat flux.
    +0134 nshf = 0;
    +0135 
    +0136 for i=1:length(suffixes)
    +0137     nc = netcdf.create([fileprefix, suffixes{i}, '.nc'], 'clobber');
    +0138 
    +0139 %     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'type','FVCOM Forcing File')
    +0140     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title','FVCOM Forcing File')
    +0141     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'institution','Plymouth Marine Laboratory')
    +0142     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'source','FVCOM grid (unstructured) surface forcing')
    +0143     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history',['File created on ', datestr(now, 'yyyy-mm-dd HH:MM:SS'), ' with write_FVCOM_forcing.m from the MATLAB fvcom-toolbox (https://github.com/pwcazenave/fvcom-toolbox)'])
    +0144     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'references','http://fvcom.smast.umassd.edu, http://codfish.smast.umassd.edu')
    +0145     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'Conventions','CF-1.0')
    +0146 %     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'infos',infos)
    +0147     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CoordinateSystem',Mobj.nativeCoords)
    +0148     netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CoordinateProjection','init=epsg:4326') % WGS84?
    +0149 
    +0150     % Dimensions
    +0151     nele_dimid=netcdf.defDim(nc,'nele',nElems);
    +0152     node_dimid=netcdf.defDim(nc,'node',nNodes);
    +0153     three_dimid=netcdf.defDim(nc,'three',3);
    +0154     time_dimid=netcdf.defDim(nc,'time',netcdf.getConstant('NC_UNLIMITED'));
    +0155     datestrlen_dimid=netcdf.defDim(nc,'DateStrLen',26);
    +0156 
    +0157     % Space variables
    +0158     x_varid=netcdf.defVar(nc,'x','NC_FLOAT',node_dimid);
    +0159     netcdf.putAtt(nc,x_varid,'long_name','nodal x-coordinate');
    +0160     netcdf.putAtt(nc,x_varid,'units','meters');
    +0161 
    +0162     y_varid=netcdf.defVar(nc,'y','NC_FLOAT',node_dimid);
    +0163     netcdf.putAtt(nc,y_varid,'long_name','nodal y-coordinate');
    +0164     netcdf.putAtt(nc,y_varid,'units','meters');
    +0165 
    +0166     xc_varid=netcdf.defVar(nc,'xc','NC_FLOAT',nele_dimid);
    +0167     netcdf.putAtt(nc,xc_varid,'long_name','zonal x-coordinate');
    +0168     netcdf.putAtt(nc,xc_varid,'units','meters');
    +0169 
    +0170     yc_varid=netcdf.defVar(nc,'yc','NC_FLOAT',nele_dimid);
    +0171     netcdf.putAtt(nc,yc_varid,'long_name','zonal y-coordinate');
    +0172     netcdf.putAtt(nc,yc_varid,'units','meters');
    +0173 
    +0174     nv_varid=netcdf.defVar(nc,'nv','NC_INT',[nele_dimid, three_dimid]);
    +0175     netcdf.putAtt(nc,nv_varid,'long_name','nodes surrounding element');
    +0176 
    +0177     % Time variables
    +0178     time_varid=netcdf.defVar(nc,'time','NC_FLOAT',time_dimid);
    +0179     netcdf.putAtt(nc,time_varid,'long_name','time');
    +0180     netcdf.putAtt(nc,time_varid,'units','days since 1858-11-17 00:00:00');
    +0181     netcdf.putAtt(nc,time_varid,'format','modified julian day (MJD)');
    +0182     netcdf.putAtt(nc,time_varid,'time_zone','UTC');
    +0183 
    +0184     itime_varid=netcdf.defVar(nc,'Itime','NC_INT',time_dimid);
    +0185     netcdf.putAtt(nc,itime_varid,'units','days since 1858-11-17 00:00:00');
    +0186     netcdf.putAtt(nc,itime_varid,'format','modified julian day (MJD)');
    +0187     netcdf.putAtt(nc,itime_varid,'time_zone','UTC');
     0188 
    -0189                     uwind_varid=netcdf.defVar(nc,'uwind_speed','NC_FLOAT',[nele_dimid, time_dimid]);
    -0190                     netcdf.putAtt(nc,uwind_varid,'long_name','Eastward Wind Speed');
    -0191                     netcdf.putAtt(nc,uwind_varid,'standard_name','Wind Speed');
    -0192                     netcdf.putAtt(nc,uwind_varid,'units','m/s');
    -0193                     netcdf.putAtt(nc,uwind_varid,'grid','fvcom_grid');
    -0194                     netcdf.putAtt(nc,uwind_varid,'type','data');
    -0195 
    -0196                     vwind_varid=netcdf.defVar(nc,'vwind_speed','NC_FLOAT',[nele_dimid, time_dimid]);
    -0197                     netcdf.putAtt(nc,vwind_varid,'long_name','Northward Wind Speed');
    -0198                     netcdf.putAtt(nc,vwind_varid,'standard_name','Wind Speed');
    -0199                     netcdf.putAtt(nc,vwind_varid,'units','m/s');
    -0200                     netcdf.putAtt(nc,vwind_varid,'grid','fvcom_grid');
    -0201                     netcdf.putAtt(nc,vwind_varid,'type','data');
    -0202 
    -0203                     % On the nodes
    -0204 %                     u10_node_varid=netcdf.defVar(nc,'U10','NC_FLOAT',[node_dimid, time_dimid]);
    -0205 %                     netcdf.putAtt(nc,u10_node_varid,'long_name','Eastward 10-m Velocity');
    -0206 %                     netcdf.putAtt(nc,u10_node_varid,'standard_name','Eastward Wind Speed');
    -0207 %                     netcdf.putAtt(nc,u10_node_varid,'units','m/s');
    -0208 %                     netcdf.putAtt(nc,u10_node_varid,'grid','fvcom_grid');
    -0209 %                     netcdf.putAtt(nc,u10_node_varid,'type','data');
    -0210 %                     netcdf.putAtt(nc,u10_node_varid,'coordinates','');
    -0211 %
    -0212 %                     v10_node_varid=netcdf.defVar(nc,'V10','NC_FLOAT',[node_dimid, time_dimid]);
    -0213 %                     netcdf.putAtt(nc,v10_node_varid,'long_name','Northward 10-m Velocity');
    -0214 %                     netcdf.putAtt(nc,v10_node_varid,'standard_name','Northward Wind Speed');
    -0215 %                     netcdf.putAtt(nc,v10_node_varid,'units','m/s');
    -0216 %                     netcdf.putAtt(nc,v10_node_varid,'grid','fvcom_grid');
    -0217 %                     netcdf.putAtt(nc,v10_node_varid,'type','data');
    -0218 %                     netcdf.putAtt(nc,v10_node_varid,'coordinates','');
    -0219 
    -0220 %                     % Both node and element centred
    -0221 %                     used_varids = [used_varids, {'u10_varid', 'v10_varid', 'u10_node_varid', 'v10_node_varid'}];
    -0222 %                     used_fnames = [used_fnames, {'uwnd', 'vwnd', 'uwnd', 'vwnd'}];
    -0223 %                     used_dims = [used_dims, {'nElems', 'nElems', 'nNodes', 'nNodes'}];
    -0224 %                     % Only on the nodes
    -0225 %                     used_varids = [used_varids, {'u10_node_varid', 'v10_node_varid'}];
    -0226 %                     used_fnames = [used_fnames, {'uwnd', 'vwnd'}];
    -0227 %                     used_dims = [used_dims, {'nNodes', 'nNodes'}];
    -0228                     % Only on the elements
    -0229 %                     used_varids = [used_varids, {'u10_varid', 'v10_varid'}];
    -0230 %                     used_fnames = [used_fnames, {'uwnd', 'vwnd'}];
    -0231 %                     used_dims = [used_dims, {'nElems', 'nElems'}];
    -0232                     % Only on the elements (both U10/V10 and uwind_speed and
    -0233                     % vwind_speed).
    -0234                     used_varids = [used_varids, {'u10_varid', 'v10_varid', 'uwind_varid', 'vwind_varid'}];
    -0235                     used_fnames = [used_fnames, {'uwnd', 'vwnd', 'uwnd', 'vwnd'}];
    -0236                     used_dims = [used_dims, {'nElems', 'nElems', 'nElems', 'nElems'}];
    -0237                 end
    +0189     itime2_varid=netcdf.defVar(nc,'Itime2','NC_INT',time_dimid);
    +0190     netcdf.putAtt(nc,itime2_varid,'units','msec since 00:00:00');
    +0191     netcdf.putAtt(nc,itime2_varid,'time_zone','UTC');
    +0192     netcdf.putAtt(nc,itime2_varid,'long_name','time');
    +0193 
    +0194     times_varid=netcdf.defVar(nc,'Times','NC_CHAR',[datestrlen_dimid,time_dimid]);
    +0195     netcdf.putAtt(nc,times_varid,'long_name','Calendar Date');
    +0196     netcdf.putAtt(nc,times_varid,'format','String: Calendar Time');
    +0197     netcdf.putAtt(nc,times_varid,'time_zone','UTC');
    +0198 
    +0199     % Since we have a dynamic number of variables in the struct, try to be a
    +0200     % bit clever about how to create the output variables.
    +0201     fnames = fieldnames(data);
    +0202     used_varids = cell(0);
    +0203     used_fnames = cell(0);
    +0204     used_dims = cell(0); % exclude time (assume all variables vary in time)
    +0205 
    +0206     for vv=1:length(fnames)
    +0207         % Need to check both whether we have the data but also whether
    +0208         % we're outputting to several NetCDF files. If so, we drop some
    +0209         % variables if we're in the wrong file loop.
    +0210         switch fnames{vv}
    +0211             case {'uwnd', 'u10'}
    +0212                 if strcmpi(suffixes{i}, '_wnd') || ~multi_out
    +0213                     % wind components (assume we have v if we have u)
    +0214 
    +0215                     % On the elements
    +0216                     u10_varid=netcdf.defVar(nc,'U10','NC_FLOAT',[nele_dimid, time_dimid]);
    +0217                     netcdf.putAtt(nc,u10_varid,'long_name','Eastward Wind Speed');
    +0218 %                     netcdf.putAtt(nc,u10_varid,'standard_name','Eastward Wind Speed');
    +0219                     netcdf.putAtt(nc,u10_varid,'units','m/s');
    +0220                     netcdf.putAtt(nc,u10_varid,'grid','fvcom_grid');
    +0221                     netcdf.putAtt(nc,u10_varid,'coordinates',coordString);
    +0222                     netcdf.putAtt(nc,u10_varid,'type','data');
    +0223 
    +0224                     v10_varid=netcdf.defVar(nc,'V10','NC_FLOAT',[nele_dimid, time_dimid]);
    +0225                     netcdf.putAtt(nc,v10_varid,'long_name','Northward Wind Speed');
    +0226 %                     netcdf.putAtt(nc,v10_varid,'standard_name','Northward Wind Speed');
    +0227                     netcdf.putAtt(nc,v10_varid,'units','m/s');
    +0228                     netcdf.putAtt(nc,v10_varid,'grid','fvcom_grid');
    +0229                     netcdf.putAtt(nc,v10_varid,'coordinates',coordString);
    +0230                     netcdf.putAtt(nc,v10_varid,'type','data');
    +0231 
    +0232                     uwind_varid=netcdf.defVar(nc,'uwind_speed','NC_FLOAT',[nele_dimid, time_dimid]);
    +0233                     netcdf.putAtt(nc,uwind_varid,'long_name','Eastward Wind Speed');
    +0234                     netcdf.putAtt(nc,uwind_varid,'standard_name','Wind Speed');
    +0235                     netcdf.putAtt(nc,uwind_varid,'units','m/s');
    +0236                     netcdf.putAtt(nc,uwind_varid,'grid','fvcom_grid');
    +0237                     netcdf.putAtt(nc,uwind_varid,'type','data');
     0238 
    -0239             case 'slp'
    -0240                 if strcmpi(suffixes{i}, '_air_press') || ~multi_out
    -0241                     % Sea level pressure
    -0242                     slp_varid=netcdf.defVar(nc,'air_pressure','NC_FLOAT',[node_dimid, time_dimid]);
    -0243                     netcdf.putAtt(nc,slp_varid,'long_name','Surface air pressure');
    -0244                     netcdf.putAtt(nc,slp_varid,'units','Pa');
    -0245                     netcdf.putAtt(nc,slp_varid,'grid','fvcom_grid');
    -0246                     netcdf.putAtt(nc,slp_varid,'coordinates','');
    -0247                     netcdf.putAtt(nc,slp_varid,'type','data');
    -0248 
    -0249                     used_varids = [used_varids, 'slp_varid'];
    -0250                     used_fnames = [used_fnames, fnames{vv}];
    -0251                     used_dims = [used_dims, 'nNodes'];
    -0252                 end
    -0253 
    -0254             case 'P_E'
    -0255                 if strcmpi(suffixes{i}, '_evap') || ~multi_out
    -0256                     % Evaporation
    -0257                     pe_varid=netcdf.defVar(nc,'evap','NC_FLOAT',[node_dimid, time_dimid]);
    -0258                     netcdf.putAtt(nc,pe_varid,'long_name','Evaporation');
    -0259                     netcdf.putAtt(nc,pe_varid,'description','Evaporation, ocean lose water is negative');
    -0260                     netcdf.putAtt(nc,pe_varid,'units','m s-1');
    -0261                     netcdf.putAtt(nc,pe_varid,'grid','fvcom_grid');
    -0262                     netcdf.putAtt(nc,pe_varid,'coordinates','');
    -0263                     netcdf.putAtt(nc,pe_varid,'type','data');
    -0264 
    -0265                     used_varids = [used_varids, 'pe_varid'];
    -0266                     used_fnames = [used_fnames, fnames{vv}];
    -0267                     used_dims = [used_dims, 'nNodes'];
    -0268                 end
    -0269 
    -0270             case 'prate'
    -0271                 if strcmpi(suffixes{i}, '_evap') || ~multi_out
    -0272                     % Precipitation
    -0273                     prate_varid=netcdf.defVar(nc,'precip','NC_FLOAT',[node_dimid, time_dimid]);
    -0274                     netcdf.putAtt(nc,prate_varid,'long_name','Precipitation');
    -0275                     netcdf.putAtt(nc,prate_varid,'description','Precipitation, ocean lose water is negative');
    -0276                     netcdf.putAtt(nc,prate_varid,'units','m s-1');
    -0277                     netcdf.putAtt(nc,prate_varid,'grid','fvcom_grid');
    -0278                     netcdf.putAtt(nc,prate_varid,'coordinates','');
    -0279                     netcdf.putAtt(nc,prate_varid,'type','data');
    -0280 
    -0281                     used_varids = [used_varids, 'prate_varid'];
    -0282                     used_fnames = [used_fnames, fnames{vv}];
    -0283                     used_dims = [used_dims, 'nNodes'];
    -0284                 end
    -0285 
    -0286             case 'nswrs'
    -0287                 if strcmpi(suffixes{i}, '_hfx') || ~multi_out
    -0288                     % Shortwave radiation
    -0289                     nswrs_varid=netcdf.defVar(nc,'short_wave','NC_FLOAT',[node_dimid, time_dimid]);
    -0290                     netcdf.putAtt(nc,nswrs_varid,'long_name','Short Wave Radiation');
    -0291                     netcdf.putAtt(nc,nswrs_varid,'units','W m-2');
    -0292                     netcdf.putAtt(nc,nswrs_varid,'grid','fvcom_grid');
    -0293                     netcdf.putAtt(nc,nswrs_varid,'coordinates','');
    -0294                     netcdf.putAtt(nc,nswrs_varid,'type','data');
    -0295 
    -0296                     used_varids = [used_varids, 'nswrs_varid'];
    -0297                     used_fnames = [used_fnames, fnames{vv}];
    -0298                     used_dims = [used_dims, 'nNodes'];
    -0299                 end
    -0300 
    -0301             case {'shtfl', 'lhtfl', 'nlwrs'}
    -0302                 try
    -0303                     % We might have already made this attribute, so fail
    -0304                     % elegantly if we do. This is because we need to put
    -0305                     % all three of shtfl, lhtfl and nlwrs to make Surface
    -0306                     % Net Heat Flux.
    -0307                     if strcmpi(suffixes{i}, '_hfx') || ~multi_out
    -0308                         % Surface net heat flux
    -0309                         nhf_varid=netcdf.defVar(nc,'net_heat_flux','NC_FLOAT',[node_dimid, time_dimid]);
    -0310                         netcdf.putAtt(nc,nhf_varid,'long_name','Surface Net Heat Flux');
    -0311                         netcdf.putAtt(nc,nhf_varid,'units','W m-2');
    -0312                         netcdf.putAtt(nc,nhf_varid,'grid','fvcom_grid');
    -0313                         netcdf.putAtt(nc,nhf_varid,'coordinates','');
    -0314                         netcdf.putAtt(nc,nhf_varid,'type','data');
    -0315                     end
    -0316                 end
    -0317                 if strcmpi(suffixes{i}, '_hfx') || ~multi_out
    -0318                     % We need to save the current variable name even if we've
    -0319                     % already made its attribute.
    -0320                     used_varids = [used_varids, 'nhf_varid'];
    -0321                     used_fnames = [used_fnames, fnames{vv}];
    -0322                     used_dims = [used_dims, 'nNodes'];
    -0323                 end
    -0324 
    -0325             case {'time', 'lon', 'lat', 'x', 'y'}
    -0326                 continue
    -0327 
    -0328             otherwise
    -0329                 if(ftbverbose)
    -0330                     warning('Unknown or unused input data type: %s', fnames{vv})
    -0331                 end
    -0332         end
    -0333     end
    +0239                     vwind_varid=netcdf.defVar(nc,'vwind_speed','NC_FLOAT',[nele_dimid, time_dimid]);
    +0240                     netcdf.putAtt(nc,vwind_varid,'long_name','Northward Wind Speed');
    +0241                     netcdf.putAtt(nc,vwind_varid,'standard_name','Wind Speed');
    +0242                     netcdf.putAtt(nc,vwind_varid,'units','m/s');
    +0243                     netcdf.putAtt(nc,vwind_varid,'grid','fvcom_grid');
    +0244                     netcdf.putAtt(nc,vwind_varid,'type','data');
    +0245 
    +0246                     % Only on the elements (both U10/V10 and uwind_speed and
    +0247                     % vwind_speed).
    +0248                     used_varids = [used_varids, {'u10_varid', 'v10_varid', 'uwind_varid', 'vwind_varid'}];
    +0249                     used_fnames = [used_fnames, {'uwnd', 'vwnd', 'uwnd', 'vwnd'}];
    +0250                     used_dims = [used_dims, {'nElems', 'nElems', 'nElems', 'nElems'}];
    +0251                 end
    +0252                 
    +0253             case {'vwnd', 'v10'}
    +0254                 % We dealt with these in the u component section above, so
    +0255                 % just pass silently.
    +0256                 true;
    +0257 
    +0258             case 'slp'
    +0259                 if strcmpi(suffixes{i}, '_air_press') || ~multi_out
    +0260                     % Sea level pressure
    +0261                     slp_varid=netcdf.defVar(nc,'air_pressure','NC_FLOAT',[node_dimid, time_dimid]);
    +0262                     netcdf.putAtt(nc,slp_varid,'long_name','Surface air pressure');
    +0263                     netcdf.putAtt(nc,slp_varid,'units','Pa');
    +0264                     netcdf.putAtt(nc,slp_varid,'grid','fvcom_grid');
    +0265                     netcdf.putAtt(nc,slp_varid,'coordinates',coordString);
    +0266                     netcdf.putAtt(nc,slp_varid,'type','data');
    +0267 
    +0268                     used_varids = [used_varids, 'slp_varid'];
    +0269                     used_fnames = [used_fnames, fnames{vv}];
    +0270                     used_dims = [used_dims, 'nNodes'];
    +0271                 end
    +0272 
    +0273             case {'pevpr', 'Et'}
    +0274                 if strcmpi(suffixes{i}, '_evap') || ~multi_out
    +0275                     % Evaporation
    +0276                     pevpr_varid=netcdf.defVar(nc,'evap','NC_FLOAT',[node_dimid, time_dimid]);
    +0277                     netcdf.putAtt(nc,pevpr_varid,'long_name','Evaporation');
    +0278                     netcdf.putAtt(nc,pevpr_varid,'description','Evaporation, ocean lose water is negative');
    +0279                     netcdf.putAtt(nc,pevpr_varid,'units','m s-1');
    +0280                     netcdf.putAtt(nc,pevpr_varid,'grid','fvcom_grid');
    +0281                     netcdf.putAtt(nc,pevpr_varid,'coordinates',coordString);
    +0282                     netcdf.putAtt(nc,pevpr_varid,'type','data');
    +0283 
    +0284                     used_varids = [used_varids, 'pevpr_varid'];
    +0285                     used_fnames = [used_fnames, fnames{vv}];
    +0286                     used_dims = [used_dims, 'nNodes'];
    +0287                 end
    +0288 
    +0289             case {'prate', 'P_E'}
    +0290                 if strcmpi(suffixes{i}, '_evap') || ~multi_out
    +0291                     % Precipitation
    +0292                     prate_varid=netcdf.defVar(nc,'precip','NC_FLOAT',[node_dimid, time_dimid]);
    +0293                     netcdf.putAtt(nc,prate_varid,'long_name','Precipitation');
    +0294                     netcdf.putAtt(nc,prate_varid,'description','Precipitation, ocean lose water is negative');
    +0295                     netcdf.putAtt(nc,prate_varid,'units','m s-1');
    +0296                     netcdf.putAtt(nc,prate_varid,'grid','fvcom_grid');
    +0297                     netcdf.putAtt(nc,prate_varid,'coordinates',coordString);
    +0298                     netcdf.putAtt(nc,prate_varid,'type','data');
    +0299 
    +0300                     used_varids = [used_varids, 'prate_varid'];
    +0301                     used_fnames = [used_fnames, fnames{vv}];
    +0302                     used_dims = [used_dims, 'nNodes'];
    +0303                 end
    +0304 
    +0305             case 'nswrs'
    +0306                 if strcmpi(suffixes{i}, '_hfx') || ~multi_out
    +0307                     % Shortwave radiation
    +0308                     nswrs_varid=netcdf.defVar(nc,'short_wave','NC_FLOAT',[node_dimid, time_dimid]);
    +0309                     netcdf.putAtt(nc,nswrs_varid,'long_name','Short Wave Radiation');
    +0310                     netcdf.putAtt(nc,nswrs_varid,'units','W m-2');
    +0311                     netcdf.putAtt(nc,nswrs_varid,'grid','fvcom_grid');
    +0312                     netcdf.putAtt(nc,nswrs_varid,'coordinates',coordString);
    +0313                     netcdf.putAtt(nc,nswrs_varid,'type','data');
    +0314 
    +0315                     used_varids = [used_varids, 'nswrs_varid'];
    +0316                     used_fnames = [used_fnames, fnames{vv}];
    +0317                     used_dims = [used_dims, 'nNodes'];
    +0318                 end
    +0319 
    +0320             case 'nlwrs'
    +0321                 if strcmpi(suffixes{i}, '_hfx') || ~multi_out
    +0322                     % Longwave radiation
    +0323                     nlwrs_varid=netcdf.defVar(nc,'long_wave','NC_FLOAT',[node_dimid, time_dimid]);
    +0324                     netcdf.putAtt(nc,nlwrs_varid,'long_name','Long Wave Radiation');
    +0325                     netcdf.putAtt(nc,nlwrs_varid,'units','W m-2');
    +0326                     netcdf.putAtt(nc,nlwrs_varid,'grid','fvcom_grid');
    +0327                     netcdf.putAtt(nc,nlwrs_varid,'coordinates',coordString);
    +0328                     netcdf.putAtt(nc,nlwrs_varid,'type','data');
    +0329 
    +0330                     used_varids = [used_varids, 'nlwrs_varid'];
    +0331                     used_fnames = [used_fnames, fnames{vv}];
    +0332                     used_dims = [used_dims, 'nNodes'];
    +0333                 end
     0334 
    -0335     % End definitions
    -0336     netcdf.endDef(nc);
    -0337 
    -0338     % Put the easy ones in first.
    -0339     netcdf.putVar(nc,nv_varid, tri');
    -0340     netcdf.putVar(nc,time_varid,0,ntimes,data.time);
    -0341     netcdf.putVar(nc,itime_varid,0,ntimes,floor(data.time));
    -0342     netcdf.putVar(nc,itime2_varid,0,ntimes,mod(data.time,1)*24*3600*1000);
    -0343     netcdf.putVar(nc,x_varid,x);
    -0344     netcdf.putVar(nc,y_varid,y);
    -0345     netcdf.putVar(nc,xc_varid,xc);
    -0346     netcdf.putVar(nc,yc_varid,yc);
    -0347 
    -0348     % Now do the dynamic ones. Set the heat flux to not done (0) until we
    -0349     % hit one of the holy trinity (shtfl, lhtfl, nlwrs).
    -0350     hf_done = 0;
    -0351     for ff=1:length(used_fnames)
    -0352         if strcmpi(used_fnames{ff}, 'shtfl') || strcmpi(used_fnames{ff}, 'lhtfl') || strcmpi(used_fnames{ff}, 'nlwrs')
    -0353             hf_done = hf_done + 1;
    -0354             if hf_done == 3
    -0355                 % We've got all three heat parameters, so dump them into the file.
    -0356                 hf = data.shtfl.node + data.lhtfl.node + data.nlwrs.node;
    -0357                 netcdf.putVar(nc,nhf_varid,[0,0],[nNodes,ntimes],hf)
    -0358             end
    -0359         else
    -0360             % One of the other data sets for which we can simply dump the
    -0361             % existing array without waiting for other data
    -0362             if strcmpi(used_dims{ff}, 'nNodes')
    -0363                 eval(['netcdf.putVar(nc,',used_varids{ff},',[0,0],[',used_dims{ff},',ntimes],data.',used_fnames{ff},'.node);'])
    -0364             else
    -0365                 eval(['netcdf.putVar(nc,',used_varids{ff},',[0,0],[',used_dims{ff},',ntimes],data.',used_fnames{ff},'.data);'])
    -0366             end
    -0367         end
    -0368     end
    -0369     if hf_done ~= 3
    -0370         warning('Did not have all the required heat flux parameters. Need ''shtfl'', ''lhtfl'', ''nlwrs''')
    -0371     end
    -0372 
    -0373     % Close the NetCDF file(s)
    -0374     netcdf.close(nc);
    -0375 end
    -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +0335 case {'shtfl', 'lhtfl', 'nshf'} % , 'nlwrs', 'nswrs'} +0336 % We can't trigger on nlwrs and nswrs here because they're +0337 % the triggers for the net longwave and shortwave variables +0338 % above. Instead, we need to use the latent heat flux +0339 % variables as the triggers for the net heat flux. +0340 % We also need to check for the existence of the "net +0341 % surface heat flux ('nshf')" field which can be created before +0342 % calling grid2fvcom. This approach means there's fewer +0343 % calls to the (expensive) interpolation as the net surface +0344 % heat flux is calculated before being interpolated onto +0345 % the FVCOM grid. Set the nshf variable accordingly. +0346 if strcmpi(fnames{vv}, 'nshf') +0347 nshf = 1; +0348 end +0349 try +0350 % We might have already made this attribute, so fail +0351 % elegantly if we do. This is because we need to put +0352 % all four of shtfl, lhtfl, nlwrs and nswrs to make +0353 % Surface Net Heat Flux. +0354 if strcmpi(suffixes{i}, '_hfx') || ~multi_out +0355 % Surface net heat flux +0356 nhf_varid=netcdf.defVar(nc,'net_heat_flux','NC_FLOAT',[node_dimid, time_dimid]); +0357 netcdf.putAtt(nc,nhf_varid,'long_name','Surface Net Heat Flux'); +0358 netcdf.putAtt(nc,nhf_varid,'units','W m-2'); +0359 netcdf.putAtt(nc,nhf_varid,'grid','fvcom_grid'); +0360 netcdf.putAtt(nc,nhf_varid,'coordinates',coordString); +0361 netcdf.putAtt(nc,nhf_varid,'type','data'); +0362 end +0363 end +0364 if strcmpi(suffixes{i}, '_hfx') || ~multi_out +0365 % We need to save the current variable name even if we've +0366 % already made its attribute. +0367 used_varids = [used_varids, 'nhf_varid']; +0368 used_fnames = [used_fnames, fnames{vv}]; +0369 used_dims = [used_dims, 'nNodes']; +0370 end +0371 +0372 case {'time', 'lon', 'lat', 'x', 'y'} +0373 continue +0374 +0375 otherwise +0376 if ftbverbose +0377 warning('Unknown or possibly unused input data type: %s', fnames{vv}) +0378 end +0379 end +0380 end +0381 +0382 % End definitions +0383 netcdf.endDef(nc); +0384 +0385 % Put the easy ones in first. +0386 netcdf.putVar(nc,nv_varid, tri'); +0387 netcdf.putVar(nc,time_varid,0,ntimes,data.time); +0388 netcdf.putVar(nc,itime_varid,0,ntimes,floor(data.time)); +0389 netcdf.putVar(nc,itime2_varid,0,ntimes,mod(data.time,1)*24*3600*1000); +0390 netcdf.putVar(nc,x_varid,x); +0391 netcdf.putVar(nc,y_varid,y); +0392 netcdf.putVar(nc,xc_varid,xc); +0393 netcdf.putVar(nc,yc_varid,yc); +0394 +0395 % Build the time string and output to NetCDF. +0396 nStringOut = char(); +0397 for tt=1:ntimes +0398 [nYr, nMon, nDay, nHour, nMin, nSec] = mjulian2greg(data.time(tt)); +0399 nDate = [nYr, nMon, nDay, nHour, nMin, nSec]; +0400 nStringOut = [nStringOut, sprintf('%04i/%02i/%02i %02i:%02i:%02i ',nDate)]; +0401 end +0402 netcdf.putVar(nc,times_varid,nStringOut); +0403 +0404 % Now do the dynamic ones. Set the heat flux to not done (hf_done = 0) +0405 % until we hit one of the holy quad (shtfl, lhtfl, nlwrs and nswrs). +0406 hf_done = 0; +0407 for ff=1:length(used_fnames) +0408 if ftbverbose +0409 fprintf('write : %s... ', used_fnames{ff}) +0410 end +0411 if strcmpi(used_fnames{ff}, 'shtfl') || strcmpi(used_fnames{ff}, 'lhtfl') || strcmpi(used_fnames{ff}, 'nlwrs') || strcmpi(used_fnames{ff}, 'nswrs') +0412 +0413 hf_done = hf_done + 1; +0414 +0415 if hf_done == 4 && nshf == 0 +0416 if ftbverbose +0417 fprintf('combining heat flux ... ') +0418 end +0419 % We've got all four heat parameters, so dump them into the +0420 % file. We have to flip the signs of the net fluxes and +0421 % subtract the latent and sensible heat fluxes because +0422 % NCEP's convention is positive upwards (out of the ocean) +0423 % and negative downwards (into the ocean), whereas FVCOM is +0424 % positive downwards (into the ocean) and negative upwards +0425 % (out of the ocean). +0426 hf = -data.nlwrs.node + -data.nswrs.node - data.lhtfl.node - data.shtfl.node; +0427 %hf = data.shtfl.node + data.lhtfl.node + data.nlwrs.node + data.nswrs.node; +0428 netcdf.putVar(nc,nhf_varid,[0,0],[nNodes,ntimes],hf) +0429 elseif strcmpi(used_fnames{ff}, 'nswrs') || strcmpi(used_fnames{ff}, 'nlwrs') +0430 % We've already done the net surface heat flux but we're on +0431 % either of the other fluxes (short/long wave) which we +0432 % need to dump. Do that here. +0433 if strcmpi(used_dims{ff}, 'nNodes') +0434 eval(['netcdf.putVar(nc,',used_varids{ff},',[0,0],[',used_dims{ff},',ntimes],data.',used_fnames{ff},'.node);']) +0435 else +0436 eval(['netcdf.putVar(nc,',used_varids{ff},',[0,0],[',used_dims{ff},',ntimes],data.',used_fnames{ff},'.data);']) +0437 end +0438 else +0439 % We haven't got the precomputed net surface heat flux but +0440 % we haven't yet got enough of the parameters to export the +0441 % heat flux from the short + long + latent + sensible. +0442 % Essentially this loop just does hf_done = hf_done + 1. +0443 end +0444 elseif strcmpi(used_fnames{ff}, 'nshf') && nshf == 1 +0445 if ftbverbose +0446 fprintf('existing combined heat flux ... ') +0447 end +0448 % We have pre-computed net surface heat flux, in which case set +0449 % hf_done to 4 and put the data into the netCDF. Also set the +0450 % nshf variable 1 to stop the net surface heat flux variable +0451 % being overwritten above. +0452 hf_done = 4; +0453 netcdf.putVar(nc, nhf_varid, [0, 0], [nNodes, ntimes], data.nshf.node) +0454 else +0455 % One of the other data sets for which we can simply dump the +0456 % existing array without waiting for other data +0457 if strcmpi(used_dims{ff}, 'nNodes') +0458 eval(['netcdf.putVar(nc,',used_varids{ff},',[0,0],[',used_dims{ff},',ntimes],data.',used_fnames{ff},'.node);']) +0459 else +0460 eval(['netcdf.putVar(nc,',used_varids{ff},',[0,0],[',used_dims{ff},',ntimes],data.',used_fnames{ff},'.data);']) +0461 end +0462 end +0463 if ftbverbose +0464 fprintf('done.\n') +0465 end +0466 end +0467 if hf_done < 4 +0468 % hf_done might be higher than four, but unless it is at least +0469 % four, we haven't got everything we need. +0470 warning('Did not have all the required heat flux parameters. Need ''shtfl'', ''lhtfl'', ''nlwrs'' and ''nwsrs''.') +0471 end +0472 +0473 % Close the NetCDF file(s) +0474 netcdf.close(nc); +0475 end +0476 +0477 if ftbverbose +0478 fprintf('end : %s \n', subname) +0479 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_meanflow.html b/doc/fvcom_prepro/write_FVCOM_meanflow.html new file mode 100644 index 0000000000000000000000000000000000000000..657ad4ccc3c02205ee076e3ceaf12d9827838a41 --- /dev/null +++ b/doc/fvcom_prepro/write_FVCOM_meanflow.html @@ -0,0 +1,186 @@ + + + + Description of write_FVCOM_meanflow + + + + + + + + + +
    Home > fvcom_prepro > write_FVCOM_meanflow.m
    + + + +

    write_FVCOM_meanflow +

    + +

    PURPOSE ^

    +
    Export mean flow forcing at the open boundary to NetCDF.
    + +

    SYNOPSIS ^

    +
    function write_FVCOM_meanflow(Mobj, ncfile, data)
    + +

    DESCRIPTION ^

    +
     Export mean flow forcing at the open boundary to NetCDF.
    +
    + function write_FVCOM_meanflow(Mobj, ncfile, data)
    +
    + DESCRIPTION:
    +    Setup an FVCOM hydrographic open boundary mean flow forcing file.
    +
    + INPUT:
    +   Mobj    - MATLAB mesh object (with fields mf_time, siglay, siglev,
    +               nObcElements and read_obc_elements).
    +   ncfile  - Output NetCDF file name.
    +   data    - 2D array of mean flow along the open boundary sized
    +               (nobcelems, time).
    +
    + OUTPUT:
    +    FVCOM mean flow values along the FVCOM open boundary in a NETCDF file
    +    named ncfile.
    +
    + Author(s):
    +    Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + TODO: 
    +    Add support for multiple open boundaries (currently hard limit of
    +    one).
    +
    + Revision history
    +    2013-02-20 - First version.
    +    2013-02-28 - Change output of velocities to be at the boundary element
    +    centres rather than the boundary nodes.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function write_FVCOM_meanflow(Mobj, ncfile, data)
    +0002 % Export mean flow forcing at the open boundary to NetCDF.
    +0003 %
    +0004 % function write_FVCOM_meanflow(Mobj, ncfile, data)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %    Setup an FVCOM hydrographic open boundary mean flow forcing file.
    +0008 %
    +0009 % INPUT:
    +0010 %   Mobj    - MATLAB mesh object (with fields mf_time, siglay, siglev,
    +0011 %               nObcElements and read_obc_elements).
    +0012 %   ncfile  - Output NetCDF file name.
    +0013 %   data    - 2D array of mean flow along the open boundary sized
    +0014 %               (nobcelems, time).
    +0015 %
    +0016 % OUTPUT:
    +0017 %    FVCOM mean flow values along the FVCOM open boundary in a NETCDF file
    +0018 %    named ncfile.
    +0019 %
    +0020 % Author(s):
    +0021 %    Pierre Cazenave (Plymouth Marine Laboratory)
    +0022 %
    +0023 % TODO:
    +0024 %    Add support for multiple open boundaries (currently hard limit of
    +0025 %    one).
    +0026 %
    +0027 % Revision history
    +0028 %    2013-02-20 - First version.
    +0029 %    2013-02-28 - Change output of velocities to be at the boundary element
    +0030 %    centres rather than the boundary nodes.
    +0031 %
    +0032 %==========================================================================
    +0033 
    +0034 subname = 'write_FVCOM_meanflow';
    +0035 
    +0036 global ftbverbose
    +0037 if ftbverbose
    +0038     fprintf('\n'); fprintf(['begin : ' subname '\n']);
    +0039 end
    +0040 
    +0041 % open new NetCDF file
    +0042 nc = netcdf.create(ncfile, 'clobber');
    +0043 
    +0044 % define global attributes
    +0045 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'type', 'FVCOM MEANFLOW TIME SERIES FILE')
    +0046 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'title', 'FVCOM MEANFLOW TIME SERIES data for open boundary')
    +0047 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'history', 'File created using write_FVCOM_meanflow.m from the MATLAB fvcom-toolbox')
    +0048 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'filename', ncfile)
    +0049 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'), 'Conventions', 'CF-1.0')
    +0050 
    +0051 % define dimensions
    +0052 nmfcell_dimid = netcdf.defDim(nc, 'nmfcell', Mobj.nObcElements);
    +0053 time_dimid = netcdf.defDim(nc, 'time', netcdf.getConstant('NC_UNLIMITED'));
    +0054 siglay_dimid = netcdf.defDim(nc, 'siglay', size(Mobj.siglay, 2));
    +0055 siglev_dimid = netcdf.defDim(nc, 'siglev', size(Mobj.siglev, 2));
    +0056 
    +0057 % define variables
    +0058 time_varid = netcdf.defVar(nc, 'time', 'NC_FLOAT', time_dimid);
    +0059 netcdf.putAtt(nc, time_varid, 'long_name', 'time');
    +0060 netcdf.putAtt(nc, time_varid, 'units', 'days since 1858-11-17 00:00:00');
    +0061 netcdf.putAtt(nc, time_varid, 'format', 'modified julian day (MJD)');
    +0062 netcdf.putAtt(nc, time_varid, 'time_zone', 'UTC');
    +0063 
    +0064 itime_varid = netcdf.defVar(nc, 'Itime', 'NC_INT', time_dimid);
    +0065 netcdf.putAtt(nc, itime_varid, 'units', 'days since 1858-11-17 00:00:00');
    +0066 netcdf.putAtt(nc, itime_varid, 'format', 'modified julian day (MJD)');
    +0067 netcdf.putAtt(nc, itime_varid, 'time_zone', 'UTC');
    +0068 
    +0069 itime2_varid = netcdf.defVar(nc, 'Itime2', 'NC_INT', time_dimid);
    +0070 netcdf.putAtt(nc, itime2_varid, 'units', 'msec since 00:00:00');
    +0071 netcdf.putAtt(nc, itime2_varid, 'time_zone', 'UTC');
    +0072 
    +0073 nmfcell_varid = netcdf.defVar(nc, 'I_MFCELL_GL', 'NC_INT', nmfcell_dimid);
    +0074 netcdf.putAtt(nc, nmfcell_varid, 'long_name', 'Open Boundary Cell Number');
    +0075 netcdf.putAtt(nc, nmfcell_varid, 'grid', 'obc_grid');
    +0076 netcdf.putAtt(nc, nmfcell_varid, 'type', 'data');
    +0077 
    +0078 mfdist_varid = netcdf.defVar(nc, 'MFDIST', 'NC_FLOAT', [siglay_dimid, nmfcell_dimid]);
    +0079 netcdf.putAtt(nc, mfdist_varid, 'long_name', 'Mean Flow Flux Vertical Distribution');
    +0080 netcdf.putAtt(nc, mfdist_varid, 'units', 'no units');
    +0081 netcdf.putAtt(nc, mfdist_varid, 'grid', 'obc_grid');
    +0082 netcdf.putAtt(nc, mfdist_varid, 'type', 'data');
    +0083 
    +0084 dmfqdis_varid = netcdf.defVar(nc, 'DMFQDIS', 'NC_FLOAT', [nmfcell_dimid, time_dimid]);
    +0085 netcdf.putAtt(nc, dmfqdis_varid, 'long_name', 'open boundary mean flow flux');
    +0086 netcdf.putAtt(nc, dmfqdis_varid, 'units', 'm^3/s');
    +0087 netcdf.putAtt(nc, dmfqdis_varid, 'grid', 'obc_grid');
    +0088 netcdf.putAtt(nc, dmfqdis_varid, 'type', 'data');
    +0089 
    +0090 % end definitions
    +0091 netcdf.endDef(nc);
    +0092 
    +0093 % write data
    +0094 netcdf.putVar(nc, time_varid, 0, numel(Mobj.mf_times), Mobj.mf_times);
    +0095 netcdf.putVar(nc, itime_varid, floor(Mobj.mf_times));
    +0096 netcdf.putVar(nc, itime2_varid, 0, numel(Mobj.mf_times), mod(Mobj.mf_times, 1) * 24 * 3600 * 1000);
    +0097 netcdf.putVar(nc, nmfcell_varid, Mobj.read_obc_elements{1});
    +0098 % MFDIST is calculated here as the diff of the sigma levels. This should
    +0099 % work for uniform and gaussian etc. distributions so long as Mobj.siglev
    +0100 % has the right values in it.
    +0101 netcdf.putVar(nc, mfdist_varid, repmat(abs(diff(Mobj.siglev)), [numel([Mobj.read_obc_elements{:}]), 1])');
    +0102 netcdf.putVar(nc, dmfqdis_varid, [0, 0], [numel(Mobj.read_obc_elements{1}), numel(Mobj.mf_times)], data);
    +0103 
    +0104 netcdf.close(nc);
    +0105 
    +0106 if ftbverbose
    +0107     fprintf(['end   : ' subname '\n'])
    +0108 end
    +0109
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_meanflow_ascii.html b/doc/fvcom_prepro/write_FVCOM_meanflow_ascii.html new file mode 100644 index 0000000000000000000000000000000000000000..41c3bdfd63100a0149166cd36eba05f4a35e1c3f --- /dev/null +++ b/doc/fvcom_prepro/write_FVCOM_meanflow_ascii.html @@ -0,0 +1,319 @@ + + + + Description of write_FVCOM_meanflow_ascii + + + + + + + + + +
    Home > fvcom_prepro > write_FVCOM_meanflow_ascii.m
    + + + +

    write_FVCOM_meanflow_ascii +

    + +

    PURPOSE ^

    +
    Export mean flow forcing files hard-coded into mod_obcs2.F.
    + +

    SYNOPSIS ^

    +
    function write_FVCOM_meanflow_ascii(Mobj, casename)
    + +

    DESCRIPTION ^

    +
     Export mean flow forcing files hard-coded into mod_obcs2.F.
    +
    + function write_FVCOM_meanflow_ascii(Mobj, datfile, data)
    +
    + DESCRIPTION:
    +    Setup an FVCOM hydrographic open boundary mean flow forcing file.
    +
    + INPUT:
    +   Mobj     - MATLAB mesh object (with fields mf_time, siglay, siglev,
    +               nObcNodes and read_obc_nodes).
    +            - Also requires two fields called meanflow_u and meanflow_v
    +               which are arrays of u and v of sizes (nObcElements,
    +               length(siglay), length(mf_times)).
    +   casename - Output file prefix. Output files will be
    +               /path/to/casename_suffix.dat, where suffix is one of:
    +                   - meanflow
    +                   - tide_cell
    +                   - tide_node
    +                   - tide_el
    +                   - tide_uv
    +   data     - 2D array of mean flow along the open boundary (nobc, time).
    +
    + OUTPUT:
    +    FVCOM mean flow values along the FVCOM open boundary in a NETCDF file
    +    named ncfile.
    +
    + Author(s):
    +    Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +    2013-02-25 - First version.
    + 
    + TODO: Implement support for multiple open boundaries in all the outputs.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function write_FVCOM_meanflow_ascii(Mobj, casename)
    +0002 % Export mean flow forcing files hard-coded into mod_obcs2.F.
    +0003 %
    +0004 % function write_FVCOM_meanflow_ascii(Mobj, datfile, data)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %    Setup an FVCOM hydrographic open boundary mean flow forcing file.
    +0008 %
    +0009 % INPUT:
    +0010 %   Mobj     - MATLAB mesh object (with fields mf_time, siglay, siglev,
    +0011 %               nObcNodes and read_obc_nodes).
    +0012 %            - Also requires two fields called meanflow_u and meanflow_v
    +0013 %               which are arrays of u and v of sizes (nObcElements,
    +0014 %               length(siglay), length(mf_times)).
    +0015 %   casename - Output file prefix. Output files will be
    +0016 %               /path/to/casename_suffix.dat, where suffix is one of:
    +0017 %                   - meanflow
    +0018 %                   - tide_cell
    +0019 %                   - tide_node
    +0020 %                   - tide_el
    +0021 %                   - tide_uv
    +0022 %   data     - 2D array of mean flow along the open boundary (nobc, time).
    +0023 %
    +0024 % OUTPUT:
    +0025 %    FVCOM mean flow values along the FVCOM open boundary in a NETCDF file
    +0026 %    named ncfile.
    +0027 %
    +0028 % Author(s):
    +0029 %    Pierre Cazenave (Plymouth Marine Laboratory)
    +0030 %
    +0031 % Revision history
    +0032 %    2013-02-25 - First version.
    +0033 %
    +0034 % TODO: Implement support for multiple open boundaries in all the outputs.
    +0035 %
    +0036 %==========================================================================
    +0037 
    +0038 subname = 'write_FVCOM_meanflow_ascii';
    +0039 
    +0040 global ftbverbose
    +0041 if ftbverbose
    +0042     fprintf(['\nbegin : ' subname '\n'])
    +0043 end
    +0044 
    +0045 %% _meanflow.dat -- mean flow velocities at the open boundary elements (?).
    +0046 
    +0047 % Create depth averaged velocity from the 3D velocity data in Mobj.
    +0048 velocity = squeeze(mean(sqrt(Mobj.meanflow_u.^2 + Mobj.meanflow_v.^2), 2));
    +0049 
    +0050 f = fopen([casename, '_meanflow.dat'], 'w');
    +0051 if f < 0
    +0052     error('Problem writing to _meanflow.dat file. Check permissions and try again.')
    +0053 end
    +0054 % Number of boundary nodes
    +0055 fprintf(f, '%8d\n', Mobj.nObcNodes);
    +0056 % Boundary node IDs
    +0057 for i = 1:Mobj.nObcNodes
    +0058     fprintf(f, '%8d\n', Mobj.read_obc_nodes{1}(i));
    +0059 end
    +0060 % Sigma level distribution
    +0061 s = '%8d';
    +0062 for ss = 1:length(Mobj.siglay)
    +0063     if ss < length(Mobj.siglay)
    +0064         s = [s, '%8.4f'];
    +0065     else
    +0066         s = [s, '%8.4f\n'];
    +0067     end
    +0068 end
    +0069 for i = 1:numel(Mobj.read_obc_nodes{1})
    +0070     fprintf(f, s, [i, abs(diff(Mobj.siglev))]);
    +0071 end
    +0072 
    +0073 % Number of times and boundary points
    +0074 [nb, nt] = size(velocity);
    +0075 
    +0076 % Add the number of time steps
    +0077 fprintf(f, '%i\n', nt);
    +0078 
    +0079 s = '%8.4f\n';
    +0080 for ss = 1:nb
    +0081     if ss < nb
    +0082         s = [s, '%8.4f'];
    +0083     else
    +0084         s = [s, '%8.4f\n'];
    +0085     end
    +0086 end
    +0087 for i = 1:size(velocity, 2)
    +0088     fprintf(f, s, [i - 1, velocity(:, i)']);
    +0089 end
    +0090 
    +0091 fclose(f);
    +0092 
    +0093 %% _tide_node.dat -- nodes along the open boundaries.
    +0094 f = fopen([casename, '_tide_node.dat'], 'w');
    +0095 if f < 0
    +0096     error('Problem writing to _tide_node.dat file. Check permissions and try again.')
    +0097 end
    +0098 % Boundary node IDs
    +0099 
    +0100 % Get a list of the open boundary nodes. Transpose Mobj.obc_nodes so the
    +0101 % order of the boundary nodes is preserved.
    +0102 tmpObcNodes = Mobj.obc_nodes';
    +0103 % Flip it back so it's the same shape as it would have been using the old
    +0104 % code.
    +0105 ObcNodes = tmpObcNodes(tmpObcNodes ~= 0)';
    +0106 
    +0107 fprintf(f, '%8d\n', numel(ObcNodes));
    +0108 for i = 1:numel(ObcNodes(i))
    +0109     fprintf(f, '%8i\n', ObcNodes(i));
    +0110 end
    +0111 
    +0112 fclose(f);
    +0113 
    +0114 %% _tide_cell.dat -- elements which have two nodes on an open boundary.
    +0115 f = fopen([casename, '_tide_cell.dat'], 'w');
    +0116 if f < 0
    +0117     error('Problem writing to _tide_cell.dat file. Check permissions and try again.')
    +0118 end
    +0119 if ~isfield(Mobj, 'read_obc_elements')
    +0120     error('Missing list of boundary element IDs. Run find_boundary_elements and try again.')
    +0121 end
    +0122 % Boundary element IDs
    +0123 ne = Mobj.nObcElements;
    +0124 fprintf(f, '%8d\n', ne);
    +0125 for j = 1:Mobj.nObs; % number of open boundaries
    +0126     for i = 1:numel(Mobj.read_obc_elements{j})
    +0127         fprintf(f, '%8i\n', Mobj.read_obc_elements{j}(i));
    +0128     end
    +0129 end
    +0130 
    +0131 fclose(f);
    +0132 
    +0133 %% _tide_el.dat -- surface elevations with time.
    +0134 f = fopen([casename, '_tide_el.dat'], 'w');
    +0135 if f < 0
    +0136     error('Problem writing to _tide_el.dat file. Check permissions and try again.')
    +0137 end
    +0138 % Boundary node IDs
    +0139 if ~isfield(Mobj, 'surfaceElevation')
    +0140     error('Missing predicted surface elevation necessary for mean flow.')
    +0141 end
    +0142 if ~isfield(Mobj, 'el_time')
    +0143     error('Missing predicted surface elevation time series necessary for mean flow.')
    +0144 end
    +0145 
    +0146 [nb, nt] = size(Mobj.surfaceElevation);
    +0147 
    +0148 s = '%8d';
    +0149 for ss = 1:nb
    +0150     if ss < nb
    +0151         s = [s, '%8.4f'];
    +0152     else
    +0153         s = [s, '%8.4f\n'];
    +0154     end
    +0155 end
    +0156 
    +0157 for i = 1:nt
    +0158     fprintf(f, s', [round(Mobj.el_time(i)), Mobj.surfaceElevation(:, i)']);
    +0159 end
    +0160 
    +0161 fclose(f);
    +0162 
    +0163 %% _tide_uv.dat -- boundary velocities
    +0164 % The format here is pretty funky. According to Dima's wrt_elj_obc.m
    +0165 % script, for each time step, there's lines of depth averaged u and v
    +0166 % followed by all the u and v components at each vertical level. All lines
    +0167 % are prefixed with the current time in seconds relative to the start of
    +0168 % the model (or mean flow time series? God knows).
    +0169 
    +0170 f = fopen([casename, '_tide_uv.dat'], 'w');
    +0171 if f < 0
    +0172     error('Problem writing to _tide_uv.dat file. Check permissions and try again.')
    +0173 end
    +0174 
    +0175 % Number of elements in the boundaries.
    +0176 ne = Mobj.nObcElements;
    +0177 
    +0178 % Number of time steps.
    +0179 nt = length(Mobj.mf_times);
    +0180 
    +0181 % Number of vertical layers.
    +0182 nz = length(Mobj.siglay);
    +0183 
    +0184 % Create a format string for the each time step plus the number of boundary
    +0185 % elements.
    +0186 s = '%8d';
    +0187 for ss = 1:ne
    +0188     
    +0189     if ss < ne
    +0190         s = [s, '%8.4f'];
    +0191     else
    +0192         s = [s, '%8.4f\n'];
    +0193     end
    +0194 end
    +0195 
    +0196 % Do the depth averaged u then v for all nodes prefixed by the current
    +0197 % time. So, wrap the whole shebang in a loop through time.
    +0198 for t = 1:nt
    +0199     
    +0200     % Time since the start of the time series (in seconds).
    +0201     iint = (Mobj.mf_times(t) - Mobj.mf_times(1)) * 24 * 3600;
    +0202     
    +0203     % Dump the time and mean u and then mean v vectors.
    +0204     fprintf(f, s, [iint; mean(Mobj.meanflow_u(:, :, t), 2)]);
    +0205     fprintf(f, s, [iint; mean(Mobj.meanflow_v(:, :, t), 2)]);
    +0206     
    +0207     % Now, for each vertical layer, dump the u and v vectors, prefixed with
    +0208     % time.
    +0209     for zz = 1:nz
    +0210         fprintf(f, s, [iint; Mobj.meanflow_u(:, zz, t)]);
    +0211         fprintf(f, s, [iint; Mobj.meanflow_v(:, zz, t)]);
    +0212     end
    +0213 end
    +0214 
    +0215 fclose(f);
    +0216 
    +0217 %% _elj_obc.dat -- surface elevation time series at open boundary nodes.
    +0218 
    +0219 % This is almost identical to _tide_el.dat but lacks the time stamp in the
    +0220 % first column.
    +0221 
    +0222 f = fopen([casename, '_elj_obc.dat'], 'w');
    +0223 if f < 0
    +0224     error('Problem writing to _elj_obc.dat file. Check permissions and try again.')
    +0225 end
    +0226 
    +0227 nt = size(Mobj.surfaceElevation, 2);
    +0228 
    +0229 for t = 1:nt
    +0230     fprintf(f, '%8.4f', Mobj.surfaceElevation(:, t));
    +0231     fprintf(f, '\n');
    +0232 end
    +0233 
    +0234 if ftbverbose
    +0235     fprintf('end   : %s\n', subname)
    +0236 end
    +0237 
    +0238
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_obs_TS.html b/doc/fvcom_prepro/write_FVCOM_obs_TS.html index 6f1a224de0a6d29f31c43b10227a56338e7077c3..ee036c90af61956a895517695cbcc4145c2d3435 100755 --- a/doc/fvcom_prepro/write_FVCOM_obs_TS.html +++ b/doc/fvcom_prepro/write_FVCOM_obs_TS.html @@ -132,68 +132,69 @@ This function is called by: 0055 nc = netcdf.create(filename,'clobber'); 0056 0057 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title',mytitle) -0058 -0059 % define dimensions -0060 ksl_dimid=netcdf.defDim(nc,'ksl',ksl); -0061 node_dimid=netcdf.defDim(nc,'ksl',nverts); -0062 time_dimid=netcdf.defDim(nc,'ksl',netcdf.getConstant('NC_UNLIMITED')); -0063 -0064 % define variables and attributes -0065 time_varid=netcdf.defVar(nc,'time','NC_FLOAT',time_dimid); -0066 netcdf.putAtt(nc,time_varid,'long_name','time'); -0067 netcdf.putAtt(nc,time_varid,'units','days since 0.0'); -0068 netcdf.putAtt(nc,time_varid,'time_zone','none'); -0069 -0070 itime_varid=netcdf.defVar(nc,'time','NC_INT',time_dimid); -0071 netcdf.putAtt(nc,itime_varid,'units','days since 0.0'); -0072 netcdf.putAtt(nc,itime_varid,'time_zone','none'); -0073 -0074 itime2_varid=netcdf.defVar(nc,'Itime','NC_INT',time_dimid); -0075 netcdf.putAtt(nc,itime2_varid,'units','msec since 00:00:00'); -0076 netcdf.putAtt(nc,itime2_varid,'time_zone','none'); -0077 -0078 zsl_varid=netcdf.defVar(nc,'Itime2','NC_FLOAT',ksl_dimid); -0079 netcdf.putAtt(nc,zsl_varid,'long_name','standard z levels positive up'); -0080 netcdf.putAtt(nc,zsl_varid,'units','m'); -0081 -0082 % TODO: Check order of dimensions here -0083 ssl_varid=netcdf.defVar(nc,'time','NC_FLOAT',[time_dimid,ksl_dimid,node_dimid]); -0084 netcdf.putAtt(nc,ssl_varid,'long_name','observed_salinity_profile'); -0085 netcdf.putAtt(nc,ssl_varid,'units','PSU'); -0086 -0087 tsl_varid=netcdf.defVar(nc,'time','NC_FLOAT',[time_dimid,ksl_dimid,node_dimid]); -0088 netcdf.putAtt(nc,tsl_varid,'long_name','observed_temperature_profile'); -0089 netcdf.putAtt(nc,tsl_varid,'units','C'); -0090 -0091 % end definitions -0092 netcdf.endDef(nc); -0093 +0058 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','File created with the write_FVCOM_obs_TS.m from the MATLAB fvcom-toolbox') +0059 +0060 % define dimensions +0061 ksl_dimid=netcdf.defDim(nc,'ksl',ksl); +0062 node_dimid=netcdf.defDim(nc,'ksl',nverts); +0063 time_dimid=netcdf.defDim(nc,'ksl',netcdf.getConstant('NC_UNLIMITED')); +0064 +0065 % define variables and attributes +0066 time_varid=netcdf.defVar(nc,'time','NC_FLOAT',time_dimid); +0067 netcdf.putAtt(nc,time_varid,'long_name','time'); +0068 netcdf.putAtt(nc,time_varid,'units','days since 0.0'); +0069 netcdf.putAtt(nc,time_varid,'time_zone','none'); +0070 +0071 itime_varid=netcdf.defVar(nc,'time','NC_INT',time_dimid); +0072 netcdf.putAtt(nc,itime_varid,'units','days since 0.0'); +0073 netcdf.putAtt(nc,itime_varid,'time_zone','none'); +0074 +0075 itime2_varid=netcdf.defVar(nc,'Itime','NC_INT',time_dimid); +0076 netcdf.putAtt(nc,itime2_varid,'units','msec since 00:00:00'); +0077 netcdf.putAtt(nc,itime2_varid,'time_zone','none'); +0078 +0079 zsl_varid=netcdf.defVar(nc,'Itime2','NC_FLOAT',ksl_dimid); +0080 netcdf.putAtt(nc,zsl_varid,'long_name','standard z levels positive up'); +0081 netcdf.putAtt(nc,zsl_varid,'units','m'); +0082 +0083 % TODO: Check order of dimensions here +0084 ssl_varid=netcdf.defVar(nc,'time','NC_FLOAT',[time_dimid,ksl_dimid,node_dimid]); +0085 netcdf.putAtt(nc,ssl_varid,'long_name','observed_salinity_profile'); +0086 netcdf.putAtt(nc,ssl_varid,'units','PSU'); +0087 +0088 tsl_varid=netcdf.defVar(nc,'time','NC_FLOAT',[time_dimid,ksl_dimid,node_dimid]); +0089 netcdf.putAtt(nc,tsl_varid,'long_name','observed_temperature_profile'); +0090 netcdf.putAtt(nc,tsl_varid,'units','C'); +0091 +0092 % end definitions +0093 netcdf.endDef(nc); 0094 -0095 % write vars -0096 netcdf.putVar(nc,time_varid,time*ones(1,nverts)); -0097 netcdf.putVar(nc,itime_varid,floor(time)*ones(1,nverts)); -0098 netcdf.putVar(nc,itime2_varid,(mod(time,1)*24*3600*1000)*ones(1,nverts)); -0099 netcdf.putVar(nc,zsl_varid,zsl); -0100 +0095 +0096 % write vars +0097 netcdf.putVar(nc,time_varid,time*ones(1,nverts)); +0098 netcdf.putVar(nc,itime_varid,floor(time)*ones(1,nverts)); +0099 netcdf.putVar(nc,itime2_varid,(mod(time,1)*24*3600*1000)*ones(1,nverts)); +0100 netcdf.putVar(nc,zsl_varid,zsl); 0101 -0102 for i=1:numel(time) -0103 for k=1:ksl -0104 nc{'tsl'}(i,k,:) = tsl(k); -0105 end; -0106 end; -0107 -0108 for i=1:numel(time) -0109 for k=1:ksl -0110 nc{'ssl'}(i,k,:) = ssl(k); -0111 end; -0112 end; -0113 -0114 ierr = close(nc); -0115 +0102 +0103 for i=1:numel(time) +0104 for k=1:ksl +0105 nc{'tsl'}(i,k,:) = tsl(k); +0106 end; +0107 end; +0108 +0109 for i=1:numel(time) +0110 for k=1:ksl +0111 nc{'ssl'}(i,k,:) = ssl(k); +0112 end; +0113 end; +0114 +0115 ierr = close(nc); 0116 0117 0118 -0119 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +0119 +0120 +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_restart.html b/doc/fvcom_prepro/write_FVCOM_restart.html new file mode 100644 index 0000000000000000000000000000000000000000..3abffb6b3c7e42c417185abf18a1690eb6fc02d1 --- /dev/null +++ b/doc/fvcom_prepro/write_FVCOM_restart.html @@ -0,0 +1,340 @@ + + + + Description of write_FVCOM_restart + + + + + + + + + +
    Home > fvcom_prepro > write_FVCOM_restart.m
    + + + +

    write_FVCOM_restart +

    + +

    PURPOSE ^

    +
    Duplicate an FVCOM restart file, replacing variable values with those
    + +

    SYNOPSIS ^

    +
    function write_FVCOM_restart(fv_restart, out_restart, indata, start_date)
    + +

    DESCRIPTION ^

    +
     Duplicate an FVCOM restart file, replacing variable values with those
    + specified in the struct data. 
    + 
    + function write_FVCOM_restart(fv_restart, out_restart, indata)
    + 
    + DESCRIPTION:
    +   Use an existing FVCOM restart file as a template, export all existing
    +   data except for variables whose names match the data in the struct
    +   'data'. 
    + 
    + INPUT:
    +   fv_restart  = full path to an existing FVCOM restart file.
    +   out_restart = full path to the restart file to be created.
    +   indata      = struct whose field names are the variable names to be
    +   replaced.
    +   start_date  = [optional] reset the restart file times to this date
    +   ([YYYY, MM, DD, HH, MM, SS]).
    + 
    + OUTPUT:
    +   FVCOM restart file.
    + 
    + EXAMPLE USAGE:
    +   indata.temp = interpolated_temp;
    +   indata.salinity = interpolated_salinity;
    +   write_FVCOM_restart('/tmp/fvcom_restart.nc', ...
    +       '/tmp/fvcom_restart_interp.nc', indata)
    + 
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    + 
    + Revision history:
    +   2013-02-08 First version.
    +   2013-02-15 Fix bug wherein only the last field in the new data would
    +   only be added to the output NetCDF file.
    +   2013-03-13 Make the time rewriting optional and not just commented out.
    + 
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function write_FVCOM_restart(fv_restart, out_restart, indata, start_date)
    +0002 % Duplicate an FVCOM restart file, replacing variable values with those
    +0003 % specified in the struct data.
    +0004 %
    +0005 % function write_FVCOM_restart(fv_restart, out_restart, indata)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %   Use an existing FVCOM restart file as a template, export all existing
    +0009 %   data except for variables whose names match the data in the struct
    +0010 %   'data'.
    +0011 %
    +0012 % INPUT:
    +0013 %   fv_restart  = full path to an existing FVCOM restart file.
    +0014 %   out_restart = full path to the restart file to be created.
    +0015 %   indata      = struct whose field names are the variable names to be
    +0016 %   replaced.
    +0017 %   start_date  = [optional] reset the restart file times to this date
    +0018 %   ([YYYY, MM, DD, HH, MM, SS]).
    +0019 %
    +0020 % OUTPUT:
    +0021 %   FVCOM restart file.
    +0022 %
    +0023 % EXAMPLE USAGE:
    +0024 %   indata.temp = interpolated_temp;
    +0025 %   indata.salinity = interpolated_salinity;
    +0026 %   write_FVCOM_restart('/tmp/fvcom_restart.nc', ...
    +0027 %       '/tmp/fvcom_restart_interp.nc', indata)
    +0028 %
    +0029 % Author(s):
    +0030 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0031 %
    +0032 % Revision history:
    +0033 %   2013-02-08 First version.
    +0034 %   2013-02-15 Fix bug wherein only the last field in the new data would
    +0035 %   only be added to the output NetCDF file.
    +0036 %   2013-03-13 Make the time rewriting optional and not just commented out.
    +0037 %
    +0038 %==========================================================================
    +0039 
    +0040 subname = 'write_FVCOM_restart';
    +0041 
    +0042 global ftbverbose
    +0043 if ftbverbose
    +0044     fprintf('\n')
    +0045     fprintf(['begin : ' subname '\n'])
    +0046 end
    +0047 
    +0048 % Get the fieldnames which must match the variable names to be replaced
    +0049 % (case sensitive).
    +0050 fnames = fieldnames(indata);
    +0051 nf = length(fnames);
    +0052 
    +0053 nc = netcdf.open(fv_restart, 'NOWRITE');
    +0054 ncout = netcdf.create(out_restart, 'clobber');
    +0055 
    +0056 [numdims, numvars, numglobatts, unlimdimID] = netcdf.inq(nc);
    +0057 
    +0058 % Define the dimensions for all variables.
    +0059 dimid = nan(numdims, 1);
    +0060 dimnames = cell(numdims, 1);
    +0061 dimlengths = nan(numdims, 1);
    +0062 for ii = 1:numdims
    +0063     [dimname, dimlen] = netcdf.inqDim(nc, ii - 1);
    +0064     if ii ~= unlimdimID + 1 % NetCDF indices start at zero
    +0065         dimid(ii) = netcdf.defDim(ncout, dimname, dimlen);
    +0066     else
    +0067         dimid(ii) = netcdf.defDim(ncout, dimname, netcdf.getConstant('NC_UNLIMITED'));
    +0068     end
    +0069     dimnames{ii} = dimname;
    +0070     dimlengths(ii) = dimlen;
    +0071 end
    +0072 
    +0073 % Now define the variables and attributes.
    +0074 for ii = 1:numvars
    +0075 
    +0076     % Find name of the current variable.
    +0077     [varname, xtype, varDimIDs, varAtts] = netcdf.inqVar(nc, ii - 1);
    +0078 
    +0079     % Create the variables.
    +0080     varid = netcdf.defVar(ncout, varname, xtype, varDimIDs);
    +0081 
    +0082     % Get each attribute and add it to the current variable.
    +0083     for j = 1:varAtts
    +0084 
    +0085         attname = netcdf.inqAttName(nc, varid, j - 1);
    +0086         attval = netcdf.getAtt(nc, varid, attname);
    +0087 
    +0088         netcdf.putAtt(ncout, varid, attname, attval);
    +0089     end
    +0090 end
    +0091 
    +0092 % Do the global attributes
    +0093 for ii = 1:numglobatts
    +0094     
    +0095     % Find the current global attribute's name and value.
    +0096     gattname = netcdf.inqAttName(nc, netcdf.getConstant('NC_GLOBAL'), ii - 1);
    +0097     gattval = netcdf.getAtt(nc, netcdf.getConstant('NC_GLOBAL'), gattname);
    +0098     
    +0099     % Put that back into the output NetCDF file.
    +0100     netcdf.putAtt(ncout, netcdf.getConstant('NC_GLOBAL'), gattname, gattval);
    +0101 end
    +0102 
    +0103 netcdf.endDef(ncout);
    +0104 
    +0105 % Get the existing data and output to the new NetCDF file, except for
    +0106 % variables which match the fieldnames in the data struct.
    +0107 for ii = 1:numvars
    +0108 
    +0109     [varname, ~, varDimIDs, ~] = netcdf.inqVar(nc, ii - 1);
    +0110     varid = netcdf.inqVarID(nc, varname);
    +0111 
    +0112     if ftbverbose
    +0113         fprintf('\tvariable %s... ', varname)
    +0114     end
    +0115 
    +0116     % We need the data irrespective of whether we're replacing it or not,
    +0117     % so grab it outside the if statement below.
    +0118     data = netcdf.getVar(nc, varid);
    +0119 
    +0120     % Get the size of the data and the dimension names.
    +0121     currDimsNames = dimnames(varDimIDs + 1);
    +0122     currDimsLengths = dimlengths(varDimIDs + 1);
    +0123 
    +0124     % Find whether we've got an unlimited dimension in this data.
    +0125     wasUnlimited = -1;
    +0126     for jj = varDimIDs
    +0127         if numel(unlimdimID) > 1
    +0128             error('Do not currently support multiple unlimited dimensions.')
    +0129         end
    +0130         if strcmpi(dimnames(jj + 1), dimnames(unlimdimID + 1))
    +0131             wasUnlimited = jj;
    +0132         end
    +0133     end
    +0134 
    +0135     % Since the restart file has a number of time values, we'll ramp up the
    +0136     % replacement data from the existing start condition to the actual
    +0137     % value over the time steps. So, we need to know how many time steps we
    +0138     % actually have.
    +0139 
    +0140     % Get the dimension data ready for the replacement arrays.
    +0141     tIdx = strncmp(dimnames(unlimdimID + 1), currDimsNames, length(dimnames{unlimdimID + 1}));
    +0142     % Not sure about the hardcoded strings below...
    +0143     sIdx = strncmp('siglay', currDimsNames, length(dimnames{unlimdimID + 1}));
    +0144     nIdx = strncmp('node', currDimsNames, length(dimnames{unlimdimID + 1}));
    +0145     nt = currDimsLengths(tIdx);
    +0146     ns = currDimsLengths(sIdx);
    +0147     nd = currDimsLengths(nIdx);
    +0148     
    +0149     % Iterate through the field names to see if we're on one of the
    +0150     % variables to be replaced.
    +0151 
    +0152     % Set variable so we know if we've already written this variable to the
    +0153     % output file.
    +0154     writtenAlready = 0;
    +0155     for vv = 1:nf
    +0156         if strcmp(varname, fnames{vv}) && writtenAlready == 0
    +0157             if ftbverbose
    +0158                 fprintf('new data... ')
    +0159             end
    +0160             % To make the scaling go from the initial value to the POLCOMS
    +0161             % value, we need to scale the difference between the end
    +0162             % members by the scaling factor at each time and add to the
    +0163             % current time's value.
    +0164             sfvdata = nan(nd, ns, nt);
    +0165             ss = 0:1 / (nt - 1):1; % scale from 0 to 1.
    +0166             startdata = squeeze(data(:, :, 1)); % use the first modelled time step
    +0167             for tt = 1:nt
    +0168                 if tt == 1
    +0169                     sfvdata(:, :, 1) = startdata;
    +0170                 else
    +0171                     td = indata.(fnames{vv}) - startdata;
    +0172                     sfvdata(:, :, tt) = startdata + (ss(tt) .* td);
    +0173                 end
    +0174             end
    +0175             % Replace the values with the scaled interpolated values,
    +0176             % checking for unlimited dimensions as we go.
    +0177             if wasUnlimited < 0
    +0178                 netcdf.putVar(ncout, varid, sfvdata)
    +0179             else
    +0180                 netcdf.putVar(ncout, varid, zeros(length(currDimsLengths), 1), currDimsLengths, sfvdata)
    +0181             end
    +0182 
    +0183             writtenAlready = 1;
    +0184 
    +0185         % We might also want to replace the time. If so, supply a fourth
    +0186         % argument (start_date) to replace the times in the existing
    +0187         % restart file with an arbitrary time period.
    +0188         elseif strcmpi(varname, 'time') && writtenAlready == 0 && nargin == 4
    +0189             if ftbverbose
    +0190                 fprintf('new data... ')
    +0191             end
    +0192 %             warning('Replacing times in the restart file')
    +0193             tmp_start_time = greg2mjulian(start_date(1), start_date(2), start_date(3) - 7, start_date(4), start_date(5), start_date(6));
    +0194             tmp_time = tmp_start_time:(tmp_start_time + nt - 1);
    +0195             netcdf.putVar(ncout, varid, tmp_time)
    +0196 
    +0197             writtenAlready = 1;
    +0198 
    +0199         elseif strcmpi(varname, 'Times') && writtenAlready == 0 && nargin == 4
    +0200             if ftbverbose
    +0201                 fprintf('new data... ')
    +0202             end
    +0203 %             warning('Replacing times in the restart file')
    +0204             tmp_time = [];
    +0205             for i = 1:nt;
    +0206                 tmp_time = [tmp_time, sprintf('%-026s', datestr(datenum(start_date) - 7 + (i - 1), 'yyyy-mm-dd HH:MM:SS.FFF'))];
    +0207             end
    +0208             netcdf.putVar(ncout, varid, tmp_time)
    +0209 
    +0210             writtenAlready = 1;
    +0211 
    +0212         elseif strcmpi(varname, 'Itime') && writtenAlready == 0 && nargin == 4
    +0213             if ftbverbose
    +0214                 fprintf('new data... ')
    +0215             end
    +0216 %             warning('Replacing times in the restart file')
    +0217             tmp_start_time = greg2mjulian(start_date(1), start_date(2), start_date(3) - 7, start_date(4), start_date(5), start_date(6));
    +0218             tmp_time = tmp_start_time:(tmp_start_time + nt - 1);
    +0219             netcdf.putVar(ncout, varid, floor(tmp_time))
    +0220 
    +0221             writtenAlready = 1;
    +0222 
    +0223         end
    +0224     end
    +0225 
    +0226     % If writtenAlready is zero, we haven't had one of the variables we're
    +0227     % replacing, so just dump the existing data.
    +0228     if writtenAlready == 0
    +0229         if ftbverbose
    +0230             fprintf('existing data... ')
    +0231         end
    +0232         % We need to check if the dimension is unlimited, and use a
    +0233         % start and end with netcdf.putVar if it is. This is largely
    +0234         % because MATLAB can't handle unlimited dimensions in the same
    +0235         % way as it does finite dimensions.
    +0236         if wasUnlimited < 0
    +0237             % We can just dump the entire data without specifying over
    +0238             % what indices.
    +0239             netcdf.putVar(ncout, varid, data);
    +0240         else
    +0241             % Use the dimension length we extracted above to output the
    +0242             % data with the valid unlimited dimension format.
    +0243             netcdf.putVar(ncout, varid, zeros(length(currDimsLengths), 1), currDimsLengths, data);
    +0244         end
    +0245     end
    +0246 
    +0247     if ftbverbose
    +0248         fprintf('done.\n')
    +0249     end
    +0250 end
    +0251 
    +0252 netcdf.close(nc)
    +0253 netcdf.close(ncout)
    +0254 
    +0255 if ftbverbose
    +0256     fprintf(['end   : ' subname '\n'])
    +0257 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_river.html b/doc/fvcom_prepro/write_FVCOM_river.html index 0a7824661c707043a512030f124269d7c2a5a251..9d2cd5632f2d151bb400ee042215bb58f0ed3190 100755 --- a/doc/fvcom_prepro/write_FVCOM_river.html +++ b/doc/fvcom_prepro/write_FVCOM_river.html @@ -4,7 +4,7 @@ Description of write_FVCOM_river - + @@ -21,46 +21,56 @@

    PURPOSE ^

    -
    write FVCOM 3.x NetCDF river file
    +
    Write FVCOM 3.x NetCDF river file

    SYNOPSIS ^

    -
    function write_FVCOM_river(RiverFile,RiverName,nRivnodes,time,flux,temp,salt,RiverInfo1,RiverInfo2)
    +
    function write_FVCOM_river(RiverFile,RiverName,time,flux,temp,salt,RiverInfo1,RiverInfo2)

    DESCRIPTION ^

    -
     write FVCOM 3.x NetCDF river file
    +
     Write FVCOM 3.x NetCDF river file
     
    - function write_FVCOM_river(RiverFile,RiverName,nRivnodes,time,flux,temp,salt,RiverInfo1,RiverInfo2)
    + function write_FVCOM_river(RiverFile,RiverName,time,flux,temp,salt,RiverInfo1,RiverInfo2)
     
      DESCRIPTION:
    -    Write river flux, temperature, and salinity to an FVCOM river file
    -    Note that it is assumed that the NetCDF file contains data for only
    -    one river, even if it is split among multiple nodes.  The flux will be
    -    set at each node as flux/nRivnodes where nRivnodes is the number of River
    -    nodes.  Salinity and Temperature will be set the same at each node
    +    Write river flux, temperature, and salinity to an FVCOM river file.
    +    Flux, temperature and salinity must be calculated prior to being given
    +    here as the raw values in the arrays are simply written out as is to
    +    the NetCDF file.
     
      INPUT
    -    RiverFile:   FVCOM 3.x NetCDF river forcing file
    -    RiverName:   Name of the actual River
    -    nRivnodes:   # of River nodes
    -    time     :   timestamp in modified Julian day 
    -    flux     :   Total river flux of same dimensions as time in m^3/s
    -    temp     :   temperature in C of same dimensions as time
    -    salt     :   salinity in PSU of same dimensions as time
    -    RiverInfo1 : global attribute of file
    -    RiverInfo2 : additional global attribute of file
    -   
    +    RiverFile  : FVCOM 3.x NetCDF river forcing file
    +    RiverName  : Name of the actual River
    +    time       : Timestamp array in modified Julian day
    +    flux       : Total river flux in m^3/s (dimensions [time, nRivernodes])
    +    temp       : Temperature in C (dimensions [time, nRivernodes])
    +    salt       : Salinity in PSU (dimensions [time, nRivernodes])
    +    RiverInfo1 : Global attribute title of file
    +    RiverInfo2 : Global attribute info of file
    +
      OUTPUT:
    -    FVCOM RiverFile with flux,temp,salt
    +    FVCOM NetCDF river file with flux, temperature and salinity.
     
      EXAMPLE USAGE
    -  write_FVCOM_river('tst_riv.nc','Penobscot',3,time,flux,salt,'Penobscot Flux','source: USGS')  
    +    write_FVCOM_river('tst_riv.nc', {'Penobscot'}, time, flux, temp, ...
    +         salt, 'Penobscot Flux', 'source: USGS')
     
      Author(s):  
         Geoff Cowles (University of Massachusetts Dartmouth)
    +    Pierre Cazenave (Plymouth Marine Laboratory)
     
      Revision history
    -   
    -==============================================================================
    + 2013-03-21 Modified to take a list of river nodes rather than a single + river spread over multiple nodes. This means you have to scale your + inputs prior to using this function. This also means I have broken + backwards compatibility with the old way of doing it (i.e. this + function previously wrote only a single river's data but spread over a + number of nodes). I removed the sediment stuff as the manual makes no + mention of this in the river input file. Also added support for writing + to NetCDF using MATLAB's native tools. + 2013-03-21 Transpose the river data arrays to the correct shape for the + NetCDF file. + +==========================================================================

    CROSS-REFERENCE INFORMATION ^

    @@ -75,159 +85,158 @@ This function is called by:

    SOURCE CODE ^

    -
    0001 function write_FVCOM_river(RiverFile,RiverName,nRivnodes,time,flux,temp,salt,RiverInfo1,RiverInfo2)
    -0002 % write FVCOM 3.x NetCDF river file
    +
    0001 function write_FVCOM_river(RiverFile,RiverName,time,flux,temp,salt,RiverInfo1,RiverInfo2)
    +0002 % Write FVCOM 3.x NetCDF river file
     0003 %
    -0004 % function write_FVCOM_river(RiverFile,RiverName,nRivnodes,time,flux,temp,salt,RiverInfo1,RiverInfo2)
    +0004 % function write_FVCOM_river(RiverFile,RiverName,time,flux,temp,salt,RiverInfo1,RiverInfo2)
     0005 %
     0006 % DESCRIPTION:
    -0007 %    Write river flux, temperature, and salinity to an FVCOM river file
    -0008 %    Note that it is assumed that the NetCDF file contains data for only
    -0009 %    one river, even if it is split among multiple nodes.  The flux will be
    -0010 %    set at each node as flux/nRivnodes where nRivnodes is the number of River
    -0011 %    nodes.  Salinity and Temperature will be set the same at each node
    -0012 %
    -0013 % INPUT
    -0014 %    RiverFile:   FVCOM 3.x NetCDF river forcing file
    -0015 %    RiverName:   Name of the actual River
    -0016 %    nRivnodes:   # of River nodes
    -0017 %    time     :   timestamp in modified Julian day
    -0018 %    flux     :   Total river flux of same dimensions as time in m^3/s
    -0019 %    temp     :   temperature in C of same dimensions as time
    -0020 %    salt     :   salinity in PSU of same dimensions as time
    -0021 %    RiverInfo1 : global attribute of file
    -0022 %    RiverInfo2 : additional global attribute of file
    -0023 %
    -0024 % OUTPUT:
    -0025 %    FVCOM RiverFile with flux,temp,salt
    -0026 %
    -0027 % EXAMPLE USAGE
    -0028 %  write_FVCOM_river('tst_riv.nc','Penobscot',3,time,flux,salt,'Penobscot Flux','source: USGS')
    -0029 %
    -0030 % Author(s):
    -0031 %    Geoff Cowles (University of Massachusetts Dartmouth)
    +0007 %    Write river flux, temperature, and salinity to an FVCOM river file.
    +0008 %    Flux, temperature and salinity must be calculated prior to being given
    +0009 %    here as the raw values in the arrays are simply written out as is to
    +0010 %    the NetCDF file.
    +0011 %
    +0012 % INPUT
    +0013 %    RiverFile  : FVCOM 3.x NetCDF river forcing file
    +0014 %    RiverName  : Name of the actual River
    +0015 %    time       : Timestamp array in modified Julian day
    +0016 %    flux       : Total river flux in m^3/s (dimensions [time, nRivernodes])
    +0017 %    temp       : Temperature in C (dimensions [time, nRivernodes])
    +0018 %    salt       : Salinity in PSU (dimensions [time, nRivernodes])
    +0019 %    RiverInfo1 : Global attribute title of file
    +0020 %    RiverInfo2 : Global attribute info of file
    +0021 %
    +0022 % OUTPUT:
    +0023 %    FVCOM NetCDF river file with flux, temperature and salinity.
    +0024 %
    +0025 % EXAMPLE USAGE
    +0026 %    write_FVCOM_river('tst_riv.nc', {'Penobscot'}, time, flux, temp, ...
    +0027 %         salt, 'Penobscot Flux', 'source: USGS')
    +0028 %
    +0029 % Author(s):
    +0030 %    Geoff Cowles (University of Massachusetts Dartmouth)
    +0031 %    Pierre Cazenave (Plymouth Marine Laboratory)
     0032 %
     0033 % Revision history
    -0034 %
    -0035 %==============================================================================
    -0036 warning off;
    -0037 
    -0038 global ftbverbose;
    -0039 if(ftbverbose);
    -0040 subname = 'write_FVCOM_river';
    -0041 fprintf('\n')
    -0042 fprintf(['begin : ' subname '\n'])
    -0043 end;
    -0044 
    -0045 
    -0046 if(ftbverbose); 
    -0047   fprintf('creating river NetCDF file %s for River %s\n',RiverFile,RiverName); 
    -0048 end;
    -0049 
    -0050 
    -0051 nTimes = prod(size(flux));
    -0052 if(ftbverbose);
    -0053   fprintf('# of river nodes: %d\n',nRivnodes);
    -0054   fprintf('# of time frames: %d\n',nTimes);
    -0055 end;
    -0056 
    -0057 [year,month,day,hour,mint,sec] = mjulian2greg(time(1));
    -0058 if(ftbverbose); fprintf('river begins at: %d %d %d\n',year,month,day); end;
    -0059 [year,month,day,hour,mint,sec] = mjulian2greg(time(end));
    -0060 if(ftbverbose); fprintf('river ends at:   %d %d %d\n',year,month,day); end;
    -0061 
    -0062 % set the flux
    -0063 if(ftbverbose); fprintf('dividing flux into %d points\n',nRivnodes); end;
    -0064 river_flux = zeros(nTimes,nRivnodes);
    -0065 for i=1:nTimes
    -0066   river_flux(i,1:nRivnodes) = flux(i)/real(nRivnodes);
    -0067 end;
    -0068 
    -0069 % set temperature and salt
    -0070 for i=1:nTimes
    -0071     river_salt(i,1:nRivnodes) = salt(i);
    -0072     river_temp(i,1:nRivnodes) = temp(i);
    -0073 end;
    -0074 
    -0075 % set some kind of sediment
    -0076 coarse_sand = 15*ones(nTimes,nRivnodes);
    -0077 medium_sand = 45*ones(nTimes,nRivnodes);
    -0078 fine_sand   = 30*ones(nTimes,nRivnodes);
    +0034 %   2013-03-21 Modified to take a list of river nodes rather than a single
    +0035 %   river spread over multiple nodes. This means you have to scale your
    +0036 %   inputs prior to using this function. This also means I have broken
    +0037 %   backwards compatibility with the old way of doing it (i.e. this
    +0038 %   function previously wrote only a single river's data but spread over a
    +0039 %   number of nodes). I removed the sediment stuff as the manual makes no
    +0040 %   mention of this in the river input file. Also added support for writing
    +0041 %   to NetCDF using MATLAB's native tools.
    +0042 %   2013-03-21 Transpose the river data arrays to the correct shape for the
    +0043 %   NetCDF file.
    +0044 %
    +0045 %==========================================================================
    +0046 
    +0047 subname = 'write_FVCOM_river';
    +0048 
    +0049 global ftbverbose
    +0050 if ftbverbose
    +0051     fprintf('\n')
    +0052     fprintf(['begin : ' subname '\n'])
    +0053 end
    +0054 
    +0055 [nTimes, nRivnodes] = size(flux);
    +0056 if ftbverbose
    +0057     fprintf('# of river nodes: %d\n', nRivnodes);
    +0058     fprintf('# of time frames: %d\n', nTimes);
    +0059 end
    +0060 
    +0061 [year, month, day, ~, ~, ~] = mjulian2greg(time(1));
    +0062 if ftbverbose; fprintf('time series begins at:\t%04d %02d %02d\n', year, month, day); end
    +0063 [year, month, day, ~, ~, ~] = mjulian2greg(time(end));
    +0064 if ftbverbose; fprintf('time series ends at:\t%04d %02d %02d\n', year, month, day); end
    +0065 clear year month day
    +0066 
    +0067 %--------------------------------------------------------------------------
    +0068 % dump to netcdf file
    +0069 %--------------------------------------------------------------------------
    +0070 
    +0071 % river node forcing
    +0072 nc = netcdf.create(RiverFile, 'clobber');
    +0073 
    +0074 % global variables
    +0075 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'type', 'FVCOM RIVER FORCING FILE')
    +0076 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'title', RiverInfo1)
    +0077 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'info', RiverInfo2)
    +0078 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'history', 'File created using write_FVCOM_river.m from the MATLAB fvcom-toolbox')
     0079 
    -0080 
    -0081 %--------------------------------------------------------------
    -0082 % dump to netcdf file
    -0083 %--------------------------------------------------------------
    -0084 
    -0085 % open boundary forcing
    -0086 nc = netcdf(RiverFile, 'clobber');       
    -0087 
    -0088 nc.type = 'FVCOM RIVER FORCING FILE' ;
    -0089 nc.title = RiverInfo1;   
    -0090 nc.info =  RiverInfo2; 
    -0091 nc.history = 'FILE CREATED using write_river_file.m' ;
    -0092 
    -0093 % dimensions
    -0094 nc('rivers') = nRivnodes; 
    -0095 nc('namelen') = 26; 
    -0096 nc('time') = 0; 
    -0097 
    -0098 % variables
    -0099 nc{'river_names'} = ncchar('rivers', 'namelen');
    -0100 
    -0101 nc{'time'} = ncfloat('time');
    -0102 nc{'time'}.long_name = 'time';  
    -0103 nc{'time'}.units     = 'days since 0.0';  
    -0104 nc{'time'}.time_zone = 'none';  
    -0105 
    -0106 nc{'Itime'} = ncint('time');
    -0107 nc{'Itime'}.units     = 'days since 0.0';  
    -0108 nc{'Itime'}.time_zone = 'none';  
    -0109 
    -0110 nc{'Itime2'} = ncint('time');
    -0111 nc{'Itime2'}.units     = 'msec since 00:00:00';
    -0112 nc{'Itime2'}.time_zone = 'none';  
    -0113 
    -0114 nc{'river_flux'} = ncfloat('time','rivers');
    -0115 nc{'river_flux'}.long_name = 'river runoff volume flux'; 
    -0116 nc{'river_flux'}.units     = 'm^3s^-1';  
    -0117 
    -0118 nc{'river_temp'} = ncfloat('time','rivers');
    -0119 nc{'river_temp'}.long_name = 'river runoff temperature'; 
    -0120 nc{'river_temp'}.units     = 'Celsius';  
    +0080 % dimensions
    +0081 namelen_dimid = netcdf.defDim(nc, 'namelen', 80);
    +0082 rivers_dimid = netcdf.defDim(nc, 'rivers', nRivnodes);
    +0083 time_dimid = netcdf.defDim(nc, 'time', netcdf.getConstant('NC_UNLIMITED'));
    +0084 date_str_len_dimid = netcdf.defDim(nc, 'DateStrLen', 26);
    +0085 
    +0086 % variables
    +0087 river_names_varid = netcdf.defVar(nc, 'river_names', 'NC_CHAR', [namelen_dimid, rivers_dimid]);
    +0088 
    +0089 time_varid = netcdf.defVar(nc, 'time', 'NC_FLOAT', time_dimid);
    +0090 netcdf.putAtt(nc, time_varid, 'long_name', 'time');
    +0091 netcdf.putAtt(nc, time_varid, 'units', 'days since 1858-11-17 00:00:00');
    +0092 netcdf.putAtt(nc, time_varid, 'format', 'modified julian day (MJD)');
    +0093 netcdf.putAtt(nc, time_varid, 'time_zone', 'UTC');
    +0094 
    +0095 itime_varid = netcdf.defVar(nc, 'Itime', 'NC_INT', time_dimid);
    +0096 netcdf.putAtt(nc, itime_varid, 'units', 'days since 1858-11-17 00:00:00');
    +0097 netcdf.putAtt(nc, itime_varid, 'format', 'modified julian day (MJD)');
    +0098 netcdf.putAtt(nc, itime_varid, 'time_zone', 'UTC');
    +0099 
    +0100 itime2_varid = netcdf.defVar(nc, 'Itime2', 'NC_INT', time_dimid);
    +0101 netcdf.putAtt(nc, itime2_varid, 'units', 'msec since 00:00:00');
    +0102 netcdf.putAtt(nc, itime2_varid, 'time_zone', 'UTC');
    +0103 
    +0104 times_varid = netcdf.defVar(nc,'Times','NC_CHAR',[date_str_len_dimid, time_dimid]);
    +0105 netcdf.putAtt(nc, times_varid, 'time_zone','UTC');
    +0106 
    +0107 river_flux_varid = netcdf.defVar(nc, 'river_flux', 'NC_FLOAT', [rivers_dimid, time_dimid]);
    +0108 netcdf.putAtt(nc, river_flux_varid, 'long_name', 'river runoff volume flux');
    +0109 netcdf.putAtt(nc, river_flux_varid, 'units', 'm^3s^-1');
    +0110 
    +0111 river_temp_varid = netcdf.defVar(nc, 'river_temp', 'NC_FLOAT', [rivers_dimid, time_dimid]);
    +0112 netcdf.putAtt(nc, river_temp_varid, 'long_name', 'river runoff temperature');
    +0113 netcdf.putAtt(nc, river_temp_varid, 'units', 'Celsius');
    +0114 
    +0115 river_salt_varid = netcdf.defVar(nc, 'river_salt', 'NC_FLOAT', [rivers_dimid, time_dimid]);
    +0116 netcdf.putAtt(nc, river_salt_varid, 'long_name', 'river runoff salinity');
    +0117 netcdf.putAtt(nc, river_salt_varid, 'units', 'PSU');
    +0118 
    +0119 % end definitions
    +0120 netcdf.endDef(nc);
     0121 
    -0122 nc{'river_salt'} = ncfloat('time','rivers');
    -0123 nc{'river_salt'}.long_name = 'river runoff salinity'; 
    -0124 nc{'river_salt'}.units     = 'PSU';  
    -0125 
    -0126 % river names (must be 26 character strings)
    -0127 for i=1:nRivnodes
    -0128   fname = [RiverName int2str(i)];
    -0129   temp  = '                          ';
    -0130   temp(1:length(fname)) = fname;
    -0131   nc{'river_names'}(i,:)   = temp;
    -0132 end;
    -0133 
    -0134 % dump dynamic data
    -0135 for i=1:nTimes
    -0136   nc{'time'}(i) = time(i);
    -0137   nc{'Itime'}(i) = floor(time(i));
    -0138   nc{'Itime2'}(i) = mod(time(i),1)*24*3600*1000.;
    -0139   nc{'river_flux'}(i,1:nRivnodes) = river_flux(i,1:nRivnodes); 
    -0140   nc{'river_temp'}(i,1:nRivnodes) = river_temp(i,1:nRivnodes); 
    -0141   nc{'river_salt'}(i,1:nRivnodes) = river_salt(i,1:nRivnodes); 
    -0142   nc{'coarse_sand'}(i,1:nRivnodes) = coarse_sand(i,1:nRivnodes); 
    -0143   nc{'medium_sand'}(i,1:nRivnodes) = medium_sand(i,1:nRivnodes); 
    -0144   nc{'fine_sand'}(i,1:nRivnodes) = fine_sand(i,1:nRivnodes); 
    -0145 end;
    +0122 % river names (must be 80 character strings)
    +0123 rString = char();
    +0124 for i = 1:nRivnodes
    +0125     % Left-aligned 80 character string.
    +0126     rString = [rString, sprintf('%-80s', RiverName{i})];
    +0127 end
    +0128 netcdf.putVar(nc, river_names_varid, rString);
    +0129 
    +0130 % dump dynamic data
    +0131 netcdf.putVar(nc, time_varid, 0, nTimes, time);
    +0132 netcdf.putVar(nc, itime_varid, 0, nTimes, floor(time));
    +0133 netcdf.putVar(nc, itime2_varid, 0, nTimes, mod(time, 1)*24*3600*1000);
    +0134 netcdf.putVar(nc, river_flux_varid, flux');
    +0135 netcdf.putVar(nc, river_temp_varid, temp');
    +0136 netcdf.putVar(nc, river_salt_varid, salt');
    +0137 
    +0138 % build the time string and output to NetCDF.
    +0139 nStringOut = char();
    +0140 for tt = 1:nTimes
    +0141     [nYr, nMon, nDay, nHour, nMin, nSec] = mjulian2greg(time(tt));
    +0142     nDate = [nYr, nMon, nDay, nHour, nMin, nSec];
    +0143     nStringOut = [nStringOut, sprintf('%04i/%02i/%02i %02i:%02i:%02i       ', nDate)];
    +0144 end
    +0145 netcdf.putVar(nc, times_varid, nStringOut);
     0146 
    -0147 nc = close(nc);    
    +0147 netcdf.close(nc);
     0148 
    -0149 
    -0150 if(ftbverbose);
    -0151   fprintf(['end   : ' subname '\n'])
    -0152 end;
    -0153
    -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +0149 if ftbverbose +0150 fprintf(['end : ' subname '\n']) +0151 end +0152
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_river_nml.html b/doc/fvcom_prepro/write_FVCOM_river_nml.html new file mode 100644 index 0000000000000000000000000000000000000000..65c3a885139a61962cd123f2dadc26f3b7c753dd --- /dev/null +++ b/doc/fvcom_prepro/write_FVCOM_river_nml.html @@ -0,0 +1,152 @@ + + + + Description of write_FVCOM_river_nml + + + + + + + + + +
    Home > fvcom_prepro > write_FVCOM_river_nml.m
    + + + +

    write_FVCOM_river_nml +

    + +

    PURPOSE ^

    +
    Write a namelist for the river nodes.
    + +

    SYNOPSIS ^

    +
    function write_FVCOM_river_nml(Mobj, nml_file, nc_file)
    + +

    DESCRIPTION ^

    +
     Write a namelist for the river nodes.
    +
    + write_FVCOM_river_nml(Mobj, nml_file, nc_file)
    +
    + DESCRIPTION:
    +   Using the output of get_POLCOMS_rivers in Mobj, output the river name,
    +   input file, grid node and vertical distribution into a namelist (.nml
    +   file).
    + 
    +   NOTE: if the vertical distribution is uniform, the string 'uniform'
    +   will be output. If a non-uniform distribution is detected, then the
    +   name list will need to be edited to reflect the distribution specified
    +   in the sigma.dat file.
    +
    + INPUT:
    +   Mobj - MATLAB mesh object with the river data.
    +   nml_file - full path to the output namelist file.
    +   nc_file - full path to the NetCDF file containing the river data.
    + 
    + OUTPUT:
    +   Namelist for inclusion in the main FVCOM namelist (RIVER_INFO_FILE).
    + 
    + EXAMPLE USAGE:
    +   write_FVCOM_river_nml(Mobj, 'casename_river.nml', 'casename_river.nc')
    +
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2013-03-21 - First version.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function write_FVCOM_river_nml(Mobj, nml_file, nc_file)
    +0002 % Write a namelist for the river nodes.
    +0003 %
    +0004 % write_FVCOM_river_nml(Mobj, nml_file, nc_file)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Using the output of get_POLCOMS_rivers in Mobj, output the river name,
    +0008 %   input file, grid node and vertical distribution into a namelist (.nml
    +0009 %   file).
    +0010 %
    +0011 %   NOTE: if the vertical distribution is uniform, the string 'uniform'
    +0012 %   will be output. If a non-uniform distribution is detected, then the
    +0013 %   name list will need to be edited to reflect the distribution specified
    +0014 %   in the sigma.dat file.
    +0015 %
    +0016 % INPUT:
    +0017 %   Mobj - MATLAB mesh object with the river data.
    +0018 %   nml_file - full path to the output namelist file.
    +0019 %   nc_file - full path to the NetCDF file containing the river data.
    +0020 %
    +0021 % OUTPUT:
    +0022 %   Namelist for inclusion in the main FVCOM namelist (RIVER_INFO_FILE).
    +0023 %
    +0024 % EXAMPLE USAGE:
    +0025 %   write_FVCOM_river_nml(Mobj, 'casename_river.nml', 'casename_river.nc')
    +0026 %
    +0027 % Author(s):
    +0028 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0029 %
    +0030 % Revision history:
    +0031 %   2013-03-21 - First version.
    +0032 %
    +0033 %==========================================================================
    +0034 
    +0035 subname = 'get_POLCOMS_rivers';
    +0036 
    +0037 global ftbverbose;
    +0038 if ftbverbose
    +0039     fprintf(['\nbegin : ' subname '\n'])
    +0040 end
    +0041 
    +0042 nr = length(Mobj.river_nodes);
    +0043 
    +0044 f = fopen(nml_file, 'w');
    +0045 if f < 0
    +0046     error('Error writing to %s. Check permissions and try again.', nml_file)
    +0047 end
    +0048 
    +0049 % Build the vertical distribution string. Round to 15 decimal places so the
    +0050 % unique check works (hopefully no one needs that many vertical layers...).
    +0051 vDist = roundn(abs(diff(Mobj.siglev)), -15);
    +0052 if length(unique(vDist)) == 1
    +0053     vString = '''uniform''';
    +0054 else
    +0055     vString = char();
    +0056     for ii = 1:length(vDist)
    +0057         vString = [vString, sprintf('%f ', vDist(ii))];
    +0058     end
    +0059 end
    +0060 
    +0061 for r = 1:nr
    +0062     fprintf(f, ' &NML_RIVER\n');
    +0063     fprintf(f, '  RIVER_NAME          = ''%s'',\n', Mobj.river_names{r});
    +0064     fprintf(f, '  RIVER_FILE          = ''%s'',\n', nc_file);
    +0065     fprintf(f, '  RIVER_GRID_LOCATION = %d,\n', Mobj.river_nodes(r));
    +0066     fprintf(f, '  RIVER_VERTICAL_DISTRIBUTION = %s\n', vString);
    +0067     fprintf(f, '  /\n');
    +0068 end
    +0069 
    +0070 fclose(f);
    +0071 
    +0072 if ftbverbose
    +0073     fprintf('end   : %s\n', subname)
    +0074 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_spectide.html b/doc/fvcom_prepro/write_FVCOM_spectide.html index ac583ada1c893495f549aca3376b45abce439a86..e7dce16a4f0ac58c3df94cad44a12352b5f2e81c 100755 --- a/doc/fvcom_prepro/write_FVCOM_spectide.html +++ b/doc/fvcom_prepro/write_FVCOM_spectide.html @@ -162,7 +162,7 @@ This function is called by: 0084 end 0085 end 0086 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'components',ComponentsOut) -0087 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','FILE CREATED using write_FVCOM_spectide') +0087 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','File created using write_FVCOM_spectide.m from the MATLAB fvcom-toolbox') 0088 0089 % define dimensions 0090 one_dimid=netcdf.defDim(nc,'one',1); @@ -243,6 +243,6 @@ This function is called by: 0165 0166 if(report); fprintf(['end : ' subname '\n']); end; 0167 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_sponge.html b/doc/fvcom_prepro/write_FVCOM_sponge.html index a522e6cf66c2b37545b0f3ace91e55fc033316c9..43c2284d11a3e5bbcb5cf871b79647b7bf01b27e 100755 --- a/doc/fvcom_prepro/write_FVCOM_sponge.html +++ b/doc/fvcom_prepro/write_FVCOM_sponge.html @@ -118,7 +118,7 @@ This function is called by: 0050 Total_Sponge = sum(Mobj.nSpongeNodes(1:Mobj.nSponge)); 0051 fprintf(fid,'Sponge Node Number = %d\n',Total_Sponge); 0052 for i=1:Mobj.nSponge -0053 if max(size(Mobj.sponge_rad))==1 % if you have a constant sponge radius +0053 if numel(unique(Mobj.sponge_rad)) == 1 % if you have a constant sponge radius 0054 for j=1:Mobj.nSpongeNodes(i) 0055 fprintf(fid,'%d %f %f \n',Mobj.sponge_nodes(i,j),Mobj.sponge_rad(i),Mobj.sponge_fac(i)); 0056 end; @@ -135,6 +135,6 @@ This function is called by: 0067 fprintf(['end : ' subname '\n']) 0068 end; 0069 -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_stations.html b/doc/fvcom_prepro/write_FVCOM_stations.html index 1d7566ab00aa9d538b34de2db22f7bbf6702c199..821f61b9ce152c984281ab2bf3f638a07c5748b7 100644 --- a/doc/fvcom_prepro/write_FVCOM_stations.html +++ b/doc/fvcom_prepro/write_FVCOM_stations.html @@ -105,7 +105,7 @@ This function is called by: 0036 % Parse input arguments 0037 %-------------------------------------------------------------------------- 0038 if exist('Mobj', 'var') ~= 1 || exist('filename', 'var') ~= 1 -0039 error('arguments to write_FVCOM_grid are incorrect') +0039 error('arguments to %s are incorrect', subname) 0040 end 0041 0042 %-------------------------------------------------------------------------- @@ -138,6 +138,6 @@ This function is called by: 0069 fprintf(['end : ' subname '\n']) 0070 end 0071 -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_tsobc.html b/doc/fvcom_prepro/write_FVCOM_tsobc.html index 72e1d87986db18023c20655914190e93862b6947..fa35db82ba390e43c2b19a354abb2bac1082af28 100644 --- a/doc/fvcom_prepro/write_FVCOM_tsobc.html +++ b/doc/fvcom_prepro/write_FVCOM_tsobc.html @@ -4,7 +4,7 @@ Description of write_FVCOM_tsobc - + @@ -21,13 +21,13 @@

    PURPOSE ^

    -
    example file for dumping a file to force temperature and salinity at the open b.
    +
    Export temperature and salinity forcing at the open boundary.

    SYNOPSIS ^

    function write_FVCOM_tsobc(basename,time,nSiglay,in_temp,in_salt,Mobj)

    DESCRIPTION ^

    -
     example file for dumping a file to force temperature and salinity at the open b.
    +
     Export temperature and salinity forcing at the open boundary.
     
      function write_FVCOM_tsobc(basename,time,nSiglay,in_temp,in_salt)
     
    @@ -81,7 +81,7 @@ This function is called by:
     
     

    SOURCE CODE ^

    0001 function write_FVCOM_tsobc(basename,time,nSiglay,in_temp,in_salt,Mobj)
    -0002 % example file for dumping a file to force temperature and salinity at the open b.
    +0002 % Export temperature and salinity forcing at the open boundary.
     0003 %
     0004 % function write_FVCOM_tsobc(basename,time,nSiglay,in_temp,in_salt)
     0005 %
    @@ -255,7 +255,7 @@ This function is called by:
     0173 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'type','FVCOM RIVER FORCING FILE')
     0174 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title','simple open boundary hydrography test')
     0175 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'type','FVCOM TIME SERIES OBC TS FILE')
    -0176 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','generated using the fvcom-toolbox')
    +0176 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','File generated using write_FVCOM_tsobc.m from the MATLAB fvcom-toolbox')
     0177 
     0178 
     0179 % define dimensions
    @@ -330,6 +330,6 @@ This function is called by:
     0248 netcdf.close(nc);
     0249 
     0250 if(ftbverbose); fprintf(['end   : ' subname '\n']);end;
    -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_wind_ts_speed.html b/doc/fvcom_prepro/write_FVCOM_wind_ts_speed.html index c0f22866cedc809ae27d0398c056c7b68de9876c..f0427c2a2a7c56d1a4c75786f080e037e1f4f3b7 100644 --- a/doc/fvcom_prepro/write_FVCOM_wind_ts_speed.html +++ b/doc/fvcom_prepro/write_FVCOM_wind_ts_speed.html @@ -65,7 +65,8 @@ arguments to the function call (time and u and v vectors). u and v vectors vary in time and space. -==============================================================================
    +============================================================================== +warning off

    CROSS-REFERENCE INFORMATION ^

    @@ -121,7 +122,7 @@ This function is called by: 0039 % vectors vary in time and space. 0040 % 0041 %============================================================================== -0042 warning off +0042 %warning off 0043 subname = 'example_FVCOM_wind_ts_speed'; 0044 global ftbverbose; 0045 if(ftbverbose); @@ -143,7 +144,7 @@ This function is called by: 0061 % netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'source','single-point time-dependent surface forcing') 0062 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'source','fvcom grid (unstructured) surface forcing') 0063 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'institution','Plymouth Marine Laboratory') -0064 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','Generated using the fvcom-toolbox') +0064 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history','File generated using the write_FVCOM_wind_ts_speed.m from the MATLAB fvcom-toolbox') 0065 0066 % dimensions 0067 nele_dimid=netcdf.defDim(nc,'nele',nElems); @@ -199,6 +200,6 @@ This function is called by: 0117 0118 0119 -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/fvcom_prepro/write_FVCOM_z0.html b/doc/fvcom_prepro/write_FVCOM_z0.html index e42eb500af4166e74c61e3889560cd5da7b757ad..4ffea283e41feed21c0b982101e85239dd04d18c 100755 --- a/doc/fvcom_prepro/write_FVCOM_z0.html +++ b/doc/fvcom_prepro/write_FVCOM_z0.html @@ -55,7 +55,8 @@ 2012-06-15 Added support for native MATLAB NetCDF routines. Requires MATLAB 2010a or higher. -============================================================================== +============================================================================== +warning off

    CROSS-REFERENCE INFORMATION ^

    @@ -101,7 +102,7 @@ This function is called by: 0029 % MATLAB 2010a or higher. 0030 % 0031 %============================================================================== -0032 warning off +0032 %warning off 0033 subname = 'write_FVCOM_z0'; 0034 global ftbverbose; 0035 if(ftbverbose); @@ -112,13 +113,13 @@ This function is called by: 0040 % Parse input arguments 0041 %------------------------------------------------------------------------------ 0042 if(~exist('z0','var')) -0043 error('incorrect usage of gen_z0_file, must provide z0 field') +0043 error('incorrect usage of write_FVCOM_z0, must provide z0 field') 0044 end; 0045 if(~exist('filename','var')) -0046 error('incorrect usage of gen_z0_file, must provide filename') +0046 error('incorrect usage of write_FVCOM_z0, must provide filename') 0047 end; 0048 if(~exist('mytitle','var')) -0049 error('incorrect usage of gen_z0_file, must provide title field') +0049 error('incorrect usage of write_FVCOM_z0, must provide title field') 0050 end; 0051 0052 % check dimensions @@ -137,29 +138,30 @@ This function is called by: 0065 nc = netcdf.create(filename,'clobber'); 0066 0067 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title',mytitle) -0068 -0069 % dimensions -0070 nele_dimid=netcdf.defDim(nc,'nele',nElems); -0071 -0072 % variables and attributes -0073 z0b_varid=netcdf.defVar(nc,'z0b','NC_FLOAT',nele_dimid); -0074 netcdf.putAtt(nc,z0b_varid,'long_name','bottom roughness'); -0075 netcdf.putAtt(nc,z0b_varid,'units','m'); -0076 -0077 % end definitions -0078 netcdf.endDef(nc); -0079 -0080 % write data -0081 netcdf.putVar(nc,z0b_varid,z0); -0082 -0083 % close file -0084 netcdf.close(nc); -0085 -0086 if(ftbverbose); -0087 fprintf(['end : ' subname '\n']) -0088 end; -0089 -0090 -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +0068 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history', 'File created using write_FVCOM_z0.m from the MATLAB fvcom-toolbox') +0069 +0070 % dimensions +0071 nele_dimid=netcdf.defDim(nc,'nele',nElems); +0072 +0073 % variables and attributes +0074 z0b_varid=netcdf.defVar(nc,'z0b','NC_FLOAT',nele_dimid); +0075 netcdf.putAtt(nc,z0b_varid,'long_name','bottom roughness'); +0076 netcdf.putAtt(nc,z0b_varid,'units','m'); +0077 +0078 % end definitions +0079 netcdf.endDef(nc); +0080 +0081 % write data +0082 netcdf.putVar(nc,z0b_varid,z0); +0083 +0084 % close file +0085 netcdf.close(nc); +0086 +0087 if(ftbverbose); +0088 fprintf(['end : ' subname '\n']) +0089 end; +0090 +0091 +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 1f586f21101169cc815f188ab3003e1bb58f2cf1..05234dbea2ad576c4adcda7071cc2b143fdcd48b 100755 --- a/doc/index.html +++ b/doc/index.html @@ -19,46 +19,51 @@

    Matlab Files found in these Directories

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    README do_surface_plot gridvecs set_elevtide
    README do_transect_plot ideal_swan_obc set_spectide
    ST_Dstar do_vector_plot ideal_swan_obc_driver_example setup_metrics
    ST_d2phi do_volume inCell show_fetch
    ST_erate do_volume_change inbox show_sigma
    ST_example do_volume_change2 inkmlbb sigma_gen
    ST_phi2d elems2nodes isintriangle sigma_geo
    ST_summary estimate_ts julian2greg sigma_tanh
    ST_taucr example lat_to_m smoothfield
    ST_wentworth example2 lon_to_m smoothfield2
    ST_wset example_FVCOM_river m_ll2ll swan2netcdf
    SW_Density example_FVCOM_tsobc m_to_lat transect_nodes_screen
    SW_Kviscosity example_FVCOM_wind_ts m_to_lon tri_from_bndry
    SW_Viscosity example_FVCOM_wind_ts_speed make_blank_mesh truncfield
    add_coriolis example_fetchcalc mjul2str utm2deg
    add_obc_nodes_graphic example_my_project mjul2str2 wave_fric
    add_obc_nodes_list example_surface_plot mjul2str_noyear wgs2utm
    add_river_nodes_graphic fetch_calc mjulian2greg wrf2fvcom_U10V10
    add_river_nodes_list find_nearest_pt my_project write_FVCOM_bath
    add_sigma_forDT fvcom2swan naut_2_cart write_FVCOM_bedflag
    add_sponge_nodes gen_semistructured_mesh nodes2elems write_FVCOM_cor
    add_sponge_nodes_list gen_unstructured_mesh pl64 write_FVCOM_elevtide
    add_stations_list generate_mjd plot_field write_FVCOM_forcing
    add_var_FVCOM_river get_AMM plot_swan_mesh write_FVCOM_grid
    calc_fetch get_HYCOM_forcing plotunswan write_FVCOM_obc
    calc_sponge_radius get_NAE2_forcing read_ERA_wind write_FVCOM_obs_TS
    calc_tauw get_NCEP_forcing read_NCEP_wind write_FVCOM_river
    calc_tauw get_NCEP_year read_fvcom_bath write_FVCOM_spectide
    centroid get_POLCOMS_tsobc read_fvcom_mesh write_FVCOM_sponge
    check_wset get_POLPRED_spectide read_fvcom_mesh write_FVCOM_stations
    connectivity get_fetch read_kml write_FVCOM_tsobc
    deg2utm get_runs read_netCDF_FVCOM write_FVCOM_wind_ts_speed
    do_ph_change_plot get_runs_test read_sigma write_FVCOM_z0
    do_ph_change_points_plot get_zeta_xtide read_sms_mesh write_dtank
    do_ph_max_change_plot ginput2 read_specfile write_river_info
    do_ph_vertical_profile greg2julian readdir ww3_to_swan_bndry
    do_residual greg2mjulian replace_FVCOM_restart_vars zero_to_nan
    do_residual_plot grid2fvcom runmean
    + README do_volume_change grid2fvcom show_fetch + README do_volume_change2 grid_vert_interp show_sigma + ST_Dstar elems2nodes gridvecs sigma_gen + ST_d2phi estimate_ts ideal_swan_obc sigma_geo + ST_erate example ideal_swan_obc_driver_example sigma_tanh + ST_example example2 inCell smoothfield + ST_phi2d example_FVCOM_river inbox smoothfield2 + ST_summary example_FVCOM_tsobc inkmlbb swan2netcdf + ST_taucr example_FVCOM_wind_ts interp_POLCOMS2FVCOM transect_nodes_screen + ST_wentworth example_FVCOM_wind_ts_speed isintriangle tri_from_bndry + ST_wset example_fetchcalc julian2greg truncfield + SW_Density example_init_lag lat_to_m utm2deg + SW_Kviscosity example_my_project lon_to_m wave_fric + SW_Viscosity example_surface_plot m_ll2ll wgs2utm + add_coriolis fetch_calc m_to_lat wrf2fvcom_U10V10 + add_obc_nodes_graphic find_boundary_elements m_to_lon write_FVCOM_bath + add_obc_nodes_list find_nearest_pt make_blank_mesh write_FVCOM_bedflag + add_river_nodes_graphic fix_inside_boundary mjul2str write_FVCOM_cor + add_river_nodes_list fvcom2swan mjul2str2 write_FVCOM_elevtide + add_sigma_forDT gen_semistructured_mesh mjulian2greg write_FVCOM_forcing + add_sponge_nodes gen_unstructured_mesh my_project write_FVCOM_grid + add_sponge_nodes_list generate_mjd naut_2_cart write_FVCOM_meanflow + add_stations_list get_AMM nodes2elems write_FVCOM_meanflow_ascii + add_var_FVCOM_river get_FVCOM_rivers pl64 write_FVCOM_obc + calc_fetch get_HYCOM_forcing plot_field write_FVCOM_obs_TS + calc_sponge_radius get_MetUM_forcing plot_swan_mesh write_FVCOM_restart + calc_tauw get_NAE2_forcing plotunswan write_FVCOM_river + calc_tauw get_NCEP_forcing read_ERA_wind write_FVCOM_river_nml + catstruct get_NCEP_year read_NCEP_wind write_FVCOM_spectide + centroid get_POLCOMS_meanflow read_fvcom_bath write_FVCOM_sponge + check_wset get_POLCOMS_netCDF read_fvcom_mesh write_FVCOM_stations + connectivity get_POLCOMS_river_discharge read_fvcom_mesh write_FVCOM_tsobc + deg2utm get_POLCOMS_river_positions read_kml write_FVCOM_wind_ts_speed + do_ph_change_plot get_POLCOMS_tsobc read_netCDF_FVCOM write_FVCOM_z0 + do_ph_change_points_plot get_POLCOMS_tsobc_gcoms read_sigma write_SMS_2dm + do_ph_max_change_plot get_POLPRED_spectide read_sms_map write_SMS_cst + do_ph_vertical_profile get_fetch read_sms_mesh write_dtank + do_residual get_runs read_specfile write_river_info + do_residual_plot get_runs_test readdir ww3_to_swan_bndry + do_surface_plot get_zeta_xtide runmean zero_to_nan + do_transect_plot ginput2 set_elevtide + do_vector_plot greg2julian set_spectide + do_volume greg2mjulian setup_metrics -
    Generated on Mon 04-Feb-2013 14:22:25 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:53 by m2html © 2005
    \ No newline at end of file diff --git a/doc/swan_scripts/graph.dot b/doc/swan_scripts/graph.dot new file mode 100644 index 0000000000000000000000000000000000000000..2d5fb236daf966d63e59c244a573bcafeede5668 --- /dev/null +++ b/doc/swan_scripts/graph.dot @@ -0,0 +1,23 @@ +/* Created by mdot for Matlab */ +digraph m2html { + example_fetchcalc -> fetch_calc; + example_fetchcalc -> get_fetch; + example_fetchcalc -> show_fetch; + fvcom2swan -> plot_swan_mesh; + ideal_swan_obc_driver_example -> ideal_swan_obc; + + calc_fetch [URL="calc_fetch.html"]; + calc_tauw [URL="calc_tauw.html"]; + example_fetchcalc [URL="example_fetchcalc.html"]; + fetch_calc [URL="fetch_calc.html"]; + fvcom2swan [URL="fvcom2swan.html"]; + get_fetch [URL="get_fetch.html"]; + ideal_swan_obc [URL="ideal_swan_obc.html"]; + ideal_swan_obc_driver_example [URL="ideal_swan_obc_driver_example.html"]; + plot_swan_mesh [URL="plot_swan_mesh.html"]; + plotunswan [URL="plotunswan.html"]; + read_specfile [URL="read_specfile.html"]; + show_fetch [URL="show_fetch.html"]; + swan2netcdf [URL="swan2netcdf.html"]; + ww3_to_swan_bndry [URL="ww3_to_swan_bndry.html"]; +} \ No newline at end of file diff --git a/doc/swan_scripts/graph.html b/doc/swan_scripts/graph.html new file mode 100644 index 0000000000000000000000000000000000000000..8e7865fb843a91320015796e43c73d9e6878184b --- /dev/null +++ b/doc/swan_scripts/graph.html @@ -0,0 +1,41 @@ + + + + Dependency Graph for swan_scripts + + + + + + + + + + +
    < Master indexIndex for swan_scripts >
    +

    Dependency Graph for swan_scripts

    + +
    +Dependency Graph for swan_scripts + + + + + + + + + + + + + + + + +
    + +
    Generated on Tue 04-Jun-2013 12:12:56 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/swan_scripts/graph.map b/doc/swan_scripts/graph.map new file mode 100644 index 0000000000000000000000000000000000000000..81be481bb3a54ab0d3c24b22f7941bf1b3941d7e --- /dev/null +++ b/doc/swan_scripts/graph.map @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/doc/swan_scripts/graph.png b/doc/swan_scripts/graph.png new file mode 100644 index 0000000000000000000000000000000000000000..8ad98e52b030121d9ed401d983fb257bc348c0a5 Binary files /dev/null and b/doc/swan_scripts/graph.png differ diff --git a/doc/swan_scripts/index.html b/doc/swan_scripts/index.html index 1ac3baef72aa2c548136f56844f57b7e9cb45e52..5bf019ad9f4043f38249afc21a6a827d29301403 100755 --- a/doc/swan_scripts/index.html +++ b/doc/swan_scripts/index.html @@ -23,7 +23,10 @@ - -
    Generated on Tue 18-Dec-2012 12:37:29 by m2html © 2005
    +

    Dependency Graph

    + +
    Generated on Tue 04-Jun-2013 12:12:54 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/catstruct.html b/doc/utilities/catstruct.html new file mode 100644 index 0000000000000000000000000000000000000000..1cd647554f08d7efe475be358734e0c847210c35 --- /dev/null +++ b/doc/utilities/catstruct.html @@ -0,0 +1,228 @@ + + + + Description of catstruct + + + + + + + + + +
    Home > utilities > catstruct.m
    + + + +

    catstruct +

    + +

    PURPOSE ^

    +
    CATSTRUCT Concatenate or merge structures with different fieldnames
    + +

    SYNOPSIS ^

    +
    function A = catstruct(varargin)
    + +

    DESCRIPTION ^

    +
     CATSTRUCT   Concatenate or merge structures with different fieldnames
    +   X = CATSTRUCT(S1,S2,S3,...) merges the structures S1, S2, S3 ...
    +   into one new structure X. X contains all fields present in the various
    +   structures. An example:
    +
    +     A.name = 'Me' ;
    +     B.income = 99999 ;
    +     X = catstruct(A,B) 
    +     % -> X.name = 'Me' ;
    +     %    X.income = 99999 ;
    +
    +   If a fieldname is not unique among structures (i.e., a fieldname is
    +   present in more than one structure), only the value from the last
    +   structure with this field is used. In this case, the fields are 
    +   alphabetically sorted. A warning is issued as well. An axample:
    +
    +     S1.name = 'Me' ;
    +     S2.age  = 20 ; S3.age  = 30 ; S4.age  = 40 ;
    +     S5.honest = false ;
    +     Y = catstruct(S1,S2,S3,S4,S5) % use value from S4
    +
    +   The inputs can be array of structures. All structures should have the
    +   same size. An example:
    +
    +     C(1).bb = 1 ; C(2).bb = 2 ;
    +     D(1).aa = 3 ; D(2).aa = 4 ;
    +     CD = catstruct(C,D) % CD is a 1x2 structure array with fields bb and aa
    +
    +   The last input can be the string 'sorted'. In this case,
    +   CATSTRUCT(S1,S2, ..., 'sorted') will sort the fieldnames alphabetically. 
    +   To sort the fieldnames of a structure A, you could use
    +   CATSTRUCT(A,'sorted') but I recommend ORDERFIELDS for doing that.
    +
    +   When there is nothing to concatenate, the result will be an empty
    +   struct (0x0 struct array with no fields).
    +
    +   NOTE: To concatenate similar arrays of structs, you can use simple
    +   concatenation: 
    +     A = dir('*.mat') ; B = dir('*.m') ; C = [A ; B] ;
    +
    +   See also CAT, STRUCT, FIELDNAMES, STRUCT2CELL, ORDERFIELDS
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function A = catstruct(varargin)
    +0002 % CATSTRUCT   Concatenate or merge structures with different fieldnames
    +0003 %   X = CATSTRUCT(S1,S2,S3,...) merges the structures S1, S2, S3 ...
    +0004 %   into one new structure X. X contains all fields present in the various
    +0005 %   structures. An example:
    +0006 %
    +0007 %     A.name = 'Me' ;
    +0008 %     B.income = 99999 ;
    +0009 %     X = catstruct(A,B)
    +0010 %     % -> X.name = 'Me' ;
    +0011 %     %    X.income = 99999 ;
    +0012 %
    +0013 %   If a fieldname is not unique among structures (i.e., a fieldname is
    +0014 %   present in more than one structure), only the value from the last
    +0015 %   structure with this field is used. In this case, the fields are
    +0016 %   alphabetically sorted. A warning is issued as well. An axample:
    +0017 %
    +0018 %     S1.name = 'Me' ;
    +0019 %     S2.age  = 20 ; S3.age  = 30 ; S4.age  = 40 ;
    +0020 %     S5.honest = false ;
    +0021 %     Y = catstruct(S1,S2,S3,S4,S5) % use value from S4
    +0022 %
    +0023 %   The inputs can be array of structures. All structures should have the
    +0024 %   same size. An example:
    +0025 %
    +0026 %     C(1).bb = 1 ; C(2).bb = 2 ;
    +0027 %     D(1).aa = 3 ; D(2).aa = 4 ;
    +0028 %     CD = catstruct(C,D) % CD is a 1x2 structure array with fields bb and aa
    +0029 %
    +0030 %   The last input can be the string 'sorted'. In this case,
    +0031 %   CATSTRUCT(S1,S2, ..., 'sorted') will sort the fieldnames alphabetically.
    +0032 %   To sort the fieldnames of a structure A, you could use
    +0033 %   CATSTRUCT(A,'sorted') but I recommend ORDERFIELDS for doing that.
    +0034 %
    +0035 %   When there is nothing to concatenate, the result will be an empty
    +0036 %   struct (0x0 struct array with no fields).
    +0037 %
    +0038 %   NOTE: To concatenate similar arrays of structs, you can use simple
    +0039 %   concatenation:
    +0040 %     A = dir('*.mat') ; B = dir('*.m') ; C = [A ; B] ;
    +0041 %
    +0042 %   See also CAT, STRUCT, FIELDNAMES, STRUCT2CELL, ORDERFIELDS
    +0043 
    +0044 % for Matlab R13 and up
    +0045 % version 3.0 (mar 2013)
    +0046 % (c) Jos van der Geest
    +0047 % email: jos@jasen.nl
    +0048 
    +0049 % History
    +0050 % Created in 2005
    +0051 % Revisions
    +0052 %   2.0 (sep 2007) removed bug when dealing with fields containing cell
    +0053 %                  arrays (Thanks to Rene Willemink)
    +0054 %   2.1 (sep 2008) added warning and error identifiers
    +0055 %   2.2 (oct 2008) fixed error when dealing with empty structs (Thanks to
    +0056 %                  Lars Barring)
    +0057 %   3.0 (mar 2013) fixed problem when the inputs were array of structures
    +0058 %                  (thanks to Tor Inge Birkenes for pointing this out).
    +0059 %                  Rephrased the help section as well.
    +0060 
    +0061 error(nargchk(1,Inf,nargin)) ;
    +0062 N = nargin ;
    +0063 
    +0064 if ~isstruct(varargin{end}),
    +0065     if isequal(varargin{end},'sorted'),
    +0066         sorted = 1 ;
    +0067         N = N-1 ;
    +0068         error(nargchk(1,Inf,N)) ;
    +0069     else
    +0070         error('catstruct:InvalidArgument','Last argument should be a structure, or the string "sorted".') ;
    +0071     end
    +0072 else
    +0073     sorted = 0 ;
    +0074 end
    +0075 
    +0076 sz0 = [] ; % used to check that all inputs have the same size
    +0077 
    +0078 % used to check for a few trivial cases
    +0079 NonEmptyInputs = false(N,1) ; 
    +0080 NonEmptyInputsN = 0 ;
    +0081 
    +0082 % used to collect the fieldnames and the inputs
    +0083 FN = cell(N,1) ;
    +0084 VAL = cell(N,1) ;
    +0085 
    +0086 % parse the inputs
    +0087 for ii=1:N,
    +0088     X = varargin{ii} ;
    +0089     if ~isstruct(X),
    +0090         error('catstruct:InvalidArgument',['Argument #' num2str(ii) ' is not a structure.']) ;
    +0091     end
    +0092     
    +0093     if ~isempty(X),
    +0094         % empty structs are ignored
    +0095         if ii > 1 && ~isempty(sz0)
    +0096             if ~isequal(size(X), sz0)
    +0097                 error('catstruct:UnequalSizes','All structures should have the same size.') ;
    +0098             end
    +0099         else
    +0100             sz0 = size(X) ;
    +0101         end
    +0102         NonEmptyInputsN = NonEmptyInputsN + 1 ;
    +0103         NonEmptyInputs(ii) = true ;
    +0104         FN{ii} = fieldnames(X) ;
    +0105         VAL{ii} = struct2cell(X) ;
    +0106     end
    +0107 end
    +0108 
    +0109 if NonEmptyInputsN == 0
    +0110     % all structures were empty
    +0111     A = struct([]) ;
    +0112 elseif NonEmptyInputsN == 1,
    +0113     % there was only one non-empty structure
    +0114     A = varargin{NonEmptyInputs} ;
    +0115     if sorted,
    +0116         A = orderfields(A) ;
    +0117     end
    +0118 else
    +0119     % there is actually something to concatenate
    +0120     FN = cat(1,FN{:}) ;    
    +0121     VAL = cat(1,VAL{:}) ;    
    +0122     FN = squeeze(FN) ;
    +0123     VAL = squeeze(VAL) ;
    +0124     [UFN,ind] = unique(FN) ;
    +0125     
    +0126     if numel(UFN) ~= numel(FN),
    +0127         warning('catstruct:DuplicatesFound','Fieldnames are not unique between structures.') ;
    +0128         sorted = 1 ;
    +0129     end
    +0130     
    +0131     if sorted,
    +0132         VAL = VAL(ind,:) ;
    +0133         FN = FN(ind,:) ;
    +0134     end
    +0135     
    +0136     A = cell2struct(VAL, FN);
    +0137     A = reshape(A, sz0) ; % reshape into original format
    +0138 end
    +0139 
    +0140 
    +0141
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/utilities/centroid.html b/doc/utilities/centroid.html index d9f2a7cbcd16dfaef28147088aceae97b063d80b..8a698ccda4eb055a37c846e54e9344e39400d926 100644 --- a/doc/utilities/centroid.html +++ b/doc/utilities/centroid.html @@ -59,7 +59,7 @@ This function is called by: 0009 0010 [m1,n1] = size(x); [m2,n2] = size(y); 0011 n = max(m1,n1); -0012 if [m1,n1] ~= [m2,n2] || min(m1,n1) ~= 1 || n <= 1 +0012 if (m1 ~= m2 && n1 ~= n2) || min(m1,n1) ~= 1 || n <= 1 0013 error('Args must be equal-sized non-scalar vectors') 0014 end 0015 x = x(:); y = y(:); @@ -68,6 +68,6 @@ This function is called by: 0018 a = 1/2*sum (x.*y2-x2.*y); 0019 x0 = 1/6*sum((x.*y2-x2.*y).*(x+x2))/a; 0020 y0 = 1/6*sum((x.*y2-x2.*y).*(y+y2))/a; -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/do_surface_plot.html b/doc/utilities/do_surface_plot.html index 8a1eccacebe29438ea4caa0ad75370a8bcdc55be..c3f68d0f1fb4599c8790231c43252041c4c4f18f 100644 --- a/doc/utilities/do_surface_plot.html +++ b/doc/utilities/do_surface_plot.html @@ -4,7 +4,7 @@ Description of do_surface_plot - + @@ -21,13 +21,43 @@

    PURPOSE ^

    -
    reads image and plots tracks or stations
    +

    SYNOPSIS ^

    function [Plots]=do_surface_plot(plotOPTS,FVCOM)

    DESCRIPTION ^

    -
     reads image and plots tracks or stations
    +
    + Function to display color maps of FVCOM variables (i.e. temperature)
    +
    +  [Plots]=do_surface_plot(plotOPTS,FVCOM)
    +
    + DESCRIPTION:
    +    Generates maps of variables using m_map toolbox (patch
    +
    + INPUT:
    +   plotOPTS   = structure array with predefined options for generating the
    +   maps
    +   FVCOM  = data extracted from FVCOM NC file. See read_netCDF_FVCOM for
    +   details
    +
    +   plotOPTS.range_lat: [50.1000 50.4000]
    +   plotOPTS.range_lon: [-4.5000 -3.8500]
    +   plotOPTS.fig_name: 'co2_S5_slowleak'
    +   plotOPTS.mesh: [1x1 struct]
    +   plotOPTS.coastline_file: '../mat/tamar3_0coast.mat'
    +   plotOPTS.zone: 30
    +   plotOPTS.ell: 'grs80'
    +   plotOPTS.var_plot: 'PH'
    +   plotOPTS.clims: [6 8]
    +   plotOPTS.do_mesh: 0
    +   plotOPTS.nz_plot: 1
    +   plotOPTS.figure: 1
    +   plotOPTS.Time_record: 7.3271e+05
    +   plotOPTS.nz_plot_vec: 1
    +   plotOPTS.data_dec: 5
    +   plotOPTS.vel_sca: 5
    +   plotOPTS.pause: 0.5000

    CROSS-REFERENCE INFORMATION ^

    @@ -43,53 +73,101 @@ This function is called by:

    SOURCE CODE ^

    0001 function [Plots]=do_surface_plot(plotOPTS,FVCOM)
    -0002 % reads image and plots tracks or stations
    -0003 m_mappath;
    -0004 
    -0005 figure(plotOPTS.figure); clf
    -0006 m_proj('UTM','lon',[plotOPTS.range_lon],'lat',[plotOPTS.range_lat],'zon',plotOPTS.zone,'ell','grs80')
    -0007 m_grid('box','fancy')
    -0008 %m_usercoast(plotOPTS.coastline_file,'Color','k','LineWidth',3);
    -0009 %[X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
    -0010 X=plotOPTS.mesh.x;
    -0011 Y=plotOPTS.mesh.y;
    -0012 for aa=1:length(plotOPTS.Time_record)
    -0013     % plot map with plotOPTS.var_plot
    -0014     hold on
    -0015     try
    -0016         % 3D data (i.e. DYE, pH etc.)
    -0017         Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
    -0018             'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),...
    -0019             'edgecolor','interp','facecolor','interp');
    -0020     catch
    -0021         % 2D data only (i.e. zeta etc.)
    -0022         Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
    -0023             'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,aa)),...
    -0024             'edgecolor','interp','facecolor','interp');
    -0025     end
    -0026     fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record))
    -0027     caxis(plotOPTS.clims)
    -0028     colorbar
    -0029     set(get(colorbar,'YLabel'),'String',plotOPTS.var_plot)
    -0030     % check if mesh elements are required
    -0031     if plotOPTS.do_mesh
    -0032         % plot vertices
    -0033         [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
    -0034         patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
    -0035             'EdgeColor',[0.6 0.6 0.6],'FaceColor','none'); hold on
    -0036     end
    -0037     %----------------------------------------------------------------------
    -0038     % Only in my case it needs adding 6 because proj automatically
    -0039     % determines a reference long in strides of 6deg while m_map doesn't
    -0040     %----------------------------------------------------------------------
    -0041     pause(plotOPTS.pause)
    -0042     if aa~=length(plotOPTS.Time_record)
    -0043         delete(Plots(1).handles)
    -0044     end
    -0045 end
    -0046 
    -0047 return
    -0048
    -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +0002 % +0003 % Function to display color maps of FVCOM variables (i.e. temperature) +0004 % +0005 % [Plots]=do_surface_plot(plotOPTS,FVCOM) +0006 % +0007 % DESCRIPTION: +0008 % Generates maps of variables using m_map toolbox (patch +0009 % +0010 % INPUT: +0011 % plotOPTS = structure array with predefined options for generating the +0012 % maps +0013 % FVCOM = data extracted from FVCOM NC file. See read_netCDF_FVCOM for +0014 % details +0015 % +0016 % plotOPTS.range_lat: [50.1000 50.4000] +0017 % plotOPTS.range_lon: [-4.5000 -3.8500] +0018 % plotOPTS.fig_name: 'co2_S5_slowleak' +0019 % plotOPTS.mesh: [1x1 struct] +0020 % plotOPTS.coastline_file: '../mat/tamar3_0coast.mat' +0021 % plotOPTS.zone: 30 +0022 % plotOPTS.ell: 'grs80' +0023 % plotOPTS.var_plot: 'PH' +0024 % plotOPTS.clims: [6 8] +0025 % plotOPTS.do_mesh: 0 +0026 % plotOPTS.nz_plot: 1 +0027 % plotOPTS.figure: 1 +0028 % plotOPTS.Time_record: 7.3271e+05 +0029 % plotOPTS.nz_plot_vec: 1 +0030 % plotOPTS.data_dec: 5 +0031 % plotOPTS.vel_sca: 5 +0032 % plotOPTS.pause: 0.5000 +0033 +0034 % +0035 % OUTPUT: +0036 % Plots = structure array with figure handles +0037 % +0038 % EXAMPLE USAGE +0039 % [Plots]=do_surface_plot(plotOPTS,FVCOM) +0040 % +0041 % Author(s): +0042 % Ricardo Torres and Pierre Cazenave (Plymouth Marine Laboratory) +0043 % +0044 % Revision history +0045 % +0046 %============================================================================== +0047 % +0048 m_mappath; +0049 % adds m_map to matlab paths. file is in utilities directory. +0050 % amend according to your m_map installation paths +0051 +0052 figure(plotOPTS.figure);clf +0053 % generate figure with correct projection lat and lon range ellipsoid and +0054 % zone. +0055 m_proj('UTM','lon',[ plotOPTS.range_lon],'lat',[plotOPTS.range_lat],'zon',plotOPTS.zone,'ell',plotOPTS.ell) +0056 m_grid('box','fancy') +0057 % add coastline if present +0058 if (isfield(plotOPTS,'coastline_file') && ~isempty(plotOPTS.coastline_file) ) +0059 m_usercoast(plotOPTS.coastline_file,'Color','k','LineWidth',3); +0060 end +0061 +0062 [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on'); +0063 %------------------------------------------------------------------------------ +0064 % Generate maps at a give level +0065 %------------------------------------------------------------------------------ +0066 +0067 for aa=1:length(plotOPTS.Time_record) +0068 fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record)); +0069 %plot map +0070 hold on +0071 Plots(plotOPTS.figure).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,... +0072 'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),'edgecolor','interp','facecolor','interp'); +0073 +0074 caxis(plotOPTS.clims) +0075 colorbar +0076 % check if mesh elements are required +0077 if plotOPTS.do_mesh +0078 %plot vertices +0079 [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on'); +0080 Plots(plotOPTS.figure).mesh=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,... +0081 'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on +0082 +0083 end +0084 %----------------------------------------------------------------------- +0085 % Only in my case it needs adding 6 because proj automatically determines a +0086 % reference long in strides of 6deg while m_map doesn't +0087 %------------------------------------------------------------------------ +0088 pause(.2) +0089 if aa~=length(plotOPTS.Time_record) +0090 delete(Plots(plotOPTS.figure).handles(:)) +0091 end +0092 +0093 end +0094 +0095 return +0096 +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/do_vector_plot.html b/doc/utilities/do_vector_plot.html index a5ffaa7d71010a9bd2e364c644846963d8d2c70a..466961b7191a8bc0e10d853eedcde52293103fbf 100644 --- a/doc/utilities/do_vector_plot.html +++ b/doc/utilities/do_vector_plot.html @@ -4,7 +4,7 @@ Description of do_vector_plot - + @@ -21,13 +21,43 @@

    PURPOSE ^

    -
    Plot vectors of parameters of interest.
    +

    SYNOPSIS ^

    function [Plots]=do_vector_plot(plotOPTS,FVCOM)

    DESCRIPTION ^

    -
     Plot vectors of parameters of interest.
    +
    + Function to display vector maps of FVCOM currents (i.e. U,V)
    +
    +  [Plots]=do_vector_plot(plotOPTS,FVCOM)
    +
    + DESCRIPTION:
    +    Generates vector maps of currents using m_map toolbox
    +
    + INPUT:
    +   plotOPTS   = structure array with predefined options for generating the
    +   maps
    +   FVCOM  = data extracted from FVCOM NC file. See read_netCDF_FVCOM for
    +   details
    +
    +   plotOPTS.range_lat: [50.1000 50.4000]
    +   plotOPTS.range_lon: [-4.5000 -3.8500]
    +   plotOPTS.fig_name: 'co2_S5_slowleak'
    +   plotOPTS.mesh: [1x1 struct]
    +   plotOPTS.coastline_file: '../mat/tamar3_0coast.mat'
    +   plotOPTS.zone: 30
    +   plotOPTS.ell: 'grs80'
    +   plotOPTS.var_plot: 'PH'
    +   plotOPTS.clims: [6 8]
    +   plotOPTS.do_mesh: 0
    +   plotOPTS.nz_plot: 1
    +   plotOPTS.figure: 1
    +   plotOPTS.Time_record: 7.3271e+05
    +   plotOPTS.nz_plot_vec: 1
    +   plotOPTS.data_dec: 5
    +   plotOPTS.vel_sca: 5
    +   plotOPTS.pause: 0.5000

    CROSS-REFERENCE INFORMATION ^

    @@ -43,65 +73,127 @@ This function is called by:

    SOURCE CODE ^

    0001 function [Plots]=do_vector_plot(plotOPTS,FVCOM)
    -0002 % Plot vectors of parameters of interest.
    -0003 m_mappath;
    -0004 
    -0005 figure(plotOPTS.figure); clf
    -0006 m_proj('UTM','lon',[plotOPTS.range_lon],'lat',[plotOPTS.range_lat],'zon',30,'ell','grs80')
    -0007 m_grid('box','fancy')
    -0008 m_usercoast(plotOPTS.coastline_file,'Color','k','LineWidth',3);
    -0009 [x,y]=m_ll2ll(FVCOM.xc,FVCOM.yc); x=x+6;
    -0010 
    -0011 igood = find (x < plotOPTS.range_lon(2) & x > plotOPTS.range_lon(1) &...
    -0012     y < plotOPTS.range_lat(2) & y > plotOPTS.range_lat(1));
    -0013 igood=igood(1:plotOPTS.data_dec:end);
    -0014 
    -0015 if isfield(plotOPTS,'nz_plot_vec')
    -0016     nLayers=size(plotOPTS.nz_plot_vec,2);
    -0017     nLayersRange=plotOPTS.nz_plot_vec;
    -0018 else
    -0019     nLayers=size(plotOPTS.nz_plot,2);
    -0020     nLayersRange=plotOPTS.nz_plot;
    -0021 end
    -0022 
    -0023 if nLayers==1
    -0024     colourSpec=[0 0 0];
    -0025 else
    -0026     colourSpec=colormap(hsv(nLayers));
    -0027 end
    -0028 
    -0029 % Preallocate outputs
    -0030 u=nan(size(igood,1),nLayers,length(plotOPTS.Time_record));
    -0031 v=nan(size(igood,1),nLayers,length(plotOPTS.Time_record));
    -0032 
    -0033 % Check if we're running
    -0034 for aa=1:length(plotOPTS.Time_record)
    -0035     fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record))
    -0036     
    -0037 
    -0038     % Mesh goes underneath vectors.
    -0039     if plotOPTS.do_mesh
    -0040         % plot vertices
    -0041         [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
    -0042         Plots(plotOPTS.figure).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
    -0043             'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on
    -0044     end
    -0045 
    -0046     for ii=1:nLayers
    -0047         u(:,ii)=squeeze(FVCOM.u(igood,nLayersRange(ii),(aa)));
    -0048         v(:,ii)=squeeze(FVCOM.v(igood,nLayersRange(ii),(aa)));
    -0049     end
    -0050     for jj=1:nLayers
    -0051         [Plots(plotOPTS.figure).handles(jj),~]=m_vec(plotOPTS.vel_sca,x(igood),y(igood),...
    -0052             u(:,jj),v(:,jj),colourSpec(jj,:),...
    -0053             'shaftwidth',1,'headwidth',2);
    -0054         hold on
    -0055     end
    -0056     pause(plotOPTS.pause)
    -0057     if aa~=length(plotOPTS.Time_record)
    -0058         delete(Plots(plotOPTS.figure).handles(:))
    -0059     end
    -0060 end
    -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +0002 % +0003 % Function to display vector maps of FVCOM currents (i.e. U,V) +0004 % +0005 % [Plots]=do_vector_plot(plotOPTS,FVCOM) +0006 % +0007 % DESCRIPTION: +0008 % Generates vector maps of currents using m_map toolbox +0009 % +0010 % INPUT: +0011 % plotOPTS = structure array with predefined options for generating the +0012 % maps +0013 % FVCOM = data extracted from FVCOM NC file. See read_netCDF_FVCOM for +0014 % details +0015 % +0016 % plotOPTS.range_lat: [50.1000 50.4000] +0017 % plotOPTS.range_lon: [-4.5000 -3.8500] +0018 % plotOPTS.fig_name: 'co2_S5_slowleak' +0019 % plotOPTS.mesh: [1x1 struct] +0020 % plotOPTS.coastline_file: '../mat/tamar3_0coast.mat' +0021 % plotOPTS.zone: 30 +0022 % plotOPTS.ell: 'grs80' +0023 % plotOPTS.var_plot: 'PH' +0024 % plotOPTS.clims: [6 8] +0025 % plotOPTS.do_mesh: 0 +0026 % plotOPTS.nz_plot: 1 +0027 % plotOPTS.figure: 1 +0028 % plotOPTS.Time_record: 7.3271e+05 +0029 % plotOPTS.nz_plot_vec: 1 +0030 % plotOPTS.data_dec: 5 +0031 % plotOPTS.vel_sca: 5 +0032 % plotOPTS.pause: 0.5000 +0033 +0034 % +0035 % OUTPUT: +0036 % Plots = structure array with figure handles +0037 % +0038 % EXAMPLE USAGE +0039 % [Plots]=do_vector_plot(plotOPTS,FVCOM) +0040 % +0041 % Author(s): +0042 % Ricardo Torres and Pierre Cazenave (Plymouth Marine Laboratory) +0043 % +0044 % Revision history +0045 % +0046 %============================================================================== +0047 m_mappath; +0048 % adds m_map to matlab paths. file is in utilities directory. +0049 % ammend according to your m_map installation paths +0050 figure(plotOPTS.figure); +0051 % generate figure with correct projection lat and lon range ellipsoid and +0052 % zone. +0053 m_proj('UTM','lon',[plotOPTS.range_lon],'lat',[plotOPTS.range_lat],'zon',plotOPTS.zone,'ell',plotOPTS.ell) +0054 m_grid('box','fancy') +0055 % add coastline if present +0056 if (isfield(plotOPTS,'coastline_file') && ~isempty(plotOPTS.coastline_file) ) +0057 m_usercoast(plotOPTS.coastline_file,'Color','k','LineWidth',3); +0058 end +0059 %----------------------------------------------------------------------- +0060 % Convert element positions from FVCOM to lat and lon using m_ll2ll.m from +0061 % utilities directory. This accesses m_map functions. +0062 % In my case it needs adding 6 because of discrepancies between proj and m_map. +0063 % Proj automatically determines a +0064 % reference long in strides of 6deg while m_map doesn't +0065 %------------------------------------------------------------------------ +0066 +0067 [x,y]=m_ll2ll(FVCOM.xc,FVCOM.yc); x=x+6; +0068 +0069 % only plot vectors inside lat and lon range and ... +0070 igood = find (x < plotOPTS.range_lon(2) & x > plotOPTS.range_lon(1) &... +0071 y < plotOPTS.range_lat(2) & y > plotOPTS.range_lat(1)); +0072 % decimate positions. Plot every plotOPTS.data_dec position. +0073 igood=igood(1:plotOPTS.data_dec:end); +0074 %------------------------------------------------------------------------ +0075 % Select how many layers to plot +0076 %------------------------------------------------------------------------ +0077 if isfield(plotOPTS,'nz_plot_vec') +0078 nLayers=size(plotOPTS.nz_plot_vec,2); +0079 nLayersRange=plotOPTS.nz_plot_vec; +0080 else +0081 nLayers=size(plotOPTS.nz_plot,2); +0082 nLayersRange=plotOPTS.nz_plot; +0083 end +0084 % choose colors for vectors +0085 if nLayers==1 +0086 colourSpec=[0 0 0]; +0087 else +0088 colourSpec=colormap(hsv(nLayers)); +0089 end +0090 +0091 % Preallocate outputs +0092 u=nan(size(igood,1),nLayers,length(plotOPTS.Time_record)); +0093 v=nan(size(igood,1),nLayers,length(plotOPTS.Time_record)); +0094 +0095 % Check if we're running +0096 for aa=1:length(plotOPTS.Time_record) +0097 fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record)) +0098 +0099 +0100 % Mesh goes underneath vectors. +0101 if plotOPTS.do_mesh +0102 % plot vertices +0103 [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on'); +0104 Plots(plotOPTS.figure).mesh=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,... +0105 'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on +0106 end +0107 +0108 for ii=1:nLayers +0109 u(:,ii)=squeeze(FVCOM.u(igood,nLayersRange(ii),(aa))); +0110 v(:,ii)=squeeze(FVCOM.v(igood,nLayersRange(ii),(aa))); +0111 end +0112 for jj=1:nLayers +0113 [Plots(plotOPTS.figure).handles(jj),~]=m_vec(plotOPTS.vel_sca,x(igood),y(igood),... +0114 u(:,jj),v(:,jj),colourSpec(jj,:),... +0115 'shaftwidth',1,'headwidth',2); +0116 hold on +0117 end +0118 pause(plotOPTS.pause) +0119 if aa~=length(plotOPTS.Time_record) +0120 delete(Plots(plotOPTS.figure).handles(:)) +0121 end +0122 end +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/find_boundary_elements.html b/doc/utilities/find_boundary_elements.html new file mode 100644 index 0000000000000000000000000000000000000000..8089458129452ba4a188f66e9384dcba4c950ee4 --- /dev/null +++ b/doc/utilities/find_boundary_elements.html @@ -0,0 +1,177 @@ + + + + Description of find_boundary_elements + + + + + + + + + +
    Home > utilities > find_boundary_elements.m
    + + + +

    find_boundary_elements +

    + +

    PURPOSE ^

    +
    Find the elements which fall along the boundary.
    + +

    SYNOPSIS ^

    +
    function Mobj = find_boundary_elements(Mobj)
    + +

    DESCRIPTION ^

    +
     Find the elements which fall along the boundary.
    + 
    + Mobj = find_boundary_elements(Mobj)
    + 
    + DESCRIPTION:
    +   Find the elements which are bounded by the open boundaries described by
    +   the nodes in Mobj.read_obc_nodes.
    + 
    + INPUT:
    +   Mobj - required fields:
    +           - read_obc_nodes
    +           - obc_nodes
    +           - tri
    + 
    + OUTPUT:
    +   Mobj - new field of a cell array read_obc_elements which contains the
    +          IDs of the elements which fall on the model open boundaries and
    +          nObcElements which is the total number of boundary elements
    +          along each boundary.
    + 
    + NOTES:
    +   This will be pretty slow if your unstructured grid has an enormous
    +   number of elements in it (it loops through every element and compares
    +   against the boundary nodes). I'm sure there's a quicker way, so feel
    +   free to have at it.
    + 
    + EXAMPLE USAGE:
    +   Mobj = find_boundary_elements(Mobj)
    + 
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    + 
    + Revision history:
    +   2013-02-26 First version.
    +   2013-02-28 Add new field to the output (total number of boundary
    +   elements as nObcElements).
    + 
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function Mobj = find_boundary_elements(Mobj)
    +0002 % Find the elements which fall along the boundary.
    +0003 %
    +0004 % Mobj = find_boundary_elements(Mobj)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Find the elements which are bounded by the open boundaries described by
    +0008 %   the nodes in Mobj.read_obc_nodes.
    +0009 %
    +0010 % INPUT:
    +0011 %   Mobj - required fields:
    +0012 %           - read_obc_nodes
    +0013 %           - obc_nodes
    +0014 %           - tri
    +0015 %
    +0016 % OUTPUT:
    +0017 %   Mobj - new field of a cell array read_obc_elements which contains the
    +0018 %          IDs of the elements which fall on the model open boundaries and
    +0019 %          nObcElements which is the total number of boundary elements
    +0020 %          along each boundary.
    +0021 %
    +0022 % NOTES:
    +0023 %   This will be pretty slow if your unstructured grid has an enormous
    +0024 %   number of elements in it (it loops through every element and compares
    +0025 %   against the boundary nodes). I'm sure there's a quicker way, so feel
    +0026 %   free to have at it.
    +0027 %
    +0028 % EXAMPLE USAGE:
    +0029 %   Mobj = find_boundary_elements(Mobj)
    +0030 %
    +0031 % Author(s):
    +0032 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0033 %
    +0034 % Revision history:
    +0035 %   2013-02-26 First version.
    +0036 %   2013-02-28 Add new field to the output (total number of boundary
    +0037 %   elements as nObcElements).
    +0038 %
    +0039 %==========================================================================
    +0040 
    +0041 subname = 'find_boundary_elements';
    +0042 
    +0043 global ftbverbose
    +0044 if ftbverbose
    +0045     fprintf('\n')
    +0046     fprintf('begin : %s\n', subname)
    +0047 end
    +0048 
    +0049 ne = length(Mobj.tri); % number of elements
    +0050 nb = length(Mobj.read_obc_nodes); % number of boundaries
    +0051 
    +0052 obc_elems = cell(nb, 1);
    +0053 nObcElements = nan(nb, 1);
    +0054 
    +0055 for i = 1:nb
    +0056 
    +0057     % Do the current boundary's nodes
    +0058     nodeIDs = Mobj.obc_nodes(i, Mobj.obc_nodes(i, :) ~= 0);
    +0059 
    +0060     f = 0;
    +0061     
    +0062     for ttt = 1:ne
    +0063         tri = Mobj.tri(ttt, :);
    +0064         C = intersect(tri, nodeIDs);
    +0065         % Only those with a face along the boundary count (i.e. two nodes
    +0066         % on the boundary), particularly for the mean flow.
    +0067         if numel(C) == 2
    +0068             f = f + 1; % increment the found counter
    +0069             obc_elems{i}(f) = ttt;
    +0070             if ftbverbose
    +0071                 fprintf('Found boundary element ID %i\n', ttt)
    +0072             end
    +0073         end
    +0074     end
    +0075     nObcElements(i) = numel(obc_elems{i}(:));
    +0076 end
    +0077 
    +0078 Mobj.read_obc_elements = obc_elems;
    +0079 Mobj.nObcElements = nObcElements;
    +0080 
    +0081 % Check it's worked for the first model boundary.
    +0082 % xc = nodes2elems(Mobj.x, Mobj);
    +0083 % yc = nodes2elems(Mobj.y, Mobj);
    +0084 % figure(1)
    +0085 % clf
    +0086 % plot(Mobj.x, Mobj.y, 'r.', xc, yc, 'ko')
    +0087 % hold on
    +0088 % plot(xc(Mobj.read_obc_elements{1}), yc(Mobj.read_obc_elements{1}), 'gx')
    +0089 % axis('equal', 'tight')
    +0090 
    +0091 if ftbverbose
    +0092     fprintf('end   : %s \n', subname)
    +0093 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/utilities/fix_inside_boundary.html b/doc/utilities/fix_inside_boundary.html new file mode 100644 index 0000000000000000000000000000000000000000..5f3e35b242f09ed7c17c361fb0cdce9eb8225d64 --- /dev/null +++ b/doc/utilities/fix_inside_boundary.html @@ -0,0 +1,302 @@ + + + + Description of fix_inside_boundary + + + + + + + + + +
    Home > utilities > fix_inside_boundary.m
    + + + +

    fix_inside_boundary +

    + +

    PURPOSE ^

    +
    Fix unstructured grid points inside the given boundary.
    + +

    SYNOPSIS ^

    +
    function [adjx, adjy] = fix_inside_boundary(x, y, node_ids, ang_thresh)
    + +

    DESCRIPTION ^

    +
     Fix unstructured grid points inside the given boundary.
    +
    + [adjx, adjy] = fix_inside_boundary(x, y, node_ids, ang_thresh)
    + 
    + DESCRIPTION:
    +   Find the coordinates of points which are normal to the open boundary
    +   described by the coordinates (x(node_ids), y(node_ids)). The distance
    +   from the boundary is determined from the mean of the length of the two
    +   adjacent boundary element lengths. Once the 'ideal' position has been
    +   identified, find the closest existing nodal position and change it to
    +   the 'ideal' position.
    +
    +   The resulting x2 and y2 coordinates can be exported to 2dm to be
    +   checked in SMS for mesh quality with the fvcom-toolbox function
    +   write_SMS_2dm.
    +
    + INPUT:
    +   x, y - Unstructured grid coordinates.
    +   node_ids - List of IDs of the nodes within the grid which are on the
    +              open boundary of interest.
    +   ang_thresh - [optional] Specify a minimum angle in degrees between the
    +                two adjacent nodal positions to deal with corners better.
    +
    + OUTPUT:
    +   adjx, adjy - New unstructured grid coordinate pairs in which the points
    +                just inside the open boundary have been adjusted so as to
    +                bisect the angle formed by the two adjacent boundary
    +                faces.
    +
    + EXAMPLE USAGE:
    +   [adjx, adjy] = fix_inside_boundary(Mobj.x, Mobj.y, Mobj.read_obc_nodes{1}, 90)
    +
    + NOTES:
    +   This works best with cartesian coordinates but will work with spherical
    +   too, although the angles for large elements will be incorrect.
    +   Secondly, this will sometimes place put points outside the model domain
    +   (though I'm not yet sure why). The net result is that you have to
    +   re-edit the grid SMS by deleting that particular node and recreating
    +   the triangulation manually.
    +
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2013-03-11 First version.
    +   2013-03-19 Add optional minimum angle support.
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function [adjx, adjy] = fix_inside_boundary(x, y, node_ids, ang_thresh)
    +0002 % Fix unstructured grid points inside the given boundary.
    +0003 %
    +0004 % [adjx, adjy] = fix_inside_boundary(x, y, node_ids, ang_thresh)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Find the coordinates of points which are normal to the open boundary
    +0008 %   described by the coordinates (x(node_ids), y(node_ids)). The distance
    +0009 %   from the boundary is determined from the mean of the length of the two
    +0010 %   adjacent boundary element lengths. Once the 'ideal' position has been
    +0011 %   identified, find the closest existing nodal position and change it to
    +0012 %   the 'ideal' position.
    +0013 %
    +0014 %   The resulting x2 and y2 coordinates can be exported to 2dm to be
    +0015 %   checked in SMS for mesh quality with the fvcom-toolbox function
    +0016 %   write_SMS_2dm.
    +0017 %
    +0018 % INPUT:
    +0019 %   x, y - Unstructured grid coordinates.
    +0020 %   node_ids - List of IDs of the nodes within the grid which are on the
    +0021 %              open boundary of interest.
    +0022 %   ang_thresh - [optional] Specify a minimum angle in degrees between the
    +0023 %                two adjacent nodal positions to deal with corners better.
    +0024 %
    +0025 % OUTPUT:
    +0026 %   adjx, adjy - New unstructured grid coordinate pairs in which the points
    +0027 %                just inside the open boundary have been adjusted so as to
    +0028 %                bisect the angle formed by the two adjacent boundary
    +0029 %                faces.
    +0030 %
    +0031 % EXAMPLE USAGE:
    +0032 %   [adjx, adjy] = fix_inside_boundary(Mobj.x, Mobj.y, Mobj.read_obc_nodes{1}, 90)
    +0033 %
    +0034 % NOTES:
    +0035 %   This works best with cartesian coordinates but will work with spherical
    +0036 %   too, although the angles for large elements will be incorrect.
    +0037 %   Secondly, this will sometimes place put points outside the model domain
    +0038 %   (though I'm not yet sure why). The net result is that you have to
    +0039 %   re-edit the grid SMS by deleting that particular node and recreating
    +0040 %   the triangulation manually.
    +0041 %
    +0042 % Author(s):
    +0043 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0044 %
    +0045 % Revision history:
    +0046 %   2013-03-11 First version.
    +0047 %   2013-03-19 Add optional minimum angle support.
    +0048 %
    +0049 %==========================================================================
    +0050 
    +0051 subname = 'fix_inside_boundary';
    +0052 
    +0053 global ftbverbose
    +0054 if ftbverbose
    +0055     fprintf('\n'); fprintf(['begin : ' subname '\n']);
    +0056 end
    +0057 
    +0058 % Check the inputs
    +0059 if length(x) ~= length(y)
    +0060     error('Size of inputs (x, y) do not match.')
    +0061 else
    +0062     % Set the number of points in the boundary
    +0063     np = length(x(node_ids));
    +0064 end
    +0065 
    +0066 if nargin == 4
    +0067     minAng = true;
    +0068 else
    +0069     minAng = false;
    +0070 end
    +0071 
    +0072 normx = nan(np, 1);
    +0073 normy = nan(np, 1);
    +0074 
    +0075 % Order the boundary points in clockwise order.
    +0076 [boundx, boundy] = poly2cw(x(node_ids), y(node_ids));
    +0077 
    +0078 % Create an array for the list of indices which have been moved which are
    +0079 % adjacent to the open boundary.
    +0080 seen = nan(np, 1);
    +0081 
    +0082 % Create the output arrays from the input data. These values will be
    +0083 % adjusted for the nodes adjacent to the open boundary defined by node_ids.
    +0084 adjx = x;
    +0085 adjy = y;
    +0086 
    +0087 for pp = 1:np
    +0088     % For each node, find the two closest nodes to it and use those as the
    +0089     % adjacent vectors. Doing this is slower than just assuming the nodes
    +0090     % are provided in a sorted order, but means we don't have to worry too
    +0091     % much about any irregularities from the sorting above (poly2cw).
    +0092     [~, idx] = sort(sqrt((boundx(pp) - boundx).^2 + (boundy(pp) - boundy).^2));
    +0093     
    +0094     % Get the coordinates of the two nearest points (skip the first closest
    +0095     % because that's the current point).
    +0096     [px1, py1] = deal(boundx(idx(2)), boundy(idx(2)));
    +0097     [px2, py2] = deal(boundx(idx(3)), boundy(idx(3)));
    +0098     
    +0099     % Find the length of the edges of the triangle formed from the three
    +0100     % points we're currently considering. 1 and 2 are those adjacent and 3
    +0101     % is the remaining side.
    +0102     ln1 = sqrt((boundx(pp) - px1)^2 + (boundy(pp) - py1)^2);
    +0103     ln2 = sqrt((boundx(pp) - px2)^2 + (boundy(pp) - py2)^2);
    +0104     ln3 = sqrt((px1 - px2)^2 + (py1 - py2)^2);
    +0105     
    +0106     % Find the angle between the two element edges and the current node
    +0107     % (cosine rule). Use the real component only for cases where the three
    +0108     % points lie on a straight line (in which case the angle should be
    +0109     % 180 degrees).
    +0110     ang1 = real(acosd((ln1^2 + ln2^2 - ln3^2) / (2 * ln1 * ln2)));
    +0111     ang1b = ang1 / 2; % bisect the angle
    +0112 
    +0113     % Check if we've been given a threshold minimum angle and skip this
    +0114     % open boundary point if we have.
    +0115     if minAng
    +0116         if ang1 < ang_thresh
    +0117             continue
    +0118         end
    +0119     end
    +0120 
    +0121     % Find the angle to the horizontal for the current node and one of the
    +0122     % other points.
    +0123     ang2 = atan2((py1 - boundy(pp)), (px1 - boundx(pp))) * (180 / pi);
    +0124     
    +0125     % Find the difference between the two.
    +0126     ang3 = ang2 - ang1b;
    +0127     
    +0128     % Now get the mean length of the two closest element edges and use that
    +0129     % to create the new point inside the boundary. Scale it to 90% of the
    +0130     % value to make a cleaner transition when we're shifting points below.
    +0131     ml = 0.9 * mean([ln1, ln2]);
    +0132     dy = ml * sind(ang3);
    +0133     dx = ml * cosd(ang3);
    +0134 
    +0135     % Add the offsets to the current node to get the new node's position.
    +0136     [xx(1), yy(1)] = deal(boundx(pp) + dx, boundy(pp) + dy);
    +0137     [xx(2), yy(2)] = deal(boundx(pp) - dx, boundy(pp) - dy);
    +0138 
    +0139     % Check which of the two sets above is inside the polygon defined by
    +0140     % the open boundary.
    +0141     if inpolygon(xx(1), yy(1), boundx, boundy) == 1
    +0142         [normx(pp, 1), normy(pp, 1)] = deal(xx(1), yy(1));
    +0143     elseif inpolygon(xx(2), yy(2), boundx, boundy) == 1
    +0144         [normx(pp, 1), normy(pp, 1)] = deal(xx(2), yy(2));
    +0145     else
    +0146         warning('Both versions of the calculated point are outside the model domain. Skipping.')
    +0147         continue
    +0148     end
    +0149         
    +0150     % OK, so now we have a new point approximately orthogonal to the
    +0151     % current node, we can use its position to find the nearest existing
    +0152     % node inside the domain and replace its coordinates with the new
    +0153     % node's.
    +0154     [~, idx2] = sort(sqrt((normx(pp, 1) - x).^2 + (normy(pp, 1) - y).^2));
    +0155     
    +0156     % We need to check we haven't seen this node before (in 'seen') and
    +0157     % also that it's not an open boundary point.
    +0158     c = 1;
    +0159     while true
    +0160         if ismember(idx2(c), node_ids) || ismember(idx2(c), seen)
    +0161             % Keep going until we find one that's not been used before.
    +0162             c = c + 1;
    +0163         else
    +0164             break
    +0165         end
    +0166     end
    +0167     % Append to the list of coordinates we've seen so we don't move the
    +0168     % same node twice.
    +0169     seen(pp) = idx2(c);
    +0170 
    +0171     % Replace the coordinates.
    +0172     adjx(idx2(c)) = normx(pp, 1);
    +0173     adjy(idx2(c)) = normy(pp, 1);
    +0174 
    +0175 end
    +0176 
    +0177 if ftbverbose
    +0178     fprintf('end   : %s\n', subname)
    +0179 end
    +0180 
    +0181 % Do a figure to see the effect
    +0182 % close all
    +0183 % h = figure(1);
    +0184 %
    +0185 % % Original node positions
    +0186 % plot(x, y, 'o', 'MarkerEdgeColor', [0.9, 0.1, 0.1], ...
    +0187 %     'MarkerFaceColor', [1, 0.1, 0.1])
    +0188 % hold on
    +0189 % axis('equal', 'tight')
    +0190 % % Adjusted node positions
    +0191 % plot(adjx, adjy, 'o', 'MarkerEdgeColor', [0.1, 0.1, 0.8], ...
    +0192 %     'MarkerFaceColor', [0.1, 0.1, 0.9])
    +0193 %
    +0194 % % Original triangulation
    +0195 % patch('Vertices', [x, y], 'Faces', Mobj.tri, 'CData', [], ...
    +0196 % 'edgecolor', [0.9, 0.1, 0.1], 'FaceColor', 'w', 'LineWidth', 1);
    +0197 % % New triangulation
    +0198 % patch('Vertices', [adjx, adjy], 'Faces', Mobj.tri, 'CData', [], ...
    +0199 % 'edgecolor', [0.1, 0.1, 0.8], 'FaceColor', 'w', 'LineWidth', 1);
    +0200 %
    +0201 % % Open boundary nodes
    +0202 % % plot(x(node_ids), y(node_ids), 'ko', 'MarkerFaceColor', 'k')
    +0203 %
    +0204 % legend('Original nodes', 'Adjusted nodes')
    +0205 % legend('BoxOff')
    +0206 %
    +0207 % xlabel('Eastings')
    +0208 % ylabel('Northings')
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/utilities/graph.dot b/doc/utilities/graph.dot new file mode 100644 index 0000000000000000000000000000000000000000..bd080b0ac52dfb1d3d98cfc5fd3ec3b39514ecd2 --- /dev/null +++ b/doc/utilities/graph.dot @@ -0,0 +1,116 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ST_Dstar -> SW_Density; + ST_Dstar -> SW_Kviscosity; + ST_erate -> ST_wset; + ST_example -> ST_Dstar; + ST_example -> ST_erate; + ST_example -> ST_phi2d; + ST_example -> ST_taucr; + ST_example -> ST_wentworth; + ST_example -> ST_wset; + ST_summary -> ST_Dstar; + ST_summary -> ST_d2phi; + ST_summary -> ST_erate; + ST_summary -> ST_taucr; + ST_summary -> ST_wentworth; + ST_summary -> ST_wset; + ST_taucr -> ST_Dstar; + ST_taucr -> SW_Density; + ST_wset -> ST_Dstar; + ST_wset -> SW_Density; + ST_wset -> SW_Kviscosity; + SW_Kviscosity -> SW_Density; + SW_Kviscosity -> SW_Viscosity; + calc_tauw -> SW_Density; + calc_tauw -> SW_Kviscosity; + check_wset -> SW_Density; + check_wset -> SW_Kviscosity; + do_residual_plot -> do_residual; + do_residual_plot -> m_ll2ll; + do_transect_plot -> m_ll2ll; + do_vector_plot -> m_ll2ll; + do_volume_change -> get_runs; + ginput2 -> ginput2; + greg2mjulian -> greg2julian; + inkmlbb -> inbox; + inkmlbb -> isintriangle; + inkmlbb -> read_kml; + inkmlbb -> tri_from_bndry; + mjulian2greg -> julian2greg; + show_sigma -> sigma_gen; + transect_nodes_screen -> ginput2; + + ST_Dstar [URL="ST_Dstar.html"]; + ST_d2phi [URL="ST_d2phi.html"]; + ST_erate [URL="ST_erate.html"]; + ST_example [URL="ST_example.html"]; + ST_phi2d [URL="ST_phi2d.html"]; + ST_summary [URL="ST_summary.html"]; + ST_taucr [URL="ST_taucr.html"]; + ST_wentworth [URL="ST_wentworth.html"]; + ST_wset [URL="ST_wset.html"]; + SW_Density [URL="SW_Density.html"]; + SW_Kviscosity [URL="SW_Kviscosity.html"]; + SW_Viscosity [URL="SW_Viscosity.html"]; + calc_tauw [URL="calc_tauw.html"]; + catstruct [URL="catstruct.html"]; + centroid [URL="centroid.html"]; + check_wset [URL="check_wset.html"]; + connectivity [URL="connectivity.html"]; + deg2utm [URL="deg2utm.html"]; + do_ph_change_plot [URL="do_ph_change_plot.html"]; + do_ph_change_points_plot [URL="do_ph_change_points_plot.html"]; + do_ph_max_change_plot [URL="do_ph_max_change_plot.html"]; + do_ph_vertical_profile [URL="do_ph_vertical_profile.html"]; + do_residual [URL="do_residual.html"]; + do_residual_plot [URL="do_residual_plot.html"]; + do_surface_plot [URL="do_surface_plot.html"]; + do_transect_plot [URL="do_transect_plot.html"]; + do_vector_plot [URL="do_vector_plot.html"]; + do_volume [URL="do_volume.html"]; + do_volume_change [URL="do_volume_change.html"]; + do_volume_change2 [URL="do_volume_change2.html"]; + find_boundary_elements [URL="find_boundary_elements.html"]; + fix_inside_boundary [URL="fix_inside_boundary.html"]; + get_NCEP_year [URL="get_NCEP_year.html"]; + get_runs [URL="get_runs.html"]; + get_runs_test [URL="get_runs_test.html"]; + ginput2 [URL="ginput2.html"]; + greg2julian [URL="greg2julian.html"]; + greg2mjulian [URL="greg2mjulian.html"]; + grid2fvcom [URL="grid2fvcom.html"]; + grid_vert_interp [URL="grid_vert_interp.html"]; + gridvecs [URL="gridvecs.html"]; + inbox [URL="inbox.html"]; + inkmlbb [URL="inkmlbb.html"]; + isintriangle [URL="isintriangle.html"]; + julian2greg [URL="julian2greg.html"]; + lat_to_m [URL="lat_to_m.html"]; + lon_to_m [URL="lon_to_m.html"]; + m_ll2ll [URL="m_ll2ll.html"]; + m_to_lat [URL="m_to_lat.html"]; + m_to_lon [URL="m_to_lon.html"]; + mjul2str [URL="mjul2str.html"]; + mjul2str2 [URL="mjul2str2.html"]; + mjulian2greg [URL="mjulian2greg.html"]; + naut_2_cart [URL="naut_2_cart.html"]; + pl64 [URL="pl64.html"]; + read_fvcom_mesh [URL="read_fvcom_mesh.html"]; + read_kml [URL="read_kml.html"]; + read_netCDF_FVCOM [URL="read_netCDF_FVCOM.html"]; + readdir [URL="readdir.html"]; + runmean [URL="runmean.html"]; + show_sigma [URL="show_sigma.html"]; + sigma_gen [URL="sigma_gen.html"]; + sigma_geo [URL="sigma_geo.html"]; + sigma_tanh [URL="sigma_tanh.html"]; + transect_nodes_screen [URL="transect_nodes_screen.html"]; + tri_from_bndry [URL="tri_from_bndry.html"]; + utm2deg [URL="utm2deg.html"]; + wave_fric [URL="wave_fric.html"]; + wgs2utm [URL="wgs2utm.html"]; + write_SMS_2dm [URL="write_SMS_2dm.html"]; + write_SMS_cst [URL="write_SMS_cst.html"]; + zero_to_nan [URL="zero_to_nan.html"]; +} \ No newline at end of file diff --git a/doc/utilities/graph.html b/doc/utilities/graph.html new file mode 100644 index 0000000000000000000000000000000000000000..48275b275daa5e422473cf03beccedaf513e9c86 --- /dev/null +++ b/doc/utilities/graph.html @@ -0,0 +1,99 @@ + + + + Dependency Graph for utilities + + + + + + + + + + +
    < Master indexIndex for utilities >
    +

    Dependency Graph for utilities

    + +
    +Dependency Graph for utilities + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    Generated on Tue 04-Jun-2013 12:12:56 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/utilities/graph.map b/doc/utilities/graph.map new file mode 100644 index 0000000000000000000000000000000000000000..256bf7a2cc2840636976e18504a375aa94d4554e --- /dev/null +++ b/doc/utilities/graph.map @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/utilities/graph.png b/doc/utilities/graph.png new file mode 100644 index 0000000000000000000000000000000000000000..4f93e39a38f8cd97b62a4f493dcbb62fa9964f53 Binary files /dev/null and b/doc/utilities/graph.png differ diff --git a/doc/utilities/grid2fvcom.html b/doc/utilities/grid2fvcom.html new file mode 100644 index 0000000000000000000000000000000000000000..3ce5d1f63ea195866615c00b464aaeeb096ceb40 --- /dev/null +++ b/doc/utilities/grid2fvcom.html @@ -0,0 +1,315 @@ + + + + Description of grid2fvcom + + + + + + + + + +
    Home > utilities > grid2fvcom.m
    + + + +

    grid2fvcom +

    + +

    PURPOSE ^

    +
    Interpolate regularly gridded surface forcing data onto a given FVCOM
    + +

    SYNOPSIS ^

    +
    function fvcom = grid2fvcom(Mobj,vars,data)
    + +

    DESCRIPTION ^

    +
     Interpolate regularly gridded surface forcing data onto a given FVCOM
    + grid.
    +
    + grid2fvcom(Mobj,vars,data)
    +
    + DESCRIPTION:
    +   Takes a given NCEP reanalysis grid file and interpolates the U10 and
    +   V10 values onto the specified FVCOM grid file.
    +
    + INPUT:
    +   Mobj - MATLAB mesh object with the following fields:
    +       x, y, lon, lat - cartesian and spherical node coordinates. These
    +       are transferred to the NetCDF file only and are not used in the
    +       interpolation at all.
    +       nVerts - number of vertices (nodes) in the unstructured grid.
    +       nElems - number of elements in the unstructured grid.
    +   vars - a cell array of the variable names to be interpolated on the
    +       FVCOM grid in Mobj (e.g. uwnd, U10, vwnd, V10 etc.).
    +   data - a struct which contains the following arrays:
    +       x - x data (probably best in cartesian for the interpolation)
    +       y - y data (probably best in cartesian for the interpolation)
    +       The struct must also contain all the variables defined in vars.
    +       time - time vector (in Modified Julian Days). If you're using some
    +       of the NCEP surface products (e.g. relative humitidy, sea level
    +       pressure), you need to supply x and y coordinates for their grids
    +       as .xalt and .yalt).
    +
    + OUTPUT:
    +   fvcom - struct of the interpolated data values at the model nodes and
    +       element centres. Also includes any variables which were in the
    +       input struct but which have not been interpolated (e.g. time).
    +
    + EXAMPLE USAGE:
    +   interpfields = {'uwnd', 'vwnd', 'slp', 'nshf', 'nlwrs', 'nswrs', ...
    +       'P_E', 'Et', 'time', 'lon', 'lat', 'x', 'y'};
    +   forcing_interp = grid2fvcom(Mobj, interpfields, forcing);
    +
    + NOTE:
    +   The shape of the returned arrays for rhum and slp (via
    +   get_NCEP_forcing.m) have sometimes differed from the other vairables
    +   (they appear to be projected onto a different grid). Unless you
    +   desperately need them, I would suggest omitting them from the
    +   interpolation here as this assumes the arrays are all the same size.
    +   Alternatively, give data.xalt and data.yalt to specify the alternative
    +   grid.
    +
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history:
    +   2012-10-15 First version based on ncep2fvcom_U10V10.m in the
    +   fvcom-toolbox.
    +   2012-10-16 Removed the code to read the NCEP file. Instead, farmed that
    +   out to a new function (read_NCEP_wind) so that the relevant section can
    +   be more readily extracted (rather than using the entire globe's data:
    +   it's easier to subsample and provide the subsampled data here).
    +   2012-10-17 Add outputs to the function for use in visualisation.
    +   2012-10-19 Add wind struct as input rather than separate u, v, time and
    +   lat/long arrays. Makes invocation a bit cleaner.
    +   2012-11-01 Farmed out the creation of the NetCDF file to
    +   write_FVCOM_forcing.m and made this purely an interpolation script.
    +   2013-02-14 Add support for interpolating data on two different grids
    +   through the .xalt and .yalt fields in the input data structure. This is
    +   handy if you've got data from NCEP from both the Surface and Gaussian
    +   products, each of which are on different grids.
    +   2013-05-16 Add parallel for loops if the Parallel Computing Toolbox is
    +   available (MATLAB parfor loops fail gracefully to for loops if it is
    +   not available, in which case no harm, no foul).
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function fvcom = grid2fvcom(Mobj,vars,data)
    +0002 % Interpolate regularly gridded surface forcing data onto a given FVCOM
    +0003 % grid.
    +0004 %
    +0005 % grid2fvcom(Mobj,vars,data)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %   Takes a given NCEP reanalysis grid file and interpolates the U10 and
    +0009 %   V10 values onto the specified FVCOM grid file.
    +0010 %
    +0011 % INPUT:
    +0012 %   Mobj - MATLAB mesh object with the following fields:
    +0013 %       x, y, lon, lat - cartesian and spherical node coordinates. These
    +0014 %       are transferred to the NetCDF file only and are not used in the
    +0015 %       interpolation at all.
    +0016 %       nVerts - number of vertices (nodes) in the unstructured grid.
    +0017 %       nElems - number of elements in the unstructured grid.
    +0018 %   vars - a cell array of the variable names to be interpolated on the
    +0019 %       FVCOM grid in Mobj (e.g. uwnd, U10, vwnd, V10 etc.).
    +0020 %   data - a struct which contains the following arrays:
    +0021 %       x - x data (probably best in cartesian for the interpolation)
    +0022 %       y - y data (probably best in cartesian for the interpolation)
    +0023 %       The struct must also contain all the variables defined in vars.
    +0024 %       time - time vector (in Modified Julian Days). If you're using some
    +0025 %       of the NCEP surface products (e.g. relative humitidy, sea level
    +0026 %       pressure), you need to supply x and y coordinates for their grids
    +0027 %       as .xalt and .yalt).
    +0028 %
    +0029 % OUTPUT:
    +0030 %   fvcom - struct of the interpolated data values at the model nodes and
    +0031 %       element centres. Also includes any variables which were in the
    +0032 %       input struct but which have not been interpolated (e.g. time).
    +0033 %
    +0034 % EXAMPLE USAGE:
    +0035 %   interpfields = {'uwnd', 'vwnd', 'slp', 'nshf', 'nlwrs', 'nswrs', ...
    +0036 %       'P_E', 'Et', 'time', 'lon', 'lat', 'x', 'y'};
    +0037 %   forcing_interp = grid2fvcom(Mobj, interpfields, forcing);
    +0038 %
    +0039 % NOTE:
    +0040 %   The shape of the returned arrays for rhum and slp (via
    +0041 %   get_NCEP_forcing.m) have sometimes differed from the other vairables
    +0042 %   (they appear to be projected onto a different grid). Unless you
    +0043 %   desperately need them, I would suggest omitting them from the
    +0044 %   interpolation here as this assumes the arrays are all the same size.
    +0045 %   Alternatively, give data.xalt and data.yalt to specify the alternative
    +0046 %   grid.
    +0047 %
    +0048 % Author(s):
    +0049 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0050 %
    +0051 % Revision history:
    +0052 %   2012-10-15 First version based on ncep2fvcom_U10V10.m in the
    +0053 %   fvcom-toolbox.
    +0054 %   2012-10-16 Removed the code to read the NCEP file. Instead, farmed that
    +0055 %   out to a new function (read_NCEP_wind) so that the relevant section can
    +0056 %   be more readily extracted (rather than using the entire globe's data:
    +0057 %   it's easier to subsample and provide the subsampled data here).
    +0058 %   2012-10-17 Add outputs to the function for use in visualisation.
    +0059 %   2012-10-19 Add wind struct as input rather than separate u, v, time and
    +0060 %   lat/long arrays. Makes invocation a bit cleaner.
    +0061 %   2012-11-01 Farmed out the creation of the NetCDF file to
    +0062 %   write_FVCOM_forcing.m and made this purely an interpolation script.
    +0063 %   2013-02-14 Add support for interpolating data on two different grids
    +0064 %   through the .xalt and .yalt fields in the input data structure. This is
    +0065 %   handy if you've got data from NCEP from both the Surface and Gaussian
    +0066 %   products, each of which are on different grids.
    +0067 %   2013-05-16 Add parallel for loops if the Parallel Computing Toolbox is
    +0068 %   available (MATLAB parfor loops fail gracefully to for loops if it is
    +0069 %   not available, in which case no harm, no foul).
    +0070 %
    +0071 %==========================================================================
    +0072 
    +0073 if nargin ~= 3
    +0074     error('Incorrect number of arguments')
    +0075 end
    +0076 
    +0077 subname = 'grid2fvcom';
    +0078 
    +0079 global ftbverbose;
    +0080 if ftbverbose
    +0081     fprintf('\nbegin : %s \n', subname)
    +0082 end
    +0083 
    +0084 % Run jobs on multiple workers if we have that functionality. Not sure if
    +0085 % it's necessary, but check we have the Parallel Toolbox first.
    +0086 wasOpened = false;
    +0087 if license('test', 'Distrib_Computing_Toolbox')
    +0088     % We have the Parallel Computing Toolbox, so launch a bunch of workers.
    +0089     if matlabpool('size') == 0
    +0090         % Force pool to be local in case we have remote pools available.
    +0091         matlabpool open local
    +0092         wasOpened = true;
    +0093     end
    +0094 end
    +0095 
    +0096 %--------------------------------------------------------------------------
    +0097 % Get the relevant bits from the FVCOM mesh object
    +0098 %--------------------------------------------------------------------------
    +0099 x = Mobj.x;
    +0100 y = Mobj.y;
    +0101 nVerts = Mobj.nVerts;
    +0102 nElems = Mobj.nElems;
    +0103 if ftbverbose
    +0104     fprintf('info for FVCOM domain\n');
    +0105     fprintf('number of nodes: %d\n', nVerts);
    +0106     fprintf('number of elems: %d\n', nElems);
    +0107 end
    +0108 
    +0109 xc = nodes2elems(x, Mobj);
    +0110 yc = nodes2elems(y, Mobj);
    +0111 
    +0112 try
    +0113     ntimes = numel(data.time);
    +0114 catch
    +0115     ntimes = numel(data.(vars{1}).time);
    +0116 end
    +0117 
    +0118 % Interpolate supplied regularly gridded data to FVCOM mesh. Use
    +0119 % TriScatteredInterp to do the interpolation instead of griddata (should be
    +0120 % faster).
    +0121 for vv = 1:length(vars)
    +0122     if strcmpi(vars{vv}, 'time')
    +0123         fprintf('transferring variable %s as is\n', vars{vv})
    +0124         fvcom.(vars{vv}) = data.(vars{vv});
    +0125         continue
    +0126     elseif strcmpi(vars{vv}, 'lat') || strcmpi(vars{vv}, 'lon') || strcmpi(vars{vv}, 'x') || strcmpi(vars{vv}, 'y')
    +0127         fprintf('reassigning variable %s from unstructured grid\n', vars{vv})
    +0128         fvcom.(vars{vv}) = Mobj.(vars{vv});
    +0129     else
    +0130         % Preallocate the output arrays.
    +0131         % Serial version:
    +0132         % fvcom.(vars{vv}).data = zeros(nElems, ntimes);
    +0133         % fvcom.(vars{vv}).node = zeros(nVerts, ntimes);
    +0134         % Also create temporary arrays for the inner loop to be
    +0135         % parallelisable (is that a word?):
    +0136         tmp_fvcom_data = zeros(nElems, ntimes);
    +0137         tmp_fvcom_node = zeros(nVerts, ntimes);
    +0138         tmp_data_data = data.(vars{vv}).data; % input to the interpolation
    +0139 
    +0140         % Use a parallel loop for the number of time steps we're
    +0141         % interpolating (should be quicker, but will use more memory...).
    +0142         parfor i = 1:ntimes
    +0143             fprintf('interpolating %s, frame %d of %d\n', vars{vv}, i, ntimes);
    +0144 
    +0145             % Serial version:
    +0146             % currvar = data.(vars{vv}).data(:, :, i);
    +0147             % Parallel version:
    +0148             currvar = tmp_data_data(:, :, i);
    +0149 
    +0150             % griddata way (cubic interpolation)
    +0151             %fvcom.(vars{vv}).node(:,i) = griddata(wind.x,wind.y,currvar,x,y,'cubic');
    +0152             %fvcom.(vars{vv}).data(:,i) = griddata(wind.x,wind.y,currvar,xc,yc,'cubic');
    +0153 
    +0154             % TriScatteredInterp way (with natural neighbour interpolation)
    +0155             % Use a try/catch to account for the different grids over which
    +0156             % the humidity and sealevel pressure data are sampled.
    +0157             try
    +0158                 ftsin = TriScatteredInterp(data.x(:), data.y(:), currvar(:), 'natural');
    +0159             catch err
    +0160                 warning([err.identifier, ': Some NCEP data are projected' ...
    +0161                     ' onto a different grid. Check you have specified' ...
    +0162                     ' data.xalt and data.yalt arrays which are on the' ...
    +0163                     ' same grid as the data to be interpolated.'])
    +0164                 ftsin = TriScatteredInterp(data.xalt(:), data.yalt(:), currvar(:), 'natural');
    +0165             end
    +0166             % Serial version:
    +0167             % fvcom.(vars{vv}).node(:,i) = ftsin(x,y);
    +0168             % fvcom.(vars{vv}).data(:,i) = ftsin(xc,yc);
    +0169             % nnans(1) = sum(isnan(fvcom.(vars{vv}).node(:,i)));
    +0170             % nnans(2) = sum(isnan(fvcom.(vars{vv}).data(:,i)));
    +0171             % Parallel version:
    +0172             tmp_fvcom_node(:, i) = ftsin(x,y);
    +0173             tmp_fvcom_data(:, i) = ftsin(xc,yc);
    +0174             nnans1 = sum(isnan(tmp_fvcom_node(:, i)));
    +0175             nnans2 = sum(isnan(tmp_fvcom_data(:, i)));
    +0176             if  nnans1 > 0
    +0177                 warning('%i NaNs in the interpolated node data. This won''t work with FVCOM.', nnans1)
    +0178             end
    +0179             if nnans2 > 0
    +0180                 warning('%i NaNs in the interpolated element data. This won''t work with FVCOM.', nnans2)
    +0181             end
    +0182         end
    +0183         % Transfer the temporary arrays back to the relevant struct and
    +0184         % clear out the temporary arrays.
    +0185         fvcom.(vars{vv}).node = tmp_fvcom_node;
    +0186         fvcom.(vars{vv}).data = tmp_fvcom_data;
    +0187         clear nnans* tmp_*
    +0188 
    +0189         fprintf('interpolation of %s complete\n', vars{vv});
    +0190     end
    +0191 end
    +0192 
    +0193 if wasOpened
    +0194     matlabpool close
    +0195 end
    +0196 
    +0197 if ftbverbose
    +0198     fprintf('end   : %s \n', subname)
    +0199 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/utilities/grid_vert_interp.html b/doc/utilities/grid_vert_interp.html new file mode 100644 index 0000000000000000000000000000000000000000..c2e7fe64021e4eded37a99d998a564da72c83d69 --- /dev/null +++ b/doc/utilities/grid_vert_interp.html @@ -0,0 +1,228 @@ + + + + Description of grid_vert_interp + + + + + + + + + +
    Home > utilities > grid_vert_interp.m
    + + + +

    grid_vert_interp +

    + +

    PURPOSE ^

    +
    Child function to interpolate a given 3D array (x by y by sigma) values
    + +

    SYNOPSIS ^

    +
    function dataz = grid_vert_interp(Mobj, lon, lat, data, depth, mask)
    + +

    DESCRIPTION ^

    +
     Child function to interpolate a given 3D array (x by y by sigma) values
    + to the unstructured grid vertical layers.
    +
    + function grid_vert_interp(Mobj, lon, lat, data, depth, mask)
    +
    + DESCRIPTION:
    +    Interpolate the regularly gridded data described by lon, lat, data
    +    (whose size should be x by y for the lon and lat arrays, and x by y by
    +    z for the data array) to the unstructured grid vertical layers defined
    +    in Mobj.siglayz. The depths in depth are used to make sure the profile
    +    is interpolated the right way up. The closest unstructured grid node
    +    is used for the vertical interpolation of each regularly gridded node.
    +
    + INPUT:
    +   Mobj        = MATLAB mesh structure which must contain:
    +                   - Mobj.siglayz - sigma layer depths for all model
    +                   nodes.
    +                   - Mobj.lon, Mobj.lat - node coordinates (long/lat).
    +   lon, lat    = Rectangular arrays of longitude and latitude (see
    +   meshgrid).
    +   data, depth = x by y by z (where z is vertical layers) grids of the
    +   data and water depths to be interpolated onto the vertical grid defined
    +   by Mobj.siglayz.
    +   mesh        = logical array of positions outside the regularly gridded
    +   domain (e.g. if the regular data contains NaNs or other undefined
    +   values, create a logical array of those positions so they can be
    +   omitted quickly).
    +   
    + OUTPUT:
    +   x by y by z array of vertically interpolated values at each regular
    +   grid location.
    +
    + EXAMPLE USAGE
    +   grid_vert_interp(Mobj, lon, lat, data, depth, mask)
    + 
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +   2013-02-08 First version.
    +   2013-05-16 Add support for parallel for-loops (not mandatory, but
    +   enabled if the Parallel Computing Toolbox is available).
    +
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function dataz = grid_vert_interp(Mobj, lon, lat, data, depth, mask)
    +0002 % Child function to interpolate a given 3D array (x by y by sigma) values
    +0003 % to the unstructured grid vertical layers.
    +0004 %
    +0005 % function grid_vert_interp(Mobj, lon, lat, data, depth, mask)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %    Interpolate the regularly gridded data described by lon, lat, data
    +0009 %    (whose size should be x by y for the lon and lat arrays, and x by y by
    +0010 %    z for the data array) to the unstructured grid vertical layers defined
    +0011 %    in Mobj.siglayz. The depths in depth are used to make sure the profile
    +0012 %    is interpolated the right way up. The closest unstructured grid node
    +0013 %    is used for the vertical interpolation of each regularly gridded node.
    +0014 %
    +0015 % INPUT:
    +0016 %   Mobj        = MATLAB mesh structure which must contain:
    +0017 %                   - Mobj.siglayz - sigma layer depths for all model
    +0018 %                   nodes.
    +0019 %                   - Mobj.lon, Mobj.lat - node coordinates (long/lat).
    +0020 %   lon, lat    = Rectangular arrays of longitude and latitude (see
    +0021 %   meshgrid).
    +0022 %   data, depth = x by y by z (where z is vertical layers) grids of the
    +0023 %   data and water depths to be interpolated onto the vertical grid defined
    +0024 %   by Mobj.siglayz.
    +0025 %   mesh        = logical array of positions outside the regularly gridded
    +0026 %   domain (e.g. if the regular data contains NaNs or other undefined
    +0027 %   values, create a logical array of those positions so they can be
    +0028 %   omitted quickly).
    +0029 %
    +0030 % OUTPUT:
    +0031 %   x by y by z array of vertically interpolated values at each regular
    +0032 %   grid location.
    +0033 %
    +0034 % EXAMPLE USAGE
    +0035 %   grid_vert_interp(Mobj, lon, lat, data, depth, mask)
    +0036 %
    +0037 % Author(s):
    +0038 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0039 %
    +0040 % Revision history
    +0041 %   2013-02-08 First version.
    +0042 %   2013-05-16 Add support for parallel for-loops (not mandatory, but
    +0043 %   enabled if the Parallel Computing Toolbox is available).
    +0044 %
    +0045 %==========================================================================
    +0046 
    +0047 subname = 'grid_vert_interp';
    +0048 
    +0049 global ftbverbose
    +0050 if ftbverbose
    +0051     fprintf('\n')
    +0052     fprintf(['begin : ' subname '\n'])
    +0053 end
    +0054 
    +0055 if ~isfield(Mobj, 'siglayz')
    +0056     error('Error: missing required sigma layer depth values for the unstructured grid.')
    +0057 end
    +0058 
    +0059 if ~Mobj.have_lonlat
    +0060     error('Need spherical coordinates')
    +0061 end
    +0062 
    +0063 if sum(size(lon) ~= size(data(:, :, 1))) ~= 0 || sum(size(lat) ~= size(data(:, :, 1))) ~= 0
    +0064     error('Size of the longitude or latitude arrays do not match the supplied data array')
    +0065 end
    +0066 
    +0067 wasOpened = false;
    +0068 if license('test', 'Distrib_Computing_Toolbox')
    +0069     % We have the Parallel Computing Toolbox, so launch a bunch of workers.
    +0070     if matlabpool('size') == 0
    +0071         % Force pool to be local in case we have remote pools available.
    +0072         matlabpool open local
    +0073         wasOpened = true;
    +0074     end
    +0075 end
    +0076 
    +0077 [~, fz] = size(Mobj.siglayz);
    +0078 [nx, ny, ~, ~] = size(data);
    +0079 
    +0080 % Preallocate the output arrays
    +0081 dataz = nan(nx, ny, fz);
    +0082 
    +0083 if ftbverbose
    +0084     tic
    +0085 end
    +0086 
    +0087 parfor xi = 1:nx
    +0088     % Get all the y and z dimension data for the current x position
    +0089     % (temperature, salinity and depth).
    +0090     xdata = squeeze(data(xi, :, :));
    +0091     xdepth = squeeze(depth(xi, :, :));
    +0092     xmask = mask(xi, :);
    +0093     
    +0094     % Preallocate the arrays for the inner loop.
    +0095     ydata = nan(ny, fz);
    +0096     for yi = 1:ny
    +0097         if xmask(yi)
    +0098             continue
    +0099         end
    +0100 
    +0101         % Find the nearest sigma layer z values from the unstructured grid.
    +0102         [md, mi] = min(sqrt((Mobj.lon - lon(xi, yi)).^2 + (Mobj.lat - lat(xi, yi)).^2));
    +0103 
    +0104         % Skip data point if the closest FVCOM node is more than 10 minutes
    +0105         % away.
    +0106         if md > 10 / 60
    +0107 %             if ftbverbose
    +0108 %                 fprintf('%s : skipping %f, %f (more than 10 minutes from the nearest unstructured grid node),\n', subname, lon(yi, xi), lat(yi, xi))
    +0109 %             end
    +0110             continue
    +0111         else
    +0112             % Use the FVCOM node's sigma depths to interpolate this POLCOMS
    +0113             % position's temperature and salinity data.
    +0114             
    +0115             % Get the FVCOM depths closest to this POLCOMS grid position.
    +0116             tfz = Mobj.siglayz(mi, :);
    +0117             % Now get the POLCOMS depths at this node for all the vertical
    +0118             % layers and linearly interpolate through the water column onto
    +0119             % the FVCOM vertical profile.
    +0120             tpz = xdepth(yi, :);
    +0121             ydata(yi, :) = interp1(tpz, xdata(yi, :), tfz, 'linear', 'extrap');
    +0122         end
    +0123     end
    +0124     dataz(xi, :, :) = ydata;
    +0125 end
    +0126 
    +0127 % Close the MATLAB pool if we opened it.
    +0128 if wasOpened
    +0129     matlabpool close
    +0130 end
    +0131 
    +0132 if ftbverbose
    +0133     toc
    +0134 end
    +0135 
    +0136 if ftbverbose
    +0137     fprintf(['end   : ' subname '\n'])
    +0138 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/utilities/index.html b/doc/utilities/index.html index 541fbe1c1285bb2d977a95acb74fd1de736ee7a7..a97b672d0c34d4ac16fc2173d21171cf29006d44 100755 --- a/doc/utilities/index.html +++ b/doc/utilities/index.html @@ -19,11 +19,14 @@

    Matlab files in this directory:

    -
     ST_DstarCalculate non-dimensional grain size D*
     ST_d2phiConvert sediment diameter (m) to phi
     ST_erateCalculate erosion rate in kg/(m^2-s)
     ST_exampleExample usage of Sediment Toolbox
     ST_phi2dConvert sediment grain size from phi to d (m)
     ST_summaryPrint summary for stats of particle diameter d (m)
     ST_taucrCalculate critical shear stress in Pascals
     ST_wentworthReport wentworth class of a particular grain size phi
     ST_wsetCalculate settling velocity of particle diameter d (m) in m/s
     SW_DensitySW_Density Density of sea water
     SW_KviscosityCalculates the kinemtic viscosity [m^2/s] from the dynamic viscosity and
     SW_ViscositySW_Viscosity Dynamic viscosity of seawater
     calc_tauwDESCRIPTION:
     centroidx and y must be non-scalar vectors of equal sizes defining a polygonal
     check_wsetCalculate settling velocity of particle diameter d (m) in m/s
     connectivityCONNECTIVITY: Assemble connectivity data for a triangular mesh.
     deg2utm-------------------------------------------------------------------------
     do_ph_change_plotCalculate the change in the given parameter (plotOPTS.var_plot) and plot
     do_ph_change_points_plotCalculate the change in the given parameter (plotOPTS.var_plot) and plot
     do_ph_max_change_plotCalculate the change in pH and plot accordingly.
     do_ph_vertical_profileFor a supplied transect, plot the vertical profile through the water
     do_residualDO_RESIDUAL Takes the u and v vectors of a model output and calculates
     do_residual_plotTake the output of do_residual and plot as a vector figure. Summarises a
     do_surface_plotreads image and plots tracks or stations
     do_transect_plot
     do_vector_plotPlot vectors of parameters of interest.
     do_volumeCalculate a volume for a given time step above a threshold value.
     do_volume_changeDO_VOLUME_CHANGE Calculate volume of water which experiences a change in
     do_volume_change2Calculate the volume exposed to a given change in pH.
     get_NCEP_yearExtract the year from a give NCEP file name (either 'uwnd.sig995.YYYY.nc'
     get_runsGET_RUNS Finds runs of continuous change in some value beyond some length
     get_runs_testFigure out a way to identify runs longer than some specified length for
     ginput2GINPUT2 Graphical input from mouse with zoom, pan, plot and scaling.
     greg2julianThis function converts the Gregorian dates to Julian dates.
     greg2mjulianmjulianday = greg2mjulian(yyyy,mm,dd,HH,MM,SS)
     gridvecsclear all; close all;
     inboxdetermine if points lie in a box
     inkmlbbfname = 'Wet_Skagit_BB.kml';
     isintriangledetermine if point (x0,y0) is in triangle defined by nodes (xt(3),yt(3))
     julian2gregThis function converts the Julian dates to Gregorian dates.
     lat_to_mdy = lat_to_m(dlat,alat)
     lon_to_mdx = lon_to_m(dlon, alat)
     m_ll2llM_ll2LL Converts LON,LAT to long,lat coordinates using the current projection
     m_to_lat
     m_to_lon
     mjul2strConvert a modified Julian day to a Matlab datestr style string
     mjul2str2Convert a modified Julian day to a Matlab datestr style string
     mjul2str_noyear
     mjulian2gregThis function converts Modified Julian dates to Gregorian dates.
     naut_2_cartconvert wind from nautical (speed,direction) to Cartesian (u,v)
     pl64low pass filter (33 hr)
     read_fvcom_meshRead fvcom mesh file into Matlab mesh object
     read_kmlREAD_KML reads a Google Earth kml file into Matlab
     read_netCDF_FVCOM
     readdirRead working directory with no arguments. Output depends on the function call
     runmeanRUNMEAN - Very fast running mean (aka moving average) filter
     show_sigmaplot a sigma distribution along a user-selected line
     sigma_gen
     sigma_geo
     sigma_tanh
     transect_nodes_screenfunction to select and output index of nodes along a defined transect
     tri_from_bndrytesselate a triangular mesh using "triangle" from a single, unclosed boundary
     utm2deg-------------------------------------------------------------------------
     wave_fricwave friction using Soulsby page 80
     wgs2utm-------------------------------------------------------------------------
     zero_to_nan
    + ST_DstarCalculate non-dimensional grain size D*  ST_d2phiConvert sediment diameter (m) to phi  ST_erateCalculate erosion rate in kg/(m^2-s)  ST_exampleExample usage of Sediment Toolbox  ST_phi2dConvert sediment grain size from phi to d (m)  ST_summaryPrint summary for stats of particle diameter d (m)  ST_taucrCalculate critical shear stress in Pascals  ST_wentworthReport wentworth class of a particular grain size phi  ST_wsetCalculate settling velocity of particle diameter d (m) in m/s  SW_DensitySW_Density Density of sea water  SW_KviscosityCalculates the kinemtic viscosity [m^2/s] from the dynamic viscosity and  SW_ViscositySW_Viscosity Dynamic viscosity of seawater  calc_tauwDESCRIPTION:  catstructCATSTRUCT Concatenate or merge structures with different fieldnames  centroidx and y must be non-scalar vectors of equal sizes defining a polygonal  check_wsetCalculate settling velocity of particle diameter d (m) in m/s  connectivityCONNECTIVITY: Assemble connectivity data for a triangular mesh.  deg2utm-------------------------------------------------------------------------  do_ph_change_plotCalculate the change in the given parameter (plotOPTS.var_plot) and plot  do_ph_change_points_plotCalculate the change in the given parameter (plotOPTS.var_plot) and plot  do_ph_max_change_plotCalculate the change in pH and plot accordingly.  do_ph_vertical_profileFor a supplied transect, plot the vertical profile through the water  do_residualDO_RESIDUAL Takes the u and v vectors of a model output and calculates  do_residual_plotTake the output of do_residual and plot as a vector figure. Summarises a  do_surface_plot  do_transect_plot  do_vector_plot  do_volumeCalculate a volume for a given time step above a threshold value.  do_volume_changeDO_VOLUME_CHANGE Calculate volume of water which experiences a change in  do_volume_change2Calculate the volume exposed to a given change in pH.  find_boundary_elementsFind the elements which fall along the boundary.  fix_inside_boundaryFix unstructured grid points inside the given boundary.  get_NCEP_yearExtract the year from a give NCEP file name (either 'uwnd.sig995.YYYY.nc'  get_runsGET_RUNS Finds runs of continuous change in some value beyond some length  get_runs_testFigure out a way to identify runs longer than some specified length for  ginput2GINPUT2 Graphical input from mouse with zoom, pan, plot and scaling.  greg2julianThis function converts the Gregorian dates to Julian dates.  greg2mjulianmjulianday = greg2mjulian(yyyy,mm,dd,HH,MM,SS)  grid2fvcomInterpolate regularly gridded surface forcing data onto a given FVCOM  grid_vert_interpChild function to interpolate a given 3D array (x by y by sigma) values  gridvecsclear all; close all;  inboxdetermine if points lie in a box  inkmlbbfname = 'Wet_Skagit_BB.kml';  isintriangledetermine if point (x0,y0) is in triangle defined by nodes (xt(3),yt(3))  julian2gregThis function converts the Julian dates to Gregorian dates.  lat_to_mdy = lat_to_m(dlat,alat)  lon_to_mdx = lon_to_m(dlon, alat)  m_ll2llM_ll2LL Converts LON,LAT to long,lat coordinates using the current projection  m_to_lat  m_to_lon  mjul2strConvert a modified Julian day to a Matlab datestr style string  mjul2str2Convert a modified Julian day to a Matlab datestr style string  mjulian2gregThis function converts Modified Julian dates to Gregorian dates.  naut_2_cartconvert wind from nautical (speed,direction) to Cartesian (u,v)  pl64low pass filter (33 hr)  read_fvcom_meshRead fvcom mesh file into Matlab mesh object  read_kmlREAD_KML reads a Google Earth kml file into Matlab  read_netCDF_FVCOM  readdirRead working directory with no arguments. Output depends on the function call  runmeanRUNMEAN - Very fast running mean (aka moving average) filter  show_sigmaplot a sigma distribution along a user-selected line  sigma_genGenerate a generalised sigma coordinate distribution.  sigma_geoGenerate a geometric sigma coordinate distribution.  sigma_tanhGenerate a tanh sigma coordinate distribution.  transect_nodes_screenfunction to select and output index of nodes along a defined transect  tri_from_bndrytesselate a triangular mesh using "triangle" from a single, unclosed boundary  utm2deg-------------------------------------------------------------------------  wave_fricwave friction using Soulsby page 80  wgs2utm-------------------------------------------------------------------------  write_SMS_2dmOutput an SMS 2dm ASCII file from the triangulation given by tri, x and  write_SMS_cstExport a set of points to a CST file which can be imported into SMS.  zero_to_nan - -
    Generated on Mon 04-Feb-2013 14:22:26 by m2html © 2005
    +

    Dependency Graph

    + +
    Generated on Tue 04-Jun-2013 12:12:54 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/m_ll2ll.html b/doc/utilities/m_ll2ll.html index 3b32761472305c19c9177a7275870ac4392101c2..e9c98fe98c62b8bc1adcc190bd7094f73880b1a8 100644 --- a/doc/utilities/m_ll2ll.html +++ b/doc/utilities/m_ll2ll.html @@ -38,7 +38,7 @@ This function calls: This function is called by: +
  • do_residual_plot Take the output of do_residual and plot as a vector figure. Summarises a
  • do_transect_plot
  • do_vector_plot
  • SUBFUNCTIONS ^

    @@ -267,6 +267,6 @@ This function is called by: 0219 lon=lon/DEG2RADS; 0220 0221 return -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/show_sigma.html b/doc/utilities/show_sigma.html index 2c8af7b6fa1a6b270bbb4a818d036f6dcc8bda3b..d8c53e499c11f7916d6d9c3730d1d4f0e51a5141 100755 --- a/doc/utilities/show_sigma.html +++ b/doc/utilities/show_sigma.html @@ -61,7 +61,7 @@

    CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • sigma_gen Generate a generalised sigma coordinate distribution.
  • This function is called by: @@ -278,6 +278,6 @@ This function is called by: 0206 end 0207 axis([xslice(1,1),xslice(end,1),min(yslice(:,end)),5]) 0208 title('sigma distribution along the transect'); -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/sigma_gen.html b/doc/utilities/sigma_gen.html index 4a4158cb4f941fe8c35321ffd4a97b2bcc3a2dd3..40ffeca1aa3f55bc7c36c5ec160320b397832b61 100755 --- a/doc/utilities/sigma_gen.html +++ b/doc/utilities/sigma_gen.html @@ -4,7 +4,7 @@ Description of sigma_gen - + @@ -21,13 +21,44 @@

    PURPOSE ^

    -
    +
    Generate a generalised sigma coordinate distribution.

    SYNOPSIS ^

    function dist = sigma_gen(nlev,dl,du,kl,ku,zkl,zku,h,hmin)

    DESCRIPTION ^

    -
    +
     Generate a generalised sigma coordinate distribution.
    +
    + Mobj = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, h, hmin)
    +
    + DESCRIPTION:
    +   Generate a uniform or hybrid vertical sigma coordinate system.
    +
    + INPUT:
    +   nlev:       Number of sigma levels (layers + 1)
    +   dl:         The lower depth boundary from the bottom, down to which the
    +               coordinates are parallel with uniform thickness.
    +   du:         The upper depth boundary from the surface, up to which the
    +               coordinates are parallel with uniform thickness.
    +   kl:         ?
    +   ku:         ?
    +   zkl:        ?
    +   zku:        ?
    +   h:          Water depth.
    +   hmin:       Minimum water depth.
    +
    + OUTPUT:
    +   dist:       Generalised vertical sigma coordinate distribution.
    +
    + EXAMPLE USAGE:
    +   Mobj = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, h, hmin)
    +
    + Author(s):
    +   Geoff Cowles (University of Massachusetts Dartmouth)
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +   2013-04-23 Added help on the function and reformatted the code.

    CROSS-REFERENCE INFORMATION ^

    @@ -43,45 +74,76 @@ This function is called by:

    SOURCE CODE ^

    0001 function dist = sigma_gen(nlev,dl,du,kl,ku,zkl,zku,h,hmin)
    -0002 
    -0003 
    -0004  
    -0005   if(h < hmin)
    -0006     z(1) = 0.0;
    -0007     dl2=0.001;
    -0008     du2=0.001;
    -0009     for k=1:nlev-1
    -0010       x1 = dl2+du2;
    -0011       x1 = x1*double(nlev-1-k)/double(nlev-1);
    -0012       x1 = x1 - dl2;
    -0013       x1 = tanh(x1);
    -0014       x2 = tanh(dl2);
    -0015       x3 = x2+tanh(du2);
    -0016       z(k+1) = (x1+x2)/x3-1.0;  
    -0017     end;
    -0018   else;
    -0019     %dr=(h-sum(zku)-sum(zkl))/h/double(nlev-ku-kl-1);
    -0020     dr=(h-du-dl)/h/double(nlev-ku-kl-1);
    -0021     z(1) = 0.0;
    -0022  
    -0023     for k=2:ku+1 
    -0024        z(k) = z(k-1)-zku(k-1)/h;
    -0025   %     fprintf('building z %f %f %f %f \n',z(k),zku(k-1),h,zku(k-1)/h)
    -0026     end;
    -0027 
    -0028     for k=ku+2:nlev-kl
    -0029       z(k)=z(k-1)-dr;
    -0030   %     fprintf('building z %f %f \n',z(k),dr)
    -0031     end;
    -0032 
    -0033     kk = 0;
    -0034     for k=nlev-kl+1:nlev
    -0035       kk=kk+1;
    -0036       z(k)=z(k-1)-zkl(kk)/h;
    -0037   %     fprintf('building z %f %f \n',z(k),zkl(kk))
    -0038     end;   
    -0039   end;
    -0040   dist = z;
    -
    Generated on Mon 04-Feb-2013 14:22:28 by m2html © 2005
    +0002 % Generate a generalised sigma coordinate distribution. +0003 % +0004 % Mobj = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, h, hmin) +0005 % +0006 % DESCRIPTION: +0007 % Generate a uniform or hybrid vertical sigma coordinate system. +0008 % +0009 % INPUT: +0010 % nlev: Number of sigma levels (layers + 1) +0011 % dl: The lower depth boundary from the bottom, down to which the +0012 % coordinates are parallel with uniform thickness. +0013 % du: The upper depth boundary from the surface, up to which the +0014 % coordinates are parallel with uniform thickness. +0015 % kl: ? +0016 % ku: ? +0017 % zkl: ? +0018 % zku: ? +0019 % h: Water depth. +0020 % hmin: Minimum water depth. +0021 % +0022 % OUTPUT: +0023 % dist: Generalised vertical sigma coordinate distribution. +0024 % +0025 % EXAMPLE USAGE: +0026 % Mobj = sigma_gen(nlev, dl, du, kl, ku, zkl, zku, h, hmin) +0027 % +0028 % Author(s): +0029 % Geoff Cowles (University of Massachusetts Dartmouth) +0030 % Pierre Cazenave (Plymouth Marine Laboratory) +0031 % +0032 % Revision history +0033 % 2013-04-23 Added help on the function and reformatted the code. +0034 +0035 dist = nan(1, nlev); +0036 +0037 if h < hmin +0038 dist(1) = 0.0; +0039 dl2 = 0.001; +0040 du2 = 0.001; +0041 for k = 1:nlev-1 +0042 x1 = dl2+du2; +0043 x1 = x1*double(nlev-1-k)/double(nlev-1); +0044 x1 = x1 - dl2; +0045 x1 = tanh(x1); +0046 x2 = tanh(dl2); +0047 x3 = x2+tanh(du2); +0048 dist(k+1) = (x1+x2)/x3-1.0; +0049 end +0050 else +0051 %dr=(h-sum(zku)-sum(zkl))/h/double(nlev-ku-kl-1); +0052 dr = (h-du-dl)/h/double(nlev-ku-kl-1); +0053 dist(1) = 0.0; +0054 +0055 for k = 2:ku+1 +0056 dist(k) = dist(k-1)-zku(k-1)/h; +0057 % fprintf('building z %f %f %f %f \n',z(k),zku(k-1),h,zku(k-1)/h) +0058 end +0059 +0060 for k = ku+2:nlev-kl +0061 dist(k) = dist(k-1)-dr; +0062 % fprintf('building z %f %f \n',z(k),dr) +0063 end +0064 +0065 kk = 0; +0066 for k = nlev-kl+1:nlev +0067 kk = kk+1; +0068 dist(k) = dist(k-1)-zkl(kk)/h; +0069 % fprintf('building z %f %f \n',z(k),zkl(kk)) +0070 end +0071 end +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/sigma_geo.html b/doc/utilities/sigma_geo.html index 4127ee696995204cba740c1d3a216b67c95ed0b2..8f4ee93c1df2a3ebabe24c2dea07be1e225c817e 100755 --- a/doc/utilities/sigma_geo.html +++ b/doc/utilities/sigma_geo.html @@ -4,7 +4,7 @@ Description of sigma_geo - + @@ -21,13 +21,37 @@

    PURPOSE ^

    -
    +
    Generate a geometric sigma coordinate distribution.

    SYNOPSIS ^

    -
    function dist = sigma_geo(nlev,p_sigma)
    +
    function dist = sigma_geo(nlev, p_sigma)

    DESCRIPTION ^

    -
    +
     Generate a geometric sigma coordinate distribution.
    +
    + Mobj = sigma_gen(nlev, p_sigma)
    +
    + DESCRIPTION:
    +   Generate a geometric vertical sigma coordinate distribution.
    +
    + INPUT:
    +   nlev:       Number of sigma levels (layers + 1)
    +   p_sigma:    1 for uniform sigma layers, 2 for parabolic function. See
    +               page 308-309 in the FVCOM manual for examples.
    +
    + OUTPUT:
    +   dist:       Geometric vertical sigma coordinate distribution.
    +
    + EXAMPLE USAGE:
    +   Mobj = read_sigma(21, 2.0)
    +
    + Author(s):
    +   Geoff Cowles (University of Massachusetts Dartmouth)
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +   2013-04-23 Added help on the function and reformatted the code to
    +   remove the FORTRAN in the else block.

    CROSS-REFERENCE INFORMATION ^

    @@ -42,22 +66,49 @@ This function is called by:

    SOURCE CODE ^

    -
    0001 function dist = sigma_geo(nlev,p_sigma)
    -0002 
    -0003 kb = nlev;
    -0004 if(p_sigma ==1)
    -0005   for k=1:nlev
    -0006     dist(k) = -((k-1)/float(kb-1))^p_sigma;
    -0007   end;
    -0008 else
    -0009   for k=1:(kb+1)/2
    -0010     dist(k) = -((k-1)/float((kb+1)/2-1))^p_sigma/2;
    -0011   end;
    -0012   do k=(kb+1)/2+1:kb   
    -0013     dist(k) = ((kb-k)/float((kb+1)/2-1))^p_sigma/2-1.0;
    -0014   end;
    -0015 end;
    -0016
    -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +
    0001 function dist = sigma_geo(nlev, p_sigma)
    +0002 % Generate a geometric sigma coordinate distribution.
    +0003 %
    +0004 % Mobj = sigma_gen(nlev, p_sigma)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Generate a geometric vertical sigma coordinate distribution.
    +0008 %
    +0009 % INPUT:
    +0010 %   nlev:       Number of sigma levels (layers + 1)
    +0011 %   p_sigma:    1 for uniform sigma layers, 2 for parabolic function. See
    +0012 %               page 308-309 in the FVCOM manual for examples.
    +0013 %
    +0014 % OUTPUT:
    +0015 %   dist:       Geometric vertical sigma coordinate distribution.
    +0016 %
    +0017 % EXAMPLE USAGE:
    +0018 %   Mobj = read_sigma(21, 2.0)
    +0019 %
    +0020 % Author(s):
    +0021 %   Geoff Cowles (University of Massachusetts Dartmouth)
    +0022 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0023 %
    +0024 % Revision history
    +0025 %   2013-04-23 Added help on the function and reformatted the code to
    +0026 %   remove the FORTRAN in the else block.
    +0027 
    +0028 dist = nan(1, nlev);
    +0029 
    +0030 kb = nlev;
    +0031 
    +0032 if p_sigma == 1
    +0033     for k = 1:nlev
    +0034         dist(k) = -((k-1)/(kb-1))^p_sigma;
    +0035     end
    +0036 else
    +0037     for k = 1:(kb+1)/2
    +0038         dist(k) = -((k-1)/((kb+1)/2-1))^p_sigma/2;
    +0039     end
    +0040     for k = (kb+1)/2+1:kb
    +0041         dist(k) = ((kb-k)/((kb+1)/2-1))^p_sigma/2-1.0;
    +0042     end
    +0043 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/sigma_tanh.html b/doc/utilities/sigma_tanh.html index a114b208d03f9936e4609871df1d6a24bdaecef4..051e5c41d50ac27582b62fe0315c0227f3f13213 100755 --- a/doc/utilities/sigma_tanh.html +++ b/doc/utilities/sigma_tanh.html @@ -4,7 +4,7 @@ Description of sigma_tanh - + @@ -21,13 +21,38 @@

    PURPOSE ^

    -
    +
    Generate a tanh sigma coordinate distribution.

    SYNOPSIS ^

    function dist = sigma_tanh(nlev,dl,du)

    DESCRIPTION ^

    -
    +
     Generate a tanh sigma coordinate distribution.
    +
    + Mobj = sigma_tanh(nlev, dl, du)
    +
    + DESCRIPTION:
    +   Generate a tanh vertical sigma coordinate distribution.
    +
    + INPUT:
    +   nlev:       Number of sigma levels (layers + 1)
    +   dl:         The lower depth boundary from the bottom, down to which the
    +               coordinates are parallel with uniform thickness.
    +   du:         The upper depth boundary from the surface, up to which the
    +               coordinates are parallel with uniform thickness.
    +
    + OUTPUT:
    +   dist:       Tanh vertical sigma coordinate distribution.
    +
    + EXAMPLE USAGE:
    +   Mobj = read_sigma(nlev, dl, du)
    +
    + Author(s):
    +   Geoff Cowles (University of Massachusetts Dartmouth)
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    +
    + Revision history
    +   2013-04-23 Added help on the function and reformatted the code.

    CROSS-REFERENCE INFORMATION ^

    @@ -43,18 +68,44 @@ This function is called by:

    SOURCE CODE ^

    0001 function dist = sigma_tanh(nlev,dl,du)
    -0002 
    -0003   z=0.0;
    -0004   for k=1:nlev
    -0005     x1=dl+du;
    -0006     x1=x1*(nlev-1-k)/(nlev-1);
    -0007     x1=x1-dl;
    -0008     x1=tanh(x1);
    -0009     x2=tanh(dl);
    -0010     x3=x2+tanh(du);
    -0011     z(k+1)=(x1+x2)/x3-1.0;
    -0012   end;
    -0013
    -
    Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
    +0002 % Generate a tanh sigma coordinate distribution. +0003 % +0004 % Mobj = sigma_tanh(nlev, dl, du) +0005 % +0006 % DESCRIPTION: +0007 % Generate a tanh vertical sigma coordinate distribution. +0008 % +0009 % INPUT: +0010 % nlev: Number of sigma levels (layers + 1) +0011 % dl: The lower depth boundary from the bottom, down to which the +0012 % coordinates are parallel with uniform thickness. +0013 % du: The upper depth boundary from the surface, up to which the +0014 % coordinates are parallel with uniform thickness. +0015 % +0016 % OUTPUT: +0017 % dist: Tanh vertical sigma coordinate distribution. +0018 % +0019 % EXAMPLE USAGE: +0020 % Mobj = read_sigma(nlev, dl, du) +0021 % +0022 % Author(s): +0023 % Geoff Cowles (University of Massachusetts Dartmouth) +0024 % Pierre Cazenave (Plymouth Marine Laboratory) +0025 % +0026 % Revision history +0027 % 2013-04-23 Added help on the function and reformatted the code. +0028 +0029 dist = nan(1, nlev); +0030 +0031 for k = 1:nlev +0032 x1 = dl+du; +0033 x1 = x1*(nlev-1-k)/(nlev-1); +0034 x1 = x1-dl; +0035 x1 = tanh(x1); +0036 x2 = tanh(dl); +0037 x3 = x2+tanh(du); +0038 dist(k+1) = (x1+x2)/x3-1.0; +0039 end +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    \ No newline at end of file diff --git a/doc/utilities/write_SMS_2dm.html b/doc/utilities/write_SMS_2dm.html new file mode 100644 index 0000000000000000000000000000000000000000..21df08bb7a9cc31263f4e34cfd4118b86a24258a --- /dev/null +++ b/doc/utilities/write_SMS_2dm.html @@ -0,0 +1,180 @@ + + + + Description of write_SMS_2dm + + + + + + + + + +
    Home > utilities > write_SMS_2dm.m
    + + + +

    write_SMS_2dm +

    + +

    PURPOSE ^

    +
    Output an SMS 2dm ASCII file from the triangulation given by tri, x and
    + +

    SYNOPSIS ^

    +
    function write_SMS_2dm(file, tri, x, y, bnd)
    + +

    DESCRIPTION ^

    +
     Output an SMS 2dm ASCII file from the triangulation given by tri, x and
    + y.
    +
    + write_SMS_2dm(tri, x, y)
    + 
    + DESCRIPTION:
    +   Create an ASCII file in the SMS 2dm format of the triangulation in tri,
    +   x and y.
    + 
    + INPUT:
    +   file - file name to save to.
    +   tri  - triangulation matrix of the nodes in x and y.
    +   x, y - coordinate pairs for the unstructured grid.
    +   bnd  - [optional] cell array of open boundary node ids to create node
    +          strings in SMS.
    + 
    + OUTPUT:
    +   file - ASCII file in SMS 2dm format.
    + 
    + EXAMPLE USAGE:
    +   write_SMS_2dm('/tmp/test.2dm', Mobj.tri, Mobj.x, Mobj.y)
    + 
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    + 
    + Revision history:
    +   2013-03-11 First version.
    + 
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function write_SMS_2dm(file, tri, x, y, bnd)
    +0002 % Output an SMS 2dm ASCII file from the triangulation given by tri, x and
    +0003 % y.
    +0004 %
    +0005 % write_SMS_2dm(tri, x, y)
    +0006 %
    +0007 % DESCRIPTION:
    +0008 %   Create an ASCII file in the SMS 2dm format of the triangulation in tri,
    +0009 %   x and y.
    +0010 %
    +0011 % INPUT:
    +0012 %   file - file name to save to.
    +0013 %   tri  - triangulation matrix of the nodes in x and y.
    +0014 %   x, y - coordinate pairs for the unstructured grid.
    +0015 %   bnd  - [optional] cell array of open boundary node ids to create node
    +0016 %          strings in SMS.
    +0017 %
    +0018 % OUTPUT:
    +0019 %   file - ASCII file in SMS 2dm format.
    +0020 %
    +0021 % EXAMPLE USAGE:
    +0022 %   write_SMS_2dm('/tmp/test.2dm', Mobj.tri, Mobj.x, Mobj.y)
    +0023 %
    +0024 % Author(s):
    +0025 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0026 %
    +0027 % Revision history:
    +0028 %   2013-03-11 First version.
    +0029 %
    +0030 %==========================================================================
    +0031 
    +0032 subname = 'write_SMS_2dm';
    +0033 
    +0034 global ftbverbose
    +0035 if ftbverbose
    +0036     fprintf('\n'); fprintf(['begin : ' subname '\n']);
    +0037 end
    +0038 
    +0039 f = fopen(file, 'w');
    +0040 if f < 0
    +0041     error('Unable to open output file (check permissions?)')
    +0042 end
    +0043 
    +0044 if length(x) ~= length(y)
    +0045     error('Input coordinate array lengths do not match.')
    +0046 else
    +0047     nn = length(x);
    +0048 end
    +0049 
    +0050 nt = size(tri, 1);
    +0051 
    +0052 % Header
    +0053 fprintf(f, 'MESH2D\nMESHNAME "mesh"\n');
    +0054 
    +0055 % Add the connectivity table
    +0056 for t = 1:nt
    +0057     fprintf(f, 'E3T %i %i %i %i 1\n', t, tri(t, :));
    +0058 end
    +0059 
    +0060 % Add the list of nodes
    +0061 for n = 1:nn
    +0062     fprintf(f, 'ND %i %.8e %.8e %.8e\n', n, x(n), y(n), 0);
    +0063 end
    +0064 
    +0065 % Check we've got some open boundaries and create the relevant node string
    +0066 % output.
    +0067 if nargin == 5
    +0068     for b = 1:length(bnd)
    +0069         c = 0; % counter for the weird nodestring format.
    +0070 
    +0071         nodestring = bnd{b}; % current open boundary nodestring indices.
    +0072         for ns = 1:length(nodestring)
    +0073             % If we're at the end of the nodestring, create a negative node
    +0074             % ID.
    +0075             if ns == length(nodestring)
    +0076                 node_id = -nodestring(ns);
    +0077             else
    +0078                 node_id = nodestring(ns);
    +0079             end
    +0080 
    +0081             % Increment the counter.
    +0082             c = c + 1;
    +0083             if c == 1
    +0084                 % Add the nodestring line prefix and the current node ID.
    +0085                 fprintf(f, 'NS %i ', node_id);
    +0086             elseif c > 0 && c < 10
    +0087                 fprintf(f, '%i ', node_id);
    +0088             elseif c >= 10 || ns == length(nodestring);
    +0089                 fprintf(f, '%i\n', node_id);
    +0090                 c = 0;
    +0091             end
    +0092         end
    +0093         % Add a newline at the end of the current nodestring.
    +0094         fprintf(f, '\n');
    +0095     end
    +0096 end
    +0097 
    +0098 % Dump all the (apparently ignored) footer information.
    +0099 fprintf(f, 'BEGPARAMDEF\nGM  "Mesh"\nSI  0\nDY  0\nTU  ""\nTD  0  0\nNUME  3\nBCPGC  0\nBEDISP  0 0 0 0 1 0 1 0 0 0 0 1\nBEFONT  0 2\nBEDISP  1 0 0 0 1 0 1 0 0 0 0 1\nBEFONT  1 2\nBEDISP  2 0 0 0 1 0 1 0 0 0 0 1\nBEFONT  2 2\nENDPARAMDEF\nBEG2DMBC\nMAT  1 "material 01"\nEND2DMBC\n');
    +0100 
    +0101 fclose(f);
    +0102 
    +0103 if ftbverbose
    +0104     fprintf('end   : %s\n', subname)
    +0105 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/utilities/write_SMS_cst.html b/doc/utilities/write_SMS_cst.html new file mode 100644 index 0000000000000000000000000000000000000000..f33bc3a8ad05c78f7a2ab2e32c9d05f21173a1d6 --- /dev/null +++ b/doc/utilities/write_SMS_cst.html @@ -0,0 +1,152 @@ + + + + Description of write_SMS_cst + + + + + + + + + +
    Home > utilities > write_SMS_cst.m
    + + + +

    write_SMS_cst +

    + +

    PURPOSE ^

    +
    Export a set of points to a CST file which can be imported into SMS.
    + +

    SYNOPSIS ^

    +
    function write_SMS_cst(file, x, y)
    + +

    DESCRIPTION ^

    +
     Export a set of points to a CST file which can be imported into SMS.
    + 
    + write_SMS_cst(file, x, y)
    + 
    + DESCRIPTION:
    +   Create an ASCII file in the CST format recognised by SMS from the
    +   coordinates specified in (x, y). If x and y are cell arrays, the
    +   coordinates in each cell array are treated as different arcs in the CST
    +   file (e.g. if you have multiple open boundaries you would like in a
    +   single CST file).
    + 
    + INPUT:
    +   file - file name to save to.
    +   x, y - coordinate pairs for the open boundary.
    + 
    + OUTPUT:
    +   file - ASCII file in SMS CST format.
    + 
    + EXAMPLE USAGE:
    +   write_SMS_cst('/tmp/test.cst', x, y)
    + 
    + Author(s):
    +   Pierre Cazenave (Plymouth Marine Laboratory)
    + 
    + Revision history:
    +   2013-03-11 First version.
    + 
    +==========================================================================
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function write_SMS_cst(file, x, y)
    +0002 % Export a set of points to a CST file which can be imported into SMS.
    +0003 %
    +0004 % write_SMS_cst(file, x, y)
    +0005 %
    +0006 % DESCRIPTION:
    +0007 %   Create an ASCII file in the CST format recognised by SMS from the
    +0008 %   coordinates specified in (x, y). If x and y are cell arrays, the
    +0009 %   coordinates in each cell array are treated as different arcs in the CST
    +0010 %   file (e.g. if you have multiple open boundaries you would like in a
    +0011 %   single CST file).
    +0012 %
    +0013 % INPUT:
    +0014 %   file - file name to save to.
    +0015 %   x, y - coordinate pairs for the open boundary.
    +0016 %
    +0017 % OUTPUT:
    +0018 %   file - ASCII file in SMS CST format.
    +0019 %
    +0020 % EXAMPLE USAGE:
    +0021 %   write_SMS_cst('/tmp/test.cst', x, y)
    +0022 %
    +0023 % Author(s):
    +0024 %   Pierre Cazenave (Plymouth Marine Laboratory)
    +0025 %
    +0026 % Revision history:
    +0027 %   2013-03-11 First version.
    +0028 %
    +0029 %==========================================================================
    +0030 
    +0031 subname = 'write_SMS_cst';
    +0032 
    +0033 global ftbverbose
    +0034 if ftbverbose
    +0035     fprintf('\n'); fprintf(['begin : ' subname '\n']);
    +0036 end
    +0037 
    +0038 f = fopen(file, 'w');
    +0039 if f < 0
    +0040     error('Unable to open output file (check permissions?)')
    +0041 end
    +0042 
    +0043 if iscell(x) && iscell(y)
    +0044     nb = length(x);
    +0045 else
    +0046     nb = 1;
    +0047 end
    +0048 
    +0049 % Header
    +0050 fprintf(f, 'COAST\n');
    +0051 fprintf(f, '%i\n', nb);
    +0052 
    +0053 for bb = 1:nb % each boundary
    +0054     if iscell(x) && iscell(y)
    +0055         np = length(x{bb});
    +0056         xx = x{bb};
    +0057         yy = y{bb};
    +0058     else
    +0059         np = length(x);
    +0060         xx = x;
    +0061         yy = y;
    +0062     end
    +0063 
    +0064     % The current arc's header
    +0065     fprintf(f, '%i\t0.0\n', np);
    +0066     
    +0067     % All the positions
    +0068     for i=1:length(xx);
    +0069         fprintf(f, '\t%.6f\t%.6f\t0.0\n', xx(i), yy(i));
    +0070     end
    +0071 
    +0072 end
    +0073     
    +0074 fclose(f);
    +0075 
    +0076 if ftbverbose
    +0077     fprintf('end   : %s \n', subname)
    +0078 end
    +
    Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005
    + + \ No newline at end of file diff --git a/make_doc.m b/make_doc.m index 7d4eed7a84d637f27b428d3c1d8b0f9417f0cb5d..8e85b5af2b49867c271bde67715ba7961c9bc820 100644 --- a/make_doc.m +++ b/make_doc.m @@ -1,3 +1,3 @@ addpath('/users/modellers/pica/Code/MATLAB/toolboxes/m2html') -m2html('mfiles',{'fvcom_postproc','fvcom_prepro','utilities','swan_scripts'},'htmldir','doc'); +m2html('mfiles',{'fvcom_postproc','fvcom_prepro','utilities','swan_scripts','tests'},'htmldir','doc');