clear all close all praw=fullfile('..','raw'); pconv=fullfile('..','Processed'); load(fullfile(praw,'sorted_profiles')) load(fullfile(praw,'origins')) outputfile=fullfile(pconv,'micore_ualg_topo.nc'); % find maximum length mxl=max([profs.xl]); dx=0.5; % create crosshore and longshore variables xx=0:dx:mxl; yy=[0 500 1000 1500 2000 700]; nx1=length(xx); ny1=length(yy); % create time variables tmp=[]; for i=1:length(profs) tmp=[tmp ;profs(i).sdates(:)]; end sdates=unique(tmp); nt=length(sdates); % make the final elevation cube inds='ABCDEP'; mat=nan(nx1,ny1,nt); for ii=1:length(sdates) sd=sdates(ii); for i=1:length(profs) [~,ia,ib]=intersect(sd,profs(i).sdates); x1=profs(i).data(ib).xcext; y1=profs(i).data(ib).ycext; nc_create_empty(outputfile); nc_add_dimension(outputfile, 'longshore_distance', ny1); longVariable = struct(... 'Name', 'long_distance', ... 'Nctype', 'float', ... 'Dimension', {{'longshore_distance'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'metre') ... ); nc_addvar(outputfile, longVariable); nc_add_dimension(outputfile, 'crosshore_distance', nx1); crossVariable = struct(... 'Name', 'cross_distance', ... 'Nctype', 'float', ... 'Dimension', {{'crosshore_distance'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'metre') ... ); nc_addvar(outputfile, crossVariable); nc_add_dimension(outputfile, 'time', nt); timeVariable = struct(... 'Name', 'time', ... 'Nctype', 'float', ... 'Dimension', {{'time'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'serial_date') ... ); nc_addvar(outputfile, timeVariable); heightVariable = struct(... 'Name', 'elevation', ... 'Nctype', 'float', ... 'Dimension', {{'longshore_distance', 'crosshore_distance','time'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'metre') ... ); nc_addvar(outputfile, heightVariable); timeVariable = struct(... 'Name', 'time', ... 'Nctype', 'float', ... 'Dimension', {{'time'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'serial_date') ... ); nc_addvar(outputfile, timeVariable); azimuthVariable = struct(... 'Name', 'azimuth', ... 'Nctype', 'float', ... 'Dimension', {{'longshore_distance'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'degrees') ... ); nc_addvar(outputfile, azimuthVariable); x_originvariable = struct(... 'Name', 'originX', ... 'Nctype', 'float', ... 'Dimension', {{'longshore_distance'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'metres') ... ); nc_addvar(outputfile, x_originvariable); y_originvariable = struct(... 'Name', 'originY', ... 'Nctype', 'float', ... 'Dimension', {{'longshore_distance'}}, ... 'Attribute', struct('Name', 'unit', 'Value', 'metres') ... ); nc_addvar(outputfile, y_originvariable); nc_varput(outputfile, 'height', zz) % nc_varput(outputfile, 'year', sdate) nc_varput(outputfile, 'long_distance', xx) nc_varput(outputfile, 'lat_distance', yy) % surface(nc_varget(outputfile, 'height')') nc_dump(outputfile)