NWPconf
Version1.0
|
Main entry point for the NWPconf bash library. More...
Functions | |
conf_init () | |
Create a list of configuration directories for current configuration. More... | |
conf_getfile ($1) | |
Return the path of the requested file according to current configuration. More... | |
conf_template ($*) | |
Generate file from template. More... | |
date_add ($1, $2, $3) | |
Add the requested number of hours to a date and return the date. More... | |
time_add ($1, $2, $3) | |
Add the requested number of hours to a date and return the time. More... | |
datetime_add ($1, $2, $3) | |
Add the requested number of hours to a date and return date and time. More... | |
date_sub ($1, $2, $3) | |
Subtract the requested number of hours to a date and return the date. More... | |
time_sub ($1, $2, $3) | |
Subtract the requested number of hours to a date and return the time. More... | |
datetime_sub ($1, $2, $3) | |
Subtract the requested number of hours to a date and return date and time. More... | |
date_now () | |
Return the current date. More... | |
time_now () | |
Return the current time. More... | |
datetime_now () | |
Return the current time. More... | |
datetime_cnmc ($1, $2) | |
Output the provided date and time in the format required by CNMC. More... | |
max ($1, $2) | |
Compute the maximum between two numerical arguments. More... | |
timeout_exec ($1,$*) | |
Execute a command with a specified timeout. More... | |
Main entry point for the NWPconf bash library.
The file nwpconf.sh is the main entry point for the whole package, it has to be sourced by the user script and other optional modules of this package have to be sourced after this.
This module provides tools for managing multiple configurations and generating configuration files from templates, tools for date and time computations and other utilities.
Configurations in nwpconf are managed in a hierarchical way, the user defines a common directory tree rooted at $NWPCONFDIR
containing different branches for different processes to be configured. The configuration for the current process is defined by the $NWPCONF
variable, thus all the directory levels between $NWPCONFDIR
and $NWPCONFDIR/$NPWCONF
define the configuration for the current process, with growing priority from $NWPCONFDIR
to $NWPCONFDIR/$NPWCONF
.
When the $ENS_MEMB
variable is set to a nonempty value, the configuration is said to be running in ensemble mode, providing extra features for managing ensemble member-specific configurations and files.
Each of these directory levels may contain a shell script file conf.sh
; upon sourcing of the current module, the configuration tree for the requested configuration is scanned and all the conf.sh
scripts encountered are sourced in order of growing priority. In this way, environment variable assignments made in following levels will override the ones made in the previous levels. The conf.sh
files should mainly contain assignments of variable with shell syntax, however any arbitrary shell code in them will be regularly executed. If a directory level does not contain such a file, it will be skipped without errors. All the configuration files in the tree are sourced in automatic export mode, so that all variable assignments are exported even without the explicit export
keyword. Thus, after sourcing the present script, the user environment will contain all the variable assignments according to the requested configurations.
When running in ensemble mode, in every directory of the tree a file named conf.sh.$ENS_MEMB
is searched for and sourced if found, after the corresponding conf.sh
file, thus allowing to define an ensemble member-specific configuration.
The configuration tree described above can also contain template files named <filename>.in
. By means of the function conf_template(), the file <filename>
will be generated in the current directory starting from the template file <filename>.in
found in the configuration tree; unlike the case for conf.sh
, if more than one matching template file is found in the tree, only the one contained in the directory with the highest priority is used. Any occurrence of @<string>@
in the template file will be replaced by the current value of $<string>
environment variable in the destination file. Any occurrence of @INCLUDE <file>@
in the template file determines the inclusion of <file>
in that point, applying recursively the same variable substitutions and file inclusion rules. If <file>
contains a directory specification, either relative or absolute, it is searched starting from the current directory, otherwise it is searchd in the configuration tree with the same rules used for finding the template file.
When running in ensemble mode, in every directory of the tree, files named <filename>.in.ens
and <filename>.in.$ENS_MEMB
are also searched for, with increasing priority and with a higher priority than the corresponding <filename>.in
.
The configuration tree can also contain generic files ready for use, at different configuration levels, the function conf_getfile() helps in choosing the one with highest priority in these cases.
As indicated above for template files, here too, in ensemble mode, the name of a file with an additional extension .ens
(for any member, with lower priority) or .$ENS_MEMB
(for a specific member, with higher priority), if present, is returned in place of the corresponding file without additional extension.
conf_init | ( | ) |
Create a list of configuration directories for current configuration.
This function is implicitly called when sourcing the present module, so it is unlikely for it to be called directly by the user; it creates the list of directories to search for configuration files in, according to the user selected configuration $NWPCONF
and the configuration root $NWPCONFDIR
, ordered from lower to higher priority.
conf_getfile | ( | $1 | ) |
Return the path of the requested file according to current configuration.
This functions prints on stdout the name of the requested configuration file contained in the configuration tree defined by $NWPCONFDIR
and $NWPCONF
. If more than one file with the requested name is found, only the one with highest priority is returned, if no files are found the function returns with an error code.
$1 | the name of the requested file |
conf_template | ( | $* | ) |
Generate file from template.
This function generates one or more files from the corresponding template according to the current configuration tree $NWPCONF
. One or more template files with the same name and additional suffix .in
must exist in the configuration tree, the one with highest priority will be used for generating the file in the current directory, if no template file is found the function returns with an error code.
$* | list of files to be generated |
date_add | ( | $1, | |
$2, | |||
$3 | |||
) |
Add the requested number of hours to a date and return the date.
This function takes in input a date and time string, adds to it an integer number of hours and prints to standard output only the recomputed date in the format YYYYMMDD
. All the computations are performed in UTC unless the variable $DATECOM
is changed from its default value date -u
.
$1 | initial date in the format YYYYMMDD |
$2 | initial time in the format HH |
$3 | number of hours to add, integer with no leading zeroes, negative values accepted |
time_add | ( | $1, | |
$2, | |||
$3 | |||
) |
Add the requested number of hours to a date and return the time.
This function works as date_add() but it prints to standard output only the recomputed time in the format HH
.
$1 | initial date in the format YYYYMMDD |
$2 | initial time in the format HH |
$3 | number of hours to add, integer with no leading zeroes, negative values accepted |
datetime_add | ( | $1, | |
$2, | |||
$3 | |||
) |
Add the requested number of hours to a date and return date and time.
This function works as date_add() but it prints to standard output the recomputed date and time in the format YYYYMMDDHH
.
$1 | initial date in the format YYYYMMDD |
$2 | initial time in the format HH |
$3 | number of hours to add, integer with no leading zeroes, negative values accepted |
date_sub | ( | $1, | |
$2, | |||
$3 | |||
) |
Subtract the requested number of hours to a date and return the date.
This function works as date_add() but it subtracts hours rather then adding them.
$1 | initial date in the format YYYYMMDD |
$2 | initial time in the format HH |
$3 | number of hours to subtract, integer with no leading zeroes, negative values accepted |
time_sub | ( | $1, | |
$2, | |||
$3 | |||
) |
Subtract the requested number of hours to a date and return the time.
This function works as time_add() but it subtracts hours rather then adding them.
$1 | initial date in the format YYYYMMDD |
$2 | initial time in the format HH |
$3 | number of hours to subtract, integer with no leading zeroes, negative values accepted |
datetime_sub | ( | $1, | |
$2, | |||
$3 | |||
) |
Subtract the requested number of hours to a date and return date and time.
This function works as datetime_add() but it subtracts hours rather then adding them.
$1 | initial date in the format YYYYMMDD |
$2 | initial time in the format HH |
$3 | number of hours to subtract, integer with no leading zeroes, negative values accepted |
date_now | ( | ) |
Return the current date.
This function prints on stdout the current date in the format YYYYMMDD
; the date is expressed in UTC unless the variable $DATECOM
is changed from its default value date -u
.
time_now | ( | ) |
Return the current time.
This function works as date_now() but it prints the current time in the format HH
.
datetime_now | ( | ) |
Return the current time.
This function works as date_now() but it prints the current date and time in the format YYYYMMDDHH
.
datetime_cnmc | ( | $1, | |
$2 | |||
) |
Output the provided date and time in the format required by CNMC.
This function prints to standard output the provided date and time in the format MMDDHHMM
as used in the files provided by the Italian Military Meteorological Service (cnmc in WMO abbreviations).
$1 | date in the format YYYYMMDD |
$2 | time in the format HH |
max | ( | $1, | |
$2 | |||
) |
Compute the maximum between two numerical arguments.
This function computes the maximum between the two integer numerical arguments provided and prints it to stdout, thus it should tipically be used as: M=`max $H1 $H2
`.
$1 | the first numerical argument |
$2 | the second numerical argument |
timeout_exec | ( | $1, | |
$* | |||
) |
Execute a command with a specified timeout.
This function executes an arbitrary command killing it when the requested time has elapsed.
$1 | value of the timeout in seconds |
$* | command to be executed and optional extra-arguments |