Home > fvcom_prepro > write_FVCOM_river.m

write_FVCOM_river

PURPOSE ^

write FVCOM 3.x NetCDF river file

SYNOPSIS ^

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

DESCRIPTION ^

 write FVCOM 3.x NetCDF river file

 function write_FVCOM_river(RiverFile,RiverName,nRivnodes,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

 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
   
 OUTPUT:
    FVCOM RiverFile with flux,temp,salt

 EXAMPLE USAGE
  write_FVCOM_river('tst_riv.nc','Penobscot',3,time,flux,salt,'Penobscot Flux','source: USGS')  

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: 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
0003 %
0004 % function write_FVCOM_river(RiverFile,RiverName,nRivnodes,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)
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);
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';  
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;
0146 
0147 nc = 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