% =========================================================================
% READ ME FIRST
% =========================================================================
% (1) Be sure to enter your name, as a string, in the space below.
%     Do this now, before you forget.
% =========================================================================
% \/\/\/ ENTER YOUR NAME \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
my_name = '';
% /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
% =========================================================================
% (2) Most of the exam reqires answers (as MATLAB statements/code)
%     to be written in the spaces provided in this file.
%     If you like -- test your code at the command line,
%     and/or in a seperate m-file, before copying-pasting into this file
%     as your 'answer'.
%     The space provided in this file for the code to be inserted 
%     looks like:
% *** ANSWER  *************************************************************

% *************************************************************************
% =========================================================================
% (3) Where specified in a question, use the variable name requested.
%     i.e. a hypothetical question asking you to 
%     multiple 2 and 3 together and assign the answer to the variable A0 --
%     make sure that you do use the variable A0 (exactly as specified), eg
%     A0 = 2*3;
% =========================================================================
% (4) Some of the exam requires that an m-file to be created and saved.
%     Ensure that you use the name for the m-fie requested in the question.
%     Ensure that you rememeber to save the m-file to the USB drive.
% =========================================================================
% (5) Some of the exam (the GUI questions) may require both m- AND .fig
%     files to be created and saved.
%     Ensure that you use the name for the GUI requested in the question.
%     Ensure that you save BOTH the m- and .fig files to the USB drive.
% =========================================================================
% (6) For the longer questions (and longer code), the marks will generally
%     be structured so that some marks are possible for a partial or
%     incomplete answer, and that many of the marks will be available for
%     'relatively' simple first steps and tasks.
% =========================================================================
% (7) There are FIVE (5) sections in this exam:
%     (A) single line MATLAB statements -- 12 questions -- 20 marks total
%     (B) multiple (code) line answers  -- 3 questions  -- 30 marks total
%     (C) code debugging                -- 2 questions  -- 10 marks total
%     (D) creating short functions      -- 5 questions  -- 20 marks total
%     (E) creating Apps/GUIs            -- 4 questions  -- 20 marks total
%     IN ADDITION, up to 5 BONUS MARKS will be awarded for consistent and
%     sufficient code commenting and formatting
%     (excepting those sections that explicitly state that code
%     commenting and formatting is not necessary).
%     The potential maximum mark is hence 105 (out of 100).
%     SO COMMENT AND FORMAT YOUR CODE WELL (throughout) FOR FREE MARKS
% =========================================================================
% (8) Provided on this USB drive, are the following files:
%     * exam_geo111_20171208.m [this file]
%     * BANANAS_.pdf -- copy of the complete course text
%     * model_grid.txt -- model grid data file
%     * data_caco3.dat -- global sediment data file
%     * etheridge_etal_1996.txt -- historical CO2 data file
% =========================================================================
% (9) The exam is nominally TWO (2) hours in duration.
%     BUT, you are allowed to continue up to 5 pm (2 hours, 50 mins total)
%     if you wish.
%     Any and all paper (including books), and electronic, notes and files
%     are ALLOWED.
%     **NO** social media, 'phone, email, txt-ing, or other electronic
%     communication is allowed.
%     Resources on the course webpage and seaorg.or and seao2.info 
%     domain are ALLOWED.
%     Searches and pages on the mathworks domain, www.mathworks.com
%     are ALLOWED -- this domain encompasses full documentation of MATLAB
%     functions and extensive question/answer dsicussion board material.
%     DO NOT search and access material elsewhere on the internet ...
%     if ont becasue it will not likely be the most productive use 
%     of your time.
% =========================================================================
%
%
%
% *************************************************************************
% *** SECTION A ***********************************************************
% *************************************************************************
% This section requires SINGLE LINE answers (as MATLAB code).
% EXAMPLE:
% 'Write down the line of code that divides 10 by 5 and assigns the result
% to the variable A0'
% would have a code answer of:
% *** ANSWER  *************************************************************
A0 = 10/5;
% *************************************************************************
% NOTE: In this section -- it does not matter whether you include the ';' 
%       at the end of the line or not.
% *************************************************************************
%
% *** QUESTION 1 **********************************************************
% Write down the line of code that creates a COLUMN vector of 77 rows
% (by 1 column), with each element having a value of 0.0.
% Assign this to the variable A1.
% [1 mark]
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 2 **********************************************************
% Write down the line of code that creates a ROW vector of 77 columns
% (by 1 row), with each element having a value of 1.0.
% Assign this to the variable A2.
% [1 mark]
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 3 **********************************************************
% Write down the line of code that creates a 10x20 (10 rows, 20 columns)
% matrix, with each element having a value of pi/2.
% Assign this to the variable A3.
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 4 **********************************************************
% Write down the line of code that creates a vector of numbers from 
% 0 to -10 in steps of -1.
% Assign this to the variable A4.
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 5 **********************************************************
% Write down the line of code that takes the 4x3 matrix
% [1 5 9; 2 6 10; 3 7 11; 4 8 12]
% and turns it into a 1x12 row vector.
% Assign this to the variable A5.
% NOTE: use the relevant function ... do not simply write out the
% row vector directly ...
% HINT: a successfull answer vector will have all the digits arranged
% in ascending order.
% order
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 6 **********************************************************
% Write down the line of code that opens the file 'paleo_CO2_data.txt'
% (for subsequent data reading).
% Assign the returned file ID to the variable A6.
% HINT: The answer DOES NOT involve the function load.
% [1 mark]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 7 **********************************************************
% Write down the line of code that determines the total number of elements
% in variable A3.
% Assign the resulting number to the variable A6.
% HINT: There are multiple ways of doing this that you have seen,
% including the use of a specific MATLAB command (that you have seen).
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 8 **********************************************************
% Write down the line of code that joins together the following 2 strings:
% 'hello'
% 'kitty'
% BUT ... with a space inbetween the two words.
% Assign the resulting string to the variable A8.
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 9 **********************************************************
% Write down the line of code that tests whether the string contained in
% variable A8 is equivalent to the string 'hello catty'.
% Assign the result (which will be true or false) to the variable A9.
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 10 *********************************************************
% Write down the line of code that finds all occurrences
% (vector indices) of the letter 'l' in string A8. 
% Assign the result to the variable A10.
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 11 *********************************************************
% Write the line of code that creates a string comprising: 
% firstly, the string eqivalent of n, where
n = 10;
% and secondly, the word 'bananas'.
% Assign the result to the variable A11.
% NOTE: Do not simply write '10bananas'.
% NOTE: You can assume the value of n is already defined (as above).
% [1 mark]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 12 *********************************************************
% Write the line of code that finds all numbers greater than 5 in 
% your variable A5 (your answer to question 5).
% Assign the result (the numbers greater than 5) to the variable A12.
% NOTE: if you could not get question 5 to work out ... carry out the same
% exercise but use the matrix given in question 5 instead of variable A5.
% [2 marks]
%
% *** ANSWER  *************************************************************

% *************************************************************************
% *************************************************************************
% 
%
%
% *************************************************************************
% *** SECTION B ***********************************************************
% *************************************************************************
% This section requires you to write MULTIPLE LINES (as MATLAB code)
% as the answer in the space provided.
% NOTE: A single blank line is shown, but this is not an indication of
%       how many lines are required for the answer -- use as many lines
%       as you need/want.
% HINT: Test your code answer in an m-file before 
%       copying-pasting into the space provided.
% HINT: Some (or even most!) marks can be gained even if the code 
%       does not fully work as intended.
% [30 marks total for this section]
% *************************************************************************
%
% *** QUESTION 1 **********************************************************
% Write down code that will achieve the following:
% (i)   Load in the historical atmospheric CO2 data (ppm) vs. year, 
%       contained in the file: 'etheridge_etal_1996.txt'. [1 mark]
% (ii)  Convert the absolute CO2 values into a ratio with the 
%       pre-industrial CO2 value of 278 ppm.
%       (i.e. 556 would have a ratio of 2.0 compared to 278)
%       [2 marks]
% (iii) Open a new figure window, and
%       plot the CO2 ratio (y-axis) vs. year (x-axis). [1 marks]
% (iv)  Add on a horizontal line indicating the pre-industrial ratio
%       (i.e. y = 1.0). [2 marks]
% (v)   Add appropriate and sufficient figure annotation. [1 mark]
% NOTE: Your choice of plotting function and plot appearance. 
% [7 marks total]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 2 **********************************************************
% Write down code that will achieve the following:
% (i)   Load in the global dataset of the composition (% of carbonate)
%       in deep-sea sediments -- file: 'data_caco3.dat'. 
%       (See NOTE about data format at end.) [2 marks]
% (ii)  Open a new figure window, and
%       scatter plot the lon,lat locations of the data points, 
%       with axes spanning the complete globe. [3 marks]
% (iii) Make the color of the data points reflect the wt% CaCO3 value.
%       [2 marks]
% (iv)  Add appropriate and sufficient figure annotation. [1 mark]
% NOTE: The format of 'data_caco3.dat' is:
%       longitude (degrees East from zero) (column 1)
%       latitude (column 2)
%       'wt% CaCO3' (column 3)
% HINT: For (iii), you'll have to specify a data point size in the 
%       scatter function call, and which can be a simple scalar 
%       (i.e. a vactor is not needed for the point size specification).
% [8 marks total]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 3 **********************************************************
% Write down code that will achieve the following:
% (i)   Asks (i.e. prints the text), at the command line:
%       'Do you like Pokemon?' 
%       and waits for an input (keyboard response) [2 marks]
% (ii)  If the answer is 'yes' or 'YES' to teh first question,
%       then asks a second question: 
%       'What is your favourite Pokemon?' [2 marks]
% (iii) If the answer to the 2nd question is 'Eevee', then print:
%       'Me too!' [1 mark]
% (iv)  If the answer to the 2nd question is NOT 'Eevee',
%       OR the answer to 'Do you like Pokemon?' is not 'yes' or 'YES',
%       prints: 'too bad :(' [2 marks]
% [7 marks total]
%
% *** ANSWER  *************************************************************

% *************************************************************************
%
% *** QUESTION 4 **********************************************************
% Write down code that will achieve the following:
% (i)   Creates a figure window with no visible axes, and with 
%       axes that completely fill the window. [2 marks]
% (ii)  Draws a 8x8 grid of squares (of even size, filling the window).
%       [2 marks]
% (iii) Colors the squares in a checkboard pattern. [2 marks]
% (iv)  For coloring, two different colors of squares are:
%       (A) a light green (any shade, excepting the MATLAB 'g' color)
%       (B) some sort of orange
%       [2 marks]
% NOTE: If you cannot get the axes to compeltely fill the figure window,
%       just make sure there are no tick marks or labels visible.
% [8 marks total]
%
% *** ANSWER  *************************************************************

% *************************************************************************
% *************************************************************************
%
%
%
% *************************************************************************
% *** SECTION C ***********************************************************
% *************************************************************************
% This section requires you to bug-fix fragments of MATLAB code and 
% provide the edited, commented, and working code as your answer
% (in place of the buggy code).
% The buggy code is given in the 'ANSWER' space.
% NOTE: Your answer may be of a different number of lines in length
%       to the orignal. Take as many lines as you see necessary. 
% NOTE: For code 'improvements', be sure to include a comment as to 'why'
%       the change you made has been done.
% HINT: Debug and test in an m-file before copying-pasting back into
%       this m-file.
% [10 marks total for this section]
% *************************************************************************
%
% *** QUESTION 1 **********************************************************
% The following code is intended to load in the 2D model grid datafile:
% 'model_grid.txt' and display it.
% But ... it does not 'work' ... :(
% Carry out the following:
% (i)   Correct the code so that it loads in the dataset correctly. 
%       [1 mark]
% (ii)  Correct the code so that it plots correctly,
%       with the World the 'right way up'. [2 marks]
% (iii) Add any other improvements to the code that you think appropriate.
%       [1 mark]
% (iv)  Add any improvements to the plot that you think appropriate.
%       [1 mark]
% HINT: Improvements to the plot may include the color scale,
%       and could well involve a different plotting/visualization function
%       than the one used in the code fragment.
% [5 marks total]
%
% *** ANSWER  *************************************************************
load model_grid
% visualize this beast!
figure;
pcolor(MODEL_GRID);
xlabel('latitude');
xlabel('longitude');
%
% *** QUESTION 2 **********************************************************
% The following code is intended to plot 2 complete cosine waves
% (angle on the x-axis, and cosine(angle) on the y-axis),
% and then save the data (format: cosine of angle (2nd column) vs. 
% angle (1st column)).
% But ... it does not 'work' ... :(
% Carry out the following:
% (i)   Correct the code so that it plots what it should do and
%       that the plot is correctly annotated. [2 marks]
% (ii)  Save the data to an ASCII text file called 'C1.txt'. [2 marks]
% (iii) Add any other improvements to the code that you think appropriate.
%       [1 mark]
% [5 marks total]
%
% *** ANSWER  *************************************************************
A = 0:10:720
B = sine(A)
figure
plot(A,B)
% *************************************************************************
%
%
%
% *************************************************************************
% *** SECTION D ***********************************************************
% *************************************************************************
% This section requires you to create an m-file function
% and save this to the USB drive as your 'answer'.
% NOTE: DO NOT paste the code into *this* file.
% HINT: Some (or even most!) marks can be gained even if the function 
%       does not fully work as intended.
% [20 marks total for this section]
% *************************************************************************
%
% *** QUESTION 1 **********************************************************
% Create and save a function, called 'D1', with the following properties:
% (i)   It takes as input, a single number. [1 mark]
% (ii)  It returns the negative of that number. [1 mark]
% [2 marks total]
%
% *** QUESTION 2 **********************************************************
% Create and save a function, called 'D2', with the following properties:
% (i)   It takes as input, an angle in degrees. [1 mark]
% (ii)  It returns the angle in radians. [1 mark]
% (iii) If the input angle is greater than or equal to 360 degrees, 
%       or less than zero, the angle is converted to an equivalent value
%       in the range 0-360 before conversion to radians and returning the
%       function value.
%       i.e. 361 degrees would be treated as 1 degree,
%            and -60 as 300, for the purpose of conversion 
%       [2 marks]
% [4 marks total]
%
% *** QUESTION 3 **********************************************************
% Create and save a function, called 'D3', with the following properties:
% (i)   It takes as input, a string. [1 mark]
% (ii)  It returns (as a numeric value) the total number of characters 
%       in the string. [2 marks]
% [3 marks total]
%
% *** QUESTION 4 **********************************************************
% Create and save a function, called 'D4', with the following properties:
% (i)   It takes as input, two numbers. [2 marks]
% (ii)  It returns the greater of the two numbers. [2 marks]
% [4 marks total]
%
% *** QUESTION 5 **********************************************************
% Create and save a function, called 'D5', with the following properties:
% (i)   It takes as input, a number (assumed to be an integer). [1 mark]
% (ii)  It returns the factorial of that number. [6 marks]
% NOTE: The factorial of a number, n, is:
%       the "product of all positive integers less than or equal to n".
%       ('product' meaning 'multiple together')
% NOTE: DO NOT use the MATLAB factorial function ...
% HINT: You may need to use a loop instead.
% [7 marks total]
%
% *************************************************************************
% *************************************************************************
%
%
%
% *************************************************************************
% *** SECTION E ***********************************************************
% *************************************************************************
% This section requires you to create (using the MATLAB GUIDE GUI App) 
% a series of Apps (GUIs) (the required specifications of which, 
% are listed).
% Save the resulting m-file and .fig file to the USB drive 
% (using the specified filename).
% NOTE: DO NOT paste the code into this *file*.
% HINT: Some (or even most!) marks can be gained even if the App does not 
%       fully work as intended.
% [20 marks total for this section]
% *************************************************************************
%
% *** QUESTION 1 **********************************************************
% Create an App, called 'E1', with the following properties:
% (i)   A single Push Button, labelled 'CLOSE ME'. [1 mark]
% (ii)  That when you click on the push button with the mouse,
%       the App ends (window closes). [3 marks]
% [4 marks total]
%
% *** QUESTION 2 **********************************************************
% Create an App, called 'E2', with the following properties:
% (i)   A single Push Button, labelled 'CLICK ME'. [1 mark]
% (ii)  That when you click on the push button with the mouse,
%       the label on the button changes to 'YOU CLICKED ME!'. [3 marks]
% (iii) That if you click on it once more (i.e. a 2nd time),
%       the label on the button changes to 'PLEASE STOP CLICKING ME :('. 
%       [2 marks]
% [6 marks total]
%
% *** QUESTION 3 **********************************************************
% Create an App, called 'E3', with the following properties:
% (i)   A single, Slider. [1 mark]
% (ii)  A single, Static Text box. [1 mark]
% (iii) That when you move the slider, the text in the Static Text box
%       changes to reflect the value of the slider. [3 marks]
% [5 marks total]
%
% *** QUESTION 4 **********************************************************
% Create an App, called 'E4', with the following properties:
% (i)   2 Push Buttons, labelled 'CLICK ME' and 'CLICK ME NEXT'. [2 marks]
% (ii)  That when you have clicked on BOTH buttons (one after another), 
%       the App ends (i.e. window closes). [3 marks]
% [5 marks total]
%
% *************************************************************************
% *************************************************************************
%
%
%
% =========================================================================
% =========================================================================
% END OF EXAM --- READ ME LAST
% =========================================================================
% CHECK that you have entered your name (string) at the top of this file.
% CHECK that for the questions requiring an m-file, it is saved to the USB.
% CHECK that for the questions requiring an m-file AND a .fig file,
%       that they are both saved to the USB drive.
% !!!CHECK!!! that you SAVED all this (answers) file before leaving ...
% =========================================================================
% =========================================================================
