0001 function write_FVCOM_river(RiverFile,RiverName,time,flux,temp,salt,RiverInfo1,RiverInfo2)
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 subname = 'write_FVCOM_river';
0049
0050 global ftbverbose
0051 if ftbverbose
0052 fprintf('\nbegin : %s\n', subname)
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 [year1, month1, day1, ~, ~, ~] = mjulian2greg(time(1));
0062 [year2, month2, day2, ~, ~, ~] = mjulian2greg(time(end));
0063 if ftbverbose
0064 fprintf('time series begins at:\t%04d %02d %02d\n', year1, month1, day1);
0065 fprintf('time series ends at:\t%04d %02d %02d\n', year2, month2, day2);
0066 end
0067 clear year? month? day?
0068
0069
0070
0071
0072
0073
0074 nc = netcdf.create(RiverFile, 'clobber');
0075
0076
0077 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'type', 'FVCOM RIVER FORCING FILE')
0078 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'title', RiverInfo1)
0079 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'info', RiverInfo2)
0080 netcdf.putAtt(nc, netcdf.getConstant('NC_GLOBAL'), 'history', sprintf('File created using %s from the MATLAB fvcom-toolbox', subname))
0081
0082
0083 namelen_dimid = netcdf.defDim(nc, 'namelen', 80);
0084 rivers_dimid = netcdf.defDim(nc, 'rivers', nRivnodes);
0085 time_dimid = netcdf.defDim(nc, 'time', netcdf.getConstant('NC_UNLIMITED'));
0086 date_str_len_dimid = netcdf.defDim(nc, 'DateStrLen', 26);
0087
0088
0089 river_names_varid = netcdf.defVar(nc, 'river_names', 'NC_CHAR', [namelen_dimid, rivers_dimid]);
0090
0091 time_varid = netcdf.defVar(nc, 'time', 'NC_FLOAT', time_dimid);
0092 netcdf.putAtt(nc, time_varid, 'long_name', 'time');
0093 netcdf.putAtt(nc, time_varid, 'units', 'days since 1858-11-17 00:00:00');
0094 netcdf.putAtt(nc, time_varid, 'format', 'modified julian day (MJD)');
0095 netcdf.putAtt(nc, time_varid, 'time_zone', 'UTC');
0096
0097 itime_varid = netcdf.defVar(nc, 'Itime', 'NC_INT', time_dimid);
0098 netcdf.putAtt(nc, itime_varid, 'units', 'days since 1858-11-17 00:00:00');
0099 netcdf.putAtt(nc, itime_varid, 'format', 'modified julian day (MJD)');
0100 netcdf.putAtt(nc, itime_varid, 'time_zone', 'UTC');
0101
0102 itime2_varid = netcdf.defVar(nc, 'Itime2', 'NC_INT', time_dimid);
0103 netcdf.putAtt(nc, itime2_varid, 'units', 'msec since 00:00:00');
0104 netcdf.putAtt(nc, itime2_varid, 'time_zone', 'UTC');
0105
0106 times_varid = netcdf.defVar(nc,'Times','NC_CHAR',[date_str_len_dimid, time_dimid]);
0107 netcdf.putAtt(nc, times_varid, 'time_zone','UTC');
0108
0109 river_flux_varid = netcdf.defVar(nc, 'river_flux', 'NC_FLOAT', [rivers_dimid, time_dimid]);
0110 netcdf.putAtt(nc, river_flux_varid, 'long_name', 'river runoff volume flux');
0111 netcdf.putAtt(nc, river_flux_varid, 'units', 'm^3s^-1');
0112
0113 river_temp_varid = netcdf.defVar(nc, 'river_temp', 'NC_FLOAT', [rivers_dimid, time_dimid]);
0114 netcdf.putAtt(nc, river_temp_varid, 'long_name', 'river runoff temperature');
0115 netcdf.putAtt(nc, river_temp_varid, 'units', 'Celsius');
0116
0117 river_salt_varid = netcdf.defVar(nc, 'river_salt', 'NC_FLOAT', [rivers_dimid, time_dimid]);
0118 netcdf.putAtt(nc, river_salt_varid, 'long_name', 'river runoff salinity');
0119 netcdf.putAtt(nc, river_salt_varid, 'units', 'PSU');
0120
0121
0122 netcdf.endDef(nc);
0123
0124
0125 rString = char();
0126 for i = 1:nRivnodes
0127
0128 rString = [rString, sprintf('%-80s', RiverName{i})];
0129 end
0130 netcdf.putVar(nc, river_names_varid, rString);
0131
0132
0133 netcdf.putVar(nc, time_varid, 0, nTimes, time);
0134 netcdf.putVar(nc, itime_varid, 0, nTimes, floor(time));
0135 netcdf.putVar(nc, itime2_varid, 0, nTimes, mod(time, 1)*24*3600*1000);
0136 netcdf.putVar(nc, river_flux_varid, flux');
0137 netcdf.putVar(nc, river_temp_varid, temp');
0138 netcdf.putVar(nc, river_salt_varid, salt');
0139
0140
0141 nStringOut = char();
0142 [nYr, nMon, nDay, nHour, nMin, nSec] = mjulian2greg(time);
0143 for tt = 1:nTimes
0144 nDate = [nYr(tt), nMon(tt), nDay(tt), nHour(tt), nMin(tt), nSec(tt)];
0145 nStringOut = [nStringOut, sprintf('%04i/%02i/%02i %02i:%02i:%02i ', nDate)];
0146 end
0147 netcdf.putVar(nc, times_varid, nStringOut);
0148
0149 netcdf.close(nc);
0150
0151 if ftbverbose
0152 fprintf('end : %s\n', subname)
0153 end
0154