#!/bin/bash
#
if [ "$(id -u)" -eq "0" ];then
  echo 'Please run this script as a normal user (not root)'
  exit 1
fi
echo "==============================================================================="
echo "              GWB: GuidosToolbox-Workbench"
echo "==============================================================================="
echo "     Part A: brief module description"
echo "==============================================================================="
echo "cmd-line image analysis modules from GuidosToolbox "
echo "(https://forest.jrc.ec.europa.eu/en/activities/lpa/gtb/):"
echo "Usage of GWB implies compliance with the conditions in the EULA_GWB.pdf"
echo "(https://ies-ows.jrc.ec.europa.eu/gtb/GWB/EULA_GWB.pdf)"
echo " "
echo "GWB_check4updates"
echo "  Display installed and current program version"
echo "  and test for program updates"
echo "  (Automatic updater for Debian systems: '/opt/GWB/tools/GWBupdate_deb.sh')"
echo " "
echo "GWB_ACC: Accounting of image objects and area classes"
echo "  Requirements: 1b-BG, 2b-FG, optional: 0b-missing, "
echo "  optional: 3b-special background 1, 4b-special background 2"
echo "  Parameter file: input/acc-parameters.txt"
echo " "
echo "GWB_DIST: Euclidean Distance and Hypsometric Curve"
echo "  Requirements: 1b-BG, 2b-FG, optional: 0b-missing"
echo "  Parameter file: input/dist-parameters.txt"
echo " "
echo "GWB_FRAG: user-selected custom scale FOS fragmentation analysis"
echo "  Requirements: binary or grayscale map (see frag-parameters.txt), "
echo "  Parameter file: input/frag-parameters.txt"
echo " "
echo "GWB_FOSCHANGE: change of FOS fragmentation/connectivity"
echo "  Requirements: two GTB/GWB-generated FOS-directories"
echo "  Parameter file: input/foschange-parameters.txt"
echo " "
echo "GWB_GSC: GraySpatCon analysis of attribute adjacency table"
echo "  Requirements: categorical map within [0b, 255b]"
echo "  Parameter file: input/gsc-parameters.txt"
echo " "
echo "GWB_LM: Landscape Mosaic "
echo "  Requirements: 1b-Agriculture, 2b-Natural, 3b-Developed "
echo "  optional: 0b-missing"
echo "  Parameter file: input/lm-parameters.txt"
echo " "
echo "GWB_MSPA: Morphological Spatial Pattern Analysis"
echo "  Requirements: 1b-BG, 2b-FG, optional: 0b-missing"
echo "  Parameter file: input/mspa-parameters.txt"
echo " "
echo "GWB_PARC: Landscape Parcellation index"
echo "  Requirements: [1b, 255b]-land cover classes, optional: 0b-missing"
echo "  Parameter file: input/parc-parameters.txt"
echo " "
echo "GWB_REC: Recode class values"
echo "  Requirements: categorical map with up to 256 classes within [0b, 255b]"
echo "  Parameter file: input/rec-parameters.txt"
echo " "
echo "GWB_RSS: Restoration Status summary"
echo "  Requirements: 1b-BG, 2b-FG, optional: 0b-missing"
echo "  Parameter file: input/rss-parameters.txt"
echo " "
echo "GWB_SC: SpatCon analysis of attribute adjacency table"
echo "  Requirements: categorical map within [0b, 255b]"
echo "  Parameter file: input/sc-parameters.txt"
echo " "
echo "GWB_SPA: Spatial Pattern Analysis (2, 3, 5, or 6 classes)"
echo "  Requirements: 1b-BG, 2b-FG, optional: 0b-missing"
echo "  Parameter file: input/spa-parameters.txt"
echo " "
echo "GWB_SPLITLUMP: Cut/process/merge buffered stripes of large images"
echo "  Requirements: categorical map within [0b, 255b]"
echo "  Parameter file: input/splitlump-parameters.txt"
echo " "
echo "More details in the module-specific parameter files, or run: GWB_XXX --help"
echo " "
echo "==============================================================================="
echo "     Part B: usage"
echo "==============================================================================="
echo "a) system mode (GWB installed in /opt/GWB/): "
echo "   To get started in system mode, copy the input/output directories to"
echo "   your $HOME folder using the command: cp -fr /opt/GWB/*put ~/"
echo "   To process, add the full path to your input and output directory: "
echo "   GWB_ACC -i=$HOME/input -o=$HOME/output"
echo " "
echo "b) standalone mode (within $HOME/GWB<version>/GWB):  "
echo "   Note: standalone mode requires using the existing directories:"
echo "   $HOME/GWB<version>/GWB/input           as the input directory and"
echo "   $HOME/GWB<version>/GWB/output          as the output directory"
echo "   To process, ensure you are in $HOME/GWB<version>/GWB, then run:"
echo "   ./GWB_ACC"
echo " "
echo  "==============================================================================="
echo "     Part C: processing requirements"
echo "==============================================================================="
echo "RAM requirements depend on amount/configuration of image objects, the selected  "
echo "module and processing settings, and the image size: imsizeGB = xdim*ydim/1024^3"
echo "  "
echo "Note:"
echo "a) On multi-user systems you may not have full access to the available RAM"
echo "b) The peak RAM usage factors below are indicative only. "
echo "c) The log-file will list: imsizeGB, ~ RAM requirements, peak RAM usage"
echo " "
echo "Approximate peak RAM usage factors for an image of size imsizeGB: "
echo "GWB_ACC       : 30 * imsizeGB"
echo "GWB_DIST      : 18 * imsizeGB"
echo "GWB_FRAG      : 20 * imsizeGB"
echo "GWB_FOSCHANGE : 11 * imsizeGB"
echo "GWB_GSC       :  5 * imsizeGB"
echo "GWB_LM        :  9 * imsizeGB"
echo "GWB_MSPA      : 20 * imsizeGB"
echo "GWB_PARC      : 22 * imsizeGB"
echo "GWB_REC       :  2 * imsizeGB"
echo "GWB_RSS       : 20 * imsizeGB"
echo "GWB_SPA       : 20 * imsizeGB"
echo "GWB_SC        :  5 * imsizeGB"
echo "GWB_SPLITLUMP: shell-script, no RAM required"
echo " "
echo "Example: input image 50,000 x 50,000 pixels -> imsizeGB = 2.33 GB. "
echo "Processing this image for GWB_ACC will require 30 * 2.33 ~ 70 GB RAM"
echo " "
echo "Online manual:  https://gwbdoc.readthedocs.io"
echo "==============================================================================="
echo " ***  To read all GWB information in Part A, B, C above,   ***"
echo " ***  either scroll up or run the command:   less /usr/bin/GWB  ***"
echo "==============================================================================="
# Find the location of this script and check status of GWB
topdir=$(dirname "$0")
if test "$topdir" = "." ; then
   topdir=$PWD;
fi
checker="$topdir"/GWB_check4updates
if [[ -f "$checker" ]];then
$checker
fi
