\name{ConfigAddEntry}
\alias{ConfigAddEntry}
\alias{ConfigEditEntry}
\alias{ConfigRemoveEntry}
\title{
Add, Remove Or Edit Entries In The Configuration
}
\description{
ConfigAddEntry(), ConfigEditEntry() and ConfigRemoveEntry() are functions to manage entries in a configuration object created with ConfigFileOpen().
}
\usage{
ConfigAddEntry(configuration, dataset_type, store_format, position = "last", dataset_name = ".*", var_name = ".*", main_path = "*", file_path = "*", nc_var_name = "*", grid = "*", suffix = "*", varmin = "*", varmax = "*")
ConfigEditEntry(configuration, dataset_type, store_format, level, position, dataset_name = NULL, var_name = NULL, main_path = NULL, file_path = NULL, nc_var_name = NULL, grid = NULL, suffix = NULL, varmin = NULL, varmax = NULL)
ConfigRemoveEntry(configuration, dataset_type, store_format, dataset_name = NULL, var_name = NULL, level = NULL, position = NULL)
}
\arguments{
  \item{configuration}{
Configuration object obtained via ConfigFileOpen() or ConfigFileCreate() that will be modified accordingly.
  }
  \item{dataset_type}{
Whether to modify a table of experimental datasets or a table of observational datasets. Can take values 'experiments' or 'observations' respectively.
  }
  \item{store_format}{
There's a table associated to each storage format (see ?ConfigFileOpen). 'store_format' tells which one to load. Can take values 'file-per-startdate', 'file-per-member' (if 'dataset_type' is 'experiments'), or 'file-per-member', 'file-per-month', 'file-per-dataset' (if 'dataset_type' is 'observations').
  }
  \item{level}{
Each table has 4 levels (see ?ConfigFileOpen) and each level has a number of indexed entries. 'level' tells the level in which the entry to edit is found, or the level which to add a new entry to.\cr
If 'dataset_name' and 'var_name' are specified this argument is ignored in ConfigRemoveEntry().\cr
  }
  \item{position}{
Each table has 4 levels (see ?ConfigFileOpen) and each level has a number of indexed entries. 'position' tells the index (relative to the level) of the entry to edit or remove.\cr
In ConfigAddEntry() it tells the position in the level which to insert the new entry to. In this case it can also take the value "last", that will put the entry at the end of the level. This is the default value.\cr
If 'dataset_name' and 'var_name' are specified this argument is ignored in ConfigRemoveEntry().
  }
  \item{dataset_name,var_name,main_path,file_path,nc_var_name,grid,suffix,varmin,varmax}{
These parameters tell the dataset name, variable name, main path, ..., of the entry to add, edit or remove.\cr
'dataset_name' and 'var_name' can take as a value a POSIX 1003.2 regular expression (see ?ConfigFileOpen).\cr
Other parameters can take as a value a shell globbing expression (see ?ConfigFileOpen).\cr
'dataset_name' and 'var_name' take by default the regular expression '.*' (match any dataset and variable name), and the others take by default '*' (associate to the pair 'dataset_name' and 'var_name' all the defined default values. In this case '*' has a special behaviour, it won't be used as a shell globbing expression. See ?ConfigFileOpen and ?ConfigShowDefinitions).
  }
}
\value{
The function returns an accordingly modified configuration object. To apply the changes in the configuration file it must be saved using ConfigFileSave().
}
\author{
History:\cr
0.1  -  2015-05  (N. Manubens, \email{nicolau.manubens@ic3.cat})  -  First version
}
\examples{
# Create an empty configuration file
config_file <- paste0(tempdir(), "/example.conf")
ConfigFileCreate(config_file)
# Open it into a configuration object
configuration <- ConfigFileOpen(config_file)
# Add an entry at the bottom of 4th level of file-per-startdate experiments 
# table which will associate the experiment "ExampleExperiment" and variable 
# "ExampleVariable" to some information about its location.
configuration <- ConfigFileAddEntry(configuration, "experiments", "file-per-startdate", "ExampleExperiment", "ExampleVariable", "/path/to/ExampleExperiment", "ExampleVariable/ExampleVariable_$START_DATE$.nc")
# Add another entry
configuration <- ConfigFileAddEntry(configuration, "experiments", "file-per-startdate", "ExampleExperiment2", "ExampleVariable", "/path/to/ExampleExperiment2", "ExampleVariable/ExampleVariable_$START_DATE$.nc")
# Edit second entry to generalize for any variable. Changing variable needs .
configuration <- ConfigFileEditEntry(configuration, "experiments", "file-per-startdate", var_name = ".*", file_path = "$VAR_NAME$/$VAR_NAME$_$START_DATE$.nc")
# Remove first entry
configuration <- ConfigFileRemoveEntry(configuration, "experiments", "file-per-startdate", "ExampleExperiment", "ExampleVariable")
# Show results
ConfigShowTable(configuration, "experiments", "file-per-ensemble")
# Now put variable in list of supported variables. In this example will be a two-dimensional variable.
configuration <- ConfigAddVar(configuration, "2d", "ExampleMistake")
# Look in list of variables and see there's nothing similar to what we look for. The previous introduction was mistaken
configuration <- ConfigShowSimilarVars(configuration, "Variable")
# Remove variable and add the desired one
configuration <- ConfigRemoveVar(configuration, "2d", "ExampleMistake")
configuration <- ConfigAddVar(configuration, "2d", "ExampleVariable")
# See results
ConfigShowVariables(configuration)
# Save the configuration
ConfigFileSave(configuration, config_file)
}
\keyword{datagen}
