home = 'E:\Malito\217_Storm Analysis\Model Runs\Flaxman_re\Future';
cd(home)

%%

% define subfolders with model trials within
runsdir1='E:\Malito\212_Flaxman_ReRun\Results\Runs_NoErosion\RCP85_NoEro';


%%
%------ name of variable you are comparing ------%

% variable 1
trim_var1 = vs_use([runsdir1 '\trim-n01.dat'],'quiet');
X.ABS = vs_let(trim_var1,'map-const','XCOR','quiet'); X.ABS = squeeze(X.ABS); X.ABS = X.ABS(1,:);

Fracmat.mud = squeeze(vs_let(trim_var1, 'map-sed-series', 'LYRFRAC', {3 1:length(X.ABS) 1 1}));
Fracmat.sand = squeeze(vs_let(trim_var1, 'map-sed-series', 'LYRFRAC', {3 1:length(X.ABS) 1 2}));

% grab the last timestep
FRC(1,:) = Fracmat.mud(end,:); FRC(2,:) = Fracmat.sand(end,:);

% Check to see if Sand + Mud = 1 for all 
check = FRC(1,1:end-1) + FRC(2,1:end-1);
 %%   -------------- Generate a SAND Fraction File -------------------
% Print this vector into a ASCII fraction.frc file to use in Delft
sand(1:length(FRC),1) = FRC(2,:);
sand(1:length(FRC),2) = FRC(2,:);
sand(1:length(FRC),3) = FRC(2,:);
sand(1:length(FRC),4) = FRC(2,:);

[m,n] = size(sand);
sand = repmat(sand,1,n);
sand(m+1,:) = -999;
sand(:,n+1) = -999;
% write tcd file
name = 'sh';
clear i
fid = fopen(name,'w+');
for i=1:numel(sand(1,:)),
    fprintf(fid,'%f ',sand(:,i));
    fprintf(fid,'\r\n');
end
fclose(fid)
movefile(name,[name '.frc'],'f')
 %%   -------------- Generate a MUD Fraction File -------------------
% Print this vector into a ASCII fraction.frc file to use in Delft
mud(1:length(FRC),1) = FRC(1,:);
mud(1:length(FRC),2) = FRC(1,:);
mud(1:length(FRC),3) = FRC(1,:);
mud(1:length(FRC),4) = FRC(1,:);

[m,n] = size(mud);
mud = repmat(mud,1,n);
mud(m+1,:) = -999;
mud(:,n+1) = -999;
% write tcd file
name = 'mh';
clear i
fid = fopen(name,'w+');
for i=1:numel(mud(1,:)),
    fprintf(fid,'%f ',mud(:,i));
    fprintf(fid,'\r\n');
end
fclose(fid)
movefile(name,[name '.frc'],'f')