\name{Load}
\alias{Load}
\title{Load Experimental And Observational Data}
\description{
  This function loads experimental data and corresponding observational data 
  from the specified experimental and observational datasets into two 
  matrices with similar structures. Only data of a specified variable and set 
  of starting dates is loaded.
  Once the two matrices are filled by calling this function, other functions
  of the Common Diagnostics package that require this data structure can be 
  executed (e.g: Ano() to compute anomalies, Clim() to compute climatologies).
}
\usage{
  Load(var, exp, obs = NULL, sdates, lonmin = 0, lonmax = 360, latmin = -90, 
  latmax = 90, nleadtime = NULL, nmember = NULL, leadtimemin = 1, 
  leadtimemax = NULL, storefreq = "monthly", sampleperiod = 1, 
  output = "areave", method = "conservative", grid = NULL, maskmod = list(NULL, 
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
  NULL), maskobs = list(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
  NULL, NULL, NULL, NULL, NULL, NULL))
}
\arguments{
  \item{var}{
    One of the following: 'tas', 'prlr', 'tos', 'g500', 'g200', 'ta50', 'psl', 
	'hflsd', 'hfssd', 'rls', 'rss', 'rsds', 'uas', 'vas', 'siaN', 'sieN', 
	'sivN', 'siaS', 'sieS', 'sivS', 'moc_40N55N_1-2km', 'moc_30N40N_1-2km', 
	'max_moc_38N50N_500m-2km', 'max_moc_40N', 'heatc', '0-315_heatc', 
	'373-657_heatc', '800-5350_heatc', 'mxl_heatc', 'NAtl_10N65N_heatc', 
	'NAtl_10N65N_0-315_heatc', 'NAtl_10N65N_373-657_heatc', 
	'NAtl_10N65N_800-5350_heatc', 'mxl_NAtl_10N65N_heatc', 'TAtl_30S30N_heatc', 
    'TAtl_30S30N_0-315_heatc', 'TAtl_30S30N_373-657_heatc',
    'TAtl_30S30N_800-5350_heatc', 'mxl_TAtl_30S30N_heatc', 'NPac_10N70N_heatc', 
	'NPac_10N70N_0-315_heatc', 'NPac_10N70N_373-657_heatc', 
	'NPac_10N70N_800-5350_heatc', 'mxl_NPac_10N70N_heatc', 'TPac_30S30N_heatc',
    'TPac_30S30N_0-315_heatc', 'TPac_30S30N_373-657_heatc', 
	'TPac_30S30N_800-5350_heatc', 'mxl_TPac_30S30N_heatc', 'Arc_65N90N_heatc', 
	'Arc_65N90N_0-315_heatc', 'Arc_65N90N_373-657_heatc', 
	'Arc_65N90N_800-5350_heatc', 'mxl_Arc_65N90N_heatc', 'Ant_90S60S_heatc',
    'Ant_90S60S_0-315_heatc', 'Ant_90S60S_373-657_heatc', 
	'Ant_90S60S_800-5350_heatc', 'mxl_Ant_90S60S_heatc', 'TInd_30S30N_heatc', 
	'TInd_30S30N_0-315_heatc', 'TInd_30S30N_373-657_heatc', 
	'TInd_30S30N_800-5350_heatc', 'mxl_TInd_30S30N_heatc'.
  }
  \item{exp}{
    IMPORTANT: Place first the experiment with the largest number of members 
	and, if possible, with the largest number of leadtimes. If not possible, it 
	is mandatory to specify the argument nleadtime.
    c('EnsEcmwfDec', 'EnsUkmoDec', 'EnsCerfacsDec', 'EnsIfmDec', 'EnsEcmwfSeas', 
	  'EnsCmccSeas', 'EnsIfmSeas', 'EnsMetfrSeas', 'EnsUkmoSeas', 
	  'DePreSysAsimDec', 'DePreSysNoAsimDec', 'DePreSysAsimSeas', 
	  'ECMWF_S3Seas', 'ECMWF_S4_sea', 'ECMWF_S4_ann', 'hadcm3dec', 'miroc4dec', 
	  'miroc5dec', 'mri-cgcm3dec', 'cancm4dec1', 'cancm4dec2', 'cnrm-cm5dec',
      'knmidec', 'smhidec', 'mpimdec', 'gfdldec', 'cmcc-cmdec', 'ipsldec', 
	  'bccdec', 'gfdlhis', 'ipslhis', 'cmcc-cmhis', 'bcchis', 'i00k', 'b013', 
	  'b014', 'yve2', \dots)
  }
  \item{obs}{
    c('ERA40', 'NCEP', 'ERAint', '20thCv2', 'GHCN', 'GHCNERSSTGISS', 'ERSST', 'HadISST', 
	  'GPCP', 'GPCC', 'CRU', 'HadSLP', 'NSIDC', 'PIOMAS', 'UCL', 'DS94', 
	  'OAFlux', 'DFS4.3', 'NCDCglo', 'NCDCland', 'NCDCoc', 'GISSglo', 
	  'GISSland', 'GISSoc', 'HadCRUT3glo', 'HadCRUT4', 
	  'HadSST2oc', 'CRUTEM3land')
  }
  \item{sdates}{
    c('ERA40', 'NCEP', 'ERAint', 'GHCN', 'GHCNERSSTGISS', 'ERSST', 'HadISST', 
	  'GPCP', 'GPCC', 'CRU', 'HadSLP', 'NSIDC', 'PIOMAS', 'UCL', 'DS94', 
	  'OAFlux', 'DFS4.3', 'NCDCglo', 'NCDCland', 'NCDCoc', 'GISSglo', 
	  'GISSland', 'GISSoc', 'HadCRUT3glo', 'HadSST2oc', 'CRUTEM3land')
  }
  \item{lonmin}{
    >= 0, default: 0
  }
  \item{lonmax}{
    <= 360, default: 360
  }
  \item{latmin}{
    >= -90, default: -90
  }
  \item{latmax}{
    <= 90, default: 90
  }
  \item{nleadtime}{
    Optional argument needed only if the first experiment in the parameter exp 
	does not have the largest number of leadtimes.
    Default: number of leadtimes of the first experiment.
  }
  \item{nmember}{
    Some experiments have more members in starting dates other than the first. 
    If it is the case in the first experiment specified, fill nmember with the 
    largest number of members.
  }
  \item{leadtimemin}{
    Load into the matrices only the leadtimes from leadtimemin. 
    Default: 1.
  }
  \item{leadtimemax}{
    Load into the matrices only the leadtimes before leadtimemax.
    Default: nleadtime.
  }
  \item{storefreq}{
    Frequency at which the data to be loaded are stored in the repository. Can 
	take values 'monthly' or 'daily'. 
    Default: 'monthly'.
  }
  \item{sampleperiod}{
    To load only a subset between leadtimemin and leadtimemax with a specified 
	period of subsampling. 
    Default: 1 (all leadtimes are loaded).
  }
  \item{output}{
    'areave' / 'lon' / 'lat' / 'lonlat'.
    1) Time series of area-averaged variables over the specified domain.
    2) Time series of meridional averages as a function of longitudes.
    3) Time series of zonal averages as a function of latitudes.
    4) Time series of 2d fields.
    Default: 'areave'
  }
  \item{method}{
    'bilinear' / 'bicubic' / 'conservative' / 'distance-weighted'
    Method of interpolation for 'lon' / 'lat' / 'lonlat' output options.
    Default: 'conservative'.
  }
  \item{grid}{
    To choose the output grid.
    Possible options: rNXxNY or tTRgrid, ex: r96x72, t106grid.
    Default: model grid, argument need to be filled if various exp on various 
	grids.
  }
  \item{maskmod}{
    list(mask[lon,lat]) = 1/0: kept/removed grid cell over the entire model 
	domains.
    Warning: list() compulsory even if 1 model!!!
    Default: 1 everywhere.
  }
  \item{maskobs}{
    list(mask[lon,lat]) = 1/0: kept/removed grid cell over the entire observed 
	domains, only necessary for 'areave' output option.
    Warning: list() compulsory even if 1 dataset !!!
    Default: 1 everywhere.
  }
}
\details{
  The two output data matrices are similar and have 7 dimensions each with the 
  following lengths:
    1) Number of experimental/observational datasets.
    2) Number of members.
    3) Number of starting dates.
    4) Number of lead-times.
    5) Number of latitudes (optional).
    6) Number of longitudes (optional).
    
  For a detailed explanation of the process read the documentation attached to 
  the package or check the comments in the code.
}
\value{
  \item{$mod}{
    Model outputs.
    If output = 'areave', matrix with dimensions
      c(nmod/nexp or nobs, nmemb/nparam, nsdates, nltime)
    If output = 'lat', matrix with dimensions
      c(nmod/nexp or nobs, nmemb/nparam, nsdates, nltime, nlat)
    If output = 'lon', matrix with dimensions
      c(nmod/nexp or nobs, nmemb/nparam, nsdates, nltime, nlon)
    If output = 'lonlat', matrix with dimensions
      c(nmod/nexp or nobs, nmemb/nparam, nsdates, nltime, nlat, nlon)
  }
  \item{$obs}{
    Observations. Matrix with same dimensions as '$mod'.
  }
  \item{$lat}{
    Latitudes of the model grid.
  }
  \item{$lon}{
    Longitudes of the model grid.
  }
}
\author{
  History:
  1.0  -  2011-03  (V. Guemas, \email{vguemas@ic3.cat})  -  Original code
}
\keyword{datagen}
