Home > utilities > read_FVCOM_river_file.m

read_FVCOM_river_file

PURPOSE ^

function [Riv]=read_river_file(river_root,Mobj)

SYNOPSIS ^

function [Riv]=read_FVCOM_river_file(river_root,Mobj)

DESCRIPTION ^

 function [Riv]=read_river_file(river_root,Mobj)
 Reads FVCOM river files 

 function [Riv]=read_river_file(river_root,Mobj)

 DESCRIPTION:
    Reads both *.nc and *nml files associated with FVCOM river input files

 INPUT
   river_root = full address of river filename without extension 
   Mobj       = needs bathymetry, nodes, elements and triangulation table. 

 OUTPUT:
    Riv       = structure variable with all variables in the file 

 EXAMPLE USAGE
    [Riv]=read_river_file('~/tapas_v0_riv_new',Mobj)

 Author(s):
    Ricardo Torres (Plymouth Marine Laboratory) 

 Revision history

   2018-07-22 First version.

==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Riv]=read_FVCOM_river_file(river_root,Mobj)
0002 % function [Riv]=read_river_file(river_root,Mobj)
0003 % Reads FVCOM river files
0004 %
0005 % function [Riv]=read_river_file(river_root,Mobj)
0006 %
0007 % DESCRIPTION:
0008 %    Reads both *.nc and *nml files associated with FVCOM river input files
0009 %
0010 % INPUT
0011 %   river_root = full address of river filename without extension
0012 %   Mobj       = needs bathymetry, nodes, elements and triangulation table.
0013 %
0014 % OUTPUT:
0015 %    Riv       = structure variable with all variables in the file
0016 %
0017 % EXAMPLE USAGE
0018 %    [Riv]=read_river_file('~/tapas_v0_riv_new',Mobj)
0019 %
0020 % Author(s):
0021 %    Ricardo Torres (Plymouth Marine Laboratory)
0022 %
0023 % Revision history
0024 %
0025 %   2018-07-22 First version.
0026 %
0027 %==============================================================================
0028 [~, subname] = fileparts(mfilename('fullpath'));
0029 global ftbverbose
0030 if ftbverbose
0031     fprintf('\nbegin : %s \n', subname)
0032 end
0033 
0034 % Check if they are in the same order... (a couple of manual test suggest
0035 ncRivers = [river_root '.nc'];
0036 fidnml = fopen ([river_root '.nml']);
0037 % get variables from netcdf file
0038 info = ncinfo(ncRivers);
0039 % extract all variables
0040 varnames={};
0041 for nn =1:length(info.Variables)
0042     varnames{nn}=info.Variables(nn).Name;
0043 end
0044 Riv=[];nn=1;
0045 for vv=varnames
0046 Riv.(vv{1}).data = ncread(ncRivers,vv{1});
0047 if isfloat(Riv.(vv{1}).data)
0048     Riv.(vv{1}).data =double(Riv.(vv{1}).data);
0049     % extract units
0050     for rr = 1:length(info.Variables(nn).Attributes)
0051     if startsWith(info.Variables(nn).Attributes(rr).Name ,'units')
0052     Riv.(vv{1}).units =     info.Variables(nn).Attributes(rr).Value
0053     end 
0054     end
0055 end
0056 nn=nn+1;
0057 end
0058 pos =0;
0059 
0060 while ~feof(fidnml)
0061     pos = pos+1;
0062     lines=cell(3,1);
0063     for dd=1:3
0064         lines{dd} = fgetl(fidnml);
0065         %     fprintf(fout,'%s\n',line)
0066     end
0067     % keep name
0068     [river_name]= extractAfter(lines{2},'= ');
0069     Riv.river_name(pos,1)={river_name(1:end-1)};
0070     % read grid location
0071     line = fgetl(fidnml);
0072     % extract grid location
0073     t =strfind(line,'=');
0074     
0075     Riv.IDX(pos,1) = str2double(line(t+1:end));
0076     % check if IDX is in the list to remove
0077         line1 = fgetl(fidnml);
0078         line2 = fgetl(fidnml);
0079 end
0080 fclose (fidnml);
0081 % extract river positions
0082 for rr=1:length(Riv.IDX)
0083 Riv.lon.data(rr) = Mobj.lon(Riv.IDX(rr,1));
0084 Riv.lat.data(rr) = Mobj.lat(Riv.IDX(rr,1));
0085 Riv.x.data(rr) = Mobj.x(Riv.IDX(rr,1));
0086 Riv.y.data(rr) = Mobj.y(Riv.IDX(rr,1));
0087 end
0088 
0089 % %% for each river estimate the annual cycle mean and river
0090 % % flow/concentration relationship
0091 % % rnut = Riv2.N1_p;
0092 % % read tamar nutrient observations.
0093 % ncfile = fullfile('/data/euryale4/backup/mbe/Experiments/Rosa_rivers/Analysis/tamar_nutrient_nc','gunnislake_dayavg_%s.nc')
0094 % vars = {'si','amm','phs','nitrate','o2'}
0095 % varsR = {'N5_s','N4_n','N1_p','N3_n','O2_o'}
0096 % tamar.time = ncread(sprintf(ncfile,vars{1}),'time');
0097 % for nn=1:length(vars)
0098 % tamar.([varsR{nn},'T']) = ncread(sprintf(ncfile,vars{nn}),'time');
0099 %  tamar.(varsR{nn}) = ncread(sprintf(ncfile,vars{nn}),vars{nn});
0100 % end
0101 %%
0102 Riv.mtime.data = (Riv.time.data+ 678942);
0103 % rr=10;

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005