0001 function write_FVCOM_heating(Mobj, fileprefix, data)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 assert(nargin == 3, 'Incorrect number of arguments')
0048
0049 subname = 'write_FVCOM_heating';
0050
0051 global ftbverbose
0052 if ftbverbose
0053 fprintf('\nbegin : %s \n', subname)
0054 end
0055
0056 tri = Mobj.tri;
0057 nNodes = Mobj.nVerts;
0058 nElems = Mobj.nElems;
0059 ntimes = numel(data.time);
0060
0061 if strcmpi(Mobj.nativeCoords, 'cartesian')
0062 x = Mobj.x;
0063 y = Mobj.y;
0064 else
0065 x = Mobj.lon;
0066 y = Mobj.lat;
0067
0068 x(x < 0) = x(x < 0) + 360;
0069 end
0070
0071 coordString = sprintf('FVCOM %s coordinates', Mobj.nativeCoords);
0072
0073
0074 xc = nodes2elems(x, Mobj);
0075 yc = nodes2elems(y, Mobj);
0076
0077
0078
0079
0080
0081 nc = netcdf.create([fileprefix, '_hfx.nc'], 'clobber');
0082
0083 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'title', 'FVCOM Forcing File')
0084 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'institution', 'Plymouth Marine Laboratory')
0085 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'source', 'FVCOM grid (unstructured) surface forcing')
0086 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'history', sprintf('File created with %s from the MATLAB fvcom-toolbox', subname))
0087 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'references', 'http://fvcom.smast.umassd.edu, http://codfish.smast.umassd.edu')
0088 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'Conventions', 'CF-1.0')
0089 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'CoordinateSystem', Mobj.nativeCoords)
0090 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'CoordinateProjection', 'init=epsg:4326')
0091
0092
0093 nele_dimid=netcdf.defDim(nc, 'nele', nElems);
0094 node_dimid=netcdf.defDim(nc, 'node', nNodes);
0095 three_dimid=netcdf.defDim(nc, 'three', 3);
0096 time_dimid=netcdf.defDim(nc, 'time', netcdf.getConstant('NC_UNLIMITED'));
0097 datestrlen_dimid=netcdf.defDim(nc, 'DateStrLen', 26);
0098
0099
0100 if strcmpi(Mobj.nativeCoords, 'cartesian')
0101 x_varid=netcdf.defVar(nc, 'x', 'NC_FLOAT', node_dimid);
0102 netcdf.putAtt(nc, x_varid, 'long_name', 'nodal x-coordinate');
0103 netcdf.putAtt(nc, x_varid, 'units', 'meters');
0104
0105 y_varid=netcdf.defVar(nc, 'y', 'NC_FLOAT', node_dimid);
0106 netcdf.putAtt(nc, y_varid, 'long_name', 'nodal y-coordinate');
0107 netcdf.putAtt(nc, y_varid, 'units', 'meters');
0108
0109 xc_varid=netcdf.defVar(nc, 'xc','NC_FLOAT', nele_dimid);
0110 netcdf.putAtt(nc, xc_varid, 'long_name', 'zonal x-coordinate');
0111 netcdf.putAtt(nc, xc_varid, 'units', 'meters');
0112
0113 yc_varid=netcdf.defVar(nc, 'yc','NC_FLOAT', nele_dimid);
0114 netcdf.putAtt(nc, yc_varid, 'long_name', 'zonal y-coordinate');
0115 netcdf.putAtt(nc, yc_varid, 'units', 'meters');
0116
0117 elseif strcmpi(Mobj.nativeCoords, 'spherical')
0118 x_varid=netcdf.defVar(nc, 'lon','NC_FLOAT', node_dimid);
0119 netcdf.putAtt(nc, x_varid, 'long_name', 'nodal longitude');
0120 netcdf.putAtt(nc, x_varid, 'units', 'degrees_east');
0121
0122 y_varid = netcdf.defVar(nc, 'lat', 'NC_FLOAT', node_dimid);
0123 netcdf.putAtt(nc, y_varid, 'long_name', 'nodal latitude');
0124 netcdf.putAtt(nc, y_varid, 'units', 'degrees_north');
0125
0126 xc_varid = netcdf.defVar(nc, 'lonc', 'NC_FLOAT', nele_dimid);
0127 netcdf.putAtt(nc, xc_varid, 'long_name', 'zonal longitude');
0128 netcdf.putAtt(nc, xc_varid, 'units', 'degrees_east');
0129
0130 yc_varid = netcdf.defVar(nc, 'latc', 'NC_FLOAT', nele_dimid);
0131 netcdf.putAtt(nc, yc_varid, 'long_name', 'zonal latitude');
0132 netcdf.putAtt(nc, yc_varid, 'units', 'degrees_north');
0133 else
0134 error('Unknown coordinate type (%s)', Mobj.nativeCoords)
0135 end
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
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 netcdf.putAtt(nc, itime2_varid, 'long_name', 'time');
0156
0157 times_varid=netcdf.defVar(nc, 'Times', 'NC_CHAR', [datestrlen_dimid, time_dimid]);
0158 netcdf.putAtt(nc, times_varid, 'long_name', 'Calendar Date');
0159 netcdf.putAtt(nc, times_varid, 'format', 'String: Calendar Time');
0160 netcdf.putAtt(nc, times_varid, 'time_zone', 'UTC');
0161
0162 airt_varid = netcdf.defVar(nc, 'air_temperature', 'NC_FLOAT', [node_dimid, time_dimid]);
0163 netcdf.putAtt(nc, airt_varid, 'long_name', 'Surface air temperature');
0164 netcdf.putAtt(nc, airt_varid, 'units', 'Celsius Degree');
0165 netcdf.putAtt(nc, airt_varid, 'grid', 'fvcom_grid');
0166 netcdf.putAtt(nc, airt_varid, 'coordinates', coordString);
0167 netcdf.putAtt(nc, airt_varid, 'type', 'data');
0168
0169 rhum_varid = netcdf.defVar(nc, 'relative_humidity', 'NC_FLOAT', [node_dimid, time_dimid]);
0170 netcdf.putAtt(nc, rhum_varid, 'long_name', 'surface air relative humidity');
0171 netcdf.putAtt(nc, rhum_varid, 'units', 'percentage');
0172 netcdf.putAtt(nc, rhum_varid, 'grid', 'fvcom_grid');
0173 netcdf.putAtt(nc, rhum_varid, 'coordinates', coordString);
0174 netcdf.putAtt(nc, rhum_varid, 'type', 'data');
0175
0176 dlwrf_varid = netcdf.defVar(nc, 'long_wave', 'NC_FLOAT', [node_dimid, time_dimid]);
0177 netcdf.putAtt(nc, dlwrf_varid, 'long_name', 'Downward solar longwave radiation flux');
0178 netcdf.putAtt(nc, dlwrf_varid, 'units', 'Watts meter-2');
0179 netcdf.putAtt(nc, dlwrf_varid, 'grid', 'fvcom_grid');
0180 netcdf.putAtt(nc, dlwrf_varid, 'coordinates', coordString);
0181 netcdf.putAtt(nc, dlwrf_varid, 'type', 'data');
0182
0183 dswrf_varid = netcdf.defVar(nc, 'short_wave', 'NC_FLOAT', [node_dimid, time_dimid]);
0184 netcdf.putAtt(nc, dswrf_varid, 'long_name', 'Downward solar shortwave radiation flux');
0185 netcdf.putAtt(nc, dswrf_varid, 'units', 'Watts meter-2');
0186 netcdf.putAtt(nc, dswrf_varid, 'grid', 'fvcom_grid');
0187 netcdf.putAtt(nc, dswrf_varid, 'coordinates', coordString);
0188 netcdf.putAtt(nc, dswrf_varid, 'type', 'data');
0189
0190 slp_varid = netcdf.defVar(nc, 'air_pressure', 'NC_FLOAT', [node_dimid, time_dimid]);
0191 netcdf.putAtt(nc, slp_varid, 'long_name', 'Surface air pressure');
0192 netcdf.putAtt(nc, slp_varid, 'units', 'Pa');
0193 netcdf.putAtt(nc, slp_varid, 'grid', 'fvcom_grid');
0194 netcdf.putAtt(nc, slp_varid, 'coordinates', coordString);
0195 netcdf.putAtt(nc, slp_varid, 'type', 'data');
0196
0197
0198 netcdf.endDef(nc);
0199
0200
0201
0202
0203 netcdf.putVar(nc, nv_varid, tri');
0204 netcdf.putVar(nc, time_varid, 0, ntimes, data.time);
0205 netcdf.putVar(nc, itime_varid, 0, ntimes, floor(data.time));
0206 netcdf.putVar(nc, itime2_varid, 0, ntimes, mod(data.time, 1) * 24 * 3600 * 1000);
0207 netcdf.putVar(nc, x_varid, x);
0208 netcdf.putVar(nc, y_varid, y);
0209 netcdf.putVar(nc, xc_varid, xc);
0210 netcdf.putVar(nc, yc_varid, yc);
0211 netcdf.putVar(nc, airt_varid, data.air.node);
0212 netcdf.putVar(nc, rhum_varid, data.rhum.node);
0213 try
0214
0215 netcdf.putVar(nc, dlwrf_varid, data.dlwrf.node);
0216 catch
0217
0218 netcdf.putVar(nc, dlwrf_varid, data.nlwrf.node);
0219 end
0220 try
0221
0222 netcdf.putVar(nc, dswrf_varid, data.dswrf.node);
0223 catch
0224
0225 netcdf.putVar(nc, dswrf_varid, data.nswrf.node);
0226 end
0227 try
0228 netcdf.putVar(nc, slp_varid, data.slp.node);
0229 catch
0230 netcdf.putVar(nc, slp_varid, data.pres.node);
0231 end
0232
0233
0234 nStringOut = char();
0235 [nYr, nMon, nDay, nHour, nMin, nSec] = mjulian2greg(data.time);
0236 for tt=1:ntimes
0237 nDate = [nYr(tt), nMon(tt), nDay(tt), nHour(tt), nMin(tt), nSec(tt)];
0238 nStringOut = [nStringOut, sprintf('%04i/%02i/%02i %02i:%02i:%02i ', nDate)];
0239 end
0240 netcdf.putVar(nc, times_varid, nStringOut);
0241
0242
0243 netcdf.close(nc);
0244
0245 if ftbverbose
0246 fprintf('end : %s \n', subname)
0247 end