#!/bin/bash # # $Id: buildnetcdf_ropp 5117 2016-12-15 15:04:41Z idculv $ # #--------------------------------------------------------------------- # Build netCDF-4 (core C and/or Fortran API) packages in ROPP_ROOT # tree using (by default) a locally-defined compiler, or if 'all' # a set of F95 compilers available on MetO Linux desktops, or a sub-set # specified in a list on the command line, e.g.: # > ./buildnetcdf_ropp ifort g95 # #--------------------------------------------------------------------- # dtstamp(){ echo "$(date --utc +"%d-%b-%Y %H:%M") UT" } elapsed(){ local now=$(date "+%s") local s=$(($now-$1)) local m=$(($s/60)) local h=$(($s/3600)) m=$(($m%60)); s=$(($s%3600%60)) printf "%2.2d:%2.2d:%2.2d\n" $h $m $s } # # --- Help # if [[ "$1" == "-h" ]] || \ [[ "$1" == "--help" ]]; then echo echo "Purpose: build netCDF-4 (core C and/or Fortran interface) for ROPP" echo echo "Usage: buildnetcdf_ropp [compiler ...] [-noc|-nof]" echo echo "Options: one or more F95 compiler tags or 'all' for a set of" echo " compilers available on Met Office Linux systems" echo echo "Default: build with a locally-defined compiler to target ROPP_ROOT" echo " which defaults to the directory containing this script." echo echo "This script saves a log file to ROPP_ROOT/logs/buildnetcdf_ropp.log or if" echo "compiler(s) are given on the command line (explicitly or with 'all')" echo "then the targets are ROPP_ROOT/ &" echo "ROPP_ROOT//buildnetcdf_ropp.log" echo exit fi # # --- List of Fortran compilers to use # fclist="" mkc="y" mkf="y" while [[ -n "$1" ]]; do if [[ "$1" == "-noc" ]]; then mkc="n" elif [[ "$1" == "-nof" ]]; then mkf="n" else fclist="$fclist $1" fi shift done fclist=${fclist## } if [[ -z $fclist ]]; then fclist="local" elif [[ $fclist == "all" ]]; then fclist="gfortran \ ifort ifort13 ifort15 ifort16 \ nagfor nagfor53 nagfor60 \ pgf95 pgf15 \ sunf95" fi # # --- Default installation target path # if [[ -z $ROPP_ROOT ]]; then export ROPP_ROOT=$(readlink -fnq ${0%/*}); fi # echo "========================== netCDF Builder ===========================" # # --- Build package with each compiler in the list, with # output to screen & a log file # sepline="---------------------------------------------------------------------" errstat=0 loglist="" for fc in $fclist; do if [[ $fc == "local" ]]; then logdir=$ROPP_ROOT/log tgtdir=$ROPP_ROOT else which $fc > /dev/null 2>&1 if [[ $? -ne 0 ]]; then echo "*** Compiler $fc not installed" continue fi logdir=$ROPP_ROOT/$fc tgtdir=$ROPP_ROOT/$fc fi mkdir -p $logdir $tgtdir log=$logdir/${0##*/}.log rm -f $log loglist="$loglist $log" echo " " | tee $log echo $sepline | tee -a $log echo "Building netCDF package on $(dtstamp) host $(hostname) by $USER" | tee -a $log echo $sepline | tee -a $log start_time=$(date "+%s") echo ">> Compiler: $fc" | tee -a $log echo "Install target: $tgtdir" | tee -a $log echo "Logging to: $log" | tee -a $log if [[ $mkc == "y" ]]; then echo " " | tee $log echo "++ Core C-only package:" | tee -a $log ./buildpack netcdf $fc 2>&1 5>&1 6>&1 | tee -a $log errstat=${PIPESTATUS[0]} fi if [[ $errstat -eq 0 ]] && \ [[ $mkf == "y" ]]; then echo $sepline | tee -a $log echo "++ Fortran interface package:" | tee -a $log ./buildpack netcdff $fc 2>&1 5>&1 6>&1 | tee -a $log errstat=${PIPESTATUS[0]} fi echo $sepline | tee -a $log echo ">> Finished at: $(dtstamp) Elapsed: $(elapsed $start_time)" | tee -a $log echo $sepline | tee -a $log echo " " | tee -a $log if [[ $errstat -ne 0 ]]; then break; fi done # echo echo "=====================================================================" echo "For a record of the build status, see log files:" for log in $loglist; do echo $log done echo # exit $errstat