...
Table of Contents
The Windows Script
| Code Block |
|---|
| title | Windows Batch Script (processDataset.bat) |
|---|
| lang | actionscript |
|---|
|
@echo off
rem enable delayed expansion - used to resolve variable in loop
rem variable has to be used with '!' instead of '%'
setlocal ENABLEDELAYEDEXPANSION
::::::::::::::::::::::::::::::::::::::::::::
:: User Configuration
::::::::::::::::::::::::::::::::::::::::::::
rem adapt this path to your needs
set gptPath="C:\Program Files\beam\beam-4.9.0.111\bin\gpt.bat"
::::::::::::::::::::::::::::::::::::::::::::
:: Command line handling
::::::::::::::::::::::::::::::::::::::::::::
rem first parameter is a path to the graph xml
set graphXmlPath=%1
rem second parameter is a path to a parameter file
set parameterFilePath=%2
rem use third parameter for path to source products
set sourceDirectory=%3
rem the fourth parameter is a file prefix for the target product name,
rem typically indicating the type of processing
set targetFilePrefix=%4
set targetDirectory=%sourceDirectory%\output\
rem Create the target directory
md %targetDirectory%
::::::::::::::::::::::::::::::::::::::::::::
:: Main processing
::::::::::::::::::::::::::::::::::::::::::::
rem double '%' in batch file and only a single '%' on command line
for %%F in (%sourceDirectory%\*.N1) do (
rem '~fF' means abolute path of 'F'
set sourceFile=%%~fF
rem '~nF' means filename without extension of 'F'
set targetFile=%targetDirectory%\%targetFilePrefix%_%%~nF.dim
set procCmd=%gptPath% %graphXmlPath% -e -p %parameterFilePath% -Ssource="!sourceFile!" -t "!targetFile!"
call !procCmd!
) |
...
| Code Block |
|---|
| title | Unix Bash Script (processDataset.bash) |
|---|
| lang | actionscript |
|---|
|
#!/bin/bash
#
############################################
# User Configuration
############################################
# adapt this path to your needs
gptPath="/opt/beam-4.9.0.111/bin/gpt.sh"
############################################
# Command line handling
############################################
# first parameter is a path to the graph xml
graphXmlPath="$1"
# second parameter is a path to a parameter file
parameterFilePath="$2"
# use third parameter for path to source products
sourceDirectory="$3"
# the fourth parameter is a file prefix for the target product name,
# typically indicating the type of processing
targetFilePrefix="$4"
############################################
# Helper functions
############################################
# Borrowed from http://www.linuxjournal.com/content/normalizing-path-names-bash
function normalizePath() {
# Remove all /./ sequences.
local path="${1//\/.\//\/}"
# Remove first dir/.. sequence.
local npath=$(echo "$path" | sed -e 's;[^/][^/]*/\.\./;;')
# Remove remaining dir/.. sequence.
while [[ "$npath" != "$path" ]]; do
path="$npath"
npath=$(echo "$path" | sed -e 's;[^/][^/]*/\.\./;;')
done
echo "$path"
}
getAbsolutePath() {
file="$1"
if [ "${file:0:1}" = "/" ]; then
# already absolute
echo "$file"
return
fi
absfile="$(pwd)/${file}"
absfile="$(normalizePath "${absfile}")"
echo "${absfile}"
}
removeExtension() {
file="$1"
echo "$(echo "$file" | sed -r 's/\.[^\.]*$//')"
}
############################################
# Main processing
############################################
targetDirectory="${sourceDirectory}/output"
# Create the target directory
mkdir -p "${targetDirectory}"
IFS=$'\n'
for F in $(ls -1 "${sourceDirectory}"/*.N1); do
sourceFile="$(getAbsolutePath "$F")"
targetFile="${targetDirectory}/${targetFilePrefix}_$(removeExtension "${F}").dim"
procCmd="\"${gptPath}\" \"${graphXmlPath}\" -e -p \"${parameterFilePath}\" -Ssource=\"${sourceFile}\" -t \"${targetFile}\""
"${procCmd}"
done |
...
www.microsoft.com - General introduction to batch files
www.microsoft.com - Explains usage of the for loop
www.dostips.com - Gives examples for string operations in batch files.
BEAM in batch mode - A presentation introducing the batch mode capabilities of BEAM. It was given at a CoastColour workshop.