source: palm/trunk/SCRIPTS/palmbuild @ 3494

Last change on this file since 3494 was 3494, checked in by suehring, 6 years ago

Surface output revised and some bugs are fixed + new post-processing tool to convert binary surface output to Paraview readable VTK files

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 33.1 KB
RevLine 
[2380]1#!/bin/bash
2
3# palmbuild - script for compiling the PALM code and its utility programs
4
5#------------------------------------------------------------------------------#
[2696]6# This file is part of the PALM model system.
[2380]7#
8# PALM is free software: you can redistribute it and/or modify it under the terms
9# of the GNU General Public License as published by the Free Software Foundation,
10# either version 3 of the License, or (at your option) any later version.
11#
12# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# PALM. If not, see <http://www.gnu.org/licenses/>.
18#
[2718]19# Copyright 2017-2018  Leibniz Universitaet Hannover
[2380]20#------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
[2410]25#
[2380]26# Former revisions:
27# -----------------
[3033]28# $Id: palmbuild 3494 2018-11-06 14:51:27Z suehring $
[3494]29# Add tool for surface-output post-processing
30#
31# 3455 2018-10-30 14:12:31Z raasch
[3455]32# options -h and -d renamed -c and -r, respectively
33#
34# 3312 2018-10-06 14:15:46Z knoop
[3236]35# "host identifier" in header output renamed "config. identifier",
36# host_configuration renamed configuration_identifier,
37# jobname renamed run_identifier
38# header output of PALM code revision,
39# options -m, -s, and -S removed
40#
41# 3210 2018-08-28 07:31:13Z sward
[3210]42# Bugfix: agent_preprocessing stays in MAKE_DEPOSITORY after compilation
43#
44# 3208 2018-08-27 13:10:50Z sward
[3208]45# Added building of agent_preprocessing
46#
47# 3033 2018-05-23 15:26:19Z raasch
[2834]48# "fname" renamed to "jobname"
49#
50# 2718 2018-01-02 08:49:38Z maronga
[2716]51# Corrected "Former revisions" section
52#
53# 2696 2017-12-14 17:12:51Z kanani
54# Change in file header (GPL part)
55#
56# 2566 2017-10-20 08:50:47Z raasch
[2566]57# informative messages switched of almost completely in silent mode
58# two header blocks merged into one
59#
60# 2506 2017-09-29 08:30:37Z raasch
[2506]61# option -V added to check for an existing SOURCES_FOR_RUN_... folder
62# host configuration added to SOURCES_FOR_RUN_... folder name
63# SOURCES_FOR_RUN_... folder is deleted in case of compilation errors
64# host_identifier renamed host_configuration
65#
66# 2500 2017-09-25 11:10:03Z raasch
[2500]67# bugfix for r2492
68#
69# 2492 2017-09-21 14:18:48Z raasch
[2489]70# ask for compilation, if SOURCES_FOR_RUN_... exists
71#
72# 2487 2017-09-21 11:30:10Z raasch
[2487]73# bugfix: abort in case of compiling/linking errors in silent mode
74#
75# 2422 2017-09-08 08:25:41Z raasch
[2422]76# initial revision
[2410]77#
[2380]78#------------------------------------------------------------------------------#
79# palmbuild - script for compiling the PALM code and its utility programs
80#
81# Procedure to compile code on local and remote hosts using the
82# make-mechanism. The source code must be provided on the local host.
83#
84# @note This script does not work on MAC OS
85#------------------------------------------------------------------------------#
86
87
88    # VARIABLE DECLARATIONS + DEFAULT VALUES
89 calltime=""
90 column1=""
91 column2=""
[3236]92 configuration_identifier=default
93 global_revision=""
[2380]94 locat=normal
95 makefile=""
96 make_options=""
97 module_commands=""
98 program_name=palm
99 remote_ip=""
100 silent=false
101 ssh_key=""
102 suf=f90
[2506]103 use_existing_sources_folder=false
[2732]104 version="palmbuild  1.0  Rev$Rev: 3494 $"
[2380]105 working_directory=`pwd`
106
107
[3312]108    # ERROR HANDLING IN CASE OF EXIT
[3236]109 trap 'rm -rf  ${source_path}/${configuration_identifier}_last_make_protocol
[3312]110       if [[ $locat != normal  &&  $locat != control_c ]]
[2380]111       then
[3312]112          printf "\n\n+++ palmbuild crashed \n\n"
[2380]113          exit 1
[3312]114       elif [[ $locat != normal ]]
115       then
116          printf "\n+++ palmbuild killed by \"^C\" \n\n"
117          exit 2
[2380]118       else
[2566]119          if [[ $silent = false ]]
120          then
[3312]121            printf "\n --> palmbuild finished\n\n"
[2566]122          fi
[2380]123          exit 0
[3312]124       fi' exit
[2380]125
126
[3312]127    # ACTIONS IN CASE OF TERMINAL-BREAK (CONTROL-C):
128 trap 'locat=control_c
129       exit 1
[2380]130      ' 2
131
132
133
134    # READ SHELLSCRIPT-OPTIONS
[3455]135 while  getopts  :c:r:uvV  option
[2380]136 do
137   case  $option  in
[3455]138       (c)   configuration_identifier=$OPTARG;;
139       (r)   run_identifier=$OPTARG;;
[2380]140       (v)   silent=true;;
[2506]141       (V)   use_existing_sources_folder=true;;
[2380]142       (\?)  printf "\n  +++ unknown option $OPTARG \n";
143             locat=parameter; exit;;
144   esac
145 done
146
147
[2506]148    # BUILD THE CONFIGURATION-FILE NAME AND THE SOURCES_FOR_RUN-FOLDER NAME
[3236]149 config_file=.palm.config.$configuration_identifier
150 sources_for_run_catalog=SOURCES_FOR_RUN_${configuration_identifier}_$run_identifier
[2380]151
152
153    # CHECK, IF CONFIGURATION-FILE EXISTS
154 if [[ ! -f $config_file ]]
155 then
156    printf "\n  +++ configuration file: "
157    printf "\n           $config_file"
158    printf "\n      does not exist"
159    locat=configuration; exit 
160 fi
161
162
163    # ### is this really required?
164 config_file=$PWD/$config_file
165
166
167    # READ VARIABLE SETTINGS FROM CONFIG FILE LINE BY LINE
168 while  read line
169 do
170
171       # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES
172    eval  line=\"$line\"
173
174
175       # INTERPRET THE LINE
176    if [[ "$(echo $line)" = "" ]]
177    then
178
179          # EMPTY LINE, NO ACTION
180       continue
181
182    elif [[ "$(echo $line | cut -c1)"  =  "#" ]]
183    then
184
185          # LINE IS A COMMENT LINE
186       continue
187
188    elif [[ "$(echo $line | cut -c1)"  =  "%" ]]
189    then
190
191          # LINE DEFINES AN ENVIRONMENT-VARIABLE
192       var=`echo $line | cut -d" " -s -f1 | cut -c2-`
193       value=`echo $line | cut -d" " -s -f2-`
194
195          # REPLACE ":" BY " " IN COMPILER- CPP- OR LINKER-OPTIONS,
196          # "::" IS REPLACED BY ":".
197       #value=`echo $value | sed 's/::/%DUM%/g' | sed 's/:/ /g' | sed 's/%DUM%/:/g'`
198
199
200          # VALUE FROM THE CONFIGURATION-FILE IS ASSIGNED TO THE
201          # ENVIRONMENT-VARIABLE, BUT ONLY IF NO VALUE HAS BEEN ALREADY
202          # ASSIGNED WITHIN THIS SCRIPT (E.G. BY SCRIPT-OPTIONS).
203          # NON-ASSIGNED VARIABLES HAVE VALUE "" OR 0 (IN CASE OF INTEGER).
204          # HENCE THE GENERAL RULE IS: SCRIPT-OPTION OVERWRITES THE
205          # CONFIGURATION-FILE.
206       if [[ "$(eval echo \$$var)" = ""  ||  "$(eval echo \$$var)" = "0" ]]
207       then
208          eval  export  $var="\$value"
209
210             # TERMINAL OUTPUT OF ENVIRONMENT-VARIABLES, IF TRACEBACK IS SWITCHED on
211          if [[ $do_trace = true ]]
212          then
213             printf "\n*** ENVIRONMENT-VARIABLE $var = $value"
214          fi
215       fi
216
217    else
218
219          # SKIP ALL OTHER LINES
220       continue
221
222    fi
223
224 done < $config_file
225
226 
[2404]227    # CHECK, IF THE BASE DIRECTORY PATH HAS BEEN GIVEN
228 if [[ "$base_directory" = "" ]]
229 then
230    printf "\n  +++ no base directory found in configuration file"
231    locat=config_file; exit
232 else
233    if [[ ! -d $base_directory ]]
234    then
235       printf "\n\n  +++ base directory \"$base_directory\" "
236       printf "\n      does not exist"
237       locat=source_path; exit
238    fi
239 fi
240
241
[2380]242    # CHECK SOURCE-CODE PATH
243 if [[ "$source_path" = "" ]]
244 then
245    printf "\n  +++ no source path found in configuration file"
246    locat=config_file; exit
247 else
248    if [[ ! -d $source_path ]]
249    then
250       printf "\n\n  +++ source path \"$source_path\" "
251       printf "\n      does not exist"
252       locat=source_path; exit
253    fi
254 fi
255
256
257    # CHECK MAKEFILE
[3236]258 makefile=$source_path/Makefile
[2380]259 if [[ ! -f $makefile ]]
260 then
261    printf "\n  +++ makefile: "
262    printf "\n           $makefile"
263    printf "\n      does not exist"
264    locat=makefile; exit 
265 fi
266
267
268    # CHECK COMPILERNAME
269 if [[ "$compiler_name" = "" ]]
270 then
271    printf "\n  +++ no compiler name found in configuration file"
272    locat=config_file; exit
273 fi
274
275
276    # CHECK SERIAL COMPILERNAME
277 if [[ "$compiler_name_ser" = "" ]]
278 then
279    printf "\n  +++ no compiler name for serial compilation in configuration file"
280    locat=config_file; exit
281 fi
282
283
284    # DETERMINE SSH-KEY TO BE USED
285 if [[ "$ssh_key" != "" ]]
286 then
287    ssh_key="-i $HOME/.ssh/`echo $line | cut -d" " -s -f2`"
288 fi
289
290
291    #CHECK CPP-OPTIONS
292 if [[ "$cpp_options" = "" ]]
293 then
294    printf "\n  +++ WARNING: no cpp-options found in configuration file"
295 fi
296
297
298    # CHECK SETTINGS IN CASE OF COMPILING ON REMOTE MACHINE
299 if [[ "$remote_ip" != "" ]]
300 then
301 
302    if [[ "$remote_username" = "" ]]
303    then
304       printf "\n  +++ no user name given in configuration file"
305       locat=config_file; exit
306    fi
307
308       # GET SOURCE AND DEPOSITORY PATH ON THE REMOTE MACHINE WITHOUT EVALUATING
309       # THE $
310       # IF NOT GIVEN, USE THE LOCAL SOURCE AND DEPOSITORY PATH
311    line=`grep %remote_source_path $config_file`
312    if [[ "$line" != "" ]]
313    then
314       remote_source_path=`echo $line | cut -d" " -s -f2`
315    else
316       line=`grep %source_path $config_file`
317       remote_source_path=`echo $line | cut -d" " -s -f2`
318    fi
319
[2404]320    line=`grep %base_directory $config_file`
[3236]321    make_depository=`echo $line | cut -d" " -s -f2`/MAKE_DEPOSITORY_${configuration_identifier}
[2380]322
323 else
324
[3236]325    make_depository=${base_directory}/MAKE_DEPOSITORY_${configuration_identifier}
[2380]326
327 fi
328
[3236]329
330    # GET THE GLOBAL REVISION-NUMBER OF THE SVN-REPOSITORY
331 global_revision=`svnversion $source_path  2>/dev/null`
332 global_revision="Rev: $global_revision"
333
334
[2380]335    # HEADER-OUTPUT (PART1: MESSAGES CONCERNING THE LOCAL HOST)
336 if [[ $silent = false ]]
337 then
[2566]338    calltime=$(date)
339    printf "\n"
340    printf "#------------------------------------------------------------------------# \n"
341    printf "| %-40s%30s | \n" "$version" "$calltime"
[3236]342    printf "| %-40s%30s | \n" "PALM code       $global_revision" " "
[2566]343    printf "|                                                                        | \n"
344    printf "| %-13s%-57s | \n" "called on:" "$(hostname) (IP:$local_ip)"
345    column2=$(echo $config_file | cut -c1-57 )
346    printf "| %-13s%-57s | \n" "config file:" "$column2"
347    line=$(echo "$config_file" | cut -c58-)
348    while [[ "$line" != "" ]]
[2380]349    do
[2566]350       column1=""
351       column2=$(echo $line | cut -c1-57 )
352       printf "| %-13s%-57s | \n" "$column1" "$column2"
353       line=$(echo "$line" | cut -c58-)
[2380]354    done
[2566]355    column2=$(echo $makefile | cut -c1-57 )
356    printf "| %-13s%-57s | \n" "makefile:" "$column2"
357    line=$(echo "$makefile" | cut -c58-)
358    while [[ "$line" != "" ]]
359    do
360       column1=""
361       column2=$(echo $line | cut -c1-57 )
362       printf "| %-13s%-57s | \n" "$column1" "$column2"
363       line=$(echo "$line" | cut -c58-)
364    done
365    column2=$(echo $source_path | cut -c1-57 )
366    printf "| %-13s%-57s | \n" "source path:" "$column2"
367    line=$(echo "$source_path" | cut -c58-)
368    while [[ "$line" != "" ]]
369    do
370       column1=""
371       column2=$(echo $line | cut -c1-57 )
372       printf "| %-13s%-57s | \n" "$column1" "$column2"
373       line=$(echo "$line" | cut -c58-)
374    done
375    printf "|                                                                        | \n"
376   
[2380]377    if [[ "$remote_ip" != "" ]]
378    then
[3236]379       column2="$configuration_identifier"
380       printf "| %-20s%-50s | \n" "config. identifier:" "$column2"
[2404]381       column2=$(echo "$make_depository" | cut -c1-50 )
[2380]382       printf "| %-20s%-50s | \n" "remote depository:" "$column2"
383    else
[3236]384       column2="$configuration_identifier"
385       printf "| %-20s%-50s | \n" "config. identifier:" "$column2"
[2404]386       column2=$(echo "$make_depository" | cut -c1-50 )
[2380]387       printf "| %-20s%-50s | \n" "local depository:" "$column2"
388    fi
[2404]389    line=$(echo "$make_depository" | cut -c51-)
390    while [[ "$line" != "" ]]
391    do
392       column1=""
393       column2=$(echo "$line" | cut -c1-50 )
394       printf "| %-20s%-50s | \n" "$column1" "$column2"
395       line=$(echo "$line" | cut -c51-)
396    done
[2566]397   
[2380]398    if [[ "$remote_ip" != "" ]]
399    then
400       printf "| %-20s%-50s | \n" "remote username:" "$remote_username"
401       printf "| %-20s%-50s | \n" "remote address:" "$remote_ip"
402    else
403       printf "| %-20s%-50s | \n" "username:" "$local_username"
404       printf "| %-20s%-50s | \n" "address:" "$local_ip"
405    fi
[2566]406   
[2380]407    printf "| %-20s%-50s | \n" "compiler:" "$compiler_name"
408    printf "| %-20s%-50s | \n" "serial compiler:" "$compiler_name_ser"
[2566]409   
[2380]410    if [[ "$make_options" != "" ]]
411    then
412       printf "| %-20s%-50s | \n" "make options:" "$make_options"
413    fi
414    column2=$(echo "$cpp_options" | cut -c1-50 )
415    printf "| %-20s%-50s | \n" "cpp options:" "$column2"
416    line=$(echo "$cpp_options" | cut -c51-)
417    while [[ "$line" != "" ]]
418    do
419       column1=""
420       column2=$(echo "$line" | cut -c1-50 )
421       printf "| %-20s%-50s | \n" "$column1" "$column2"
422       line=$(echo "$line" | cut -c51-)
423    done
424    column2=$(echo "$compiler_options" | cut -c1-50 )
425    printf "| %-20s%-50s | \n" "compiler options:" "$column2"
426    line=$(echo "$compiler_options" | cut -c51-)
427    while [[ "$line" != "" ]]
428    do
429       column1=""
430       column2=$(echo "$line" | cut -c1-50 )
431       printf "| %-20s%-50s | \n" "$column1" "$column2"
432       line=$(echo "$line" | cut -c51-)
433    done
[2388]434    column2=$(echo "$linker_options" | cut -c1-50 )
435    printf "| %-20s%-50s | \n" "linker options:" "$column2"
436    line=$(echo "$linker_options" | cut -c51-)
[2380]437    while [[ "$line" != "" ]]
438    do
439       column1=""
440       column2=$(echo "$line" | cut -c1-50 )
441       printf "| %-20s%-50s | \n" "$column1" "$column2"
442       line=$(echo "$line" | cut -c51-)
443    done
444    if [[ "$login_init_cmd" != "" ]]
445    then
446       column2=$(echo "$login_init_cmd" | cut -c1-50 )
447       printf "| %-20s%-50s | \n" "login init command:" "$column2"
448       line=$(echo "$login_init_cmd" | cut -c51-)
449       while [[ "$line" != "" ]]
450       do
451          column1=""
452          column2=$(echo "$line" | cut -c1-50 )
453          printf "| %-20s%-50s | \n" "$column1" "$column2"
454          line=$(echo "$line" | cut -c51-)
455       done
456    fi
457    if [[ "$module_commands" != "" ]]
458    then
459       column2=$(echo "$module_commands" | cut -c1-50 )
460       printf "| %-20s%-50s | \n" "module command(s):" "$column2"
461       line=$(echo "$module_commands" | cut -c51-)
462       while [[ "$line" != "" ]]
463       do
464          column1=""
465          column2=$(echo "$line" | cut -c1-50 )
466          printf "| %-20s%-50s | \n" "$column1" "$column2"
467          line=$(echo "$line" | cut -c51-)
468       done
469    fi
470    printf "#------------------------------------------------------------------------# \n"
471
[2566]472    answer=dummy
473    printf "\n"
474    while [[ "$answer" != y  &&  "$answer" != Y  && "$answer" != c  &&  "$answer" != C  && "$answer" != s  &&  "$answer" != S  &&  "$answer" != a  &&  "$answer" != A ]]
475    do
476       printf " >>> continue (y(es)/c(ontinue)/a(bort)) ?  "
477       read  answer
478    done
479    if [[ $answer = a  ||  $answer = A ]]
[2380]480    then
[2566]481       locat=user_abort; exit
[2380]482    fi
[2566]483    if [[ $answer = c  ||  $answer = C ]]
484    then
485       silent=true
486    fi
487 fi
[2380]488
489
[2566]490    # TAR THE SOURCES AND MAKEFILES
491    # UTILITIES ARE TEMPORARILY COPIED TO THE SOURCE DIRECTORY IN ORDER TO TAR
492    # THEM TOO
493 if [[ $silent = false ]]
494 then
495    printf "\n\n  *** tar of makefile and source files in"
496    printf "\n      $source_path\n"
497 fi
498 cd  $source_path
499 cp -p  ../UTIL/combine_plot_fields.f90  .
500 cp -p  ../UTIL/compare_palm_logs.f90  .
[3208]501 cp -p  ../UTIL/agent_preprocessing/agent_preprocessing.f90  .
[3494]502 cp -p  ../UTIL/surface_output_processing/surface_output_to_vtk.f90  .
[2566]503 cp -p  ../UTIL/Makefile_utilities  .
504 tar -cf  ${program_name}_sources.tar  Makefile*  *.$suf
[3494]505 rm  combine_plot_fields.f90  compare_palm_logs.f90 agent_preprocessing.f90  surface_output_to_vtk.f90 Makefile_utilities
[2566]506
507
508    # MAKE ON REMOTE HOST
509 if [[ "$remote_ip" != "" ]]
510 then
511
512       # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_...
[3236]513    if [[ "$run_identifier" = "" ]]
[2380]514    then
515
[2566]516          # COPY CURRENT SOURCE CODE TO SOURCE-CODE DIRECTORY ON THE REMOTE HOST
517          # CREATE THIS DIRECTORY, IF IT DOES NOT EXIST
518       if [[ $silent = false ]]
[2380]519       then
[2566]520          echo " "
[2404]521          echo "  *** copying \"${program_name}_sources.tar\" to \"${remote_ip}:${make_depository}/\" "
522          echo "[[ ! -d ${make_depository} ]]  &&  (echo \"  *** ${make_depository} will be created\"; mkdir -p  ${make_depository})"  |  ssh  -q  $ssh_key ${remote_username}@${remote_ip}  2>&1
523          scp  $ssh_key ${source_path}/${program_name}_sources.tar  ${remote_username}@${remote_ip}:${make_depository}/${program_name}_sources.tar
[2566]524       else
525          echo "[[ ! -d ${make_depository} ]]  &&  mkdir -p  ${make_depository}"  |  ssh  -q  $ssh_key ${remote_username}@${remote_ip}  2>&1
526          scp  $ssh_key ${source_path}/${program_name}_sources.tar  ${remote_username}@${remote_ip}:${make_depository}/${program_name}_sources.tar  >  /dev/null
527       fi
[2380]528
529
530
[2566]531
532          # UNTAR PREVIOUS UPDATE ON REMOTE HOST, IF EXISTING
533       if [[ $silent = false ]]
534       then
[2380]535          echo "  *** untar previous update on remote host, if existing"
[2566]536       fi
537       echo "cd ${make_depository}; [[ -f ${program_name}_current_version.tar ]]  &&  tar -xf  ${program_name}_current_version.tar"  |  ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  2>&1
[2380]538
539
[2566]540          # UNTAR CURRENT SOURCES ON REMOTE HOST
541       if [[ $silent = false ]]
542       then
[2380]543          echo "  *** untar current sources on remote host"
[2566]544       fi
545       echo  "cd ${make_depository}; tar -xf  ${program_name}_sources.tar"  |  ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  2>&1
[2380]546
547
[2566]548          # CREATE INIT AND MODULE COAMMNDS
549       [[ "$login_init_cmd" != "" ]]   &&  login_init_cmd=${login_init_cmd}";"
550       [[ "$module_commands" != "" ]]  &&  module_commands=${module_commands}";"
[2380]551
552
[2566]553          # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES
554       if [[ $silent = false ]]
555       then
[2380]556          echo " "
557          echo "  *** creating utilities on remote host"
[2566]558       fi
559       make_call_string="make  -f Makefile_utilities  $make_options  F90=$compiler_name  F90_SER=$compiler_name_ser  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
[3236]560       echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]561
[3236]562       if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
[2566]563       then
564          printf "\a\n  +++ error(s) occurred during compiling or linking of utilities"
[3236]565          printf "\n      for host configuration \"$configuration_identifier\" "
[2566]566          if [[ $silent = false ]]
[2380]567          then
[2566]568             answer=dummy
569             printf "\n"
570             while [[ "$answer" != c  &&  "$answer" != k ]]
571             do
572                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
573                read  answer
574                if [[ "$answer" = l ]]
[2380]575                then
[3236]576                   more ${configuration_identifier}_last_make_protocol
[2380]577                fi
[2566]578             done
579             if [[ $answer = k ]]
580             then
[2487]581                locat=user_abort; exit
[2380]582             fi
[2566]583          else
584                # ABORT ANYWAY
585             locat=user_abort; exit
[2380]586          fi
[2566]587       fi
[2380]588
[2566]589          # NOW COMPILE THE PALM CODE
590          # COMMANDS WILL BE COMMUNICATED TO SSH VIA PIPE, SINCE THIS WAY THE SYSTEM- AND
591          # USER-PROFILES OF THE SHELL ARE COMPLETELY EXECUTED (OTHERWISE, MAKE
592          # MAY E.G. MISS THE COMPILER-PATHS)
593       if [[ $silent = false ]]
594       then
[2380]595          echo " "
596          echo "  *** compile PALM sources on remote host"
[2566]597       fi
598       make_call_string="make  $make_options  PROG=$program_name  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
[3236]599       echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]600
[3236]601       if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
[2566]602       then
[3236]603          printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]604          if [[ $silent = false ]]
[2380]605          then
[2566]606             answer=dummy
607             printf "\n"
608             while [[ "$answer" != c  &&  "$answer" != k ]]
609             do
610                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
611                read  answer
612                if [[ "$answer" = l ]]
[2380]613                then
[3236]614                   more ${configuration_identifier}_last_make_protocol
[2380]615                fi
[2566]616             done
617             if [[ $answer = k ]]
618             then
[2487]619                locat=user_abort; exit
[2380]620             fi
[2566]621          else
622                # ABORT ANYWAY
623             locat=user_abort; exit
[2380]624          fi
[2566]625       fi
[2380]626
[2566]627          # TAR UPDATED VERSION ON THE REMOTE HOST
628       if [[ $silent = false ]]
629       then
[2380]630          printf "\n  *** tar update on remote host ..."
[2566]631       fi
632       echo  "cd ${make_depository}; chmod u+w *; tar -cf  ${program_name}_current_version.tar  ${program_name}  *.f90 *.o *.mod *.x"  |  ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  2>&1
[2380]633
634
[2566]635       # NOW COMES THE BRANCH FOR CREATING THE EXECUTABLE FOR THE CURRENT RUN
636       # INCLUDING E.G. USER-INTERFACE ROUTINES. ALSO ADD OTHER UTILITY EXECUTABLES. EVERYTHING IS
637       # COLLECTED IN DIRECTORY SOURCES_FOR_RUN_...
[3236]638    elif [[ "$run_identifier" != "" ]]
[2566]639    then
640
641          # FIRST CHECK, IF COMPILED SOURCES FOR THIS RUN IDENTIFIER EXISTS
642          # AND ASK, IF THEY SHALL BE USED
[3236]643       echo  "[[ -d ${fast_io_catalog}/${sources_for_run_catalog} ]]  &&  echo sources for run found" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1  >  ${configuration_identifier}_last_make_protocol
644       if [[ $(grep -c "sources for run found" ${configuration_identifier}_last_make_protocol) != 0  &&  $use_existing_sources_folder = true ]]
[2380]645       then
[3236]646          printf "\a\n  *** compiled sources for run \"$run_identifier\" found on remote host in folder"
[2566]647          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
648          printf "\n      will be used!"
649          exit
650       fi
[2380]651
[2566]652          # COPY MAKE DEPOSITORY ON REMOTE MACHINE TO SOURCES_FOR_RUN_...
653       if [[ $silent = false ]]
654       then
[3236]655          printf "\n  *** copy MAKE_DEPOSITORY_${configuration_identifier} on remote host to $sources_for_run_catalog \n"
[2566]656       fi
657       echo  "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}; mkdir -p ${fast_io_catalog}/${sources_for_run_catalog}; cp ${make_depository}/${program_name}_current_version.tar  ${fast_io_catalog}/${sources_for_run_catalog}; cd ${fast_io_catalog}/${sources_for_run_catalog}; tar xf ${program_name}_current_version.tar"  |  ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  2>&1
[2380]658
659
[2566]660          # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_... ON THE REMOTE MACHINE
661       if [[ $silent = false ]]
662       then
[2506]663          printf "\n  *** copy ${base_directory}/${sources_for_run_catalog}"
664          printf "\n      to $sources_for_run_catalog on remote host \n"
[2566]665       fi
666       scp  -q  $ssh_key  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${remote_username}@${remote_ip}:${fast_io_catalog}/${sources_for_run_catalog}
[2380]667
668
[2566]669          # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY
670       if [[ $(ls -1 ${base_directory}/${sources_for_run_catalog}/ | grep -c .$suf) != 0 ]]
671       then
672
673          make_call_string="make  $make_options  PROG=$program_name  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
674          [[ "$login_init_cmd" != "" ]]   &&  login_init_cmd=${login_init_cmd}";"
675          [[ "$module_commands" != "" ]]  &&  module_commands=${module_commands}";"
676          if [[ $silent = false ]]
[2380]677          then
678             echo "  *** execute \"make\" on remote host"
[2566]679          fi
[3236]680          echo "$login_init_cmd $module_commands cd ${fast_io_catalog}/${sources_for_run_catalog}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]681
[3236]682          if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
[2566]683          then
[3236]684             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]685             if [[ $silent = false ]]
[2380]686             then
[2566]687                answer=dummy
688                printf "\n"
689                while [[ "$answer" != c  &&  "$answer" != k ]]
690                do
691                   printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
692                   read  answer
693                   if [[ "$answer" = l ]]
[2380]694                   then
[3236]695                      more ${configuration_identifier}_last_make_protocol
[2380]696                   fi
[2566]697                done
698                if [[ $answer = k ]]
699                then
[2506]700                   echo "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1
[2487]701                   locat=user_abort; exit
[2380]702                fi
[2566]703             else
704                   # ABORT ANYWAY
705                echo "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1
706                locat=user_abort; exit
[2380]707             fi
[2566]708          fi
[2380]709
[2566]710       else
[2380]711
[2566]712          echo "  *** nothing to compile for this run"
[2380]713
714       fi
715
[2566]716    fi
[2380]717
[3236]718    rm -rf  ${source_path}/${configuration_identifier}_last_make_protocol
[2380]719
720
[2566]721    # MAKE ON LOCAL HOST
722 else
[2380]723
[2566]724
725       # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_... ON THE
726       # LOCAL HOST
[3236]727    if [[ "$run_identifier" = "" ]]
[2566]728    then
729
730          # SET THE ENVIRONMENT (EXECUTE INIT AND MODULE COMMANDS)
731       if [[ "$login_init_cmd" != "" ]]
[2380]732       then
[2566]733          $login_init_cmd
734       fi
[2380]735
[2566]736       if [[ "$module_commands" != "" ]]
737       then
738          $module_commands
739       fi
[2380]740
741
[2566]742          # CREATE MAKE-DEPOSITORY, IF IT DOES NOT EXIST
743       eval make_depository=$make_depository
744       if [[ ! -d $make_depository ]]
745       then
746          if  mkdir -p $make_depository
[2380]747          then
[2566]748             if [[ $silent = false ]]
[2380]749             then
750                printf "\n\n  *** directory for local make depository:"
[2404]751                printf "\n           $make_depository"
[2380]752                printf "\n      was created\n"
753             fi
[2566]754          else
755             printf "\n  +++ directory for local make depository:"
756             printf "\n           $make_depository"
757             printf "\n      cannot be created"
758             locat=local_depository; exit
[2380]759          fi
[2566]760       fi
[2380]761
[2566]762          # COPY SOURCE-CODE FROM REPOSITORY TO MAKE-DEPOSITORY
763       if [[ $silent = false ]]
764       then
[2380]765          echo " "
766          echo "  *** untar current source sources on local host in"
[2404]767          echo "      $make_depository"
[2566]768       fi
769       cd  $make_depository
770       cp  $source_path/${program_name}_sources.tar  .
771       tar xf  ${program_name}_sources.tar
[2380]772
773
[2566]774          # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES
775       if [[ $silent = false ]]
776       then
[2380]777          echo " "
778          echo "  *** creating utilities on local host"
[2566]779       fi
[3312]780       make  -f Makefile_utilities  $make_options  F90=$compiler_name  F90_SER=$compiler_name_ser  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options" | tee ${configuration_identifier}_last_make_protocol
[2380]781
[3312]782       if [[ ${PIPESTATUS[0]} != 0 ]]
783       then
784          printf "\a\n  +++ error(s) occurred during compiling of the utilities for host configuration \"$configuration_identifier\" "
785          if [[ $silent = false ]]
786          then
787             answer=dummy
788             printf "\n"
789             while [[ "$answer" != c  &&  "$answer" != k ]]
790             do
791                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
792                read  answer
793                if [[ "$answer" = l ]]
794                then
795                   more ${configuration_identifier}_last_make_protocol
796                fi
797             done
798             if [[ $answer = k ]]
799             then
800                locat=user_abort; exit
801             fi
802          else
803             # ABORT ANYWAY
804             locat=user_abort; exit
805          fi
806       else
807          cp agent_preprocessing $source_path/../SCRIPTS/.
808       fi
[2380]809
[3312]810
[2566]811          # CALL MAKE ON LOCAL HOST USING THE  OPTIONS DETERMINED FURTHER ABOVE
812       if [[ $silent = false ]]
813       then
[2380]814          echo " "
815          echo "  *** compile PALM sources on local host"
[2566]816       fi
[2380]817
[3236]818       make  $make_options  PROG=$program_name  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options"  2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]819
[3312]820       if [[ ${PIPESTATUS[0]} != 0 ]]
[2566]821       then
[3236]822          printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]823          if [[ $silent = false ]]
[2380]824          then
[2566]825             answer=dummy
826             printf "\n"
827             while [[ "$answer" != c  &&  "$answer" != k ]]
828             do
829                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
830                read  answer
831                if [[ "$answer" = l ]]
[2380]832                then
[3236]833                   more ${configuration_identifier}_last_make_protocol
[2380]834                fi
[2566]835             done
836             if [[ $answer = k ]]
837             then
[2487]838                locat=user_abort; exit
[2380]839             fi
[2566]840          else
841                # ABORT ANYWAY
842             locat=user_abort; exit
[2380]843          fi
[2566]844       fi
[2380]845
846
[2566]847          # TAR NEW VERSION ON LOCAL HOST
848       if [[ $silent = false ]]
849       then
[2380]850          printf "\n  *** tar update on local host ..."
[2566]851       fi
852       tar -cf  ${program_name}_current_version.tar  ${program_name} *.$suf *.o *.mod *.x
[2380]853
[2566]854    else
[2380]855
[2566]856          # NOW COMES THE BRANCH FOR CREATING THE EXECUTABLE FOR THE CURRENT RUN
857          # INCLUDING E.G. USER-INTERFACE ROUTINES. ALSO ADD OTHER UTILITY EXECUTABLES. EVERYTHING IS
858          # COLLECTED IN DIRECTORY SOURCES_FOR_RUN_...
[2380]859
[2566]860          # FIRST CHECK, IF COMPILED SOURCES FOR THIS RUN IDENTIFIER EXISTS
861          # AND ASK, IF THEY SHALL BE USED
862       if [[ -d ${fast_io_catalog}/${sources_for_run_catalog}  &&  $use_existing_sources_folder = true ]]
863       then
[3236]864          printf "\a\n  *** compiled sources for run \"$run_identifier\" found on local host in folder"
[2566]865          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
866          printf "\n      will be used!"
867          exit
868       fi
[2489]869
[2566]870          # SECOND CHECK, IF A DEPOSITORY EXISTS ON THE LOCAL MACHINE
871       if [[ ! -d ${make_depository} ]]
872       then
873          printf "\n  +++ directory for local make depository:"
874          printf "\n           $make_depository"
[3455]875          printf "\n      not found. Please run \"palmbuild -c $configuration_identifier\" "
[2566]876          locat=make_depository; exit
877       fi
[2380]878
879
[2566]880          # COPY MAKE DEPOSITORY ON LOCAL MACHINE TO SOURCES_FOR_RUN_...
881       if [[ $silent = false ]]
882       then
[3236]883          printf "\n  *** copy MAKE_DEPOSITORY_${configuration_identifier} on local host to "
[2506]884          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog} \n"
[2566]885       fi
886       rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
887       mkdir -p ${fast_io_catalog}/${sources_for_run_catalog}
888       cp ${make_depository}/${program_name}_current_version.tar  ${fast_io_catalog}/${sources_for_run_catalog}
889       cd $fast_io_catalog/${sources_for_run_catalog}
890       tar xf ${program_name}_current_version.tar
[2380]891
892
[2566]893          # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_...
894          # IN THE FAST_IO_CATALOG ON THE LOCAL MACHINE
895       if [[ $silent = false ]]
896       then
[2506]897          printf "\n  *** copy ${base_directory}/${sources_for_run_catalog} to"
898          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog} on local host \n"
[2566]899       fi
900       cp  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${fast_io_catalog}/${sources_for_run_catalog}
[2380]901
902
[2566]903          # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY
904       if [[ $(ls -1 ${base_directory}/${sources_for_run_catalog}/ | grep -c .$suf) != 0 ]]
905       then
906
907          if [[ $silent = false ]]
[2380]908          then
909             echo "  *** execute \"make\" on local host"
[2566]910          fi
911          [[ "$login_init_cmd" != "" ]]   &&  $login_init_cmd
912          [[ "$module_commands" != "" ]]  &&  $module_commands
[2380]913
[2566]914          make  $make_options  PROG=$program_name  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options"
[2380]915
[3312]916          if [[ ${PIPESTATUS[0]} != 0 ]]
[2566]917          then
918
[3236]919             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]920             if [[ $silent = false ]]
[2380]921             then
[2566]922                answer=dummy
923                printf "\n"
924                while [[ "$answer" != c  &&  "$answer" != k ]]
925                do
926                   printf "  >>> continue / kill palmbuild (c/k) ? "
927                   read  answer
928                done
929                if [[ $answer = k ]]
[2380]930                then
[2506]931                   rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
[2487]932                   locat=user_abort; exit
[2380]933                fi
[2566]934             else
935                   # ABORT ANYWAY
936                rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
937                locat=user_abort; exit
[2380]938             fi
[2566]939          fi
[2380]940
[2566]941       else
[2380]942
[2566]943          echo "  *** nothing to compile for this run"
[2380]944
[2566]945       fi
[2380]946
947    fi
[2566]948 fi
Note: See TracBrowser for help on using the repository browser.