#!/bin/bash # --------------------------------------------------------------------------- # # comp : Compiler script for use in ad3 (customized for hardware and # # optimization). Note that this script will not be replaced if part # # of WAVEWATCH III is re-installed. Used by ad3. # # # # use : comp name # # name: name of source code file without the extension. # # # # error codes : 1 : input error # # 2 : no environment file $ww3_env found. # # 3 : error in creating scratch directory. # # 4 : w3adc error. # # 5 : compiler error. # # # # remarks : # # # # - This script runs from the scratch directory, where it should remain. # # # # - For this script to interact with ad3, it needs to generate / leave # # following files : # # $name.F90 : Source code (generated by ad3). # # $name.l : Listing file. # # $name.o : Object module. # # comp.stat.$name : status file of compiler, containing number of # # errors and number of warnings (generated by comp) # # # # - Upon (first) installation of WAVEWATCH III the user needs to check the # # existing compilers and options available in the script cmplr.env # # # # - This version is a template for mpt/intel/gnu/pgi with optimized or # # debugging options by adding _debug # # # # M. Accensi # # August 2018 # # --------------------------------------------------------------------------- # # 1. Preparations # # --------------------------------------------------------------------------- # # 1.a Check and process input if [ "$#" -ne '1' ] then echo "usage: comp name" ; exit 1 fi name="$1" echo " Compiling $name" # 1.b Initial clean-up - - - - - - - - - - - - - - - - - - - - - - - - - - - - rm -f $name.l rm -f $name.o rm -f $name.out rm -f $name.err rm -f comp.stat.$name # --------------------------------------------------------------------------- # # 2. Compile # # --------------------------------------------------------------------------- # # 2.a Build options and determine compiler name - - - - - - - - - - - - - - - - # compiler if [ "$mpi_mod" = 'yes' ] ; then comp='' else comp='' fi # compilation options opt="" # oasis coupler include dir if [ "$oasis_mod" = 'yes' ] then opt="$opt -I$OASISDIR/build/lib/psmile.MPI1" fi # netcdf include dir if [ "$netcdf_compile" = 'yes' ] then case $WWATCH3_NETCDF in NC3) opt="$opt -I$NETCDF_INCDIR" ;; NC4) if [ "$mpi_mod" = 'no' ]; then comp="`$NETCDF_CONFIG --fc`"; fi opt="$opt -I`$NETCDF_CONFIG --includedir`" ;; esac fi # ftn include dir opt="$opt -I$path_i" opt="$opt $ESMF_F90COMPILEPATHS" opt="$opt $EXTRA_COMP_OPTIONS" # 2.b Compile - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $comp $opt $name.$fext 1> $name.out 2> $name.err OK="$?" # --------------------------------------------------------------------------- # # 3. Postprocessing # # --------------------------------------------------------------------------- # # 3.a Capture errors - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # nr_err : number of errors. # nr_war : number of warnings. nr_err='0' nr_war='0' if [ -s $name.err ] then nr_err="$(grep -i error $name.err | wc -l | awk '{ print $1 }')" nr_war="$(grep -i warning $name.err | wc -l | awk '{ print $1 }')" else if [ "$OK" != '0' ] then nr_err='1' fi fi # 3.b Make file comp.stat - - - - - - - - - - - - - - - - - - - - - - - - - - echo "ERROR $nr_err" > comp.stat.$name echo "WARNING $nr_war" >> comp.stat.$name # 3.c Prepare listing - - - - - - - - - - - - - - - - - - - - - - - - - - - - # if compiler does not provide listing, make listing from source code # and compiler messages. Second input line for w3list identifies if # comment lines are to be numbered. # listing done by the compiler if [ -s $name.lst ] then mv $name.lst $name.l fi # listing done by w3list if [ ! -f $name.l ] then echo "w3list $name.$fext" echo "$name.$fext" > w3list.inp echo "T" >> w3list.inp w3list < w3list.inp 2> /dev/null rm -f w3list.inp mv w3list.out $name.l fi # add comp options, warnings and error to listing if [ -s $name.l ] then echo '------------' >> $name.l echo "$comp $opt" >> $name.l echo '------------' >> $name.l cat $name.out >> $name.l 2> /dev/null echo '------------' >> $name.l cat $name.err >> $name.l 2> /dev/null echo '------------' >> $name.l fi # remove empty warning and error files # find . -name "*.out" -or -name "*.err" -empty -delete # end of comp --------------------------------------------------------------- #