% Database of ocean ages:
%  Muller, R.D., M. Sdrolias, C. Gaina, and W.R. Roest 2008. Age, spreading rates and 
%   spreading symmetry of the world's ocean crust, Geochem. Geophys. Geosyst.,
%    9, Q04006, doi:10.1029/2007GC001743.
% avaliable through the NOAA data center: http://www.ngdc.noaa.gov/mgg/ocean_age/ocean_age_2008.html
%


%this is a script to show you how to access information in Muller's
% compilation of ocean age.  The data base is in the form of a large
% matrix. Each line has a longitude, lattitude, age (Ma) and age
% uncertainty (Ma).  Each line increments lattitudes and longitudes in .1
% degree steps.  Here are the first four lines of the matrix:  
%       Longitude       Latitude   Age(Ma)       Age Uncertianty(Ma)
%         -180           90       55.569           15
%       -179.9           90       55.569           15
%       -179.8           90       55.568           15
%       -179.7           90       55.568           15      
% There are a total of 6,485,401 lines.  So this is a big matrix that will
% fill up a lot of computer memory if you load it and any search of it is
% going to take some time.   I give below an example of how you can search
% the data base to find ages and age uncertainties for a collection of
% lattudes and longitudes.

% Here are some test locations where I want to know the ages:
 latdata=[ 40 40 40 40 40 40 ];
 longdata=[-130 -129 -128 -127 -126 -125 ];
 npts=length(latdata);  %need to know the number of points I have
 
 % now set up a couple variables to put ages and uncertainties into
 agedata=zeros(1,npts);
 uncertdata=agedata;
 
% Now I need to load the big file.  Expect this to be slow:

load ages

% the search assumes that the lats and longs are given only to the nearest
% 0.1 degree so that there is an exact match.  The loop searches the data
% base for each of your points:

 for i=1:npts,
     id=find(age(:,1)==longdata(i) & age(:,2)==latdata(i));
     agedata(i)=age(id,3);
     uncertdata(i)=age(id,4);
 end
 
 
 
 %%%
 % I've added a function that plots x and y uncertainties:
 % given x, dx, y and dy
 % plot the data point with a symbol:
 %     plot(x,y,'o')
 % now add the x and y errorbars:
 %     hold on % need to hold the plotted symbols
 %     errorbarxy(x,y,dx,dy)
 %     hold off
 % There you have it