function [stages, vs, straw]=geologicstages()
%[stages, version, raw stage data] = GeologicStages
%May be called with 1, 2 or 3 outputs requested.
%   
%This function is called by geowhen, geolist, and geotimeline to load
%the geologic record.  It is expected that most common uses of this information
%can be accessed through one of those helper functions rather than by using this
%array directly.
%  
%This function provides a array data structure "stages" which contains compiled
%information on the geologic time scale with the following fields:  
%
%	Name:             The principal name for the stage
%	AKA:              A cell array of strings which are aliases for this stage
%	Start:            Approximate start date of the stage (Ma)
%	End:              Approximate end date of the stage (Ma)
%	dStart:           Error in the start value
%	dEnd:             Error in the end value
%	Category:         Category of time period
%	Start_Defined_By: Indicator event/fossil defining the start of stage
%	End_Defined_By:   Indicator event/fossil defining the end of stage
%	Start_Source:     Reference for the start date and error
%	End_Source:	      Reference for the end date and error
%	GSSP:             Global Stratotype information
%	Comment:          Any additional comments regarding this stage.
%
%Note that the errors may be reported as a single value indicating a +/- uncertainty
%or they may be an array of two numbers giving seperate positive and negative errors.
%
%
%The version number is a unique identifier to keep track of updates and changes made
%as new information and better dates become available.
%
%The "raw stage data" returns a array with the same fields as above, but
%the relative dependancies have not been expanded, and hence many stages will have
%start and end fields that reference the following or preceeding stage as the 
%record holding the date and boundary information.  In practice this information
%is only rarely of interest.


%%%%%%%%%%%%%%%%%%%%%
%% Design Comments %%
%%%%%%%%%%%%%%%%%%%%%

%This archive is intended to serve as the basis for teaching MATLAB about the 
%geologic timescale.  It provides the data structure on which other functions
%are built to interpret or display this information in ways that are convenient
%and useful to the user.

%In designing this archive I have taken care to make it relatively easy to edit,
%and in particular ensure that boundaries which are shared at the start or end
%of multiple different divisions are referenced to each other so that the specific
%date is defined at only one location that each record looks to.  Hence changing
%one number updates all of the stages tied to that date.

%The dates given are typically those taken from the lists used as source material,
%and have unknown errors, except for major boundaries where specific reference
%material is given.  Also "faunal stages" (ie. those defined by the presence of
%certain fauna) at times have ages which are merely given as interpolations
%between known ages.  In general the smallest stages have the least certain dates,
%and may even be uncertain in their ordering and position relative to other stages.
%The longer stages are generally more well defined.

%In case of conflict between various lists the International Commision on
%Stratigraphy is given precedence, followed by the lists which are the most
%detailed and professionally documented.

%Additional stages should be added to this file by placing them under the
%appropriate category heading, and then by age (or stratographic group then age
%if their are competing divisions of the same time block).  Use of the predefined
%local functions is strongly recommended.


%%%%%%%%%%%%%%%%%%
%%  Authorship  %%
%%%%%%%%%%%%%%%%%%

%This database was constructed by Robert A. Rohde

%Last Modified: 3/9/2004

%To contact the author regarding additions, corrections, modifications,
%write to geowhen@robertrohde.com.  Please include the information on the
%stage(s) you want to change and any reference material to support those
%changes.  The latest version can also be obtained by emailing the above
%address.

%%%%%%%%%%%%%%%%%%%%%%%
%% Beginning of Code %%
%%%%%%%%%%%%%%%%%%%%%%%

%Defines the data structure used in constructing the stage list.
%Made global so that local functions can access it directly.
global GL_STAGES;
GL_STAGES = struct('Name',[],'Start',[],'End',[],'Category',[],...
   'dStart',[],'dEnd',[],'AKA',[],'Start_Defined_By',[],'Start_Source',...
   [],'End_Defined_By',[],'End_Source',[],'GSSP',[],'Comment',[]);

%Unique version identifier.  The first digit indicates major versions,
%the second indicates minor versions, and the last changes any time
%this file is updated (even if trivially so).
version = '1.0.0';

%If called with no outputs, display version ID.
if nargout == 0
	disp(' ');
	disp('  Geologic Stages Database  ');
	disp(' ');
	disp(['       Version ' version]);
	disp(' ');
	return;
end

%%%%%%%%%%%%%%%%%%%%%%%%
%  Stage List Sources  %
%%%%%%%%%%%%%%%%%%%%%%%%

% A list of references used in getting names and relative placements of stages.

%Harland et. al., _A Geologic time scale 1989_, Cambridge University Press:New York, 1990.
%Harland et. al., _Geologic time scale_, Cambridge University Press:New York, 1982.
%Gradstein, Ogg, Smith, et. al., _A Geologic Time Scale 2004_, Cambridge University Press:New York, 2004.
%"Overview of Global Boundary Stratotype Sections and Points", ICS,
%   http://micropress.org/stratigraphy/gssp.htm
%Paleobiology Database Conversion Table
%   http://www.paleodb.org/
%Palaeos: http://www.palaeos.com/
%"Phanerozoic Geologic Time Scale", http://uk.cambridge.org/resources/0521538424/files/figureA.pdf
%International Commission on Stratigraphy: http://www.stratigraphy.org/
%_Atlas of Life on Earth_, Barnes & Noble Books, 2001.
%Gradstein and Ogg, A Phanerozoic time scale.  _Episodes_, v.19, no.1&2., 1996.
%Haq and Eysinga, _Geological Time Table_, Elsevier Science, 1998. 
%Palmer and Geissman, 1999 Geologic Time Scale, Geological Society of America, 1999. 

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%  Date Sources  %%%%
%%%%%%%%%%%%%%%%%%%%%%%%

%Variables are used so that the reference may be easily attached to multiple
%stages.

ICS = 'Gradstein, Ogg, Smith, et. al., _A Geologic Time Scale 2004_';
SolarForm = 'Amelin, Krot, Hutcheon, and Ulyanov, "Lead Isotopic Ages of Chondrules and Calcium-Aluminum-Rich Inclusions", _Science_, Sept. 6, 2002.';
Cm = 'Amthor et. al., "Extinction of Cloudinia and Namacalathus at the Precambrian-Cambrian boundary in Oman", _Geology_, v. 31, p. 431-434, 2003.';
C14 = 'CALIB Radiocarbon Calculator version 4.4 using INTCAL98 calibration curve.';
GO96 = 'Gradstein and Ogg, "A Phanerozoic time scale", _Episodes_, v.19, no.1&2., 1996.';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Start of Geologic Timescale Entries %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%References that refer to other stages must take the form
%Start = '<Name>.Start' or '<Name>.End', or
%End = '<Name>.Start' or '<Name>.End', where
%<Name> is the primary name of the stage (NOT an alias).

%The following helper functions are defined for adding information to
%the data array: AddStage, AddAKA, AddError, AddDef, AddComment, AddSource, AddGSSP
%Information about these functions are avaiable at the end of this file.
%It is recommended that one inspect the formatting of records shown below and
%try to maintain it before adding any additional records.

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%      Eons      %%%%
%%%%%%%%%%%%%%%%%%%%%%%%
AddStage('Hadean',4567.17,'Archean.Start','Eon');
AddError(0.7);
AddAKA('Priscoan','Azoic');
AddDef('Formation of Earth');
AddComment('Start date reflects earliest CAIs formation, at the birth of the solar system.  The Hadean is not officially recognized ICS nomenclature.');
AddSource(SolarForm);
AddStage('Archean',3800,'Proterozoic.Start','Eon');
AddAKA('Archeozoic')
AddComment('The base of the Archean is not formally defined by the ICS.');
AddStage('Proterozoic',2500,'Phanerozoic.Start','Eon');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Phanerozoic',542.0,(1950-now/365.25)/1e6,'Eon');
AddDef('Trace fossil, lowest occurrence of Treptichnus (Phycodes) pedum.  Near base of negative carbon-isotope excursion.','Today (in Myr before 1950)');
AddSource(Cm);
AddError(0.3,0);
AddStage('Precambrian','Hadean.Start','Cambrian.Start','Time');
AddAKA('Cryptozoic','Primordial');
AddComment('Cryptozoic is sometimes identified as excluding the Hadean');

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%      Eras      %%%%
%%%%%%%%%%%%%%%%%%%%%%%%

%Archean
AddStage('Eoarchean','Archean.Start','Paleoarchean.Start','Era');
AddComment('Base of the Eoarchean is not formally defined by the ICS.');
AddStage('Paleoarchean',3600,'Mesoarchean.Start','Era');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Mesoarchean',3200,'Neoarchean.Start','Era');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Neoarchean',2800,'Archean.End','Era');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);

%Proterozoic
AddStage('Paleoproterozoic','Proterozoic.Start','Mesoproterozoic.Start','Era');
AddStage('Mesoproterozoic',1600,'Neoproterozoic.Start','Era');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Neoproterozoic',1000,'Proterozoic.End','Era'); 
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);

%Phanerozoic
AddStage('Paleozoic','Phanerozoic.Start','Mesozoic.Start','Era');
AddAKA('Primary');
AddStage('Mesozoic',251.0,'Cenozoic.Start','Era');
AddDef('Conodont, lowest occurrence of Hindeodus parvus; termination of major negative carbon-isotope excursion.  About 1 myr after peak of Late Permian extinctions.');
AddSource(ICS);
AddError(0.4);
AddAKA('Secondary');
AddStage('Cenozoic',65.5,'Phanerozoic.End','Era');
AddDef('Iridium Anomaly.  Associated with a major extinction horizon (foraminifers, calcareous nannofossils, dinosaurs, etc.)');
AddError(0.3);
AddSource(ICS);

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%    Sub-eras    %%%%
%%%%%%%%%%%%%%%%%%%%%%%%
AddStage('Tertiary','Cenozoic.Start','Quaternary.Start','Sub-era');
AddStage('Quaternary',1.806,'Cenozoic.End','Sub-era'); 
AddComment(['Quaternary is not a formally recognized ICS chronostratigraphic unit,' ...
	' however it is traditionally associated with the Holocene and Pleistocene.  An ',...
	'alternative definition sets the Quaternary as the start of North Pole glaciations ',...
	'circa 2.5 Ma.  In which case it includes part of the Pliocene.']);
AddDef(['Just above top of magnetic polarity chronozone C2n (Olduvai) and the extinction level of calcareous nannofossil Discoaster brouweri (base Zone CN13).  Above are lowest occurrence of calcareous nannofossil medium Gephyrocapsa spp. ',...
	'and extinction level of planktonic foraminifer Globigerinoides extremus.']);
AddSource(ICS)
AddError(0.005);

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%     Periods    %%%%
%%%%%%%%%%%%%%%%%%%%%%%%

%Proterozoic
AddStage('Siderian','Paleoproterozoic.Start','Rhyacian.Start','Period');
AddStage('Rhyacian',2300,'Orosirian.Start','Period');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Orosirian',2050,'Statherian.Start','Period');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Statherian',1800,'Paleoproterozoic.End','Period');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Calymmian','Mesoproterozoic.Start','Ectasian.Start','Period');
AddStage('Ectasian',1400,'Stenian.Start','Period');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Stenian',1200,'Mesoproterozoic.End','Period');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Tonian','Neoproterozoic.Start','Cryogenian.Start','Period');
AddStage('Cryogenian',850,'Ediacaran.Start','Period');
AddSource(ICS);
AddDef('Fixed Date');
AddError(0);
AddStage('Ediacaran',600,'Neoproterozoic.End','Period');
AddDef('Termination of Varanger (or Marinoan) glaciation, and distinctive C-13 change.');
AddAKA('Ediacarian','Neoproterozoic III');
AddComment('Exact date and boundary is grossly uncertain at present.  This stage replaces "Neoproterozoic III".');
AddSource(ICS);

%Paleozoic
AddStage('Cambrian','Paleozoic.Start','Ordovician.Start','Period');
AddStage('Ordovician',488.3,'Silurian.Start','Period');
AddDef('Conodont, lowest occurrence of Iapetognathus fluctivagus; just above base of Cordylodus lindstromi conodont Zone.  Just below lowest occurrence of planktonic graptolites.');
AddSource(ICS);
AddError(1.7);
AddStage('Silurian',443.7,'Devonian.Start','Period');
AddDef('Graptolites, lowest occurrences of Parakidograptus acuminatus and Akidograptus ascensus.');
AddError(1.5);
AddSource(ICS);
AddStage('Devonian',416.0,'Carboniferous.Start','Period');
AddDef('Graptolite, lowest occurrence of Monograptus uniformis.');
AddError(2.8);
AddSource(ICS);
AddStage('Carboniferous',359.2,'Permian.Start','Period');
AddDef('Conodont, above lowest occurrence of Siphonodella sulcata.');
AddSource(ICS);
AddError(2.5);
AddStage('Permian',299.0,'Paleozoic.End','Period');
AddError(0.8)
AddSource(ICS);
AddDef('Conodont, lowest occurrence of Streptognathodus isolatus within the S. "wabaunsensis" conodont chronocline.  6 m higher is lowest fusilinid foraminifer Sphaeroschwagerina.');

%Mesozoic
AddStage('Triassic','Mesozoic.Start','Jurassic.Start','Period');
AddStage('Jurassic',199.6,'Cretaceous.Start','Period');
AddError(0.6);
AddSource(ICS);
AddDef('Near lowest occurrence of smooth Psiloceras planorbis ammonite group.');
AddStage('Cretaceous',145.5,'Mesozoic.End','Period');
AddError(4.0);
AddSource(ICS);
AddDef('Maybe near lowest occurrence of ammonite Berriasella jacobi.');

%Cenozoic
AddStage('Paleogene','Tertiary.Start','Neogene.Start','Period');
AddStage('Neogene',23.03,'Tertiary.End','Period');
AddDef('Base of magnetic polarity chronozone C6Cn.2n; lowest occurrence of planktonic foraminifer Paragloborotalia kugleri; near extinction of calcareous nannofossil Reticulofenestra bisecta (base Zone NN1).');
AddError(0.05);
AddSource(ICS);
AddStage('Pleistogene','Quaternary.Start','Quaternary.End','Period');

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%     Epochs     %%%%
%%%%%%%%%%%%%%%%%%%%%%%%

%Cambrian
AddStage('Early Cambrian','Cambrian.Start','Middle Cambrian.Start','Epoch');
AddAKA('Lower Cambrian','Caerfai','Waucoban');
AddGSSP('Chapel Island Formation, Fortune Head, Burin Peninsula, southeast Newfoundland, Canada');
AddStage('Middle Cambrian',513.0,'Late Cambrian.Start','Epoch');
AddAKA('St. David''s','Albertian','Saint David''s');
AddError(2.0);
AddSource(ICS);
AddStage('Late Cambrian',501.0,'Cambrian.End','Epoch');
AddAKA('Upper Cambrian','Merioneth','Furongian','Croixian');
AddError(2.0);
AddDef('Trilobite, lowest occurrence of agnostoid Glyptagnostus reticulatus.  Coincides with base of large positive carbon-isotope excursion.');
AddSource(ICS);

%Ordovician
AddStage('Early Ordovician','Ordovician.Start','Middle Ordovician.Start','Epoch');
AddAKA('Lower Ordovician','Canadian');
AddStage('Middle Ordovician',471.8,'Late Ordovician.Start','Epoch');
AddError(1.6)
AddSource(ICS);
AddAKA('Dyfed');
AddDef('Conodont, potentially lowest occurrence of Protoprioniodus aranda or of Baltoniodus triangularis.');
AddStage('Late Ordovician',460.9,'Ordovician.End','Epoch');
AddSource(ICS);
AddError(1.6);
AddAKA('Upper Ordovician','Bala','Balan');
AddDef('Graptolite, lowest occurrence of Nemagraptus gracilis.');

%Silurian
AddStage('Early Silurian','Silurian.Start','Late Silurian.Start','Epoch');
AddAKA('Lower Silurian');
AddStage('Late Silurian',422.9,'Silurian.End','Epoch');
AddError(2.5);
AddSource(ICS);
AddAKA('Upper Silurian');
AddDef('Imprecise.  Just below base of local acritarch Leptobrachion longhopense range zone.  May be near base of Neodiversograptus nilssoni graptolite zone.');

%Devonian
AddStage('Early Devonian','Devonian.Start','Middle Devonian.Start','Epoch');
AddAKA('Lower Devonian','Helderbergian');
AddDef('Graptolite, lowest occurrence of Monograptus uniformis.');
AddStage('Middle Devonian',397.5,'Late Devonian.Start','Epoch');
AddError(2.7);
AddSource(ICS);
AddAKA('Cazenovian');
AddDef('Conodont, lowest occurrence of Polygnathus costatus partitus; major faunal turnover.');
AddStage('Late Devonian',385.3,'Devonian.End','Epoch');
AddAKA('Upper Devonian');
AddError(2.6);
AddSource(ICS);
AddDef('Conodont, lowest occurrence of Ancyrodella rotundiloba (defines base of Lower Polygnathus asymmetricus conodont Zone).');

%Carboniferous
AddStage('Mississippian','Carboniferous.Start','Pennsylvanian.Start','Epoch');
AddAKA('Lower Carboniferous','Early Carboniferous','Dinantian');
AddStage('Pennsylvanian',318.1,'Carboniferous.End','Epoch');
AddAKA('Upper Carboniferous','Late Carboniferous','Silesian');
AddDef('Conodont, lowest occurrence of Declinognathodus nodiliferus s.l.');
AddSource(ICS);
AddError(1.3);

%Permian
AddStage('Early Permian','Permian.Start','Middle Permian.Start','Epoch');
AddAKA('Lower Permian','Rotliegendes','Cisuralian','Xixianian');
AddStage('Middle Permian',270.6,'Late Permian.Start','Epoch');
AddAKA('Guadalupian');
AddSource(ICS);
AddError(0.7);
AddDef('Conodont, lowest occurrence of Jinogondolella nanginkensis.');
AddComment('In two Epoch models of the Permian, the entire Middle Permian is added to the Late Permian.');
AddStage('Late Permian',260.4,'Permian.End','Epoch');
AddError(0.7);
AddSource(ICS);
AddAKA('Upper Permian','Zechstein','Lopingian','Tatarian');
AddDef('Near lowest occurrence of conodont Clarkina postbitteri.');
AddComment('In two Epoch models of the Permian, the entire Middle Permian is added to the Late Permian.');

%Triassic
AddStage('Early Triassic','Triassic.Start','Middle Triassic.Start','Epoch');
AddAKA('Lower Triassic','Buntsandstein','Scythian');
AddStage('Middle Triassic',245.0,'Late Triassic.Start','Epoch');
AddError(1.5);
AddSource(ICS);
AddAKA('Muschelkalk');
AddDef('Ammonite, near lowest occurrences of genera Japonites, Paradanubites, and Paracrochordiceras; and of the conodont Chiosella timorensis.');
AddStage('Late Triassic',228.0,'Triassic.End','Epoch');
AddError(2.0);
AddSource(ICS);
AddAKA('Upper Triassic','Keuper');
AddDef('Near first occurrence of the ammonoids Daxatina or Trachyceras, and of the conodont Metapolygnathus polygnathiformis.');

%Jurassic
AddStage('Early Jurassic','Jurassic.Start','Middle Jurassic.Start','Epoch');
AddAKA('Lower Jurassic','Lias','Ziliujinguan');
AddStage('Middle Jurassic',175.6,'Late Jurassic.Start','Epoch');
AddError(2.0);
AddSource(ICS);
AddAKA('Dogger');
AddDef('Ammonite, lowest occurrence of Leioceras genus.');
AddStage('Late Jurassic',161.2,'Jurassic.End','Epoch');
AddError(4.0);
AddSource(ICS);
AddAKA('Upper Jurassic','Malm','Morrisonian');
AddDef('Ammonite, Brightia thuouxensis Horizon at base of the Cardioceras scarburgense Subzone (Quenstedtoceras mariae Zone).')

%Cretaceous
AddStage('Early Cretaceous','Cretaceous.Start','Late Cretaceous.Start','Epoch');
AddAKA('Lower Cretaceous','Durango');
AddStage('Late Cretaceous',99.6,'Cretaceous.End','Epoch');
AddError(0.9);
AddSource(ICS);
AddAKA('Upper Cretaceous','Gulfian','Austinian','Eagle Fordian');
AddDef('Planktonic foraminifer, lowest occurrence of Rotalipora globotruncanoides.');

%Paleogene
AddStage('Paleocene','Paleogene.Start','Eocene.Start','Epoch');
AddStage('Eocene',55.8,'Oligocene.Start','Epoch');
AddError(0.2);
AddSource(ICS);
AddDef('Base of negative carbon-isotope excursion.');
AddAKA('Clairbornean');
AddStage('Oligocene',33.9,'Paleogene.End','Epoch');
AddError(0.1);
AddSource(ICS);
AddAKA('Midwayan');
AddDef('Planktonic foraminifer, extinction of Hantkenina.');

%Neogene
AddStage('Miocene','Neogene.Start','Pliocene.Start','Epoch');
AddStage('Pliocene',5.332,'Neogene.End','Epoch');
AddDef(['Top of magnetic polarity chronozone C3r, ~100 kyr before Thvera normal-polarity subchronozone (C3n.4n).  ',...
	'Calcareous nannofossils -- near extinction level of Triquetrorhabdulus rugosus (base Zone CN10b) and the lowest occurrence of Ceratolithus acutus.']);
AddSource(ICS);
AddError(0.005);

%Quaternary
AddStage('Pleistocene','Pleistogene.Start','Holocene.Start','Epoch');
AddStage('Holocene',0.01143,'Pleistogene.End','Epoch');
AddDef('Excatly 10,000 Carbon-14 years BP.  Near the end of the Younger Dryas cold spell.');
AddAKA('Recent');
AddSource(C14);
AddError(0.00013);

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%   Sub-Epochs   %%%%
%%%%%%%%%%%%%%%%%%%%%%%%

%Silurian
AddStage('Llandovery','Early Silurian.Start','Wenlock.Start','Sub-Epoch');
AddStage('Wenlock',428.2,'Early Silurian.End','Sub-Epoch');
AddDef('Imprecise.  Between the base of acritarch biozone 5 and extinction of conodont Pterospathodus amorphognathoides.  May be near base of Cyrtograptus centrifugus graptolite zone.');
AddError(2.3);
AddSource(ICS);
AddStage('Ludlow','Late Silurian.Start','Pridoli.Start','Sub-Epoch');
AddStage('Pridoli',418.7,'Late Silurian.End','Sub-Epoch');
AddError(2.7);
AddSource(ICS);
AddDef('Graptolite, lowest occurrence of Monograptus parultimus.');
AddGSSP('Pozáry section near Reporje, Barrandian area, Prague, Czech Republic');
AddAKA('Yulongsian');

%Carboniferous
AddStage('Early Mississippian','Mississippian.Start','Tournaisian.End','Sub-Epoch');
AddAKA('Lower Mississipian');
AddStage('Middle Mississippian','Visean.Start','Visean.End','Sub-Epoch');
AddStage('Late Mississippian','Serpukhovian.Start','Mississippian.End','Sub-Epoch');
AddAKA('Upper Mississippian');
AddStage('Early Pennsylvanian','Pennsylvanian.Start','Bashkirian.End','Sub-Epoch');
AddAKA('Lower Pennsylvanian');
AddStage('Middle Pennsylvanian','Moscovian.Start','Moscovian.End','Sub-Epoch');
AddStage('Late Pennsylvanian','Kasimovian.Start','Pennsylvanian.End','Sub-Epoch');
AddAKA('Upper Pennsylvanian');

%Paleocene
AddStage('Early Paleocene','Danian.Start','Danian.End','Sub-Epoch');
AddAKA('Lower Paleocene');
AddStage('Middle Paleocene','Selandian.Start','Selandian.End','Sub-Epoch');
AddStage('Late Paleocene','Thanetian.Start','Thanetian.End','Sub-Epoch');
AddAKA('Upper Paleocene');

%Eocene
AddStage('Early Eocene','Ypresian.Start','Ypresian.End','Sub-Epoch');
AddAKA('Lower Eocene');
AddStage('Middle Eocene','Lutetian.Start','Bartonian.End','Sub-Epoch');
AddStage('Late Eocene','Priabonian.Start','Priabonian.End','Sub-Epoch');
AddAKA('Upper Eocene');

%Oligocene
AddStage('Early Oligocene','Rupelian.Start','Rupelian.End','Sub-Epoch');
AddAKA('Lower Oligocene');
AddStage('Late Oligocene','Chattian.Start','Chattian.End','Sub-Epoch');
AddAKA('Upper Oligocene');

%Miocene
AddStage('Early Miocene','Aquitanian.Start','Burdigalian.End','Sub-Epoch');
AddAKA('Lower Miocene');
AddStage('Middle Miocene','Langhian.Start','Serravallian.End','Sub-Epoch');
AddStage('Late Miocene','Tortonian.Start','Messinian.End','Sub-Epoch');
AddAKA('Upper Miocene');

%Pliocene
AddStage('Early Pliocene','Zanclean.Start','Zanclean.End','Sub-Epoch');
AddAKA('Lower Pliocene');
AddStage('Late Pliocene','Piacenzian.Start','Gelasian.End','Sub-Epoch');
AddAKA('Upper Pliocene');

%%%%%%%%%%%%%%%%%%%%%%%%
%%%%     Stages     %%%%
%%%%%%%%%%%%%%%%%%%%%%%%

%Hadean & Archean
AddStage('Isuan',3800,3500,'European Stage');
AddStage('Swazian',4000,'Randian.Start','South African Stage');
AddComment('Alternative Start: End of Isuan');
AddStage('Randian',3000,'Archean.End','South African Stage');
AddStage('Cryptic','Hadean.Start','Basin Groups.Start','General Stage');
AddStage('Basin Groups',4150,'Nectarian.Start','General Stage');
AddStage('Nectarian',3975,'Early Imbrian.Start','General Stage');
AddStage('Early Imbrian',3900,'Isuan.Start','General Stage');
AddStage('Wutaian',2600,'Luliangian.Start','Chinese Stage');
AddStage('Fupingan',3100,'Wutaian.Start','Chinese Stage');
AddStage('Qianxin',3800,3400,'Chinese Stage');

%Proterozoic
AddStage('Huronian','Proterozoic.Start','Riphean.Start','General Stage');
AddComment('Alternative End: Start of Animikean');
AddStage('Riphean',1400,'Sturtian.Start','General Stage');
AddStage('Sturtian',800,'Vendian.Start','General Stage');
AddStage('Vendian',610,'Proterozoic.End','General Stage');
AddStage('Varangian','Vendian.Start','Ediacaran.Start','Faunal Stage');
AddAKA('Varanger');
AddStage('Smalfjord','Varangian.Start','Mortesnes.Start','Faunal Stage');
AddStage('Mortesnes',605,'Varangian.End','Faunal Stage');
AddStage('Wonokan','Ediacaran.Start','Poundian.Start','Faunal Stage');
AddStage('Poundian',570,'Ediacaran.End','Faunal Stage');
AddStage('Animikean',2225,'Riphean.Start','General Stage');
AddStage('Burzyan','Riphean.Start','Yurmatian.Start','General Substage');
AddStage('Yurmatian',1375,'Karatau.Start','General Substage');
AddStage('Karatau',1100,'Riphean.End','General Substage');
AddStage('Sinian','Sturtian.Start','Vendian.End','Chinese Stage');
AddStage('Jinningian',1750,'Sinian.Start','Chinese Stage');
AddStage('Luliangian',2350,'Jinningian.Start','Chinese Stage');

%Cambrian
AddStage('Paibian','Late Cambrian.Start',493,'ICS Stage');
AddGSSP('Huaqiao Formation, Paibi section, Northwest Hunan province, south China');
AddStage('Nemakit-Daldynian','Early Cambrian.Start','Tommotian.Start','Russian-Kazakhian Stage');
AddStage('Tommotian',534.0,'Atdabanian.Start','Russian-Kazakhian Stage');
AddSource(GO96);
AddStage('Atdabanian',530,'Botomian.Start','Russian-Kazakhian Stage');
AddSource(GO96);
AddStage('Botomian',524,'Toyonian.Start','Russian-Kazakhian Stage');
AddSource(GO96);
AddStage('Toyonian',518.5,'Early Cambrian.End','Russian-Kazakhian Stage');
AddStage('Lenian','Botomian.Start','Toyonian.End','Faunal Stage');
AddStage('Amgan','Middle Cambrian.Start','Mayan.Start','Russian-Kazakhian Stage');
AddAKA('Solvan');
AddStage('Mayan',502,'Middle Cambrian.End','Russian-Kazakhian Stage');
AddAKA('Menevian');
AddStage('Ayusokkanian','Late Cambrian.Start','Sakian.Start','Russian-Kazakhian Stage');
AddStage('Sakian',494.5,'Aksayan.Start','Russian-Kazakhian Stage');
AddStage('Aksayan',493,'Batyrbayan.Start','Russian-Kazakhian Stage');
AddStage('Batyrbayan',491.5,'Late Cambrian.End','Russian-Kazakhian Stage');
AddStage('Montezuman',529.5,'Dyeran.Start','North American Stage');
AddStage('Dyeran',524.5,'Delamaran.Start','North American Stage');
AddStage('Delamaran',512,'Marjuman.Start','North American Stage');
AddStage('Marjuman',504,'Steptoan.Start','North American Stage');
AddStage('Steptoan',494.5,'Sunwaptan.Start','North American Stage');
AddStage('Sunwaptan',493,'Ibexian.Start','North American Stage');
AddStage('Ibexian',491,'White Rockian.Start','North American Stage');
AddStage('Maentwrogian','Late Cambrian.Start','Festiniogian.Start','Faunal Stage');
AddAKA('Dresbachian','Gushanian');
AddStage('Festiniogian',496.8,'Dolgellian.Start','Faunal Stage');
AddAKA('Franconian','Changshanian');
AddComment('On scales that use a 2 stage Late Cambrian, the Dolgellian frequently includes the Festiniogian');
AddStage('Dolgellian',492.5,'Late Cambrian.End','Faunal Stage');
AddAKA('Trempealeauan','Fengshanian');
AddComment('On scales that use a 2 stage Late Cambrian, the Dolgellian frequently includes the Festiniogian');
AddStage('Maozhangian','Middle Cambrian.Start','Zuzhuangian.Start','Chinese Stage');
AddStage('Zuzhuangian',509,'Zhungxian.Start','Chinese Stage');
AddStage('Zhungxian',505,'Middle Cambrian.End','Chinese Stage');
AddStage('Meishuchuan','Early Cambrian.Start','Qungzusian.Start','Chinese Stage');
AddStage('Qungzusian',532,'Changlangpuan.Start','Chinese Stage');
AddStage('Changlangpuan',523,'Longwangmioan.Start','Chinese Stage');
AddStage('Longwangmioan',518,'Early Cambrian.End','Chinese Stage');

%Ordovician
AddStage('Tremadocian','Early Ordovician.Start','Arenig.Start','ICS Stage');
AddAKA('Deming','Gasconadian','Tremadoc','Lianghekouan');
AddGSSP('Green Point, western Newfoundland, Canada');
AddStage('Arenig',478.6,'Early Ordovician.End','ICS Stage');
AddAKA('Cassinian','Arenigian','Ordovician II')
AddDef('Graptolite, lowest occurrence of Tetragraptus approximatus.');
AddGSSP('Diabasbrottet quarry, Vdstergvtland, southern Sweden');
AddComment('Official ICS name not yet decided.  Final Stage may not neccesary coincide with the Arenig.');
AddError(1.7);
AddSource(ICS);
AddStage('Ordovician III','Middle Ordovician.Start','Darriwilian.Start','ICS Stage');
AddComment('Official ICS name not yet decided.');
AddStage('Darriwilian',468.1,'Middle Ordovician.End','ICS Stage');
AddError(1.6);
AddDef('Graptolite, lowest occurrence of Undulograptus austrodentatus.');
AddGSSP('Ningkuo Formation, Huangnitang, Changshan, Zhejiang province, southeast China');
AddSource(ICS);
AddStage('Ordovician V','Late Ordovician.Start','Ordovician VI.Start','ICS Stage');
AddComment('Official ICS name not yet decided.');
AddGSSP('FŒgelsŒng, Scane, southern Sweden');
AddStage('Ordovician VI',455.8,'Hirnantian.Start','ICS Stage');
AddComment('Official ICS name not yet decided.');
AddError(1.6);
AddSource(ICS);
AddDef('Potentially near first appearance of the graptolite Diplacanthograptus caudatus');
AddStage('Hirnantian',445.6,'Late Ordovician.End','ICS Stage');
AddAKA('Gamachian');
AddError(1.5);
AddDef('Potentially at base of the Normalograptus extraordinarius-N. ojsuensis graptolite biozone.');
AddSource(ICS);
AddStage('Llanvirn','Middle Ordovician.Start','Llandeilo.Start','General Stage');
AddAKA('Llanvirnian','Guniutanian','Abereiddian');
AddComment(['Competing definition considers the Llanvirn to represent the entire Middle Ordovician, ',...
	'in which case the Abereiddian and Llandeilian are considered to be it''s stages.']);
AddStage('Llandeilo',464.0,'Middle Ordovician.End','General Stage');
AddSource(GO96);
AddAKA('Llandeilian','Miaopoan','Chazyan');
AddStage('Caradoc','Late Ordovician.Start','Ashgill.Start','General Stage');
AddAKA('Trentonian','Caradocian');
AddStage('Ashgill',449.0,'Late Ordovician.End','General Stage');
AddAKA('Wufengian');
AddSource(GO96);
AddStage('Cressagian','Tremadocian.Start','Migneintian.Start','European Stage');
AddStage('Migneintian',486,'Tremadocian.End','European Stage');
AddStage('Moridunian','Arenig.Start','Whitiandian.Start','European Stage');
AddStage('Whitiandian',475,'Fennian.Start','European Stage');
AddStage('Fennian',473.5,'Arenig.End','European Stage');
AddStage('Aurelucian','Caradoc.Start','Burrellian.Start','European Stage');
AddStage('Burrellian',457,'Cheneyan.Start','European Stage');
AddStage('Cheneyan',455,'Streffordian.Start','European Stage');
AddAKA('Geneyan');
AddStage('Streffordian',452,'Caradoc.End','European Stage');
AddStage('Pusgillian','Ashgill.Start','Cautleyan.Start','European Stage');
AddStage('Cautleyan',447.5,'Rawtheyan.Start','European Stage');
AddStage('Rawtheyan',446.5,'Hirnantian.Start','European Stage');
AddStage('White Rockian',473,'Mohawkian.Start','North American Stage');
AddStage('Mohawkian',461,'Cincinnatian.Start','North American Stage');
AddStage('Cincinnatian',451,'Late Ordovician.End','North American Stage');
AddStage('Richmondian','Pusgillian.Start','Rawtheyan.End','Faunal Stage');
AddStage('Mayvillian','Onnian.Start','Pusgillian.End','Faunal Stage');
AddStage('Onnian',453,'Caradoc.End','Faunal Stage');
AddStage('Actonian',454,'Onnian.Start','Faunal Stage');
AddStage('Edenian','Actonian.Start','Onnian.End','Faunal Stage');
AddStage('Marshbrookian',455,'Actonian.Start','Faunal Stage');
AddStage('Longvillian',457,'Marshbrookian.Start','Faunal Stage');
AddStage('Shermanian','Longvillian.Start','Marshbrookian.End','Faunal Stage');
AddStage('Soudleyan',458,'Longvillian.Start','Faunal Stage');
AddAKA('Kirkfield');
AddStage('Harnagian',459,'Soudleyan.Start','Faunal Stage');
AddAKA('Rocklandian');
AddStage('Costonian','Caradoc.Start','Harnagian.Start','Faunal Stage');
AddAKA('Blackriverian','Blackriveran','Black Riveran');
AddStage('Honghuazuanian','Arenig.Start','Dawanian.Start','Chinese Stage');
AddStage('Dawanian',472,'Arenig.End','Chinese Stage');
AddStage('Baotan','Late Ordovician.Start','Linxiangian.Start','Chinese Stage');
AddStage('Linxiangian',454.5,'Late Ordovician.End','Chinese Stage');

%Silurian
AddStage('Rhuddanian','Llandovery.Start','Aeronian.Start','ICS Stage');
AddGSSP('Birkhill Shale Formation, Dob''s Linn, Moffat, Scotland, UK');
AddStage('Aeronian',439.0,'Telychian.Start','ICS Stage');
AddDef('Graptolite, lowest occurrence of Monograptus austerus sequens.');
AddGSSP('Trefawr forestry road, north of Cwm-coed-Aeron Farm, Llandovery area, south-central Wales, UK');
AddError(1.8);
AddSource(ICS);
AddStage('Telychian',436.0,'Llandovery.End','ICS Stage');
AddAKA('Ontarian');
AddError(1.9);
AddSource(ICS);
AddDef('Brachiopods, just above extinction of Eocoelia intermedia and below lowest succeeding species Eocoelia curtisi.  Near base of  Monograptus turriculatus graptolite zone.');
AddGSSP('Cefn Cerig road, Llandovery area, south-central Wales, UK');
AddStage('Sheinwoodian','Wenlock.Start','Homerian.Start','ICS Stage');
AddAKA('Tonawandian');
AddGSSP('Hughley Brook, Apedale, Shropshire, southwest England, UK');
AddStage('Homerian',426.2,'Wenlock.End','ICS Stage');
AddAKA('Lockportian');
AddError(2.4);
AddSource(ICS);
AddDef('Graptolite, lowest occurrence of Cyrtograptus lundgreni.');
AddGSSP('Whitwell Coppice, Homer, Shropshire, southwest England, UK');
AddStage('Gorstian','Ludlow.Start','Ludfordian.Start','ICS Stage');
AddGSSP('Pitch Coppice quarry, Ludlow, Shropshire, southwest England, UK');
AddStage('Ludfordian',421.3,'Ludlow.End','ICS Stage');
AddError(2.6);
AddSource(ICS);
AddGSSP('Sunnyhill Quarry, Ludlow, Shropshire, southwest England, UK');
AddDef('Imprecise.  May be near base of Saetograptus leintwardinensis graptolite zone.');
AddStage('Medinan','Early Silurian.Start','Niagaran.Start','North American Stage');
AddStage('Niagaran',432,'Cayugan.Start','North American Stage');
AddStage('Cayugan',421,'Late Silurian.End','North American Stage');
AddStage('Alexandrian','Rhuddanian.Start','Aeronian.End','Faunal Stage');
AddStage('Whitwellian','Sheinwoodian.End','Gleedonian.Start','Faunal Stage');
AddStage('Gleedonian',425.4,'Wenlock.End','Faunal Stage');
AddStage('Longmaxian','Silurian.Start','Shinulanian.Start','Chinese Stage');
AddStage('Shinulanian',438,'Baishaean.Start','Chinese Stage');
AddStage('Baishaean',433,'Xiushanian.Start','Chinese Stage');
AddStage('Xiushanian',429,'Guandian.Start','Chinese Stage');
AddStage('Guandian',425.5,'Miaogoalingian.Start','Chinese Stage');
AddStage('Miaogoalingian',422,'Pridoli.Start','Chinese Stage');
AddStage('Idwian','Aeronian.Start','Fronian.Start','Faunal Stage');
AddStage('Fronian',437.5,'Aeronian.End','Faunal Stage');

%Devonian
AddStage('Lochkovian','Early Devonian.Start','Praghian.Start','ICS Stage');
AddAKA('Gedinnian');
AddGSSP('Klonk, Barrandian area, southwest of Prague, Czech Republic');
AddStage('Praghian',411.2,'Emsian.Start','ICS Stage');
AddError(2.8);
AddSource(ICS);
AddAKA('Siegenian');
AddDef('Conodont, lowest occurrence of Eognathodus sulcatus.');
AddGSSP('Velká Chuchle quarry, southwest part of Prague city, Czech Republic');
AddStage('Emsian',407.0,'Early Devonian.End','ICS Stage');
AddError(2.8);
AddSource(ICS);
AddAKA('Sawkillian','Deer Parkian','Sipaian');
AddDef('Conodont, lowest occurrence of Polygnathus kitabicus (= Po. dehiscens).');
AddGSSP('Zinzil''ban Gorge, SE of Samarkand, Uzbekistan');
AddStage('Eifelian','Middle Devonian.Start','Givetian.Start','ICS Stage');
AddAKA('Southwoodian');
AddGSSP('Wetteldorf Richtschnitt, Schšnecken-Wetteldorf, Eifel Hills, western Germany');
AddStage('Givetian',391.8,'Middle Devonian.End','ICS Stage');
AddError(2.7);
AddSource(ICS);
AddAKA('Tioughniogan','Taghanican','Geneseean');
AddDef('Conodont, lowest occurrence of Polygnathus hemiansatus, near base of goniatite Maenioceras Stufe.');
AddGSSP('Jebel Mech Irdane ridge, Tafilalt, Morocco');
AddStage('Frasnian','Late Devonian.Start','Famennian.Start','ICS Stage');
AddAKA('Sonyean','West Fallsian','Shetianqiaoan');
AddGSSP('Col du Puech de la Suque section, St. Nazaire-de-Ladarez, SE Montagne Noir, southern France');
AddStage('Famennian',374.5,'Late Devonian.End','ICS Stage');
AddError(2.6);
AddSource(ICS);
AddAKA('Canadaway','Conneautan','Conewangan','Xikuangshanian');
AddDef('Just above major extinction horizon (Upper Kellwasser Event), including conodonts Ancyrodella and Ozarkodina and goniatites of Gephuroceratidae and Beloceratidae.');
AddGSSP('Upper Coumiac quarry, Cessenon, Montagne Noir, southern France');
AddStage('Ulsterian','Early Devonian.Start','Erian.Start','North American Stage');
AddStage('Erian',379,'Senecan.Start','North American Stage');
AddStage('Senecan',374,'Chatauquan.Start','North American Stage');
AddStage('Chatauquan',365,'Late Devonian.End','North American Stage');
AddStage('Lianhuashanian','Early Devonian.Start','Nagaolingian.Start','Chinese Stage');
AddStage('Nagaolingian',413,'Yujianian.Start','Chinese Stage');
AddStage('Yujianian',410,'Emsian.Start','Chinese Stage');
AddStage('Yingtangian','Middle Devonian.Start','Dongganglingian.Start','Chinese Stage');
AddStage('Dongganglingian',391.4,'Middle Devonian.End','Chinese Stage');

%Carboniferous - Early (Mississippian)
AddStage('Tournaisian','Carboniferous.Start','Visean.Start','ICS Stage');
AddGSSP('La Serre, Montagne Noir, Cabrihres, southern France');
AddAKA('Courceyan');
AddStage('Visean',345.3,'Serpukhovian.Start','ICS Stage');
AddError(2.1);
AddSource(ICS);
AddDef('Foraminifer, lineage Eoparastaffella simplex morphotype 1/morphotype 2.');
AddStage('Serpukhovian',326.4,'Mississippian.End','ICS Stage');
AddError(1.6);
AddSource(ICS);
AddGSSP('Near lowest occurrence of conodont, Lochriea crusiformis.');
AddStage('Namurian','Visean.End','Westphalian.Start','European Stage');
AddStage('Kinderhookian','Mississippian.Start','Osagean.Start','North American Stage');
AddStage('Osagean',348,'Meramecian.Start','North American Stage');
AddStage('Meramecian',340,'Chesterian.Start','North American Stage');
AddStage('Chesterian',333,'Mississippian.End','North American Stage');
AddStage('Hastarian','Carboniferous.Start','Osagean.Start','Faunal Stage');
AddAKA('Chouteau');
AddStage('Chokerian',325,'Alportian.Start','Faunal Stage');
AddAKA('Chokierian')
AddStage('Alportian',324.5,'Serpukhovian.End','Faunal Stage');
AddStage('Arnsbergian',326,'Chokerian.Start','Faunal Stage');
AddStage('Elvirian','Arnsbergian.Start','Chokerian.End','Faunal Stage');
AddStage('Pendleian','Visean.End','Arnsbergian.Start','Faunal Stage');
AddStage('Brigantian',336.0,'Visean.End','Faunal Stage');
AddAKA('St. Geneviere','Gasperian','Saint Geneviere');
AddStage('Asbian',337.5,'Meramecian.End','Faunal Stage');
AddStage('Holkerian',339,'Asbian.Start','Faunal Stage');
AddAKA('Salem');
AddStage('Chadian','Visean.Start','Arundian.Start','Faunal Stage');
AddStage('Arundian',341,'Holkerian.Start','Faunal Stage');
AddAKA('Warsaw');
AddStage('Ivorean','Osagean.Start','Tournaisian.End','Faunal Stage');
AddStage('Shaodongian','Mississippian.Start','Yanguan.Start','Chinese Stage');
AddStage('Yanguan',349.5,'Datangian.Start','Chinese Stage');
AddStage('Datangian',345,'Dewuan.Start','Chinese Stage');
AddStage('Dewuan',333,'Mississippian.End','Chinese Stage');

%Carboniferous - Late (Pennsylvanian)
AddStage('Westphalian',315,'Stephanian.Start','European Stage');
AddStage('Stephanian',306.5,'Carboniferous.End','European Stage');
AddStage('Atokan/Derryan','Moscovian.Start','Desmoinian.Start','North American Stage');
AddAKA('Atokan','Derryan');
AddStage('Desmoinian',308,'Missourian.Start','North American Stage');
AddAKA('Desmoinesian');
AddStage('Missourian','Kasimovian.Start','Virgilian.Start','North American Stage');
AddAKA('Cantabrian');
AddStage('Virgilian',305,'Pennsylvanian.End','North American Stage');
AddStage('Bashkirian','Pennsylvanian.Start','Moscovian.Start','ICS Stage');
AddAKA('Morrowan');
AddGSSP('Battleship Wash Formation, Arrow Canyon, southern Nevada, USA');
AddStage('Moscovian',311.7,'Kasimovian.Start','ICS Stage');
AddError(1.1);
AddSource(ICS);
AddAKA('Bolsovian');
AddDef('Near lowest occurrences of Declinognathodus donetzianus and/or Idiognathoides postsulcatus conodont species, and fusulinid species Aljutovella aljutovica.');
AddStage('Kasimovian',306.5,'Gzhelian.Start','ICS Stage');
AddError(1.0);
AddSource(ICS);
AddDef('Near base of Obsoletes obsoletes and Protriticites pseudomontiparus fusulinid zone, or lowest occurrence of Parashumardites ammonoid.');
AddStage('Gzhelian',303.9,'Pennsylvanian.End','ICS Stage');
AddError(0.9);
AddSource(ICS);
AddAKA('Gzelian');
AddDef('Near lowest occurrences of the fusulinids Daixina, Jigulites and Rugosofusulina, or lowest occurrence of Streptognathodus zethu.');
AddStage('Noginskian',300.5,'Gzhelian.End','Faunal Stage');
AddStage('Klazminskian','Gzhelian.Start','Noginskian.Start','Faunal Stage');
AddStage('Dorogomilovksian','Missourian.End','Kasimovian.End','Faunal Stage');
AddStage('Chamovnicheskian',306,'Missourian.End','Faunal Stage');
AddStage('Krevyakinskian','Missourian.Start','Chamovnicheskian.Start','Faunal Stage');
AddStage('Myachkovskian',307.2,'Moscovian.End','Faunal Stage');
AddStage('Podolskian','Desmoinian.Start','Myachkovskian.Start','Faunal Stage');
AddStage('Kashirskian',309.2,'Podolskian.Start','Faunal Stage');
AddStage('Vereiskian','Moscovian.Start','Kashirskian.Start','Faunal Stage');
AddStage('Melekesskian',313.4,'Bashkirian.End','Faunal Stage');
AddAKA('Duckmantian');
AddStage('Cheremshanskian',314.5,'Melekesskian.Start','Faunal Stage');
AddAKA('Langsettian');
AddStage('Yeadonian',315.5,'Cheremshanskian.Start','Faunal Stage');
AddStage('Marsdenian',317,'Yeadonian.Start','Faunal Stage');
AddStage('Kinderscoutian','Serpukhovian.End','Marsdenian.Start','Faunal Stage');
AddStage('Huashibanian','Pennsylvanian.Start','Dalanian.Start','Chinese Stage');
AddStage('Dalanian',313,'Mapingian.Start','Chinese Stage');
AddStage('Mapingian',310,'Pennsylvanian.End','Chinese Stage');

%Permian
AddStage('Asselian','Early Permian.Start','Sakmarian.Start','ICS Stage');
AddAKA('Krumaian','Uskalikian','Surenian');
AddGSSP('Aidaralash Creek, Aktöbe, southern Ural Mountains, northern Kazakhstan');
AddStage('Sakmarian',294.6,'Artinskian.Start','ICS Stage');
AddAKA('Sterlitamakian','Tastubian');
AddError(0.8);
AddSource(ICS);
AddDef('Conodont, near lowest occurrence of conodont Streptognathodus postfusus.');
AddStage('Artinskian',284.4,'Kungurian.Start','ICS Stage');
AddAKA('Baigendzinian','Aktastinian');
AddError(0.7);
AddSource(ICS);
AddDef('Near lowest occurrence of conodont Sweetognathus whitei-Mesogondolella bisselli.');
AddStage('Kungurian',275.6,'Early Permian.End','ICS Stage');
AddAKA('Irenian','Filippovian');
AddDef('Near lowest occurrence of conodont Neostreptognathus pnevi - N. exculptus.');
AddError(0.7);
AddSource(ICS);
AddStage('Roadian','Middle Permian.Start','Wordian.Start','ICS Stage');
AddAKA('Ufiman'); 
AddGSSP('Cutoff Formation, Stratotype Canyon, southern Guadalupe Mountains, Texas, USA');
AddStage('Wordian',268.0,'Capitanian.Start','ICS Stage');
AddError(0.7);
AddSource(ICS);
AddDef('Conodont, lowest occurrence of Jinogondolella aserrata.');
AddGSSP('Getaway Ledge outcrop, Guadalupe Pass, SE Guadalupe Mountains, Texas, USA');
AddStage('Capitanian',265.8,'Middle Permian.End','ICS Stage');
AddError(0.7);
AddSource(ICS);
AddDef('Conodont, lowest occurrence of Jinogondolella postserrata.');
AddGSSP('Pinery Limestone Member, Nipple Hill, SE Guadalupe Mountains, Texas, USA');
AddStage('Wuchiapingian','Late Permian.Start','Changhsingian.Start','ICS Stage');
AddAKA('Wujiapingian','Djulfian','Longtanian','Rustlerian','Saladoan','Castile','Dzhulfian');
AddStage('Changhsingian',253.8,'Late Permian.End','ICS Stage');
AddError(0.7);
AddSource(ICS);
AddAKA('Dorashamian','Dewey Lake','Changxingian','Changshingian');
AddDef('Near lowest occurrence of conodont Clarkina wangi.');
AddStage('Kazanian','Roadian.Start','Middle Permian.End','European Stage');
AddAKA('Maokovian');
AddStage('Wolfcampian','Early Permian.Start','Leonardian.Start','North American Stage');
AddStage('Leonardian',280,'Early Permian.End','North American Stage');
AddStage('Ochoan',258,'Late Permian.End','North American Stage');
AddStage('Thuringian','Middle Permian.Start','Permian.End','Faunal Stage');

%Triassic
AddStage('Induan','Early Triassic.Start','Olenekian.Start','ICS Stage');
AddGSSP('Meishan, Zhejiang, China');
AddAKA('Feixianguanian')
AddStage('Olenekian',249.7,'Early Triassic.End','ICS Stage');
AddError(0.7);
AddSource(ICS);
AddDef('Near lowest occurrence of Hedenstroemia or Meekoceras gracilitatis ammonites, and of the conodont Neospathodus waageni.');
AddAKA('Yongningzhenian');
AddStage('Anisian','Middle Triassic.Start','Ladinian.Start','ICS Stage');
AddAKA('Guanlingian');
AddStage('Ladinian',237.0,'Middle Triassic.End','ICS Stage');
AddError(2.0);
AddDef('Alternate levels are near base of Reitzi, Secedensis, or Curionii ammonite zone; near first occurrence of the conodont genus Budurovignathus.');
AddAKA('Falangian');
AddSource(ICS);
AddStage('Carnian','Late Triassic.Start','Norian.Start','ICS Stage');
AddStage('Norian',216.5,'Rhaetian.Start','ICS Stage');
AddError(2.0);
AddSource(ICS);
AddDef('Base of Klamathites macrolobatus or Stikinoceras kerri ammonoid zones and the Metapolygnathus communisti or M. primitius conodont zones.');
AddStage('Rhaetian',203.6,'Late Triassic.End','ICS Stage');
AddError(1.5);
AddSource(ICS);
AddDef('Near lowest occurrence of ammonite Cochlocera, conodonts Misikella spp. and Epigondolella mosheri, and radiolarian Proparvicingula moniliformis.');
AddStage('Spathian',247.4,'Early Triassic.End','Faunal Stage');
AddStage('Smithian','Olenekian.Start','Spathian.Start','Faunal Stage');
AddAKA('Nammalian');
AddStage('Dienerian',250.4,'Induan.End','Faunal Stage');
AddStage('Griesbachian','Early Triassic.Start','Dienerian.Start','Faunal Stage');
AddAKA('Ellesmerian','Gangetian');
AddStage('Aegean','Anisian.Start','Bithynian.Start','Faunal Stage');
AddStage('Bithynian',243,'Pelsonian.Start','Faunal Stage');
AddStage('Pelsonian',241,'Illyrian.Start','Faunal Stage');
AddStage('Illyrian',239,'Anisian.End','Faunal Stage');
AddStage('Fassanian','Ladinian.Start','Longobardian.Start','Faunal Stage');
AddStage('Longobardian',231.4,'Ladinian.End','Faunal Stage');
AddStage('Lacinian','Norian.Start','Alaunian.Start','Faunal Stage');
AddStage('Alaunian',216.0,'Sevatian.Start','Faunal Stage');
AddStage('Sevatian',211,'Norian.End','Faunal Stage');
AddStage('Bananian','Late Triassic.Start','Huobachengian.Start','Chinese Stage');
AddStage('Huobachengian',219,'Erqiaoan.Start','Chinese Stage');
AddStage('Erqiaoan',209,'Late Triassic.End','Chinese Stage');
AddStage('Julian','Carnian.Start','Tuvalian.Start','Faunal Stage');
AddStage('Tuvalian',225,'Carnian.End','Faunal Stage');

%Jurassic
AddStage('Hettangian','Early Jurassic.Start','Sinemurian.Start','ICS Stage');
AddStage('Sinemurian',196.5,'Pliensbachian.Start','ICS Stage');
AddError(1.0);
AddSource(ICS);
AddGSSP('East Quantoxead, Watchet, West Somerset, SW England, UK');
AddAKA('Lotharingian');
AddDef('Ammonite, lowest occurrence of arietitid genera Vermiceras and Metophioceras.');
AddStage('Pliensbachian',189.6,'Toarcian.Start','ICS Stage');
AddError(1.5);
AddSource(ICS);
AddGSSP('Wine Haven section, Robin Hood''s Bay, Yorkshire, England, UK');
AddDef('Ammonite, lowest occurrences of Bifericeras donovani and of genera Apoderoceras and Gleviceras.');
AddAKA('Charmouthian');
AddStage('Toarcian',183.0,'Early Jurassic.End','ICS Stage');
AddError(1.5);
AddSource(ICS);
AddDef('Ammonite, near lowest occurrence of a diversified Eodactylites ammonite fauna; correlates with the NW European Paltus horizon.');
AddStage('Aalenian','Middle Jurassic.Start','Bajocian.Start','ICS Stage');
AddGSSP('Fuentelsalz, central Spain');
AddStage('Bajocian',171.6,'Bathonian.Start','ICS Stage');
AddError(3.0);
AddSource(ICS);
AddGSSP('Cabo Mondego, western Portugal');
AddDef('Ammonite, lowest occurrence of the genus Hyperlioceras (defines base of the Hyperlioceras discites Zone).');
AddStage('Bathonian',167.7,'Callovian.Start','ICS Stage');
AddError(3.5);
AddSource(ICS);
AddDef('Ammonite, lowest occurrence of Parkinsonia (G.) convergens (defines base of Zigzagiceras zigzag Zone).');
AddStage('Callovian',164.7,'Middle Jurassic.End','ICS Stage');
AddError(4.0);
AddSource(ICS);
AddDef('Ammonite, lowest occurrence of the genus Kepplerites (Kosmoceratidae).  (Defines base of Macrocephalites herveyi Zone in sub-Boreal province of Great Britain to southwest Germany.)');
AddAKA('Dreussian');
AddStage('Oxfordian','Late Jurassic.Start','Kimmeridgian.Start','ICS Stage');
AddStage('Kimmeridgian',155.7,'Tithonian.Start','ICS Stage');
AddError(4.0);
AddSource(ICS);
AddDef('Ammonite, near base of Pictonia baylei ammonite zone of Boreal realm.');
AddComment('This definition is approximately 1 Myr older than previously used Tethyan event boundary.');
AddStage('Tithonian',150.8,'Late Jurassic.End','ICS Stage');
AddError(4.0);
AddSource(ICS);
AddDef('Near base of Hybonoticeras hybonotum ammonite zone and lowest occurrence of Gravesia genus, and the base of magnetic polarity chronozone M22An.')
AddStage('Xintiangouan','Middle Jurassic.Start','Shaximioan.Start','Chinese Stage');
AddStage('Shaximioan',167,'Middle Jurassic.End','Chinese Stage');
AddStage('Xuiningiang','Late Jurassic.Start','Penglaizhenian.Start','Chinese Stage');
AddStage('Penglaizhenian',149,'Late Jurassic.End','Chinese Stage');
AddStage('Volgian','Tithonian.Start','Ryzanian.Start','Faunal Stage');
AddStage('Ryzanian',142.0,136.5,'Faunal Stage');
AddSource(GO96,GO96);
AddStage('Portlandian',146,'Volgian.End','Faunal Stage');
AddSource(GO96);

%Cretaceous
AddStage('Berriasian','Early Cretaceous.Start','Valanginian.Start','ICS Stage');
AddStage('Valanginian',140.2,'Hauterivian.Start','ICS Stage');
AddError(3.0);
AddSource(ICS);
AddDef('Calpionellid, lowest occurrence of Calpionellites darderi (base of Calpionellid Zone E); followed by the lowest occurrence of ammonite "Thurmanniceras" pertransiens.');
AddStage('Hauterivian',136.4,'Barremian.Start','ICS Stage');
AddError(2.0);
AddSource(ICS);
AddDef('Ammonite, lowest occurrence of genus Acanthodiscus (especially A. radiatus).');
AddStage('Barremian',130.0,'Aptian.Start','ICS Stage');
AddError(1.5);
AddSource(ICS);
AddDef('Ammonite, lowest occurrence of Spitidiscus hugii - Spitidiscus vandeckii group.');
AddStage('Aptian',125.0,'Albian.Start','ICS Stage');
AddError(1.0);
AddSource(ICS);
AddDef('Magnetic polarity chronozone, base of M0r.');
AddAKA('Urgonian');
AddStage('Albian',112.0,'Early Cretaceous.End','ICS Stage');
AddError(1.0);
AddSource(ICS);
AddAKA('Frederiksbergian','Gault');
AddDef('Calcareous nannofossil, lowest occurrence of Praediscosphaera columnata (= P. cretacea of some earlier studies), is one potential marker.');
AddStage('Cenomanian','Late Cretaceous.Start','Turonian.Start','ICS Stage');
AddAKA('Woodbinian');
AddGSSP('Mont Risou, Rosans, Haute-Alpes, SE France');
AddStage('Turonian',93.5,'Coniacian.Start','ICS Stage');
AddError(0.8);
AddSource(ICS);
AddDef('Ammonite, lowest occurrence of Watinoceras devonense.');
AddGSSP('Rock Canyon Anticline, east of Pueblo, Colorado, west-central USA');
AddStage('Coniacian',89.3,'Santonian.Start','ICS Stage');
AddError(1.0);
AddSource(ICS);
AddGSSP('Salzgitter-Salder Quarry, SW of Hannover, Lower Saxony, northern Germany');
AddDef('Inoceramid bivalve, lowest occurrence of Cremnoceramus rotundatus.');
AddStage('Santonian',85.8,'Campanian.Start','ICS Stage');
AddError(0.7);
AddSource(ICS);
AddDef('Inoceramid bivalve, lowest occurrence of Cladoceramus undulatoplicatus.');
AddStage('Campanian',83.5,'Maastrichtian.Start','ICS Stage');
AddError(0.7);
AddSource(ICS);
AddDef('Crinoid, extinction of Marsupites testudinarius.');
AddAKA('Taylorian');
AddStage('Maastrichtian',70.6,'Late Cretaceous.End','ICS Stage');
AddError(0.6);
AddSource(ICS);
AddGSSP('Grande Carrière quarry, Tercis-les-Bains, Landes province, SW France');
AddAKA('Navarroan','Maestrichtian');
AddDef('Mean of 12 biostratigraphic criteria of equal importance.  Closely above is lowest occurrence of ammonite Pachydiscus neubergicus.  Boreal proxy is lowest occurrence of belemnite Belemnella lanceolata.');
AddStage('Coahulian','Early Cretaceous.Start','Comanchean.Start','North American Stage');
AddStage('Comanchean',122,'Early Cretaceous.End','North American Stage');
AddStage('Gallic','Barremian.Start','Turonian.End','General Stage');
AddAKA('Trinitian','Nuevo Leonian');
AddStage('Neocomian','Berriasian.Start','Hauterivian.End','General Stage');
AddStage('Senonian','Coniacian.Start','Late Cretaceous.End','General Stage');
AddStage('Rognacian',68,'Maastrichtian.End','Faunal Stage');
AddStage('Begudian','Maastrichtian.Start','Rognacian.Start','Faunal Stage');
AddStage('Fuvelian',77,'Campanian.End','Faunal Stage');
AddStage('Valdonnian','Campanian.Start','Fuvelian.Start','Faunal Stage');

%Paleogene
AddStage('Danian','Paleocene.Start','Selandian.Start','ICS Stage');
AddGSSP('Base of boundary clay, El Kef, Tunisia');
AddAKA('Montian');
AddStage('Selandian',61.7,'Thanetian.Start','ICS Stage');
AddError(0.2);
AddSource(ICS);
AddStage('Thanetian',58.7,'Paleocene.End','ICS Stage');
AddError(0.2);
AddSource(ICS);
AddAKA('Landenian','Heersian');
AddDef('Magnetic polarity chronozone, base of C26n, is a temporary assignment.');
AddStage('Ypresian','Eocene.Start','Lutetian.Start','ICS Stage');
AddGSSP('Dababiya Section near Luxor, Egypt');
AddStage('Lutetian',48.6,'Bartonian.Start','ICS Stage');
AddError(0.2);
AddSource(ICS);
AddDef('Planktonic foraminifer, lowest occurrence of Hantkenina.');
AddStage('Bartonian',40.4,'Priabonian.Start','ICS Stage');
AddError(0.2);
AddSource(ICS);
AddAKA('Auversian');
AddDef('Near extinction of calcareous nannofossil Reticulofenestra reticulata.');
AddStage('Priabonian',37.2,'Eocene.End','ICS Stage');
AddError(0.1);
AddSource(ICS);
AddAKA('Jacksonian');
AddDef('Near lowest occurrence of calcareous nannofossil Chiasmolithus oamaruensis (base Zone NP18).');
AddStage('Rupelian','Oligocene.Start','Chattian.Start','ICS Stage');
AddAKA('Stampian','Tongrian','Latdorfian','Vicksburgian');
AddGSSP('Massignano quarry, Ancona, Italy');
AddStage('Chattian',28.4,'Oligocene.End','ICS Stage');
AddError(0.1);
AddSource(ICS);
AddAKA('Chickasawhayan');
AddDef('Planktonic foraminifer, extinction of Chiloguembelina (base Zone P21b).');
AddStage('Puercan','Paleocene.Start','Torrejonian.Start','North American Stage');
AddStage('Torrejonian',62.5,'Tiffanian.Start','North American Stage');
AddStage('Tiffanian',60.5,'Clarkforkian.Start','North American Stage');
AddStage('Clarkforkian',56,'Wasatchian.Start','North American Stage');
AddStage('Wasatchian',55.5,'Bridgerian.Start','North American Stage');
AddStage('Bridgerian',50.5,'Uintan.Start','North American Stage');
AddStage('Uintan',45.4,'Duchesnean.Start','North American Stage');
AddStage('Duchesnean',40,'Chadronian.Start','North American Stage');
AddStage('Chadronian',37,'Orellan.Start','North American Stage');
AddStage('Orellan',33.5,'Whitneyan.Start','North American Stage');
AddStage('Whitneyan',32,'Arikareean.Start','North American Stage');
AddStage('Arikareean',30.5,'Hemingfordian.Start','North American Stage');

%Neogene
AddStage('Aquitanian','Miocene.Start','Burdigalian.Start','ICS Stage');
AddGSSP('Lemme-Carrosio section, Carrosio village, north of Genoa, Italy');
AddStage('Burdigalian',20.43,'Langhian.Start','ICS Stage');
AddError(0.05);
AddSource(ICS);
AddDef('Near lowest occurrence of planktonic foraminifer Globigerinoides altiaperturus or top of magnetic polarity chronozone C6An.');
AddStage('Langhian',15.97,'Serravallian.Start','ICS Stage');
AddError(0.05);
AddSource(ICS);
AddDef('Near first occurrence of planktonic foraminifer Praeorbulina glomerosa and top of magnetic polarity chronozone C5Cn.1n.');
AddStage('Serravallian',13.65,'Tortonian.Start','ICS Stage');
AddError(0.05);
AddSource(ICS);
AddDef('Near lowest occurrence of nannofossil Sphenolithus heteromorphus, and within magnetic polarity chronozone C5ABr.');
AddStage('Tortonian',11.608,'Messinian.Start','ICS Stage');
AddError(0.005);
AddDef('Last common occurrences of the calcareous nannofossil Discoaster kugleri and the planktonic foraminifer Globigerinoides subquadratus.  Associated with the short normal-polarity subchron C5r.2n.');
AddGSSP('Monte dei Corvi beach section, Ancona, Italy');
AddStage('Messinian',7.246,'Miocene.End','ICS Stage');
AddError(0.005);
AddSource(ICS);
AddDef('Middle of magnetic polarity chronozone C3Br.1r; lowest regular occurrence of the Globorotalia conomiozea planktonic foraminifer group.');
AddGSSP('Oued Akrech, Rabat, Morocco');
AddSource(ICS);
AddStage('Zanclean','Pliocene.Start','Piacenzian.Start','ICS Stage');
AddAKA('Zanclian','Tabianian','Dacian');
AddGSSP('Trubi Formation, Eraclea Minoa, Sicily, Italy');
AddStage('Piacenzian',3.600,'Gelasian.Start','ICS Stage');
AddDef('Base of magnetic polarity chronozone C2An (Gauss); extinction levels of planktonic foraminifers Globorotalia margaritae and Pulleniatina primalis.');
AddSource(ICS);
AddError(0.005);
AddGSSP('Punta Piccola, Sicily, Italy');
AddAKA('Astian','Redonian','Romanian');
AddStage('Gelasian',2.588,'Pliocene.End','ICS Stage');
AddDef('Isotopic stage 103, base of magnetic polarity chronozone C2r (Matuyama).  Above are extinction levels of calcareous nannofossil Discoaster pentaradiatus and D. surculus.');
AddSource(ICS);
AddError(0.005);
AddAKA('Waltonian');
AddGSSP('Nicola Bed, Monte San Nicola, Gela, Sicily, Italy');
AddStage('Hemingfordian',19,'Barstovian.Start','North American Stage');
AddStage('Barstovian',16,'Clarendonian.Start','North American Stage');
AddStage('Clarendonian',11.5,'Hemphillian.Start','North American Stage');
AddStage('Hemphillian',9,'Blancan.Start','North American Stage');
AddStage('Blancan',4.75,'Tertiary.End','North American Stage');

%Pleistocene
AddStage('Early Pleistocene','Pleistocene.Start','Middle Pleistocene.Start','ICS Stage');
AddAKA('Lower Pleistocene','Calabrian');
AddGSSP('Vrica, Calabria, Italy');
AddStage('Middle Pleistocene',0.781,'Late Pleistocene.Start','ICS Stage');
AddAKA('Ionian');
AddDef('Brunhes-Matuyama magnetic reversal.');
AddSource(ICS);
AddError(0.005);
AddStage('Late Pleistocene',0.126,'Pleistocene.End','ICS Stage');
AddDef('Base of the Eemian interglacial stage (base of marine isotope stage 5e) before final glacial episode of Pleistocene.');
AddSource(ICS);
AddError(0.005);
AddAKA('Upper Pleistocene','Tarantian');
AddStage('Sicilian','Middle Pleistocene.Start','Tyrrhenian.Start','European Stage');
AddStage('Tyrrhenian',0.26,'Late Pleistocene.End','European Stage');
AddStage('Irvingtonian','Pleistocene.Start','Rancholabrean.Start','North American Stage');
AddStage('Rancholabrean',0.3,'Pleistocene.End','North American Stage');

%%%%%%%%%%%%%%%%%%%%%%%%%
%%% END OF STAGE LIST %%%
%%%%%%%%%%%%%%%%%%%%%%%%%

%Remove the blank entry at front of list.
GL_STAGES = GL_STAGES(2:end);

%If three outputs are requested, save the raw data before processing.
if nargout > 2
	straw = GL_STAGES;
end

%if two or more outputs are requested, output the version identifier.
if nargout > 1
   vs = version;
end

%Call local function to resolve all the references to other stage boundaries
for a = 1:length(GL_STAGES)
   chainsimplify(a);   
end

%set output variable
stages = GL_STAGES;

%delete global variable
clear GL_STAGES;

%%%%%%%%%%%%%%%%%%%%%%%%%
% END OF MAIN FUNCTION  %
%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Local Helper Functions  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function AddStage(varargin)
%Add a new stage to the data structure, filling each of it's fields
%with the variables in varargin.
global GL_STAGES;
f = fieldnames(GL_STAGES);
v = varargin;
v{length(f)} = [];
GL_STAGES(end+1) = cell2struct(v',f,1);


function AddAKA(varargin)
%Add AKA field data to the last stage in data structure.
global GL_STAGES;
GL_STAGES(end).AKA = varargin;

function AddComment(st)
%Add comment field data to the last stage in data structure.
global GL_STAGES;
GL_STAGES(end).Comment = st;

function AddGSSP(st)
%Add GSSP field data to the last stage in data structure.
global GL_STAGES;
GL_STAGES(end).GSSP = st;

function AddDef(varargin)
%Add Start and End definition field data to the last stage in data structure.
%If one argument adds Start_Defined_By, if two arguments, uses first for 
%start and second for end.
global GL_STAGES;
if (nargin == 2)
	GL_STAGES(end).Start_Defined_By = varargin{1};
	GL_STAGES(end).End_Defined_By = varargin{2};
elseif (nargin >= 1)
  	GL_STAGES(end).Start_Defined_By = varargin{1};
end

function AddError(varargin)
%Add Start and End error field data to the last stage in data structure.
%If one argument adds dStart, if two arguments, uses first for 
%dStart and second for dEnd.
global GL_STAGES;
if (nargin == 2)
	GL_STAGES(end).dStart = varargin{1};
	GL_STAGES(end).dEnd = varargin{2};
elseif (nargin >= 1)
  	GL_STAGES(end).dStart = varargin{1};
end

function AddSource(varargin)
%Add Start and End source field data to the last stage in data structure.
%If one argument adds Start_Source, if two arguments, uses first for 
%start and second for end.
global GL_STAGES;
if (nargin == 2)
	GL_STAGES(end).Start_Source = varargin{1};
	GL_STAGES(end).End_Source = varargin{2};
elseif (nargin >= 1)
  	GL_STAGES(end).Start_Source = varargin{1};
end


function chainsimplify(a)
%Function that goes through and simplifies all of the references to other stages
%for stage GL_STAGES(a).  Effectively this takes the boundary information that 
%is defined in only one place and distributes it to all of the stages sharing that
%boundary.

%get access to the global data structure
global GL_STAGES;

%length of the data structure
lgs = length(GL_STAGES);

%temperary variables holding the current value of start and end for GL_STAGES(a).
tmps = GL_STAGES(a).Start;
tmpe = GL_STAGES(a).End;

%If tmpe is a string check for reference syntax
if (ischar(tmpe)) 
   p = findstr(tmpe,'.Start');
   if (isempty(p))
   	  p = findstr(tmpe,'.End');
   end
   %If it is a reference to another stage get that stage's data.  
   if (~isempty(p)) 
      %name of other stage to access
	   nm = tmpe(1:(p(end)-1));
	   %field of other stage to check
	   fld = tmpe((p(end)+1):end);
	   %number of the record with the information we seek
	   %set to 0 to indicate not found yet.
	   fnd = 0;
	   %Is it the last record?
	   if (a < lgs)
		   %No - Then check the following record, because references are
		   %often in sequence.
		   if (strcmp(GL_STAGES(a+1).Name,nm))
           %set target record as the next one if name matches.
			  fnd= a+1;
		   end
      end
	   %Not found yet?  Then search all other records.
	   if (fnd==0)
		   for b = [1:a,(a+2):lgs]
            %Does the name match?
            if (strcmp(GL_STAGES(b).Name,nm)) 
               %Yes - Record the record number
               fnd= b;
               %Exit the loop
               break;
            end
         end
	   end
	   %If not found anywhere in record, throw an error.
	   if (fnd == 0)
         error(['Chain Simplify Not Found: ' tmpe]);
	   end
      %Make sure that the one we found is also reduced.
      chainsimplify(fnd);
      %If we want to use the start data than choose the first, else see if
      %we want the second, else skip.  In each case we carry over the 
      %date, error, source and definition and put them in the end records.
      if strcmp(fld,'Start')
         GL_STAGES(a).End = GL_STAGES(fnd).Start;
         GL_STAGES(a).dEnd = GL_STAGES(fnd).dStart;
         GL_STAGES(a).End_Source = GL_STAGES(fnd).Start_Source;
         GL_STAGES(a).End_Defined_By = GL_STAGES(fnd).Start_Defined_By;
      elseif strcmp(fld,'End')
         GL_STAGES(a).End = GL_STAGES(fnd).End;
         GL_STAGES(a).dEnd = GL_STAGES(fnd).dEnd;
         GL_STAGES(a).End_Source = GL_STAGES(fnd).End_Source;
         GL_STAGES(a).End_Defined_By = GL_STAGES(fnd).End_Defined_By;		 
	  end   
	end
end

%Same set of routines except applied to the start records.
%See comments given above.
if (ischar(tmps)) 
   p = findstr(tmps,'.Start');
  	if (isempty(p))
   	p = findstr(tmps,'.End');
   end   
   if (~isempty(p)) 
	   nm = tmps(1:(p(end)-1));
	   fld = tmps((p(end)+1):end);
		fnd = 0;
	   if (a < lgs)
		   if (strcmp(GL_STAGES(a+1).Name,nm))
      		fnd= a+1;
		   end
   	end
	   if (fnd==0)
		   for b = [1:a,(a+2):lgs]
   		   if (strcmp(GL_STAGES(b).Name,nm)) 
   	      	fnd= b;
	   	      break;
	   	   end
   	   end
	   end
	   if (fnd == 0)
   	   error(['Chain Simplify Not Found: ' tmps]);
	   end
      chainsimplify(fnd);
      if strcmp(fld,'End')
         GL_STAGES(a).Start = GL_STAGES(fnd).End;
         GL_STAGES(a).dStart = GL_STAGES(fnd).dEnd;
         GL_STAGES(a).Start_Source = GL_STAGES(fnd).End_Source;
         GL_STAGES(a).Start_Defined_By = GL_STAGES(fnd).End_Defined_By;
      elseif strcmp(fld,'Start')
         GL_STAGES(a).Start = GL_STAGES(fnd).Start;
         GL_STAGES(a).dStart = GL_STAGES(fnd).dStart;
         GL_STAGES(a).Start_Source = GL_STAGES(fnd).Start_Source;
         GL_STAGES(a).Start_Defined_By = GL_STAGES(fnd).Start_Defined_By;
      end   
	end
end
