function profiles = loadprofiles(foldername,varargin) % loadprofiles.m Copyright (C) Matt Wilson, 7 May 2009 % http://mattwilson.eu % % Uses readprofile to load in all LISFLOOD-FP channel profile output files % in a given folder into a structure. Simply call the function with the % folder name as input, and all profiles in that folder will be loaded into % a structure indexed by the model output number. % % Usage: % profiles = loadprofiles(foldername); % % where foldername is a string containing the name of the output folder. A % list of files to ignore may be provided after the foldername: % % profiles = loadprofiles(foldername,'ignoreme.profile'); % profiles = loadprofiles(foldername,ignorelist); % % where ignorelist is a cell array containing a series of strings of the % filenames to ignore. Note that the function will fully handle files % compressed with gzip, and there is no need to specify whether files % should be uncompressed or not. % % The structure returned will a structure with the following fields: % filename % data % % filename is the name of profile file and data is a structure with the % profile data. Once loaded, the following code will animate through the % water surface elevation profile of the first channel segment: % % for i = 1:length(profiles) % c = profiles(i).data.Chainage; we = profiles(i).data.WaterElev; % plot(c,we),title(profiles(i).filename),pause(0.1) % end % % % See also: readprofile % % Released under the GNU General Public Licence, version 3 % http://www.gnu.org/licenses/ % % This program is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program. If not, see . % ignorelist = []; if nargin > 1 ignorelist = varargin{1}; end % get list of files from folder: fdir = dir(foldername); profiles = struct; callgzip = 0; ignore=0; % scan through files and load profiles into the profiles struct for i = 2:1:length(fdir) if ~isempty(findstr('.profile',fdir(i).name)) && isempty(findstr('-T.profile',fdir(i).name)) % check if file is on ignore list if ~isempty(ignorelist) if iscell(ignorelist) for j = 1:length(ignorelist) if strcmp(ignorelist{j},fdir(i).name), ignore=1; break; else ignore=0; end end else if strcmp(ignorelist,fdir(i).name), ignore=1; else ignore=0; end end end if ignore==0 % get number from filename num = fdir(i).name(findstr('-',fdir(i).name)+1:findstr('.profile',fdir(i).name)-1); pindex = str2double(num)+1; if ~isnan(pindex) % check whether file is compressed with gzip if strcmp(fdir(i).name(end-2:end),'.gz') callgzip=1; fdir(i).name = fdir(i).name(1:end-3); % strip off .gz ending else callgzip=0; end profiles(pindex).filename = fdir(i).name; % load profile data if callgzip==1 profiles(pindex).data = readprofile([foldername '\' fdir(i).name],'-gzip'); else profiles(pindex).data = readprofile([foldername '\' fdir(i).name]); end end end end end