ENH: PatchEdgeFaceWave: new wave method
[OpenFOAM-2.0.x.git] / etc / codeTemplates / template / foamNewTemplate
blobdfc2e13375e3b17e521ed5a46480a17a250da3da
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamNewTemplate
28 # Description
29 # Create a new standard OpenFOAM templated source file
31 #------------------------------------------------------------------------------
32 Script=${0##*/}
33 Template="$WM_PROJECT_DIR/etc/codeTemplates/template/_TemplateTemplate"
35 usage() {
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
37 cat<<USAGE
39 Usage: $Script [OPTION] <type> <ClassName> <Template arguments...>
40 options:
41 -help print the usage
43 * create a new standard OpenFOAM source file for templated classes
45 type: (C|H|I|IO)
47 A ClassName starting with '-' will simply display the template
49 USAGE
50 exit 1
53 # this implicitly covers a lone -help
54 [ "$#" -gt 1 ] || usage
57 className="$2"
58 unset Type printOpt
60 # for a className starting with '-' simply display the code
61 if [ "${2#-}" != "${2}" ]
62 then
63 printOpt=true
67 case "$1" in
68 (-h | -help)
69 usage
71 (C|H)
72 Type=".$1"
74 (I)
75 Type="$1.H"
77 (IO)
78 Type="$1.C"
81 usage "unknown type '$1'"
83 esac
86 if [ "${printOpt:-false}" = true ]
87 then
88 [ "$#" -eq 2 ] || usage "wrong number of arguments"
89 shift 2
91 cat $Template$Type
93 else
95 [ "$#" -ge 3 ] || usage "wrong number of arguments"
96 shift 2
98 fileName="$className$Type"
100 echo "$Script: Creating new template interface file $fileName"
101 if [ -e "$fileName" ]
102 then
103 echo " Error: file exists"
104 exit 1
108 # process class name
109 sed -e "s/CLASSNAME/$className/g" $Template$Type > $fileName.1
112 # process remaining (template) arguments
113 for tArg
115 sed -e "s/TemplateClassArgument/class $tArg, TemplateClassArgument/g" \
116 -e "s/TemplateArgument/$tArg, TemplateArgument/g" \
117 $fileName.1 > $fileName.2
119 mv $fileName.2 $fileName.1
120 done
123 # remove remaining ", Template .."
124 sed -e "s/, TemplateClassArgument//g" \
125 -e "s/, TemplateArgument//g" \
126 $fileName.1 > $fileName
128 rm $fileName.1
130 #------------------------------------------------------------------------------