source: palm/trunk/SCRIPTS/palm_find_lowest_available_error_number @ 3941

Last change on this file since 3941 was 3118, checked in by knoop, 6 years ago

Bugfix: palm_find_lowest_available_error_number is now able to find error numbers used in multi-line message calls

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#!/usr/bin/env bash
2#------------------------------------------------------------------------------#
3# This file is part of the PALM model system.
4#
5# PALM is free software: you can redistribute it and/or modify it under the terms
6# of the GNU General Public License as published by the Free Software Foundation,
7# either version 3 of the License, or (at your option) any later version.
8#
9# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along with
14# PALM. If not, see <http://www.gnu.org/licenses/>.
15#
16# Copyright 2018-2018  Leibniz Universitaet Hannover
17#------------------------------------------------------------------------------#
18#
19# Current revisions:
20# ------------------
21#
22#
23# Former revisions:
24# -----------------
25# $Id: palm_find_lowest_available_error_number 3118 2018-07-11 12:57:35Z suehring $
26# Initial revision
27#
28#------------------------------------------------------------------------------#
29# palm_find_lowest_available_error_number does what its name indicates
30#------------------------------------------------------------------------------#
31SOURCE="${BASH_SOURCE[0]}"
32while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
33  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
34  SOURCE="$(readlink "$SOURCE")"
35  # if $SOURCE was a relative symlink, we need to resolve it
36  # relative to the path where the symlink file was located
37  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
38done
39SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
40
41working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
42trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
43source_dir=${trunk_dir}/SOURCE
44
45contains() {
46    [[ ${1} =~ (^|[[:space:]])${2}($|[[:space:]]) ]] && return 0 || return 1
47}
48
49error_code_prefix="PA"
50
51all_found_error_codes=$(grep -A10 -P "CALL message\( " ${source_dir}/*.f90 \
52      | sed -e ':a;N;$!ba;s/ *& *\n */ /g' \
53      | grep -P "CALL message\( " \
54      | grep -oP "${error_code_prefix}(?<!\d)\d{4}(?!\d)" | sort | uniq -c  \
55      | grep -oP "${error_code_prefix}(?<!\d)\d{4}(?!\d)")
56
57for n in {1..9999} ; do
58   current_code=$(printf "${error_code_prefix}%04d" $((10#${n})))
59   if ! contains "$all_found_error_codes" "$current_code"; then
60     echo $current_code
61     break
62   fi
63done
Note: See TracBrowser for help on using the repository browser.