Due to a shift in policy, from 0900 GMT on Wednesday 14th July 2021, we will be disabling ssh access to the server for external users. External users who wish to continue to access code repositories on the server will need to switch to using https. This can be accomplished in the following way: 1) On the repo on gitlab, use the clone dialogue and select ‘Clone with HTTPS’ to get the address of the repo; 2) From within the checkout of your repo run: $ git remote set-url origin HTTPS_ADDRESS. Here, replace HTTPS_ADDRESS with the address you have just copied from GitLab. Pulls and pushes will now require you to enter a username and password rather than using a ssh key. If you would prefer not to enter a password each time, you might consider caching your login credentials.

read_NCEP_wind.html 10.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of read_NCEP_wind</title>
  <meta name="keywords" content="read_NCEP_wind">
  <meta name="description" content="Reads in two NCEP wind vector files (U and V) and outputs four arrays of">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">fvcom_prepro</a> &gt; read_NCEP_wind.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for fvcom_prepro&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>read_NCEP_wind
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Reads in two NCEP wind vector files (U and V) and outputs four arrays of</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function ncep = read_NCEP_wind(ncep_u10_file, ncep_v10_file) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Reads in two NCEP wind vector files (U and V) and outputs four arrays of
 longitude, latitude, u10 and v10 velocity components.
 
 function read_NCEP_wind()
 
 DESCRIPTION:
   Read a pair of NCEP NetCDF files (U10 and V10 vectors) and output to
   four arrays of longitude, latitude, u10 and v10.
 
 INPUT:
   NCEP NetCDF U10 filename (and path)
   NCEP NetCDF V10 filename (and path)
 
 OUTPUT:
   ncep - struct with the time, latitude, longitude, u10 and v10 arrays in
   it. Time is in Modified Julian Days.
 
 Author(s)
   Pierre Cazenave (Plymouth Marine Laboratory)
 
 Revision history:
   2012-10-16 First version based on parts of ncep2fvcom_U10V10.m in the
   fvcom-toolbox.
 
==========================================================================</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function ncep = read_NCEP_wind(ncep_u10_file, ncep_v10_file)</a>
0002 <span class="comment">% Reads in two NCEP wind vector files (U and V) and outputs four arrays of</span>
0003 <span class="comment">% longitude, latitude, u10 and v10 velocity components.</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% function read_NCEP_wind()</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% DESCRIPTION:</span>
0008 <span class="comment">%   Read a pair of NCEP NetCDF files (U10 and V10 vectors) and output to</span>
0009 <span class="comment">%   four arrays of longitude, latitude, u10 and v10.</span>
0010 <span class="comment">%</span>
0011 <span class="comment">% INPUT:</span>
0012 <span class="comment">%   NCEP NetCDF U10 filename (and path)</span>
0013 <span class="comment">%   NCEP NetCDF V10 filename (and path)</span>
0014 <span class="comment">%</span>
0015 <span class="comment">% OUTPUT:</span>
0016 <span class="comment">%   ncep - struct with the time, latitude, longitude, u10 and v10 arrays in</span>
0017 <span class="comment">%   it. Time is in Modified Julian Days.</span>
0018 <span class="comment">%</span>
0019 <span class="comment">% Author(s)</span>
0020 <span class="comment">%   Pierre Cazenave (Plymouth Marine Laboratory)</span>
0021 <span class="comment">%</span>
0022 <span class="comment">% Revision history:</span>
0023 <span class="comment">%   2012-10-16 First version based on parts of ncep2fvcom_U10V10.m in the</span>
0024 <span class="comment">%   fvcom-toolbox.</span>
0025 <span class="comment">%</span>
0026 <span class="comment">%==========================================================================</span>
0027 
96
0028 <span class="comment">%warning off</span>
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
0029 
0030 <span class="keyword">if</span> nargin ~= 2
0031     error(<span class="string">'Incorrect number of arguments'</span>)
0032 <span class="keyword">end</span>
0033 
0034 subname = <span class="string">'read_NCEP_wind'</span>;
0035 
0036 <span class="keyword">global</span> ftbverbose;
0037 <span class="keyword">if</span>(ftbverbose);
0038   fprintf(<span class="string">'\n'</span>)
0039   fprintf([<span class="string">'begin : '</span> subname <span class="string">'\n'</span>])
0040 <span class="keyword">end</span>;
0041 
0042 <span class="keyword">if</span> exist(ncep_u10_file, <span class="string">'file'</span>) ~= 2
0043    error([<span class="string">'file: '</span> ncep_u10_file <span class="string">' does not exist'</span>]);
0044 <span class="keyword">end</span>
0045 <span class="keyword">if</span> exist(ncep_v10_file, <span class="string">'file'</span>) ~= 2
0046     error([<span class="string">'file: '</span> ncep_v10_file <span class="string">' does not exist'</span>]);
0047 <span class="keyword">end</span>
0048 
0049 <span class="comment">%--------------------------------------------------------------------------</span>
0050 <span class="comment">% Open NCEP data and check for time range</span>
0051 <span class="comment">%--------------------------------------------------------------------------</span>
0052 
0053 <span class="comment">% Get the year from the NCEP file name</span>
0054 ncep_u10_year = get_NCEP_year(ncep_u10_file);
0055 ncep_v10_year = get_NCEP_year(ncep_v10_file);
0056 <span class="comment">% Check both files are from the same year</span>
0057 <span class="keyword">if</span> (ncep_u10_year - ncep_v10_year) ~= 0
0058     error(<span class="string">'Input U and V wind data files are from different years'</span>)
0059 <span class="keyword">end</span>
0060 
0061 <span class="comment">% Get the time. It's stored relative to the 1st January for the given year.</span>
0062 <span class="comment">% We're assuming that since both files are for the same year, we don't have</span>
0063 <span class="comment">% to pull the 'time' variable out from both (they should be identical).</span>
0064 nc_u10 = netcdf.open(ncep_u10_file, <span class="string">'NOWRITE'</span>);
0065 nc_v10 = netcdf.open(ncep_v10_file, <span class="string">'NOWRITE'</span>);
0066 time_varid = netcdf.inqVarID(nc_u10, <span class="string">'time'</span>);
0067 nceptimehours = netcdf.getVar(nc_u10, time_varid);
0068 
0069 <span class="comment">% NCEP dates are relative to 0001/01/01 00:00:00 and stored in hours.</span>
0070 <span class="comment">% MATLAB's dates are relative to 0000/00/00 00:00:00 and stored in days.</span>
0071 <span class="comment">% Need to add a year and a day to the NCEP time when converting.</span>
0072 nceptimedays = datevec((nceptimehours/24) + datenum(1, 0, -1));
0073 ncep.time = greg2mjulian(nceptimedays(:,1), nceptimedays(:,2),<span class="keyword">...</span>
0074     nceptimedays(:,3), nceptimedays(:,4), nceptimedays(:,5),<span class="keyword">...</span>
0075     nceptimedays(:,6));
0076 
0077 <span class="keyword">if</span>(ftbverbose);
0078     fprintf(<span class="string">'beg time of NCEP data %04i/%02i/%02i %02i:%02i:%02i\n'</span>,nceptimedays(1,:));
0079     fprintf(<span class="string">'end time of NCEP data %04i/%02i/%02i %02i:%02i:%02i\n'</span>,nceptimedays(<span class="keyword">end</span>,:));
0080 <span class="keyword">end</span>
0081 
0082 <span class="comment">% Get the geographical information from the NCEP data. Again, use the U10</span>
0083 <span class="comment">% file only (we're assuming they're both global).</span>
0084 lat_varid = netcdf.inqVarID(nc_u10, <span class="string">'lat'</span>);
0085 lon_varid = netcdf.inqVarID(nc_u10, <span class="string">'lon'</span>);
0086 nceplatvector = netcdf.getVar(nc_u10, lat_varid);
0087 nceplonvector = netcdf.getVar(nc_u10, lon_varid);
0088 
0089 [ncep.lon, ncep.lat] = meshgrid(nceplonvector, nceplatvector);
0090 
0091 <span class="comment">% Find the necessary variables</span>
0092 u10_varid_NCEP = netcdf.inqVarID(nc_u10, <span class="string">'uwnd'</span>);
0093 v10_varid_NCEP = netcdf.inqVarID(nc_v10, <span class="string">'vwnd'</span>);
0094 
0095 <span class="comment">% Get the U10 and V10 data</span>
0096 U10 = netcdf.getVar(nc_u10, u10_varid_NCEP, <span class="string">'single'</span>);
0097 V10 = netcdf.getVar(nc_v10, v10_varid_NCEP, <span class="string">'single'</span>);
0098 
0099 <span class="comment">% The NCEP data are packed as integers. The following equation describes</span>
0100 <span class="comment">% how to unpack them:</span>
0101 <span class="comment">%     unpacked value = add_offset + ( (packed value) * scale_factor )</span>
0102 <span class="comment">% (from http://www.esrl.noaa.gov/psd/data/gridded/faq.html#2).</span>
0103 <span class="comment">% Keep them as singles for now to avoid horrible rounding errors.</span>
0104 scale_factor = netcdf.getAtt(nc_u10,u10_varid_NCEP,<span class="string">'scale_factor'</span>,<span class="string">'single'</span>);
0105 add_offset = netcdf.getAtt(nc_u10,u10_varid_NCEP,<span class="string">'add_offset'</span>,<span class="string">'single'</span>);
0106 
0107 <span class="comment">% Unpack the values. U10 and V10 must be doubles for griddata to work. Fix</span>
0108 <span class="comment">% the order of the dimensions to match the coordinates in nceplon and</span>
0109 <span class="comment">% nceplat.</span>
0110 ncep.uwnd = permute(double(add_offset + (U10.*scale_factor)), [2,1,3]);
0111 ncep.vwnd = permute(double(add_offset + (V10.*scale_factor)), [2,1,3]);
0112 
0113 netcdf.close(nc_u10)
0114 netcdf.close(nc_v10)</pre></div>
183
<hr><address>Generated on Tue 04-Jun-2013 12:12:57 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
184 185
</body>
</html>