#!/bin/sh
#################################################################################
##                                                                             ##
##                    b  a  c  k  t  r  a  c  e                                ##
##                                                                             ##
##    sh script to write out backtrace from core file                          ##
##    Usage: backtrace [core]                                                  ##
##                                                                             ##
## (C) Potsdam Institute for Climate Impact Research (PIK), see COPYRIGHT file ##
## authors, and contributors see AUTHORS file                                  ##
## This file is part of LPJmL and licensed under GNU AGPL Version 3            ##
## or later. See LICENSE file or go to http://www.gnu.org/licenses/            ##
## Contact: https://github.com/PIK-LPJmL/LPJmL                                 ##
##                                                                             ##
#################################################################################

if [ $# -lt 1 ]
then
  core=core
else
  core=$1
fi
if [ "$LPJROOT" == "" ]
then
  exe=bin/lpjml
else
  exe=$LPJROOT/bin/lpjml
fi
if test -f $core
then
  gdb  -ex "bt" -ex "q"  -q $exe $core
else
  echo >&2 "Error: core file '$core' does not exist"
fi
