forked from NREL/EnergyPlus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunepmacro
171 lines (151 loc) · 3.99 KB
/
runepmacro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
#====================================================================
# Runs EPMacro (macro preprocessor for EnergyPlus input files)
#
# This script needs the environment variable ENERGYPLUS_DIR to be
# set to the root directory of EnergyPlus.
#
# April 28, 2003, [email protected]
# modified March 29, 2009, [email protected]
# Added support to find ENERGYPLUS_DIR if unset by user
#====================================================================
HEADER="=============== EPMacro ================="
# Name of executable
PRG_N=EPMacro
# Input path
INP_P=`pwd`
# Output path
OUT_P=$INP_P
# output/input file names
LINK_NAMES="in.imf out.idf audit.out"
# function to set ENERGYPLUS_DIR relative to this script
function SetEnergyPlusDir() {
unamestr=`uname`
if [ "$unamestr" == 'Darwin' ]; then
ENERGYPLUS_DIR="/usr"
else
U_DIR=`pwd`
if [ -n "`readlink "$0"`" ]; then
S_DIR=$(cd "$(dirname "$(readlink "$0")")"; pwd)
cd "$U_DIR"
else
S_DIR=$(cd "$(dirname "$0")"; pwd)
cd "$U_DIR"
fi
ENERGYPLUS_DIR=`dirname "$S_DIR"`
fi
}
# Check for user set ENERGYPLUS_DIR
auto_eplus_dir=true
if [ -n "$ENERGYPLUS_DIR" ]; then
auto_eplus_dir=false
fi
# Set the ENERGYPLUS_DIR
if $auto_eplus_dir; then
SetEnergyPlusDir
fi
# ==========================================================
function Usage() {
echo "Usage: runepmacro InputFileName"
echo " or: runepmacro --clean (or -c)"
echo " or: runepmacro --help (or -h)"
echo ""
echo "Runs EPMacro program."
echo ""
echo "InputFileName does not have a file extension."
echo ""
echo " --clean, or -c deletes all output files in the current directory"
echo " --help, or -h displays this help"
}
# ==========================================================
function CleanOutputFiles() {
# delete files
# delete links
for files in $LINK_NAMES;
do
if [ -L $files ]; then
rm $files
fi
done
echo "Deleted output files";
}
# ==========================================================
function ExitWithError() {
echo "===== EnergyPlus terminated with error ====="
exit 1
}
# ==========================================================
if [ "$1" = "" ]; then
Usage ; exit 0;
fi
if [ "$1" = "--help" ]; then
Usage ; exit 0;
fi
if [ "$1" = "-h" ]; then
Usage ; exit 0;
fi
# ==========================================================
if [ "$ENERGYPLUS_DIR" = "" ]; then
echo "$HEADER";
echo "To use EnergyPlus, you need to set the";
echo "environment variable ENERGYPLUS_DIR to";
echo "the root directory of EnergyPlus.";
ExitWithError;
fi
# ==========================================================
# Clean output files only
if [ $1 = --clean ]; then
CleanOutputFiles ; exit 0;
fi
if [ $1 = -c ]; then
CleanOutputFiles ; exit 0;
fi
# ==========================================================
# Prepare to run EPMacro
# Check for imf file
if [ ! -f $INP_P/$1.imf ]; then
echo "$HEADER"
echo "First argument must the input file name,"
echo "did not find $INP_P/$1.imf"
echo ""
Usage
ExitWithError
fi
# ==========================================================
echo "$HEADER"
echo " Input file : $1.imf"
# ==========================================================
# Delete all output files
for filename in $LINK_NAMES;
do
rm -f $filename
done
# ==========================================================
# Make links
ln -s $INP_P/$1.imf in.imf
# ==========================================================
# Start energyplus
if $auto_eplus_dir; then
$ENERGYPLUS_DIR/bin/$PRG_N
else
$ENERGYPLUS_DIR/$PRG_N
fi
# ==========================================================
# Move output files (except inp, since it is only a symlink)
if [ -f audit.out ]; then
mv audit.out $1.epmdet
fi
if [ -f out.idf ]; then
mv out.idf $1.epmidf
fi
# Delete additional files
for filename in $LINK_NAMES;
do
if [ -f $filename ]; then
rm $filename
fi
done
#====================================================================
# Check for error
#
# Not implemented for EPMacro