-
Notifications
You must be signed in to change notification settings - Fork 25
/
rp2so
executable file
·122 lines (107 loc) · 4 KB
/
rp2so
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
#!/bin/bash
#update 26 april comments from Andy
#first use WINE to install refprop.exe in the C:\Program Files\REFPROP\ directory (or virtual box if WINE doesn't work for you)
#then execute this shell script
#note, you will need to have the following installed on Linux:
# gfortran
# sed
# dos2unix
#finally, you can then use the refprop.py interface to call the librefprop.so
#cause the script to abort immediately on error instead of trying to continue
#an error could for example be caused by not running this script as superuser (sudo), if installing to a path that requires superuser permissions
set -e
#set the default paths. don't use relative paths
DefaultREFPROPSourcePath=~/.wine/drive_c/Program\ Files/REFPROP
Defaultpath=/usr/local/lib/refprop
#now ask the user if they want to change from the default paths
echo "Enter the path where the REFPROP source files were installed to (relative paths not allowed)."
echo "Hit Enter to accept the default of $DefaultREFPROPSourcePath"
read REFPROPSourcePath;
if [ "$REFPROPSourcePath" == "" ]; then
REFPROPSourcePath=${DefaultREFPROPSourcePath}
fi;
echo
echo "Enter base path where the compiled REFPROP files will be installed to (relative paths not allowed)"
echo "Hit Enter to accept the default of $Defaultpath"
echo "Warning: You may need to be running this script as superuser (i.e. 'sudo ./rp2so') for $Defaultpath"
echo "You can press Control-C to stop the script now."
read path;
if [ "$path" == "" ]; then
path=${Defaultpath}
fi;
echo
#delete previous installation
echo "Are you sure you want to delete $path ?"
echo "Enter 'y' for yes, Control-C to stop the script now, or anything else for no"
read yess;
echo
if [ "$yess" == "y" ]; then
echo "--- Deleting $path ---"
rm -rf ${path}
else
echo "--- Not deleting $path ---"
fi;
#create directories
echo "--- Creating directories ---"
mkdir -p ${path}/FOR/
mkdir -p ${path}/fluids/
mkdir -p ${path}/mixtures/
#copy fortran / refprop files to ${path}
echo "--- Copying source files ---"
cp -r "${REFPROPSourcePath}"/fortran/*.FOR ${path}/FOR/
cp -r "${REFPROPSourcePath}"/fluids/* ${path}/fluids/
cp -r "${REFPROPSourcePath}"/mixtures/* ${path}/mixtures/
#allow read permission all
echo "--- Changing file permissions ---"
chmod -R a+r ${path}/fluids/
chmod -R a+r ${path}/mixtures/
#rename all filenames to UPPERCASE and correct fortran extension (*.FOR > *.f)
echo "--- Renaming lowercase to UPPERCASE filenames and correct extension---"
cd ${path}/fluids/
rename 'y/a-z/A-Z/' *
cd ${path}/mixtures/
rename 'y/a-z/A-Z/' *
cd ${path}/FOR/
rename 'y/a-z/A-Z/' *
rename -f 's/\.FOR/\.f/' ${path}/FOR/*.FOR
#modify PASS_FTN.f
#remove windows specific command
echo "--- Applying a linux specific fix to PASS_FTN.f ---"
sed -i 's/ dll_export/c dll_export/' ${path}/FOR/PASS_FTN.f
#process files (dos to unix)
echo "--- Converting source file line endings from dos to unix ---"
for files in ${path}/FOR/*.f ${path}/fluids/* ${path}/mixtures/*
do
{
echo "processing ${files}"
#change *.f files from dos to unix
dos2unix -q ${files}
} &
done
#wait for multiprocessing to complete
wait
#modify *.f
echo "--- Applying common file fix ---"
for files in ${path}/FOR/*.f
do
{
sudo sed -i "s/'commons.for'/'COMMONS.include'/" ${files}
sudo sed -i "s/'comtrn.for'/'COMTRN.include'/" ${files}
} &
done
wait
#rename COMMONS.f and COMTRN.f to *.include
rename -f 's/\.f/\.include/' ${path}/FOR/COMMONS.f ${path}/FOR/COMTRN.f
#create the dynamically link "shared objects" (so) library
echo "--- Creating shared object file ---"
#option -fopenmp is possible but at present does not have any speed gains on the contrary
#option -lc, does nothing?
gfortran -shared -fpic -Ofast ${path}/FOR/*.f -Wl,-soname,librefprop.so.9 -o ${path}/librefprop.so.9.1 #-lc -fopenmp
#install the object file
echo "--- Installing object file ---"
rm -rf ${path%/refprop}/librefprop.so
ldconfig -n ${path}
ln -s ${path}/librefprop.so.9 ${path%/refprop}/librefprop.so
echo
echo "Note: If you want to display ported commands, type:"
echo "nm ${path%/refprop}/librefprop.so"