source: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/bin/kpp4palm.ksh @ 4051

Last change on this file since 4051 was 3800, checked in by forkel, 6 years ago

added leading blanks to dummy statements

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 13.4 KB
Line 
1#!/usr/bin/ksh
2
3# kpp4palm - script for creating gasphase module
4
5#------------------------------------------------------------------------------#
6# This file is part of the PALM model system.
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#
19# Copyright 2017-2018  Klaus Ketelsen and MPI-CH (April 2007)
20# Copyright 2017-2018  Karlsruhe Institute of Technology
21# Copyright 2017-2018  Leibniz Universitaet Hannover
22#------------------------------------------------------------------------------#
23# Nov. 2016: Initial Version of KPP chemistry convertor adapted for PALM
24# by Klaus Ketelsen
25#
26# This code is a modified version of KP4 (Jöckel, P., Kerkweg, A., Pozzer, A.,
27# Sander, R., Tost, H., Riede, H., Baumgaertner, A., Gromov, S., and Kern, B.,
28# 2010: Development cycle 2 of the Modular Earth Submodel System (MESSy2),
29# Geosci. Model Dev., 3, 717-752, https://doi.org/10.5194/gmd-3-717-2010).
30# KP4 is part of the Modular Earth Submodel System (MESSy), which is is
31# available under the  GNU General Public License (GPL).
32#
33#------------------------------------------------------------------------------#
34#
35# Current revisions:
36# ------------------
37#
38#
39# Former revisions:
40# -----------------
41# $Id: kpp4palm.ksh 3800 2019-03-15 16:40:25Z suehring $
42# Removed edit of phot(nphot) for version edit phot(nphot), now done in fortran_file.C (15.03.2019, forkel)
43# Editing with sed to add dummy statements toavoud unused variables (15.03.2019, forkel)
44#
45# 3780 2019-03-05 11:19:45Z forkel
46# forkel   05. March 2019: cs_mech and set_cm
47# forkel   30. Oktober 2018: Integrating contents of kp4_compress into chem_gasphase_mod.f90
48# forkel   25. September 2018: Added cat for $MECH to pass mechanism name to kpp4palm
49# ketelsen 18. September 2018: Added cat for '#INLINE F90_GLOBAL'
50# (moved here from mechanisms/def_MECH/chem_gasphase.kpp
51#
52# forkel: 14. September  2018: WCOPY removed
53# ketelsen: July 2018: Adaptations for vektor mode
54# forkel June 2018: re-established original case of subroutine names
55# forkel May 2018: additional copying of chem_gasphase_mod.f90 into $DEFDIR
56# forkel 20.04.2018: removed  wlamch and wlamch_add from $KPP_SUBROUTINE_LIST
57#                    (epsilon(one) is used now)
58# forkel March 2017
59# Re-introduced relative path for KPP_HOME
60# Subroutine list adapted to lowercase subroutine names
61# Added arr2, removed update_sun and k_3rd from subroutine list
62# Renamed output file to chem_gasphase_mod
63# Renamed this file from kp4/ksh to kpp4kpp.ksh
64# changed location of def_mechanism directories to gasphase_preproc/mechanisms
65#
66#
67# 2718 2018-01-02 08:49:38Z maronga
68# Initial revision
69#
70#
71##########################################################################
72#
73#
74# Other notes:
75# ------------#
76# Re-introduced relative path for KPP_HOME
77# Subroutine list adapted to lowercase subroutine names
78# Added arr2, removed update_sun and k_3rd from subroutine list
79# Renamed output file to chem_gasphase_mod
80# Renamed this fikle from kp4/ksh to kpp4kpp.ksh
81# changed location of def_mechanism directories to GASPHASE_PREPROC/mechanisms
82#
83# Nov. 2016: Initial Version of KPP chemistry convertor by Klaus Ketelsen
84#
85#
86
87set -eu
88
89
90########################### User SetUp ####################################
91
92export KPP_HOME=`pwd`/kpp
93export KPP=$KPP_HOME/bin/kpp
94
95BASE=`pwd`/kpp4palm
96
97########################## End User Setup ################################
98
99WORK=tmp_kpp4palm
100
101# Default
102
103MECH=smog
104OUTDIR=`pwd`/../../../SOURCE
105OUTFILE=chem_gasphase_mod
106DEFDIR=`pwd`/mechanisms/def_smog
107PREFIX=chem_gasphase_mod
108MODE="scalar"
109VLEN=1
110KEEP="NO"
111UPDT="NO"
112DE_INDEX=0
113DE_INDEX_FAST="YES"
114
115export KPP_SOLVER=Rosenbrock
116
117# get Command line option
118
119while  getopts :m:i:fkup:o:s:vl:w:  c     # get options
120do case $c in
121      m)   MECH=$OPTARG;;            # mechanism
122
123      i)   DE_INDEX=$OPTARG;;        # if set, deindexing
124
125      f)   DE_INDEX_FAST="YES";;     # if set, fast deindexing
126
127      k)   KEEP="YES";;              # keep Working directory
128
129      o)   OUTDIR=$OPTARG;;          # Output directory of Generated Code =
130                                     # SOURCE directory (do not change)
131
132      p)   PREFIX=$OPTARG;;          # Name Prefix (chem_gasphase_mod, do not change)
133
134      s)   KPP_SOLVER=$OPTARG;;      # Chosen solver (only Rosebrock solvers work for vector mode)
135
136      u)   UPDT="YES";;              # update mechanisms/def_$MECH/chem_gasphase_mod.f90
137
138      v)   MODE="vector";;           # Set to vector Mode
139
140      l)   VLEN=$OPTARG;;            # Set vector length
141
142      w)   WORK=$OPTARG;;            # Working directory
143
144      \?)  print ${0##*/} "unknown option:" $OPTARG
145           print "USAGE: ${0##*/} [ -m dir -e -k -u -o dir -p name -s solver -v -l length -w dir ] "
146           exit 1;;
147   esac
148done
149shift OPTIND-1
150
151echo MECHANISM = $MECH
152echo DE_INDEX = $DE_INDEX
153echo KEEP = $KEEP
154echo UPDT = $UPDT
155echo MODE = $MODE
156echo VLEN = $VLEN
157
158DEF_PREFIX=${PREFIX}.kpp
159DEFDIR=`pwd`/mechanisms/def_$MECH
160echo DEFDIR = $DEFDIR
161
162# Create or clean working directory
163
164MY_PWD=`pwd`
165mkdir -p $WORK
166rm -rf $WORK/*
167cd $WORK
168
169# kpp dependend, may be changed
170
171KPP_FILE_LIST="Initialize Integrator LinearAlgebra Jacobian Function Rates Util"
172if [[ $MODE = "vector" ]]
173 then
174KPP_FILE_LIST="$KPP_FILE_LIST kp4_compress_subroutines"
175fi
176
177KPP_SUBROUTINE_LIST="Initialize"
178KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST INTEGRATE Fun"
179KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppSolve KppDecomp"
180KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Jac_SP k_arr "
181KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Update_RCONST ARR2"
182KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST initialize_kpp_ctrl error_output"
183
184# if [[ $MODE = "vector" && $KPP_SOLVER = "ROS2" ]]
185# then
186#   cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90    # get vector Solver
187# else
188# #  KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST FunTemplate JacTemplate Update_SUN "
189#   KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
190#   if [[ $MODE = "vector" ]]
191#   then
192#     cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90  # get vector Solver
193#   else
194#     KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate Update_SUN"
195#   fi
196# fi
197 if [[ $MODE = "vector" ]]
198 then
199   # get vector Solver
200   cp $BASE/templates/${KPP_SOLVER}_vec.f90 ${KPP_SOLVER}.f90
201   cp $BASE/templates/kp4_compress_header ${PREFIX}_kp4_compress_header.f90
202   cp $BASE/templates/kp4_compress_subroutines ${PREFIX}_kp4_compress_subroutines.f90
203fi
204
205# Interface ignore list
206KPP_INTERFACE_IGNORE=" "
207
208echo " "
209echo KPP_SOLVER $KPP_SOLVER
210echo " "
211
212case $KPP_SOLVER in
213    ROS2) ;;
214
215    Rosenbrock)   
216      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WSCAL WAXPY"
217      if [[ $MODE != "vector" ]]
218      then
219         KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate"
220        KPP_INTERFACE_IGNORE="WAXPY"
221
222      else
223        KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST FunTemplate JacTemplate"
224        KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST kco_initialize kco_compress kco_finalize"
225      fi;;
226
227    rosenbrock_mz)
228      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
229      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate Update_SUN";;
230
231    rosenbrock)
232      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
233      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST Rosenbrock  FunTemplate JacTemplate";;
234
235    kpp_lsode)
236      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
237      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppLsode DLSODE JAC_CHEM FUN_CHEM"
238      KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE JAC_CHEM KppDecomp KppSolve";;
239
240    kpp_radau5)
241      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY FUN_CHEM JAC_CHEM SET2ZERO"
242      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST RADAU5 Update_SUN"
243      KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST KppSolveCmplx KppDecompCmplx";;
244
245    kpp_sdirk)
246       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
247       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST SDIRK JAC_CHEM SET2ZERO FUN_CHEM"
248       KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE Set2zero SET2ZERO FUN_CHEM";;
249
250    kpp_seulex)
251       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST WCOPY WSCAL WAXPY"
252       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST ATMSEULEX"
253       KPP_SUBROUTINE_LIST="$KPP_SUBROUTINE_LIST SEULEX_ErrorMsg SEULEX_Integrator FUN_CHEM JAC_CHEM SEUL"
254       KPP_INTERFACE_IGNORE="$KPP_INTERFACE_IGNORE SEULEX_Integrator SDIRK FUN_CHEM SEUL";;
255
256   \?)  print "SORRY ONLY ROSENBROCK METHODS WORK AT THE MOMENT:" $KPP_SOLVER
257        exit 1;;
258esac
259#mz-ak-20070509+
260
261KPP_INCLUDE_LIST="Parameters Global JacobianSP Monitor"
262if [[ $MODE = "vector" ]]
263 then
264KPP_INCLUDE_LIST="$KPP_INCLUDE_LIST kp4_compress_header"
265fi
266
267#Get definition Files
268
269cp $DEFDIR/*.eqn         .
270cp $DEFDIR/*.spc         .
271cp $DEFDIR/${PREFIX}.kpp     .
272
273# Global variable are defined here
274# This has the advantage that it is not necessary to include these variables in all .kpp definition files
275
276cat  >> ${PREFIX}.kpp  <<  EOF
277#INLINE F90_GLOBAL
278! QVAP - Water vapor
279  REAL(kind=dp) :: QVAP
280! FAKT - Conversion factor
281  REAL(kind=dp) :: FAKT
282
283! CS_MECH for check of mechanism name with namelist
284  CHARACTER(LEN=30) :: CS_MECH
285#ENDINLINE
286EOF
287
288# Store mechanism name in file mech_list
289cat  >> mech_list  <<  EOF
290!   Mechanism: $MECH
291!
292EOF
293
294# Store mechanism name for cs_mech
295cat  >> set_cm  <<  EOF
296
297! Set cs_mech for check with mechanism name from namelist
298    cs_mech = '$MECH'
299EOF
300
301# Run kpp
302
303$KPP $DEF_PREFIX
304
305# Get templates for C++ program
306
307cp $BASE/templates/module_header* .           # Use fixed Module_header
308cp $BASE/templates/initialize_kpp_ctrl_template.f90 .  # CTRL kpp time stepping
309
310# file with subroutine list for c++ program create_kpp_module
311
312for i in $KPP_FILE_LIST
313do
314  echo ${PREFIX}_${i} >> file_list
315done
316echo initialize_kpp_ctrl_template >> file_list
317
318# file with subroutine list for c++ program create_kpp_module
319
320for i in $KPP_SUBROUTINE_LIST
321do
322  echo $i >> subroutine_list
323done
324
325# file with include list for c++ program create_kpp_module
326
327for i in $KPP_INCLUDE_LIST
328do
329  echo ${PREFIX}_${i} >> include_list
330done
331
332touch interface_ignore_list
333for i in $KPP_INTERFACE_IGNORE
334do
335  echo $i >> interface_ignore_list
336done
337
338echo start kpp4palm.exe with arguments
339echo $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST
340
341$BASE/bin/kpp4palm.exe $PREFIX $MODE $VLEN $DE_INDEX $DE_INDEX_FAST
342
343# Add dummy statements in order to prevent warnings due to unused variables
344#
345sed -i -e '/cfactor =/a !  ' kk_kpp.f90
346sed -i -e '/cfactor =/a BLANKS  IF ( lu_crow(1) == 1  .OR.  lu_icol(1) == 1  .OR.  lu_irow(1) == 1 )  CONTINUE ' kk_kpp.f90
347sed -i -e '/cfactor =/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
348sed -i -e '/cfactor =/a !  ' kk_kpp.f90
349
350if [[ $MODE = "vector" ]]
351then
352sed -i -e '/! Computation of equation rates/i ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
353sed -i -e '/! Computation of equation rates/i BLANKS  IF ( f(vl,nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
354sed -i -e '/! Computation of equation rates/i !  ' kk_kpp.f90
355else
356sed -i -e '/! Computation of equation rates/i ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
357sed -i -e '/! Computation of equation rates/i BLANKS  IF ( f(nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
358sed -i -e '/! Computation of equation rates/i !  ' kk_kpp.f90
359fi
360
361if [[ $MODE = "vector" ]]
362then
363sed -i -e '/REAL(kind=dp) :: b/a  BLANKS  IF ( f(vl,nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
364sed -i -e '/REAL(kind=dp) :: b/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
365sed -i -e '/REAL(kind=dp):: b/a !' kk_kpp.f90
366else
367sed -i -e '/REAL(kind=dp):: b/a BLANKS  IF ( f(nfix) > 0.0_dp )  CONTINUE' kk_kpp.f90
368sed -i -e '/REAL(kind=dp):: b/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
369sed -i -e '/REAL(kind=dp):: b/a !' kk_kpp.f90
370fi
371
372sed -i -e '/one=1.0_dp/a BLANKS  IF ( incx == 0 )  CONTINUE' kk_kpp.f90
373sed -i -e '/one=1.0_dp/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
374sed -i -e '/one=1.0_dp/a !  ' kk_kpp.f90
375
376sed -i -e '/IF (alpha .eq. zero)RETURN/i !  ' kk_kpp.f90
377sed -i -e '/IF (alpha .eq. zero)RETURN/i ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
378sed -i -e '/IF (alpha .eq. zero)RETURN/i BLANKS  IF ( incx == 0  .OR.  incy == 0 )  CONTINUE' kk_kpp.f90
379
380sed -i -e '/INTENT(INOUT):: b(n)/a BLANKS  IF ( pivot(1) == 0 )  CONTINUE' kk_kpp.f90
381sed -i -e '/INTENT(INOUT):: b(n)/a ! Following line is just to avoid compiler message about unused variables' kk_kpp.f90
382sed -i -e '/INTENT(INOUT):: b(n)/a !  ' kk_kpp.f90
383
384sed -i -e '1,$s/BLANKS /  /  ' kk_kpp.f90
385
386if [[ -e $OUTDIR/${OUTFILE}.f90 ]] 
387then
388 mv $OUTDIR/${OUTFILE}.f90 $OUTDIR/${OUTFILE}.f90.sav
389fi
390cp -p kk_kpp.f90    $OUTDIR/${OUTFILE}.f90
391echo " "
392echo "Write kpp module -- > " $OUTDIR/${OUTFILE}.f90
393
394if [[ $UPDT = "YES" ]]
395then
396cp -p kk_kpp.f90    $DEFDIR/${OUTFILE}.f90
397echo " "
398echo "Write kpp module -- > " $DEFDIR/${OUTFILE}.f90
399fi
400
401if [[ $KEEP = "NO" ]]
402then
403  cd  $MY_PWD
404  rm -rf $WORK
405fi
406exit
407
Note: See TracBrowser for help on using the repository browser.