#! /bin/ksh ################################################################################ # # Script to generate a component model compile script # # File : ~/util/compile/frames/Create_COMP_models.frm # # Stephanie Legutke, MPI-HH, M&D Dec 14, 2004 # # This script is used to generate a compile script for a PRISM component model. # The script is specifically created for the target platform. # Depending on the node name it selects site and OS specifics. # The node name is either detected with `uname -n` or, if the script is not # created on the target machine, it must be specifieid by the user. # The generated compile script is moved to ~/src/mod/'modelname' # after successful generation. # The script uses m4 for preprocessing. It has been tested with # GNU m4 version 1.4. Other, older or non-GNU versions of m4 may fail! # # This script is called interactively only. # # 7 positional parameters : # # Usage : Create_COMP_models.frm \ # 'model_name' \ # [message_passing [std out [std err [node[version[partner models]]]]]] # # $1='model_name' (required) # $2=""/"MPI1"/"NONE" message passing # $3=""/"-" directing std output to a file / the screen # $4=""/"-"/"+" directing err output to a file / the screen / stdout # $5=""/"'node'" node name for header files with OS/site specs # $6=""/"'version'" version acronym for differentiation of executables # $7=""/"partner models" models of the coupled model constellation # # If not called with all parameters, the defaults are: # $2 MPI2 # $3 gmake directs stdout to a file # $4 gmake directs stderr to a file # $5 node name `uname -n` of the machine where the script is run # $6 D10 # $7 " " (standalone) # # # Note: if the model has not yet been ported to a machine (specified by # node name) a message like: infile.m4:53: m4: Cannot open include/... # for some model or machine dependent header file will be given. # These files have to be provided then. # ################################################################################ set +x if [ "$1" = "" ] || [ "$1" = "--" ] || [ "$1" = "help" ] || [ "$1" = "--help" ] ; then echo echo '--------------------------------------------------------------------------' echo ' ' echo ' This script may fail if you do not use the right version of m4!' if [ "$5" = "rhodes" ] ; then echo ' The version you use is :' `/usr/freeware/bin/m4 --version` elif [ "$5" = "zahir" ] ; then echo ' The version you use is :' `/usr/local/bin/m4 --version` elif [ "$5" = "vargas" ] ; then echo ' The version you use is :' '`/usr/local/pub/M4/m4-1.4.11/bin/m4 --version`' else echo ' The version you use is :' `m4 --version` fi echo ' Make sure this is GNU m4 younger than version 1.4!' echo ' ' echo '--------------------------------------------------------------------------' echo '----------- Usage --------------------------------------------------------' echo ' $1=model name (none)' echo ' $2=""/"MPI1"/"NONE": message passing (MPI2)' echo ' $3=""/"-": std output of compile script -> file / screen (file)' echo ' $4=""/"-"/"+": err output -> file / the screen / stdout (file)' echo ' $5=""/"node name": node name of compile server (`uname -n`)' echo ' $6="version acronym" (none)' echo ' $7="list of participating models" (none)' echo '' echo ' Specification of defaults is not allowed: write e.g.' echo ' Create_COMP_models.frm oasis3 "" - "" ""' echo ' instead of' echo ' Create_COMP_models.frm oasis3 "MPI2" - "" ""' echo '--------------------------------------------------------------------------' exit fi # # Model names for header file selection # list_of_PRISM_models="arpege_climat4 echam5 hamocc ham lim lmdz mozart mpi-om oasis3 opa orchidee pisces psmodel toy4opa toyatm toyche toyoce toy4arpege" valid_model=no for spec_model in ${list_of_PRISM_models}; do if [ "$1" = "$spec_model" ]; then valid_model=yes model=$1 fi done if [ "${valid_model}" = "no" ]; then echo ' The model name is not a valid PRISM model: '$1 echo ' The script is stopped!' exit 1 fi # # Model version # if [ "$6" = "" ]; then version=D10 else version=$6 echo "* " echo "* Compile script for model $model, version=$version is created" fi # # If no partner models are specified with cpl_to the standalone version is taken as default. # This may not be possible for al models. # if [ "$7" = "" ] || [ "$7" = " " ]; then cpl_to=" " else for model1 in $7; do valid_model=no for model2 in ${list_of_PRISM_models}; do if [ "$model1" = "$model2" ]; then valid_model=yes fi done if [ "${valid_model}" = "no" ]; then echo ' One of the models names is not a valid PRISM model: ' $model1 echo ' The script is stopped!' exit 1 fi done if [ "${valid_model}" = "yes" ]; then cpl_to=$7 echo "* " echo "* Partner component models are: ${cpl_to}" fi fi # # HOST, OS, node name for header selection # echo ' ' node=`uname -n` node1_7=`echo ${node} | cut -c1-7` if [ ${node1_7} = platine ]; then node=${node1_7}; fi if [ ${node1_7} = mercure ]; then node=${node1_7}; fi node1_5=`echo ${node} | cut -c1-5` if [ ${node1_5} = zahir ]; then node=${node1_5}; fi if [ ${node1_5} = curie ]; then node=${node1_5}; fi node1_6=`echo ${node} | cut -c1-6` if [ ${node1_6} = vargas ] || [ ${node1_6} = titane ]; then node=${node1_6}; fi node1_3=`echo ${node} | cut -c1-3` if [ ${node1_3} = ada ]; then node=${node1_3}; fi build=`uname -s` if [ "$5" != "" ] && [ "$5" != $node ]; then echo ' ' echo Warning: the node specified is not the node of this machine. echo Ensure that the site/OS specific header files exist. node=$5 build="" echo '* Creating compile script' echo ' for ' $model'.' else echo '* Creating compile script' echo ' on/for a '$build ' platform with node name ' $node',' echo ' for ' $model'.' fi node1_4=`echo ${node} | cut -c1-4` if [ ${node1_4} = xbar ]; then node=${node1_4}; fi if [ ${node1_4} = hpca ]; then node=${node1_4}; fi node1_2=`echo ${node} | cut -c1-2` if [ ${node1_2} = ds ]; then node=${node1_2}; fi node1_6=`echo ${node} | cut -c1-6` if [ ${node1_6} = total1 ]; then node=${node1_6}; fi echo '* Abbreviated node name is ' $node'.' # # Checking consistency of message passing parameter and model # mespas=irgendwas messpass=MPI2 if [ "$2" != "" ]; then if [ "$2" = "MPI1" ] || [ "$2" = "NONE" ]; then if [ "$2" = "MPI1" ] ; then if [ "$model" = "echam5" ] || [ "$model" = "mpi-om" ] || [ "$model" = "hamocc" ] || [ "$model" = "pisces" ] || [ "$model" = "psoce" ] ; then echo 'MPI1 for '$model' is not possible.' exit 1 else messpass=$2 mespas=MPI2 fi fi if [ "$2" = "NONE" ] ; then if [ "$model" = "" ] ; then echo 'NONE for '$model' is not possible.' exit 1 else messpass=$2 mespas=MPI2 fi fi else echo 'ERROR:This message passing may not be specified:'$2 exit 1 fi fi echo '* The message passing will be '$messpass'.' # # Redirecting standard output and err output # outout='stdout=$SCRIPTDIR/COMP_${MODEL_DIR}.log' if [ "$3" != "" ]; then if [ "$3" = "-" ]; then outout='stdout=`tty`' echo '* (g)make standard output will directed to screen.' else echo 'This values is not allowed for parameter 3 (std out)' exit fi else echo '* (g)make standard output will be directed to a file.' fi errout='stderr=$SCRIPTDIR/COMP_${MODEL_DIR}.err' if [ "$4" != "" ]; then if [ "$4" = "-" ]; then echo '* (g)make standard error will directed to screen.' errout='stderr=`tty`' elif [ "$4" = "+" ]; then echo '* (g)make standard error will directed to stdout.' errout='stderr="$stdout"' else echo 'This values is not allowed for parameter 4 (std err)' exit fi else echo '* (g)make standard error will be directed to a file.' fi # # Change to directory of script # scriptdir=`dirname $0` cd $scriptdir # /u/fj/mfuj/mfuj004/bin/m4 ; xbar cat > infile.m4 <) dnl include(include/Prolog_all.h)dnl include(include/Prolog_models.h)dnl export TARFILE=\${MODEL_DIR}_\`date +%y%m%d\`.tar dnl dnl GUI input for all compile scripts dnl changecom(#) define(${mespas},${messpass})dnl include(include/Guispecif_all.h)dnl undefine([{${mespas}}])dnl changecom dnl dnl GUI input for all model compile scripts dnl changecom(#) define(Invalid_model,"${cpl_to}")dnl include(include/Guispecif_models.h)dnl undefine([{Invalid_model}])dnl changecom dnl dnl GUI input depending on model dnl changecom(#) define(_ModVers,_${version})dnl include(include/Guispecif_${model}.h)dnl undefine([{_ModVers}])dnl sinclude(include/Guispecif_${model}_frm.h)dnl changecom dnl dnl Command parameter input (scripting only) dnl include(include/Command_par_models_frm.h)dnl include(include/Input_check_all_frm.h)dnl dnl dnl Parameter renaming and printing dnl include(include/Print_par_all.h)dnl include(include/Print_par_models.h)dnl include(include/Print_par_${model}.h)dnl dnl dnl Site and OS specifics dnl include(include_${node}/Sitespecific_${node}.h)dnl include(include_${node}/Compile_mode_${model}_${node}.h)dnl include(include_${node}/OSspecific_${node}.h)dnl dnl dnl Non Site and OS dependent cpp flags dnl include(include/Cppflags_${model}.h)dnl include(include/Cppflags_edit.h)dnl dnl dnl Name of executabele dnl include(include/Execname.h)dnl dnl dnl Libraries and directories dnl include(include/Libraries_${model}.h)dnl include(include/Libraries_models.h)dnl include(include/Build_dirs_models.h)dnl dnl dnl Check library update status : scripting only dnl include(include/Check_libs.h)dnl dnl dnl Additional update conditions dnl sinclude(include/Add_cond_${model}.h)dnl dnl dnl Create top level Makefile dnl include(include/Top_makefile_all.h)dnl define(NodeName,$node)dnl include(include/Top_makefile_models.h)dnl undefine(NodeName)dnl define(outdev,${outout})dnl outdev undefine([{outdev}])dnl define(errdev,${errout})dnl errdev undefine([{errdev}])dnl if [ -f \$BLDROOT/${model}.status ]; then rm \$BLDROOT/${model}.status; fi dnl dnl Make model dnl include(include/Make_model.h)dnl dnl dnl Print update status : scripting only dnl include(include/Status_mods_frm.h)dnl dnl dnl Save/rename the executable dnl include(include/Save_exec.h)dnl dnl dnl Embedding as batch (not needed on all nodes) dnl sinclude(include_${node}/Qsub_end_${node}.h)dnl exit m4exit EOF # # Run m4. # if [ "$5" = "rhodes" ] ; then /usr/freeware/bin/m4 infile.m4 > COMP_${model} elif [ "$5" = "zahir" ] ; then /usr/local/bin/m4 infile.m4 > COMP_${model} elif [ "$5" = "vargas" ] ; then /usr/local/pub/M4/m4-1.4.11/bin/m4 infile.m4 > COMP_${model} else m4 infile.m4 > COMP_${model} fi status=$? if [ $status -eq 0 ]; then if [ ! ${model} = "oasis3" ]; then Compile_script=COMP_${model}_$6.${node} else Compile_script=COMP_${model}_${messpass}.${node} fi mv COMP_${model} ../../../src/mod/${model}/${Compile_script} chmod 755 ../../../src/mod/${model}/${Compile_script} olddir=`pwd` cd ../../../src/mod/${model} moddir=`pwd` echo "* The model directory is " $moddir echo "* The compile script name is "$moddir/${Compile_script} echo ' ' else echo "An error occurred! Status="$status echo ' ' fi cd $olddir rm infile.m4 exit