Home > utilities > get_polcoms_timeseriesv1.m

get_polcoms_timeseriesv1

PURPOSE ^

ts_controlfile='/users/modellers/rito/Models/MEDINA/tseries.MEDI29'

SYNOPSIS ^

function [polcoms]=get_polcoms_timeseriesv1(rootfname,ts_controlfile,Mobj,inputConf,tseries_dir,mm,polcoms)

DESCRIPTION ^

ts_controlfile='/users/modellers/rito/Models/MEDINA/tseries.MEDI29'
tseries_dir='/data/perseus1/to_archive/suka_VECTORS/MEDI29_RA/physseries_MEDI29_2000';
tseries_dir='/users/modellers/rito/Models/MEDINA/polcoms/physseries_MEDI29.2006';

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [polcoms]=get_polcoms_timeseriesv1(rootfname,ts_controlfile,Mobj,inputConf,tseries_dir,mm,polcoms)
0002 %ts_controlfile='/users/modellers/rito/Models/MEDINA/tseries.MEDI29'
0003 %tseries_dir='/data/perseus1/to_archive/suka_VECTORS/MEDI29_RA/physseries_MEDI29_2000';
0004 %tseries_dir='/users/modellers/rito/Models/MEDINA/polcoms/physseries_MEDI29.2006';
0005 
0006 % Run jobs on multiple workers if we have that functionality. Not sure if
0007 % it's necessary, but check we have the Parallel Toolbox first.
0008 
0009 
0010 %%
0011 % Read Tseries file with number and locations of timeseries
0012 nvars2 = 9;
0013 var_names2 = {'u','v','temp','sal','aa','ak','qsq','al','iop'};
0014 %%
0015 
0016 fid = fopen(ts_controlfile);
0017 nstations = textscan(fid, '%u',1);
0018 C=  textscan(fid, '%u%u%f%f',nstations{1});
0019 fclose(fid);
0020 [lat,lon]=deal(C{3},C{4});
0021 [polcoms_i,polcoms_j]=deal(C{1},C{2});
0022 clear C
0023 % convert lat and lon to utm
0024 % Convert the small subdomain into cartesian coordinates.
0025 tmpZone = regexpi(inputConf.utmZone,'\ ','split');
0026 [tseries.x, tseries.y] = wgs2utm(lat(:), lon(:), str2double(char(tmpZone{1}(1))), 'N');
0027 
0028 % Select points in the FVCOM domain (near the boundary as determined in
0029 % Mobj
0030 distance = abs(complex(tseries.x,tseries.y)-complex(nanmean(Mobj.x),nanmean(Mobj.y)));
0031 dist_lim = mode(distance);
0032 igood=find(distance < dist_lim*5);
0033 %%
0034 
0035 % build timeseries filenames for the time range under consideration
0036 % read timeseries files. Make sure the correct variables in the files are
0037 % read. We need a map of variables on the file
0038 inputConf.zetUVfile=fullfile(tseries_dir,['zet_UBVB.',rootfname,'.',num2str(inputConf.modelYear),'.',num2str(mm,'%02d')]);
0039 inputConf.PolcomsPoints=[polcoms_i(igood),polcoms_j(igood)];
0040 % timeseries doesn't have information about the depth levels. Actual depths
0041 % need to be calculated from total depth and scoord distribution.
0042 
0043 
0044 % extract positions lat and lon at interest points
0045 polcoms.bcidx=sub2ind(size(polcoms.latb),inputConf.PolcomsPoints(:,1),inputConf.PolcomsPoints(:,2));
0046 latb=polcoms.latb(polcoms.bcidx);
0047 lonb=polcoms.lonb(polcoms.bcidx);
0048 [polcoms.bcxb, polcoms.bcyb] = wgs2utm(latb(:), lonb(:), str2double(char(tmpZone{1}(1))), 'N');
0049 latu=polcoms.latu(polcoms.bcidx);
0050 lonu=polcoms.lonu(polcoms.bcidx);
0051 [polcoms.bcxu, polcoms.bcyu] = wgs2utm(latu(:), lonu(:), str2double(char(tmpZone{1}(1))), 'N');
0052 
0053 % obtain depth levels for each station
0054 % depth levels at each station need reconstructing because polcoms timeseries files do not
0055 % include information on the depth levels.
0056 [polcoms.xb, polcoms.yb] = wgs2utm(polcoms.latb(:), polcoms.lonb(:), str2double(char(tmpZone{1}(1))), 'N');
0057 [polcoms.xu, polcoms.yu] = wgs2utm(polcoms.latu(:), polcoms.lonu(:), str2double(char(tmpZone{1}(1))), 'N');
0058 
0059 fdb = TriScatteredInterp(polcoms.xb(:), polcoms.yb(:), polcoms.bathy(:), 'natural');
0060 % interpolate bathymetry onto boundary points (b and u points)
0061 polcoms.bchb=fdb(polcoms.bcxb,polcoms.bcyb);
0062 polcoms.bchu=fdb(polcoms.bcxu, polcoms.bcyu);
0063 % and onto fvcom bc positions (I don't think I need this)
0064 % polcoms.hb=fdb(Mobj.x(oNodes),Mobj.y(oNodes));
0065 % polcoms.hu=fdb(Mobj.xc(oElems),Mobj.yc(oElems));
0066 polcoms.igood=igood;
0067 
0068 %%
0069 
0070 
0071 for ff=1:length(igood)
0072     fname =fullfile(tseries_dir,['physseries.',num2str(igood(ff)),'.',rootfname,'.',num2str(inputConf.modelYear),'.',num2str(mm,'%02d')]);
0073     cleanfile =fullfile(tseries_dir,'cleanfile');
0074     clean_statement=['sed ''s/^\**/0/g'' ' , fname,' > ',cleanfile];
0075     system(clean_statement);
0076     data = load(cleanfile);
0077     jday = data(:,1);data(:,1)=[];
0078     jday = reshape(jday,nvars2,[]);
0079     [~,ntimes]=size(jday);
0080     [~,ndepths]=size(data);
0081     
0082      jday = jday(1,:);jday = repmat(jday,[ndepths 1]);
0083     for nn=1:length(var_names2)
0084         polcoms.(var_names2{nn})(ff,:,:) = data(nn:length(var_names2):end,:)'./1000;
0085     end
0086      polcoms.jday(ff,:,:) = jday/24;
0087     
0088 end
0089 % Generate timerecord from filename and length of data
0090 polcoms.time=datenum(inputConf.modelYear,mm,1):1/24:(size(polcoms.jday,3)-1)/24+datenum(inputConf.modelYear,mm,1);
0091 inputConf.PolcomsLevs=ndepths;
0092 
0093 % read zetUBVB file to extract surface elevation
0094 [dumpstruct]=readzetUBVB(inputConf,ntimes);
0095 polcoms=catstruct(dumpstruct,polcoms);
0096 polcoms.ndepths=ndepths;
0097 polcoms.ntimes=ntimes;
0098 return
0099 % make surface timeseries of 2d variables (zet, ub and vb)
0100 % build timeseries matrix for each variable
0101 
0102 
0103 % output as netcdf file in expected format for latest FVCOM 3.2
0104 
0105 % Close the MATLAB pool if we opened it.
0106

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