<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://source.geography.bristol.ac.uk/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jeff-neal</id>
	<title>SourceWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://source.geography.bristol.ac.uk/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jeff-neal"/>
	<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/wiki/Special:Contributions/Jeff-neal"/>
	<updated>2026-04-06T01:18:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.8</generator>
	<entry>
		<id>https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5167</id>
		<title>LISFLOOD-FP and MATLAB</title>
		<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5167"/>
		<updated>2008-05-14T11:09:07Z</updated>

		<summary type="html">&lt;p&gt;Jeff-neal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains various Matlab functions that may be useful for analysing results from the [http://www.ggy.bris.ac.uk/research/hydrology/models/lisflood LISFLOOD-FP] model.&lt;br /&gt;
&lt;br /&gt;
==File import and export==&lt;br /&gt;
&lt;br /&gt;
===Importing ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will import an ascii raster file using the string filename. To use it, copy and past text into a textfile called ascii_reader.m&lt;br /&gt;
&lt;br /&gt;
 function [dem, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % This function reads arc .asc files&lt;br /&gt;
 % requires filename string as input&lt;br /&gt;
 &lt;br /&gt;
 % j neal&lt;br /&gt;
 % 18/6/07&lt;br /&gt;
 %% read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 dem = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 dem = dem';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
You can view the imported file using the command:&lt;br /&gt;
&lt;br /&gt;
 imagesc(dem);&lt;br /&gt;
&lt;br /&gt;
===Exporting ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will create an ascii raster file called filename from the 2D matrix DEM.  To use it, copy and past text into a textfile called ascii_write.m&lt;br /&gt;
&lt;br /&gt;
 function ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 &lt;br /&gt;
 % ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 % only filename (string) and DEM (2D matrix) are essential&lt;br /&gt;
 % this function writes ascii raster files for arc&lt;br /&gt;
 % j neal&lt;br /&gt;
 % 6/3/2008&lt;br /&gt;
 &lt;br /&gt;
 if nargin &amp;lt; 2, &lt;br /&gt;
     error('Requires at least two input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4, &lt;br /&gt;
     xllcorner = 0;&lt;br /&gt;
     yllcorner = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 5,&lt;br /&gt;
     cellsize = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 6&lt;br /&gt;
     nodata = -9999;&lt;br /&gt;
 end&lt;br /&gt;
 A = size(DEM);&lt;br /&gt;
 fout = fopen (filename,'w');&lt;br /&gt;
 fprintf(fout, 'ncols         %.0f\n', A(2));  &lt;br /&gt;
 fprintf(fout, 'nrows         %.0f\n', A(1));&lt;br /&gt;
 fprintf(fout, 'xllcorner     %f\n', xllcorner);&lt;br /&gt;
 fprintf(fout, 'yllcorner     %f\n', yllcorner);&lt;br /&gt;
 fprintf(fout, 'cellsize      %f\n', cellsize);&lt;br /&gt;
 fprintf(fout, 'NODATA_value  %f\n', nodata); &lt;br /&gt;
 for ii = 1:A(1)&lt;br /&gt;
     B = DEM(ii,:);&lt;br /&gt;
     fprintf(fout, '%1.3f ', B);&lt;br /&gt;
     fprintf(fout, '\n');&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
===Importing .profile files===&lt;br /&gt;
&lt;br /&gt;
This function imports .profile files&lt;br /&gt;
&lt;br /&gt;
 function [data, M] = profileread (resroot, numfiles, t, string1, string2)&lt;br /&gt;
 &lt;br /&gt;
 % This function reads LISFLOOD-FP .profile files&lt;br /&gt;
 %&lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT)&lt;br /&gt;
 %   where RESROOT is a string containing the resroot from the LISFLOOD-FP&lt;br /&gt;
 %   .par file. Absolute path names can also be used e.g. 'C:\LISFLOOD\resroot'&lt;br /&gt;
 %   DATA is a structure containing .header {cell aray}&lt;br /&gt;
 %                                  .segmentN (numerical array for segment N)&lt;br /&gt;
 %&lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT, NUMFILES)&lt;br /&gt;
 %   NUMFILES = number of files to read. Reads m files assuming that the files &lt;br /&gt;
 %   are numbered such that resroot-000m.profile. &lt;br /&gt;
 %   DATA(m) is a structure containing m files&lt;br /&gt;
 % &lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT, NUMFILES, 1)&lt;br /&gt;
 %   specifies the profiles were exported a user specified time such that&lt;br /&gt;
 %   resroot-000x-t.profile&lt;br /&gt;
 %&lt;br /&gt;
 % [DATA, M] = PROFILEREAD (RESROOT, NUMFILES, 1, string1, string2)&lt;br /&gt;
 %   instructs the function to plot string1 or sting1 against string2... these&lt;br /&gt;
 %   strings muct match the headernames in the .profile file e.g. 'Flow'&lt;br /&gt;
 %   returns movieframes in the structure M. Also plots the data.&lt;br /&gt;
 %&lt;br /&gt;
 % Note: LISFLOOD-FP will name multiple files 0 to m-1 but DATA(m) will count from 1 to m&lt;br /&gt;
 %&lt;br /&gt;
 % j.neal&lt;br /&gt;
 % 12/5/2008&lt;br /&gt;
 %%&lt;br /&gt;
 if nargin &amp;lt; 1, &lt;br /&gt;
    error('Requires filename'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 2,&lt;br /&gt;
    % only one file&lt;br /&gt;
    numfiles = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 2,&lt;br /&gt;
    t = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4,&lt;br /&gt;
    % no plotting required&lt;br /&gt;
    plotting = 0;&lt;br /&gt;
    M = 0;&lt;br /&gt;
 elseif nargin &amp;lt; 5,&lt;br /&gt;
    % use plotter&lt;br /&gt;
    plotting = 1;&lt;br /&gt;
 elseif nargin &amp;lt; 6,&lt;br /&gt;
    plotting = 2;&lt;br /&gt;
 end&lt;br /&gt;
 %% Arrange data read&lt;br /&gt;
 if t == 1&lt;br /&gt;
    fileex = '-t.profile';&lt;br /&gt;
 else&lt;br /&gt;
    fileex = '.profile';&lt;br /&gt;
 end&lt;br /&gt;
 if numfiles == 0&lt;br /&gt;
    % read in a single .profile file&lt;br /&gt;
    filename = [resroot,fileex];&lt;br /&gt;
    data = read_profile (filename);&lt;br /&gt;
 elseif numfiles &amp;lt; 9999&lt;br /&gt;
    % read a series of .profile files&lt;br /&gt;
    for i = 1:numfiles&lt;br /&gt;
        ii = i-1;&lt;br /&gt;
        if ii &amp;lt; 10&lt;br /&gt;
            resroot2 = [resroot,'-000',num2str(ii),fileex];&lt;br /&gt;
        elseif ii &amp;lt; 100&lt;br /&gt;
            resroot2 = [resroot,'-00',num2str(ii),fileex];&lt;br /&gt;
        elseif ii &amp;lt; 1000&lt;br /&gt;
            resroot2 = [resroot,'-0',num2str(ii),fileex];&lt;br /&gt;
        else&lt;br /&gt;
            resroot2 = [resroot,'-',num2str(ii),fileex];&lt;br /&gt;
        end&lt;br /&gt;
        %returnes structure with format data(i).segmentX... also includes .header &lt;br /&gt;
        [data(i), seg_num] = read_profile (resroot2); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
    end&lt;br /&gt;
 else&lt;br /&gt;
    error ('Too many files or incorrect input to numfiles'); &lt;br /&gt;
 end&lt;br /&gt;
 %% Plotting under development&lt;br /&gt;
 % account for 0 seg num&lt;br /&gt;
 seg_num = seg_num +1;&lt;br /&gt;
 % if plotting == 0 % do nothing... no plots&lt;br /&gt;
 if plotting == 1&lt;br /&gt;
    % find the column you want to plot&lt;br /&gt;
    I = strmatch(string1 , data(1).header);&lt;br /&gt;
    % plot a single variable&lt;br /&gt;
    A = size(data);&lt;br /&gt;
    for i = 1:A(2)&lt;br /&gt;
        figure(i);&lt;br /&gt;
        for j = 1:seg_num&lt;br /&gt;
            k = j-1;&lt;br /&gt;
            subplot(1,seg_num,j);&lt;br /&gt;
            eval(['plot(data(i).segment',num2str(k),'(:,',num2str(I),'));']);&lt;br /&gt;
            tstring = ['Plot of ',resroot,num2str(i),' segment ',num2str(k)];  &lt;br /&gt;
            title(tstring);&lt;br /&gt;
            % get movie frame&lt;br /&gt;
            M(i,j) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
 elseif plotting == 2&lt;br /&gt;
    % find the columns you want to plot&lt;br /&gt;
    I = strmatch(string1 , data(1).header);&lt;br /&gt;
    I2 = strmatch(string2 , data(1).header);&lt;br /&gt;
    A = size(data);&lt;br /&gt;
    for i = 1:A(2)&lt;br /&gt;
        figure(i);&lt;br /&gt;
        for j = 1:seg_num&lt;br /&gt;
            k = j-1;&lt;br /&gt;
            subplot(1,seg_num,j);&lt;br /&gt;
            eval(['plot(data(i).segment',num2str(k),'(:,',num2str(I),'),data(i).segment',num2str(k),'(:,',num2str(I2),'));']);&lt;br /&gt;
            % get movie frame&lt;br /&gt;
            tstring = ['Plot of ',resroot,num2str(i),' segment ',num2str(k)];  &lt;br /&gt;
            title(tstring);&lt;br /&gt;
            M(i,j) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
 %% read .profile file&lt;br /&gt;
 function [data, seg_num] = read_profile (filename) &lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 more_segs = 1;&lt;br /&gt;
 % read 'Channel_segment:' from file&lt;br /&gt;
 temp = fscanf(fin,'%s',1); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 while more_segs == 1&lt;br /&gt;
    % read filename&lt;br /&gt;
    seg_num = fscanf(fin,'%f',1);&lt;br /&gt;
    for i = 1:11&lt;br /&gt;
        data.header{i} = fscanf(fin,'%s',1);&lt;br /&gt;
    end&lt;br /&gt;
    testline = 1;&lt;br /&gt;
    j = 0;&lt;br /&gt;
    while testline == 1&lt;br /&gt;
        j = j+1;&lt;br /&gt;
        % reads the first bit of the line as a string&lt;br /&gt;
        A = fscanf(fin, '%s',1);&lt;br /&gt;
        % this string is either a numer of a new channel sgment of the end&lt;br /&gt;
        % of the file&lt;br /&gt;
        % if end of file&lt;br /&gt;
        ST = feof (fin);&lt;br /&gt;
        if ST == 1&lt;br /&gt;
            % reached the end of the file exit both while loops&lt;br /&gt;
            testline = 0;&lt;br /&gt;
            more_segs = 0;&lt;br /&gt;
        else&lt;br /&gt;
            TF = strcmp('Channel_segment:', A);&lt;br /&gt;
            if TF == 1&lt;br /&gt;
                % new segment has been found&lt;br /&gt;
                testline = 0;&lt;br /&gt;
            else&lt;br /&gt;
                % read rest for line into data&lt;br /&gt;
                B(j,1) = str2double(A); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
                for k = 2:11&lt;br /&gt;
                    B(j,k) = fscanf(fin, '%f',1); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
                 end&lt;br /&gt;
             end&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
     eval(['data.segment',num2str(seg_num),' = B;']);&lt;br /&gt;
     clear B&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Writing parameter files===&lt;br /&gt;
&lt;br /&gt;
This function can be used to write many LISFLOOD-FP parameter files with ''N'' different channel and floodplain roughness, using your own ''N-by-''2 matrix called roughness. You will need to edit the code for your application by commenting unwanted lines with a percentage symbol.&lt;br /&gt;
&lt;br /&gt;
 function prm_writer (roughness) &lt;br /&gt;
 &lt;br /&gt;
 % This function writes LISFLOOD-FP parameter files numbered 1 to n using&lt;br /&gt;
 % the roughness values in the n-by-2 matrix roughness. yuo will need to&lt;br /&gt;
 % edit the code for your application.&lt;br /&gt;
 &lt;br /&gt;
 [num_sims] = size(roughness);&lt;br /&gt;
 for i = 1:num_sims(1)&lt;br /&gt;
 a = ['mymodel', num2str(i),'.par']; b = num2str(i);&lt;br /&gt;
 fout = fopen(a,'w');&lt;br /&gt;
 fprintf(fout,'DEMfile                  mydem.dem.ascii\n');&lt;br /&gt;
 fprintf(fout,'resroot                  myres%s\n',b);&lt;br /&gt;
 fprintf(fout,'dirroot                  mydir\n');&lt;br /&gt;
 fprintf(fout,'sim_time                 245000.0\n');&lt;br /&gt;
 fprintf(fout,'initial_tstep            10.0\n');&lt;br /&gt;
 fprintf(fout,'massint                  300.0\n');&lt;br /&gt;
 fprintf(fout,'saveint                  10000.0\n');&lt;br /&gt;
 %fprintf(fout,'overpass                 135000.0\n');&lt;br /&gt;
 fprintf(fout,'fpfric                   %1.3f\n',roughness(i,2));&lt;br /&gt;
 fprintf(fout,'nch                      %1.3f\n',roughness(i,1));&lt;br /&gt;
 %fprintf(fout,'manningfile              mymanfile%s.n.ascii\n',b);&lt;br /&gt;
 fprintf(fout,'riverfile                myriver.river\n');&lt;br /&gt;
 fprintf(fout,'bdyfile                  mybdy.bdy\n');&lt;br /&gt;
 fprintf(fout,'stagefile                mystage.stage\n');&lt;br /&gt;
 fprintf(fout,'bcifile                  mybci.bci\n');&lt;br /&gt;
 %fprintf(fout,'startfile                mystart.old\n');&lt;br /&gt;
 %fprintf(fout,'checkpoint               2\n');&lt;br /&gt;
 %fprintf(fout,'checkfile                mycheck.chkpnt\n');&lt;br /&gt;
 fprintf(fout,'elevoff\n');&lt;br /&gt;
 fprintf(fout,'qoutput\n');&lt;br /&gt;
 fprintf(fout,'diffusive\n');&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==Plotting flow vectors from .Qx and .Qy files==&lt;br /&gt;
&lt;br /&gt;
This function will plot flow vectors from a .Qx and .Qy over a dem using the matlab functions image and quiver  &lt;br /&gt;
&lt;br /&gt;
 function lisflood_flow_plotter (qxfile, qyfile, demfile, north, east, south, west, scaling)&lt;br /&gt;
 &lt;br /&gt;
 % This function plots flow vectors from LISFLOOD_FP Qx and QY files&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile);&lt;br /&gt;
 %&lt;br /&gt;
 % these input variables are strings containing the relative of full&lt;br /&gt;
 % pathnames of the .Qx .Qy and ascii dem files to be plotted.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W);&lt;br /&gt;
 %&lt;br /&gt;
 % N, E, W and S are optional they specify the northernmost, southeernmost&lt;br /&gt;
 % ect cell to be displayed. this can be used to crop the domain.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W, scaling);&lt;br /&gt;
 % &lt;br /&gt;
 % scaling is an optional term used to manually scale the vector lengthes&lt;br /&gt;
 % drawn by quiver (the arrow plotting function).&lt;br /&gt;
 %&lt;br /&gt;
 % J Neal&lt;br /&gt;
 % 20/02/2008 &lt;br /&gt;
 &lt;br /&gt;
 %% decide if crop is required and give imput error message&lt;br /&gt;
 if nargin &amp;lt; 3, &lt;br /&gt;
     error('Requires at least three input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7, &lt;br /&gt;
     crop = 0;&lt;br /&gt;
 else&lt;br /&gt;
     crop = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7,&lt;br /&gt;
     scaling = 1;&lt;br /&gt;
 end &lt;br /&gt;
 % Note don't do this for large areas ?&lt;br /&gt;
 %% Task 1: read ascii files&lt;br /&gt;
 % read Qx file&lt;br /&gt;
 [QX, ncolsqx, nrowsqx, xllcornerqx, yllcornerqx, cellsizeqx] = read_file (qxfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read Qy file&lt;br /&gt;
 [QY, ncolsqy, nrowsqy, xllcornerqy, yllcornerqy, cellsizeqy] = read_file (qyfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read DEM&lt;br /&gt;
 [DEM, ncolsdem, nrowsdem, xllcornerdem, yllcornerdem, cellsizedem] = read_file (demfile);&lt;br /&gt;
 %% crop data if required&lt;br /&gt;
 if crop == 1;&lt;br /&gt;
     DEM = DEM(north:south,west:east);&lt;br /&gt;
     QX = QX(north:south,west:east+1);&lt;br /&gt;
     QY = QY(north:south+1,west:east);&lt;br /&gt;
     xllcornerdem = xllcornerdem + west*cellsizedem - cellsizedem;&lt;br /&gt;
     yllcornerdem = yllcornerdem + (nrowsdem - south) * cellsizedem;&lt;br /&gt;
     [nrowsqx, ncolsqx] = size(QX); [nrowsqy, ncolsqy] = size(QY); [nrowsdem, ncolsdem] = size(DEM);&lt;br /&gt;
 end&lt;br /&gt;
 %% Taks 2: Plot dem and generate figure&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap('gray');&lt;br /&gt;
 % Create axes&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcornerdem + nrowsdem*cellsizedem ,yllcornerdem},...&lt;br /&gt;
     'YTick',[0.5,nrowsdem+0.5],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcornerdem,xllcornerdem+ncolsdem*cellsizedem},...&lt;br /&gt;
     'XTick',[0.5, ncolsdem + 0.5],...&lt;br /&gt;
     'Layer','top',...&lt;br /&gt;
     'DataAspectRatio',[1 1 1]...&lt;br /&gt;
     %,'Clim',[13 30]... % uncomment to set colourmap limits manually&lt;br /&gt;
     );&lt;br /&gt;
 &lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM,'Parent',axes1,'CDataMapping','scaled');&lt;br /&gt;
 axis('image');&lt;br /&gt;
 xlabel('Easting (m)');&lt;br /&gt;
 ylabel('Northing (m)');&lt;br /&gt;
 %% Task 3: calculate flow vectors&lt;br /&gt;
 % pre allocate memory for loop... it will run faster this way&lt;br /&gt;
 xlocs = zeros(ncolsqx*nrowsqx+ncolsqy*nrowsqy,1);&lt;br /&gt;
 ylocs = xlocs;&lt;br /&gt;
 U = xlocs;&lt;br /&gt;
 V = xlocs;&lt;br /&gt;
 %work out X and Y locations&lt;br /&gt;
 for i = 1:nrowsqx&lt;br /&gt;
     for j = 1:ncolsqx&lt;br /&gt;
         xlocs((i-1)*ncolsqx+j,1) = j - 0.5;&lt;br /&gt;
         ylocs((i-1)*ncolsqx+j,1) = i;&lt;br /&gt;
         U((i-1)*ncolsqx+j,1) = QX(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 for i = 1:nrowsqy&lt;br /&gt;
     for j = 1:ncolsqy&lt;br /&gt;
         xlocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = j;&lt;br /&gt;
         ylocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = i - 0.5;&lt;br /&gt;
         V(ncolsqx*nrowsqx+(i-1)*ncolsqy+j,1) = QY(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % work out number of nonzeros elements&lt;br /&gt;
 num_flows = nnz(U+V);&lt;br /&gt;
 xlocs2 = zeros(num_flows,1);&lt;br /&gt;
 ylocs2 = xlocs2;&lt;br /&gt;
 U2 = xlocs2;&lt;br /&gt;
 V2 = xlocs2;&lt;br /&gt;
 % remover zero flow locations&lt;br /&gt;
 k = 1;&lt;br /&gt;
 for i = 1:ncolsqx*nrowsqx+ncolsqy*nrowsqy&lt;br /&gt;
     if (U(i,1) == 0) &amp;amp;&amp;amp; (V(i,1) == 0)&lt;br /&gt;
         % do nothing&lt;br /&gt;
     else&lt;br /&gt;
         xlocs2(k,1) = xlocs(i,1);&lt;br /&gt;
         ylocs2(k,1) = ylocs(i,1);&lt;br /&gt;
         U2(k,1) = U(i,1);&lt;br /&gt;
         V2(k,1) = V(i,1);&lt;br /&gt;
         k = k+1;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % check numbers are correct&lt;br /&gt;
 if k == num_flows + 1&lt;br /&gt;
     % all is ok&lt;br /&gt;
 else&lt;br /&gt;
     disp('Problem with flows');&lt;br /&gt;
 end&lt;br /&gt;
 %% Task 4: overlay flow vectors&lt;br /&gt;
 disp('Plotting data... if this is taking a long time you may need fewer locations');&lt;br /&gt;
 quiver (xlocs2,ylocs2,U2,V2, scaling);&lt;br /&gt;
 % quiver (xloc2,yloc2,U2,V2,'Parent',figure1);&lt;br /&gt;
 disp('Done');&lt;br /&gt;
 %% function to read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
==Making movies from .wd files==&lt;br /&gt;
&lt;br /&gt;
This function will convert a series of .wd .Qx or .Qy file into a .avi movie with the same filename&lt;br /&gt;
&lt;br /&gt;
 function LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ) &lt;br /&gt;
 &lt;br /&gt;
 % LISFLOOD_mov generates movies of LISFLOOD-FP output&lt;br /&gt;
 %&lt;br /&gt;
 % LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ)&lt;br /&gt;
 % &lt;br /&gt;
 % where &lt;br /&gt;
 % resroot is the LISFLOOD resroot (relative to m file or absolute)(string)&lt;br /&gt;
 % fileex is the file extension '.wd' (can be chaned to plot WSE and flows)&lt;br /&gt;
 % vartype is the name of the variable being plotted e.g. 'Depth'&lt;br /&gt;
 % num_snaps is the number of snapshot times&lt;br /&gt;
 % snapint is the time interval between each LISFLOOD-FP snapshot (seconds)&lt;br /&gt;
 % dem is the name of the demfile (relative or absolute)&lt;br /&gt;
 % demCS is the range of dem hights to be plotted e.g. demCS = [0,20];&lt;br /&gt;
 % depthCS is the range of depth values to be plotted e.g. depthCS = [0,10];&lt;br /&gt;
 % framesPS number of frames per second (each plot is a simgle frame)&lt;br /&gt;
 % movQ is the movie quality between 1 and 100 (100 is best)&lt;br /&gt;
 % &lt;br /&gt;
 % 8/11/2007. J Neal.&lt;br /&gt;
 %&lt;br /&gt;
 % EXAMPLE:&lt;br /&gt;
 % LISFLOOD_mov ('C:\Experiment1\res22','.wd','Water depth',24,10000,...&lt;br /&gt;
 % 'C:\Experiment1\dem10m.dem.ascii',[0,60], [0,10],1,100);&lt;br /&gt;
 %% Movie maker&lt;br /&gt;
 % read dem filenam is filename and 1 specifies the 0.00 should not be NaN's&lt;br /&gt;
 [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (dem); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 % A = [resroot,'.avi'];&lt;br /&gt;
 % mov = avifile(A);&lt;br /&gt;
 % loop through snapshots&lt;br /&gt;
 for i = 1:num_snaps&lt;br /&gt;
     if i &amp;lt; 10&lt;br /&gt;
         resfile = [resroot,'-000',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 100&lt;br /&gt;
         resfile = [resroot,'-00',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 1000&lt;br /&gt;
         resfile = [resroot,'-0',num2str(i),fileex];&lt;br /&gt;
     else&lt;br /&gt;
         resfile = [resroot,'-',num2str(i),fileex];&lt;br /&gt;
     end&lt;br /&gt;
     % read in deoth file for resfile i (2 specifies the 0.00 should be NaN&lt;br /&gt;
     [DEPTH, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (resfile);&lt;br /&gt;
     % plot data as figure 1&lt;br /&gt;
     plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype);&lt;br /&gt;
     % get movie frame&lt;br /&gt;
     M(i) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     hold off;&lt;br /&gt;
 %     mov = addframe(mov,M(i));&lt;br /&gt;
     % close the figure&lt;br /&gt;
     close all&lt;br /&gt;
 end &lt;br /&gt;
 % % close .avi file&lt;br /&gt;
 % mov = close(mov);&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 disp('Generating .avi movie file');&lt;br /&gt;
 A = [resroot,fileex,'.avi'];&lt;br /&gt;
 movie2avi(M,A,'fps',framesPS,'quality',movQ);&lt;br /&gt;
 disp(A);&lt;br /&gt;
 %% Read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 % convert nodata to NaN;&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if OUT(ii,jj) == nodata&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         elseif OUT(ii,jj) == -99.000&lt;br /&gt;
             % lisflood uses -99.000 as nodat so will also remove these&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         else&lt;br /&gt;
             % do nothing&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% Plotter data for movie slide&lt;br /&gt;
 function plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype)&lt;br /&gt;
 % number of colors in colormap&lt;br /&gt;
 num_colors = 64;&lt;br /&gt;
 % DEM and variable color map&lt;br /&gt;
 cmap = [gray(num_colors); jet(num_colors)];&lt;br /&gt;
 % scale DEM and DEPTH data to fit with new colormap&lt;br /&gt;
 demCS2 = demCS(2)-demCS(1);&lt;br /&gt;
 dem_scalar = num_colors/demCS2;&lt;br /&gt;
 DEM2 = DEM*dem_scalar;&lt;br /&gt;
 depthCS2 = depthCS(2)-depthCS(1);&lt;br /&gt;
 depth_scalar = num_colors/depthCS2;&lt;br /&gt;
 DEPTH2 = (DEPTH*depth_scalar)+num_colors+1;&lt;br /&gt;
 %Plot the DEM&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap(cmap);&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcorner+(nrows*cellsize),yllcorner+cellsize},...&lt;br /&gt;
     'YTick', [1,nrows],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcorner,xllcorner+(ncols*cellsize)-cellsize},...&lt;br /&gt;
     'XTick',[1,ncols],...&lt;br /&gt;
     'Layer','top');&lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM2,'Parent',axes1);&lt;br /&gt;
 axis('equal');axis('tight');&lt;br /&gt;
 % Overlay the water depth (or other variable)&lt;br /&gt;
 H = image(DEPTH2);&lt;br /&gt;
 % code to make depth plot layer transparent&lt;br /&gt;
 OP = ones(nrows,ncols);&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if DEPTH(ii,jj) &amp;gt; 0&lt;br /&gt;
         else&lt;br /&gt;
             OP(ii,jj) = 0;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % make transparent. depth layer must be H&lt;br /&gt;
 set(H,'AlphaData',OP);&lt;br /&gt;
 % label colourbar&lt;br /&gt;
 color_breaks = 5;&lt;br /&gt;
 colorbreak = num_colors/color_breaks;&lt;br /&gt;
 SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 SCALE(1) = 0.0001;&lt;br /&gt;
 for j = 1:color_breaks*2&lt;br /&gt;
     SCALE(j+1) = colorbreak*j;&lt;br /&gt;
 end&lt;br /&gt;
 SCALE(color_breaks+1) = num_colors+1;&lt;br /&gt;
 VIS_SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 VIS_SCALE(1) = demCS(1);&lt;br /&gt;
 for j = 1:color_breaks-1&lt;br /&gt;
     VIS_SCALE(j+1) = ((demCS2/color_breaks)*j)+demCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 VIS_SCALE(color_breaks+1) = depthCS(1);&lt;br /&gt;
 for j = 1:color_breaks&lt;br /&gt;
     VIS_SCALE(j+1+color_breaks) = ((depthCS2/color_breaks)*j)+depthCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 colorbar('YTick',SCALE,'YTickLabel',VIS_SCALE);&lt;br /&gt;
 % Label axis&lt;br /&gt;
 xlabel('BNG easting (m)');&lt;br /&gt;
 ylabel('BNG northing (m)');&lt;br /&gt;
 A = [vartype,' over DEM at time ',num2str((i*snapint)),'s'];&lt;br /&gt;
 title(A);&lt;/div&gt;</summary>
		<author><name>Jeff-neal</name></author>
	</entry>
	<entry>
		<id>https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5164</id>
		<title>LISFLOOD-FP and MATLAB</title>
		<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5164"/>
		<updated>2008-05-14T09:05:53Z</updated>

		<summary type="html">&lt;p&gt;Jeff-neal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains various Matlab functions that may be useful for analysing results from the [http://www.ggy.bris.ac.uk/research/hydrology/models/lisflood LISFLOOD-FP] model.&lt;br /&gt;
&lt;br /&gt;
==File import and export==&lt;br /&gt;
&lt;br /&gt;
===Importing ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will import an ascii raster file using the string filename. To use it, copy and past text into a textfile called ascii_reader.m&lt;br /&gt;
&lt;br /&gt;
 function [dem, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % This function reads arc .asc files&lt;br /&gt;
 % requires filename string as input&lt;br /&gt;
 &lt;br /&gt;
 % j neal&lt;br /&gt;
 % 18/6/07&lt;br /&gt;
 %% read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 dem = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 dem = dem';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
You can view the imported file using the command:&lt;br /&gt;
&lt;br /&gt;
 imagesc(dem);&lt;br /&gt;
&lt;br /&gt;
===Exporting ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will create an ascii raster file called filename from the 2D matrix DEM.  To use it, copy and past text into a textfile called ascii_write.m&lt;br /&gt;
&lt;br /&gt;
 function ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 &lt;br /&gt;
 % ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 % only filename (string) and DEM (2D matrix) are essential&lt;br /&gt;
 % this function writes ascii raster files for arc&lt;br /&gt;
 % j neal&lt;br /&gt;
 % 6/3/2008&lt;br /&gt;
 &lt;br /&gt;
 if nargin &amp;lt; 2, &lt;br /&gt;
     error('Requires at least two input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4, &lt;br /&gt;
     xllcorner = 0;&lt;br /&gt;
     yllcorner = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 5,&lt;br /&gt;
     cellsize = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 6&lt;br /&gt;
     nodata = -9999;&lt;br /&gt;
 end&lt;br /&gt;
 A = size(DEM);&lt;br /&gt;
 fout = fopen (filename,'w');&lt;br /&gt;
 fprintf(fout, 'ncols         %.0f\n', A(2));  &lt;br /&gt;
 fprintf(fout, 'nrows         %.0f\n', A(1));&lt;br /&gt;
 fprintf(fout, 'xllcorner     %f\n', xllcorner);&lt;br /&gt;
 fprintf(fout, 'yllcorner     %f\n', yllcorner);&lt;br /&gt;
 fprintf(fout, 'cellsize      %f\n', cellsize);&lt;br /&gt;
 fprintf(fout, 'NODATA_value  %f\n', nodata); &lt;br /&gt;
 for ii = 1:A(1)&lt;br /&gt;
     B = DEM(ii,:);&lt;br /&gt;
     fprintf(fout, '%1.3f ', B);&lt;br /&gt;
     fprintf(fout, '\n');&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
===Importing .profile files===&lt;br /&gt;
&lt;br /&gt;
This function imports .profile files&lt;br /&gt;
&lt;br /&gt;
 function [data, M] = profileread (resroot, numfiles, t, string1, string2)&lt;br /&gt;
 &lt;br /&gt;
 % This function reads LISFLOOD-FP .profile files&lt;br /&gt;
 %&lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT)&lt;br /&gt;
 %   where RESROOT is a string containing the resroot from the LISFLOOD-FP&lt;br /&gt;
 %   .par file. Absolute path names can also be used e.g. 'C:\LISFLOOD\resroot'&lt;br /&gt;
 %   DATA is a structure containing .header {cell aray}&lt;br /&gt;
 %                                  .segmentN (numerical array for segment N)&lt;br /&gt;
 %&lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT, NUMFILES)&lt;br /&gt;
 %   NUMFILES = number of files to read. Reads m files assuming that the files &lt;br /&gt;
 %   are numbered such that resroot-000m.profile. &lt;br /&gt;
 %   DATA(m) is a structure containing m files&lt;br /&gt;
 % &lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT, NUMFILES, 1)&lt;br /&gt;
 %   specifies the profiles were exported a user specified time such that&lt;br /&gt;
 %   resroot-000x-t.profile&lt;br /&gt;
 %&lt;br /&gt;
 % [DATA, M] = PROFILEREAD (RESROOT, NUMFILES, 1, string1, string2)&lt;br /&gt;
 %   instructs the function to plot string1 or sting1 against string2... these&lt;br /&gt;
 %   strings muct match the headernames in the .profile file e.g. 'Flow'&lt;br /&gt;
 %   returns movieframes in the structure M&lt;br /&gt;
 %&lt;br /&gt;
 % Note: LISFLOOD-FP will name multiple files 0 to m-1 but DATA(m) will count from 1 to m&lt;br /&gt;
 %&lt;br /&gt;
 % j.neal&lt;br /&gt;
 % 12/5/2008&lt;br /&gt;
 %%&lt;br /&gt;
 if nargin &amp;lt; 1, &lt;br /&gt;
     error('Requires filename'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 2,&lt;br /&gt;
     % only one file&lt;br /&gt;
     numfiles = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 2,&lt;br /&gt;
     t = 0;&lt;br /&gt;
 end &lt;br /&gt;
 if nargin &amp;lt; 4,&lt;br /&gt;
     % no plotting required&lt;br /&gt;
     plotting = 0;&lt;br /&gt;
     M = 0;&lt;br /&gt;
 elseif nargin &amp;lt; 5,&lt;br /&gt;
     % use plotter&lt;br /&gt;
     plotting = 1;&lt;br /&gt;
 elseif nargin &amp;lt; 6,&lt;br /&gt;
     plotting = 2;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 %% Arrange data read&lt;br /&gt;
 if t == 1&lt;br /&gt;
     fileex = '-t.profile';&lt;br /&gt;
 else&lt;br /&gt;
     fileex = '.profile';&lt;br /&gt;
 end&lt;br /&gt;
 if numfiles == 0&lt;br /&gt;
     % read in a single .profile file&lt;br /&gt;
     filename = [resroot,fileex];&lt;br /&gt;
     data = read_profile (filename);&lt;br /&gt;
 elseif numfiles &amp;lt; 9999&lt;br /&gt;
     % read a series of .profile files&lt;br /&gt;
     for i = 1:numfiles&lt;br /&gt;
         ii = i-1;&lt;br /&gt;
         if ii &amp;lt; 10&lt;br /&gt;
             resroot2 = [resroot,'-000',num2str(ii),fileex];&lt;br /&gt;
         elseif ii &amp;lt; 100&lt;br /&gt;
             resroot2 = [resroot,'-00',num2str(ii),fileex];&lt;br /&gt;
         elseif ii &amp;lt; 1000&lt;br /&gt;
             resroot2 = [resroot,'-0',num2str(ii),fileex];&lt;br /&gt;
         else&lt;br /&gt;
             resroot2 = [resroot,'-',num2str(ii),fileex];&lt;br /&gt;
         end&lt;br /&gt;
         %returnes structure with format data(i).segmentX... also includes .header &lt;br /&gt;
         [data(i), seg_num] = read_profile (resroot2); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     end&lt;br /&gt;
 else&lt;br /&gt;
     error ('Too many files or incorrect input to numfiles'); &lt;br /&gt;
 end&lt;br /&gt;
 %% Plotting under development&lt;br /&gt;
 % if plotting == 0 % do nothing... no plots&lt;br /&gt;
 if plotting == 1&lt;br /&gt;
     disp('Note: Plotting functions under development');&lt;br /&gt;
     % find the column you want to plot&lt;br /&gt;
     I = strmatch(string1 , data(1).header);&lt;br /&gt;
     % plot a single variable&lt;br /&gt;
     A = size(data);&lt;br /&gt;
     for i = 1:A(2)&lt;br /&gt;
         for j = 1:seg_num&lt;br /&gt;
             k = j-1;&lt;br /&gt;
             eval(['plot(data(i).segment',num2str(k),'(:,',num2str(I),'));']);&lt;br /&gt;
             % get movie frame&lt;br /&gt;
             M(i,j) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 elseif plotting == 2&lt;br /&gt;
     disp('Note: Plotting functions under development');&lt;br /&gt;
     % find the columns you want to plot&lt;br /&gt;
     I = strmatch(string1 , data(1).header);&lt;br /&gt;
     I2 = strmatch(string2 , data(1).header);&lt;br /&gt;
     A = size(data);&lt;br /&gt;
     for i = 1:A(2)&lt;br /&gt;
         for j = 1:seg_num&lt;br /&gt;
             k = j-1;&lt;br /&gt;
             eval(['plot(data(i).segment',num2str(k),'(:,',num2str(I),'),data(i).segment',num2str(k),'(:,',num2str(I2),'));']);&lt;br /&gt;
             % get movie frame&lt;br /&gt;
             M(i,j) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% read .profile file&lt;br /&gt;
 function [data, seg_num] = read_profile (filename)&lt;br /&gt;
 &lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 more_segs = 1;&lt;br /&gt;
 % read 'Channel_segment:' from file&lt;br /&gt;
 temp = fscanf(fin,'%s',1); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 while more_segs == 1&lt;br /&gt;
     % read filename&lt;br /&gt;
     seg_num = fscanf(fin,'%f',1);&lt;br /&gt;
     for i = 1:11&lt;br /&gt;
         data.header{i} = fscanf(fin,'%s',1);&lt;br /&gt;
     end&lt;br /&gt;
     testline = 1;&lt;br /&gt;
     j = 0;&lt;br /&gt;
     while testline == 1&lt;br /&gt;
         j = j+1;&lt;br /&gt;
         % reads the first bit of the line as a string&lt;br /&gt;
         A = fscanf(fin, '%s',1);&lt;br /&gt;
         % this string is either a numer of a new channel sgment of the end&lt;br /&gt;
         % of the file&lt;br /&gt;
         % if end of file&lt;br /&gt;
         ST = feof (fin);&lt;br /&gt;
         if ST == 1&lt;br /&gt;
             % reached the end of the file exit both while loops&lt;br /&gt;
             testline = 0;&lt;br /&gt;
             more_segs = 0;&lt;br /&gt;
         else&lt;br /&gt;
             TF = strcmp('Channel_segment:', A); &lt;br /&gt;
 &lt;br /&gt;
             if TF == 1&lt;br /&gt;
                 % new segment has been found&lt;br /&gt;
                 testline = 0;&lt;br /&gt;
             else&lt;br /&gt;
                 % read rest for line into data&lt;br /&gt;
                 B(j,1) = str2double(A); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
                 for k = 2:11&lt;br /&gt;
                     B(j,k) = fscanf(fin, '%f',1); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
                 end&lt;br /&gt;
             end&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
     eval(['data.segment',num2str(seg_num),' = B;']);&lt;br /&gt;
     clear B&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Writing parameter files===&lt;br /&gt;
&lt;br /&gt;
This function can be used to write many LISFLOOD-FP parameter files with ''N'' different channel and floodplain roughness, using your own ''N-by-''2 matrix called roughness. You will need to edit the code for your application by commenting unwanted lines with a percentage symbol.&lt;br /&gt;
&lt;br /&gt;
 function prm_writer (roughness) &lt;br /&gt;
 &lt;br /&gt;
 % This function writes LISFLOOD-FP parameter files numbered 1 to n using&lt;br /&gt;
 % the roughness values in the n-by-2 matrix roughness. yuo will need to&lt;br /&gt;
 % edit the code for your application.&lt;br /&gt;
 &lt;br /&gt;
 [num_sims] = size(roughness);&lt;br /&gt;
 for i = 1:num_sims(1)&lt;br /&gt;
 a = ['mymodel', num2str(i),'.par']; b = num2str(i);&lt;br /&gt;
 fout = fopen(a,'w');&lt;br /&gt;
 fprintf(fout,'DEMfile                  mydem.dem.ascii\n');&lt;br /&gt;
 fprintf(fout,'resroot                  myres%s\n',b);&lt;br /&gt;
 fprintf(fout,'dirroot                  mydir\n');&lt;br /&gt;
 fprintf(fout,'sim_time                 245000.0\n');&lt;br /&gt;
 fprintf(fout,'initial_tstep            10.0\n');&lt;br /&gt;
 fprintf(fout,'massint                  300.0\n');&lt;br /&gt;
 fprintf(fout,'saveint                  10000.0\n');&lt;br /&gt;
 %fprintf(fout,'overpass                 135000.0\n');&lt;br /&gt;
 fprintf(fout,'fpfric                   %1.3f\n',roughness(i,2));&lt;br /&gt;
 fprintf(fout,'nch                      %1.3f\n',roughness(i,1));&lt;br /&gt;
 %fprintf(fout,'manningfile              mymanfile%s.n.ascii\n',b);&lt;br /&gt;
 fprintf(fout,'riverfile                myriver.river\n');&lt;br /&gt;
 fprintf(fout,'bdyfile                  mybdy.bdy\n');&lt;br /&gt;
 fprintf(fout,'stagefile                mystage.stage\n');&lt;br /&gt;
 fprintf(fout,'bcifile                  mybci.bci\n');&lt;br /&gt;
 %fprintf(fout,'startfile                mystart.old\n');&lt;br /&gt;
 %fprintf(fout,'checkpoint               2\n');&lt;br /&gt;
 %fprintf(fout,'checkfile                mycheck.chkpnt\n');&lt;br /&gt;
 fprintf(fout,'elevoff\n');&lt;br /&gt;
 fprintf(fout,'qoutput\n');&lt;br /&gt;
 fprintf(fout,'diffusive\n');&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==Plotting flow vectors from .Qx and .Qy files==&lt;br /&gt;
&lt;br /&gt;
This function will plot flow vectors from a .Qx and .Qy over a dem using the matlab functions image and quiver  &lt;br /&gt;
&lt;br /&gt;
 function lisflood_flow_plotter (qxfile, qyfile, demfile, north, east, south, west, scaling)&lt;br /&gt;
 &lt;br /&gt;
 % This function plots flow vectors from LISFLOOD_FP Qx and QY files&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile);&lt;br /&gt;
 %&lt;br /&gt;
 % these input variables are strings containing the relative of full&lt;br /&gt;
 % pathnames of the .Qx .Qy and ascii dem files to be plotted.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W);&lt;br /&gt;
 %&lt;br /&gt;
 % N, E, W and S are optional they specify the northernmost, southeernmost&lt;br /&gt;
 % ect cell to be displayed. this can be used to crop the domain.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W, scaling);&lt;br /&gt;
 % &lt;br /&gt;
 % scaling is an optional term used to manually scale the vector lengthes&lt;br /&gt;
 % drawn by quiver (the arrow plotting function).&lt;br /&gt;
 %&lt;br /&gt;
 % J Neal&lt;br /&gt;
 % 20/02/2008 &lt;br /&gt;
 &lt;br /&gt;
 %% decide if crop is required and give imput error message&lt;br /&gt;
 if nargin &amp;lt; 3, &lt;br /&gt;
     error('Requires at least three input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7, &lt;br /&gt;
     crop = 0;&lt;br /&gt;
 else&lt;br /&gt;
     crop = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7,&lt;br /&gt;
     scaling = 1;&lt;br /&gt;
 end &lt;br /&gt;
 % Note don't do this for large areas ?&lt;br /&gt;
 %% Task 1: read ascii files&lt;br /&gt;
 % read Qx file&lt;br /&gt;
 [QX, ncolsqx, nrowsqx, xllcornerqx, yllcornerqx, cellsizeqx] = read_file (qxfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read Qy file&lt;br /&gt;
 [QY, ncolsqy, nrowsqy, xllcornerqy, yllcornerqy, cellsizeqy] = read_file (qyfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read DEM&lt;br /&gt;
 [DEM, ncolsdem, nrowsdem, xllcornerdem, yllcornerdem, cellsizedem] = read_file (demfile);&lt;br /&gt;
 %% crop data if required&lt;br /&gt;
 if crop == 1;&lt;br /&gt;
     DEM = DEM(north:south,west:east);&lt;br /&gt;
     QX = QX(north:south,west:east+1);&lt;br /&gt;
     QY = QY(north:south+1,west:east);&lt;br /&gt;
     xllcornerdem = xllcornerdem + west*cellsizedem - cellsizedem;&lt;br /&gt;
     yllcornerdem = yllcornerdem + (nrowsdem - south) * cellsizedem;&lt;br /&gt;
     [nrowsqx, ncolsqx] = size(QX); [nrowsqy, ncolsqy] = size(QY); [nrowsdem, ncolsdem] = size(DEM);&lt;br /&gt;
 end&lt;br /&gt;
 %% Taks 2: Plot dem and generate figure&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap('gray');&lt;br /&gt;
 % Create axes&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcornerdem + nrowsdem*cellsizedem ,yllcornerdem},...&lt;br /&gt;
     'YTick',[0.5,nrowsdem+0.5],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcornerdem,xllcornerdem+ncolsdem*cellsizedem},...&lt;br /&gt;
     'XTick',[0.5, ncolsdem + 0.5],...&lt;br /&gt;
     'Layer','top',...&lt;br /&gt;
     'DataAspectRatio',[1 1 1]...&lt;br /&gt;
     %,'Clim',[13 30]... % uncomment to set colourmap limits manually&lt;br /&gt;
     );&lt;br /&gt;
 &lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM,'Parent',axes1,'CDataMapping','scaled');&lt;br /&gt;
 axis('image');&lt;br /&gt;
 xlabel('Easting (m)');&lt;br /&gt;
 ylabel('Northing (m)');&lt;br /&gt;
 %% Task 3: calculate flow vectors&lt;br /&gt;
 % pre allocate memory for loop... it will run faster this way&lt;br /&gt;
 xlocs = zeros(ncolsqx*nrowsqx+ncolsqy*nrowsqy,1);&lt;br /&gt;
 ylocs = xlocs;&lt;br /&gt;
 U = xlocs;&lt;br /&gt;
 V = xlocs;&lt;br /&gt;
 %work out X and Y locations&lt;br /&gt;
 for i = 1:nrowsqx&lt;br /&gt;
     for j = 1:ncolsqx&lt;br /&gt;
         xlocs((i-1)*ncolsqx+j,1) = j - 0.5;&lt;br /&gt;
         ylocs((i-1)*ncolsqx+j,1) = i;&lt;br /&gt;
         U((i-1)*ncolsqx+j,1) = QX(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 for i = 1:nrowsqy&lt;br /&gt;
     for j = 1:ncolsqy&lt;br /&gt;
         xlocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = j;&lt;br /&gt;
         ylocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = i - 0.5;&lt;br /&gt;
         V(ncolsqx*nrowsqx+(i-1)*ncolsqy+j,1) = QY(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % work out number of nonzeros elements&lt;br /&gt;
 num_flows = nnz(U+V);&lt;br /&gt;
 xlocs2 = zeros(num_flows,1);&lt;br /&gt;
 ylocs2 = xlocs2;&lt;br /&gt;
 U2 = xlocs2;&lt;br /&gt;
 V2 = xlocs2;&lt;br /&gt;
 % remover zero flow locations&lt;br /&gt;
 k = 1;&lt;br /&gt;
 for i = 1:ncolsqx*nrowsqx+ncolsqy*nrowsqy&lt;br /&gt;
     if (U(i,1) == 0) &amp;amp;&amp;amp; (V(i,1) == 0)&lt;br /&gt;
         % do nothing&lt;br /&gt;
     else&lt;br /&gt;
         xlocs2(k,1) = xlocs(i,1);&lt;br /&gt;
         ylocs2(k,1) = ylocs(i,1);&lt;br /&gt;
         U2(k,1) = U(i,1);&lt;br /&gt;
         V2(k,1) = V(i,1);&lt;br /&gt;
         k = k+1;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % check numbers are correct&lt;br /&gt;
 if k == num_flows + 1&lt;br /&gt;
     % all is ok&lt;br /&gt;
 else&lt;br /&gt;
     disp('Problem with flows');&lt;br /&gt;
 end&lt;br /&gt;
 %% Task 4: overlay flow vectors&lt;br /&gt;
 disp('Plotting data... if this is taking a long time you may need fewer locations');&lt;br /&gt;
 quiver (xlocs2,ylocs2,U2,V2, scaling);&lt;br /&gt;
 % quiver (xloc2,yloc2,U2,V2,'Parent',figure1);&lt;br /&gt;
 disp('Done');&lt;br /&gt;
 %% function to read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
==Making movies from .wd files==&lt;br /&gt;
&lt;br /&gt;
This function will convert a series of .wd .Qx or .Qy file into a .avi movie with the same filename&lt;br /&gt;
&lt;br /&gt;
 function LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ) &lt;br /&gt;
 &lt;br /&gt;
 % LISFLOOD_mov generates movies of LISFLOOD-FP output&lt;br /&gt;
 %&lt;br /&gt;
 % LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ)&lt;br /&gt;
 % &lt;br /&gt;
 % where &lt;br /&gt;
 % resroot is the LISFLOOD resroot (relative to m file or absolute)(string)&lt;br /&gt;
 % fileex is the file extension '.wd' (can be chaned to plot WSE and flows)&lt;br /&gt;
 % vartype is the name of the variable being plotted e.g. 'Depth'&lt;br /&gt;
 % num_snaps is the number of snapshot times&lt;br /&gt;
 % snapint is the time interval between each LISFLOOD-FP snapshot (seconds)&lt;br /&gt;
 % dem is the name of the demfile (relative or absolute)&lt;br /&gt;
 % demCS is the range of dem hights to be plotted e.g. demCS = [0,20];&lt;br /&gt;
 % depthCS is the range of depth values to be plotted e.g. depthCS = [0,10];&lt;br /&gt;
 % framesPS number of frames per second (each plot is a simgle frame)&lt;br /&gt;
 % movQ is the movie quality between 1 and 100 (100 is best)&lt;br /&gt;
 % &lt;br /&gt;
 % 8/11/2007. J Neal.&lt;br /&gt;
 %&lt;br /&gt;
 % EXAMPLE:&lt;br /&gt;
 % LISFLOOD_mov ('C:\Experiment1\res22','.wd','Water depth',24,10000,...&lt;br /&gt;
 % 'C:\Experiment1\dem10m.dem.ascii',[0,60], [0,10],1,100);&lt;br /&gt;
 %% Movie maker&lt;br /&gt;
 % read dem filenam is filename and 1 specifies the 0.00 should not be NaN's&lt;br /&gt;
 [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (dem); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 % A = [resroot,'.avi'];&lt;br /&gt;
 % mov = avifile(A);&lt;br /&gt;
 % loop through snapshots&lt;br /&gt;
 for i = 1:num_snaps&lt;br /&gt;
     if i &amp;lt; 10&lt;br /&gt;
         resfile = [resroot,'-000',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 100&lt;br /&gt;
         resfile = [resroot,'-00',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 1000&lt;br /&gt;
         resfile = [resroot,'-0',num2str(i),fileex];&lt;br /&gt;
     else&lt;br /&gt;
         resfile = [resroot,'-',num2str(i),fileex];&lt;br /&gt;
     end&lt;br /&gt;
     % read in deoth file for resfile i (2 specifies the 0.00 should be NaN&lt;br /&gt;
     [DEPTH, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (resfile);&lt;br /&gt;
     % plot data as figure 1&lt;br /&gt;
     plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype);&lt;br /&gt;
     % get movie frame&lt;br /&gt;
     M(i) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     hold off;&lt;br /&gt;
 %     mov = addframe(mov,M(i));&lt;br /&gt;
     % close the figure&lt;br /&gt;
     close all&lt;br /&gt;
 end &lt;br /&gt;
 % % close .avi file&lt;br /&gt;
 % mov = close(mov);&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 disp('Generating .avi movie file');&lt;br /&gt;
 A = [resroot,fileex,'.avi'];&lt;br /&gt;
 movie2avi(M,A,'fps',framesPS,'quality',movQ);&lt;br /&gt;
 disp(A);&lt;br /&gt;
 %% Read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 % convert nodata to NaN;&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if OUT(ii,jj) == nodata&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         elseif OUT(ii,jj) == -99.000&lt;br /&gt;
             % lisflood uses -99.000 as nodat so will also remove these&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         else&lt;br /&gt;
             % do nothing&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% Plotter data for movie slide&lt;br /&gt;
 function plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype)&lt;br /&gt;
 % number of colors in colormap&lt;br /&gt;
 num_colors = 64;&lt;br /&gt;
 % DEM and variable color map&lt;br /&gt;
 cmap = [gray(num_colors); jet(num_colors)];&lt;br /&gt;
 % scale DEM and DEPTH data to fit with new colormap&lt;br /&gt;
 demCS2 = demCS(2)-demCS(1);&lt;br /&gt;
 dem_scalar = num_colors/demCS2;&lt;br /&gt;
 DEM2 = DEM*dem_scalar;&lt;br /&gt;
 depthCS2 = depthCS(2)-depthCS(1);&lt;br /&gt;
 depth_scalar = num_colors/depthCS2;&lt;br /&gt;
 DEPTH2 = (DEPTH*depth_scalar)+num_colors+1;&lt;br /&gt;
 %Plot the DEM&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap(cmap);&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcorner+(nrows*cellsize),yllcorner+cellsize},...&lt;br /&gt;
     'YTick', [1,nrows],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcorner,xllcorner+(ncols*cellsize)-cellsize},...&lt;br /&gt;
     'XTick',[1,ncols],...&lt;br /&gt;
     'Layer','top');&lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM2,'Parent',axes1);&lt;br /&gt;
 axis('equal');axis('tight');&lt;br /&gt;
 % Overlay the water depth (or other variable)&lt;br /&gt;
 H = image(DEPTH2);&lt;br /&gt;
 % code to make depth plot layer transparent&lt;br /&gt;
 OP = ones(nrows,ncols);&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if DEPTH(ii,jj) &amp;gt; 0&lt;br /&gt;
         else&lt;br /&gt;
             OP(ii,jj) = 0;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % make transparent. depth layer must be H&lt;br /&gt;
 set(H,'AlphaData',OP);&lt;br /&gt;
 % label colourbar&lt;br /&gt;
 color_breaks = 5;&lt;br /&gt;
 colorbreak = num_colors/color_breaks;&lt;br /&gt;
 SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 SCALE(1) = 0.0001;&lt;br /&gt;
 for j = 1:color_breaks*2&lt;br /&gt;
     SCALE(j+1) = colorbreak*j;&lt;br /&gt;
 end&lt;br /&gt;
 SCALE(color_breaks+1) = num_colors+1;&lt;br /&gt;
 VIS_SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 VIS_SCALE(1) = demCS(1);&lt;br /&gt;
 for j = 1:color_breaks-1&lt;br /&gt;
     VIS_SCALE(j+1) = ((demCS2/color_breaks)*j)+demCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 VIS_SCALE(color_breaks+1) = depthCS(1);&lt;br /&gt;
 for j = 1:color_breaks&lt;br /&gt;
     VIS_SCALE(j+1+color_breaks) = ((depthCS2/color_breaks)*j)+depthCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 colorbar('YTick',SCALE,'YTickLabel',VIS_SCALE);&lt;br /&gt;
 % Label axis&lt;br /&gt;
 xlabel('BNG easting (m)');&lt;br /&gt;
 ylabel('BNG northing (m)');&lt;br /&gt;
 A = [vartype,' over DEM at time ',num2str((i*snapint)),'s'];&lt;br /&gt;
 title(A);&lt;/div&gt;</summary>
		<author><name>Jeff-neal</name></author>
	</entry>
	<entry>
		<id>https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5163</id>
		<title>LISFLOOD-FP and MATLAB</title>
		<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5163"/>
		<updated>2008-05-12T16:02:27Z</updated>

		<summary type="html">&lt;p&gt;Jeff-neal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains various Matlab functions that may be useful for analysing results from the [http://www.ggy.bris.ac.uk/research/hydrology/models/lisflood LISFLOOD-FP] model.&lt;br /&gt;
&lt;br /&gt;
==File import and export==&lt;br /&gt;
&lt;br /&gt;
===Importing ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will import an ascii raster file using the string filename. To use it, copy and past text into a textfile called ascii_reader.m&lt;br /&gt;
&lt;br /&gt;
 function [dem, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % This function reads arc .asc files&lt;br /&gt;
 % requires filename string as input&lt;br /&gt;
 &lt;br /&gt;
 % j neal&lt;br /&gt;
 % 18/6/07&lt;br /&gt;
 %% read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 dem = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 dem = dem';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
You can view the imported file using the command:&lt;br /&gt;
&lt;br /&gt;
 imagesc(dem);&lt;br /&gt;
&lt;br /&gt;
===Exporting ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will create an ascii raster file called filename from the 2D matrix DEM.  To use it, copy and past text into a textfile called ascii_write.m&lt;br /&gt;
&lt;br /&gt;
 function ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 &lt;br /&gt;
 % ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 % only filename (string) and DEM (2D matrix) are essential&lt;br /&gt;
 % this function writes ascii raster files for arc&lt;br /&gt;
 % j neal&lt;br /&gt;
 % 6/3/2008&lt;br /&gt;
 &lt;br /&gt;
 if nargin &amp;lt; 2, &lt;br /&gt;
     error('Requires at least two input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4, &lt;br /&gt;
     xllcorner = 0;&lt;br /&gt;
     yllcorner = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 5,&lt;br /&gt;
     cellsize = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 6&lt;br /&gt;
     nodata = -9999;&lt;br /&gt;
 end&lt;br /&gt;
 A = size(DEM);&lt;br /&gt;
 fout = fopen (filename,'w');&lt;br /&gt;
 fprintf(fout, 'ncols         %.0f\n', A(2));  &lt;br /&gt;
 fprintf(fout, 'nrows         %.0f\n', A(1));&lt;br /&gt;
 fprintf(fout, 'xllcorner     %f\n', xllcorner);&lt;br /&gt;
 fprintf(fout, 'yllcorner     %f\n', yllcorner);&lt;br /&gt;
 fprintf(fout, 'cellsize      %f\n', cellsize);&lt;br /&gt;
 fprintf(fout, 'NODATA_value  %f\n', nodata); &lt;br /&gt;
 for ii = 1:A(1)&lt;br /&gt;
     B = DEM(ii,:);&lt;br /&gt;
     fprintf(fout, '%1.3f ', B);&lt;br /&gt;
     fprintf(fout, '\n');&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
===Importing .profile files===&lt;br /&gt;
&lt;br /&gt;
This function imports .profile files&lt;br /&gt;
&lt;br /&gt;
 function [data, M] = profileread (resroot, numfiles, t, string1, string2)&lt;br /&gt;
 &lt;br /&gt;
 % This function reads LISFLOOD-FP .profile files&lt;br /&gt;
 %&lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT)&lt;br /&gt;
 %   where RESROOT is a string containing the resroot from the LISFLOOD-FP&lt;br /&gt;
 %   .par file. Absolute path names can also be used e.g. 'C:\LISFLOOD\resroot'&lt;br /&gt;
 %   DATA is a structure containing .header {cell aray}&lt;br /&gt;
 %                                  .segmentN (numerical array for segment N)&lt;br /&gt;
 %&lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT, NUMFILES)&lt;br /&gt;
 %   NUMFILES = number of files to read. Reads m files assuming that the files &lt;br /&gt;
 %   are numbered such that resroot-000m.profile. &lt;br /&gt;
 %   DATA(m) is a structure containing m files&lt;br /&gt;
 % &lt;br /&gt;
 % DATA = PROFILEREAD (RESROOT, NUMFILES, 1)&lt;br /&gt;
 %   specifies the profiles were exported a user specified time such that&lt;br /&gt;
 %   resroot-000x-t.profile&lt;br /&gt;
 %&lt;br /&gt;
 % [DATA, M] = PROFILEREAD (RESROOT, NUMFILES, 1, string1, string2)&lt;br /&gt;
 %   instructs the function to plot string1 or sting1 against string2... these&lt;br /&gt;
 %   strings muct match the headernames in the .profile file e.g. 'Flow'&lt;br /&gt;
 %   returns movieframes in the structure M&lt;br /&gt;
 %&lt;br /&gt;
 % Note: LISFLOOD-FP will name multiple files 0 to m-1 but DATA(m) will count from 1 to m&lt;br /&gt;
 %&lt;br /&gt;
 % j.neal&lt;br /&gt;
 % 12/5/2008&lt;br /&gt;
 %%&lt;br /&gt;
 if nargin &amp;lt; 1, &lt;br /&gt;
     error('Requires filename'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 2,&lt;br /&gt;
     % only one file&lt;br /&gt;
     numfiles = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 2,&lt;br /&gt;
     t = 0;&lt;br /&gt;
 end &lt;br /&gt;
 if nargin &amp;lt; 4,&lt;br /&gt;
     % no plotting required&lt;br /&gt;
     plotting = 0;&lt;br /&gt;
     M = 0;&lt;br /&gt;
 elseif nargin &amp;lt; 5,&lt;br /&gt;
     % use plotter&lt;br /&gt;
     plotting = 1;&lt;br /&gt;
 elseif nargin &amp;lt; 6,&lt;br /&gt;
     plotting = 2;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 %% Arrange data read&lt;br /&gt;
 if t == 1&lt;br /&gt;
     fileex = '-t.profile';&lt;br /&gt;
 else&lt;br /&gt;
     fileex = '.profile';&lt;br /&gt;
 end&lt;br /&gt;
 if numfiles == 0&lt;br /&gt;
     % read in a single .profile file&lt;br /&gt;
     filename = [resroot,fileex];&lt;br /&gt;
     data = read_profile (filename, 1);&lt;br /&gt;
 elseif numfiles &amp;lt; 9999&lt;br /&gt;
     % read a series of .profile files&lt;br /&gt;
     for i = 1:numfiles&lt;br /&gt;
         ii = 1-1;&lt;br /&gt;
         if ii &amp;lt; 10&lt;br /&gt;
             resroot2 = [resroot,'-000',num2str(ii),fileex];&lt;br /&gt;
         elseif ii &amp;lt; 100&lt;br /&gt;
             resroot2 = [resroot,'-00',num2str(ii),fileex];&lt;br /&gt;
         elseif ii &amp;lt; 1000&lt;br /&gt;
             resroot2 = [resroot,'-0',num2str(ii),fileex];&lt;br /&gt;
         else&lt;br /&gt;
             resroot2 = [resroot,'-',num2str(ii),fileex];&lt;br /&gt;
         end&lt;br /&gt;
         %returnes structure with format data(i).segmentX... also includes .header &lt;br /&gt;
         [data(i), seg_num] = read_profile (resroot2); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     end&lt;br /&gt;
 else&lt;br /&gt;
     error ('Too many files or incorrect input to numfiles'); &lt;br /&gt;
 end&lt;br /&gt;
 %% Plotting under development&lt;br /&gt;
 % if plotting == 0 % do nothing... no plots&lt;br /&gt;
 if plotting == 1&lt;br /&gt;
     disp('Note: Plotting functions under development');&lt;br /&gt;
     % find the column you want to plot&lt;br /&gt;
     I = strmatch(string1 , data(1).header);&lt;br /&gt;
     % plot a single variable&lt;br /&gt;
     A = size(data);&lt;br /&gt;
     for i = 1:A(2)&lt;br /&gt;
         for j = 1:seg_num&lt;br /&gt;
             k = j-1;&lt;br /&gt;
             eval(['plot(data(i).segment',num2str(k),'(:,',num2str(I),'));']);&lt;br /&gt;
             % get movie frame&lt;br /&gt;
             M(i,j) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 elseif plotting == 2&lt;br /&gt;
     disp('Note: Plotting functions under development');&lt;br /&gt;
     % find the columns you want to plot&lt;br /&gt;
     I = strmatch(string1 , data(1).header);&lt;br /&gt;
     I2 = strmatch(string2 , data(1).header);&lt;br /&gt;
     A = size(data);&lt;br /&gt;
     for i = 1:A(2)&lt;br /&gt;
         for j = 1:seg_num&lt;br /&gt;
             k = j-1;&lt;br /&gt;
             eval(['plot(data(i).segment',num2str(k),'(:,',num2str(I),'),data(i).segment',num2str(k),'(:,',num2str(I2),'));']);&lt;br /&gt;
             % get movie frame&lt;br /&gt;
             M(i,j) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% read .profile file&lt;br /&gt;
 function [data, seg_num] = read_profile (filename)&lt;br /&gt;
 &lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 more_segs = 1;&lt;br /&gt;
 % read 'Channel_segment:' from file&lt;br /&gt;
 temp = fscanf(fin,'%s',1); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 while more_segs == 1&lt;br /&gt;
     % read filename&lt;br /&gt;
     seg_num = fscanf(fin,'%f',1);&lt;br /&gt;
     for i = 1:11&lt;br /&gt;
         data.header{i} = fscanf(fin,'%s',1);&lt;br /&gt;
     end&lt;br /&gt;
     testline = 1;&lt;br /&gt;
     j = 0;&lt;br /&gt;
     while testline == 1&lt;br /&gt;
         j = j+1;&lt;br /&gt;
         % reads the first bit of the line as a string&lt;br /&gt;
         A = fscanf(fin, '%s',1);&lt;br /&gt;
         % this string is either a numer of a new channel sgment of the end&lt;br /&gt;
         % of the file&lt;br /&gt;
         % if end of file&lt;br /&gt;
         ST = feof (fin);&lt;br /&gt;
         if ST == 1&lt;br /&gt;
             % reached the end of the file exit both while loops&lt;br /&gt;
             testline = 0;&lt;br /&gt;
             more_segs = 0;&lt;br /&gt;
         else&lt;br /&gt;
             TF = strcmp('Channel_segment:', A); &lt;br /&gt;
 &lt;br /&gt;
             if TF == 1&lt;br /&gt;
                 % new segment has been found&lt;br /&gt;
                 testline = 0;&lt;br /&gt;
             else&lt;br /&gt;
                 % read rest for line into data&lt;br /&gt;
                 B(j,1) = str2double(A); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
                 for k = 2:11&lt;br /&gt;
                     B(j,k) = fscanf(fin, '%f',1); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
                 end&lt;br /&gt;
             end&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
     eval(['data.segment',num2str(seg_num),' = B;']);&lt;br /&gt;
     clear B&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Writing parameter files===&lt;br /&gt;
&lt;br /&gt;
This function can be used to write many LISFLOOD-FP parameter files with ''N'' different channel and floodplain roughness, using your own ''N-by-''2 matrix called roughness. You will need to edit the code for your application by commenting unwanted lines with a percentage symbol.&lt;br /&gt;
&lt;br /&gt;
 function prm_writer (roughness) &lt;br /&gt;
 &lt;br /&gt;
 % This function writes LISFLOOD-FP parameter files numbered 1 to n using&lt;br /&gt;
 % the roughness values in the n-by-2 matrix roughness. yuo will need to&lt;br /&gt;
 % edit the code for your application.&lt;br /&gt;
 &lt;br /&gt;
 [num_sims] = size(roughness);&lt;br /&gt;
 for i = 1:num_sims(1)&lt;br /&gt;
 a = ['mymodel', num2str(i),'.par']; b = num2str(i);&lt;br /&gt;
 fout = fopen(a,'w');&lt;br /&gt;
 fprintf(fout,'DEMfile                  mydem.dem.ascii\n');&lt;br /&gt;
 fprintf(fout,'resroot                  myres%s\n',b);&lt;br /&gt;
 fprintf(fout,'dirroot                  mydir\n');&lt;br /&gt;
 fprintf(fout,'sim_time                 245000.0\n');&lt;br /&gt;
 fprintf(fout,'initial_tstep            10.0\n');&lt;br /&gt;
 fprintf(fout,'massint                  300.0\n');&lt;br /&gt;
 fprintf(fout,'saveint                  10000.0\n');&lt;br /&gt;
 %fprintf(fout,'overpass                 135000.0\n');&lt;br /&gt;
 fprintf(fout,'fpfric                   %1.3f\n',roughness(i,2));&lt;br /&gt;
 fprintf(fout,'nch                      %1.3f\n',roughness(i,1));&lt;br /&gt;
 %fprintf(fout,'manningfile              mymanfile%s.n.ascii\n',b);&lt;br /&gt;
 fprintf(fout,'riverfile                myriver.river\n');&lt;br /&gt;
 fprintf(fout,'bdyfile                  mybdy.bdy\n');&lt;br /&gt;
 fprintf(fout,'stagefile                mystage.stage\n');&lt;br /&gt;
 fprintf(fout,'bcifile                  mybci.bci\n');&lt;br /&gt;
 %fprintf(fout,'startfile                mystart.old\n');&lt;br /&gt;
 %fprintf(fout,'checkpoint               2\n');&lt;br /&gt;
 %fprintf(fout,'checkfile                mycheck.chkpnt\n');&lt;br /&gt;
 fprintf(fout,'elevoff\n');&lt;br /&gt;
 fprintf(fout,'qoutput\n');&lt;br /&gt;
 fprintf(fout,'diffusive\n');&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==Plotting flow vectors from .Qx and .Qy files==&lt;br /&gt;
&lt;br /&gt;
This function will plot flow vectors from a .Qx and .Qy over a dem using the matlab functions image and quiver  &lt;br /&gt;
&lt;br /&gt;
 function lisflood_flow_plotter (qxfile, qyfile, demfile, north, east, south, west, scaling)&lt;br /&gt;
 &lt;br /&gt;
 % This function plots flow vectors from LISFLOOD_FP Qx and QY files&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile);&lt;br /&gt;
 %&lt;br /&gt;
 % these input variables are strings containing the relative of full&lt;br /&gt;
 % pathnames of the .Qx .Qy and ascii dem files to be plotted.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W);&lt;br /&gt;
 %&lt;br /&gt;
 % N, E, W and S are optional they specify the northernmost, southeernmost&lt;br /&gt;
 % ect cell to be displayed. this can be used to crop the domain.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W, scaling);&lt;br /&gt;
 % &lt;br /&gt;
 % scaling is an optional term used to manually scale the vector lengthes&lt;br /&gt;
 % drawn by quiver (the arrow plotting function).&lt;br /&gt;
 %&lt;br /&gt;
 % J Neal&lt;br /&gt;
 % 20/02/2008 &lt;br /&gt;
 &lt;br /&gt;
 %% decide if crop is required and give imput error message&lt;br /&gt;
 if nargin &amp;lt; 3, &lt;br /&gt;
     error('Requires at least three input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7, &lt;br /&gt;
     crop = 0;&lt;br /&gt;
 else&lt;br /&gt;
     crop = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7,&lt;br /&gt;
     scaling = 1;&lt;br /&gt;
 end &lt;br /&gt;
 % Note don't do this for large areas ?&lt;br /&gt;
 %% Task 1: read ascii files&lt;br /&gt;
 % read Qx file&lt;br /&gt;
 [QX, ncolsqx, nrowsqx, xllcornerqx, yllcornerqx, cellsizeqx] = read_file (qxfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read Qy file&lt;br /&gt;
 [QY, ncolsqy, nrowsqy, xllcornerqy, yllcornerqy, cellsizeqy] = read_file (qyfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read DEM&lt;br /&gt;
 [DEM, ncolsdem, nrowsdem, xllcornerdem, yllcornerdem, cellsizedem] = read_file (demfile);&lt;br /&gt;
 %% crop data if required&lt;br /&gt;
 if crop == 1;&lt;br /&gt;
     DEM = DEM(north:south,west:east);&lt;br /&gt;
     QX = QX(north:south,west:east+1);&lt;br /&gt;
     QY = QY(north:south+1,west:east);&lt;br /&gt;
     xllcornerdem = xllcornerdem + west*cellsizedem - cellsizedem;&lt;br /&gt;
     yllcornerdem = yllcornerdem + (nrowsdem - south) * cellsizedem;&lt;br /&gt;
     [nrowsqx, ncolsqx] = size(QX); [nrowsqy, ncolsqy] = size(QY); [nrowsdem, ncolsdem] = size(DEM);&lt;br /&gt;
 end&lt;br /&gt;
 %% Taks 2: Plot dem and generate figure&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap('gray');&lt;br /&gt;
 % Create axes&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcornerdem + nrowsdem*cellsizedem ,yllcornerdem},...&lt;br /&gt;
     'YTick',[0.5,nrowsdem+0.5],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcornerdem,xllcornerdem+ncolsdem*cellsizedem},...&lt;br /&gt;
     'XTick',[0.5, ncolsdem + 0.5],...&lt;br /&gt;
     'Layer','top',...&lt;br /&gt;
     'DataAspectRatio',[1 1 1]...&lt;br /&gt;
     %,'Clim',[13 30]... % uncomment to set colourmap limits manually&lt;br /&gt;
     );&lt;br /&gt;
 &lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM,'Parent',axes1,'CDataMapping','scaled');&lt;br /&gt;
 axis('image');&lt;br /&gt;
 xlabel('Easting (m)');&lt;br /&gt;
 ylabel('Northing (m)');&lt;br /&gt;
 %% Task 3: calculate flow vectors&lt;br /&gt;
 % pre allocate memory for loop... it will run faster this way&lt;br /&gt;
 xlocs = zeros(ncolsqx*nrowsqx+ncolsqy*nrowsqy,1);&lt;br /&gt;
 ylocs = xlocs;&lt;br /&gt;
 U = xlocs;&lt;br /&gt;
 V = xlocs;&lt;br /&gt;
 %work out X and Y locations&lt;br /&gt;
 for i = 1:nrowsqx&lt;br /&gt;
     for j = 1:ncolsqx&lt;br /&gt;
         xlocs((i-1)*ncolsqx+j,1) = j - 0.5;&lt;br /&gt;
         ylocs((i-1)*ncolsqx+j,1) = i;&lt;br /&gt;
         U((i-1)*ncolsqx+j,1) = QX(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 for i = 1:nrowsqy&lt;br /&gt;
     for j = 1:ncolsqy&lt;br /&gt;
         xlocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = j;&lt;br /&gt;
         ylocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = i - 0.5;&lt;br /&gt;
         V(ncolsqx*nrowsqx+(i-1)*ncolsqy+j,1) = QY(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % work out number of nonzeros elements&lt;br /&gt;
 num_flows = nnz(U+V);&lt;br /&gt;
 xlocs2 = zeros(num_flows,1);&lt;br /&gt;
 ylocs2 = xlocs2;&lt;br /&gt;
 U2 = xlocs2;&lt;br /&gt;
 V2 = xlocs2;&lt;br /&gt;
 % remover zero flow locations&lt;br /&gt;
 k = 1;&lt;br /&gt;
 for i = 1:ncolsqx*nrowsqx+ncolsqy*nrowsqy&lt;br /&gt;
     if (U(i,1) == 0) &amp;amp;&amp;amp; (V(i,1) == 0)&lt;br /&gt;
         % do nothing&lt;br /&gt;
     else&lt;br /&gt;
         xlocs2(k,1) = xlocs(i,1);&lt;br /&gt;
         ylocs2(k,1) = ylocs(i,1);&lt;br /&gt;
         U2(k,1) = U(i,1);&lt;br /&gt;
         V2(k,1) = V(i,1);&lt;br /&gt;
         k = k+1;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % check numbers are correct&lt;br /&gt;
 if k == num_flows + 1&lt;br /&gt;
     % all is ok&lt;br /&gt;
 else&lt;br /&gt;
     disp('Problem with flows');&lt;br /&gt;
 end&lt;br /&gt;
 %% Task 4: overlay flow vectors&lt;br /&gt;
 disp('Plotting data... if this is taking a long time you may need fewer locations');&lt;br /&gt;
 quiver (xlocs2,ylocs2,U2,V2, scaling);&lt;br /&gt;
 % quiver (xloc2,yloc2,U2,V2,'Parent',figure1);&lt;br /&gt;
 disp('Done');&lt;br /&gt;
 %% function to read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
==Making movies from .wd files==&lt;br /&gt;
&lt;br /&gt;
This function will convert a series of .wd .Qx or .Qy file into a .avi movie with the same filename&lt;br /&gt;
&lt;br /&gt;
 function LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ) &lt;br /&gt;
 &lt;br /&gt;
 % LISFLOOD_mov generates movies of LISFLOOD-FP output&lt;br /&gt;
 %&lt;br /&gt;
 % LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ)&lt;br /&gt;
 % &lt;br /&gt;
 % where &lt;br /&gt;
 % resroot is the LISFLOOD resroot (relative to m file or absolute)(string)&lt;br /&gt;
 % fileex is the file extension '.wd' (can be chaned to plot WSE and flows)&lt;br /&gt;
 % vartype is the name of the variable being plotted e.g. 'Depth'&lt;br /&gt;
 % num_snaps is the number of snapshot times&lt;br /&gt;
 % snapint is the time interval between each LISFLOOD-FP snapshot (seconds)&lt;br /&gt;
 % dem is the name of the demfile (relative or absolute)&lt;br /&gt;
 % demCS is the range of dem hights to be plotted e.g. demCS = [0,20];&lt;br /&gt;
 % depthCS is the range of depth values to be plotted e.g. depthCS = [0,10];&lt;br /&gt;
 % framesPS number of frames per second (each plot is a simgle frame)&lt;br /&gt;
 % movQ is the movie quality between 1 and 100 (100 is best)&lt;br /&gt;
 % &lt;br /&gt;
 % 8/11/2007. J Neal.&lt;br /&gt;
 %&lt;br /&gt;
 % EXAMPLE:&lt;br /&gt;
 % LISFLOOD_mov ('C:\Experiment1\res22','.wd','Water depth',24,10000,...&lt;br /&gt;
 % 'C:\Experiment1\dem10m.dem.ascii',[0,60], [0,10],1,100);&lt;br /&gt;
 %% Movie maker&lt;br /&gt;
 % read dem filenam is filename and 1 specifies the 0.00 should not be NaN's&lt;br /&gt;
 [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (dem); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 % A = [resroot,'.avi'];&lt;br /&gt;
 % mov = avifile(A);&lt;br /&gt;
 % loop through snapshots&lt;br /&gt;
 for i = 1:num_snaps&lt;br /&gt;
     if i &amp;lt; 10&lt;br /&gt;
         resfile = [resroot,'-000',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 100&lt;br /&gt;
         resfile = [resroot,'-00',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 1000&lt;br /&gt;
         resfile = [resroot,'-0',num2str(i),fileex];&lt;br /&gt;
     else&lt;br /&gt;
         resfile = [resroot,'-',num2str(i),fileex];&lt;br /&gt;
     end&lt;br /&gt;
     % read in deoth file for resfile i (2 specifies the 0.00 should be NaN&lt;br /&gt;
     [DEPTH, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (resfile);&lt;br /&gt;
     % plot data as figure 1&lt;br /&gt;
     plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype);&lt;br /&gt;
     % get movie frame&lt;br /&gt;
     M(i) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     hold off;&lt;br /&gt;
 %     mov = addframe(mov,M(i));&lt;br /&gt;
     % close the figure&lt;br /&gt;
     close all&lt;br /&gt;
 end &lt;br /&gt;
 % % close .avi file&lt;br /&gt;
 % mov = close(mov);&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 disp('Generating .avi movie file');&lt;br /&gt;
 A = [resroot,fileex,'.avi'];&lt;br /&gt;
 movie2avi(M,A,'fps',framesPS,'quality',movQ);&lt;br /&gt;
 disp(A);&lt;br /&gt;
 %% Read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 % convert nodata to NaN;&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if OUT(ii,jj) == nodata&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         elseif OUT(ii,jj) == -99.000&lt;br /&gt;
             % lisflood uses -99.000 as nodat so will also remove these&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         else&lt;br /&gt;
             % do nothing&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% Plotter data for movie slide&lt;br /&gt;
 function plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype)&lt;br /&gt;
 % number of colors in colormap&lt;br /&gt;
 num_colors = 64;&lt;br /&gt;
 % DEM and variable color map&lt;br /&gt;
 cmap = [gray(num_colors); jet(num_colors)];&lt;br /&gt;
 % scale DEM and DEPTH data to fit with new colormap&lt;br /&gt;
 demCS2 = demCS(2)-demCS(1);&lt;br /&gt;
 dem_scalar = num_colors/demCS2;&lt;br /&gt;
 DEM2 = DEM*dem_scalar;&lt;br /&gt;
 depthCS2 = depthCS(2)-depthCS(1);&lt;br /&gt;
 depth_scalar = num_colors/depthCS2;&lt;br /&gt;
 DEPTH2 = (DEPTH*depth_scalar)+num_colors+1;&lt;br /&gt;
 %Plot the DEM&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap(cmap);&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcorner+(nrows*cellsize),yllcorner+cellsize},...&lt;br /&gt;
     'YTick', [1,nrows],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcorner,xllcorner+(ncols*cellsize)-cellsize},...&lt;br /&gt;
     'XTick',[1,ncols],...&lt;br /&gt;
     'Layer','top');&lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM2,'Parent',axes1);&lt;br /&gt;
 axis('equal');axis('tight');&lt;br /&gt;
 % Overlay the water depth (or other variable)&lt;br /&gt;
 H = image(DEPTH2);&lt;br /&gt;
 % code to make depth plot layer transparent&lt;br /&gt;
 OP = ones(nrows,ncols);&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if DEPTH(ii,jj) &amp;gt; 0&lt;br /&gt;
         else&lt;br /&gt;
             OP(ii,jj) = 0;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % make transparent. depth layer must be H&lt;br /&gt;
 set(H,'AlphaData',OP);&lt;br /&gt;
 % label colourbar&lt;br /&gt;
 color_breaks = 5;&lt;br /&gt;
 colorbreak = num_colors/color_breaks;&lt;br /&gt;
 SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 SCALE(1) = 0.0001;&lt;br /&gt;
 for j = 1:color_breaks*2&lt;br /&gt;
     SCALE(j+1) = colorbreak*j;&lt;br /&gt;
 end&lt;br /&gt;
 SCALE(color_breaks+1) = num_colors+1;&lt;br /&gt;
 VIS_SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 VIS_SCALE(1) = demCS(1);&lt;br /&gt;
 for j = 1:color_breaks-1&lt;br /&gt;
     VIS_SCALE(j+1) = ((demCS2/color_breaks)*j)+demCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 VIS_SCALE(color_breaks+1) = depthCS(1);&lt;br /&gt;
 for j = 1:color_breaks&lt;br /&gt;
     VIS_SCALE(j+1+color_breaks) = ((depthCS2/color_breaks)*j)+depthCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 colorbar('YTick',SCALE,'YTickLabel',VIS_SCALE);&lt;br /&gt;
 % Label axis&lt;br /&gt;
 xlabel('BNG easting (m)');&lt;br /&gt;
 ylabel('BNG northing (m)');&lt;br /&gt;
 A = [vartype,' over DEM at time ',num2str((i*snapint)),'s'];&lt;br /&gt;
 title(A);&lt;/div&gt;</summary>
		<author><name>Jeff-neal</name></author>
	</entry>
	<entry>
		<id>https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5038</id>
		<title>LISFLOOD-FP and MATLAB</title>
		<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5038"/>
		<updated>2008-03-18T15:57:47Z</updated>

		<summary type="html">&lt;p&gt;Jeff-neal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains various Matlab functions that may be useful for analysing results from the [http://www.ggy.bris.ac.uk/research/hydrology/models/lisflood LISFLOOD-FP] model.&lt;br /&gt;
&lt;br /&gt;
==File import and export==&lt;br /&gt;
&lt;br /&gt;
===Importing ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will import an ascii raster file using the string filename. To use it, copy and past text into a textfile called ascii_reader.m&lt;br /&gt;
&lt;br /&gt;
 function [dem, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % This function reads arc .asc files&lt;br /&gt;
 % requires filename string as input&lt;br /&gt;
 &lt;br /&gt;
 % j neal&lt;br /&gt;
 % 18/6/07&lt;br /&gt;
 %% read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 dem = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 dem = dem';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
You can view the imported file using the command:&lt;br /&gt;
&lt;br /&gt;
 imagesc(dem);&lt;br /&gt;
&lt;br /&gt;
===Exporting ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will create an ascii raster file called filename from the 2D matrix DEM.  To use it, copy and past text into a textfile called ascii_write.m&lt;br /&gt;
&lt;br /&gt;
 function ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 &lt;br /&gt;
 % ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 % only filename (string) and DEM (2D matrix) are essential&lt;br /&gt;
 % this function writes ascii raster files for arc&lt;br /&gt;
 % j neal&lt;br /&gt;
 % 6/3/2008&lt;br /&gt;
 &lt;br /&gt;
 if nargin &amp;lt; 2, &lt;br /&gt;
     error('Requires at least two input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4, &lt;br /&gt;
     xllcorner = 0;&lt;br /&gt;
     yllcorner = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 5,&lt;br /&gt;
     cellsize = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 6&lt;br /&gt;
     nodata = -9999;&lt;br /&gt;
 end&lt;br /&gt;
 A = size(DEM);&lt;br /&gt;
 fout = fopen (filename,'w');&lt;br /&gt;
 fprintf(fout, 'ncols         %.0f\n', A(2));  &lt;br /&gt;
 fprintf(fout, 'nrows         %.0f\n', A(1));&lt;br /&gt;
 fprintf(fout, 'xllcorner     %f\n', xllcorner);&lt;br /&gt;
 fprintf(fout, 'yllcorner     %f\n', yllcorner);&lt;br /&gt;
 fprintf(fout, 'cellsize      %f\n', cellsize);&lt;br /&gt;
 fprintf(fout, 'NODATA_value  %f\n', nodata); &lt;br /&gt;
 for ii = 1:A(1)&lt;br /&gt;
     B = DEM(ii,:);&lt;br /&gt;
     fprintf(fout, '%1.3f ', B);&lt;br /&gt;
     fprintf(fout, '\n');&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
===Writing parameter files===&lt;br /&gt;
&lt;br /&gt;
This function can be used to write many LISFLOOD-FP parameter files with ''N'' different channel and floodplain roughness, using your own ''N-by-''2 matrix called roughness. You will need to edit the code for your application by commenting unwanted lines with a percentage symbol.&lt;br /&gt;
&lt;br /&gt;
 function prm_writer (roughness) &lt;br /&gt;
 &lt;br /&gt;
 % This function writes LISFLOOD-FP parameter files numbered 1 to n using&lt;br /&gt;
 % the roughness values in the n-by-2 matrix roughness. yuo will need to&lt;br /&gt;
 % edit the code for your application.&lt;br /&gt;
 &lt;br /&gt;
 [num_sims] = size(roughness);&lt;br /&gt;
 for i = 1:num_sims(1)&lt;br /&gt;
 a = ['mymodel', num2str(i),'.par']; b = num2str(i);&lt;br /&gt;
 fout = fopen(a,'w');&lt;br /&gt;
 fprintf(fout,'DEMfile                  mydem.dem.ascii\n');&lt;br /&gt;
 fprintf(fout,'resroot                  myres%s\n',b);&lt;br /&gt;
 fprintf(fout,'dirroot                  mydir\n');&lt;br /&gt;
 fprintf(fout,'sim_time                 245000.0\n');&lt;br /&gt;
 fprintf(fout,'initial_tstep            10.0\n');&lt;br /&gt;
 fprintf(fout,'massint                  300.0\n');&lt;br /&gt;
 fprintf(fout,'saveint                  10000.0\n');&lt;br /&gt;
 %fprintf(fout,'overpass                 135000.0\n');&lt;br /&gt;
 fprintf(fout,'fpfric                   %1.3f\n',roughness(i,2));&lt;br /&gt;
 fprintf(fout,'nch                      %1.3f\n',roughness(i,1));&lt;br /&gt;
 %fprintf(fout,'manningfile              mymanfile%s.n.ascii\n',b);&lt;br /&gt;
 fprintf(fout,'riverfile                myriver.river\n');&lt;br /&gt;
 fprintf(fout,'bdyfile                  mybdy.bdy\n');&lt;br /&gt;
 fprintf(fout,'stagefile                mystage.stage\n');&lt;br /&gt;
 fprintf(fout,'bcifile                  mybci.bci\n');&lt;br /&gt;
 %fprintf(fout,'startfile                mystart.old\n');&lt;br /&gt;
 %fprintf(fout,'checkpoint               2\n');&lt;br /&gt;
 %fprintf(fout,'checkfile                mycheck.chkpnt\n');&lt;br /&gt;
 fprintf(fout,'elevoff\n');&lt;br /&gt;
 fprintf(fout,'qoutput\n');&lt;br /&gt;
 fprintf(fout,'diffusive\n');&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==Plotting flow vectors from .Qx and .Qy files==&lt;br /&gt;
&lt;br /&gt;
This function will plot flow vectors from a .Qx and .Qy over a dem using the matlab functions image and quiver  &lt;br /&gt;
&lt;br /&gt;
 function lisflood_flow_plotter (qxfile, qyfile, demfile, north, east, south, west, scaling)&lt;br /&gt;
 &lt;br /&gt;
 % This function plots flow vectors from LISFLOOD_FP Qx and QY files&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile);&lt;br /&gt;
 %&lt;br /&gt;
 % these input variables are strings containing the relative of full&lt;br /&gt;
 % pathnames of the .Qx .Qy and ascii dem files to be plotted.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W);&lt;br /&gt;
 %&lt;br /&gt;
 % N, E, W and S are optional they specify the northernmost, southeernmost&lt;br /&gt;
 % ect cell to be displayed. this can be used to crop the domain.&lt;br /&gt;
 %&lt;br /&gt;
 % lisflood_flow_plotter (qxfile, qyfile, demfile, N, E, S, W, scaling);&lt;br /&gt;
 % &lt;br /&gt;
 % scaling is an optional term used to manually scale the vector lengthes&lt;br /&gt;
 % drawn by quiver (the arrow plotting function).&lt;br /&gt;
 %&lt;br /&gt;
 % J Neal&lt;br /&gt;
 % 20/02/2008 &lt;br /&gt;
 &lt;br /&gt;
 %% decide if crop is required and give imput error message&lt;br /&gt;
 if nargin &amp;lt; 3, &lt;br /&gt;
     error('Requires at least three input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7, &lt;br /&gt;
     crop = 0;&lt;br /&gt;
 else&lt;br /&gt;
     crop = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 7,&lt;br /&gt;
     scaling = 1;&lt;br /&gt;
 end &lt;br /&gt;
 % Note don't do this for large areas ?&lt;br /&gt;
 %% Task 1: read ascii files&lt;br /&gt;
 % read Qx file&lt;br /&gt;
 [QX, ncolsqx, nrowsqx, xllcornerqx, yllcornerqx, cellsizeqx] = read_file (qxfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read Qy file&lt;br /&gt;
 [QY, ncolsqy, nrowsqy, xllcornerqy, yllcornerqy, cellsizeqy] = read_file (qyfile); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % read DEM&lt;br /&gt;
 [DEM, ncolsdem, nrowsdem, xllcornerdem, yllcornerdem, cellsizedem] = read_file (demfile);&lt;br /&gt;
 %% crop data if required&lt;br /&gt;
 if crop == 1;&lt;br /&gt;
     DEM = DEM(north:south,west:east);&lt;br /&gt;
     QX = QX(north:south,west:east+1);&lt;br /&gt;
     QY = QY(north:south+1,west:east);&lt;br /&gt;
     xllcornerdem = xllcornerdem + west*cellsizedem - cellsizedem;&lt;br /&gt;
     yllcornerdem = yllcornerdem + (nrowsdem - south) * cellsizedem;&lt;br /&gt;
     [nrowsqx, ncolsqx] = size(QX); [nrowsqy, ncolsqy] = size(QY); [nrowsdem, ncolsdem] = size(DEM);&lt;br /&gt;
 end&lt;br /&gt;
 %% Taks 2: Plot dem and generate figure&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap('gray');&lt;br /&gt;
 % Create axes&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcornerdem + nrowsdem*cellsizedem ,yllcornerdem},...&lt;br /&gt;
     'YTick',[0.5,nrowsdem+0.5],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcornerdem,xllcornerdem+ncolsdem*cellsizedem},...&lt;br /&gt;
     'XTick',[0.5, ncolsdem + 0.5],...&lt;br /&gt;
     'Layer','top',...&lt;br /&gt;
     'DataAspectRatio',[1 1 1]...&lt;br /&gt;
     %,'Clim',[13 30]... % uncomment to set colourmap limits manually&lt;br /&gt;
     );&lt;br /&gt;
 &lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM,'Parent',axes1,'CDataMapping','scaled');&lt;br /&gt;
 axis('image');&lt;br /&gt;
 xlabel('Easting (m)');&lt;br /&gt;
 ylabel('Northing (m)');&lt;br /&gt;
 %% Task 3: calculate flow vectors&lt;br /&gt;
 % pre allocate memory for loop... it will run faster this way&lt;br /&gt;
 xlocs = zeros(ncolsqx*nrowsqx+ncolsqy*nrowsqy,1);&lt;br /&gt;
 ylocs = xlocs;&lt;br /&gt;
 U = xlocs;&lt;br /&gt;
 V = xlocs;&lt;br /&gt;
 %work out X and Y locations&lt;br /&gt;
 for i = 1:nrowsqx&lt;br /&gt;
     for j = 1:ncolsqx&lt;br /&gt;
         xlocs((i-1)*ncolsqx+j,1) = j - 0.5;&lt;br /&gt;
         ylocs((i-1)*ncolsqx+j,1) = i;&lt;br /&gt;
         U((i-1)*ncolsqx+j,1) = QX(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 for i = 1:nrowsqy&lt;br /&gt;
     for j = 1:ncolsqy&lt;br /&gt;
         xlocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = j;&lt;br /&gt;
         ylocs(ncolsqx*nrowsqx + (i-1)*ncolsqy +j,1) = i - 0.5;&lt;br /&gt;
         V(ncolsqx*nrowsqx+(i-1)*ncolsqy+j,1) = QY(i,j);&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % work out number of nonzeros elements&lt;br /&gt;
 num_flows = nnz(U+V);&lt;br /&gt;
 xlocs2 = zeros(num_flows,1);&lt;br /&gt;
 ylocs2 = xlocs2;&lt;br /&gt;
 U2 = xlocs2;&lt;br /&gt;
 V2 = xlocs2;&lt;br /&gt;
 % remover zero flow locations&lt;br /&gt;
 k = 1;&lt;br /&gt;
 for i = 1:ncolsqx*nrowsqx+ncolsqy*nrowsqy&lt;br /&gt;
     if (U(i,1) == 0) &amp;amp;&amp;amp; (V(i,1) == 0)&lt;br /&gt;
         % do nothing&lt;br /&gt;
     else&lt;br /&gt;
         xlocs2(k,1) = xlocs(i,1);&lt;br /&gt;
         ylocs2(k,1) = ylocs(i,1);&lt;br /&gt;
         U2(k,1) = U(i,1);&lt;br /&gt;
         V2(k,1) = V(i,1);&lt;br /&gt;
         k = k+1;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % check numbers are correct&lt;br /&gt;
 if k == num_flows + 1&lt;br /&gt;
     % all is ok&lt;br /&gt;
 else&lt;br /&gt;
     disp('Problem with flows');&lt;br /&gt;
 end&lt;br /&gt;
 %% Task 4: overlay flow vectors&lt;br /&gt;
 disp('Plotting data... if this is taking a long time you may need fewer locations');&lt;br /&gt;
 quiver (xlocs2,ylocs2,U2,V2, scaling);&lt;br /&gt;
 % quiver (xloc2,yloc2,U2,V2,'Parent',figure1);&lt;br /&gt;
 disp('Done');&lt;br /&gt;
 %% function to read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
==Making movies from .wd files==&lt;br /&gt;
&lt;br /&gt;
This function will convert a series of .wd .Qx or .Qy file into a .avi movie with the same filename&lt;br /&gt;
&lt;br /&gt;
 function LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ) &lt;br /&gt;
 &lt;br /&gt;
 % LISFLOOD_mov generates movies of LISFLOOD-FP output&lt;br /&gt;
 %&lt;br /&gt;
 % LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ)&lt;br /&gt;
 % &lt;br /&gt;
 % where &lt;br /&gt;
 % resroot is the LISFLOOD resroot (relative to m file or absolute)(string)&lt;br /&gt;
 % fileex is the file extension '.wd' (can be chaned to plot WSE and flows)&lt;br /&gt;
 % vartype is the name of the variable being plotted e.g. 'Depth'&lt;br /&gt;
 % num_snaps is the number of snapshot times&lt;br /&gt;
 % snapint is the time interval between each LISFLOOD-FP snapshot (seconds)&lt;br /&gt;
 % dem is the name of the demfile (relative or absolute)&lt;br /&gt;
 % demCS is the range of dem hights to be plotted e.g. demCS = [0,20];&lt;br /&gt;
 % depthCS is the range of depth values to be plotted e.g. depthCS = [0,10];&lt;br /&gt;
 % framesPS number of frames per second (each plot is a simgle frame)&lt;br /&gt;
 % movQ is the movie quality between 1 and 100 (100 is best)&lt;br /&gt;
 % &lt;br /&gt;
 % 8/11/2007. J Neal.&lt;br /&gt;
 %&lt;br /&gt;
 % EXAMPLE:&lt;br /&gt;
 % LISFLOOD_mov ('C:\Experiment1\res22','.wd','Water depth',24,10000,...&lt;br /&gt;
 % 'C:\Experiment1\dem10m.dem.ascii',[0,60], [0,10],1,100);&lt;br /&gt;
 %% Movie maker&lt;br /&gt;
 % read dem filenam is filename and 1 specifies the 0.00 should not be NaN's&lt;br /&gt;
 [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (dem); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 % A = [resroot,'.avi'];&lt;br /&gt;
 % mov = avifile(A);&lt;br /&gt;
 % loop through snapshots&lt;br /&gt;
 for i = 1:num_snaps&lt;br /&gt;
     if i &amp;lt; 10&lt;br /&gt;
         resfile = [resroot,'-000',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 100&lt;br /&gt;
         resfile = [resroot,'-00',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 1000&lt;br /&gt;
         resfile = [resroot,'-0',num2str(i),fileex];&lt;br /&gt;
     else&lt;br /&gt;
         resfile = [resroot,'-',num2str(i),fileex];&lt;br /&gt;
     end&lt;br /&gt;
     % read in deoth file for resfile i (2 specifies the 0.00 should be NaN&lt;br /&gt;
     [DEPTH, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (resfile);&lt;br /&gt;
     % plot data as figure 1&lt;br /&gt;
     plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype);&lt;br /&gt;
     % get movie frame&lt;br /&gt;
     M(i) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     hold off;&lt;br /&gt;
 %     mov = addframe(mov,M(i));&lt;br /&gt;
     % close the figure&lt;br /&gt;
     close all&lt;br /&gt;
 end &lt;br /&gt;
 % % close .avi file&lt;br /&gt;
 % mov = close(mov);&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 disp('Generating .avi movie file');&lt;br /&gt;
 A = [resroot,fileex,'.avi'];&lt;br /&gt;
 movie2avi(M,A,'fps',framesPS,'quality',movQ);&lt;br /&gt;
 disp(A);&lt;br /&gt;
 %% Read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 % convert nodata to NaN;&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if OUT(ii,jj) == nodata&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         elseif OUT(ii,jj) == -99.000&lt;br /&gt;
             % lisflood uses -99.000 as nodat so will also remove these&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         else&lt;br /&gt;
             % do nothing&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% Plotter data for movie slide&lt;br /&gt;
 function plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype)&lt;br /&gt;
 % number of colors in colormap&lt;br /&gt;
 num_colors = 64;&lt;br /&gt;
 % DEM and variable color map&lt;br /&gt;
 cmap = [gray(num_colors); jet(num_colors)];&lt;br /&gt;
 % scale DEM and DEPTH data to fit with new colormap&lt;br /&gt;
 demCS2 = demCS(2)-demCS(1);&lt;br /&gt;
 dem_scalar = num_colors/demCS2;&lt;br /&gt;
 DEM2 = DEM*dem_scalar;&lt;br /&gt;
 depthCS2 = depthCS(2)-depthCS(1);&lt;br /&gt;
 depth_scalar = num_colors/depthCS2;&lt;br /&gt;
 DEPTH2 = (DEPTH*depth_scalar)+num_colors+1;&lt;br /&gt;
 %Plot the DEM&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap(cmap);&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcorner+(nrows*cellsize),yllcorner+cellsize},...&lt;br /&gt;
     'YTick', [1,nrows],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcorner,xllcorner+(ncols*cellsize)-cellsize},...&lt;br /&gt;
     'XTick',[1,ncols],...&lt;br /&gt;
     'Layer','top');&lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM2,'Parent',axes1);&lt;br /&gt;
 axis('equal');axis('tight');&lt;br /&gt;
 % Overlay the water depth (or other variable)&lt;br /&gt;
 H = image(DEPTH2);&lt;br /&gt;
 % code to make depth plot layer transparent&lt;br /&gt;
 OP = ones(nrows,ncols);&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if DEPTH(ii,jj) &amp;gt; 0&lt;br /&gt;
         else&lt;br /&gt;
             OP(ii,jj) = 0;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % make transparent. depth layer must be H&lt;br /&gt;
 set(H,'AlphaData',OP);&lt;br /&gt;
 % label colourbar&lt;br /&gt;
 color_breaks = 5;&lt;br /&gt;
 colorbreak = num_colors/color_breaks;&lt;br /&gt;
 SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 SCALE(1) = 0.0001;&lt;br /&gt;
 for j = 1:color_breaks*2&lt;br /&gt;
     SCALE(j+1) = colorbreak*j;&lt;br /&gt;
 end&lt;br /&gt;
 SCALE(color_breaks+1) = num_colors+1;&lt;br /&gt;
 VIS_SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 VIS_SCALE(1) = demCS(1);&lt;br /&gt;
 for j = 1:color_breaks-1&lt;br /&gt;
     VIS_SCALE(j+1) = ((demCS2/color_breaks)*j)+demCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 VIS_SCALE(color_breaks+1) = depthCS(1);&lt;br /&gt;
 for j = 1:color_breaks&lt;br /&gt;
     VIS_SCALE(j+1+color_breaks) = ((depthCS2/color_breaks)*j)+depthCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 colorbar('YTick',SCALE,'YTickLabel',VIS_SCALE);&lt;br /&gt;
 % Label axis&lt;br /&gt;
 xlabel('BNG easting (m)');&lt;br /&gt;
 ylabel('BNG northing (m)');&lt;br /&gt;
 A = [vartype,' over DEM at time ',num2str((i*snapint)),'s'];&lt;br /&gt;
 title(A);&lt;/div&gt;</summary>
		<author><name>Jeff-neal</name></author>
	</entry>
	<entry>
		<id>https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5037</id>
		<title>LISFLOOD-FP and MATLAB</title>
		<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5037"/>
		<updated>2008-03-18T15:50:34Z</updated>

		<summary type="html">&lt;p&gt;Jeff-neal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains various Matlab functions that may be useful for analysing results from the [http://www.ggy.bris.ac.uk/research/hydrology/models/lisflood LISFLOOD-FP] model.&lt;br /&gt;
&lt;br /&gt;
==File import and export==&lt;br /&gt;
&lt;br /&gt;
===Importing ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will import an ascii raster file using the string filename. To use it, copy and past text into a textfile called ascii_reader.m&lt;br /&gt;
&lt;br /&gt;
 function [dem, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % This function reads arc .asc files&lt;br /&gt;
 % requires filename string as input&lt;br /&gt;
 &lt;br /&gt;
 % j neal&lt;br /&gt;
 % 18/6/07&lt;br /&gt;
 %% read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 dem = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 dem = dem';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
You can view the imported file using the command:&lt;br /&gt;
&lt;br /&gt;
 imagesc(dem);&lt;br /&gt;
&lt;br /&gt;
===Exporting ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will create an ascii raster file called filename from the 2D matrix DEM.  To use it, copy and past text into a textfile called ascii_write.m&lt;br /&gt;
&lt;br /&gt;
 function ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 &lt;br /&gt;
 % ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 % only filename (string) and DEM (2D matrix) are essential&lt;br /&gt;
 % this function writes ascii raster files for arc&lt;br /&gt;
 % j neal&lt;br /&gt;
 % 6/3/2008&lt;br /&gt;
 &lt;br /&gt;
 if nargin &amp;lt; 2, &lt;br /&gt;
     error('Requires at least two input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4, &lt;br /&gt;
     xllcorner = 0;&lt;br /&gt;
     yllcorner = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 5,&lt;br /&gt;
     cellsize = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 6&lt;br /&gt;
     nodata = -9999;&lt;br /&gt;
 end&lt;br /&gt;
 A = size(DEM);&lt;br /&gt;
 fout = fopen (filename,'w');&lt;br /&gt;
 fprintf(fout, 'ncols         %.0f\n', A(2));  &lt;br /&gt;
 fprintf(fout, 'nrows         %.0f\n', A(1));&lt;br /&gt;
 fprintf(fout, 'xllcorner     %f\n', xllcorner);&lt;br /&gt;
 fprintf(fout, 'yllcorner     %f\n', yllcorner);&lt;br /&gt;
 fprintf(fout, 'cellsize      %f\n', cellsize);&lt;br /&gt;
 fprintf(fout, 'NODATA_value  %f\n', nodata); &lt;br /&gt;
 for ii = 1:A(1)&lt;br /&gt;
     B = DEM(ii,:);&lt;br /&gt;
     fprintf(fout, '%1.3f ', B);&lt;br /&gt;
     fprintf(fout, '\n');&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
===Writing parameter files===&lt;br /&gt;
&lt;br /&gt;
This function can be used to write many LISFLOOD-FP parameter files with ''N'' different channel and floodplain roughness, using your own ''N-by-''2 matrix called roughness. You will need to edit the code for your application by commenting unwanted lines with a percentage symbol.&lt;br /&gt;
&lt;br /&gt;
 function prm_writer (roughness) &lt;br /&gt;
 &lt;br /&gt;
 % This function writes LISFLOOD-FP parameter files numbered 1 to n using&lt;br /&gt;
 % the roughness values in the n-by-2 matrix roughness. yuo will need to&lt;br /&gt;
 % edit the code for your application.&lt;br /&gt;
 &lt;br /&gt;
 [num_sims] = size(roughness);&lt;br /&gt;
 for i = 1:num_sims(1)&lt;br /&gt;
 a = ['mymodel', num2str(i),'.par']; b = num2str(i);&lt;br /&gt;
 fout = fopen(a,'w');&lt;br /&gt;
 fprintf(fout,'DEMfile                  mydem.dem.ascii\n');&lt;br /&gt;
 fprintf(fout,'resroot                  myres%s\n',b);&lt;br /&gt;
 fprintf(fout,'dirroot                  mydir\n');&lt;br /&gt;
 fprintf(fout,'sim_time                 245000.0\n');&lt;br /&gt;
 fprintf(fout,'initial_tstep            10.0\n');&lt;br /&gt;
 fprintf(fout,'massint                  300.0\n');&lt;br /&gt;
 fprintf(fout,'saveint                  10000.0\n');&lt;br /&gt;
 %fprintf(fout,'overpass                 135000.0\n');&lt;br /&gt;
 fprintf(fout,'fpfric                   %1.3f\n',roughness(i,2));&lt;br /&gt;
 fprintf(fout,'nch                      %1.3f\n',roughness(i,1));&lt;br /&gt;
 %fprintf(fout,'manningfile              mymanfile%s.n.ascii\n',b);&lt;br /&gt;
 fprintf(fout,'riverfile                myriver.river\n');&lt;br /&gt;
 fprintf(fout,'bdyfile                  mybdy.bdy\n');&lt;br /&gt;
 fprintf(fout,'stagefile                mystage.stage\n');&lt;br /&gt;
 fprintf(fout,'bcifile                  mybci.bci\n');&lt;br /&gt;
 %fprintf(fout,'startfile                mystart.old\n');&lt;br /&gt;
 %fprintf(fout,'checkpoint               2\n');&lt;br /&gt;
 %fprintf(fout,'checkfile                mycheck.chkpnt\n');&lt;br /&gt;
 fprintf(fout,'elevoff\n');&lt;br /&gt;
 fprintf(fout,'qoutput\n');&lt;br /&gt;
 fprintf(fout,'diffusive\n');&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Making movies from .wd files==&lt;br /&gt;
&lt;br /&gt;
This function will convert a series of .wd .Qx or .Qy file into a .avi movie with the same filename&lt;br /&gt;
&lt;br /&gt;
 function LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ) &lt;br /&gt;
 &lt;br /&gt;
 % LISFLOOD_mov generates movies of LISFLOOD-FP output&lt;br /&gt;
 %&lt;br /&gt;
 % LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ)&lt;br /&gt;
 % &lt;br /&gt;
 % where &lt;br /&gt;
 % resroot is the LISFLOOD resroot (relative to m file or absolute)(string)&lt;br /&gt;
 % fileex is the file extension '.wd' (can be chaned to plot WSE and flows)&lt;br /&gt;
 % vartype is the name of the variable being plotted e.g. 'Depth'&lt;br /&gt;
 % num_snaps is the number of snapshot times&lt;br /&gt;
 % snapint is the time interval between each LISFLOOD-FP snapshot (seconds)&lt;br /&gt;
 % dem is the name of the demfile (relative or absolute)&lt;br /&gt;
 % demCS is the range of dem hights to be plotted e.g. demCS = [0,20];&lt;br /&gt;
 % depthCS is the range of depth values to be plotted e.g. depthCS = [0,10];&lt;br /&gt;
 % framesPS number of frames per second (each plot is a simgle frame)&lt;br /&gt;
 % movQ is the movie quality between 1 and 100 (100 is best)&lt;br /&gt;
 % &lt;br /&gt;
 % 8/11/2007. J Neal.&lt;br /&gt;
 %&lt;br /&gt;
 % EXAMPLE:&lt;br /&gt;
 % LISFLOOD_mov ('C:\Experiment1\res22','.wd','Water depth',24,10000,...&lt;br /&gt;
 % 'C:\Experiment1\dem10m.dem.ascii',[0,60], [0,10],1,100);&lt;br /&gt;
 %% Movie maker&lt;br /&gt;
 % read dem filenam is filename and 1 specifies the 0.00 should not be NaN's&lt;br /&gt;
 [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (dem); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 % A = [resroot,'.avi'];&lt;br /&gt;
 % mov = avifile(A);&lt;br /&gt;
 % loop through snapshots&lt;br /&gt;
 for i = 1:num_snaps&lt;br /&gt;
     if i &amp;lt; 10&lt;br /&gt;
         resfile = [resroot,'-000',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 100&lt;br /&gt;
         resfile = [resroot,'-00',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 1000&lt;br /&gt;
         resfile = [resroot,'-0',num2str(i),fileex];&lt;br /&gt;
     else&lt;br /&gt;
         resfile = [resroot,'-',num2str(i),fileex];&lt;br /&gt;
     end&lt;br /&gt;
     % read in deoth file for resfile i (2 specifies the 0.00 should be NaN&lt;br /&gt;
     [DEPTH, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (resfile);&lt;br /&gt;
     % plot data as figure 1&lt;br /&gt;
     plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype);&lt;br /&gt;
     % get movie frame&lt;br /&gt;
     M(i) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     hold off;&lt;br /&gt;
 %     mov = addframe(mov,M(i));&lt;br /&gt;
     % close the figure&lt;br /&gt;
     close all&lt;br /&gt;
 end &lt;br /&gt;
 % % close .avi file&lt;br /&gt;
 % mov = close(mov);&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 disp('Generating .avi movie file');&lt;br /&gt;
 A = [resroot,fileex,'.avi'];&lt;br /&gt;
 movie2avi(M,A,'fps',framesPS,'quality',movQ);&lt;br /&gt;
 disp(A);&lt;br /&gt;
 %% Read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 % convert nodata to NaN;&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if OUT(ii,jj) == nodata&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         elseif OUT(ii,jj) == -99.000&lt;br /&gt;
             % lisflood uses -99.000 as nodat so will also remove these&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         else&lt;br /&gt;
             % do nothing&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% Plotter data for movie slide&lt;br /&gt;
 function plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype)&lt;br /&gt;
 % number of colors in colormap&lt;br /&gt;
 num_colors = 64;&lt;br /&gt;
 % DEM and variable color map&lt;br /&gt;
 cmap = [gray(num_colors); jet(num_colors)];&lt;br /&gt;
 % scale DEM and DEPTH data to fit with new colormap&lt;br /&gt;
 demCS2 = demCS(2)-demCS(1);&lt;br /&gt;
 dem_scalar = num_colors/demCS2;&lt;br /&gt;
 DEM2 = DEM*dem_scalar;&lt;br /&gt;
 depthCS2 = depthCS(2)-depthCS(1);&lt;br /&gt;
 depth_scalar = num_colors/depthCS2;&lt;br /&gt;
 DEPTH2 = (DEPTH*depth_scalar)+num_colors+1;&lt;br /&gt;
 %Plot the DEM&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap(cmap);&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcorner+(nrows*cellsize),yllcorner+cellsize},...&lt;br /&gt;
     'YTick', [1,nrows],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcorner,xllcorner+(ncols*cellsize)-cellsize},...&lt;br /&gt;
     'XTick',[1,ncols],...&lt;br /&gt;
     'Layer','top');&lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM2,'Parent',axes1);&lt;br /&gt;
 axis('equal');axis('tight');&lt;br /&gt;
 % Overlay the water depth (or other variable)&lt;br /&gt;
 H = image(DEPTH2);&lt;br /&gt;
 % code to make depth plot layer transparent&lt;br /&gt;
 OP = ones(nrows,ncols);&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if DEPTH(ii,jj) &amp;gt; 0&lt;br /&gt;
         else&lt;br /&gt;
             OP(ii,jj) = 0;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % make transparent. depth layer must be H&lt;br /&gt;
 set(H,'AlphaData',OP);&lt;br /&gt;
 % label colourbar&lt;br /&gt;
 color_breaks = 5;&lt;br /&gt;
 colorbreak = num_colors/color_breaks;&lt;br /&gt;
 SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 SCALE(1) = 0.0001;&lt;br /&gt;
 for j = 1:color_breaks*2&lt;br /&gt;
     SCALE(j+1) = colorbreak*j;&lt;br /&gt;
 end&lt;br /&gt;
 SCALE(color_breaks+1) = num_colors+1;&lt;br /&gt;
 VIS_SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 VIS_SCALE(1) = demCS(1);&lt;br /&gt;
 for j = 1:color_breaks-1&lt;br /&gt;
     VIS_SCALE(j+1) = ((demCS2/color_breaks)*j)+demCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 VIS_SCALE(color_breaks+1) = depthCS(1);&lt;br /&gt;
 for j = 1:color_breaks&lt;br /&gt;
     VIS_SCALE(j+1+color_breaks) = ((depthCS2/color_breaks)*j)+depthCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 colorbar('YTick',SCALE,'YTickLabel',VIS_SCALE);&lt;br /&gt;
 % Label axis&lt;br /&gt;
 xlabel('BNG easting (m)');&lt;br /&gt;
 ylabel('BNG northing (m)');&lt;br /&gt;
 A = [vartype,' over DEM at time ',num2str((i*snapint)),'s'];&lt;br /&gt;
 title(A);&lt;/div&gt;</summary>
		<author><name>Jeff-neal</name></author>
	</entry>
	<entry>
		<id>https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5036</id>
		<title>LISFLOOD-FP and MATLAB</title>
		<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5036"/>
		<updated>2008-03-18T15:26:50Z</updated>

		<summary type="html">&lt;p&gt;Jeff-neal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains various Matlab functions that may be useful for analysing results from the [http://www.ggy.bris.ac.uk/research/hydrology/models/lisflood LISFLOOD-FP] model.&lt;br /&gt;
&lt;br /&gt;
==File import and export==&lt;br /&gt;
&lt;br /&gt;
===Importing ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will import an ascii raster file using the string filename. To use it, copy and past text into a textfile called ascii_reader.m&lt;br /&gt;
&lt;br /&gt;
 function [dem, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % This function reads arc .asc files&lt;br /&gt;
 % requires filename string as input&lt;br /&gt;
 &lt;br /&gt;
 % j neal&lt;br /&gt;
 % 18/6/07&lt;br /&gt;
 %% read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 dem = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 dem = dem';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
You can view the imported file using the command:&lt;br /&gt;
&lt;br /&gt;
 imagesc(dem);&lt;br /&gt;
&lt;br /&gt;
===Exporting ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will create an ascii raster file called filename from the 2D matrix DEM.  To use it, copy and past text into a textfile called ascii_write.m&lt;br /&gt;
&lt;br /&gt;
 function ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 &lt;br /&gt;
 % ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 % only filename (string) and DEM (2D matrix) are essential&lt;br /&gt;
 % this function writes ascii raster files for arc&lt;br /&gt;
 % j neal&lt;br /&gt;
 % 6/3/2008&lt;br /&gt;
 &lt;br /&gt;
 if nargin &amp;lt; 2, &lt;br /&gt;
     error('Requires at least two input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4, &lt;br /&gt;
     xllcorner = 0;&lt;br /&gt;
     yllcorner = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 5,&lt;br /&gt;
     cellsize = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 6&lt;br /&gt;
     nodata = -9999;&lt;br /&gt;
 end&lt;br /&gt;
 A = size(DEM);&lt;br /&gt;
 fout = fopen (filename,'w');&lt;br /&gt;
 fprintf(fout, 'ncols         %.0f\n', A(2));  &lt;br /&gt;
 fprintf(fout, 'nrows         %.0f\n', A(1));&lt;br /&gt;
 fprintf(fout, 'xllcorner     %f\n', xllcorner);&lt;br /&gt;
 fprintf(fout, 'yllcorner     %f\n', yllcorner);&lt;br /&gt;
 fprintf(fout, 'cellsize      %f\n', cellsize);&lt;br /&gt;
 fprintf(fout, 'NODATA_value  %f\n', nodata); &lt;br /&gt;
 for ii = 1:A(1)&lt;br /&gt;
     B = DEM(ii,:);&lt;br /&gt;
     fprintf(fout, '%1.3f ', B);&lt;br /&gt;
     fprintf(fout, '\n');&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
==Making movies from .wd files==&lt;br /&gt;
&lt;br /&gt;
This function will convert a series of .wd .Qx or .Qy file into a .avi movie with the same filename&lt;br /&gt;
&lt;br /&gt;
 function LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ) &lt;br /&gt;
 &lt;br /&gt;
 % LISFLOOD_mov generates movies of LISFLOOD-FP output&lt;br /&gt;
 %&lt;br /&gt;
 % LISFLOOD_mov (resroot,fileex,vartype,num_snaps,snapint,dem,demCS,depthCS,framesPS,movQ)&lt;br /&gt;
 % &lt;br /&gt;
 % where &lt;br /&gt;
 % resroot is the LISFLOOD resroot (relative to m file or absolute)(string)&lt;br /&gt;
 % fileex is the file extension '.wd' (can be chaned to plot WSE and flows)&lt;br /&gt;
 % vartype is the name of the variable being plotted e.g. 'Depth'&lt;br /&gt;
 % num_snaps is the number of snapshot times&lt;br /&gt;
 % snapint is the time interval between each LISFLOOD-FP snapshot (seconds)&lt;br /&gt;
 % dem is the name of the demfile (relative or absolute)&lt;br /&gt;
 % demCS is the range of dem hights to be plotted e.g. demCS = [0,20];&lt;br /&gt;
 % depthCS is the range of depth values to be plotted e.g. depthCS = [0,10];&lt;br /&gt;
 % framesPS number of frames per second (each plot is a simgle frame)&lt;br /&gt;
 % movQ is the movie quality between 1 and 100 (100 is best)&lt;br /&gt;
 % &lt;br /&gt;
 % 8/11/2007. J Neal.&lt;br /&gt;
 %&lt;br /&gt;
 % EXAMPLE:&lt;br /&gt;
 % LISFLOOD_mov ('C:\Experiment1\res22','.wd','Water depth',24,10000,...&lt;br /&gt;
 % 'C:\Experiment1\dem10m.dem.ascii',[0,60], [0,10],1,100);&lt;br /&gt;
 %% Movie maker&lt;br /&gt;
 % read dem filenam is filename and 1 specifies the 0.00 should not be NaN's&lt;br /&gt;
 [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (dem); %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 % A = [resroot,'.avi'];&lt;br /&gt;
 % mov = avifile(A);&lt;br /&gt;
 % loop through snapshots&lt;br /&gt;
 for i = 1:num_snaps&lt;br /&gt;
     if i &amp;lt; 10&lt;br /&gt;
         resfile = [resroot,'-000',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 100&lt;br /&gt;
         resfile = [resroot,'-00',num2str(i),fileex];&lt;br /&gt;
     elseif i &amp;lt; 1000&lt;br /&gt;
         resfile = [resroot,'-0',num2str(i),fileex];&lt;br /&gt;
     else&lt;br /&gt;
         resfile = [resroot,'-',num2str(i),fileex];&lt;br /&gt;
     end&lt;br /&gt;
     % read in deoth file for resfile i (2 specifies the 0.00 should be NaN&lt;br /&gt;
     [DEPTH, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (resfile);&lt;br /&gt;
     % plot data as figure 1&lt;br /&gt;
     plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype);&lt;br /&gt;
     % get movie frame&lt;br /&gt;
     M(i) = getframe(gcf); %#ok&amp;lt;AGROW&amp;gt;&lt;br /&gt;
     hold off;&lt;br /&gt;
 %     mov = addframe(mov,M(i));&lt;br /&gt;
     % close the figure&lt;br /&gt;
     close all&lt;br /&gt;
 end &lt;br /&gt;
 % % close .avi file&lt;br /&gt;
 % mov = close(mov);&lt;br /&gt;
 % generate empty .avi file&lt;br /&gt;
 disp('Generating .avi movie file');&lt;br /&gt;
 A = [resroot,fileex,'.avi'];&lt;br /&gt;
 movie2avi(M,A,'fps',framesPS,'quality',movQ);&lt;br /&gt;
 disp(A);&lt;br /&gt;
 %% Read LISFLOOD ascii files using filename&lt;br /&gt;
 function [OUT, ncols, nrows, xllcorner, yllcorner, cellsize] = read_file (filename)&lt;br /&gt;
 % read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 OUT = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 OUT = OUT';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
 % convert nodata to NaN;&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if OUT(ii,jj) == nodata&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         elseif OUT(ii,jj) == -99.000&lt;br /&gt;
             % lisflood uses -99.000 as nodat so will also remove these&lt;br /&gt;
             OUT(ii,jj) = NaN;&lt;br /&gt;
         else&lt;br /&gt;
             % do nothing&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 %% Plotter data for movie slide&lt;br /&gt;
 function plotter (DEPTH, DEM, nrows, ncols, cellsize, xllcorner, yllcorner,demCS,depthCS,snapint,i,vartype)&lt;br /&gt;
 % number of colors in colormap&lt;br /&gt;
 num_colors = 64;&lt;br /&gt;
 % DEM and variable color map&lt;br /&gt;
 cmap = [gray(num_colors); jet(num_colors)];&lt;br /&gt;
 % scale DEM and DEPTH data to fit with new colormap&lt;br /&gt;
 demCS2 = demCS(2)-demCS(1);&lt;br /&gt;
 dem_scalar = num_colors/demCS2;&lt;br /&gt;
 DEM2 = DEM*dem_scalar;&lt;br /&gt;
 depthCS2 = depthCS(2)-depthCS(1);&lt;br /&gt;
 depth_scalar = num_colors/depthCS2;&lt;br /&gt;
 DEPTH2 = (DEPTH*depth_scalar)+num_colors+1;&lt;br /&gt;
 %Plot the DEM&lt;br /&gt;
 figure1 = figure('PaperSize',[20.98 29.68],'Color',[1 1 1]);&lt;br /&gt;
 colormap(cmap);&lt;br /&gt;
 axes1 = axes('Parent',figure1,'YTickLabel',{yllcorner+(nrows*cellsize),yllcorner+cellsize},...&lt;br /&gt;
     'YTick', [1,nrows],...&lt;br /&gt;
     'YDir','reverse',...&lt;br /&gt;
     'XTickLabel',{xllcorner,xllcorner+(ncols*cellsize)-cellsize},...&lt;br /&gt;
     'XTick',[1,ncols],...&lt;br /&gt;
     'Layer','top');&lt;br /&gt;
 box('on');&lt;br /&gt;
 hold('all');&lt;br /&gt;
 image(DEM2,'Parent',axes1);&lt;br /&gt;
 axis('equal');axis('tight');&lt;br /&gt;
 % Overlay the water depth (or other variable)&lt;br /&gt;
 H = image(DEPTH2);&lt;br /&gt;
 % code to make depth plot layer transparent&lt;br /&gt;
 OP = ones(nrows,ncols);&lt;br /&gt;
 for ii = 1:nrows&lt;br /&gt;
     for jj = 1:ncols&lt;br /&gt;
         if DEPTH(ii,jj) &amp;gt; 0&lt;br /&gt;
         else&lt;br /&gt;
             OP(ii,jj) = 0;&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
 % make transparent. depth layer must be H&lt;br /&gt;
 set(H,'AlphaData',OP);&lt;br /&gt;
 % label colourbar&lt;br /&gt;
 color_breaks = 5;&lt;br /&gt;
 colorbreak = num_colors/color_breaks;&lt;br /&gt;
 SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 SCALE(1) = 0.0001;&lt;br /&gt;
 for j = 1:color_breaks*2&lt;br /&gt;
     SCALE(j+1) = colorbreak*j;&lt;br /&gt;
 end&lt;br /&gt;
 SCALE(color_breaks+1) = num_colors+1;&lt;br /&gt;
 VIS_SCALE = zeros(color_breaks*2,1);&lt;br /&gt;
 VIS_SCALE(1) = demCS(1);&lt;br /&gt;
 for j = 1:color_breaks-1&lt;br /&gt;
     VIS_SCALE(j+1) = ((demCS2/color_breaks)*j)+demCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 VIS_SCALE(color_breaks+1) = depthCS(1);&lt;br /&gt;
 for j = 1:color_breaks&lt;br /&gt;
     VIS_SCALE(j+1+color_breaks) = ((depthCS2/color_breaks)*j)+depthCS(1);&lt;br /&gt;
 end&lt;br /&gt;
 colorbar('YTick',SCALE,'YTickLabel',VIS_SCALE);&lt;br /&gt;
 % Label axis&lt;br /&gt;
 xlabel('BNG easting (m)');&lt;br /&gt;
 ylabel('BNG northing (m)');&lt;br /&gt;
 A = [vartype,' over DEM at time ',num2str((i*snapint)),'s'];&lt;br /&gt;
 title(A);&lt;/div&gt;</summary>
		<author><name>Jeff-neal</name></author>
	</entry>
	<entry>
		<id>https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5035</id>
		<title>LISFLOOD-FP and MATLAB</title>
		<link rel="alternate" type="text/html" href="https://source.geography.bristol.ac.uk/mediawiki/index.php?title=LISFLOOD-FP_and_MATLAB&amp;diff=5035"/>
		<updated>2008-03-18T15:13:45Z</updated>

		<summary type="html">&lt;p&gt;Jeff-neal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains various Matlab functions that may be useful for analysing results from the [http://www.ggy.bris.ac.uk/research/hydrology/models/lisflood LISFLOOD-FP] model.&lt;br /&gt;
&lt;br /&gt;
==File import and export==&lt;br /&gt;
&lt;br /&gt;
===Importing ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will import an ascii raster file using the string filename. To use it, copy and past text into a textfile called ascii_reader.m&lt;br /&gt;
&lt;br /&gt;
 function [dem, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % [DEM, ncols, nrows, xllcorner, yllcorner, cellsize] = ascii_reader (filename) &lt;br /&gt;
 &lt;br /&gt;
 % This function reads arc .asc files&lt;br /&gt;
 % requires filename string as input&lt;br /&gt;
 &lt;br /&gt;
 % j neal&lt;br /&gt;
 % 18/6/07&lt;br /&gt;
 %% read an ascii file&lt;br /&gt;
 fin = fopen(filename,'r');&lt;br /&gt;
 A = fscanf(fin,'%s',1); ncols = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nrows = fscanf(fin,'%f',1);           %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); xllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); yllcorner = fscanf(fin,'%f',1);       %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); cellsize = fscanf(fin,'%f',1);        %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 A = fscanf(fin,'%s',1); nodata = fscanf(fin,'%f',1);          %#ok&amp;lt;NASGU&amp;gt;&lt;br /&gt;
 dem = fscanf(fin,'%f',[ncols, nrows]);&lt;br /&gt;
 dem = dem';&lt;br /&gt;
 fclose('all');&lt;br /&gt;
&lt;br /&gt;
You can view the imported file using the command:&lt;br /&gt;
&lt;br /&gt;
 imagesc(dem);&lt;br /&gt;
&lt;br /&gt;
===Exporting ascii raster files===&lt;br /&gt;
&lt;br /&gt;
This function will create an ascii raster file called filename from the 2D matrix DEM.  To use it, copy and past text into a textfile called ascii_write.m&lt;br /&gt;
&lt;br /&gt;
 function ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 &lt;br /&gt;
 % ascii_write (filename, DEM, xllcorner, yllcorner, cellsize, nodata)&lt;br /&gt;
 % only filename (string) and DEM (2D matrix) are essential&lt;br /&gt;
 % this function writes ascii raster files for arc&lt;br /&gt;
 % j neal&lt;br /&gt;
 % 6/3/2008&lt;br /&gt;
 &lt;br /&gt;
 if nargin &amp;lt; 2, &lt;br /&gt;
     error('Requires at least two input arguments'); &lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 4, &lt;br /&gt;
     xllcorner = 0;&lt;br /&gt;
     yllcorner = 0;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 5,&lt;br /&gt;
     cellsize = 1;&lt;br /&gt;
 end&lt;br /&gt;
 if nargin &amp;lt; 6&lt;br /&gt;
     nodata = -9999;&lt;br /&gt;
 end&lt;br /&gt;
 A = size(DEM);&lt;br /&gt;
 fout = fopen (filename,'w');&lt;br /&gt;
 fprintf(fout, 'ncols         %.0f\n', A(2));  &lt;br /&gt;
 fprintf(fout, 'nrows         %.0f\n', A(1));&lt;br /&gt;
 fprintf(fout, 'xllcorner     %f\n', xllcorner);&lt;br /&gt;
 fprintf(fout, 'yllcorner     %f\n', yllcorner);&lt;br /&gt;
 fprintf(fout, 'cellsize      %f\n', cellsize);&lt;br /&gt;
 fprintf(fout, 'NODATA_value  %f\n', nodata); &lt;br /&gt;
 for ii = 1:A(1)&lt;br /&gt;
     B = DEM(ii,:);&lt;br /&gt;
     fprintf(fout, '%1.3f ', B);&lt;br /&gt;
     fprintf(fout, '\n');&lt;br /&gt;
 end&lt;br /&gt;
 fclose('all');&lt;/div&gt;</summary>
		<author><name>Jeff-neal</name></author>
	</entry>
</feed>