create_symlinks.sh 15 KB
Newer Older
Sebastian Milinski's avatar
Sebastian Milinski committed
1
2
3
4
5
6
7
8
#!/bin/bash

# v1.0 (5.1.2018 by sebastian.milinski@mpimet.mpg.de)

# TODO: check if links exist and either delete them or don't recreate (otherwise there are lots of warnings) (use ln -sf but this doesn't )
# TODO: add underscore between prefix and numeric id (for some reason this gives warnings when trying to create symlinks)
# TODO: parallelisation: limit to n_max parallel jobs?

9
10
# TODO: implement dynamic linking of BOT and ATM files in case of missing files (see issue #1)

Sebastian Milinski's avatar
Sebastian Milinski committed
11
12
13
14
15
16
17
18
19
# This script creates symbolic links to all model output. During this process it:
# - copies the whole directory structure from the source directory to the target directory
# - creates symbolic links for all files present in the source directory in the same location in the target directory
# - allows to rename the links to files in order to change the experiment id

# The aim of this is to have one directory for the Grand Ensemble that holds subfolders for each experiment (piControl, historical, 1% CO2, RCP2.6, RCP4.5 and RCP8.5)

# Necessary user input (* :defaults already set based on output location and data availability on mistral on 5.1.2018):
# - target directory
20
# - * source directory
Sebastian Milinski's avatar
Sebastian Milinski committed
21
22
23
# - * experiment id (source)
# - * experiment id (target)

24
target_dir=/work/mh1007/MPI-ESM-GE # creates taget directory
Sebastian Milinski's avatar
Sebastian Milinski committed
25
26
27

#####
# control if all experiments should be processed
28
29
force_historical=false
force_1perc=false
30
31
force_rcp26=false
force_rcp45=false
32
33
force_rcp85=false
force_control=true
Sebastian Milinski's avatar
Sebastian Milinski committed
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
#####################
# PiControl
if [ "$force_control" = true ]; then

echo creating links for PiControl runs


# path to control run from swiss machine
source_dir=/work/mh1007/mpiesm1/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
target_subdir=${target_dir}/pictrl

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=lkm
ens_0=0001 		# first ensemble member to include
ens_n=${ens_0}  # last ensemble member to include

# source_prefic will be substituted with this
target_prefix=pictrl
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=0

# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi

# path to control run from mistral
source_dir=/work/mh0469/m214089/mpiesm/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
target_subdir=${target_dir}/pictrl

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=lkm
ens_0=0016 		# first ensemble member to include
ens_n=${ens_0}  # last ensemble member to include

# source_prefic will be substituted with this
target_prefix=pictrl
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-14

# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi
Sebastian Milinski's avatar
Sebastian Milinski committed
104
105
106
107
108
109
110
111
112


#####################
# historical
if [ "$force_historical" = true ]; then
# path to directory where all members for the experiment are located
source_dir=/work/mh1007/mpiesm1/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
113
target_subdir=${target_dir}/hist
Sebastian Milinski's avatar
Sebastian Milinski committed
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

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=lkm
ens_0=101 		# first ensemble member to include
ens_n=200		# last ensemble member to include

# source_prefic will be substituted with this
target_prefix=hist
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-100


echo creating links for historical runs
# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi

#####################
# 1% CO2 #1-68
if [ "$force_1perc" = true ]; then
# path to directory where all members for the experiment are located
source_dir=/work/mh1007/mpiesm1/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
149
target_subdir=${target_dir}/onepct
Sebastian Milinski's avatar
Sebastian Milinski committed
150
151
152
153
154
155
156

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=lkm
ens_0=401 		# first ensemble member to include
ens_n=468		# last ensemble member to include

# source_prefic will be substituted with this
157
target_prefix=onepct
Sebastian Milinski's avatar
Sebastian Milinski committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-400


echo creating links for 1%CO2 runs 1-68
# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
#####################
# 1% CO2 #68-100

# path to directory where all members for the experiment are located
source_dir=/work/mh0033/m214013/mpiesm-1.1.00p2/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
183
target_subdir=${target_dir}/onepct
Sebastian Milinski's avatar
Sebastian Milinski committed
184
185
186
187
188
189
190

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=mb
ens_0=469 		# first ensemble member to include
ens_n=500		# last ensemble member to include

# source_prefic will be substituted with this
191
target_prefix=onepct
Sebastian Milinski's avatar
Sebastian Milinski committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-400


echo creating links for 1%CO2 runs 69-100
# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi
#####################
# RCP 2.6
if [ "$force_rcp26" = true ]; then
# path to directory where all members for the experiment are located
source_dir=/work/mh0033/m214013/mpiesm-1.1.00p2/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
target_subdir=${target_dir}/rcp26

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=mb
source_suffix=_rcp26
ens_0=101 		# first ensemble member to include
ens_n=200		# last ensemble member to include

# source_prefic will be substituted with this
target_prefix=rcp26
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-100


echo creating links for RCP 2.6 runs
# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)${source_suffix}
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi
#####################
# RCP 4.5
if [ "$force_rcp45" = true ]; then
# path to directory where all members for the experiment are located
source_dir=/work/mh0033/m214013/mpiesm-1.1.00p2/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
target_subdir=${target_dir}/rcp45

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=mb
source_suffix=_rcp45
ens_0=101 		# first ensemble member to include
ens_n=200		# last ensemble member to include

# source_prefic will be substituted with this
target_prefix=rcp45
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-100


echo creating links for RCP 4.5 runs
# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)${source_suffix}
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi

#####################
285
# RCP 8.5 1-30
Sebastian Milinski's avatar
Sebastian Milinski committed
286
287
if [ "$force_rcp85" = true ]; then
# path to directory where all members for the experiment are located
288
source_dir=/work/mh1007/mpiesm1/experiments
Sebastian Milinski's avatar
Sebastian Milinski committed
289
290
291
292
293
294
295
296

# directory where links to members will be created. Choose a meaningful name that starts with a letter
target_subdir=${target_dir}/rcp85

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=cr
source_suffix=_rcp85
ens_0=101 		# first ensemble member to include
297
ens_n=130		# last ensemble member to include
Sebastian Milinski's avatar
Sebastian Milinski committed
298

299
# source_prefix will be substituted with this
Sebastian Milinski's avatar
Sebastian Milinski committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
target_prefix=rcp85
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-100


echo creating links for RCP 8.5 runs
# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)${source_suffix}
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi

321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#####################
# RCP 8.5 31-63
if [ "$force_rcp85" = true ]; then
# path to directory where all members for the experiment are located
source_dir=/work/bm0976/m300497/MPIESM/GLENSv1/output/experiments

# directory where links to members will be created. Choose a meaningful name that starts with a letter
target_subdir=${target_dir}/rcp85

# which members should be used from source_dir? Define prefix and counter (counter is expanded to 4-digit number with leading zeros later)
source_prefix=cr
source_suffix=_rcp85
ens_0=131 		# first ensemble member to include
ens_n=178		# last ensemble member to include

# source_prefix will be substituted with this
target_prefix=rcp85
# ensemble counter offset, i.e. choose -100 to change lkm0101 to hist0001
counter_offset=-100


echo creating links for RCP 8.5 runs
# Loop through each ensemble member
for rrr in $(seq $ens_0 $ens_n); do #change to 200
	source_expid=${source_prefix}$(printf "%04d" $rrr)${source_suffix}
	target_counter=$(expr $rrr + $counter_offset)
	target_expid=${target_prefix}$(printf "%04d" $target_counter)
	echo $source_expid - $target_expid
	# echo copy directory structure
	mkdir -p ${target_subdir}/${target_expid}
	find ${source_dir}/${source_expid} -mindepth 1 -depth -type d -printf "%P\n" | while read dir; do mkdir -p "${target_subdir}/${target_expid}/${dir}"; done
	# echo linking files
	find ${source_dir}/${source_expid} -type f -printf "%P\n" | while read file; do ln -s ${source_dir}/${source_expid}/$file $(echo ${target_subdir}/${target_expid}/$file | sed "s/$source_expid/$target_expid/"); done &
done
wait
fi
Sebastian Milinski's avatar
Sebastian Milinski committed
357
358
359
360
361
362