0001 function write_FVCOM_groundwater(Mobj, grndwtr_file, varargin)
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
0048
0049
0050
0051
0052 global ftbverbose
0053
0054 subname = 'write_FVCOM_groundwater';
0055 if ftbverbose
0056 fprintf('\nbegin : %s \n', subname);
0057 end
0058
0059
0060 strtime = true;
0061 inttime = false;
0062 floattime = false;
0063 for vv = 1:2:length(varargin)
0064 switch varargin{vv}
0065 case 'strtime'
0066 strtime = true;
0067 case 'inttime'
0068 inttime = true;
0069 case 'floattime'
0070 floattime = true;
0071 end
0072 end
0073
0074
0075
0076
0077
0078
0079 nc = netcdf.create(grndwtr_file, 'clobber');
0080
0081
0082 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'type', 'FVCOM GROUNDWATER FORCING FILE')
0083 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'source', 'FVCOM grid (unstructured) surface forcing')
0084 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'history', sprintf('File created with %s from the MATLAB fvcom-toolbox', subname))
0085
0086
0087 node_dimid = netcdf.defDim(nc, 'node', Mobj.nVerts);
0088
0089
0090 nele_dimid = netcdf.defDim(nc, 'nele', Mobj.nElems);
0091 time_dimid = netcdf.defDim(nc, 'time', netcdf.getConstant('NC_UNLIMITED'));
0092 date_str_len_dimid = netcdf.defDim(nc, 'DateStrLen', 26);
0093
0094
0095 gflux_varid = netcdf.defVar(nc, 'groundwater_flux', 'NC_FLOAT', [node_dimid, time_dimid]);
0096 netcdf.putAtt(nc, gflux_varid, 'long_name', 'groundwater volume flux');
0097 netcdf.putAtt(nc, gflux_varid, 'units', 'm3 s-1');
0098 netcdf.putAtt(nc, gflux_varid, 'grid', 'fvcom_grid');
0099 netcdf.putAtt(nc, gflux_varid, 'type', 'data');
0100
0101 gtemp_varid = netcdf.defVar(nc, 'groundwater_temp', 'NC_FLOAT', [node_dimid, time_dimid]);
0102 netcdf.putAtt(nc, gtemp_varid, 'long_name', 'groundwater inflow temperature');
0103 netcdf.putAtt(nc, gtemp_varid, 'units', 'degrees_C');
0104 netcdf.putAtt(nc, gtemp_varid, 'grid', 'fvcom_grid');
0105 netcdf.putAtt(nc, gtemp_varid, 'type', 'data');
0106
0107 gsalt_varid = netcdf.defVar(nc, 'groundwater_salt', 'NC_FLOAT', [node_dimid, time_dimid]);
0108 netcdf.putAtt(nc, gsalt_varid, 'long_name', 'groundwater inflow salinity');
0109 netcdf.putAtt(nc, gsalt_varid, 'units', '1e-3');
0110 netcdf.putAtt(nc, gsalt_varid, 'grid', 'fvcom_grid');
0111 netcdf.putAtt(nc, gsalt_varid, 'type', 'data');
0112
0113 iint_varid = netcdf.defVar(nc, 'iint', 'NC_INT', time_dimid);
0114 netcdf.putAtt(nc, iint_varid, 'long_name', 'internal mode iteration number');
0115
0116 if floattime
0117 time_varid = netcdf.defVar(nc, 'time', 'NC_FLOAT', time_dimid);
0118 netcdf.putAtt(nc, time_varid, 'long_name', 'time');
0119 netcdf.putAtt(nc, time_varid, 'units', 'days since 1858-11-17 00:00:00');
0120 netcdf.putAtt(nc, time_varid, 'format', 'modified julian day (MJD)');
0121 netcdf.putAtt(nc, time_varid, 'time_zone', 'UTC');
0122 end
0123
0124 if inttime
0125 itime_varid = netcdf.defVar(nc, 'Itime', 'NC_INT', time_dimid);
0126 netcdf.putAtt(nc, itime_varid, 'units', 'days since 1858-11-17 00:00:00');
0127 netcdf.putAtt(nc, itime_varid, 'format', 'modified julian day (MJD)');
0128 netcdf.putAtt(nc, itime_varid, 'time_zone', 'UTC');
0129
0130 itime2_varid = netcdf.defVar(nc, 'Itime2', 'NC_INT', time_dimid);
0131 netcdf.putAtt(nc, itime2_varid, 'units', 'msec since 00:00:00');
0132 netcdf.putAtt(nc, itime2_varid, 'time_zone', 'UTC');
0133 end
0134
0135 if strtime
0136 Times_varid = netcdf.defVar(nc, 'Times', 'NC_CHAR', [date_str_len_dimid, time_dimid]);
0137 netcdf.putAtt(nc, Times_varid, 'time_zone', 'UTC');
0138 end
0139
0140
0141 netcdf.endDef(nc);
0142
0143
0144 nTimes = length(Mobj.groundwater.times);
0145 netcdf.putVar(nc, iint_varid, 0, nTimes, 1:nTimes);
0146 if floattime
0147 netcdf.putVar(nc, time_varid, 0, nTimes, Mobj.groundwater.times);
0148 end
0149 if inttime
0150 netcdf.putVar(nc, itime_varid, floor(Mobj.groundwater.times));
0151 netcdf.putVar(nc, itime2_varid, 0, nTimes, round(mod(Mobj.groundwater.times, 1) * 24 * 60 * 60 * 1000));
0152 end
0153 if strtime
0154 nStringOut = char();
0155 [nYr, nMon, nDay, nHour, nMin, nSec] = mjulian2greg(Mobj.groundwater.times);
0156 for i = 1:nTimes
0157 nDate = [nYr(i), nMon(i), nDay(i), nHour(i), nMin(i), nSec(i)];
0158 nStringOut = [nStringOut, sprintf('%04i/%02i/%02i %02i:%02i:%09.6f', nDate)];
0159 end
0160 netcdf.putVar(nc, Times_varid, nStringOut);
0161 end
0162 netcdf.putVar(nc, gflux_varid, Mobj.groundwater.flux);
0163 netcdf.putVar(nc, gtemp_varid, Mobj.groundwater.temp);
0164 netcdf.putVar(nc, gsalt_varid, Mobj.groundwater.salt);
0165
0166
0167 netcdf.close(nc);
0168
0169 if ftbverbose
0170 fprintf('end : %s \n', subname)
0171 end