Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
global start
global default_dataset
global filename
global skip_frame
global delay
global speed
global colourmap
global closeit
global menu_items
%video source (tutorial for the interative menu)
%https://www.youtube.com/watch?v=zLb4ZHFfbO0&ab_channel=Introductiontoprogramminganddataprocessing
%tutorial to read and display nc files
%https://uk.mathworks.com/matlabcentral/answers/282679-how-open-a-nc-file-in-matlab
%create the options for the menu function
menu_items = {'Visualize Data', 'Read guide', 'Quit the program'};
while true
%pass the arguments for the menu function and display
choice = show_menu(menu_items);
%visualize data
if choice == 1
data_display()
%read the instructions
elseif choice == 2
%need to create instructions
%quit
elseif choice == 3
break
end
end
function num = inputNumber(prompt)
while true
num = str2double(input(prompt, 's')); %asks the user for input and converts it to a number
if ~isnan(num) %if it's a number
break;
end
end
end
function choice = show_menu(options)
%show the options the user has for the menu
for i = 1:length(options)
fprintf('%d. %s\n', i, options{i});
end
%retrieve the valid choice
choice = 0;
while ~any(choice == 1:length(options))
choice = inputNumber('Please choose a menu interaction ');
end
end
function data_display()
%default the program to be playing from start (0 = paused)
start = 1;
%if values of program_exit turns 1, exits program
program_dispose = 0;
%if the value is 1, it will skip frame by frame
skip_frame = 0;
%how fast the frames will be skipped
speed = 0;
%the delay of the frames
delay = 0;
%assigns the file comb.nc to a variable
filename = "Comb.nc";
default_dataset = 'silam_ozone'; %default dataset, first to show
%read the file and set variables to hold x and y values (latitude and
%longitude)
latitude = ncread(filename, 'lat'); %reads latitude data
yax = length(latitude); % latitude set to y axis
longitude = ncread(filename, 'lon'); %reads longitude data
xax = length(longitude); % longitude set to x axis
time = ncread(filename,'hour') ; %reads the time
%create the interface properties
interface()
while program_dispose == 0
for i = 1:length(time)
current_hour = "Current Hour: " + (i-1); %displays current hour
%we can call uicontrol to control our labels properties (interactive buttons)
uicontrol( 'Position', [20 380 100 30],'String',current_hour,'Callback',@(src,evnt)none);
if start == 1 %by default
if (speed == 1) && (mod(i,2) == 0)
z = ncread(filename,default_dataset,[1 1 i],[xax yax 1]) ; %reads and plots the lon and lat data
pcolor(longitude,latitude,z') ; %Colors the displayed data
shading interp %Sets color shading properties
drawnow %updates the figures and process callbacks
pause(delay) %stops the execution for a specific delay
end
if (speed == 0)
z = ncread(filename,default_dataset,[1 1 i],[xax yax 1]) ;
pcolor(longitude,latitude,z') ;
shading interp
drawnow
pause(delay)
end
else
while start == 0
current_hour = "start 0 Hour: " + (i-1);
uicontrol( 'Position', [20 380 100 30],'String',current_hour,'Callback',@(src,evnt)none);
z = ncread(filename,default_dataset,[1 1 i],[xax yax 1]) ;
pcolor(longitude,latitude,z') ;
shading interp
drawnow
if skip_frame == 1 %when on pause and if skip_frame is pressed, it will skip one frame and change its value right after
skip_frame = 0; %now set the value to zero to stop the frame from skipping
if i < length(time) %skip the frame by 1
i = i + 1;
else
i = 1; %resets the frame count
end
end
end
end
end
end
function faster()
if delay == 0 %if no delay exists
if speed ~= 1 %If multiplier of speed is different from 1
speed = speed + 1; %changes the speed value to a higher value
end
else
delay = delay - 0.1; % decrease delay by 0.1
end
end
function slower()
if speed == 0
delay = delay + 0.1; %sets a small delay of 0.1
else
speed = speed - 1; %decreases the speed
end
end
function interface()
colourmap = 0; %default colour map
bp = 'silam_ozone'; % The default dataset
f = figure; %variable "f" will hold the figure properties
f.Resize='off'; %this will disable resizing of the window
dataset = ["chimere_ozone","emep_ozone","ensemble_ozone","lotoseuros_ozone","match_ozone","mocage_ozone","silam_ozone"];
for d = 1:length(dataset) %displays the buttons to change the dataset
uicontrol( 'Position', [440 (d*45) 100 30],'String',dataset(d),'Callback',@(src,evnt)buttonCallback(dataset(d)) );
end
%Calls the function pause, to temporarily stop the loop from executing
uicontrol('Position', [250 380 60 30],'String','Pause','Callback',@(src,evnt)pause);
%Calls the function play, to resume the loop execution
uicontrol('Position', [140 380 100 30],'String','Resume','Callback',@(src,evnt)start_function);
%Calls the skipping_frame function, to move to the next frame
uicontrol('Position', [320 380 60 30],'String','Skip Frame','Callback',@(src,evnt)skipping_frame);
%Calls the exit function, this stops the program completely
uicontrol('Position', [440 380 100 30],'String','Exit','Callback',@(src,evnt)exit);
%Calls the slower function, slowing down how fast every frame is displayed
uicontrol('Position', [140 45 60 30],'String','Slower','Callback',@(src,evnt)slower);
%Calls the faster function, accelarating how fast every frame is displayed
uicontrol('Position', [210 45 60 30],'String','Faster','Callback',@(src,evnt)faster);
%Calls the colour blind function, changes the colours of every frame
%to match the specific colour blind mode
uicontrol('Position', [20 45 100 30],'String','Colour Blind','Callback',@(src,evnt)colour_map);
function skipping_frame()
skip_frame = 1; %changes the value of the skip frame to 1, moving to the next frame
end
function pause()
start = 0; %By setting start to zero the execution stops
end
function start_function()
start = 1; %By setting start to one the execution resumes
end
function buttonCallback(newString)
bp = newString;
default_dataset = bp; %sets the default_dataset to be equal to bp (default map)
end
function colour_map() %Loop through colour maps and setting the map choice to that specific selected colour map
if colourmap == 0
colormap copper
colourmap = 1;
elseif colourmap == 1
colormap gray
colourmap = 2;
elseif colourmap == 2
colormap bone
colourmap = 3;
elseif colourmap == 3
colormap jet
colourmap = 4;
elseif colourmap == 4
colormap autumn
colourmap = 5;
elseif colourmap == 5
colormap winter
colourmap = 6;
elseif colourmap == 6
colormap hot
colourmap = 7;
elseif colourmap == 7
colormap default
colourmap = 0;
end
end
function exit()
start = 1; %stops the busy waiting loop
program_dispose = 1; %stops the main loop
close all %Closes all windows
end
end
end