-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstitch_up.sh
executable file
·164 lines (118 loc) · 6.15 KB
/
stitch_up.sh
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
#!/bin/bash
# Script 1/1
######################
## By Megan Stalker ##
######################
# This script:
# 1. Concatenates the output files (OUTPUT, SOLVAT, HISTORY) generated by performing a DL_POLY simulation and restarted using the restart.sh script
# 2. Visualises an observable (the timesteps from the HISTORY file) to assist the user in determining whether the files are corrupt
##########
# A NOTE:#
##########
# Throughout this script, operations on HISTORY files are commented out as these operations are time and resource intensive. Uncomment the relevant lines (91, 119, 125) to execute operations on HISTORY files
#######################################################################################################################################################################################################################
# #
# 1. STITCH UP #
# #
#######################################################################################################################################################################################################################
############
# CLEAN-UP #
############
# Removes any files generated by previously running this script
rm _tmp
rm timesteps
#############
# UNZIPPING #
#############
# Unzips the necessary files
gunzip */OUTPUT.gz
gunzip */STATIS.gz
gunzip */SOLVAT.gz
gunzip */HISTORY.gz
gunzip OUTPUT.gz
gunzip STATIS.gz
gunzip SOLVAT.gz
gunzip HISTORY.gz
gunzip CONTROL.gz
gunzip FIELD.gz
gunzip CONFIG.gz
#########################
# DIRECTORY ENUMERATION #
#########################
# Calculates the number of directories in the parent directory
numdir=$(ls -d */ | grep save | wc -l | awk '{ print $1 }')
#echo "numdir" $numdir
pwd
#################
# FILE RENAMING #
#################
# Renames the relevant output files (OUTPUT, SOLVAT, HISTORY) to reflect the directory that they are in
# Any loose files in the parent directory are renamed
mv OUTPUT OUTPUT_$numdir
mv SOLVAT SOLVAT_$numdir
mv HISTORY HISTORY_$numdir
mv STATIS STATIS_$numdir
num=0
batch=0
while [ $batch -lt $numdir ]; do
cd save$num
pwd
mv OUTPUT OUTPUT_$num
mv SOLVAT SOLVAT_$num
mv HISTORY HISTORY_$num
mv STATIS STATIS_$num
# Concatenates the separate relevant output files (OUTPUT, SOLVAT, HISTORY) into one single output file (OUTPUT_tmp, SOLVAT_tmp, HISTORY_tmp) in the parent directory
cat OUTPUT_$num >> ../OUTPUT_tmp
cat SOLVAT_$num >> ../SOLVAT_tmp
cat STATIS_$num >> ../STATIS_tmp
# cat HISTORY_$num >> ../HISTORY_tmp
# Extracts the single observable (timesteps from the HISTORY file) into a separate file (timesteps_$num)
grep "timestep" HISTORY_* | awk '{print $2}' >> timesteps_$num
cd ..
pwd
(( batch++ ))
(( num++ ))
done
# Any loose files in the parent directory are moved into a new directory (save$numdir)
fold=$(echo save$num)
echo "fold" $fold
mkdir save$numdir
for file in * .*
do
test -f "$file" && mv "$file" "$fold"/
done
# Extracts any files created by the script back into the parent directory
mv $fold/stitch_up.sh .
mv $fold/OUTPUT_tmp .
mv $fold/SOLVAT_tmp .
mv $fold/STATIS_tmp .
mv $fold/CONTROL* .
mv $fold/CONFIG* .
mv $fold/FIELD* .
#mv $fold/HISTORY_tmp .
# Concatenates the relevant output files (OUTPUT, SOLVAT, HISTORY) which were previously loose in the parent directory into the relevant output files (OUTPUT_tmp, SOLVAT_tmp, HISTORY_tmp) in the parent directory
cat save$numdir/OUTPUT_$num >> OUTPUT_tmp
cat save$numdir/SOLVAT_$num >> SOLVAT_tmp
cat save$numdir/STATIS_$num >> STATIS_tmp
#cat save$numdir/HISTORY_$num >> HISTORY_tmp
mv OUTPUT_tmp OUTPUT
mv SOLVAT_tmp SOLVAT
mv STATIS_tmp STATIS
#######################################################################################################################################################################################################################
# #
# 2. CORRUPTION CHECK #
# #
#######################################################################################################################################################################################################################
# Extracts the single observable (timesteps from the HISTORY file) from the file which was previously loose in the parent directory into a separate file (timesteps_$num)
grep "timestep" save$numdir/HISTORY_$num | awk '{print $2}' >> save$numdir/timesteps_$num
# Concatenates the single observable (timesteps from the HISTORY file) into a separate file (timesteps) in the parent directory
for i in $(ls -dv save*/ )
do
cat $i/timestep* >> timesteps
done
# Plots the single observable (timesteps from the HISTORY file) using gnuplot
# Uncorrupted files will display a linear trend
# Corrupted files will display some discontinuity in the linear trend
gnuplot --persist -e 'plot "timesteps"; pause mouse close; exit gnuplot'
# If you cannot access screen resources use the following command, as opposed to the above
#gnuplot --persist -e 'set terminal 'dumb'; plot "timesteps"; pause mouse close; exit gnuplot'