function varargout = amat(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% this is the start of Antonia's meta-analysis toolbox
%% which is going to do all sorts of wonderful things


%-Format arguments
%-----------------------------------------------------------------------
if nargin == 0, Action='Welcome'; else, Action = varargin{1}; end
global ma;

%=======================================================================
switch lower(Action)
    %=======================================================================
    
case 'welcome'             %-Welcome splash screen
    
    disp('')
    disp('------- Starting Antonia''s Meta-Analysis Toolbox -------------')
    disp('')

    try
        v = spm('ver');
        if(strcmp(v,'SPM2')==0)
            disp('SPM2 must be on the matlab path');
            return;
        end
    catch
        disp('SPM2 must be on the matlab path');
        return  
    end    
    
    %%% load up defaults
    ma = load('amat_defaults.mat');

    %%%% load up coordinate databases
    if(ma_database('read_brain_areas')<0)
        return;
    end
    
    %% load pubmed database
    load(ma.defaults.pubmeddb);
    ma.pubmed = pubmed;
    
    %% start up all windows
    close all
    Fmenu = ma_menu;
    Fbrain = ma_figure('Create','Graphics','Graphics','on');
    Ftable = ma_table('Create');
    Finfo = ma_interactive('Create');

    %% run stats
    ma_database('stats');
    
    
case 'defaults'
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% generate defaults from scratch
    
    defaults.localdb = 'mydatabase.csv';
    defaults.globaldb = 'amat_database.csv';
    defaults.pubmeddb = 'amat_pubmed.mat';
    defaults.nbours = 30;
    defaults.unicodes =     {'&#x00E8;'    'e'
        '&#x00E9;'    'y'
        '&#x00FC;'    'o'
        '&#x00F6;'    'o'
        '&#x00E5;'    'a'
        '&#x00E4;'    'u'
        '&#x00F8;'    'a'
        '&#x00E1;'    'a'
        '&#x00A9;'    'c'
        '&#x00E0;'    'y'
        '&#x00E7;'    'c'
        '&apos;'      ''
        '&quot;'      '"'};
    defaults.tofind =   {'year'       '<Year>'            '</Year>'            [ 1]
        'journal'    '<MedlineTA>'       '</MedlineTA>'       [ 1]
        'title'      '<ArticleTitle>'    '</ArticleTitle>'    [ 1]
        'authors'    '<LastName>'        '</LastName>'        [20]};
    defaults.tablelines = 20;
    
    defaults
    ma.defaults = defaults;
    if(yesno('Do you want to save the regenerated defaults?')==1)
        save amat_defaults defaults;
    end
    
case 'exit'
    close all
    clear all   
    disp('')
    disp('------- Thank you and goodbye -------------')
    disp('')
    
    
    %=======================================================================

end












