├── FluEgg_version.txt ├── _config.yml ├── logo.png ├── FluEgg.fig ├── browse.png ├── circle.png ├── modeleval.m ├── reorient.m ├── results.fig ├── asiancarp.png ├── batchgui.fig ├── calendar.png ├── downDist.fig ├── eggsfig2.png ├── riverfig.png ├── cellslabel.fig ├── google_earth.fig ├── pcscurvature.m ├── Minigui_Video.fig ├── snapshotPlotDt.fig ├── AboutBackground.png ├── Edit_River_Input_File.fig ├── Longitudinal_Dist_Eggs.fig ├── Egg_vertical_concentration.fig ├── PercentageEggs_location_time.fig ├── density.m ├── gitignore ├── NewFeatures.txt ├── sn2xy_License.txt ├── import_dss.m ├── HatchingTime.m ├── savefast.m ├── Dietrich.m ├── kml2struct.m ├── cellslabel.m ├── license_FluEgg_1.3.txt ├── savitzkyGolayFilt.m ├── subaxis.m ├── sn2xy.m ├── deg2utm.m ├── downDist.m ├── utm2deg.m ├── parseArgs.m ├── dlmcell.m ├── batchgui.m ├── Extract_RAS_TS.m ├── Longitudinal_Dist_Eggs.m ├── savitzkyGolay.m ├── PercentageEggs_location_time.m ├── General_2_use_outside_FluEgg_Extract_RAS.m ├── README.md ├── Extract_RAS.m ├── snapshotPlotDt.m ├── Egg_vertical_concentration.m ├── interparc.m ├── GEplot_3D.m └── Minigui_Video.m /FluEgg_version.txt: -------------------------------------------------------------------------------- 1 | v3.0.2 2 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/logo.png -------------------------------------------------------------------------------- /FluEgg.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/FluEgg.fig -------------------------------------------------------------------------------- /browse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/browse.png -------------------------------------------------------------------------------- /circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/circle.png -------------------------------------------------------------------------------- /modeleval.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/modeleval.m -------------------------------------------------------------------------------- /reorient.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/reorient.m -------------------------------------------------------------------------------- /results.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/results.fig -------------------------------------------------------------------------------- /asiancarp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/asiancarp.png -------------------------------------------------------------------------------- /batchgui.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/batchgui.fig -------------------------------------------------------------------------------- /calendar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/calendar.png -------------------------------------------------------------------------------- /downDist.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/downDist.fig -------------------------------------------------------------------------------- /eggsfig2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/eggsfig2.png -------------------------------------------------------------------------------- /riverfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/riverfig.png -------------------------------------------------------------------------------- /cellslabel.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/cellslabel.fig -------------------------------------------------------------------------------- /google_earth.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/google_earth.fig -------------------------------------------------------------------------------- /pcscurvature.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/pcscurvature.m -------------------------------------------------------------------------------- /Minigui_Video.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/Minigui_Video.fig -------------------------------------------------------------------------------- /snapshotPlotDt.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/snapshotPlotDt.fig -------------------------------------------------------------------------------- /AboutBackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/AboutBackground.png -------------------------------------------------------------------------------- /Edit_River_Input_File.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/Edit_River_Input_File.fig -------------------------------------------------------------------------------- /Longitudinal_Dist_Eggs.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/Longitudinal_Dist_Eggs.fig -------------------------------------------------------------------------------- /Egg_vertical_concentration.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/Egg_vertical_concentration.fig -------------------------------------------------------------------------------- /PercentageEggs_location_time.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgarciabotero/FluEgg/HEAD/PercentageEggs_location_time.fig -------------------------------------------------------------------------------- /density.m: -------------------------------------------------------------------------------- 1 | function [Rhow]=density(T) 2 | %Ecuation of state UNESCO(1987) 3 | %Temperature should be in C & Rho in Kg/m^3 4 | a_0=999.842594; 5 | a_1=6.793952e-2; 6 | a_2=-9.09529e-3; 7 | a_3=1.001685e-4; 8 | a_4=-1.120083e-6; 9 | a_5=6.536332e-9; 10 | Rhow=a_0+a_1*T+a_2*T.^2+a_3*T.^3+a_4*T.^4+a_5*T.^5; 11 | end 12 | 13 | -------------------------------------------------------------------------------- /gitignore: -------------------------------------------------------------------------------- 1 | # Folders # 2 | ################### 3 | Temp/ 4 | results/ 5 | not needed/ 6 | Executable/ 7 | Input_Files/ 8 | 9 | # FluEgg Specific # 10 | ################### 11 | *.doc 12 | *.docx 13 | 14 | # Matlab Specific # 15 | ################### 16 | *.asv 17 | 18 | # Compiled source # 19 | ################### 20 | *.com 21 | *.class 22 | *.dll 23 | *.exe 24 | *.o 25 | *.so 26 | *.prj 27 | 28 | # Packages # 29 | ############ 30 | # it's better to unpack these files and commit the raw source 31 | # git has its own built in compression methods 32 | *.7z 33 | *.dmg 34 | *.gz 35 | *.iso 36 | *.jar 37 | *.rar 38 | *.tar 39 | *.zip 40 | 41 | # Logs and databases # 42 | ###################### 43 | *.log 44 | *.sql 45 | *.sqlite 46 | 47 | -------------------------------------------------------------------------------- /NewFeatures.txt: -------------------------------------------------------------------------------- 1 | "New Features as of Dec 16, 2015" 2 | "-Added a tool in results to calculate the percentage of eggs at a particular location and a given time. This is useful for back-calculation of spawning grounds from egg samples (Jan 23, 2017)" 3 | -HEC-RAS-Fluegg interaction tool. HEC-RAS 5.0.3 4 | -Larvae transport untill Gas Bladder Inflation Stage 5 | -Rearranged post-processing tools by: 6 | *Longitudinal 7 | *Vertical 8 | *Temporal 9 | *Mixed 10 | -Added Google Earth funcionality 11 | -Longitudinal distribution: 12 | *Added stats summary to longitudinal distribution. 13 | *Added a tool for outputting results in different units. 14 | -------------------------------------------------------------------------------- /sn2xy_License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /import_dss.m: -------------------------------------------------------------------------------- 1 | %%%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 2 | %% Import CSV created with HEC-DSSVue % 3 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 4 | %-------------------------------------------------------------------------% 5 | % This function is used to extract data from a tab-separated file that % 6 | % with data from a HEC-DSS file 7 | % References: % 8 | % Goodell, C.R. 2014. % 9 | % Breaking the HEC-RAS Code: A User's Guide to Automating HEC-RAS. A User's 10 | % Guide to Automating HEC-RAS. h2ls. Portland, OR. % 11 | %-------------------------------------------------------------------------% 12 | % % 13 | %-------------------------------------------------------------------------% 14 | % Created by : Santiago Santacruz & Tatiana % 15 | % Date : January 20, 2016 % 16 | % Last Modified : Febrauary 20, 2016 % 17 | %-------------------------------------------------------------------------% 18 | % Inputs: 19 | % Outputs: 20 | % Copyright 2017 Santiago Santacruz & Tatiana Garcia 21 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | function [dss_data] = import_dss(filename) 23 | fid = fopen(filename); 24 | check_fid(fid) 25 | dss_data = {}; 26 | dss_data.parts = textscan(fid, '%s %s', 5); 27 | dss_data.units = textscan(fid, '%s %s', 1); 28 | dss_data.type = textscan(fid, '%s %s', 1); 29 | dss_data.data = textscan(fid, '%s %s %s %f'); 30 | fclose(fid); 31 | end 32 | 33 | function check_fid(fid) 34 | if fid == -1 35 | ed = warndlg('Your file could not be read','Observed Data'); 36 | set(ed, 'WindowStyle', 'modal'); 37 | uiwait(ed); 38 | end 39 | end -------------------------------------------------------------------------------- /HatchingTime.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | function [TimeToHatch] = HatchingTime(Temp,specie) 20 | AvgTemp=mean(Temp); 21 | if strcmp(specie,'Silver')%if specie=='Silver' 22 | %% If silver carp 23 | %This funtion includes a compilation of different research done about 24 | %hatching time R^2=0.96558 25 | TimeToHatch=1.2087e+7*(AvgTemp^-4.2664)+10.242;%Time to hatch in hours 26 | TimeToHatch=num2str((round(TimeToHatch*10))/10); TimeToHatch=single(str2double(TimeToHatch)); %1 decimals 27 | elseif strcmp(specie,'Bighead') 28 | %% If Bighead carp 29 | %This funtion includes a compilation of different research done about 30 | %hatching time R^2=0.93029 31 | TimeToHatch=35703*(AvgTemp^-2.223);%Time to hatch in hours 32 | TimeToHatch=num2str((round(TimeToHatch*10))/10); TimeToHatch=single(str2double(TimeToHatch)); 33 | else %case Grass Carp : TG March,2015 34 | %This funtion includes a compilation of different research done about 35 | %hatching time R^2=0.8871 36 | TimeToHatch=3.677e+07*AvgTemp.^-4.788+18.87;% Time to hatch in hours 37 | TimeToHatch=num2str((round(TimeToHatch*10))/10); TimeToHatch=single(str2double(TimeToHatch)); 38 | end 39 | 40 | 41 | -------------------------------------------------------------------------------- /savefast.m: -------------------------------------------------------------------------------- 1 | function savefast(filename, varargin) 2 | % savefast: fast saves of large arrays to .mat files 3 | % 4 | % Matlab's 'save' command can be very slow when saving large arrays, 5 | % because by default Matlab attempts to use compression. This function 6 | % provides a much faster alternative, at the cost of larger files. 7 | % 8 | % The syntax is identical to that of the Matlab save command. 9 | % 10 | % Example: 11 | % >> ops = struct('algorithm', 'greedy'); 12 | % >> A = int32(randi(20, 1000, 1200, 40)); 13 | % >> B = randn(500, 1800, 60); 14 | % >> tic; save /tmp/test ops A B; toc 15 | % Elapsed time is 22.980294 seconds. 16 | % >> tic; savefast /tmp/test ops A B; toc 17 | % Elapsed time is 0.571098 seconds. 18 | 19 | % Copyright 2013 by Timothy E. Holy 20 | 21 | % Extract the variable values 22 | vars = cell(size(varargin)); 23 | for i = 1:numel(vars) 24 | vars{i} = evalin('caller', varargin{i}); 25 | end 26 | 27 | % Separate numeric arrays from the rest 28 | isnum = cellfun(@(x) isa(x, 'numeric'), vars); 29 | 30 | % Append .mat if necessary 31 | [filepath, filebase, ext] = fileparts(filename); 32 | if isempty(ext) 33 | filename = fullfile(filepath, [filebase '.mat']); 34 | end 35 | 36 | create_dummy = false; 37 | if all(isnum) 38 | % Save a dummy variable, just to create the file 39 | dummy = 0; %#ok 40 | save(filename, '-v7.3', 'dummy'); 41 | create_dummy = true; 42 | else 43 | s = struct; 44 | for i = 1:numel(isnum) 45 | if ~isnum(i) 46 | s.(varargin{i}) = vars{i}; 47 | end 48 | end 49 | save(filename, '-v7.3', '-struct', 's'); 50 | end 51 | 52 | % Delete the dummy, if necessary, just in case the user supplied a 53 | % variable called dummy 54 | if create_dummy 55 | fid = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); 56 | H5L.delete(fid,'dummy','H5P_DEFAULT'); 57 | H5F.close(fid); 58 | end 59 | 60 | % Save all numeric variables 61 | for i = 1:numel(isnum) 62 | if ~isnum(i) 63 | continue 64 | end 65 | varname = ['/' varargin{i}]; 66 | h5create(filename, varname, size(vars{i}), 'DataType', class(vars{i})); 67 | h5write(filename, varname, vars{i}); 68 | end 69 | end 70 | 71 | -------------------------------------------------------------------------------- /Dietrich.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | %%%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 20 | %% Calculate settling velocity using Dietrich equation % 21 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | %-------------------------------------------------------------------------% 23 | % This function is used calculate settling velocity using Dietrich 24 | % equation % 25 | %-------------------------------------------------------------------------% 26 | % % 27 | %-------------------------------------------------------------------------% 28 | % Created by : Tatiana Garcia % 29 | % Last Modified : May 27, 2016 % 30 | %-------------------------------------------------------------------------% 31 | % Reference: Garcia, M. H. (2008). Sedimentation engineering: processes, 32 | % measurements, modeling and practice. ASCE Manuals and Reports 33 | % on Engineering Practice No. 110. Page 41 % 34 | % Inputs: 35 | % D = egg diameter in mm 36 | % T = temperature in Celsius degrees 37 | % SG =egg specific gravity (dimensionless)= density of egg/density 38 | % of water. 39 | % Outputs: 40 | % 41 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 42 | function [vs] = Dietrich(D,SG,T) 43 | D = D/10; % convert to cm from mm 44 | g = 981; %gravity cm/s^2 45 | viscosity = (1.79e-6*100^2)/(1+(0.03368*T)+(0.00021*(T^2)));%cm^2/s 46 | % constants 47 | b1 = 2.891394; 48 | b2 = 0.95296; 49 | b3 = 0.056835; 50 | b4 = 0.002892; 51 | b5 = 0.000245; 52 | Rep = (D*sqrt((SG-1)*g*D))/viscosity; %Reynolds particle number. 53 | Rf = exp(-b1+(b2*(log(Rep)))-(b3*((log(Rep))^2))... 54 | -(b4*((log(Rep))^3))+(b5*((log(Rep))^4))); 55 | vs = Rf*sqrt((SG-1)*g*D); %Settling velocity in cm/s 56 | 57 | 58 | -------------------------------------------------------------------------------- /kml2struct.m: -------------------------------------------------------------------------------- 1 | function kmlStruct = kml2struct(kmlFile) 2 | % kmlStruct = kml2struct(kmlFile) 3 | % 4 | % Import a .kml file as a vector array of shapefile structs, with Geometry, Name, 5 | % Description, Lon, Lat, and BoundaryBox fields. Structs may contain a mix 6 | % of points, lines, and polygons. 7 | % 8 | % .kml files with folder structure will not be presented as such, but will 9 | % appear as a single vector array of structs. 10 | % 11 | % 12 | 13 | [FID msg] = fopen(kmlFile,'rt'); 14 | 15 | if FID<0 16 | error(msg) 17 | end 18 | 19 | txt = fread(FID,'uint8=>char')'; 20 | fclose(FID); 21 | 22 | expr = '.+?'; 23 | 24 | objectStrings = regexp(txt,expr,'match'); 25 | 26 | Nos = length(objectStrings); 27 | 28 | for ii = 1:Nos 29 | % Find Object Name Field 30 | bucket = regexp(objectStrings{ii},'.+?','match'); 31 | if isempty(bucket) 32 | name = 'undefined'; 33 | else 34 | % Clip off flags 35 | name = regexprep(bucket{1},'\s*',''); 36 | name = regexprep(name,'\s*',''); 37 | end 38 | 39 | % Find Object Description Field 40 | bucket = regexp(objectStrings{ii},'.+?','match'); 41 | if isempty(bucket) 42 | desc = ''; 43 | else 44 | % Clip off flags 45 | desc = regexprep(bucket{1},'\s*',''); 46 | desc = regexprep(desc,'\s*',''); 47 | end 48 | 49 | geom = 0; 50 | % Identify Object Type 51 | if ~isempty(regexp(objectStrings{ii},'.+?','match'); 72 | % Clip off flags 73 | coordStr = regexprep(bucket{1},'(\s+)*',''); 74 | coordStr = regexprep(coordStr,'(\s+)*',''); 75 | % Split coordinate string by commas or white spaces, and convert string 76 | % to doubles 77 | coordMat = str2double(regexp(coordStr,'[,\s]+','split')); 78 | % Rearrange coordinates to form an x-by-3 matrix 79 | [m,n] = size(coordMat); 80 | coordMat = reshape(coordMat,3,m*n/3)'; 81 | 82 | % define polygon in clockwise direction, and terminate 83 | [Lat, Lon] = poly2ccw(coordMat(:,2),coordMat(:,1)); 84 | if geom==3 85 | Lon = [Lon;NaN]; 86 | Lat = [Lat;NaN]; 87 | end 88 | 89 | % Create structure 90 | kmlStruct(ii).Geometry = geometry; 91 | kmlStruct(ii).Name = name; 92 | kmlStruct(ii).Description = desc; 93 | kmlStruct(ii).Lon = Lon; 94 | kmlStruct(ii).Lat = Lat; 95 | kmlStruct(ii).BoundingBox = [[min(Lon) min(Lat);max(Lon) max(Lat)]]; 96 | end -------------------------------------------------------------------------------- /cellslabel.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | %%%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 20 | %% Add labels to figures % 21 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | %-------------------------------------------------------------------------% 23 | % This function is used to add label of cells to figures % 24 | %-------------------------------------------------------------------------% 25 | % % 26 | %-------------------------------------------------------------------------% 27 | % Created by : Tatiana Garcia % 28 | % Last Modified : May 17, 2016 % 29 | %-------------------------------------------------------------------------% 30 | % Inputs: 31 | % Outputs: 32 | % 33 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 34 | 35 | function varargout = cellslabel(varargin) 36 | % Last Modified by GUIDE v2.5 27-Aug-2013 12:04:08 37 | 38 | % Begin initialization code - DO NOT EDIT 39 | gui_Singleton = 1; 40 | gui_State = struct('gui_Name', mfilename, ... 41 | 'gui_Singleton', gui_Singleton, ... 42 | 'gui_OpeningFcn', @cellslabel_OpeningFcn, ... 43 | 'gui_OutputFcn', @cellslabel_OutputFcn, ... 44 | 'gui_LayoutFcn', [] , ... 45 | 'gui_Callback', []); 46 | if nargin && ischar(varargin{1}) 47 | gui_State.gui_Callback = str2func(varargin{1}); 48 | end 49 | 50 | if nargout 51 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 52 | else 53 | gui_mainfcn(gui_State, varargin{:}); 54 | end 55 | % End initialization code - DO NOT EDIT 56 | 57 | % --- Executes just before cellslabel is made visible. 58 | function cellslabel_OpeningFcn(hObject, eventdata, handles, varargin) 59 | handles.output = hObject; 60 | guidata(hObject, handles); 61 | 62 | % --- Outputs from this function are returned to the command line. 63 | function varargout = cellslabel_OutputFcn(hObject, eventdata, handles) 64 | varargout{1} = handles.output; 65 | 66 | % If user press button_Yes. 67 | function button_Yes_Callback(hObject, eventdata, handles) 68 | label_on=1; 69 | handleResults=getappdata(0,'handleResults'); 70 | setappdata(handleResults, 'label_on', label_on); 71 | close; 72 | 73 | % If user press button_Yes._No. 74 | function button_No_Callback(hObject, eventdata, handles) 75 | label_on=0; 76 | handleResults=getappdata(0,'handleResults'); 77 | setappdata(handleResults, 'label_on', label_on); 78 | close; 79 | -------------------------------------------------------------------------------- /license_FluEgg_1.3.txt: -------------------------------------------------------------------------------- 1 | ============================================================================== 2 | FluEgg Release License 3 | ============================================================================== 4 | University of Illinois/NCSA Open Source License 5 | 6 | Copyright (c) 2011-2014 University of Illinois at Urbana-Champaign 7 | All rights reserved. 8 | 9 | Developed by: Tatiana Garcia 10 | Ven Te Chow Hydrosystems Laboratory, Department of Civil and Environmental Engineering at University of Illinois at Urbana-Champaign 11 | http://vtchl.illinois.edu 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the 14 | Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 15 | Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 16 | 17 | -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. 18 | -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other 19 | materials provided with the distribution. 20 | -Neither the names of Tatiana Garcia, Ven Te Chow Hydrosystems Laboratory, Department of Civil and Environmental Engineering at University of Illinois at 21 | Urbana-Champaign, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written 22 | permission. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 25 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. 27 | 28 | ============================================================================== 29 | Copyrights and Licenses for Third Party Software Distributed with FluEgg: 30 | ============================================================================== 31 | The FluEgg software contains code written by third parties. Such software will 32 | have its own individual LICENSE.TXT file in the directory in which it appears. 33 | This file will describe the copyrights, license, and restrictions which apply 34 | to that code. 35 | 36 | The disclaimer of warranty in the University of Illinois/NCSA Open Source License 37 | applies to all code in the FluEgg Distribution, and nothing in any of the 38 | other licenses gives permission to use the names of Tatiana Garcia, Ven Te Chow Hydrosystems Laboratory, Department of Civil and Environmental Engineering at 39 | University of Illinois at Urbana-Champaign or the University of Illinois to endorse or promote products derived from this 40 | Software. 41 | 42 | The following pieces of software have additional or alternate copyrights, 43 | licenses, and/or restrictions: 44 | 45 | Program/Function Developer Directory 46 | ---------------- --------- --------- 47 | voxel.m Suresh Joel FluEgg_Git_Repo\voxel.m 48 | cells.m Suresh Joel FluEgg_Git_Repo\voxel.m 49 | dlmcell Roland Pfister FluEgg_Git_Repo\dlmcell.m 50 | parseArgs.m Aslak Grinsted FluEgg_Git_Repo\parseArgs.m 51 | subaxis.m Aslak Grinsted FluEgg_Git_Repo\subaxis.m -------------------------------------------------------------------------------- /savitzkyGolayFilt.m: -------------------------------------------------------------------------------- 1 | function y=savitzkyGolayFilt(x,N,DN,F,W,DIM) 2 | %savitzkyGolayFilt Savitzky-Golay Filtering. 3 | % savitzkyGolayFilt(X,N,DN,F) filters the signal X using a Savitzky-Golay 4 | % (polynomial) filter. The polynomial order, N, must be less than the 5 | % frame size, F, and F must be odd. DN specifies the differentiation 6 | % order (DN=0 is smoothing). For a DN higher than zero, you'll have to 7 | % scale the output by 1/T^DN to acquire the DNth smoothed derivative of 8 | % input X, where T is the sampling interval. The length of the input X 9 | % must be >= F. If X is a matrix, the filtering is done on the columns 10 | % of X. 11 | % 12 | % Note that if the polynomial order N equals F-1, no smoothing 13 | % will occur. 14 | % 15 | % savitzkyGolayFilt(X,N,DN,F,W) specifies a weighting vector W with 16 | % length F containing real, positive valued weights employed during the 17 | % least-squares minimization. If not specified, or if specified as 18 | % empty, W defaults to an identity matrix. 19 | % 20 | % savitzkyGolayFilt(X,N,DN,F,[],DIM) or savitzkyGolayFilt(X,N,DN,F,W,DIM) 21 | % operates along the dimension DIM. 22 | % 23 | % See also savitzkyGolay, FILTER, sgolayfilt 24 | 25 | % References: 26 | % [1] Sophocles J. Orfanidis, INTRODUCTION TO SIGNAL PROCESSING, 27 | % Prentice-Hall, 1995, Chapter 8. 28 | 29 | % Author(s): R. Losada 30 | % Copyright 1988-2004 The MathWorks, Inc. 31 | % $Revision: 1.11.4.4 $ $Date: 2009/08/11 15:47:54 $ 32 | 33 | error(nargchk(4,6,nargin,'struct')); 34 | 35 | % Check if the input arguments are valid 36 | if round(F) ~= F, error(generatemsgid('MustBeInteger'),'Frame length must be an integer.'), end 37 | if rem(F,2) ~= 1, error(generatemsgid('SignalErr'),'Frame length must be odd.'), end 38 | if round(N) ~= N, error(generatemsgid('MustBeInteger'),'Polynomial order must be an integer.'), end 39 | if N > F-1, error(generatemsgid('InvalidRange'),'The Polynomial order must be less than the frame length.'), end 40 | if DN > N, error(generatemsgid('InvalidRange'),'The Differentiation order must be less than or equal to the Polynomial order.'), end 41 | 42 | if nargin < 5 || isempty(W) 43 | % No weighting matrix, make W an identity 44 | W = ones(F,1); 45 | else 46 | % Check for right length of W 47 | if length(W) ~= F, error(generatemsgid('InvalidDimensions'),'The weight vector must be of the same length as the frame length.'),end 48 | % Check to see if all elements are positive 49 | if min(W) <= 0, error(generatemsgid('InvalidRange'),'All the elements of the weight vector must be greater than zero.'), end 50 | end 51 | 52 | if nargin < 6, DIM = []; end 53 | 54 | % Compute the projection matrix B 55 | pp = fix(-F./2):fix(F./2); 56 | B = savitzkyGolay(pp,N,DN,pp,W); 57 | 58 | if ~isempty(DIM) && DIM > ndims(x) 59 | error(generatemsgid('InvalidDimensions'),'Dimension specified exceeds the dimensions of X.') 60 | end 61 | 62 | % Reshape X into the right dimension. 63 | if isempty(DIM) 64 | % Work along the first non-singleton dimension 65 | [x, nshifts] = shiftdim(x); 66 | else 67 | % Put DIM in the first dimension (this matches the order 68 | % that the built-in filter function uses) 69 | perm = [DIM,1:DIM-1,DIM+1:ndims(x)]; 70 | x = permute(x,perm); 71 | end 72 | 73 | if size(x,1) < F, error(generatemsgid('InvalidDimensions'),'The length of the input must be >= frame length.'), end 74 | 75 | % Preallocate output 76 | y = zeros(size(x)); 77 | 78 | % Compute the transient on (note, this is different than in sgolayfilt, 79 | % they had an optimization leaving out some transposes that is only valid 80 | % for DN==0) 81 | y(1:(F+1)/2-1,:) = fliplr(B(:,(F-1)/2+2:end)).'*flipud(x(1:F,:)); 82 | 83 | % Compute the steady state output 84 | ytemp = filter(B(:,(F-1)./2+1),1,x); 85 | y((F+1)/2:end-(F+1)/2+1,:) = ytemp(F:end,:); 86 | 87 | % Compute the transient off 88 | y(end-(F+1)/2+2:end,:) = fliplr(B(:,1:(F-1)/2)).'*flipud(x(end-(F-1):end,:)); 89 | 90 | % Convert Y to the original shape of X 91 | if isempty(DIM) 92 | y = shiftdim(y, -nshifts); 93 | else 94 | y = ipermute(y,perm); 95 | end -------------------------------------------------------------------------------- /subaxis.m: -------------------------------------------------------------------------------- 1 | function h=subaxis(varargin) 2 | %SUBAXIS Create axes in tiled positions. (just like subplot) 3 | % Usage: 4 | % h=subaxis(rows,cols,cellno[,settings]) 5 | % h=subaxis(rows,cols,cellx,celly[,settings]) 6 | % h=subaxis(rows,cols,cellx,celly,spanx,spany[,settings]) 7 | % 8 | % SETTINGS: Spacing,SpacingHoriz,SpacingVert 9 | % Padding,PaddingRight,PaddingLeft,PaddingTop,PaddingBottom 10 | % Margin,MarginRight,MarginLeft,MarginTop,MarginBottom 11 | % Holdaxis 12 | % 13 | % all units are relative (e.g from 0 to 1) 14 | % 15 | % Abbreviations of parameters can be used.. (Eg MR instead of MarginRight) 16 | % (holdaxis means that it wont delete any axes below.) 17 | % 18 | % 19 | % Example: 20 | % 21 | % >> subaxis(2,1,1,'SpacingVert',0,'MR',0); 22 | % >> imagesc(magic(3)) 23 | % >> subaxis(2,'p',.02); 24 | % >> imagesc(magic(4)) 25 | % 26 | % 2001 / Aslak Grinsted (Feel free to modify this code.) 27 | f=gcf; 28 | 29 | 30 | Args=[]; 31 | UserDataArgsOK=0; 32 | Args=get(f,'UserData'); 33 | if isstruct(Args) 34 | UserDataArgsOK=isfield(Args,'SpacingHorizontal')&isfield(Args,'Holdaxis')&isfield(Args,'rows')&isfield(Args,'cols'); 35 | end 36 | OKToStoreArgs=isempty(Args)|UserDataArgsOK; 37 | 38 | if isempty(Args)&(~UserDataArgsOK) 39 | Args=struct('Holdaxis',0, ... 40 | 'SpacingVertical',0.05,'SpacingHorizontal',0.05, ... 41 | 'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ... 42 | 'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ... 43 | 'rows',[],'cols',[]); 44 | end 45 | Args=parseArgs(varargin,Args,{'Holdaxis'},{'Spacing' {'sh','sv'}; 'Padding' {'pl','pr','pt','pb'}; 'Margin' {'ml','mr','mt','mb'}}); 46 | 47 | if (length(Args.NumericArguments)>1) 48 | Args.rows=Args.NumericArguments{1}; 49 | Args.cols=Args.NumericArguments{2}; 50 | %remove these 2 numerical arguments 51 | Args.NumericArguments={Args.NumericArguments{3:end}}; 52 | end 53 | 54 | if OKToStoreArgs 55 | set(f,'UserData',Args); 56 | end 57 | 58 | 59 | 60 | 61 | switch length(Args.NumericArguments) 62 | case 0 63 | return % no arguments but rows/cols.... 64 | case 1 65 | %%modf TGB 66 | if numel(Args.NumericArguments{1}) == 2 % restore subplot(m,n,[x y]) behaviour 67 | [x1 y1] = ind2sub([Args.cols Args.rows],Args.NumericArguments{1}(1)); % subplot and ind2sub count differently (column instead of row first) --> switch cols/rows 68 | [x2 y2] = ind2sub([Args.cols Args.rows],Args.NumericArguments{1}(end)); 69 | else 70 | x1=mod((Args.NumericArguments{1}-1),Args.cols)+1; x2=x1; 71 | y1=floor((Args.NumericArguments{1}-1)/Args.cols)+1; y2=y1; 72 | end 73 | % x1=mod((Args.NumericArguments{1}-1),Args.cols)+1; x2=x1; 74 | % y1=floor((Args.NumericArguments{1}-1)/Args.cols)+1; y2=y1; 75 | case 2 76 | x1=Args.NumericArguments{1};x2=x1; 77 | y1=Args.NumericArguments{2};y2=y1; 78 | case 4 79 | x1=Args.NumericArguments{1};x2=x1+Args.NumericArguments{3}-1; 80 | y1=Args.NumericArguments{2};y2=y1+Args.NumericArguments{4}-1; 81 | otherwise 82 | error('subaxis argument error') 83 | end 84 | 85 | 86 | cellwidth=((1-Args.MarginLeft-Args.MarginRight)-(Args.cols-1)*Args.SpacingHorizontal)/Args.cols; 87 | cellheight=((1-Args.MarginTop-Args.MarginBottom)-(Args.rows-1)*Args.SpacingVertical)/Args.rows; 88 | xpos1=Args.MarginLeft+Args.PaddingLeft+cellwidth*(x1-1)+Args.SpacingHorizontal*(x1-1); 89 | xpos2=Args.MarginLeft-Args.PaddingRight+cellwidth*x2+Args.SpacingHorizontal*(x2-1); 90 | ypos1=Args.MarginTop+Args.PaddingTop+cellheight*(y1-1)+Args.SpacingVertical*(y1-1); 91 | ypos2=Args.MarginTop-Args.PaddingBottom+cellheight*y2+Args.SpacingVertical*(y2-1); 92 | 93 | if Args.Holdaxis 94 | h=axes('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]); 95 | else 96 | h=subplot('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]); 97 | end 98 | 99 | 100 | set(h,'box','on'); 101 | %h=axes('position',[x1 1-y2 x2-x1 y2-y1]); 102 | set(h,'units',get(gcf,'defaultaxesunits')); 103 | set(h,'tag','subaxis'); 104 | 105 | 106 | 107 | if (nargout==0) clear h; end; 108 | 109 | -------------------------------------------------------------------------------- /sn2xy.m: -------------------------------------------------------------------------------- 1 | function [ x, y ] = sn2xy( s, n, centerlinex, centerliney, varargin ) 2 | %sn2xy: Transform curvilinear orthogonal to cartesian coordinates 3 | %usage: [x,y] = sn2xy(s,n,centerlineX,centerlineY) 4 | %usage: [x,y] = sn2xy(s,n,centerlineX,centerlineY,discretisation) 5 | % 6 | %arguments: 7 | % s - a jx1 real numeric vector containing the s-coordinates of the 8 | % points to be transformed, as fractional distances along the 9 | % centerline. s has to be between 0 and 1 10 | % n - a jx1 real numeric vector containing the n-coordinates of the 11 | % points to be transformed, as normal distances from the 12 | % centerline 13 | % cx, cy - kx1 real numeric vectors containing the x and y coordinates of 14 | % the points describing the centerline 15 | % discretisation - integer specifying how many samples to use for 16 | % discretising the spline interpolation of the centerline. 17 | % Defaults to 10. 18 | % A value of 0 specifies the use of the full spline (very slow). 19 | % 20 | %Requires the distance2curve function by John D'Errico 21 | % http://www.mathworks.de/matlabcentral/fileexchange/34869-distance2curve 22 | % 23 | %Based on Merwade et al (2005) "Geospatial Representation of River Channels" 24 | % Journal of Hydrological Engineering, 10, 243-251 25 | % 26 | % 27 | %Usage example: 28 | % % Generate test data 29 | % dataX = sin( (0:0.01:1)' *2*pi) + (rand(101,1) - 0.5) * 0.4; 30 | % dataY = (0:0.02:2)' - 0.4*sin((0:0.01:1)' *4*pi) + ... 31 | % (rand(101,1)-0.5) * 0.4; 32 | % 33 | % hold off 34 | % scatter(dataX, dataY); 35 | % 36 | % % Provide centerline path 37 | % centerlineX = sin( (0:0.05:1)' *2*pi); 38 | % centerlineX = [-0.2; centerlineX; 0.2]; 39 | % 40 | % centerlineY = (0:0.1:2)' - 0.4 * sin( (0:0.05:1)'*4*pi); 41 | % centerlineY = [0.1; centerlineY; 1.9]; 42 | % 43 | % hold all 44 | % plot(centerlineX, centerlineY); 45 | % hold off 46 | % 47 | % % Transform to flow-oriented S-N coordinate system 48 | % [S, N, L] = xy2sn(dataX, dataY, centerlineX, centerlineY); 49 | % 50 | % % Plot points in S-N coordinate system 51 | % scatter(S*L, N, [], S, 'f') 52 | % axis equal 53 | % 54 | % % Plot points in X-Y coordinate system, using S for colour 55 | % scatter(dataX, dataY, [], S, 'f') 56 | % axis equal 57 | % 58 | % 59 | % %% Generate a grid in the S-N coordinate system and transform it to X-Y 60 | % gridlinesS=repmat( (0:0.02:1), 5, 1); 61 | % gridlinesN=repmat( (-0.2:0.1:0.2)',1,51); 62 | % plot(gridlinesS*L,gridlinesN, 'k') 63 | % axis equal 64 | % hold all 65 | % plot(gridlinesS'*L,gridlinesN', 'k') 66 | % hold off 67 | % 68 | % [gridlinesX, gridlinesY] = sn2xy(gridlinesS, gridlinesN, ... 69 | % centerlineX, centerlineY); 70 | % 71 | % % Reshape resulting vector back to matrix structure 72 | % gridlinesX = reshape(gridlinesX, size(gridlinesS)); 73 | % gridlinesY = reshape(gridlinesY, size(gridlinesS)); 74 | % 75 | % % Plot data and grid in XY and SN coordinates 76 | % subplot(3,2,[1 3]) 77 | % plot(gridlinesX,gridlinesY, 'k') 78 | % axis equal 79 | % hold all 80 | % plot(gridlinesX',gridlinesY', 'k') 81 | % colormap('winter') 82 | % scatter(dataX, dataY, [], S, 'f') 83 | % hold off 84 | % subplot(3,2,[5:6]) 85 | % plot(gridlinesS*L,gridlinesN, 'k') 86 | % hold all; axis equal; plot(gridlinesS'*L,gridlinesN', 'k') 87 | % scatter(S*L, N, [], S, 'f') 88 | 89 | if nargin == 4 90 | splinesampling = 10; 91 | elseif nargin == 5 92 | splinesampling = varargin{1}; 93 | end 94 | 95 | if splinesampling > 0 96 | % Use a linear approximation of the spline interpolation 97 | nCenterline = length(centerlinex); 98 | t = 1:nCenterline; 99 | ts = 1:1/splinesampling:nCenterline; 100 | cx = spline(t,centerlinex,ts)'; 101 | cy = spline(t,centerliney,ts)'; 102 | 103 | [Pnew, Ttnew] = interparc(s, cx, cy, 'linear'); 104 | else 105 | % Use the full spline interpolation 106 | [Pnew, Ttnew] = interparc(s, centerlinex, centerliney, 'sp');% interparc: interpolate points along a curve in 2 or more dimensions 107 | end 108 | 109 | %% 110 | % Calculate normal vectors on thalweg curve 111 | Tnnew = [-Ttnew(:,2), Ttnew(:,1)]; 112 | Tnnew = bsxfun(@rdivide, Tnnew, sqrt(sum(Tnnew.^2,2))); 113 | 114 | x = Pnew(:,1) + Tnnew(:,1).*n(:); 115 | y = Pnew(:,2) + Tnnew(:,2).*n(:); 116 | 117 | end 118 | 119 | -------------------------------------------------------------------------------- /deg2utm.m: -------------------------------------------------------------------------------- 1 | function [x,y,utmzone] = deg2utm(Lat,Lon) 2 | % ------------------------------------------------------------------------- 3 | % [x,y,utmzone] = deg2utm(Lat,Lon) 4 | % 5 | % Description: Function to convert lat/lon vectors into UTM coordinates (WGS84). 6 | % Some code has been extracted from UTM.m function by Gabriel Ruiz Martinez. 7 | % 8 | % Inputs: 9 | % Lat: Latitude vector. Degrees. +ddd.ddddd WGS84 10 | % Lon: Longitude vector. Degrees. +ddd.ddddd WGS84 11 | % 12 | % Outputs: 13 | % x, y , utmzone. See example 14 | % 15 | % Example 1: 16 | % Lat=[40.3154333; 46.283900; 37.577833; 28.645650; 38.855550; 25.061783]; 17 | % Lon=[-3.4857166; 7.8012333; -119.95525; -17.759533; -94.7990166; 121.640266]; 18 | % [x,y,utmzone] = deg2utm(Lat,Lon); 19 | % fprintf('%7.0f ',x) 20 | % 458731 407653 239027 230253 343898 362850 21 | % fprintf('%7.0f ',y) 22 | % 4462881 5126290 4163083 3171843 4302285 2772478 23 | % utmzone = 24 | % 30 T 25 | % 32 T 26 | % 11 S 27 | % 28 R 28 | % 15 S 29 | % 51 R 30 | % 31 | % Example 2: If you have Lat/Lon coordinates in Degrees, Minutes and Seconds 32 | % LatDMS=[40 18 55.56; 46 17 2.04]; 33 | % LonDMS=[-3 29 8.58; 7 48 4.44]; 34 | % Lat=dms2deg(mat2dms(LatDMS)); %convert into degrees 35 | % Lon=dms2deg(mat2dms(LonDMS)); %convert into degrees 36 | % [x,y,utmzone] = deg2utm(Lat,Lon) 37 | % 38 | % Author: 39 | % Rafael Palacios 40 | % Universidad Pontificia Comillas 41 | % Madrid, Spain 42 | % Version: Apr/06, Jun/06, Aug/06, Aug/06 43 | % Aug/06: fixed a problem (found by Rodolphe Dewarrat) related to southern 44 | % hemisphere coordinates. 45 | % Aug/06: corrected m-Lint warnings 46 | %------------------------------------------------------------------------- 47 | 48 | % Argument checking 49 | % 50 | error(nargchk(2, 2, nargin)); %2 arguments required 51 | n1=length(Lat); 52 | n2=length(Lon); 53 | if (n1~=n2) 54 | error('Lat and Lon vectors should have the same length'); 55 | end 56 | 57 | 58 | % Memory pre-allocation 59 | % 60 | x=zeros(n1,1); 61 | y=zeros(n1,1); 62 | utmzone(n1,:)='60 X'; 63 | 64 | % Main Loop 65 | % 66 | for i=1:n1 67 | la=Lat(i); 68 | lo=Lon(i); 69 | 70 | sa = 6378137.000000 ; sb = 6356752.314245; 71 | 72 | %e = ( ( ( sa ^ 2 ) - ( sb ^ 2 ) ) ^ 0.5 ) / sa; 73 | e2 = ( ( ( sa ^ 2 ) - ( sb ^ 2 ) ) ^ 0.5 ) / sb; 74 | e2cuadrada = e2 ^ 2; 75 | c = ( sa ^ 2 ) / sb; 76 | %alpha = ( sa - sb ) / sa; %f 77 | %ablandamiento = 1 / alpha; % 1/f 78 | 79 | lat = la * ( pi / 180 ); 80 | lon = lo * ( pi / 180 ); 81 | 82 | Huso = fix( ( lo / 6 ) + 31); 83 | S = ( ( Huso * 6 ) - 183 ); 84 | deltaS = lon - ( S * ( pi / 180 ) ); 85 | 86 | if (la<-72), Letra='C'; 87 | elseif (la<-64), Letra='D'; 88 | elseif (la<-56), Letra='E'; 89 | elseif (la<-48), Letra='F'; 90 | elseif (la<-40), Letra='G'; 91 | elseif (la<-32), Letra='H'; 92 | elseif (la<-24), Letra='J'; 93 | elseif (la<-16), Letra='K'; 94 | elseif (la<-8), Letra='L'; 95 | elseif (la<0), Letra='M'; 96 | elseif (la<8), Letra='N'; 97 | elseif (la<16), Letra='P'; 98 | elseif (la<24), Letra='Q'; 99 | elseif (la<32), Letra='R'; 100 | elseif (la<40), Letra='S'; 101 | elseif (la<48), Letra='T'; 102 | elseif (la<56), Letra='U'; 103 | elseif (la<64), Letra='V'; 104 | elseif (la<72), Letra='W'; 105 | else Letra='X'; 106 | end 107 | 108 | a = cos(lat) * sin(deltaS); 109 | epsilon = 0.5 * log( ( 1 + a) / ( 1 - a ) ); 110 | nu = atan( tan(lat) / cos(deltaS) ) - lat; 111 | v = ( c / ( ( 1 + ( e2cuadrada * ( cos(lat) ) ^ 2 ) ) ) ^ 0.5 ) * 0.9996; 112 | ta = ( e2cuadrada / 2 ) * epsilon ^ 2 * ( cos(lat) ) ^ 2; 113 | a1 = sin( 2 * lat ); 114 | a2 = a1 * ( cos(lat) ) ^ 2; 115 | j2 = lat + ( a1 / 2 ); 116 | j4 = ( ( 3 * j2 ) + a2 ) / 4; 117 | j6 = ( ( 5 * j4 ) + ( a2 * ( cos(lat) ) ^ 2) ) / 3; 118 | alfa = ( 3 / 4 ) * e2cuadrada; 119 | beta = ( 5 / 3 ) * alfa ^ 2; 120 | gama = ( 35 / 27 ) * alfa ^ 3; 121 | Bm = 0.9996 * c * ( lat - alfa * j2 + beta * j4 - gama * j6 ); 122 | xx = epsilon * v * ( 1 + ( ta / 3 ) ) + 500000; 123 | yy = nu * v * ( 1 + ta ) + Bm; 124 | 125 | if (yy<0) 126 | yy=9999999+yy; 127 | end 128 | 129 | x(i)=xx; 130 | y(i)=yy; 131 | if ~isnan(Lat(i)) 132 | utmzone(i,:)=sprintf('%02d %c',Huso,Letra); 133 | else 134 | utmzone(i,:)=''; 135 | end 136 | end 137 | 138 | -------------------------------------------------------------------------------- /downDist.m: -------------------------------------------------------------------------------- 1 | function varargout = downDist(varargin) 2 | % DOWNDIST MATLAB code for downDist.fig 3 | % DOWNDIST, by itself, creates a new DOWNDIST or raises the existing 4 | % singleton*. 5 | % 6 | % H = DOWNDIST returns the handle to a new DOWNDIST or the handle to 7 | % the existing singleton*. 8 | % 9 | % DOWNDIST('CALLBACK',hObject,eventData,handles,...) calls the local 10 | % function named CALLBACK in DOWNDIST.M with the given input arguments. 11 | % 12 | % DOWNDIST('Property','Value',...) creates a new DOWNDIST or raises the 13 | % existing singleton*. Starting from the left, property value pairs are 14 | % applied to the GUI before downDist_OpeningFcn gets called. An 15 | % unrecognized property name or invalid value makes property application 16 | % stop. All inputs are passed to downDist_OpeningFcn via varargin. 17 | % 18 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 19 | % instance to run (singleton)". 20 | % 21 | % See also: GUIDE, GUIDATA, GUIHANDLES 22 | 23 | % Edit the above text to modify the response to help downDist 24 | 25 | % Last Modified by GUIDE v2.5 06-Mar-2014 15:35:18 26 | 27 | % Begin initialization code - DO NOT EDIT 28 | gui_Singleton = 1; 29 | gui_State = struct('gui_Name', mfilename, ... 30 | 'gui_Singleton', gui_Singleton, ... 31 | 'gui_OpeningFcn', @downDist_OpeningFcn, ... 32 | 'gui_OutputFcn', @downDist_OutputFcn, ... 33 | 'gui_LayoutFcn', [] , ... 34 | 'gui_Callback', []); 35 | if nargin && ischar(varargin{1}) 36 | gui_State.gui_Callback = str2func(varargin{1}); 37 | end 38 | 39 | if nargout 40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 41 | else 42 | gui_mainfcn(gui_State, varargin{:}); 43 | end 44 | % End initialization code - DO NOT EDIT 45 | 46 | 47 | % --- Executes just before downDist is made visible. 48 | function downDist_OpeningFcn(hObject, ~, handles, varargin) 49 | handles.output = hObject; 50 | guidata(hObject, handles); 51 | 52 | % UIWAIT makes downDist wait for user response (see UIRESUME) 53 | % uiwait(handles.figure1); 54 | 55 | 56 | % --- Outputs from this function are returned to the command line. 57 | function varargout = downDist_OutputFcn(~, ~, handles) 58 | varargout{1} = handles.output; 59 | 60 | 61 | 62 | function dX_Callback(~, ~, ~) 63 | 64 | % --- Executes during object creation, after setting all properties. 65 | function dX_CreateFcn(hObject, eventdata, handles) 66 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 67 | set(hObject,'BackgroundColor','white'); 68 | end 69 | 70 | 71 | % --- Executes on button press in Continuebutton. 72 | function Continuebutton_Callback(hObject, eventdata, handles) 73 | dX=str2double(get(handles.dX,'String'))*1000;% It is in km and then we convert it to m 74 | handleResults=getappdata(0,'handleResults'); 75 | ResultsSim=getappdata(handleResults,'ResultsSim'); 76 | CumlDistance=ResultsSim.CumlDistance; 77 | 78 | %% Error checking========================================================== 79 | if isempty(dX)||isnan(dX) 80 | ed=msgbox('Empty input field. Please make sure all required fields are filled out correctly ','FluEgg Error: Empty fields','error'); 81 | try 82 | rmappdata(handleResults,'dX') 83 | catch 84 | %If the handle does not exist, dont do anything 85 | end 86 | set(ed, 'WindowStyle', 'modal'); 87 | uiwait(ed); 88 | return 89 | end 90 | if dX<=0 91 | ed=msgbox('Incorrect negative or zero value. Please make sure all required fields are filled out correctly','FluEgg Error: Incorrect negative or zero value','error'); 92 | try 93 | rmappdata(handleResults,'dX') 94 | catch 95 | %If the handle does not exist, dont do anything 96 | end 97 | set(ed, 'WindowStyle', 'modal'); 98 | uiwait(ed); 99 | return 100 | end 101 | if dX>CumlDistance(end)*1000 102 | ed = errordlg('The longitudinal distance you input is out of the domain','Error'); 103 | try 104 | rmappdata(handleResults,'dX') 105 | catch 106 | %If the handle does not exist, dont do anything 107 | end 108 | set(ed, 'WindowStyle', 'modal'); 109 | uiwait(ed); 110 | return 111 | end 112 | %========================================================================== 113 | 114 | setappdata(handleResults, 'dX', dX); 115 | close; 116 | 117 | -------------------------------------------------------------------------------- /utm2deg.m: -------------------------------------------------------------------------------- 1 | function [Lat,Lon] = utm2deg(xx,yy,utmzone) 2 | % ------------------------------------------------------------------------- 3 | % [Lat,Lon] = utm2deg(x,y,utmzone) 4 | % 5 | % Description: Function to convert vectors of UTM coordinates into Lat/Lon vectors (WGS84). 6 | % Some code has been extracted from UTMIP.m function by Gabriel Ruiz Martinez. 7 | % 8 | % Inputs: 9 | % x, y , utmzone. 10 | % 11 | % Outputs: 12 | % Lat: Latitude vector. Degrees. +ddd.ddddd WGS84 13 | % Lon: Longitude vector. Degrees. +ddd.ddddd WGS84 14 | % 15 | % Example 1: 16 | % x=[ 458731; 407653; 239027; 230253; 343898; 362850]; 17 | % y=[4462881; 5126290; 4163083; 3171843; 4302285; 2772478]; 18 | % utmzone=['30 T'; '32 T'; '11 S'; '28 R'; '15 S'; '51 R']; 19 | % [Lat, Lon]=utm2deg(x,y,utmzone); 20 | % fprintf('%11.6f ',lat) 21 | % 40.315430 46.283902 37.577834 28.645647 38.855552 25.061780 22 | % fprintf('%11.6f ',lon) 23 | % -3.485713 7.801235 -119.955246 -17.759537 -94.799019 121.640266 24 | % 25 | % Example 2: If you need Lat/Lon coordinates in Degrees, Minutes and Seconds 26 | % [Lat, Lon]=utm2deg(x,y,utmzone); 27 | % LatDMS=dms2mat(deg2dms(Lat)) 28 | %LatDMS = 29 | % 40.00 18.00 55.55 30 | % 46.00 17.00 2.01 31 | % 37.00 34.00 40.17 32 | % 28.00 38.00 44.33 33 | % 38.00 51.00 19.96 34 | % 25.00 3.00 42.41 35 | % LonDMS=dms2mat(deg2dms(Lon)) 36 | %LonDMS = 37 | % -3.00 29.00 8.61 38 | % 7.00 48.00 4.40 39 | % -119.00 57.00 18.93 40 | % -17.00 45.00 34.33 41 | % -94.00 47.00 56.47 42 | % 121.00 38.00 24.96 43 | % 44 | % Author: 45 | % Rafael Palacios 46 | % Universidad Pontificia Comillas 47 | % Madrid, Spain 48 | % Version: Apr/06, Jun/06, Aug/06 49 | % Aug/06: corrected m-Lint warnings 50 | %------------------------------------------------------------------------- 51 | format long 52 | % Argument checking 53 | % 54 | error(nargchk(3, 3, nargin)); %3 arguments required 55 | n1=length(xx); 56 | n2=length(yy); 57 | n3=size(utmzone,1); 58 | if (n1~=n2 || n1~=n3) 59 | error('x,y and utmzone vectors should have the same number or rows'); 60 | end 61 | c=size(utmzone,2); 62 | if (c~=4) 63 | error('utmzone should be a vector of strings like "30 T"'); 64 | end 65 | 66 | 67 | 68 | % Memory pre-allocation 69 | % 70 | Lat=zeros(n1,1); 71 | Lon=zeros(n1,1); 72 | 73 | 74 | % Main Loop 75 | % 76 | for i=1:n1 77 | if (utmzone(i,4)>'X' || utmzone(i,4)<'C') 78 | fprintf('utm2deg: Warning utmzone should be a vector of strings like "30 T", not "30 t"\n'); 79 | end 80 | if (utmzone(i,4)>'M') 81 | hemis='N'; % Northern hemisphere 82 | else 83 | hemis='S'; 84 | end 85 | 86 | x=xx(i); 87 | y=yy(i); 88 | zone=str2double(utmzone(i,1:2)); 89 | 90 | sa = 6378137.000000 ; sb = 6356752.314245; 91 | 92 | % e = ( ( ( sa ^ 2 ) - ( sb ^ 2 ) ) ^ 0.5 ) / sa; 93 | e2 = ( ( ( sa ^ 2 ) - ( sb ^ 2 ) ) ^ 0.5 ) / sb; 94 | e2cuadrada = e2 ^ 2; 95 | c = ( sa ^ 2 ) / sb; 96 | % alpha = ( sa - sb ) / sa; %f 97 | % ablandamiento = 1 / alpha; % 1/f 98 | 99 | X = x - 500000; 100 | 101 | if hemis == 'S' || hemis == 's' 102 | Y = y - 10000000; 103 | else 104 | Y = y; 105 | end 106 | 107 | S = ( ( zone * 6 ) - 183 ); 108 | lat = Y / ( 6366197.724 * 0.9996 ); 109 | v = ( c / ( ( 1 + ( e2cuadrada * ( cos(lat) ) ^ 2 ) ) ) ^ 0.5 ) * 0.9996; 110 | a = X / v; 111 | a1 = sin( 2 * lat ); 112 | a2 = a1 * ( cos(lat) ) ^ 2; 113 | j2 = lat + ( a1 / 2 ); 114 | j4 = ( ( 3 * j2 ) + a2 ) / 4; 115 | j6 = ( ( 5 * j4 ) + ( a2 * ( cos(lat) ) ^ 2) ) / 3; 116 | alfa = ( 3 / 4 ) * e2cuadrada; 117 | beta = ( 5 / 3 ) * alfa ^ 2; 118 | gama = ( 35 / 27 ) * alfa ^ 3; 119 | Bm = 0.9996 * c * ( lat - alfa * j2 + beta * j4 - gama * j6 ); 120 | b = ( Y - Bm ) / v; 121 | Epsi = ( ( e2cuadrada * a^ 2 ) / 2 ) * ( cos(lat) )^ 2; 122 | Eps = a * ( 1 - ( Epsi / 3 ) ); 123 | nab = ( b * ( 1 - Epsi ) ) + lat; 124 | senoheps = ( exp(Eps) - exp(-Eps) ) / 2; 125 | Delt = atan(senoheps / (cos(nab) ) ); 126 | TaO = atan(cos(Delt) * tan(nab)); 127 | longitude = (Delt *(180 / pi ) ) + S; 128 | latitude = ( lat + ( 1 + e2cuadrada* (cos(lat)^ 2) - ( 3 / 2 ) * e2cuadrada * sin(lat) * cos(lat) * ( TaO - lat ) ) * ( TaO - lat ) ) * ... 129 | (180 / pi); 130 | 131 | Lat(i)=latitude; 132 | Lon(i)=longitude; 133 | 134 | end -------------------------------------------------------------------------------- /parseArgs.m: -------------------------------------------------------------------------------- 1 | function ArgStruct=parseArgs(args,ArgStruct,varargin) 2 | % Helper function for parsing varargin. 3 | % 4 | % 5 | % ArgStruct=parseArgs(varargin,ArgStruct[,FlagtypeParams[,Aliases]]) 6 | % 7 | % * ArgStruct is the structure full of named arguments with default values. 8 | % * Flagtype params is params that don't require a value. (the value will be set to 1 if it is present) 9 | % * Aliases can be used to map one argument-name to several argstruct fields 10 | % 11 | % 12 | % example usage: 13 | % -------------- 14 | % function parseargtest(varargin) 15 | % 16 | % %define the acceptable named arguments and assign default values 17 | % Args=struct('Holdaxis',0, ... 18 | % 'SpacingVertical',0.05,'SpacingHorizontal',0.05, ... 19 | % 'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ... 20 | % 'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ... 21 | % 'rows',[],'cols',[]); 22 | % 23 | % %The capital letters define abrreviations. 24 | % % Eg. parseargtest('spacingvertical',0) is equivalent to parseargtest('sv',0) 25 | % 26 | % Args=parseArgs(varargin,Args, ... % fill the arg-struct with values entered by the user 27 | % {'Holdaxis'}, ... %this argument has no value (flag-type) 28 | % {'Spacing' {'sh','sv'}; 'Padding' {'pl','pr','pt','pb'}; 'Margin' {'ml','mr','mt','mb'}}); 29 | % 30 | % disp(Args) 31 | % 32 | % 33 | % 34 | % 35 | % % Aslak Grinsted 2003 36 | 37 | Aliases={}; 38 | FlagTypeParams=''; 39 | 40 | if (length(varargin)>0) 41 | FlagTypeParams=strvcat(varargin{1}); 42 | if length(varargin)>1 43 | Aliases=varargin{2}; 44 | end 45 | end 46 | 47 | 48 | %---------------Get "numeric" arguments 49 | NumArgCount=1; 50 | while (NumArgCount<=size(args,2))&(~ischar(args{NumArgCount})) 51 | NumArgCount=NumArgCount+1; 52 | end 53 | NumArgCount=NumArgCount-1; 54 | if (NumArgCount>0) 55 | ArgStruct.NumericArguments={args{1:NumArgCount}}; 56 | else 57 | ArgStruct.NumericArguments={}; 58 | end 59 | 60 | 61 | %--------------Make an accepted fieldname matrix (case insensitive) 62 | Fnames=fieldnames(ArgStruct); 63 | for i=1:length(Fnames) 64 | name=lower(Fnames{i,1}); 65 | Fnames{i,2}=name; %col2=lower 66 | AbbrevIdx=find(Fnames{i,1}~=name); 67 | Fnames{i,3}=[name(AbbrevIdx) ' ']; %col3=abreviation letters (those that are uppercase in the ArgStruct) e.g. SpacingHoriz->sh 68 | %the space prevents strvcat from removing empty lines 69 | Fnames{i,4}=isempty(strmatch(Fnames{i,2},FlagTypeParams)); %Does this parameter have a value? (e.g. not flagtype) 70 | end 71 | FnamesFull=strvcat(Fnames{:,2}); 72 | FnamesAbbr=strvcat(Fnames{:,3}); 73 | 74 | if length(Aliases)>0 75 | for i=1:length(Aliases) 76 | name=lower(Aliases{i,1}); 77 | FieldIdx=strmatch(name,FnamesAbbr,'exact'); %try abbreviations (must be exact) 78 | if isempty(FieldIdx) 79 | FieldIdx=strmatch(name,FnamesFull); %&??????? exact or not? 80 | end 81 | Aliases{i,2}=FieldIdx; 82 | AbbrevIdx=find(Aliases{i,1}~=name); 83 | Aliases{i,3}=[name(AbbrevIdx) ' ']; %the space prevents strvcat from removing empty lines 84 | Aliases{i,1}=name; %dont need the name in uppercase anymore for aliases 85 | end 86 | %Append aliases to the end of FnamesFull and FnamesAbbr 87 | FnamesFull=strvcat(FnamesFull,strvcat(Aliases{:,1})); 88 | FnamesAbbr=strvcat(FnamesAbbr,strvcat(Aliases{:,3})); 89 | end 90 | 91 | %--------------get parameters-------------------- 92 | l=NumArgCount+1; 93 | while (l<=length(args)) 94 | a=args{l}; 95 | if ischar(a) 96 | paramHasValue=1; % assume that the parameter has is of type 'param',value 97 | a=lower(a); 98 | FieldIdx=strmatch(a,FnamesAbbr,'exact'); %try abbreviations (must be exact) 99 | if isempty(FieldIdx) 100 | FieldIdx=strmatch(a,FnamesFull); 101 | end 102 | if (length(FieldIdx)>1) %shortest fieldname should win 103 | [mx,mxi]=max(sum(FnamesFull(FieldIdx,:)==' ',2)); 104 | FieldIdx=FieldIdx(mxi); 105 | end 106 | if FieldIdx>length(Fnames) %then it's an alias type. 107 | FieldIdx=Aliases{FieldIdx-length(Fnames),2}; 108 | end 109 | 110 | if isempty(FieldIdx) 111 | error(['Unknown named parameter: ' a]) 112 | end 113 | for curField=FieldIdx' %if it is an alias it could be more than one. 114 | if (Fnames{curField,4}) 115 | val=args{l+1}; 116 | else 117 | val=1; %parameter is of flag type and is set (1=true).... 118 | end 119 | ArgStruct.(Fnames{curField,1})=val; 120 | end 121 | l=l+1+Fnames{FieldIdx(1),4}; %if a wildcard matches more than one 122 | else 123 | error(['Expected a named parameter: ' num2str(a)]) 124 | end 125 | end 126 | 127 | -------------------------------------------------------------------------------- /dlmcell.m: -------------------------------------------------------------------------------- 1 | function dlmcell(file,cell_array,varargin) 2 | %% <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> %% 3 | % <><><><><> dlmcell - Write Cell Array to Text File <><><><><> % 4 | % <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> % 5 | % Version: 01.06.2010 % 6 | % (c) Roland Pfister % 7 | % roland_pfister@t-online.de % 8 | % 1. Synopsis % 9 | % % 10 | % A single cell array is written to an output file. Cells may consist of % 11 | % any combination of (a) numbers, (b) letters, or (c) words. The inputs % 12 | % are as follows: % 13 | % % 14 | % - file The output filename (string). % 15 | % - cell_array The cell array to be written. % 16 | % - delimiter Delimiter symbol, e.g. ',' (optional; % 17 | % default: tab ('\t'}). % 18 | % - append '-a' for appending the content to the % 19 | % output file (optional). % 20 | % % 21 | % 2. Example % 22 | % % 23 | % mycell = {'Numbers', 'Letters', 'Words','More Words'; ... % 24 | % 1, 'A', 'Apple', {'Apricot'}; ... % 25 | % 2, 'B', 'Banana', {'Blueberry'}; ... % 26 | % 3, 'C', 'Cherry', {'Cranberry'}; }; % 27 | % dlmcell('mytext.txt',mycell); % 28 | % % 29 | % <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> % 30 | 31 | 32 | 33 | %% Check input arguments 34 | if nargin < 2 35 | disp('Error - Give at least two input arguments!'); 36 | return; 37 | elseif nargin > 4 38 | disp('Error - Do not give more than 4 input arguments!'); 39 | return; 40 | end 41 | if ~ischar(file) 42 | disp(['Error - File input has to be a string (e.g. ' ... 43 | char(39) 'output.txt' char(39) '!']); 44 | return; 45 | end; 46 | if ~iscell(cell_array) 47 | disp('Error - Input cell_array not of the type "cell"!'); 48 | return; 49 | end; 50 | delimiter = '\t'; 51 | append = 'w'; 52 | if nargin > 2 53 | for i = 1:size(varargin,2) 54 | if strcmp('-a',varargin{1,i}) == 1 55 | append = 'a'; 56 | else 57 | delimiter = varargin{1,i}; 58 | end; 59 | end; 60 | end 61 | 62 | %% Open output file and prepare output array. 63 | output_file = fopen(file,append); 64 | output = cell(size(cell_array,1),size(cell_array,2)); 65 | 66 | %% Evaluate and write input array. 67 | for i = 1:size(cell_array,1) 68 | for j = 1:size(cell_array,2) 69 | if numel(cell_array{i,j}) == 0 70 | output{i,j} = ''; 71 | % Check whether the content of cell i,j is 72 | % numeric and convert numbers to strings. 73 | elseif isnumeric(cell_array{i,j}) || islogical(cell_array{i,j}) 74 | output{i,j} = num2str(cell_array{i,j}(1,1)); 75 | 76 | % Check whether the content of cell i,j is another cell (e.g. a 77 | % string of length > 1 that was stored as cell. If cell sizes 78 | % equal [1,1], convert numbers and char-cells to strings. 79 | % 80 | % Note that any other cells-within-the-cell will produce errors 81 | % or wrong results. 82 | elseif iscell(cell_array{i,j}) 83 | if size(cell_array{i,j},1) == 1 && size(cell_array{i,j},1) == 1 84 | if isnumeric(cell_array{i,j}{1,1}) 85 | output{i,j} = num2str(cell_array{i,j}{1,1}(1,1)); 86 | elseif ischar(cell_array{i,j}{1,1}) 87 | output{i,j} = cell_array{i,j}{1,1}; 88 | end; 89 | end; 90 | 91 | % If the cell already contains a string, nothing has to be done. 92 | elseif ischar(cell_array{i,j}) 93 | output{i,j} = cell_array{i,j}; 94 | end; 95 | 96 | % Cell i,j is written to the output file. A delimiter is appended 97 | % for all but the last element of each row. 98 | fprintf(output_file,'%s',output{i,j}); 99 | if j ~= size(cell_array,2) 100 | fprintf(output_file,'%s',delimiter); 101 | end 102 | end; 103 | % At the end of a row, a newline is written to the output file. 104 | fprintf(output_file,'\r\n'); 105 | end; 106 | 107 | %% Close output file. 108 | fclose(output_file); 109 | 110 | end -------------------------------------------------------------------------------- /batchgui.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | function varargout = batchgui(varargin) 20 | % BATCHGUI MATLAB code for batchgui.fig 21 | % BATCHGUI, by itself, creates a new BATCHGUI or raises the existing 22 | % singleton*. 23 | % 24 | % H = BATCHGUI returns the handle to a new BATCHGUI or the handle to 25 | % the existing singleton*. 26 | % 27 | % BATCHGUI('CALLBACK',hObject,eventData,handles,...) calls the local 28 | % function named CALLBACK in BATCHGUI.M with the given input arguments. 29 | % 30 | % BATCHGUI('Property','Value',...) creates a new BATCHGUI or raises the 31 | % existing singleton*. Starting from the left, property value pairs are 32 | % applied to the GUI before batchgui_OpeningFcn gets called. An 33 | % unrecognized property name or invalid value makes property application 34 | % stop. All inputs are passed to batchgui_OpeningFcn via varargin. 35 | % 36 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 37 | % instance to run (singleton)". 38 | % 39 | % See also: GUIDE, GUIDATA, GUIHANDLES 40 | 41 | % Edit the above text to modify the response to help batchgui 42 | 43 | % Last Modified by GUIDE v2.5 28-Feb-2017 10:58:53 44 | 45 | % Begin initialization code - DO NOT EDIT 46 | gui_Singleton = 1; 47 | gui_State = struct('gui_Name', mfilename, ... 48 | 'gui_Singleton', gui_Singleton, ... 49 | 'gui_OpeningFcn', @batchgui_OpeningFcn, ... 50 | 'gui_OutputFcn', @batchgui_OutputFcn, ... 51 | 'gui_LayoutFcn', [] , ... 52 | 'gui_Callback', []); 53 | if nargin && ischar(varargin{1}) 54 | gui_State.gui_Callback = str2func(varargin{1}); 55 | end 56 | 57 | if nargout 58 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 59 | else 60 | gui_mainfcn(gui_State, varargin{:}); 61 | end 62 | % End initialization code - DO NOT EDIT 63 | end 64 | 65 | % --- Executes just before batchgui is made visible. 66 | function batchgui_OpeningFcn(hObject, eventdata, handles, varargin) 67 | % This function has no output args, see OutputFcn. 68 | % hObject handle to figure 69 | % eventdata reserved - to be defined in a future version of MATLAB 70 | % handles structure with handles and user data (see GUIDATA) 71 | % varargin command line arguments to batchgui (see VARARGIN) 72 | 73 | % Choose default command line output for batchgui 74 | handles.output = hObject; 75 | 76 | % Update handles structure 77 | guidata(hObject, handles); 78 | 79 | % UIWAIT makes batchgui wait for user response (see UIRESUME) 80 | % uiwait(handles.figure1); 81 | end 82 | 83 | % --- Outputs from this function are returned to the command line. 84 | function varargout = batchgui_OutputFcn(hObject, eventdata, handles) 85 | % varargout cell array for returning output args (see VARARGOUT); 86 | % hObject handle to figure 87 | % eventdata reserved - to be defined in a future version of MATLAB 88 | % handles structure with handles and user data (see GUIDATA) 89 | 90 | % Get default command line output from handles structure 91 | varargout{1} = handles.output; 92 | end 93 | 94 | 95 | function NumSim_Callback(hObject, eventdata, handles) 96 | % hObject handle to NumSim (see GCBO) 97 | % eventdata reserved - to be defined in a future version of MATLAB 98 | % handles structure with handles and user data (see GUIDATA) 99 | 100 | % Hints: get(hObject,'String') returns contents of NumSim as text 101 | % str2double(get(hObject,'String')) returns contents of NumSim as a double 102 | end 103 | 104 | 105 | % --- Executes on button press in BatchrunButton. 106 | function BatchrunButton_Callback(hObject, eventdata, handles) 107 | hFluEggGui = getappdata(0,'hFluEggGui'); 108 | inputdata=getappdata(hFluEggGui,'inputdata'); 109 | inputdata.Batch.NumSim=str2double(get(handles.NumSim,'String')); 110 | inputdata.Batch.continuee=1; 111 | setappdata(hFluEggGui,'inputdata',inputdata) 112 | close(handles.figure1)%Close GUI 113 | end 114 | -------------------------------------------------------------------------------- /Extract_RAS_TS.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2016 Santiago Santacruz and Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | %%%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 20 | %% Extract output from HEC-RAS % 21 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | %-------------------------------------------------------------------------% 23 | % This function is used to extract data from a HEC-RAS project and produces % 24 | % References: % 25 | % Goodell, C.R. 2014. % 26 | % Breaking the HEC-RAS Code: A User's Guide to Automating HEC-RAS. A User's 27 | % Guide to Automating HEC-RAS. h2ls. Portland, OR. % 28 | %-------------------------------------------------------------------------% 29 | % % 30 | %-------------------------------------------------------------------------% 31 | % Created by : Santiago Santacruz & Tatiana % 32 | % Date : December 20, 2016 % 33 | % Last Modified : July 11, 2017 % 34 | %-------------------------------------------------------------------------% 35 | % Inputs: 36 | % Outputs: 37 | % Copyright 2016 Santiago Santacruz & Tatiana Garcia 38 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 39 | 40 | function [XS, hydrographs, profiles] = ... 41 | Extract_RAS_TS(strRASProject, handles)%, Plan, RiverStation) 42 | 43 | %% Creates a COM Server for the HEC-RAS Controller 44 | % The command above depends on the version of HEC-RAS you have, in my case 45 | % I am using version 5.0.3 46 | try 47 | RC = actxserver('RAS503.HECRASController'); 48 | catch 49 | try %HECRAS 5.0.2 50 | RC = actxserver('RAS502.HECRASController'); 51 | catch 52 | try %HECRAS 5.0.1 53 | RC = actxserver('RAS501.HECRASController'); 54 | catch 55 | try %HECRAS 5.0.0 56 | RC = actxserver('RAS500.HECRASController'); 57 | catch 58 | end %HECRAS 5.0.0 59 | end %HECRAS 5.0.1 60 | end%HECRAS 5.0.2 61 | end %HECRAS 5.0.3 62 | 63 | %% get variables from GUI with user selection 64 | lngRiverID = get(handles.popup_River,'Value'); % RiverID 65 | lngReachID = get(handles.popup_Reach,'Value'); % ReachID 66 | 67 | % Plan 68 | list = get(handles.popupPlan,'String'); 69 | val = get(handles.popupPlan,'value'); 70 | Plan = list(val,:); 71 | Plan = Plan{1}; 72 | 73 | % River Station 74 | list = get(handles.popup_River_Station,'String'); 75 | val = get(handles.popup_River_Station,'value'); 76 | XS = list(val,:); 77 | XS = XS{1}; 78 | 79 | %% Open the project 80 | %strRASProject = 'D:\Asian Carp\Asian Carp_USGS_Project\Tributaries data\Sandusky River\SANDUSKY_Hec_RAS_mod\Sandusky_mod_II\BallvilleDam_Updated.prj'; 81 | RC.Project_Open(strRASProject); %open and show interface, no need to use RC.ShowRAS in Matlab 82 | RC.Plan_SetCurrent(Plan); %Set Current Plan to selected Plan 83 | 84 | %% Define Variables 85 | lngNodeID = RC.Geometry_GetNode(lngRiverID, lngReachID, XS); % NodeID 86 | %% 87 | % Variables to be extracted 88 | lngQChannelID = 7; % Flow in the main channel 89 | lngWseID = 2; % Water Surface Elevation 90 | %% Get data 91 | [nProfiles, profiles] = RC.Output_GetProfiles(0, 0); 92 | QChannel_TS = nan(nProfiles - 1, 1); % Discard MaxWSL profile 93 | WSE = nan(nProfiles - 1, 1); % Discard MaxWSL profile 94 | 95 | for i = 1:nProfiles-1 % Profile = 1 is for MaxWSL (to be discarded) 96 | QChannel_TS(i) = RC.Output_NodeOutput(lngRiverID,... 97 | lngReachID,... 98 | lngNodeID,... 99 | 0,... 100 | i + 1,... 101 | lngQChannelID); 102 | WSE(i) = RC.Output_NodeOutput(lngRiverID,... 103 | lngReachID,... 104 | lngNodeID,... 105 | 0,... 106 | i + 1,... 107 | lngWseID); 108 | end 109 | hydrographs = [(1:numel(WSE))', QChannel_TS, WSE]; 110 | profiles = {profiles{2:end}}'; %Don't save MaxWS profile 111 | try 112 | RC.QuitRAS 113 | catch 114 | end 115 | delete(RC); 116 | end 117 | -------------------------------------------------------------------------------- /Longitudinal_Dist_Eggs.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | function varargout = Longitudinal_Dist_Eggs(varargin) 20 | % Last Modified by GUIDE v2.5 14-Aug-2014 10:36:53 21 | 22 | % Begin initialization code - DO NOT EDIT 23 | gui_Singleton = 1; 24 | gui_State = struct('gui_Name', mfilename, ... 25 | 'gui_Singleton', gui_Singleton, ... 26 | 'gui_OpeningFcn', @Longitudinal_Dist_Eggs_OpeningFcn, ... 27 | 'gui_OutputFcn', @Longitudinal_Dist_Eggs_OutputFcn, ... 28 | 'gui_LayoutFcn', [] , ... 29 | 'gui_Callback', []); 30 | if nargin && ischar(varargin{1}) 31 | gui_State.gui_Callback = str2func(varargin{1}); 32 | end 33 | 34 | if nargout 35 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 36 | else 37 | gui_mainfcn(gui_State, varargin{:}); 38 | end 39 | % End initialization code - DO NOT EDIT 40 | 41 | 42 | % --- Executes just before Longitudinal_Dist_Eggs is made visible. 43 | function Longitudinal_Dist_Eggs_OpeningFcn(hObject, ~, handles, varargin) 44 | diary('./results/FluEgg_LogFile.txt') 45 | handleResults=getappdata(0,'handleResults'); 46 | ResultsSim=getappdata(handleResults,'ResultsSim'); 47 | Temp=ResultsSim.Temp; 48 | %%Eggs biological properties 49 | specie=ResultsSim.specie; 50 | %% 51 | set(handles.SetTime,'String',round((ResultsSim.time(end)/3600)*10)/10); 52 | setappdata(handleResults, 'continue', 0); 53 | handles.output = hObject; 54 | guidata(hObject, handles); 55 | 56 | % --- Outputs from this function are returned to the command line. 57 | function varargout = Longitudinal_Dist_Eggs_OutputFcn(~, ~, handles) 58 | diary off 59 | varargout{1} = handles.output; 60 | 61 | function SetTime_Callback(~, ~, handles) 62 | function SetTime_CreateFcn(hObject, ~, handles) 63 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 64 | set(hObject,'BackgroundColor','white'); 65 | end 66 | 67 | % --- Executes on button press in Continue_button. 68 | function Continue_button_Callback(hObject, eventdata, handles) 69 | handleResults=getappdata(0,'handleResults'); 70 | SetTime=str2double(get(handles.SetTime,'String')); 71 | ResultsSim=getappdata(handleResults,'ResultsSim'); 72 | CalculateEggs_at_risk_hatching=(get(handles.Hatchingrisk,'value')); 73 | %% Error checking========================================================== 74 | if isempty(SetTime)||isnan(SetTime) 75 | ed=msgbox('Empty input field. Please make sure all required fields are filled out correctly ','FluEgg Error: Empty fields','error'); 76 | try 77 | rmappdata(handleResults,'SetTime') 78 | catch 79 | %If the handle does not exist, dont do anything 80 | end 81 | set(ed, 'WindowStyle', 'modal'); 82 | uiwait(ed); 83 | return 84 | end 85 | if SetTime<=0 86 | ed=msgbox('Incorrect negative or zero value. Please make sure all required fields are filled out correctly','FluEgg Error: Incorrect negative or zero value','error'); 87 | try 88 | rmappdata(handleResults,'SetTime') 89 | catch 90 | %If the handle does not exist, dont do anything 91 | end 92 | set(ed, 'WindowStyle', 'modal'); 93 | uiwait(ed); 94 | return 95 | end 96 | if SetTime>str2double(num2str(round(ResultsSim.time(end)*10/3600)/10)) 97 | ed = errordlg('Time exceeds simulation time','FluEgg Error: incorrect input value'); 98 | try 99 | rmappdata(handleResults,'SetTime') 100 | catch 101 | %If the handle does not exist, dont do anything 102 | end 103 | set(ed, 'WindowStyle', 'modal'); 104 | uiwait(ed); 105 | return 106 | end 107 | if (CalculateEggs_at_risk_hatching==1)&(SetTime 2011-02-05 48 | % Department of Psychology, The University of Hong Kong 49 | % 50 | % Originally based on 51 | % http://www.mathworks.in/matlabcentral/fileexchange/4038-savitzky-golay-smoothing-and-differentiation-filter 52 | % Allthough I have replaced almost all the code (partially based on 53 | % the comments on the FEX submission), increasing its compatibility 54 | % with MATLABs sgolay (now supports a weight matrix), its numerical 55 | % stability and it speed. Now, the help is pretty much all that 56 | % remains. 57 | % Jianwen Luo 2003-10-05 58 | % Department of Biomedical Engineering, Department of Electrical Engineering 59 | % Tsinghua University, Beijing 100084, P. R. China 60 | % Reference 61 | %[1]A. Savitzky and M. J. E. Golay, "Smoothing and Differentiation of Data 62 | % by Simplified Least Squares Procedures," Analytical Chemistry, vol. 36, 63 | % pp. 1627-1639, 1964. 64 | %[2]J. Steinier, Y. Termonia, and J. Deltour, "Comments on Smoothing and 65 | % Differentiation of Data by Simplified Least Square Procedures," 66 | % Analytical Chemistry, vol. 44, pp. 1906-1909, 1972. 67 | %[3]H. H. Madden, "Comments on Savitzky-Golay Convolution Method for 68 | % Least-Squares Fit Smoothing and Differentiation of Digital Data," 69 | % Analytical Chemistry, vol. 50, pp. 1383-1386, 1978. 70 | %[4]R. A. Leach, C. A. Carter, and J. M. Harris, "Least-Squares Polynomial 71 | % Filters for Initial Point and Slope Estimation," Analytical Chemistry, 72 | % vol. 56, pp. 2304-2307, 1984. 73 | %[5]P. A. Baedecker, "Comments on Least-Square Polynomial Filters for 74 | % Initial Point and Slope Estimation," Analytical Chemistry, vol. 57, pp. 75 | % 1477-1479, 1985. 76 | %[6]P. A. Gorry, "General Least-Squares Smoothing and Differentiation by 77 | % the Convolution (Savitzky-Golay) Method," Analytical Chemistry, vol. 78 | % 62, pp. 570-573, 1990. 79 | %[7]Luo J W, Ying K, He P, Bai J. Properties of Savitzky-Golay Digital 80 | % Differentiators, Digital Signal Processing, 2005, 15(2): 122-136. 81 | % 82 | %See also: 83 | % sgolay, savitzkyGolayFilt 84 | 85 | % Check if the input arguments are valid and apply defaults 86 | error(nargchk(2,6,nargin,'struct')); 87 | 88 | if round(n) ~= n, error(generatemsgid('MustBeInteger'),'Polynomial order (n) must be an integer.'), end 89 | if round(dn) ~= dn, error(generatemsgid('MustBeInteger'),'Differentiation order (dn) must be an integer.'), end 90 | if n > length(x)-1, error(generatemsgid('InvalidRange'),'The Polynomial Order must be less than the frame length.'), end 91 | if dn > n, error(generatemsgid('InvalidRange'),'The Differentiation order must be less than or equal to the Polynomial order.'), end 92 | 93 | % set defaults if needed 94 | if nargin<6 95 | flag=false; 96 | end 97 | if nargin < 5 || isempty(W) 98 | % No weighting matrix, make W an identity 99 | W = eye(length(x0)); 100 | else 101 | % Check W is real. 102 | if ~isreal(W), error(generatemsgid('NotReal'),'The weight vector must be real.'),end 103 | % Check for right length of W 104 | if length(W) ~= length(x0), error(generatemsgid('InvalidDimensions'),'The weight vector must be of the same length as the frame length.'),end 105 | % Check to see if all elements are positive 106 | if min(W) <= 0, error(generatemsgid('InvalidRange'),'All the elements of the weight vector must be greater than zero.'), end 107 | % Diagonalize the vector to form the weighting matrix 108 | W = diag(W); 109 | end 110 | if nargin<4 111 | x0=0; 112 | end 113 | if nargin<3 114 | dn=0; 115 | end 116 | 117 | % prepare for symbolic output 118 | if flag 119 | x=sym(x); 120 | x0=sym(x0); 121 | end 122 | 123 | Nx = length(x); 124 | x=x(:); 125 | Nx0 = length(x0); 126 | x0=x0(:); 127 | 128 | if flag 129 | A=ones(length(x),1); 130 | for k=1:n 131 | A=[A x.^k]; 132 | end 133 | df = inv(A'*A)*A'; % backslash operator doesn't work as expected with symbolic inputs, but the "slowness and inaccuracy" of this method doesn't matter when doing the symbolic version 134 | else 135 | df = cumprod([ones(Nx,1) x*ones(1,n)],2) \ eye(Nx); 136 | end 137 | df = df.'; 138 | 139 | hx = [(zeros(Nx0,dn)) ones(Nx0,1)*prod(1:dn)]; % order=0:dn-1,& dn,respectively 140 | for k=1:n-dn % order=dn+1:n=dn+k 141 | hx = [hx x0.^k*prod(dn+k:-1:k+1)]; 142 | end 143 | 144 | % filter coeffs 145 | fc = df*hx'*W; -------------------------------------------------------------------------------- /PercentageEggs_location_time.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | function varargout = PercentageEggs_location_time(varargin) 20 | % PERCENTAGEEGGS_LOCATION_TIME MATLAB code for PercentageEggs_location_time.fig 21 | %%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | %% Calculate percentage of eggs at a given % 23 | %% location, depth, and time % 24 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 25 | %-------------------------------------------------------------------------% 26 | % FluEgg tool to calculate percentage of eggs at a given location, depth % 27 | % and time. This tool is particulary useful for hindcasting spawning % 28 | % grounds based on eggs collected in the field % 29 | %-------------------------------------------------------------------------% 30 | % Created by : Tatiana Garcia % 31 | % Last Modified : October 24, 2016 % 32 | %-------------------------------------------------------------------------% 33 | % Copyright 2013 Tatiana Garcia 34 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 35 | 36 | % Last Modified by GUIDE v2.5 25-Oct-2016 10:57:47 37 | 38 | % Begin initialization code - DO NOT EDIT 39 | gui_Singleton = 1; 40 | gui_State = struct('gui_Name', mfilename, ... 41 | 'gui_Singleton', gui_Singleton, ... 42 | 'gui_OpeningFcn', @PercentageEggs_location_time_OpeningFcn, ... 43 | 'gui_OutputFcn', @PercentageEggs_location_time_OutputFcn, ... 44 | 'gui_LayoutFcn', [] , ... 45 | 'gui_Callback', []); 46 | if nargin && ischar(varargin{1}) 47 | gui_State.gui_Callback = str2func(varargin{1}); 48 | end 49 | 50 | if nargout 51 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 52 | else 53 | gui_mainfcn(gui_State, varargin{:}); 54 | end 55 | end %function 56 | % End initialization code - DO NOT EDIT 57 | 58 | 59 | function PercentageEggs_location_time_OpeningFcn(hObject, eventdata, handles, varargin) 60 | axes(handles.bottom); imshow('asiancarp.png'); 61 | %%========================================================================= 62 | % handleResults=getappdata(0,'handleResults'); 63 | % ResultsSim=getappdata(handleResults,'ResultsSim'); 64 | 65 | handles.output = hObject; 66 | guidata(hObject, handles); 67 | end %function 68 | 69 | function varargout = PercentageEggs_location_time_OutputFcn(hObject, eventdata, handles) 70 | varargout{1} = handles.output; 71 | end %function 72 | 73 | function [Egg_sampling_location_m,eggAge,Sampling_depth_m,SamplingTime_minutes]=load_data_from_GUI(handles) 74 | Egg_sampling_location_m=str2double(get(handles.Egg_sampling_location_m,'String')); 75 | eggAge=str2double(get(handles.eggAge,'String')); 76 | Sampling_depth_m=str2double(get(handles.Sampling_depth_m,'String')); 77 | SamplingTime_minutes=str2double(get(handles.SamplingTime_minutes,'String')); 78 | end 79 | 80 | 81 | % --- Executes on button press in calculate_percentage_of_eggs_button. 82 | function calculate_percentage_of_eggs_button_Callback(hObject, eventdata, handles) 83 | %The percentage of eggs is calculated based on eggs located before the 84 | %bongonet at the starting sampling time. Number of eggs collected 85 | %corresponds to eggs that crossed the sampling distance withing the 86 | %sampling time 87 | 88 | %% Load results 89 | handleResults=getappdata(0,'handleResults'); 90 | ResultsSim=getappdata(handleResults,'ResultsSim'); 91 | [Egg_sampling_location_m,eggAge,Sampling_depth_m,SamplingTime_minutes]=load_data_from_GUI(handles); 92 | X=ResultsSim.X; 93 | Z=ResultsSim.Z; 94 | time=ResultsSim.time; 95 | 96 | %% Where are all the eggs where when sampling occured? 97 | TimeIndex_start=find(time<=((eggAge*3600)-(SamplingTime_minutes*60/2)),1,'last'); 98 | TimeIndex_end=find(time>=((eggAge*3600)+(SamplingTime_minutes*60/2)),1,'first'); 99 | if isempty(TimeIndex_end) 100 | ed=errordlg(['You need to do another simulation with at least ',num2str(SamplingTime_minutes/2),' minutes more of simulation time'],'Error'); 101 | set(ed, 'WindowStyle', 'modal'); 102 | uiwait(ed); 103 | Exit=1; 104 | return 105 | end 106 | X_at_timewindow=X(TimeIndex_start:TimeIndex_end,:); 107 | 108 | % DispersionofEggsat_sampling=max(X_at_sampling)-min(X_at_sampling); 109 | % Dx_m=round(2*(DispersionofEggsat_sampling^(1/3)))/2; 110 | 111 | %find eggs at starting sampling window located before the net in the 112 | %longitudinal direction 113 | EggsBeforeNetAtSampling=find(( X_at_timewindow(1,:)<=Egg_sampling_location_m)); 114 | N=0; %Initialize egg counter=0 115 | set(handles.Percentage_eggs,'String',' ') 116 | for i=1:size(EggsBeforeNetAtSampling,2) %For all eggs located before the net at the begining of the sampling period.. 117 | % Find the time at which eggs crossed the net 118 | Samplingtimeindex=find(X_at_timewindow(:,EggsBeforeNetAtSampling(i))>=Egg_sampling_location_m,1,'first'); 119 | if Samplingtimeindex>=1 %If egg crossed the net 120 | %EggIndex(i)=EggsBeforeNetAtSampling(i); 121 | %% Find the vertical location of the egg 122 | ZeggAtSampling=Z(TimeIndex_start+Samplingtimeindex,EggsBeforeNetAtSampling(i)); 123 | %% If located where net was, count it 124 | if ZeggAtSampling>=-Sampling_depth_m 125 | N=N+1; 126 | end 127 | end 128 | end 129 | set(handles.Percentage_eggs,'String', num2str(N*100/size(X,2))) 130 | ed=errordlg('Done','Check your results'); 131 | set(ed, 'WindowStyle', 'modal'); 132 | uiwait(ed); 133 | end 134 | 135 | %If user changes sampling location or egg age 136 | function Egg_sampling_location_m_Callback(hObject, eventdata, handles) 137 | try % Try first, because if the user had not finished filling up the blcks we might have an error 138 | calculate_location_accuracy(handles); 139 | catch 140 | end 141 | end 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | % 170 | % function Generateplot_debuggin(handles) 171 | % figure('color','w') 172 | % plot([Egg_sampling_location_m Egg_sampling_location_m],[5600 5900],'r','linewidth',3) 173 | % hold on 174 | % for i=1:size( X_at_sampling,2) 175 | % plot(X_at_timewindow(:,i),[time(TimeIndex_start):time(2)-time(1):time(TimeIndex_end)],'*g') 176 | % hold all 177 | % end 178 | % %find eggs at starting sampling window located before the net 179 | % EggsBeforeNetAtSampling=find(( X_at_timewindow(1,:)<=Egg_sampling_location_m)); 180 | % N=0; 181 | % for i=1:size(EggsBeforeNetAtSampling,2) 182 | % Samplingtimeindex=find(X_at_timewindow(:,EggsBeforeNetAtSampling(i))>=Egg_sampling_location_m,1,'first'); 183 | % if Samplingtimeindex>=1 184 | % EggIndex(i)=EggsBeforeNetAtSampling(i); 185 | % ZeggAtSampling=Z(TimeIndex_start+Samplingtimeindex,EggsBeforeNetAtSampling(i)) 186 | % if ZeggAtSampling>=-Sampling_depth_m 187 | % N=N+1; 188 | % end 189 | % plot(X_at_timewindow(:,EggsBeforeNetAtSampling(i)),[time(TimeIndex_start):time(2)-time(1):time(TimeIndex_end)],'*k') 190 | % 191 | % end 192 | % end 193 | % end 194 | 195 | -------------------------------------------------------------------------------- /General_2_use_outside_FluEgg_Extract_RAS.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | %%%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 20 | %% Extract output from HEC-RAS % 21 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | %-------------------------------------------------------------------------% 23 | % This function is used to extract data from a HEC-RAS project and produces % 24 | % References: % 25 | % Goodell, C.R. 2014. % 26 | % Breaking the HEC-RAS Code: A User's Guide to Automating HEC-RAS. A User's 27 | % Guide to Automating HEC-RAS. h2ls. Portland, OR. % 28 | %-------------------------------------------------------------------------% 29 | % % 30 | %-------------------------------------------------------------------------% 31 | % Created by : Tatiana Garcia % 32 | % Date : March 29, 2016 % 33 | % Last Modified : April 18, 2016 % 34 | %-------------------------------------------------------------------------% 35 | % Inputs: 36 | % Outputs: 37 | % 38 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 39 | 40 | function [Riverinputfile]=Extract_RAS(strRASProject) 41 | 42 | %% Creates a COM Server for the HEC-RAS Controller 43 | RC = actxserver('RAS500.HECRASController'); 44 | % The command above depends on the version of HEC-RAS you have, in my case 45 | % I am using version 5.0. 46 | 47 | %% Open the project 48 | %strRASProject = 'D:\Asian Carp\Asian Carp_USGS_Project\Tributaries data\Sandusky River\SANDUSKY_Hec_RAS_mod\Sandusky_mod_II\BallvilleDam_Updated.prj'; 49 | RC.Project_Open(strRASProject); %open and show interface, no need to use RC.ShowRAS in Matlab 50 | 51 | %% Define Variables 52 | % strRASProject-->The path and filename of the desired HEC-RAS Project. 53 | %lngMessages = 1; % Number of messages returned by the RASController 54 | %strMessages = {}; % An array of messages returned by the RASController 55 | lngRiverID = 1; % RiverID 56 | lngReachID = 1; % ReachID 57 | lngProfile = 1; % Profile Number 58 | lngUpDn = 0; % Up/Down index for nodes with multiple sections (only used for bridges) 59 | 60 | % Output ID of Variables ( see page 247 in reference book for more details) 61 | % lngWS_ID = 2; % The Water Surface Elevation ID is 2. 62 | lngVelChnl_ID = 25; % The ID of the average velocity of flow for the main channel is 23. 63 | lngHydrDepthC_ID = 128; % Hydraulic depth in channel. 64 | lngQChannel_ID = 7; % Flow in the main channel. 65 | lngHydrRadiusC_ID = 210; % ID for hydraulic radius in channel. 66 | lngMannWtdChnl_ID = 45; % ID for Conveyance weighted Manning's n for the main channel. 67 | lngLengthChnl_ID = 42; % ID for Downstream reach length of the main channel to next XS 68 | %(unless BR in d/s, then this is the distance to the deck/roadway). 69 | 70 | lngNum_XS = RC.Schematic_XSCount(); %Number of XS - HEC-RAS Controller will populate. 71 | 72 | [~,~,lngNum_RS]=RC.Geometry_GetNodes(lngRiverID,lngReachID,0,0,0);%Number of nodes 73 | 74 | % Preallocate memory 75 | strRS = cell(lngNum_RS,1); %Array of names of the nodes-->River station name. See page 36 in book 76 | strNodeType = strRS; %Pre-allocate array for node type 77 | 78 | % Preallocate memory for output vectors 79 | %sngWS = nan(lngNum_RS,1); 80 | sngVelChnl = nan(lngNum_XS,1); 81 | sngHydrDepthC = nan(lngNum_XS,1); 82 | sngQChannel = nan(lngNum_XS,1); 83 | sngHydrRadiusC = nan(lngNum_XS,1); 84 | sngMannWtdChnl = nan(lngNum_XS,1); 85 | sngLengthChnl = nan(lngNum_XS,1); 86 | 87 | %% Run the current plan 88 | %RC.Compute_CurrentPlan(0,0); %from book: = RC.Compute_CurrentPlan(lngMessages,strMessages(), True) 89 | % RC.Compute_HideComputationWindow; %To hide Computation Window 90 | 91 | % Uncoment the lines below for info about current plan 92 | % Current_Plan= RC.CurrentPlanFile() 93 | % Current_Geometry_File= RC.CurrentGeomFile() 94 | 95 | %% Output Results 96 | XC_counter=0; 97 | % Extracts variable info from XS to Xs 98 | for i=1:lngNum_RS 99 | strNodeType{i}=RC.Geometry.NodeCType(lngRiverID,lngReachID,i); 100 | 101 | if strcmp(strNodeType{i},'')% An empty strings (i.e. ' ') denotes a cross section; 102 | XC_counter=XC_counter+1; 103 | % Here we assing the river station name to each node 104 | strRS{XC_counter} = RC.Geometry.NodeRS(lngRiverID,lngReachID,i); 105 | % Extracts average velocity of flow for the main channel 106 | sngVelChnl(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 107 | lngProfile,lngVelChnl_ID); 108 | % Extracts hydraulic depth in channel 109 | sngHydrDepthC(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 110 | lngProfile,lngHydrDepthC_ID); 111 | % Extracts flow in the main channel. 112 | sngQChannel(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 113 | lngProfile,lngQChannel_ID); 114 | % Extracts hydraulic radius in channel. 115 | sngHydrRadiusC(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 116 | lngProfile,lngHydrRadiusC_ID); 117 | % Extracts conveyance weighted Manning's n for the main channel. 118 | sngMannWtdChnl(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 119 | lngProfile,lngMannWtdChnl_ID); 120 | % Extracts conveyance weighted Manning's n for the main channel. 121 | sngLengthChnl(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 122 | lngProfile,lngLengthChnl_ID); 123 | % Extracts Water Surface Elevation at each XS 124 | %sngWS(i) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 125 | % lngProfile,lngWS_ID); 126 | end%if is a cross section 127 | 128 | end %for 129 | sngLengthChnl(end)=0; %There is not data of length channel for the last cell 130 | 131 | %% Generate Rivirinputfile dataset for the FluEgg model 132 | Riverinputfile=Generate_Rivirinputfile(); 133 | 134 | try 135 | RC.Quit 136 | catch 137 | end 138 | delete(RC); 139 | 140 | 141 | 142 | %% ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 143 | function Riverinputfile=Generate_Rivirinputfile() 144 | CumlDistance=[0;cumsum(sngLengthChnl(1:end-1))/1000];%In km 145 | CellNumber=(1:1:lngNum_XS)'; 146 | ks=(8.1.*sngMannWtdChnl.*sqrt(9.81)).^6; 147 | Ustar=sngVelChnl./(8.1*((sngHydrRadiusC./ks).^(1/6))); 148 | Riverinputfile=[CellNumber CumlDistance sngHydrDepthC sngQChannel... 149 | sngVelChnl zeros(lngNum_XS,1) zeros(lngNum_XS,1) Ustar ... 150 | 22*ones(lngNum_XS,1)]; % default temperature 22C 151 | end 152 | %% ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 153 | 154 | end 155 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 156 | %% <<<<<<<<<<<<<<<<<<<<<<<<< END OF FUNCTION >>>>>>>>>>>>>>>>>>>>>>>>>>>>%% 157 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 158 | 159 | %% Notes: 160 | % When there is not data the controller puts a very large number: 3.39999995214436e+38 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fluvial Egg Drift Simulator (FluEgg) 2 | A three-dimensional Lagrangian model capable of evaluating the influence of flow velocity, shear dispersion and turbulent diffusion on the transport and dispersal patterns of Asian carp eggs is presented. The models variables include not only biological behavior (growth rate, density changes) but also the physical characteristics of the flow field, such as mean velocities and eddy diffusivities. 3 | 4 | # Code Structure 5 | The Graphical User Inter Interface (GUI) code for the FluEgg is FluEgg.m and FluEgg.fig. 6 | The Main function of FluEgg is called FluEgggui, this function uses the Jump function, in this function particles move (jump) every time step following the random walk and random displacement approach. 7 | 8 | # Motivation 9 | The transport of Asian carp eggs and fish in the early stages of development is very important on their life history and recruitment success. A better understanding of the transport and dispersal patterns of Asian carp at early life stages might give insight into the development and implementation of control strategies for Asian carp. 10 | 11 | The FluEgg model was developed to evaluate the influence of flow velocity, shear dispersion and turbulent diffusion on the transport and dispersal patterns of Asian carp eggs. FluEgg output includes the three-dimensional location of the eggs at each time 12 | step together with its growth stage. The output results can be used to estimate lateral, longitudinal or vertical egg distribution. In addition, it can be used to generate an egg breakthrough curve (egg concentration as a function of time) at a certain downstream location from the virtual spawning location. Egg breakthrough curves are important for understanding egg dispersion and travel times. 13 | Egg vertical concentration distribution might give insights into egg suspension and settlement. Egg longitudinal concentration distributions can be used to estimate the streamwise and shear velocity, and minimum river length required for successful egg development. 14 | 15 | Egg lateral distributions give information about dead zones, provided the input hydraulic data for the model is sufficiently well 16 | described. The location of suitable spawning grounds can be predicted based on the egg growth stage and on the vertical, lateral 17 | or longitudinal egg concentration distributions. 18 | The FluEgg model has the capability to predict the drifting behavior of eggs based on the physical properties of the eggs and 19 | the environmental and hydrodynamic characteristics of the stream where the eggs are drifting. 20 | A complete description of the FluEgg model was presented by Garcia et al. (2013); users can refer to this paper for detailed information on both the mathematical model and the performance of the model. 21 | 22 | #References 23 | Garcia, T., Jackson, P.R.,Murphy, E.A., Valocchi, A.J., Garcia, M.H., 2013. Development of a Fluvial Egg Drift Simulator to evaluate the transport and dispersion of Asian carp eggs in rivers. Ecol. Model. 263, 211–222 24 | 25 | # Installation 26 | The FluEgg model iswritten in the MATLAB® programming language (Mathworks, Natick, MA,USA). It requires the statistics and image processing toolboxes. 27 | 28 | ============================================================================== 29 | FluEgg Release License 30 | ============================================================================== 31 | %============================================================================== 32 | % FluEgg -Fluvial Egg Drift Simulator 33 | %============================================================================== 34 | % Copyright (c) 2013 Tatiana Garcia 35 | 36 | % This program is free software: you can redistribute it and/or modify 37 | % it under the terms of the GNU General Public License version 3 as published by 38 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 39 | % with a permitted obligation to maintain Appropriate Legal Notices. 40 | 41 | % This program is distributed in the hope that it will be useful, 42 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 43 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 44 | % GNU General Public License for more details. 45 | 46 | % You should have received a copy of the GNU General Public License 47 | % along with this program. If not, see . 48 | 49 | ============================================================================== 50 | DISCLAIMER 51 | ============================================================================== 52 | 53 | Unless otherwise noted below, this software is in the public domain because it contains materials that 54 | originally came from the United States Geological Survey, an agency of the United States Department of 55 | Interior. For more information, see the official USGS copyright policy at: 56 | 57 | http://www.usgs.gov/visual-id/credit_usgs.html#copyright 58 | 59 | Although this software program has been used by the USGS, no warranty, expressed or implied, is made by 60 | the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material 61 | nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS 62 | in connection therewith. 63 | 64 | This software is provided "AS IS." 65 | 66 | Attributions and Licences: 67 | References to or use of non-U.S. Department of the Interior (DOI) products does not constitute an endorsement by the DOI. 68 | 69 | This information is preliminary or provisional and is subject to 70 | revision. It is being provided to meet the need for timely best 71 | science. The information has not received final approval by the USGS 72 | and is provided on the condition that neither the USGS nor the 73 | U.S. Government shall be held liable for any damages resulting from 74 | the authorized or unauthorized use of the information. 75 | 76 | ============================================================================== 77 | Copyrights and Licenses for Third Party Software Distributed with FluEgg: 78 | ============================================================================== 79 | The FluEgg program contains code written by third parties. Such software will 80 | have its own individual LICENSE.TXT file in the directory in which it appears. 81 | This file will describe the copyrights, license, and restrictions which apply 82 | to that code. 83 | 84 | The disclaimer of warranty in thid Open Source License 85 | applies to all code in the FluEgg Distribution, and nothing in any of the 86 | other licenses gives permission to use the names of Tatiana Garcia, U.S Geological Survey 87 | to endorse or promote products derived from this Software. 88 | 89 | The following pieces of software have additional or alternate copyrights, 90 | licenses, and/or restrictions: 91 | 92 | Program/Function Developer Directory Notes 93 | ---------------- --------- --------- --------- 94 | FluEgg 1.3 Tatiana Garcia, University of Illinois FluEgg_Git_Repo\license_FluEgg_1.3.txt 95 | voxel.m Suresh Joel FluEgg_Git_Repo\voxel.m 96 | cells.m Suresh Joel FluEgg_Git_Repo\voxel.m 97 | dlmcell Roland Pfister FluEgg_Git_Repo\dlmcell.m Used in FluEgggui.m 98 | parseArgs.m Aslak Grinsted FluEgg_Git_Repo\parseArgs.m Used in Subaxis.m 99 | subaxis.m Aslak Grinsted FluEgg_Git_Repo\subaxis.m This function is used to reduce spacing between figure border and figure axis 100 | savefast.m Timothy E. Holy FluEgg_Git_Repo\savefast.m Used in FluEgggui.m 101 | pcscurvature.m Inci-Burak Güneralp,Prolific Oven,Palo Alto,CA FluEgg_Git_Repo\pcscurvature.m Used in google_earth.m-->Parametric cubic spline interpolation of digitized data points of meandering rivers 102 | reorient.m Inci-Burak Güneralp,Prolific Oven,Palo Alto,CA FluEgg_Git_Repo\reorient.m Used in pcscurvature.m 103 | savitzkyGolayFilt.m R. Losada FluEgg_Git_Repo\savitzkyGolayFilt.m Used in pcscurvature.m 104 | savitzkyGolay.m Jianwen Luo,Tsinghua University FluEgg_Git_Repo\savitzkyGolay.m Used in savitzkyGolayFilt.m 105 | deg2utm.m Rafael Palacios,Universidad Pontificia Comillas FluEgg_Git_Repo\deg2utm.m Used in google_earth.m-->Function to convert lat/lon vectors into UTM coordinates 106 | GEplot_3D.m Modif by P.R. Jackson and Tatiana Garcia FluEgg_Git_Repo\GEplot_3D.m Used in google_earth.m. Initial version (GEplot) developed by Rafael Palacios, Universidad Pontificia Comillas. 107 | kml2struct.m James Slegers Used in google_earth.m 108 | sn2xy.m FluEgg_Git_Repo\sn2xy_License.txt Used in google_earth.m-->Transform curvilinear orthogonal to cartesian coordinates 109 | utm2deg.m Rafael Palacios,Universidad Pontificia Comillas FluEgg_Git_Repo\deg2utm.m Used in google_earth.m and GEplot_3D-->Function to convert vectors of UTM coordinates into Lat/Lon vectors (WGS84). 110 | -------------------------------------------------------------------------------- /Extract_RAS.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | %%%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 20 | %% Extract output from HEC-RAS % 21 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | %-------------------------------------------------------------------------% 23 | % This function is used to extract data from a HEC-RAS project and produces % 24 | % References: % 25 | % Goodell, C.R. 2014. % 26 | % Breaking the HEC-RAS Code: A User's Guide to Automating HEC-RAS. A User's 27 | % Guide to Automating HEC-RAS. h2ls. Portland, OR. % 28 | %-------------------------------------------------------------------------% 29 | % % 30 | %-------------------------------------------------------------------------% 31 | % Created by : Tatiana Garcia % 32 | % Date : March 29, 2016 % 33 | % Last Modified : April 18, 2016 % 34 | %-------------------------------------------------------------------------% 35 | % Inputs: 36 | % Outputs: 37 | % 38 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 39 | 40 | function [Riverinputfile]=Extract_RAS(strRASProject,handles,profile) 41 | 42 | %% Creates a COM Server for the HEC-RAS Controller 43 | 44 | % The command above depends on the version of HEC-RAS you have, in my case 45 | % I am using version 5.0.3 46 | try 47 | RC = actxserver('RAS503.HECRASController'); 48 | catch 49 | try %HECRAS 5.0.2 50 | RC = actxserver('RAS502.HECRASController'); 51 | catch 52 | try %HECRAS 5.0.1 53 | RC = actxserver('RAS501.HECRASController'); 54 | catch 55 | try %HECRAS 5.0.0 56 | RC = actxserver('RAS500.HECRASController'); 57 | catch 58 | end %HECRAS 5.0.0 59 | end %HECRAS 5.0.1 60 | end%HECRAS 5.0.2 61 | end %HECRAS 5.0.3 62 | 63 | 64 | %% Open the project 65 | %strRASProject = 'D:\Asian Carp\Asian Carp_USGS_Project\Tributaries data\Sandusky River\SANDUSKY_Hec_RAS_mod\Sandusky_mod_II\BallvilleDam_Updated.prj'; 66 | RC.Project_Open(strRASProject); %open and show interface, no need to use RC.ShowRAS in Matlab 67 | 68 | %% Define Variables 69 | % get variables from GUI with user selection 70 | lngRiverID = get(handles.popup_River,'Value'); % RiverID 71 | lngReachID = get(handles.popup_Reach,'Value'); % ReachID 72 | %% 73 | if profile==-1 74 | lngProfile = get(handles.popup_HECRAS_profile,'Value')-1; % Profile Number, 1 is all profiles 75 | else 76 | %The first profile in HEC-RAS corresponds to MAX WS, then the profile 77 | % corresponding to initial conditions is: 78 | lngProfile=profile+1; 79 | end 80 | 81 | lngUpDn = 0; % Up/Down index for nodes with multiple sections (only used for bridges) 82 | % Output ID of Variables ( see page 247 in reference book for more details) 83 | % lngWS_ID = 2; % The Water Surface Elevation ID is 2. 84 | lngVelChnl_ID = 25; % The ID of the average velocity of flow for the main channel is 23. 85 | lngHydrDepthC_ID = 128; % Hydraulic depth in channel. 86 | lngQChannel_ID = 7; % Flow in the main channel. 87 | lngHydrRadiusC_ID = 210; % ID for hydraulic radius in channel. 88 | lngMannWtdChnl_ID = 45; % ID for Conveyance weighted Manning's n for the main channel. 89 | lngLengthChnl_ID = 42; % ID for Downstream reach length of the main channel to next XS 90 | %(unless BR in d/s, then this is the distance to the deck/roadway). 91 | 92 | lngNum_XS = RC.Schematic_XSCount(); %Number of XS - HEC-RAS Controller will populate. 93 | 94 | [~,~,lngNum_RS]=RC.Geometry_GetNodes(lngRiverID,lngReachID,0,0,0);%Number of nodes 95 | 96 | % Preallocate memory 97 | strRS = cell(lngNum_RS,1); %Array of names of the nodes-->River station name. See page 36 in book 98 | strNodeType = strRS; %Pre-allocate array for node type 99 | 100 | % Preallocate memory for output vectors 101 | %sngWS = nan(lngNum_RS,1); 102 | sngVelChnl = nan(lngNum_XS,1); 103 | sngHydrDepthC = nan(lngNum_XS,1); 104 | sngQChannel = nan(lngNum_XS,1); 105 | sngHydrRadiusC = nan(lngNum_XS,1); 106 | sngMannWtdChnl = nan(lngNum_XS,1); 107 | sngLengthChnl = nan(lngNum_XS,1); 108 | 109 | %% Run the current plan 110 | %RC.Compute_CurrentPlan(0,0); %from book: = RC.Compute_CurrentPlan(lngMessages,strMessages(), True) 111 | % RC.Compute_HideComputationWindow; %To hide Computation Window 112 | 113 | % Uncoment the lines below for info about current plan and project 114 | % Do not delete, we might need this in the future 115 | %========================================================================== 116 | %Current_Plan= RC.CurrentPlanFile() 117 | %Current_Geometry_File= RC.CurrentGeomFile() 118 | %[lngNumProf,strProfileName]=RC.Output_GetProfiles(0,0) %Profiles names and todatl number 119 | 120 | %% Output Results 121 | XC_counter=0; 122 | % Extracts variable info from XS to Xs 123 | for i=1:lngNum_RS 124 | strNodeType{i}=RC.Geometry.NodeCType(lngRiverID,lngReachID,i); 125 | 126 | if strcmp(strNodeType{i},'')% An empty strings (i.e. ' ') denotes a cross section; 127 | XC_counter=XC_counter+1; 128 | % Here we assing the river station name to each node 129 | strRS{XC_counter} = RC.Geometry.NodeRS(lngRiverID,lngReachID,i); 130 | % Extracts average velocity of flow for the main channel 131 | sngVelChnl(XC_counter) = abs(RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 132 | lngProfile,lngVelChnl_ID)); 133 | % Extracts hydraulic depth in channel 134 | sngHydrDepthC(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 135 | lngProfile,lngHydrDepthC_ID); 136 | % Extracts flow in the main channel. 137 | sngQChannel(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 138 | lngProfile,lngQChannel_ID); 139 | % Extracts hydraulic radius in channel. 140 | sngHydrRadiusC(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 141 | lngProfile,lngHydrRadiusC_ID); 142 | % Extracts conveyance weighted Manning's n for the main channel. 143 | sngMannWtdChnl(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 144 | lngProfile,lngMannWtdChnl_ID); 145 | % Extracts conveyance weighted Manning's n for the main channel. 146 | sngLengthChnl(XC_counter) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 147 | lngProfile,lngLengthChnl_ID); 148 | % Extracts Water Surface Elevation at each XS 149 | %sngWS(i) = RC.Output_NodeOutput(lngRiverID,lngReachID,i,lngUpDn,... 150 | % lngProfile,lngWS_ID); 151 | end%if is a cross section 152 | 153 | end %for 154 | sngLengthChnl(end)=0; %There is not data of length channel for the last cell 155 | 156 | %% Generate Rivirinputfile dataset for the FluEgg model 157 | Riverinputfile=Generate_Rivirinputfile(); 158 | 159 | try 160 | %Kill Hec-ras 161 | !taskkill /im ras.exe 162 | RC.QuitRAS 163 | 164 | catch 165 | end 166 | delete(RC); 167 | 168 | 169 | 170 | %% ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 171 | function Riverinputfile=Generate_Rivirinputfile() 172 | CumlDistance=[0;cumsum(sngLengthChnl(1:end-1))/1000];%In km 173 | CumlDistance=[((CumlDistance(1:end-1)+CumlDistance(2:end))/2); CumlDistance(end)]; %FluEgg cells are located between 2 XS 174 | CellNumber=(1:1:lngNum_XS)'; 175 | ks=(8.1.*sngMannWtdChnl.*sqrt(9.81)).^6; 176 | Ustar=abs(sngVelChnl./(8.1*((sngHydrRadiusC./ks).^(1/6)))); 177 | %% Temperature choice 178 | Temperature=str2double(get(handles.Const_Temp(2),'String')); 179 | if isnan(Temperature) %If user didn't input temperature 180 | ed = errordlg('Please input temperature','Error'); 181 | set(ed, 'WindowStyle', 'modal'); 182 | uiwait(ed); 183 | return 184 | end 185 | Riverinputfile=[CellNumber CumlDistance sngHydrDepthC sngQChannel... 186 | sngVelChnl zeros(lngNum_XS,1) zeros(lngNum_XS,1) Ustar ... 187 | Temperature*ones(lngNum_XS,1)]; % default temperature 22C 188 | end 189 | %% ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 190 | 191 | end 192 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 193 | %% <<<<<<<<<<<<<<<<<<<<<<<<< END OF FUNCTION >>>>>>>>>>>>>>>>>>>>>>>>>>>>%% 194 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 195 | 196 | %% Notes: 197 | % When there is not data the controller puts a very large number: 3.39999995214436e+38 198 | -------------------------------------------------------------------------------- /snapshotPlotDt.m: -------------------------------------------------------------------------------- 1 | %%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 2 | %% Generate snapshot plot % 3 | %% Post-processing tools % 4 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 5 | %-------------------------------------------------------------------------% 6 | % This is a Sub-GUI of the results GUI, it is used inside FluEgg to % 7 | % generate the snapshot figure of eggs at a given DT. % 8 | %-------------------------------------------------------------------------% 9 | % % 10 | %-------------------------------------------------------------------------% 11 | % Created by : Tatiana Garcia % 12 | % Last Modified : July 15, 2016 % 13 | %-------------------------------------------------------------------------% 14 | % Copyright 2016 Tatiana Garcia 15 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 16 | function varargout = snapshotPlotDt(varargin) 17 | % Last Modified by GUIDE v2.5 15-Jul-2016 11:46:21 18 | 19 | % Begin initialization code - DO NOT EDIT 20 | gui_Singleton = 1; 21 | gui_State = struct('gui_Name', mfilename, ... 22 | 'gui_Singleton', gui_Singleton, ... 23 | 'gui_OpeningFcn', @snapshotPlotDt_OpeningFcn, ... 24 | 'gui_OutputFcn', @snapshotPlotDt_OutputFcn, ... 25 | 'gui_LayoutFcn', [] , ... 26 | 'gui_Callback', []); 27 | if nargin && ischar(varargin{1}) 28 | gui_State.gui_Callback = str2func(varargin{1}); 29 | end 30 | 31 | if nargout 32 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 33 | else 34 | gui_mainfcn(gui_State, varargin{:}); 35 | end 36 | end 37 | % End initialization code - DO NOT EDIT 38 | 39 | 40 | % --- Executes just before snapshotPlotDt is made visible. 41 | function snapshotPlotDt_OpeningFcn(hObject, ~, handles, varargin) 42 | diary('./results/FluEgg_LogFile.txt') 43 | handleResults=getappdata(0,'handleResults'); 44 | ResultsSim=getappdata(handleResults,'ResultsSim'); 45 | time=ResultsSim.time; 46 | T2_Hatching=ResultsSim.T2_Hatching; 47 | T2_Gas_bladder=ResultsSim.T2_Gas_bladder; 48 | %% Default values and options 49 | % If the user simulated until hatching time, diplay plot option 50 | if time(end)/3600>=T2_Hatching 51 | set(handles.Add_Hatching_Time,'Visible','on'); 52 | set(handles.Add_Hatching_Time,'Value',1); 53 | 54 | else 55 | set(handles.Add_Hatching_Time,'Visible','off'); 56 | end 57 | 58 | % If the user simulated until GBI stage, diplay plot option 59 | if time(end)/3600>=T2_Gas_bladder 60 | set(handles.Add_GBI,'Visible','on'); 61 | set(handles.Add_GBI,'Value',1); 62 | else 63 | set(handles.Add_Hatching_Time,'Visible','off'); 64 | end 65 | 66 | %set(handles.TimeStep_Snapshot,'String',round(10*time(end)/3600/10)/10) 67 | handles.output = hObject; 68 | guidata(hObject, handles); 69 | 70 | %Default selection of snapshot times 71 | if (time(end)/3600>=T2_Hatching)&&(time(end)/3600=T2_Gas_bladder 74 | set(handles.Snapshot_Time_Table,'Data',[0;1;round(T2_Hatching*10)/10;round(T2_Gas_bladder*10)/10]); 75 | end 76 | end 77 | 78 | % --- Outputs from this function are returned to the command line. 79 | function varargout = snapshotPlotDt_OutputFcn(~, ~, handles) 80 | diary off 81 | varargout{1} = handles.output; 82 | end 83 | 84 | function TimeStep_Snapshot_Callback(~, ~, handles) 85 | end 86 | 87 | function TimeStep_Snapshot_CreateFcn(hObject, ~, handles) 88 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 89 | set(hObject,'BackgroundColor','white'); 90 | end 91 | end 92 | 93 | % --- Executes on button press in SaveTimestep_button. 94 | function SaveTimestep_button_Callback(hObject, eventdata, handles) 95 | try 96 | SnapshotEvolution(hObject, eventdata, handles); 97 | catch 98 | handleResults=getappdata(0,'handleResults'); 99 | ResultsSim=getappdata(handleResults,'ResultsSim'); 100 | % TimeStep_Snapshot=str2double(get(handles.TimeStep_Snapshot,'String')); 101 | % if isnan(TimeStep_Snapshot) 102 | % msgbox('Empty input field. Please make sure all required fields are filled out correctly ','FluEgg Error: Empty fields','error'); 103 | % return 104 | % end 105 | %======================================================================== 106 | % Check for negative values 107 | Snapshot_Time_Table=get(handles.Snapshot_Time_Table,'Data'); 108 | if sum(Snapshot_Time_Table<0)>0 109 | msgbox('Incorrect negative or zero value. Please make sure all required fields are filled out correctly','FluEgg Error: Incorrect negative or zero value','error'); 110 | return 111 | end 112 | end 113 | diary off 114 | close(handles.figure1) 115 | end 116 | 117 | function SnapshotEvolution(~, ~, handles) 118 | handleResults=getappdata(0,'handleResults'); 119 | ResultsSim=getappdata(handleResults,'ResultsSim'); 120 | Snapshot_Time_Table=get(handles.Snapshot_Time_Table,'Data'); 121 | %TimeStep_Snapshot=str2double(get(handles.TimeStep_Snapshot,'String')); 122 | %% Getting results data 123 | X = ResultsSim.X; 124 | Z = ResultsSim.Z; 125 | time = ResultsSim.time; 126 | CumlDistance = double(ResultsSim.CumlDistance); 127 | Depth = double(ResultsSim.Depth); 128 | Xi = double(ResultsSim.Spawning(1,1));% in m 129 | Zi = double(ResultsSim.Spawning(1,3));% in m 130 | Dt=time(2)-time(1); 131 | T2_Hatching=ResultsSim.T2_Hatching; 132 | T2_Gas_bladder=ResultsSim.T2_Gas_bladder; 133 | 134 | %% Figure 135 | set(0,'Units','pixels') ; 136 | scnsize = get(0,'ScreenSize'); 137 | figure('Name','Evolution of a mass of Asian carp eggs','NumberTitle','off',... 138 | 'Menubar','figure','color','w','position',[8 scnsize(4)/2.6 scnsize(3)/2.1333 scnsize(4)/2]); 139 | subaxis(1,1,1,'MR',0.035,'ML',0.09,'MB',0.12,'MT',0.075); 140 | 141 | Legends=cell(1,length(Snapshot_Time_Table)); 142 | 143 | for i=1:length(Snapshot_Time_Table) 144 | t=Snapshot_Time_Table(i)*3600; %Time in seconds 145 | if t==0 146 | scatter((X(round(t/Dt+1),:)/1000),Z(round(t/Dt+1),:),30,'filled'); 147 | hold all 148 | else 149 | if tMaxX,1,'first'); 170 | xlim([xticks(minxtick) xticks(maxxtick)]) 171 | ylim([-max(Depth)-0.15 0]) 172 | set(gca,'XMinorTick','on') 173 | No=length(Depth); 174 | 175 | %% Text 176 | text(Xi/1000-CumlDistance(end)*0.007,Zi+Depth(end)*0.028, '\downarrow','FontWeight','bold','FontName','Arial') 177 | text(Xi/1000-CumlDistance(end)*0.04,Zi+Depth(end)*0.07, 'Fish spawn here','FontWeight','normal','FontName','Arial') 178 | text(MaxX/2.4,0.08,'Water surface','FontWeight','normal','FontName','Arial') 179 | text(MaxX*0.9,-Depth(end)*0.95,'\downarrow','FontWeight','bold','FontName','Arial');%,'FontSize',20 180 | text(MaxX*0.9,-Depth(end)*0.9, 'River bed','FontWeight','normal','FontName','Arial') 181 | 182 | %% Cell labels ON-OFF 183 | label_on=get(handles.Labelcheckbox,'Value'); 184 | 185 | if label_on==1 186 | 187 | for i=1:length(CumlDistance) 188 | if i==1 189 | text(CumlDistance(i)/5.5,-Depth(i)*1.03,texlabel(num2str(i)),'FontWeight','normal','FontName','Arial','FontSize',8) 190 | else 191 | text(CumlDistance(i)-(CumlDistance(i)-CumlDistance(i-1))/1.1,-Depth(i)*1.03,texlabel(num2str(i)),'FontWeight','normal','FontName','Arial','FontSize',8) 192 | end 193 | end 194 | text(CumlDistance(1)/3,-Depth(1)*2.5,texlabel('Cell #'),'FontWeight','normal','FontName','Arial','FontSize',8) 195 | 196 | end 197 | diary off 198 | end 199 | 200 | % --- Executes on button press in Add_GBI. 201 | function Add_GBI_Callback(hObject, eventdata, handles) 202 | handleResults=getappdata(0,'handleResults'); 203 | ResultsSim=getappdata(handleResults,'ResultsSim'); 204 | T2_Hatching=ResultsSim.T2_Hatching; 205 | T2_Gas_bladder=ResultsSim.T2_Gas_bladder; 206 | time=ResultsSim.time; 207 | GBI_switch=get(handles.Add_GBI,'Value'); 208 | Snapshot_Time_Table=get(handles.Snapshot_Time_Table,'Data'); 209 | if GBI_switch==0 210 | if time(end)>=T2_Hatching 211 | set(handles.Snapshot_Time_Table,'Data',[0;1;fix(T2_Hatching/2);round(T2_Hatching*10)/10]); 212 | end 213 | elseif GBI_switch==1&&time(end)>=T2_Gas_bladder 214 | set(handles.Snapshot_Time_Table,'Data',[0;1;round(T2_Hatching*10)/10;round(T2_Gas_bladder*10)/10]); 215 | end 216 | end 217 | 218 | 219 | % --- Executes on button press in Add_Hatching_Time. 220 | function Add_Hatching_Time_Callback(hObject, eventdata, handles) 221 | handleResults=getappdata(0,'handleResults'); 222 | ResultsSim=getappdata(handleResults,'ResultsSim'); 223 | T2_Hatching=ResultsSim.T2_Hatching; 224 | T2_Gas_bladder=ResultsSim.T2_Gas_bladder; 225 | time=ResultsSim.time; 226 | Hatching_switch=get(handles.Add_Hatching_Time,'Value'); 227 | Snapshot_Time_Table=get(handles.Snapshot_Time_Table,'Data'); 228 | if Hatching_switch==1 229 | if time(end)>=T2_Hatching 230 | id=find(Snapshot_Time_Table==T2_Hatching,1,'first'); 231 | if isempty(id) 232 | set(handles.Snapshot_Time_Table,'Data',sort([Snapshot_Time_Table;round(T2_Hatching*10)/10])); 233 | end 234 | end 235 | end 236 | end 237 | 238 | % --- Executes on button press in Add_snapshot. 239 | function Add_snapshot_Callback(hObject, eventdata, handles) 240 | Add_snapshot=get(hObject,'Value'); 241 | Snapshot_Time_Table=get(handles.Snapshot_Time_Table,'Data'); 242 | if Add_snapshot==1 243 | set(handles.Snapshot_Time_Table,'Data',[Snapshot_Time_Table;NaN]); 244 | end 245 | set(handles.Add_snapshot,'Value',0); 246 | end 247 | 248 | 249 | % --- Executes on button press in clear_table. 250 | function clear_table_Callback(hObject, eventdata, handles) 251 | clear_table=get(hObject,'Value'); 252 | if clear_table==1 253 | set(handles.Snapshot_Time_Table,'Data',0); 254 | end 255 | % Unselect options 256 | set(handles.Add_Hatching_Time,'Value',0); 257 | set(handles.Add_GBI,'Value',0); 258 | set(handles.Add_snapshot,'Value',0); 259 | end 260 | -------------------------------------------------------------------------------- /Egg_vertical_concentration.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | %%%:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 20 | %% Egg vertical concentration distribution % 21 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 22 | %-------------------------------------------------------------------------% 23 | % This function is part of the post-processing tools included in FluEgg. % 24 | % This tool is used to generate a vertical concentration distribution of % 25 | % eggs at a given downstream distance % 26 | %-------------------------------------------------------------------------% 27 | % % 28 | %-------------------------------------------------------------------------% 29 | % Created by : Tatiana Garcia % 30 | % Last Modified : May 31, 2016 % 31 | %-------------------------------------------------------------------------% 32 | % 33 | %:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::% 34 | function varargout = Egg_vertical_concentration(varargin) 35 | % EGG_VERTICAL_CONCENTRATION MATLAB code for Egg_vertical_concentration.fig 36 | % 37 | % Last Modified by GUIDE v2.5 05-Aug-2013 14:19:10 38 | 39 | % Begin initialization code - DO NOT EDIT 40 | gui_Singleton = 1; 41 | gui_State = struct('gui_Name', mfilename, ... 42 | 'gui_Singleton', gui_Singleton, ... 43 | 'gui_OpeningFcn', @Egg_vertical_concentration_OpeningFcn, ... 44 | 'gui_OutputFcn', @Egg_vertical_concentration_OutputFcn, ... 45 | 'gui_LayoutFcn', [] , ... 46 | 'gui_Callback', []); 47 | if nargin && ischar(varargin{1}) 48 | gui_State.gui_Callback = str2func(varargin{1}); 49 | end 50 | 51 | if nargout 52 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 53 | else 54 | gui_mainfcn(gui_State, varargin{:}); 55 | end 56 | % End initialization code - DO NOT EDIT 57 | 58 | %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 59 | function Egg_vertical_concentration_OpeningFcn(hObject, ~, handles, varargin) 60 | diary('./results/FluEgg_LogFile.txt') 61 | axes(handles.bottom); imshow('asiancarp.png'); 62 | %% Loads results 63 | handleResults = getappdata(0,'handleResults'); 64 | ResultsSim = getappdata(handleResults,'ResultsSim'); 65 | CumlDistance = ResultsSim.CumlDistance; 66 | Depth = ResultsSim.Depth; 67 | % populate default parameters 68 | set(handles.X_editBox,'String',round(CumlDistance(end)/2)); 69 | set(handles.Nlayers_editBox,'String',7); 70 | %% Get user input data from current GUI 71 | Dist_X = str2double(get(handles.X_editBox,'String'))*1000;% It is in km and then we convert it to m 72 | Nlayers = str2double(get(handles.Nlayers_editBox,'String')); 73 | cell = find((CumlDistance)*1000>=Dist_X);cell=cell(1); 74 | % 75 | H = Depth(cell); 76 | Nodes = 0:-H/(Nlayers):-H; 77 | Nodes = Nodes'; 78 | set(handles.LayerNodes_table,'Data',[Nodes (Nodes+H)/H]);%Nodes of the layers in model coordinates 79 | %% 80 | handles.output = hObject; 81 | handles.update = 0; 82 | guidata(hObject, handles); 83 | 84 | function Egg_Vertical_Concentration_Distribution(hObject, eventdata, handles) 85 | 86 | %% This function divides the water depth into layers and gets the nodes table 87 | %% From Results Gui 88 | handleResults = getappdata(0,'handleResults'); 89 | ResultsSim = getappdata(handleResults,'ResultsSim'); 90 | CumlDistance = ResultsSim.CumlDistance; 91 | Depth = ResultsSim.Depth; 92 | Nlayers = str2double(get(handles.Nlayers_editBox,'String')); 93 | 94 | %% From Current Gui 95 | Dist_X = str2double(get(handles.X_editBox,'String'))*1000;% It is in km and then we convert it to m 96 | % display error if distance is outside of domain 97 | if Dist_X>CumlDistance(end)*1000 98 | ed = errordlg('The longitudinal distance you input is out of the domain','Error'); 99 | set(ed, 'WindowStyle', 'modal'); 100 | uiwait(ed); 101 | end 102 | 103 | % Find cell corresponding to selected distance 104 | cell = find((CumlDistance)*1000>=Dist_X);cell=cell(1); 105 | H = Depth(cell); 106 | 107 | %% If user wants to add additional nodes to layers. 108 | if handles.update==0 109 | if handles.eddit==1 %if we need to add an extra node 110 | Nodes = get(handles.LayerNodes_table,'Data');Nodes=Nodes(:,1); 111 | extra = str2double(get(handles.ExtraNode_editBox,'String')); 112 | Nodes = [extra; Nodes]; 113 | else 114 | Nodes = 0:-H/(Nlayers):-H; 115 | Nodes = Nodes'; 116 | end 117 | else %handles.update==1 Ïf the table is eddited please update the Nodes 118 | Nodes = get(handles.LayerNodes_table,'Data');Nodes=Nodes(:,1); 119 | end 120 | 121 | Nodes = sort(Nodes,'ascend'); 122 | sortedNodes = sort(Nodes,'descend'); 123 | set(handles.LayerNodes_table,'Data',[sortedNodes (sortedNodes+H)/H]);%Nodes of the layers in model coordinates 124 | Nodes = get(handles.LayerNodes_table,'Data'); 125 | 126 | function Plot_Vertical_Distribution(hObject, eventdata, handles) 127 | % This function generates the plot of the vertical concentration 128 | % distribution 129 | %% Error checking========================================================== 130 | if isempty(str2double(get(handles.X_editBox,'String')))||isempty(str2double(get(handles.Nlayers_editBox,'String')))||isnan(str2double(get(handles.X_editBox,'String')))||isnan(str2double(get(handles.Nlayers_editBox,'String'))) 131 | msgbox('Empty input field. Please make sure all required fields are filled out correctly ','FluEgg Error: Empty fields','error'); 132 | return 133 | end 134 | if str2double(get(handles.X_editBox,'String'))<=0||str2double(get(handles.Nlayers_editBox,'String'))<=0 135 | msgbox('Incorrect negative or zero value. Please make sure all required fields are filled out correctly','FluEgg Error: Incorrect negative or zero value','error'); 136 | return 137 | end 138 | %========================================================================== 139 | %% From results GUI 140 | handleResults = getappdata(0,'handleResults'); 141 | ResultsSim = getappdata(handleResults,'ResultsSim'); 142 | CumlDistance = ResultsSim.CumlDistance; 143 | Depth = ResultsSim.Depth; 144 | X = ResultsSim.X; 145 | Z = ResultsSim.Z; 146 | %% Input data from current GUI 147 | Nodes = get(handles.LayerNodes_table,'Data'); 148 | Dist_X = str2double(get(handles.X_editBox,'String'))*1000; 149 | cell = find((CumlDistance)*1000>=Dist_X);cell=cell(1); 150 | H = Depth(cell); 151 | %% 152 | c = 0; 153 | [~,b] = size(X); 154 | check = 0; 155 | %% Have all the eggs arrive to distance X??? 156 | for i=1:b 157 | tind=find(X(:,i)>=Dist_X); 158 | if length(tind)>=1 159 | tind = tind(1); 160 | c = c+1; 161 | Z_Dist_X(c) = Z(tind,i); 162 | check = check+1; 163 | end 164 | end 165 | 166 | %% Display error if not all the eggs arrived to distance selected by user 167 | if check==0 168 | ed = errordlg('No eggs have arrived downstream distance X, please check the egg vertical distribution closer to the spawning location or run the model for a longer time','Error'); 169 | set(ed, 'WindowStyle', 'modal'); 170 | uiwait(ed); 171 | else 172 | z_over_H = Nodes; 173 | z_over_H = z_over_H(:,2); 174 | z_over_H = sort(z_over_H,'ascend'); 175 | Nodes = sort(Nodes(:,1),'ascend'); 176 | z_o_H_midd = z_over_H(1:end-1)+(diff(z_over_H)/2);%in dimensionless form z/H middle points 177 | hightLayers = [abs(diff(Nodes))];%in m 178 | N = histc(Z_Dist_X,Nodes); 179 | N = N(1:end-1)'; 180 | %% 181 | Cy = (N./hightLayers)*100; 182 | Cavg = sum(N)/H; 183 | CyCavg = Cy./Cavg; 184 | Vertdist = [z_o_H_midd CyCavg]; 185 | %% Saving results as .mat 186 | handleResults = getappdata(0,'handleResults'); 187 | fullpath_result = getappdata(handleResults,'fullpath_result'); 188 | save(fullpath_result,'Vertdist','-mat','-append'); 189 | %% Saving results as text file 190 | handleResults = getappdata(0,'handleResults'); 191 | pathname = getappdata(handleResults,'pathname'); 192 | hdr = {'Z/H','Log Cz/Cavg'}; 193 | dlmwrite([pathname,'VertDist' '.txt'],[sprintf('%s\t',hdr{:}) ''],''); 194 | dlmwrite([pathname,'VertDist' '.txt'],Vertdist,'-append','delimiter','\t','precision', 6); 195 | %% 196 | %if Batch==0 % in case of batch processing 197 | set(0,'Units','pixels') ; 198 | scnsize = get(0,'ScreenSize'); 199 | figure('Name','Egg vertical concentration distribution','Color',[1 1 1],... 200 | 'position',[8 scnsize(4)/2.6 scnsize(3)/2.1333 scnsize(4)/2]); 201 | subaxis(1,1,1,'MR',0.035,'ML',0.09,'MB',0.13,'MT',0.075); 202 | semilogx(CyCavg,z_o_H_midd,'MarkerFaceColor',[0 0 0],'MarkerSize',5,... 203 | 'Marker','square','LineWidth',2,'LineStyle','--','Color',[0 0 0]); 204 | xlim([1 500]) 205 | ylim([0 1]) 206 | set(gca,'XTick',[0 10 50 100 500],'XTickLabel',[0 10 50 100 500]); 207 | xlabel('log C_z/C [%]'); 208 | ylabel('z/h+1'); 209 | legend('FluEgg simulation','Location','NorthWest') 210 | %% Grid ON-OFF 211 | gridon = get(handles.Grid_on_checkbox,'Value'); %Need to comment this for now 212 | if gridon==1 213 | grid on 214 | else 215 | grid off 216 | end 217 | %% Message 218 | h = msgbox([num2str(sum(N)) ' eggs passed by ' num2str(Dist_X/1000) ' km downstream from the virtual spawning location during the simulation time'],'FluEgg Message'); 219 | diary off 220 | end 221 | close(handles.figure1); 222 | 223 | function varargout = Egg_vertical_concentration_OutputFcn(~, ~, handles) 224 | diary off 225 | varargout{1} = handles.output; 226 | 227 | function X_editBox_Callback(hObject,eventdata, handles) 228 | handles.eddit = 0; 229 | Egg_Vertical_Concentration_Distribution(hObject, eventdata, handles); 230 | 231 | function X_editBox_CreateFcn(hObject, eventdata, handles) 232 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 233 | set(hObject,'BackgroundColor','white'); 234 | end 235 | 236 | function Nlayers_editBox_Callback(hObject, eventdata, handles) 237 | handles.eddit = 0; 238 | Egg_Vertical_Concentration_Distribution(hObject, eventdata, handles); 239 | guidata(hObject, handles); 240 | 241 | function Nlayers_editBox_CreateFcn(hObject, eventdata, handles) 242 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 243 | set(hObject,'BackgroundColor','white'); 244 | end 245 | 246 | function ExtraNode_editBox_Callback(hObject, eventdata, handles) 247 | function ExtraNode_editBox_CreateFcn(hObject, eventdata, handles) 248 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 249 | set(hObject,'BackgroundColor','white'); 250 | end 251 | 252 | function Plot_button_Callback(hObject, eventdata, handles) 253 | Plot_Vertical_Distribution(hObject, eventdata, handles) 254 | 255 | function Grid_on_checkbox_Callback(hObject, eventdata, handles) 256 | 257 | %If user eddits the table, for example add an additional node 258 | function AddNode_button_Callback(hObject, eventdata, handles) 259 | handles.eddit = 1; 260 | Egg_Vertical_Concentration_Distribution(hObject, eventdata, handles); 261 | guidata(hObject, handles); 262 | 263 | function LayerNodes_table_CellEditCallback(hObject, eventdata, handles) 264 | handles.update = 1; 265 | Egg_Vertical_Concentration_Distribution(hObject, eventdata, handles); 266 | -------------------------------------------------------------------------------- /interparc.m: -------------------------------------------------------------------------------- 1 | function [pt,dudt,fofthandle] = interparc(t,px,py,varargin) 2 | % interparc: interpolate points along a curve in 2 or more dimensions 3 | % usage: pt = interparc(t,px,py) % a 2-d curve 4 | % usage: pt = interparc(t,px,py,pz) % a 3-d curve 5 | % usage: pt = interparc(t,px,py,pz,pw,...) % a 4-d or higher dimensional curve 6 | % usage: pt = interparc(t,px,py,method) % a 2-d curve, method is specified 7 | % usage: [pt,dudt,fofthandle] = interparc(t,px,py,...) % also returns derivatives, and a function handle 8 | % 9 | % Interpolates new points at any fractional point along 10 | % the curve defined by a list of points in 2 or more 11 | % dimensions. The curve may be defined by any sequence 12 | % of non-replicated points. 13 | % 14 | % arguments: (input) 15 | % t - vector of numbers, 0 <= t <= 1, that define 16 | % the fractional distance along the curve to 17 | % interpolate the curve at. t = 0 will generate 18 | % the very first point in the point list, and 19 | % t = 1 yields the last point in that list. 20 | % Similarly, t = 0.5 will yield the mid-point 21 | % on the curve in terms of arc length as the 22 | % curve is interpolated by a parametric spline. 23 | % 24 | % If t is a scalar integer, at least 2, then 25 | % it specifies the number of equally spaced 26 | % points in arclength to be generated along 27 | % the curve. 28 | % 29 | % px, py, pz, ... - vectors of length n, defining 30 | % points along the curve. n must be at least 2. 31 | % Exact Replicate points should not be present 32 | % in the curve, although there is no constraint 33 | % that the curve has replicate independent 34 | % variables. 35 | % 36 | % method - (OPTIONAL) string flag - denotes the method 37 | % used to compute the points along the curve. 38 | % 39 | % method may be any of 'linear', 'spline', or 'pchip', 40 | % or any simple contraction thereof, such as 'lin', 41 | % 'sp', or even 'p'. 42 | % 43 | % method == 'linear' --> Uses a linear chordal 44 | % approximation to interpolate the curve. 45 | % This method is the most efficient. 46 | % 47 | % method == 'pchip' --> Uses a parametric pchip 48 | % approximation for the interpolation 49 | % in arc length. 50 | % 51 | % method == 'spline' --> Uses a parametric spline 52 | % approximation for the interpolation in 53 | % arc length. Generally for a smooth curve, 54 | % this method may be most accurate. 55 | % 56 | % method = 'csape' --> if available, this tool will 57 | % allow a periodic spline fit for closed curves. 58 | % ONLY use this method if your points should 59 | % represent a closed curve. 60 | % 61 | % If the last point is NOT the same as the 62 | % first point on the curve, then the curve 63 | % will be forced to be periodic by this option. 64 | % That is, the first point will be replicated 65 | % onto the end. 66 | % 67 | % If csape is not present in your matlab release, 68 | % then an error will result. 69 | % 70 | % DEFAULT: 'spline' 71 | % 72 | % 73 | % arguments: (output) 74 | % pt - Interpolated points at the specified fractional 75 | % distance (in arc length) along the curve. 76 | % 77 | % dudt - when a second return argument is required, 78 | % interparc will return the parametric derivatives 79 | % (dx/dt, dy/dt, dz/dt, ...) as an array. 80 | % 81 | % fofthandle - a function handle, taking numbers in the interval [0,1] 82 | % and evaluating the function at those points. 83 | % 84 | % Extrapolation will not be permitted by this call. 85 | % Any values of t that lie outside of the interval [0,1] 86 | % will be clipped to the endpoints of the curve. 87 | % 88 | % Example: 89 | % % Interpolate a set of unequally spaced points around 90 | % % the perimeter of a unit circle, generating equally 91 | % % spaced points around the perimeter. 92 | % theta = sort(rand(15,1))*2*pi; 93 | % theta(end+1) = theta(1); 94 | % px = cos(theta); 95 | % py = sin(theta); 96 | % 97 | % % interpolate using parametric splines 98 | % pt = interparc(100,px,py,'spline'); 99 | % 100 | % % Plot the result 101 | % plot(px,py,'r*',pt(:,1),pt(:,2),'b-o') 102 | % axis([-1.1 1.1 -1.1 1.1]) 103 | % axis equal 104 | % grid on 105 | % xlabel X 106 | % ylabel Y 107 | % title 'Points in blue are uniform in arclength around the circle' 108 | % 109 | % 110 | % Example: 111 | % % For the previous set of points, generate exactly 6 112 | % % points around the parametric splines, verifying 113 | % % the uniformity of the arc length interpolant. 114 | % pt = interparc(6,px,py,'spline'); 115 | % 116 | % % Convert back to polar form. See that the radius 117 | % % is indeed 1, quite accurately. 118 | % [TH,R] = cart2pol(pt(:,1),pt(:,2)) 119 | % % TH = 120 | % % 0.86005 121 | % % 2.1141 122 | % % -2.9117 123 | % % -1.654 124 | % % -0.39649 125 | % % 0.86005 126 | % % R = 127 | % % 1 128 | % % 0.9997 129 | % % 0.9998 130 | % % 0.99999 131 | % % 1.0001 132 | % % 1 133 | % 134 | % % Unwrap the polar angles, and difference them. 135 | % diff(unwrap(TH)) 136 | % % ans = 137 | % % 1.2541 138 | % % 1.2573 139 | % % 1.2577 140 | % % 1.2575 141 | % % 1.2565 142 | % 143 | % % Six points around the circle should be separated by 144 | % % 2*pi/5 radians, if they were perfectly uniform. The 145 | % % slight differences are due to the imperfect accuracy 146 | % % of the parametric splines. 147 | % 2*pi/5 148 | % % ans = 149 | % % 1.2566 150 | % 151 | % 152 | % See also: arclength, spline, pchip, interp1 153 | % 154 | % Author: John D'Errico 155 | % e-mail: woodchips@rochester.rr.com 156 | % Release: 1.0 157 | % Release date: 3/15/2010 158 | 159 | % unpack the arguments and check for errors 160 | if nargin < 3 161 | error('ARCLENGTH:insufficientarguments', ... 162 | 'at least t, px, and py must be supplied') 163 | end 164 | 165 | t = t(:); 166 | if (numel(t) == 1) && (t > 1) && (rem(t,1) == 0) 167 | % t specifies the number of points to be generated 168 | % equally spaced in arclength 169 | t = linspace(0,1,t)'; 170 | elseif any(t < 0) || any(t > 1) 171 | error('ARCLENGTH:impropert', ... 172 | 'All elements of t must be 0 <= t <= 1') 173 | end 174 | 175 | % how many points will be interpolated? 176 | nt = numel(t); 177 | 178 | % the number of points on the curve itself 179 | px = px(:); 180 | py = py(:); 181 | n = numel(px); 182 | 183 | % are px and py both vectors of the same length? 184 | if ~isvector(px) || ~isvector(py) || (length(py) ~= n) 185 | error('ARCLENGTH:improperpxorpy', ... 186 | 'px and py must be vectors of the same length') 187 | elseif n < 2 188 | error('ARCLENGTH:improperpxorpy', ... 189 | 'px and py must be vectors of length at least 2') 190 | end 191 | 192 | % compose px and py into a single array. this way, 193 | % if more dimensions are provided, the extension 194 | % is trivial. 195 | pxy = [px,py]; 196 | ndim = 2; 197 | 198 | % the default method is 'linear' 199 | method = 'spline'; 200 | 201 | % are there any other arguments? 202 | if nargin > 3 203 | % there are. check the last argument. Is it a string? 204 | if ischar(varargin{end}) 205 | method = varargin{end}; 206 | varargin(end) = []; 207 | 208 | % method may be any of {'linear', 'pchip', 'spline', 'csape'.} 209 | % any any simple contraction thereof. 210 | valid = {'linear', 'pchip', 'spline', 'csape'}; 211 | [method,errstr] = validstring(method,valid); 212 | if ~isempty(errstr) 213 | error('INTERPARC:incorrectmethod',errstr) 214 | end 215 | end 216 | 217 | % anything that remains in varargin must add 218 | % an additional dimension on the curve/polygon 219 | for i = 1:numel(varargin) 220 | pz = varargin{i}; 221 | pz = pz(:); 222 | if numel(pz) ~= n 223 | error('ARCLENGTH:improperpxorpy', ... 224 | 'pz must be of the same size as px and py') 225 | end 226 | pxy = [pxy,pz]; %#ok 227 | end 228 | 229 | % the final number of dimensions provided 230 | ndim = size(pxy,2); 231 | end 232 | 233 | % if csape, then make sure the first point is replicated at the end. 234 | % also test to see if csape is available 235 | if method(1) == 'c' 236 | if exist('csape','file') == 0 237 | error('CSAPE was requested, but you lack the necessary toolbox.') 238 | end 239 | 240 | p1 = pxy(1,:); 241 | pend = pxy(end,:); 242 | 243 | % get a tolerance on whether the first point is replicated. 244 | if norm(p1 - pend) > 10*eps(norm(max(abs(pxy),[],1))) 245 | % the two end points were not identical, so wrap the curve 246 | pxy(end+1,:) = p1; 247 | nt = nt + 1; 248 | end 249 | end 250 | 251 | % preallocate the result, pt 252 | pt = NaN(nt,ndim); 253 | 254 | % Compute the chordal (linear) arclength 255 | % of each segment. This will be needed for 256 | % any of the methods. 257 | chordlen = sqrt(sum(diff(pxy,[],1).^2,2)); 258 | 259 | % Normalize the arclengths to a unit total 260 | chordlen = chordlen/sum(chordlen); 261 | 262 | % cumulative arclength 263 | cumarc = [0;cumsum(chordlen)]; 264 | 265 | % The linear interpolant is trivial. do it as a special case 266 | if method(1) == 'l' 267 | % The linear method. 268 | 269 | % which interval did each point fall in, in 270 | % terms of t? 271 | [junk,tbins] = histc(t,cumarc); %#ok 272 | 273 | % catch any problems at the ends 274 | tbins((tbins <= 0) | (t <= 0)) = 1; 275 | tbins((tbins >= n) | (t >= 1)) = n - 1; 276 | 277 | % interpolate 278 | s = (t - cumarc(tbins))./chordlen(tbins); 279 | % be nice, and allow the code to work on older releases 280 | % that don't have bsxfun 281 | pt = pxy(tbins,:) + (pxy(tbins+1,:) - pxy(tbins,:)).*repmat(s,1,ndim); 282 | 283 | % do we need to compute derivatives here? 284 | if nargout > 1 285 | dudt = (pxy(tbins+1,:) - pxy(tbins,:))./repmat(chordlen(tbins),1,ndim); 286 | end 287 | 288 | % do we need to create the spline as a piecewise linear function? 289 | if nargout > 2 290 | spl = cell(1,ndim); 291 | for i = 1:ndim 292 | coefs = [diff(pxy(:,i))./diff(cumarc),pxy(1:(end-1),i)]; 293 | spl{i} = mkpp(cumarc.',coefs); 294 | end 295 | 296 | %create a function handle for evaluation, passing in the splines 297 | fofthandle = @(t) foft(t,spl); 298 | end 299 | 300 | % we are done at this point 301 | return 302 | end 303 | 304 | % If we drop down to here, we have either a spline 305 | % or csape or pchip interpolant to work with. 306 | 307 | % compute parametric splines 308 | spl = cell(1,ndim); 309 | spld = spl; 310 | diffarray = [3 0 0;0 2 0;0 0 1;0 0 0]; 311 | for i = 1:ndim 312 | switch method 313 | case 'pchip' 314 | spl{i} = pchip(cumarc,pxy(:,i)); 315 | case 'spline' 316 | spl{i} = spline(cumarc,pxy(:,i)); 317 | nc = numel(spl{i}.coefs); 318 | if nc < 4 319 | % just pretend it has cubic segments 320 | spl{i}.coefs = [zeros(1,4-nc),spl{i}.coefs]; 321 | spl{i}.order = 4; 322 | end 323 | case 'csape' 324 | % csape was specified, so the curve is presumed closed, 325 | % therefore periodic 326 | spl{i} = csape(cumarc,pxy(:,i),'periodic'); 327 | nc = numel(spl{i}.coefs); 328 | if nc < 4 329 | % just pretend it has cubic segments 330 | spl{i}.coefs = [zeros(1,4-nc),spl{i}.coefs]; 331 | spl{i}.order = 4; 332 | end 333 | end 334 | 335 | % and now differentiate them 336 | xp = spl{i}; 337 | xp.coefs = xp.coefs*diffarray; 338 | xp.order = 3; 339 | spld{i} = xp; 340 | end 341 | 342 | % catch the case where there were exactly three points 343 | % in the curve, and spline was used to generate the 344 | % interpolant. In this case, spline creates a curve with 345 | % only one piece, not two. 346 | if (numel(cumarc) == 3) && (method(1) == 's') 347 | cumarc = spl{1}.breaks; 348 | n = numel(cumarc); 349 | chordlen = sum(chordlen); 350 | end 351 | 352 | % Generate the total arclength along the curve 353 | % by integrating each segment and summing the 354 | % results. The integration scheme does its job 355 | % using an ode solver. 356 | 357 | % polyarray here contains the derivative polynomials 358 | % for each spline in a given segment 359 | polyarray = zeros(ndim,3); 360 | seglen = zeros(n-1,1); 361 | 362 | % options for ode45 363 | opts = odeset('reltol',1.e-9); 364 | for i = 1:spl{1}.pieces 365 | % extract polynomials for the derivatives 366 | for j = 1:ndim 367 | polyarray(j,:) = spld{j}.coefs(i,:); 368 | end 369 | 370 | % integrate the arclength for the i'th segment 371 | % using ode45 for the integral. I could have 372 | % done this part with quad too, but then it 373 | % would not have been perfectly (numerically) 374 | % consistent with the next operation in this tool. 375 | [tout,yout] = ode45(@(t,y) segkernel(t,y),[0,chordlen(i)],0,opts); %#ok 376 | seglen(i) = yout(end); 377 | end 378 | 379 | % and normalize the segments to have unit total length 380 | totalsplinelength = sum(seglen); 381 | cumseglen = [0;cumsum(seglen)]; 382 | 383 | % which interval did each point fall into, in 384 | % terms of t, but relative to the cumulative 385 | % arc lengths along the parametric spline? 386 | [junk,tbins] = histc(t*totalsplinelength,cumseglen); %#ok 387 | 388 | % catch any problems at the ends 389 | tbins((tbins <= 0) | (t <= 0)) = 1; 390 | tbins((tbins >= n) | (t >= 1)) = n - 1; 391 | 392 | % Do the fractional integration within each segment 393 | % for the interpolated points. t is the parameter 394 | % used to define the splines. It is defined in terms 395 | % of a linear chordal arclength. This works nicely when 396 | % a linear piecewise interpolant was used. However, 397 | % what is asked for is an arclength interpolation 398 | % in terms of arclength of the spline itself. Call s 399 | % the arclength traveled along the spline. 400 | s = totalsplinelength*t; 401 | 402 | % the ode45 options will now include an events property 403 | % so we can catch zero crossings. 404 | opts = odeset('reltol',1.e-9,'events',@ode_events); 405 | 406 | ti = t; 407 | for i = 1:nt 408 | % si is the piece of arc length that we will look 409 | % for in this spline segment. 410 | si = s(i) - cumseglen(tbins(i)); 411 | 412 | % extract polynomials for the derivatives 413 | % in the interval the point lies in 414 | for j = 1:ndim 415 | polyarray(j,:) = spld{j}.coefs(tbins(i),:); 416 | end 417 | 418 | % we need to integrate in t, until the integral 419 | % crosses the specified value of si. Because we 420 | % have defined totalsplinelength, the lengths will 421 | % be normalized at this point to a unit length. 422 | % 423 | % Start the ode solver at -si, so we will just 424 | % look for an event where y crosses zero. 425 | [tout,yout,te,ye] = ode45(@(t,y) segkernel(t,y),[0,chordlen(tbins(i))],-si,opts); %#ok 426 | 427 | % we only need that point where a zero crossing occurred 428 | % if no crossing was found, then we can look at each end. 429 | if ~isempty(te) 430 | ti(i) = te(1) + cumarc(tbins(i)); 431 | else 432 | % a crossing must have happened at the very 433 | % beginning or the end, and the ode solver 434 | % missed it, not trapping that event. 435 | if abs(yout(1)) < abs(yout(end)) 436 | % the event must have been at the start. 437 | ti(i) = tout(1) + cumarc(tbins(i)); 438 | else 439 | % the event must have been at the end. 440 | ti(i) = tout(end) + cumarc(tbins(i)); 441 | end 442 | end 443 | end 444 | 445 | % Interpolate the parametric splines at ti to get 446 | % our interpolated value. 447 | for L = 1:ndim 448 | pt(:,L) = ppval(spl{L},ti); 449 | end 450 | 451 | % do we need to compute first derivatives here at each point? 452 | if nargout > 1 453 | dudt = zeros(nt,ndim); 454 | for L = 1:ndim 455 | dudt(:,L) = ppval(spld{L},ti); 456 | end 457 | end 458 | 459 | % create a function handle for evaluation, passing in the splines 460 | if nargout > 2 461 | fofthandle = @(t) foft(t,spl); 462 | end 463 | 464 | % =============================================== 465 | % nested function for the integration kernel 466 | % =============================================== 467 | function val = segkernel(t,y) %#ok 468 | % sqrt((dx/dt)^2 + (dy/dt)^2 + ...) 469 | val = zeros(size(t)); 470 | for k = 1:ndim 471 | val = val + polyval(polyarray(k,:),t).^2; 472 | end 473 | val = sqrt(val); 474 | 475 | end % function segkernel 476 | 477 | % =============================================== 478 | % nested function for ode45 integration events 479 | % =============================================== 480 | function [value,isterminal,direction] = ode_events(t,y) %#ok 481 | % ode event trap, looking for zero crossings of y. 482 | value = y; 483 | isterminal = ones(size(y)); 484 | direction = ones(size(y)); 485 | end % function ode_events 486 | 487 | end % mainline - interparc 488 | 489 | 490 | % =============================================== 491 | % end mainline - interparc 492 | % =============================================== 493 | % begin subfunctions 494 | % =============================================== 495 | 496 | % =============================================== 497 | % subfunction for evaluation at any point externally 498 | % =============================================== 499 | function f_t = foft(t,spl) 500 | % tool allowing the user to evaluate the interpolant at any given point for any values t in [0,1] 501 | pdim = numel(spl); 502 | f_t = zeros(numel(t),pdim); 503 | 504 | % convert t to a column vector, clipping it to [0,1] as we do. 505 | t = max(0,min(1,t(:))); 506 | 507 | % just loop over the splines in the cell array of splines 508 | for i = 1:pdim 509 | f_t(:,i) = ppval(spl{i},t); 510 | end 511 | end % function foft 512 | 513 | 514 | function [str,errorclass] = validstring(arg,valid) 515 | % validstring: compares a string against a set of valid options 516 | % usage: [str,errorclass] = validstring(arg,valid) 517 | % 518 | % If a direct hit, or any unambiguous shortening is found, that 519 | % string is returned. Capitalization is ignored. 520 | % 521 | % arguments: (input) 522 | % arg - character string, to be tested against a list 523 | % of valid choices. Capitalization is ignored. 524 | % 525 | % valid - cellstring array of alternative choices 526 | % 527 | % Arguments: (output) 528 | % str - string - resulting choice resolved from the 529 | % list of valid arguments. If no unambiguous 530 | % choice can be resolved, then str will be empty. 531 | % 532 | % errorclass - string - A string argument that explains 533 | % the error. It will be one of the following 534 | % possibilities: 535 | % 536 | % '' --> No error. An unambiguous match for arg 537 | % was found among the choices. 538 | % 539 | % 'No match found' --> No match was found among 540 | % the choices provided in valid. 541 | % 542 | % 'Ambiguous argument' --> At least two ambiguous 543 | % matches were found among those provided 544 | % in valid. 545 | % 546 | % 547 | % Example: 548 | % valid = {'off' 'on' 'The sky is falling'} 549 | % 550 | % 551 | % See also: parse_pv_pairs, strmatch, strcmpi 552 | % 553 | % Author: John D'Errico 554 | % e-mail: woodchips@rochester.rr.com 555 | % Release: 1.0 556 | % Release date: 3/25/2010 557 | 558 | ind = find(strncmpi(lower(arg),valid,numel(arg))); 559 | if isempty(ind) 560 | % No hit found 561 | errorclass = 'No match found'; 562 | str = ''; 563 | elseif (length(ind) > 1) 564 | % Ambiguous arg, hitting more than one of the valid options 565 | errorclass = 'Ambiguous argument'; 566 | str = ''; 567 | return 568 | else 569 | errorclass = ''; 570 | str = valid{ind}; 571 | end 572 | 573 | end % function validstring 574 | 575 | -------------------------------------------------------------------------------- /GEplot_3D.m: -------------------------------------------------------------------------------- 1 | function GEplot_3D(filename,Lat_susp,Lon_susp,Elev_susp,style_susp,Lat_bot,Lon_bot,Elev_bot,style_bot,ERH,Spawning_Location,T2_Gas_bladder,opt11,opt12,opt21,opt22) 2 | % 3 | %3D adaptation of GEplot. 3D version will plot a 3 dimensional plot given the added elevation vector 4 | %input--P.R. Jackson, USGS, 1-16-08 5 | %input-- Tatiana Garcia, USGS, 5-18-15. This version generates a 3D plot 6 | %with two line paths or two folders with placemarks and two colors. 7 | %The symbols where changed to the shaded dot from google earth images. 8 | % 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 9 | %Eplot_3D(filename,Lat_susp,Lon_susp,Elev_susp,style_susp,Lat_bot,Lon_bot,Elev_bot,style_bot,ERH,Xi,opt11,opt12,opt21,opt22) 10 | % function GEplot(filename,Lat,Lon,style,opt11,opt12,opt21,opt22) 11 | % function GEplot_3D(filename,Lat,Lon,Elev,style,opt11,opt12,opt21,opt22) 12 | 13 | % Description: creates a file in kml format that can be opened into Google Earth. 14 | % GEplot_3D uses the same syntax as the traditional plot function but 15 | % requires Latitude and Longitudd (WGS84) instead of x and y (note that Lat is 16 | % the first argument). 17 | % If you need to convert from UTM to Lat/Lon you may use utm2deg.m also 18 | % available at Matlab Central 19 | % 20 | % Arguments: 21 | % filename Example 'rafael', will become 'rafael.kml'. The same name 22 | % will appear inside Temporary Places in Google Earth as a layer. 23 | % dot_size Approximate size of the mark, in meters 24 | % Lat, Lon Vectors containing Latitudes and Longitudes. The number of marks 25 | % created by this function is equal to the length of Lat/Lon vectors 26 | %(opt)style allows for specifying symbols and colors (line styles are not 27 | % supported by Google Earth currently. (see bellow) 28 | %(opt)opt... allows for specifying symbol size and line width (see bellow) 29 | % 30 | % Example: 31 | % GEplot('my_track',Lat,Lon,'o-r','MarkerSize',10,'LineWidth',3) 32 | % GEplot('my_track',Lat,Lon) 33 | % 34 | % Plot style parameters implemented in GEplot 35 | % color symbol line style 36 | % ----------------------------------------------------------- 37 | % b blue . point - solid 38 | % g green o circle (none) no line 39 | % r red x x-mark 40 | % c cyan + plus 41 | % m magenta * star 42 | % y yellow s square 43 | % k black d diamond 44 | % w white (new) S filled square (new) 45 | % D filled diamond (new) 46 | % O filled circle=big dot (new) 47 | % 48 | % Plot properties: 'MarkerSize' 'LineWidth' 49 | % 50 | % Additional Notes: 51 | % 'Hold on' and 'Hold off' were not implemented since one can generate a 52 | % .kmz file for each plot and open all simultaneously within GE. 53 | % Unless you have a lot of data point it is recomended to show the symbols 54 | % since they are created in a separate folder so within Google Earth it 55 | % is very easy to show/hide the line or the symbols. 56 | % Current kml/kmz format does not support different linestyles, just solid. 57 | % Nevertheless it is possible to define the opacity of the color (the 58 | % first FF in the color definition means no transparency). 59 | % Within Matlab, it is possible to generate a second plot with the 60 | % same name, then you just need to select File/Revert within GE to update. 61 | % 62 | % 63 | % Author: Rafael Palacios, Universidad Pontificia Comillas 64 | % http://www.iit.upcomillas.es/palacios 65 | % November 2006 66 | % Version 1.1: Fixed an error while plotting graphs without symbols. 67 | % 68 | 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 70 | % Argument checking 71 | % 72 | error(nargchk(11,15, nargin)); %8 arguments required, 14 maximum 73 | n1=length(Lat_susp); 74 | n2=length(Lon_susp); 75 | n3=length(Elev_susp); 76 | if (n1~=n2 | n1~=n3) 77 | error('Lat, Lon, and Elev vectors should have the same length'); 78 | end 79 | n4=length(Lat_bot); 80 | n5=length(Lon_bot); 81 | n6=length(Elev_bot); 82 | if (n4~=n5 | n4~=n6) 83 | error('Lat, Lon, and Elev vectors should have the same length'); 84 | end 85 | if (nargin==13 || nargin==15) 86 | error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number'); 87 | end 88 | 89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 90 | % symbol size and line width 91 | % 92 | markersize=7; %matlab default 93 | linewidth=2; %matlab default is 0.5, too thin for map overlay 94 | if (nargin==14) 95 | if (strcmpi(opt11,'markersize')==1) 96 | markersize=opt12; 97 | elseif (strcmpi(opt11,'linewidth')==1) 98 | linewidth=opt12; 99 | else 100 | error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number'); 101 | end 102 | end 103 | if (nargin==16) 104 | if (strcmpi(opt21,'markersize')==1) 105 | markersize=opt22; 106 | elseif (strcmpi(opt21,'linewidth')==1) 107 | linewidth=opt22; 108 | else 109 | error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number'); 110 | end 111 | end 112 | 113 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 114 | % symbol, line style and color 115 | % 116 | symbol='none'; 117 | iconfilename='none'; 118 | linestyle='-'; 119 | color='b'; 120 | colorstring='7fff0000'; 121 | 122 | if (nargin>=9) 123 | %linestyle 124 | if (strfind(style_susp,'-')) 125 | linestyle='-'; 126 | else 127 | linestyle='none'; 128 | end 129 | %% 130 | if (strfind(style_bot,'-')) 131 | linestyle='-'; 132 | else 133 | linestyle='none'; 134 | end 135 | %% 136 | %symbol 137 | if (strfind(style_susp,'.')), symbol='.'; iconfilename_susp='dot'; end 138 | if (strfind(style_susp,'o')), symbol='o'; iconfilename_susp='circle'; end 139 | if (strfind(style_susp,'x')), symbol='x'; iconfilename_susp='x'; end 140 | if (strfind(style_susp,'+')), symbol='+'; iconfilename_susp='plus'; end 141 | if (strfind(style_susp,'*')), symbol='*'; iconfilename_susp='star'; end 142 | if (strfind(style_susp,'s')), symbol='s'; iconfilename_susp='square'; end 143 | if (strfind(style_susp,'d')), symbol='d'; iconfilename_susp='diamond'; end 144 | if (strfind(style_susp,'S')), symbol='S'; iconfilename_susp='Ssquare'; end 145 | if (strfind(style_susp,'D')), symbol='D'; iconfilename_susp='Sdiamon'; end 146 | if (strfind(style_susp,'O')), symbol='O'; iconfilename_susp='dot'; end 147 | if (strfind(style_susp,'0')), symbol='O'; iconfilename_susp='dot'; end 148 | 149 | if (strfind(style_bot,'.')), symbol='.'; iconfilename_bot='dot'; end 150 | if (strfind(style_bot,'o')), symbol='o'; iconfilename_bot='circle'; end 151 | if (strfind(style_bot,'x')), symbol='x'; iconfilename_bot='x'; end 152 | if (strfind(style_bot,'+')), symbol='+'; iconfilename_bot='plus'; end 153 | if (strfind(style_bot,'*')), symbol='*'; iconfilename_bot='star'; end 154 | if (strfind(style_bot,'s')), symbol='s'; iconfilename_bot='square'; end 155 | if (strfind(style_bot,'d')), symbol='d'; iconfilename_bot='diamond'; end 156 | if (strfind(style_bot,'S')), symbol='S'; iconfilename_bot='Ssquare'; end 157 | if (strfind(style_bot,'D')), symbol='D'; iconfilename_bot='Sdiamon'; end 158 | if (strfind(style_bot,'O')), symbol='O'; iconfilename_bot='dot'; end 159 | if (strfind(style_bot,'0')), symbol='O'; iconfilename_bot='dot'; end 160 | 161 | %color 162 | if (strfind(style_susp,'b')), color_susp='b'; colorstring_susp='7fff0000'; end 163 | if (strfind(style_susp,'g')), color_susp='g'; colorstring_susp='7f00ff00'; end 164 | if (strfind(style_susp,'r')), color_susp='r'; colorstring_susp='7f0000ff'; end 165 | if (strfind(style_susp,'c')), color_susp='c'; colorstring_susp='7fffff00'; end 166 | if (strfind(style_susp,'m')), color_susp='m'; colorstring_susp='7fff00ff'; end 167 | if (strfind(style_susp,'y')), color_susp='y'; colorstring_susp='7f00ffff'; end 168 | if (strfind(style_susp,'k')), color_susp='k'; colorstring_susp='7f000000'; end 169 | if (strfind(style_susp,'w')), color_susp='w'; colorstring_susp='7fffffff'; end 170 | 171 | if (strfind(style_bot,'b')), color_bot='b'; colorstring_bot='7fff0000'; end 172 | if (strfind(style_bot,'g')), color_bot='g'; colorstring_bot='7f00ff00'; end 173 | if (strfind(style_bot,'r')), color_bot='r'; colorstring_bot='7f0000ff'; end 174 | if (strfind(style_bot,'c')), color_bot='c'; colorstring_bot='7fffff00'; end 175 | if (strfind(style_bot,'m')), color_bot='m'; colorstring_bot='7fff00ff'; end 176 | if (strfind(style_bot,'y')), color_bot='y'; colorstring_bot='7f00ffff'; end 177 | if (strfind(style_bot,'k')), color_bot='k'; colorstring_bot='7f000000'; end 178 | if (strfind(style_bot,'w')), color_bot='w'; colorstring_bot='7fffffff'; end 179 | end 180 | 181 | % iconfilename_susp=strcat('GEimages/',iconfilename_susp,'_',color_susp,'.png'); 182 | % iconfilename_bot=strcat('GEimages/',iconfilename_bot,'_',color_bot,'.png'); 183 | 184 | if (symbol=='.') 185 | markersize=markersize/5; 186 | end 187 | 188 | 189 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 190 | % Creating kml file 191 | % 192 | fp=fopen(strcat(filename,'.kml'),'w'); 193 | if (fp==-1) 194 | message=disp('Unable to open file %s.kml',filename); 195 | error(message); 196 | end 197 | fprintf(fp,'\n'); 198 | fprintf(fp,'\n'); 199 | fprintf(fp,'\n'); 200 | name=regexp(filename, '\\', 'split');name=name(end); 201 | 202 | %Symbol styles definition 203 | %%======================================================================================================= 204 | fprintf(fp,'\n'); 225 | fprintf(fp,'\n'); 226 | %%======================================================================================================= 227 | fprintf(fp,'\n'); 244 | fprintf(fp,'\n'); 245 | %%======================================================================================================= 246 | 247 | 248 | if (linestyle=='-') 249 | if T2_Gas_bladder==0 % If user did not simulate larvae stage... 250 | fprintf(fp,'%s\n',['Longitudinal distribution of eggs at hatching time ' char(name)]); 251 | fprintf(fp,'Longitudinal distribution of eggs (using GEplot.m and the VMT version-GEplot_3D.m)\n'); 252 | %% 253 | fprintf(fp,' \n'); 254 | fprintf(fp,' \n'); 255 | fprintf(fp,' Eggs in suspension\n'); 256 | fprintf(fp,' 1\n'); 257 | fprintf(fp,' 1\n'); 258 | fprintf(fp,' mystyle1\n'); 259 | fprintf(fp,' \n'); 260 | fprintf(fp,' 1\n'); 261 | fprintf(fp,' 1\n'); 262 | fprintf(fp,' relativeToGround\n'); 263 | fprintf(fp,' \n'); 264 | for k=1:n1 265 | fprintf(fp,'%.6f,%.6f,%07.2f\n',Lon_susp(k),Lat_susp(k),Elev_susp(k)); %max(Elev)- 266 | end 267 | fprintf(fp,' \n'); 268 | fprintf(fp,' \n'); 269 | fprintf(fp,' \n'); 270 | %% 271 | if ~isempty(Lat_bot) 272 | 273 | fprintf(fp,' \n'); 274 | fprintf(fp,' \n'); 275 | fprintf(fp,' Eggs near the bottom\n'); 276 | fprintf(fp,' 1\n'); 277 | fprintf(fp,' 1\n'); 278 | fprintf(fp,' mystyle2\n'); 279 | fprintf(fp,' \n'); 280 | fprintf(fp,' 1\n'); 281 | fprintf(fp,' 1\n'); 282 | fprintf(fp,' relativeToGround\n'); 283 | fprintf(fp,' \n'); 284 | for k=1:n4 285 | fprintf(fp,'%.6f,%.6f,%07.2f\n',Lon_bot(k),Lat_bot(k),Elev_bot(k)); %max(Elev)- 286 | end 287 | fprintf(fp,' \n'); 288 | fprintf(fp,' \n'); 289 | fprintf(fp,' \n'); 290 | end 291 | %% 292 | % Peak egg concentration 293 | idmax=find(Elev_susp==max(Elev_susp));idmax=idmax(1); 294 | % 295 | fprintf(fp,' \n'); 296 | fprintf(fp,'%s\n',['Approximately ' num2str(round((ERH*10)/10)) '% of eggs are at risk of hatching']); 297 | fprintf(fp,' \n'); 303 | fprintf(fp,' \n'); 304 | fprintf(fp,' 1\n'); 305 | fprintf(fp,' %.6f,%.6f,%07.2f\n',Lon_susp(idmax),Lat_susp(idmax),Elev_susp(idmax)); 306 | fprintf(fp,' relativeToGround\n'); 307 | fprintf(fp,' \n'); 308 | fprintf(fp,' \n'); 309 | 310 | else 311 | fprintf(fp,'%s\n',['Longitudinal distribution of larvae at gas bladder inflation stage ' char(name)]); 312 | fprintf(fp,'Longitudinal distribution of of larvae at gas bladder inflation stage (using GEplot.m and the VMT version-GEplot_3D.m)\n'); 313 | %% 314 | fprintf(fp,' \n'); 315 | fprintf(fp,' \n'); 316 | fprintf(fp,' Larvae at gas bladder stage\n'); 317 | fprintf(fp,' 1\n'); 318 | fprintf(fp,' 1\n'); 319 | fprintf(fp,' mystyle1\n'); 320 | fprintf(fp,' \n'); 321 | fprintf(fp,' 1\n'); 322 | fprintf(fp,' 1\n'); 323 | fprintf(fp,' relativeToGround\n'); 324 | fprintf(fp,' \n'); 325 | for k=1:n1 326 | fprintf(fp,'%.6f,%.6f,%07.2f\n',Lon_susp(k),Lat_susp(k),Elev_susp(k)); %max(Elev)- 327 | end 328 | fprintf(fp,' \n'); 329 | fprintf(fp,' \n'); 330 | fprintf(fp,' \n'); 331 | %% 332 | end 333 | end %if distribution 334 | %%======================================================================================================= 335 | 336 | if (strcmp(symbol,'none')==0) 337 | if ~isempty(Lat_bot) 338 | fprintf(fp,'%s\n',['Egg plume at hatching time ' char(name)]); 339 | fprintf(fp,'Streamwise location of eggs at hatching time (using GEplot.m and the VMT version-GEplot_3D.m)\n'); 340 | else 341 | fprintf(fp,'%s\n',['Larvae (gas bladder stage) plume ' char(name)]); 342 | fprintf(fp,'Streamwise location of gas bladder stage larvae (using GEplot.m and the VMT version-GEplot_3D.m)\n'); 343 | end 344 | 345 | %%======================================================================================================= 346 | fprintf(fp,' \n'); 347 | if ~isempty(Lat_bot) 348 | fprintf(fp,' Streamwise position of eggs in suspension\n'); 349 | else 350 | fprintf(fp,' Streamwise position of larvae at gas bladder stage\n'); 351 | end 352 | for k=1:n1 353 | fprintf(fp,' \n'); 354 | fprintf(fp,' \n'); 355 | % fprintf(fp,' Point %d\n',k); %you may add point labels here 356 | fprintf(fp,' 1\n'); 357 | fprintf(fp,' 1\n'); 358 | fprintf(fp,' mystyle1\n'); 359 | fprintf(fp,' \n'); 360 | fprintf(fp,' \n'); 361 | fprintf(fp,'%.6f,%.6f,%07.2f\n',Lon_susp(k),Lat_susp(k),Elev_susp(k)); %max(Elev)- 362 | fprintf(fp,' \n'); 363 | fprintf(fp,' \n'); 364 | fprintf(fp,' \n'); 365 | end 366 | fprintf(fp,' \n'); 367 | %%======================================================================================================= 368 | 369 | if ~isempty(Lat_bot) 370 | fprintf(fp,' \n'); 371 | fprintf(fp,' Streamwise position of eggs near the bed\n'); 372 | for k=1:n4 373 | fprintf(fp,' \n'); 374 | fprintf(fp,' \n'); 375 | % fprintf(fp,' Point %d\n',k); %you may add point labels here 376 | fprintf(fp,' 1\n'); 377 | fprintf(fp,' 1\n'); 378 | fprintf(fp,' mystyle2\n'); 379 | fprintf(fp,' \n'); 380 | fprintf(fp,' \n'); 381 | fprintf(fp,'%.6f,%.6f,%07.2f\n',Lon_bot(k),Lat_bot(k),Elev_bot(k)); %max(Elev)- 382 | fprintf(fp,' \n'); 383 | fprintf(fp,' \n'); 384 | fprintf(fp,' \n'); 385 | end 386 | fprintf(fp,' \n'); 387 | end 388 | %%======================================================================================================= 389 | end 390 | 391 | %%======================================================================================================= 392 | fprintf(fp,' \n'); 393 | fprintf(fp,'%s\n',['Spawning location']); 394 | fprintf(fp,' \n'); 403 | fprintf(fp,' \n'); 404 | %fprintf(fp,' 1\n'); 405 | fprintf(fp,' %.6f,%.6f,%07.2f\n',Spawning_Location(2),Spawning_Location(1),0); 406 | fprintf(fp,' relativeToGround\n'); 407 | fprintf(fp,' \n'); 408 | fprintf(fp,' \n'); 409 | %%======================================================================================================= 410 | 411 | fprintf(fp,'\n'); 412 | fprintf(fp,'\n'); 413 | 414 | fclose(fp); 415 | -------------------------------------------------------------------------------- /Minigui_Video.m: -------------------------------------------------------------------------------- 1 | %============================================================================== 2 | % FluEgg -Fluvial Egg Drift Simulator 3 | %============================================================================== 4 | % Copyright (c) 2013 Tatiana Garcia 5 | 6 | % This program is free software: you can redistribute it and/or modify 7 | % it under the terms of the GNU General Public License version 3 as published by 8 | % the Free Software Foundation (currently at http://www.gnu.org/licenses/agpl.html) 9 | % with a permitted obligation to maintain Appropriate Legal Notices. 10 | 11 | % This program is distributed in the hope that it will be useful, 12 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | % GNU General Public License for more details. 15 | 16 | % You should have received a copy of the GNU General Public License 17 | % along with this program. If not, see . 18 | 19 | function varargout = Minigui_Video(varargin) 20 | % MINIGUI_VIDEO MATLAB code for Minigui_Video.fig 21 | % MINIGUI_VIDEO, by itself, creates a new MINIGUI_VIDEO or raises the existing 22 | % singleton*. 23 | % 24 | % H = MINIGUI_VIDEO returns the handle to a new MINIGUI_VIDEO or the handle to 25 | % the existing singleton*. 26 | % 27 | % MINIGUI_VIDEO('CALLBACK',hObject,eventData,handles,...) calls the local 28 | % function named CALLBACK in MINIGUI_VIDEO.M with the given input arguments. 29 | % 30 | % MINIGUI_VIDEO('Property','Value',...) creates a new MINIGUI_VIDEO or raises the 31 | % existing singleton*. Starting from the left, property value pairs are 32 | % applied to the GUI before Minigui_Video_OpeningFcn gets called. An 33 | % unrecognized property name or invalid value makes property application 34 | % stop. All inputs are passed to Minigui_Video_OpeningFcn via varargin. 35 | % 36 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 37 | % instance to run (singleton)". 38 | % 39 | % See also: GUIDE, GUIDATA, GUIHANDLES 40 | 41 | % Edit the above text to modify the response to help Minigui_Video 42 | 43 | % Last Modified by GUIDE v2.5 28-Aug-2014 09:33:54 44 | 45 | % Begin initialization code - DO NOT EDIT 46 | gui_Singleton = 1; 47 | gui_State = struct('gui_Name', mfilename, ... 48 | 'gui_Singleton', gui_Singleton, ... 49 | 'gui_OpeningFcn', @Minigui_Video_OpeningFcn, ... 50 | 'gui_OutputFcn', @Minigui_Video_OutputFcn, ... 51 | 'gui_LayoutFcn', [] , ... 52 | 'gui_Callback', []); 53 | if nargin && ischar(varargin{1}) 54 | gui_State.gui_Callback = str2func(varargin{1}); 55 | end 56 | 57 | if nargout 58 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 59 | else 60 | gui_mainfcn(gui_State, varargin{:}); 61 | end 62 | % End initialization code - DO NOT EDIT 63 | 64 | 65 | function Minigui_Video_OpeningFcn(hObject, eventdata, handles, varargin) 66 | diary('./results/FluEgg_LogFile.txt') 67 | handleResults=getappdata(0,'handleResults'); 68 | ResultsSim=getappdata(handleResults,'ResultsSim'); 69 | CumlDistance=ResultsSim.CumlDistance; 70 | time=ResultsSim.time;%seconds 71 | set(handles.Fcell_edit,'String',length(CumlDistance)) 72 | set(handles.Frames_edit,'String',10) 73 | %% 74 | NoFrames=str2double(get(handles.Frames_edit,'String')); 75 | Time_step_frames=time(end)/3600/NoFrames;%hours 76 | set(handles.Display_text,'String',['The video will display one frame every ',sprintf('%.1f',Time_step_frames),' hour(s)']) 77 | handles.output = hObject; 78 | guidata(hObject, handles); 79 | 80 | function varargout = Minigui_Video_OutputFcn(hObject, eventdata, handles) 81 | diary off 82 | varargout{1} = handles.output; 83 | 84 | function Fcell_edit_Callback(hObject, eventdata, handles) 85 | function Fcell_edit_CreateFcn(hObject, eventdata, handles) 86 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 87 | set(hObject,'BackgroundColor','white'); 88 | end 89 | 90 | function Frames_edit_Callback(hObject, eventdata, handles) 91 | update(hObject, eventdata, handles); 92 | function Frames_edit_CreateFcn(hObject, eventdata, handles) 93 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 94 | set(hObject,'BackgroundColor','white'); 95 | end 96 | 97 | function video(~, ~, handles) 98 | %% Load data 99 | handleResults=getappdata(0,'handleResults'); 100 | ResultsSim=getappdata(handleResults,'ResultsSim'); 101 | X=ResultsSim.X; 102 | Z=ResultsSim.Z; 103 | Y=ResultsSim.Y; 104 | CumlDistance=ResultsSim.CumlDistance; 105 | Depth=ResultsSim.Depth; 106 | Width=ResultsSim.Width; 107 | VX=ResultsSim.VX; 108 | time=ResultsSim.time;%seconds 109 | Fcell=str2double(get(handles.Fcell_edit,'String')); 110 | NoFrames=str2double(get(handles.Frames_edit,'String')); 111 | %% Error checking========================================================== 112 | if isempty(Fcell)||isnan(Fcell)||isempty(NoFrames)||isnan(NoFrames) 113 | ed=msgbox('Empty input field. Please make sure all required fields are filled out correctly ','FluEgg Error: Empty fields','error'); 114 | set(ed, 'WindowStyle', 'modal'); 115 | uiwait(ed); 116 | return 117 | end 118 | if Fcell<=0||NoFrames<=0 119 | ed=msgbox('Incorrect negative or zero value. Please make sure all required fields are filled out correctly','FluEgg Error: Incorrect negative or zero value','error'); 120 | set(ed, 'WindowStyle', 'modal'); 121 | uiwait(ed); 122 | return 123 | end 124 | if Fcell>length(CumlDistance) 125 | ed=msgbox('Incorrect input value. The number of cells to display exceeds the total number of cells in the domain','FluEgg Error: Incorrect input value','error'); 126 | set(ed, 'WindowStyle', 'modal'); 127 | uiwait(ed); 128 | return 129 | end 130 | %% ========================================================================== 131 | 132 | Videodata.Time_step_frames=time(end)/3600/NoFrames;%hours 133 | set(handles.Display_text,'String',['The video will display one frame every ',sprintf('%.1f',Videodata.Time_step_frames),' hour(s)']) 134 | 135 | %% 136 | %% 137 | opengl('software') 138 | set(0,'Units','pixels') ; 139 | scnsize = get(0,'ScreenSize'); 140 | hf=figure('Name','3D animation of eggs transport (video)','NumberTitle','off',... 141 | 'color','w','position',[8 scnsize(4)/11 scnsize(3)/1.1 scnsize(4)/1.289]); 142 | % 'color','w','position',[8 scnsize(4)/2.6 scnsize(3)/2.1333 scnsize(4)/2]); 143 | 144 | subaxis(1,1,1,'MR',0.1,'ML',0.1,'MB',0.4,'MT',0.19); 145 | axis off 146 | font='Helvetica'; fontsize = 12; 147 | %% Drawing cells 148 | %% cubes 149 | colormap([0.6 1 1;0.57 0.97 1;0.54 0.94 1;0.51 0.9 1;0.49 0.89 1;0.46 0.88 1;0.43 0.83 1;0.4 0.8 1;0.39 0.79 1;0.375 0.775000035762787 1;0.362500011920929 0.762499988079071 1;0.349999994039536 0.75 1;0.337500005960464 0.737500011920929 1;0.325000017881393 0.725000023841858 1;0.3125 0.712500035762787 1;0.300000011920929 0.700000047683716 1;0.287499994039536 0.6875 1;0.275000005960464 0.675000011920929 1;0.262500017881393 0.662500023841858 1;0.25 0.650000035762787 1;0.237499997019768 0.637500047683716 1;0.225000008940697 0.625 1;0.212500005960464 0.612500011920929 1;0.200000002980232 0.600000023841858 1;0.1875 0.587500035762787 1;0.174999997019768 0.575000047683716 1;0.162500008940697 0.5625 1;0.150000005960464 0.550000011920929 1;0.137500002980232 0.537500023841858 1;0.125 0.525000035762787 1;0.112500004470348 0.512499988079071 1;0.100000001490116 0.5 1;0.0874999985098839 0.487500011920929 1;0.0750000029802322 0.475000023841858 1;0.0625 0.462500005960464 1;0.0500000007450581 0.450000017881393 1;0.0375000014901161 0.4375 1;0.025000000372529 0.425000011920929 1;0.0125000001862645 0.412499994039536 1;0 0.400000005960464 1;0 0.387500017881393 0.987500011920929;0 0.375 0.975000023841858;0 0.362500011920929 0.962499976158142;0 0.349999994039536 0.949999988079071;0 0.337500005960464 0.9375;0 0.325000017881393 0.925000011920929;0 0.3125 0.912500023841858;0 0.300000011920929 0.899999976158142;0 0.287499994039536 0.887499988079071;0 0.275000005960464 0.875;0 0.262500017881393 0.862500011920929;0 0.25 0.850000023841858;0 0.237499997019768 0.837500035762787;0 0.225000008940697 0.824999988079071;0 0.212500005960464 0.8125;0 0.200000002980232 0.800000011920929;0 0.174999997019768 0.775000035762787;0 0.150000005960464 0.75;0 0.125 0.72;0 0.1 0.700000047683716;0 0.075 0.675;0 0.05 0.65;0 0.025 0.625;0 0 0.6]); 150 | xo=0; 151 | %% Cells to plot 152 | for k=1:Fcell%length(CumlDistance)%Fcell 153 | if k>1 154 | xo=CumlDistance(k-1); 155 | end 156 | x(:,k)=[xo CumlDistance(k) CumlDistance(k) xo]; 157 | y(:,k)=[Width(k) Width(k) Width(k) Width(k)]; 158 | z(:,k)=[-Depth(k) -Depth(k) 0 0 ]; %[0 0 Depth(k) Depth(k)]; 159 | colorp(:,k)=[VX(k) VX(k) VX(k) VX(k)];%%VX=Vmag before 160 | yb(:,k)=[0 0 Width(k) Width(k)]; 161 | yf(:,k)=[0 0 0 0]; 162 | zb(:,k)=[-Depth(k) -Depth(k) -Depth(k) -Depth(k)];%[0 0 0 0]; 163 | zt(:,k)=[0 0 0 0];%[Depth(k) Depth(k) Depth(k) Depth(k)]; 164 | xx(:,k)=[xo xo xo xo]; 165 | yy(:,k)=[0 Width(k) Width(k) 0]; 166 | end 167 | %% 168 | t=0; 169 | %% Plot t=0 and adjust plot 170 | scatter3(X(round(t+1),:)/1000,Y(round(t+1),:),Z(round(t+1),:),1.3*20,'y','MarkerFaceColor','flat','MarkerEdgeColor',[0 0 0]); 171 | colormap([0.6 1 1;0.57 0.97 1;0.54 0.94 1;0.51 0.9 1;0.49 0.89 1;0.46 0.88 1;0.43 0.83 1;0.4 0.8 1;0.39 0.79 1;0.375 0.775000035762787 1;0.362500011920929 0.762499988079071 1;0.349999994039536 0.75 1;0.337500005960464 0.737500011920929 1;0.325000017881393 0.725000023841858 1;0.3125 0.712500035762787 1;0.300000011920929 0.700000047683716 1;0.287499994039536 0.6875 1;0.275000005960464 0.675000011920929 1;0.262500017881393 0.662500023841858 1;0.25 0.650000035762787 1;0.237499997019768 0.637500047683716 1;0.225000008940697 0.625 1;0.212500005960464 0.612500011920929 1;0.200000002980232 0.600000023841858 1;0.1875 0.587500035762787 1;0.174999997019768 0.575000047683716 1;0.162500008940697 0.5625 1;0.150000005960464 0.550000011920929 1;0.137500002980232 0.537500023841858 1;0.125 0.525000035762787 1;0.112500004470348 0.512499988079071 1;0.100000001490116 0.5 1;0.0874999985098839 0.487500011920929 1;0.0750000029802322 0.475000023841858 1;0.0625 0.462500005960464 1;0.0500000007450581 0.450000017881393 1;0.0375000014901161 0.4375 1;0.025000000372529 0.425000011920929 1;0.0125000001862645 0.412499994039536 1;0 0.400000005960464 1;0 0.387500017881393 0.987500011920929;0 0.375 0.975000023841858;0 0.362500011920929 0.962499976158142;0 0.349999994039536 0.949999988079071;0 0.337500005960464 0.9375;0 0.325000017881393 0.925000011920929;0 0.3125 0.912500023841858;0 0.300000011920929 0.899999976158142;0 0.287499994039536 0.887499988079071;0 0.275000005960464 0.875;0 0.262500017881393 0.862500011920929;0 0.25 0.850000023841858;0 0.237499997019768 0.837500035762787;0 0.225000008940697 0.824999988079071;0 0.212500005960464 0.8125;0 0.200000002980232 0.800000011920929;0 0.174999997019768 0.775000035762787;0 0.150000005960464 0.75;0 0.125 0.72;0 0.1 0.700000047683716;0 0.075 0.675;0 0.05 0.65;0 0.025 0.625;0 0 0.6]); 172 | %% Drawing cubes 173 | patch(x,y,z,colorp) %Back face 174 | hold on 175 | patch(x,yb,zb,colorp)%Bottom face 176 | patch(x,yb,zt,'w','FaceAlpha',0.02)%Top face,optional 'FaceColor','none' 177 | hh=patch(xx,yy,z,colorp); 178 | uistack(hh,'bottom') 179 | bar=colorbar('Limits',[0 1.2],'XTick',[0:0.2:1.2],'XTickLabel',[0:0.2:1.2],'location','NorthOutside'); 180 | set(get(bar,'xlabel'),'String', 'Cell Velocity [m/s]');clear bar;%Velocity=Vmag 181 | bar=findobj(gcf,'Tag','Colorbar'); 182 | set(bar,'Position',[0.74 0.05 0.25 0.016]); 183 | hold off 184 | %% 185 | xlim([0 CumlDistance(Fcell)]); ylim([0 max(Width(1:Fcell))]); zlim([-max(Depth(1:Fcell)) 0]); 186 | daspect('auto');grid off; box on 187 | %% 188 | xlabel('Distance in X(km)','FontSize',fontsize-1); 189 | ylabel('Width(m)','FontSize',fontsize-1); 190 | zlabel({'Depth (m)'},'FontSize',fontsize-1); 191 | set(gca,'FontSize',fontsize-1) 192 | %%=========================================================== 193 | Videodata.continueB_text = uicontrol('Parent',hf,'Style','text','Position',[10,125,300,18],... 194 | 'String','Please set-up the view. Press any key to continue with the video','HorizontalAlignment','left','BackgroundColor',get(hf,'Color')); 195 | Videodata.Continue_Button=uicontrol('Parent',hf,'Style','pushbutton','Position',[100,95,100,23],... 196 | 'String','Continue','BackgroundColor',[0.039 0.141 0.416],'ForegroundColor',[1 1 1],'Callback',@continue_pushbutton); 197 | Videodata.AZ_slider = uicontrol('Parent',hf,'Style','slider','Position',[100,58,100,23],... 198 | 'value',15, 'min',-15, 'max',45,'callback', @AZ_slider_Callback); 199 | Videodata.AZ_text = uicontrol('Parent',hf,'Style','text','Position',[10,54,80,30],... 200 | 'String','View point (azimuth)','BackgroundColor',get(hf,'Color')); 201 | Videodata.EL_slider = uicontrol('Parent',hf,'Style','slider','Position',[100,18,100,23],... 202 | 'value',30, 'min',-15, 'max',45,'callback', @EL_slider_Callback); 203 | Videodata.EL_text = uicontrol('Parent',hf,'Style','text','Position',[10,14,80,30],... 204 | 'String','View point (elevation)','BackgroundColor',get(hf,'Color')); 205 | view([15 30]) 206 | 207 | %%=========================================================== 208 | %% 209 | xlabel('Distance in X(km)','FontSize',fontsize-1); 210 | ylabel('Width(m)','FontSize',fontsize-1); 211 | zlabel({'Depth (m)'},'FontSize',fontsize-1); 212 | set(gca,'FontSize',fontsize-1) 213 | %% Passing variables into continue function 214 | Videodata.x=x; 215 | Videodata.y=y; 216 | Videodata.z=z; 217 | Videodata.colorp=colorp; 218 | Videodata.yb=yb; 219 | Videodata.zb=zb; 220 | Videodata.zt=zt; 221 | Videodata.xx=xx; 222 | Videodata.yy=yy; 223 | Videodata.Fcell=Fcell; 224 | Videodata.hf=hf; 225 | %% 226 | setappdata(handleResults, 'Videodata',Videodata); 227 | %[ca cel]=view; 228 | % if getappdata(handleResults,'continue')==1 229 | % 230 | 231 | 232 | function continue_pushbutton(~,~,~) 233 | %% Getting data 234 | handleResults=getappdata(0,'handleResults'); 235 | ResultsSim=getappdata(handleResults,'ResultsSim'); 236 | Videodata=getappdata(handleResults,'Videodata'); 237 | X=ResultsSim.X; 238 | Z=ResultsSim.Z; 239 | Y=ResultsSim.Y; 240 | CumlDistance=ResultsSim.CumlDistance; 241 | Depth=ResultsSim.Depth; 242 | Width=ResultsSim.Width; 243 | VX=ResultsSim.VX; 244 | D=ResultsSim.D; 245 | time=ResultsSim.time;%seconds 246 | Dt=time(2)-time(1); 247 | x=Videodata.x; 248 | y=Videodata.y; 249 | z=Videodata.z; 250 | colorp=Videodata.colorp; 251 | yb=Videodata.yb; 252 | zb=Videodata.zb; 253 | zt=Videodata.zt; 254 | xx=Videodata.xx; 255 | yy=Videodata.yy; 256 | Fcell=Videodata.Fcell; 257 | fontsize = 12; 258 | %% 259 | set(Videodata.AZ_slider,'Visible','off') 260 | set(Videodata.EL_slider,'Visible','off') 261 | set(Videodata.AZ_text,'Visible','off') 262 | set(Videodata.EL_text,'Visible','off') 263 | set(Videodata.continueB_text,'Visible','off') 264 | set(Videodata.Continue_Button,'Visible','off') 265 | 266 | [ca cel]=view; 267 | counter=1; 268 | %% Plot t 269 | for t=0:round(Videodata.Time_step_frames*3600):length(time)*Dt 270 | if round(t/Dt+1)<=length(time) 271 | scatter3(X(round(t/Dt+1),:)/1000,Y(round(t/Dt+1),:),Z(round(t/Dt+1),:),1.3*20,'y','MarkerFaceColor','flat','MarkerEdgeColor',[0 0 0]); 272 | colormap([0.6 1 1;0.57 0.97 1;0.54 0.94 1;0.51 0.9 1;0.49 0.89 1;0.46 0.88 1;0.43 0.83 1;0.4 0.8 1;0.39 0.79 1;0.375 0.775000035762787 1;0.362500011920929 0.762499988079071 1;0.349999994039536 0.75 1;0.337500005960464 0.737500011920929 1;0.325000017881393 0.725000023841858 1;0.3125 0.712500035762787 1;0.300000011920929 0.700000047683716 1;0.287499994039536 0.6875 1;0.275000005960464 0.675000011920929 1;0.262500017881393 0.662500023841858 1;0.25 0.650000035762787 1;0.237499997019768 0.637500047683716 1;0.225000008940697 0.625 1;0.212500005960464 0.612500011920929 1;0.200000002980232 0.600000023841858 1;0.1875 0.587500035762787 1;0.174999997019768 0.575000047683716 1;0.162500008940697 0.5625 1;0.150000005960464 0.550000011920929 1;0.137500002980232 0.537500023841858 1;0.125 0.525000035762787 1;0.112500004470348 0.512499988079071 1;0.100000001490116 0.5 1;0.0874999985098839 0.487500011920929 1;0.0750000029802322 0.475000023841858 1;0.0625 0.462500005960464 1;0.0500000007450581 0.450000017881393 1;0.0375000014901161 0.4375 1;0.025000000372529 0.425000011920929 1;0.0125000001862645 0.412499994039536 1;0 0.400000005960464 1;0 0.387500017881393 0.987500011920929;0 0.375 0.975000023841858;0 0.362500011920929 0.962499976158142;0 0.349999994039536 0.949999988079071;0 0.337500005960464 0.9375;0 0.325000017881393 0.925000011920929;0 0.3125 0.912500023841858;0 0.300000011920929 0.899999976158142;0 0.287499994039536 0.887499988079071;0 0.275000005960464 0.875;0 0.262500017881393 0.862500011920929;0 0.25 0.850000023841858;0 0.237499997019768 0.837500035762787;0 0.225000008940697 0.824999988079071;0 0.212500005960464 0.8125;0 0.200000002980232 0.800000011920929;0 0.174999997019768 0.775000035762787;0 0.150000005960464 0.75;0 0.125 0.72;0 0.1 0.700000047683716;0 0.075 0.675;0 0.05 0.65;0 0.025 0.625;0 0 0.6]); 273 | %% Drawing cubes 274 | patch(x,y,z,colorp) %Back face 275 | hold on 276 | patch(x,yb,zb,colorp)%Bottom face 277 | patch(x,yb,zt,'w','FaceAlpha',0.02)%Top face,optional 'FaceColor','none' 278 | % patch(x,yf,z,'w','FaceAlpha',0.02) %Front face 279 | % hh=patch(x,yf,z,colorp); %Front face; 280 | hh=patch(xx,yy,z,colorp); 281 | uistack(hh,'bottom') 282 | bar=colorbar('Limits',[0 1.2],'XTick',[0:0.2:1.2],'XTickLabel',[0:0.2:1.2],'location','NorthOutside'); 283 | set(get(bar,'xlabel'),'String', 'Cell Velocity [m/s]');clear bar;%Velocity=Vmag 284 | bar=findobj(gcf,'Tag','Colorbar'); 285 | set(bar,'Position',[0.73 0.03 0.25 0.016]); 286 | hold off 287 | title(['Time=',num2str(round((time(round(t/Dt+1))/3600)*10)/10),' hours',' ','Egg diameter=',num2str(round(D(round(t/Dt+1))*10)/10),' mm'],'FontSize',fontsize) 288 | %% 289 | xlim([0 CumlDistance(Fcell)]); 290 | ylim([0 max(Width(1:Fcell))]); 291 | zlim([-max(Depth(1:Fcell)) 0]); 292 | % try 293 | % set(gca,'YTick',[0 round(max(Width(1:Fcell)))],'YTickLabel',[0 round(max(Width(1:Fcell)))]); 294 | % catch 295 | % end 296 | %% Aspect 297 | % zamp=0.07;%0.07 298 | % yamp=3;%3 299 | % daspect([0.1 yamp zamp]) 300 | % daspect([1 450 3000]) 301 | %% 302 | %daspect([1 20 1]) 303 | %daspect([1 80 3]) 304 | daspect('auto') 305 | grid off 306 | box on 307 | %view(3) 308 | %% 309 | xlabel('Distance in X(km)','FontSize',fontsize-1); 310 | ylabel('Width(m)','FontSize',fontsize-1); 311 | zlabel({'Depth (m)'},'FontSize',fontsize-1); 312 | set(gca,'FontSize',fontsize-1) 313 | %% 314 | 315 | end 316 | view([ca cel]) 317 | %% 318 | movegui(Videodata.hf) 319 | M(counter)=getframe(gcf); 320 | counter=counter+1; 321 | if t==0 322 | Message= msgbox('Your video is now being created. Please wait','FluEgg is creating the video','help'); 323 | pause(2.2) 324 | try 325 | delete(Message) 326 | catch 327 | %continue 328 | end 329 | end 330 | end 331 | 332 | [h, w, p] = size(M(1).cdata); 333 | % resize figure based on frame's w x h, and place at (8 scnsize(4)/2.6) 334 | try 335 | set(hf,'Position', [8 scnsize(4)/2.6 w h]); 336 | catch 337 | end 338 | axis off 339 | %% Save the movie 340 | handleResults=getappdata(0,'handleResults'); 341 | pathname=getappdata(handleResults,'pathname'); 342 | movie2avi(M,[pathname,'animation' '.avi'], 'compression', 'None','fps',2,'quality',100);%Saving the movie 343 | Message= msgbox('Your video is completed. It is available in the results folder','FluEgg','help'); 344 | pause(3) 345 | try 346 | delete(Message) 347 | catch 348 | %continue 349 | end 350 | delete(Videodata.hf) 351 | diary off 352 | 353 | function update(~, ~, handles) 354 | handleResults=getappdata(0,'handleResults'); 355 | ResultsSim=getappdata(handleResults,'ResultsSim'); 356 | time=ResultsSim.time;%seconds 357 | NoFrames=str2double(get(handles.Frames_edit,'String')); 358 | Time_step_frames=time(end)/3600/NoFrames;%hours 359 | set(handles.Display_text,'String',['The video will display one frame every ',sprintf('%.1f',Time_step_frames),' hour(s)']) 360 | % --- Executes on button press in Video_button. 361 | function Video_button_Callback(hObject, eventdata, handles) 362 | video(hObject, eventdata, handles); 363 | %close(handles.figure1); 364 | function EL_slider_Callback(hObject,~,~) 365 | [ca cel]=view; 366 | view([ca get(hObject,'value')]) 367 | % --- Executes on slider movement. 368 | function AZ_slider_Callback(hObject,~,~) 369 | [ca cel]=view; 370 | view([get(hObject,'value') cel]) 371 | 372 | % 373 | % function Aspect_Callback(hObject, eventdata, handles) 374 | % daspect([1 get(hObject,'value') 3]) 375 | % 376 | % 377 | --------------------------------------------------------------------------------