Skip to content
Snippets Groups Projects

Generalization

Merged Bianca Wentzel requested to merge generalization into plugin_template
Compare and Show latest version
2 files
+ 68
47
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 45
47
@@ -4,47 +4,18 @@
@@ -4,47 +4,18 @@
#
#
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-License-Identifier: BSD-3-Clause
check_var_name () {
#######################################
# check for same variable name from settings and file with 1 variable inside
# Extracts the height level for the variable from the given file
# $1: var_name from settings
# Globals:
# $2: var_name from file
# None
if [ "$1" != "$2" ]; then
# Arguments:
echo "ERROR variable name: $1 $2"
# $1: File to retrieve height level from
###to-do: exit script with error message exit /b
# Outputs:
fi
# Outputs the found height level
}
# Returns:
# None
check_var_names () {
#######################################
# check for same variable name from settings and file with many variable inside
# $1: var_name from settings
# $2...$n: var_names from file, String (HHL HSURF FR_LAND DEPTH_LK FR_LAKE SOILTYP FIELDCAP PORVOL WILPOINT)
local stringarray=(${@:2}) # without first element ($1)
found=false
for i in "${stringarray[@]}"
do
# echo $i
if [ "$i" == "$1" ] ; then
found=true
fi
done
if [ "$found" = "false" ]; then
echo "ERROR variable name: $1 $2"
###to-do: exit script with error message exit /b
fi
}
get_unit () {
# extract the unit of variable
# searching for "....." and cut out without ""
local TEXT=$@
local START=$(($(echo "$@" | grep -aob '"' | grep -oE '[0-9]+' | head -n1) + 1))
local LENGTH=$(($(echo "$@" | grep -aob '"' | grep -oE '[0-9]+' | head -n2 | tail -n1) - $START))
echo ${TEXT:$START:$LENGTH} #### ${@ geht auch ?
}
get_height () {
get_height () {
# extract the height level of variable
# $1: file name
feld=($(cdo zaxisdes $1))
feld=($(cdo zaxisdes $1))
# search="units"
# search="units"
# for i in "${!feld[@]}"; do
# for i in "${!feld[@]}"; do
@@ -65,9 +36,18 @@ get_height () {
@@ -65,9 +36,18 @@ get_height () {
echo ${feld[$(($i + 2))]}
echo ${feld[$(($i + 2))]}
}
}
 
#######################################
 
# Extracts the gridsize for the x axis of the given file
 
# Globals:
 
# None
 
# Arguments:
 
# $1: File to retrieve gridsize from
 
# Outputs:
 
# Outputs the found x gridsize
 
# Returns:
 
# None
 
#######################################
get_x_size () {
get_x_size () {
# gridsize: x
# $1: file name
feld=($(cdo griddes $1))
feld=($(cdo griddes $1))
search="xsize"
search="xsize"
for i in "${!feld[@]}"; do
for i in "${!feld[@]}"; do
@@ -77,9 +57,18 @@ get_x_size () {
@@ -77,9 +57,18 @@ get_x_size () {
### to-do: abfrage nicht gefunden i== echo ${#feld[@]}
### to-do: abfrage nicht gefunden i== echo ${#feld[@]}
}
}
 
#######################################
 
# Extracts the gridsize for the y axis of the given file
 
# Globals:
 
# None
 
# Arguments:
 
# $1: File to retrieve gridsize from
 
# Outputs:
 
# Outputs the found y gridsize
 
# Returns:
 
# None
 
#######################################
get_y_size () {
get_y_size () {
# gridsize: y
# $1: file name
feld=($(cdo griddes $1))
feld=($(cdo griddes $1))
search="ysize"
search="ysize"
for i in "${!feld[@]}"; do
for i in "${!feld[@]}"; do
@@ -90,10 +79,19 @@ get_y_size () {
@@ -90,10 +79,19 @@ get_y_size () {
}
}
### todo: unite 3 last functions
### todo: unite 3 last functions
 
#######################################
 
# Converts unit of given dataset to scientific standard unit for given variable
 
# Globals:
 
# None
 
# Arguments:
 
# $1: File containing the data
 
# $2: Variable name
 
# Outputs:
 
# Converted data (values and unit) are saved to new file while echoing the done convertion to the user
 
# Returns:
 
# None
 
#######################################
convert_unit() {
convert_unit() {
# $1 file path
# $2 variable name
UNIT=$( cdo partab $1 | grep "units" | grep -o -P '(?<=").*(?=")' )
UNIT=$( cdo partab $1 | grep "units" | grep -o -P '(?<=").*(?=")' )
case ${UNIT} in
case ${UNIT} in
Loading