-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive_esm.sh
executable file
·2131 lines (1963 loc) · 79.1 KB
/
archive_esm.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
##########################################################################
# File: archive_esm.sh
#
# This script is used to archive raw, restart, and logging data of mpiesm
# coupled models. Additionally climatologies are performed and archived.
#
# Usage:
# ------
# archive_esm.sh [OPTIONS]...
#
# Options are
# --help, -h display built-in help text and exit.
#
# for more use --help
#
###########################################################################
# ---- Error handling ----------------------------------------------------#
set -e
# Trap error and killer signals
# so that we can exit with a message incl. line no
trap 'err_exit ${LINENO}' ERR
trap 'err_exit "" "Received signal SIGHUP !"' SIGHUP
trap 'err_exit "" "Received signal SIGINT !"' SIGINT
trap 'err_exit "" "Received signal SIGTERM !"' SIGTERM
trap 'err_exit "" "Received signal SIGQUIT !"' SIGQUIT
#-------------------------------------------------------------------------#
# ---- Format specifier --------------------------------------------------#
# bold
b="\e[1m"
# underlined
u="\e[4m"
# normal
n="\e[0m"
#-------------------------------------------------------------------------#
# ---- Functions ---------------------------------------------------------#
# Error and exit for non existing raw data directories
function err_dat_dir() {
# $1 line no
# $2 component (Atmosphere/Land/Ocean/OBGC)
# $3 data directory
local code=1
if [ ! -d $3 ]; then
local msg="$2 dir is not there! $3"
err_exit $1 "${msg}" ${code}
fi
}
# Error and exit for non existing raw data file
function err_dat_file() {
# $1 line no
# $2 raw data file
local msg="Raw data file $2 is not there or permissions denied!"
local code=1
err_exit $1 "${msg}" ${code}
}
# Exit with message
function err_exit {
# $1 line no
# $2 error message
# $3 error code
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
local err_msg="ERROR $0 on or near line ${parent_lineno}"
echo
if [[ -n "$message" ]] ; then
echo "${err_msg}: ${message}"
else
echo "${err_msg}"
fi
on_exit ${code}
exit ${code}
}
# Error and exit for empty mandatory options
function err_option() {
# $1 line no
# $2 name of option
local msg="Empty mandatory $2 option!"
local code=1
err_exit $1 "${msg}" ${code}
}
# Error and exit for read-only raw data directories
function err_ro_dat_dir() {
# $1 line no
# $2 component (Atmosphere/Land/Ocean/OBGC)
# $3 data directory
if [ ! -w $3 ]; then
local msg="$2 dir is write-protected for user!"
local code=1
err_exit $1 "${msg}" ${code}
fi
}
# Error and exit for processing's first year > last year
function err_years() {
# $1 line no
# $2 first year
# $3 last year
local msg="Processing's first year $2 > last year $3!"
local code=1
err_exit $1 "${msg}" ${code}
}
# get multi-year monthly means climatology
function get_lm_climatology() {
# $1 name of data file with e.g. monthly means
# $2 time period of data file
# $3 type id of input data, e.g. monthly means
# $4 type id of multi-year monthly means
# $5 variable to store file name of multi-year monthly means
# $6 path to code file for data file
# $7 tidying up is desired on failure
# cdo command to get climatology output file in netCDF format
local cdo
set_cdo_cmd $1 $6 cdo $7
# climatology file name
local outfile=$(set_climatology_fname $1 $2 $3 $4)
# Retrieve data file isn't in netCDF format
if [[ $(get_str_short_suffix "$1" ".") != "nc" ]]; then
# climatology file is in netCDF format
outfile=$(get_str_short_prefix ${outfile} ".").nc
fi
# get multi-year monthly means
${cdo} -lmean $1 ${outfile}
# return climatology file name
eval ${5}="'${outfile}'"
}
# get monthly means climatology
function get_mm_climatology() {
# $1 name of data file with e.g. daily means
# $2 time period of data file
# $3 type id of input data, e.g. daily means
# $4 type id of monthly means
# $5 variable to store file name of monthly means
# $6 path to code file for data file
# $7 tidying up is desired on failure
# cdo command to get climatology output file in netCDF format
local cdo
set_cdo_cmd $1 $6 cdo $7
# climatology file name
local outfile=$(set_climatology_fname $1 $2 $3 $4)
# Retrieve data file isn't in netCDF format
if [[ $(get_str_short_suffix "$1" ".") != "nc" ]]; then
# climatology file is in netCDF format
outfile=$(get_str_short_prefix ${outfile} ".").nc
fi
# get monthly means
${cdo} -monmean $1 ${outfile}
# return climatology file name
eval ${5}="'${outfile}'"
}
# Get option argument and store it in function argument
function get_option_arg() {
# $1 variable to store argument
# $2:@ option followed by it's arguments
# Variable to store arguments
local _var=$1
# Arguments
local args=""
# Retrieve option: non empty argument and argument starts with "-"
if [[ -n ${2} && ( ${2:0:1} == "-" ) ]]; then
shift
# Retrieve args: non empty arguments and arguments doesn't start with "-"
while [[ -n ${2} && ( ${2:0:1} != "-" ) ]]; do
args="${args} ${2}"
shift
done
# Remove 1st character of arguments string, is a blank space
args=${args:1}
eval ${_var}="'${args}'"
fi
}
# get multi-year seasonal means climatology
function get_sm_climatology() {
# $1 name of data file with e.g. multi-year monthly means
# $2 time period of data file
# $3 type id of input data, e.g multi_year monthly means
# $4 type id of multi-year seasonal means
# $5 variable to store file name of multi-year seasonal means
# $6 path to code file for data file
# $7 tidying up is desired on failure
# cdo command to get climatology output file in netCDF format
local cdo
set_cdo_cmd $1 $6 cdo $7
# climatology file name
local outfile=$(set_climatology_fname $1 $2 $3 $4)
# Retrieve data file isn't in netCDF format
if [[ $(get_str_short_suffix "$1" ".") != "nc" ]]; then
# climatology file is in netCDF format
outfile=$(get_str_short_prefix ${outfile} ".").nc
fi
# get multi-year seasonal means
### compare to yseasmean?
${cdo} -mergetime \
-timmean -selmon,12,1,2 $1 \
-timmean -selmon,3,4,5 $1 \
-timmean -selmon,6,7,8 $1 \
-timmean -selmon,9,10,11 $1 \
${outfile}
# return climatology file name
eval ${5}="'${outfile}'"
}
# get longest prefix of a string
function get_str_long_prefix() {
# $1 string, e.g. file name
# $2 delimiter
# get longest prefix of string up to delimiter
local prefix=${1%$2*}
# return prefix
echo ${prefix}
}
# get longest suffix of a string
function get_str_long_suffix() {
# $1 string, e.g. file name
# $2 delimiter
# get longest suffix of string from delimiter backwards
local suffix=${1#*${2}}
# return prefix
echo ${suffix}
}
# get shortest prefix of a string
function get_str_short_prefix() {
# $1 string, e.g. file name
# $2 delimiter
# get shortest prefix of string up to delimiter
local prefix=${1%%$2*}
# return prefix
echo ${prefix}
}
# get shortest suffix of a string
function get_str_short_suffix() {
# $1 string, e.g. file name
# $2 delimiter
# get shortes suffix of string from delimiter backwards
local suffix=${1##*${2}}
# return prefix
echo ${suffix}
}
# get time means climatology
function get_tm_climatology() {
# $1 name of data file to get climatology from
# $2 time period of data file
# $3 type id of input data, e.g multi_year monthly means
# $4 type id of time means
# $5 variable to store file name of time means
# $6 path to code file for data file
# $7 tidying up is desired on failure
# cdo command to get climatology output file in netCDF format
local cdo
set_cdo_cmd $1 $6 cdo $7
# climatology file name
local outfile=$(set_climatology_fname $1 $2 $3 $4)
# Retrieve data file isn't in netCDF format
if [[ $(get_str_short_suffix "$1" ".") != "nc" ]]; then
# climatology file is in netCDF format
outfile=$(get_str_short_prefix ${outfile} ".").nc
fi
# get multi-year seasonal means
${cdo} -timmean $1 ${outfile}
# return climatology file name
eval ${5}="'${outfile}'"
}
# Some info on exit
function on_exit() {
local exit_code=${1:-$?}
echo
echo Exiting $0 with status $exit_code
exit $exit_code
}
# Moving/copying data message within processing
function proc_mv_msg() {
# $1 command
# $2 $3 Source and destination directory
if [ "$1" == "mv" ]; then
printf "\tmove "
elif [ "$1" == "cp" ]; then
printf "\tcopy "
fi
printf "data from $2 to $3 \n\n"
}
# archiving data message within processing
function proc_tar_msg() {
# $1 command
# $2 tar file name
# $3 path to tar file
if [ "$1" == "tar -cvf" ]; then
printf "\tcreating "
elif [ "$1" == "tar -rvf" ]; then
printf "\tappending files to "
fi
printf "tar file $2 on $3 containing: \n"
}
# check size of transferred files
function put_check_size() {
# $1 local file size
# $2 remote file name incl. path
# $3 log file of file transfer
# remote file size
tarball=$(get_str_short_suffix "${2}" "/")
local rsz=$(grep "^-.*${tarball}$" $3 | awk '{print $5}')
# error code
local code=1
# if empty abort
if [ -z ${rsz} ] ; then
local msg="Remote tarball $2 not there!"
err_exit $LINENO "${msg}" ${code}
fi
# if not equal to local abort
if [ ${1} -ne ${rsz} ] ; then
local msg="Tarballs local size = ${1} /= remote size = ${rsz}!"
err_exit $LINENO "${msg}" ${code}
fi
}
# select code file of raw data file
function select_code_file() {
# $1 data file name (wo path)
# $2 path to code file for data file
# $3 variable to store code file name
# delimiter to get substrings of prefix
local delim="_"
# get experiment id of file name
local iden=$(get_str_short_prefix "$1" "${delim}")
# get model component of file name
#local comp=${1#*_}
local comp=$(get_str_long_suffix "$1" "${delim}")
#comp=${comp%%_*}
comp=$(get_str_short_prefix "${comp}" "${delim}")
# select code file of data file
local file
case $1 in
*${comp}*_accw_*)
file="${iden}_${comp}_accw.codes"
;;
*${comp}*_ATM_*)
file="${iden}_${comp}_echam.codes"
;;
*${comp}*_BOT_*)
file="${iden}_${comp}_echam.codes"
;;
*${comp}*_co2_*)
file="${iden}_${comp}_co2.codes"
;;
*${comp}*_jsbach_*)
file="${iden}_${comp}_jsbach.codes"
;;
*${comp}*_land_*)
file="${iden}_${comp}_land.codes"
;;
*${comp}*_surf_*)
file="${iden}_${comp}_surf.codes"
;;
*${comp}*_veg_*)
file="${iden}_${comp}_veg.codes"
;;
*${comp}*_yasso_*)
file="${iden}_${comp}_yasso.codes"
;;
*)
local msg="No code file for data file $1 defined!"
err_exit $LINENO "${msg}" 1
esac
# return code file name incl. path
file="$2/${file}"
if [[ -f ${file} ]]; then
eval $3="'${file}'"
else
err_exit $LINENO "Code file ${file} not found!" 1
fi
}
# set cdo commands with outfile in netCDF format
function set_cdo_cmd() {
# $1 name of input data file
# $2 path to code file for data file
# $3 variable to store cdo command
# $4 tidying up is desired on failure
# Retrieve data file isn't in netCDF format
if [[ $(get_str_short_suffix "$1" ".") != "nc" ]]; then
# get code file for data file
local codefile
select_code_file $1 $2 codefile $4
# cdo command to convert climatology file to netCDF
local cmd="cdo --silent -f nc -setpartab,${codefile}"
else
# cdo command for netCDF data files
local cmd="cdo --silent"
fi
# return cdo command
eval ${3}="'${cmd}'"
}
# set climatology file name
function set_climatology_fname() {
# $1 name of data file to get climatology from
# $2 time period of data file
# $3 type id of data to get climatology from, e.g. daily means
# $4 type id of climatology data
# prefix of data file name up to time period
local pref=$(get_str_short_prefix "$1" "$2")
# suffix of data file incl. time period
local suff=${2}$(get_str_short_suffix "$1" "$2")
# climatology file name
local outfile=${pref}${4}_${suff}
# delete type id of monthly means substring
outfile=${outfile/_${3}_/"_"}
# return climatology file name
echo "${outfile}"
}
# Tidying up: mv data files of temporary directory back
# to where they come from
function tidying_up() {
# $file_pats global data file patterns
# $mvcp global move/copy of model data to temporary
# directory and vice versa
# $sub_time global placeholder for time period of data files
# $tmp_path global temporary directory
# $years global list of years of processing
local msg # local error message
local code=1 # local error code
printf "\nMove/Copy model data files from temporary directory"
printf "${tmp_path} to where they come from"
printf "\nfor ${first_year} to ${last_year} starts ...\n"
# Retrieve temporary directory doesn't exist and exit
err_dat_dir ${LINENO} "temporary" "${tmp_path}" false
# Retrieve temporary directory doesn't contain any files
# and exit
if [ ! "$(find ${tmp_path} -type f 2>/dev/null)" ]; then
printf "\n\tRETURN: temporary dir doesn't contain any files!\n\n"
exit
fi
for (( i=0;i<${#file_pats[@]};i++ )); do
# Pattern of temporary data file names
local pat="$(get_str_short_suffix "${file_pats[i]}" "/")"
# Path where the temporary data files comes from
local in_path="$(get_str_long_prefix "${file_pats[i]}" "/")"
# Retrieve path doesn't exist and exit
#if [ ! -d ${in_path} ]; then
# msg="Path ${in_path} where the temporary "
# msg="${msg}" "data files comes from is not there!"
# err_exit ${LINENO} "${msg}" ${code}
#fi
# not needed: path inquired within global file patterns
# Loop through all years for processing
for year in ${years}; do
# Data file names
fnames="${pat/${sub_time}/${year}*}"
# Loop through temporay data files
for file in ${tmp_path}/${fnames}; do
# Set raw data file
in_file=$(get_str_short_suffix "${file}" "/")
in_file=${in_path}/${in_file}
# Retrieve temporary data file exists
if [[ -f "${file}" ]]; then
# Retrieve raw data file doesn't exists
if [[ ! -f "${in_file}" ]]; then
# Move temporary data file
# back to where it comes from
printf "\n\t${mvcp} "${file}" "${in_file}"\n"
${mvcp} "${file}" "${in_file}"
# Retrieve raw data file exists
else
printf "\n\tNo move/copy: raw data file ${in_file} exists !\n"
fi
# Retrieve temporary data file doesn't exist
else
printf "\n\tNo move/copy: temporary data files ${file} not found !\n"
fi
done
done
done
printf "\nMove/Copy model data files done!\n"
}
# Built-in help text
function usage() {
printf "${b}NAME${n}\n\t$(basename $0) - archiving mpiesm model data\n\n"
printf "${b}SYNOPSIS ${n}\n\t${b}$(basename $0)${n} [${u}OPTION${n}]...\n\n"
printf "${b}DESCRIPTION ${n}\n"
printf "\tArchives mpiesm model raw, restart, and/or logging data for a\n"
printf "\tuser specified time period and model components. Additionally\n"
printf "\tclimatologies are performed.\n"
printf "\tThe user can freely select which files should be processed.\n"
printf "\tFurthermore the archiving and the processing of the\n"
printf "\tclimatologies can be switched on/off.\n\n"
printf "\tIn the experiment's root directory, see option experiment_path,\n"
printf "\tthe raw and restart data are expected in the outdata and restart\n"
printf "\tsubdirectory of the model component, and the logging data in\n"
printf "\tthe log subdirectory.\n\n"
printf "\tThe data are moved or copied to and processed in the temporary\n"
printf "\tdirectory, see option tmp_path. That will be previously cleaned up.\n\n"
printf "\tOptionally monthly (mm), multi-year monthly (lm) and seasonal (sm),\n"
printf "\tand time mean (tm) climatologies of the model raw data being\n"
printf "\tprocessed and copied into the local storage directory, see\n"
printf "\toption climatologies_path. The files are named after the\n"
printf "\tprocessed raw data file combined with the climatology type and\n"
printf "\tthe time period replaced with the processing's first and last\n"
printf "\tyear.\n\n"
printf "\tFor archiving each data and climatology file get zipped and put\n"
printf "\tinto a tarball. The raw data and climatologies of each model\n"
printf "\tcomponent, the restart and logging data get each one tarball.\n"
printf "\tThey are named after\n"
printf "\t<experiment_id>_<model_component|restart|log>_<firstyear_lastyear>.tar\n\n"
printf "\tThe minimum and maximum size of the tarballs are 1 GB (warning)\n"
printf "\tand 500 GB (error).\n\n"
printf "\tThe tarballs are transfered via pftp to the archive path on\n"
printf "\tthe long term remote archiv and copied into the local storage\n"
printf "\tdirectory, see options remote_archive_path and local_archive_path.\n"
printf "\tThe transfer expects a valid netrc.\n\n"
printf "\tAll directories incl. the remote directories are created as\n"
printf "\trequired.\n\n"
printf "\tEnabling tidying up, see option ltidying, moves or copies data\n"
printf "\tfiles from the temporary directory to where they come from. By\n"
printf "\tthe setup you set the temporary files and where they come from.\n"
printf "\tNo more archiving and/or climatologies are performed.\n\n"
printf "${b}OPTIONS${n}\n"
printf "\t${b}--atmosphere_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select raw data of the\n"
printf "\t\tatmosphere model component for processing, see options\n"
printf "\t\tlatmosphere and larchive_data and/or lclimatologies:\n"
printf "\t\t<experiment_path>/outdata/<atmosphere_model_component>/\n"
printf "\t\t<experiment_id>_<atmosphere_model_component>_<atmosphere_data_pat><time period>.grb\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"accw_ ATM_mm_ BOT_mm_ co2_ co2_mm_ echam_\"\n"
printf "\t${b}--atmosphere_data_type${n} ${u}TYPE${n}\n"
printf "\t\ttype of raw data of atmosphere model component to control\n"
printf "\t\tperforming climatologies (daily means = dm, monthly means = mm,\n"
printf "\t\tyearly means = ym, no climatologies desired = none).\n"
printf "\t\tdefault: \"mm mm mm none mm none\"\n"
printf "\t${b}--atmosphere_model_component${n} ${u}COMPONENT${n}\n"
printf "\t\tmodel component of file patterns to select raw and restart\n"
printf "\t\tdata of the atmosphere model component for processing, see\n"
printf "\t\toption atmosphere_data_pat and atmosphere_restart_data_pat.\n"
printf "\t\tdefault: \"echam6\"\n"
printf "\t${b}--atmosphere_restart_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select restart data of\n"
printf "\t\tthe atmosphere model component for processing, see options\n"
printf "\t\tlatmosphere and larchive_restart:\n"
printf "\t\t<experiment_path>/restart/<atmosphere_model_component>/\n"
printf "\t\trestart_<experiment_id>_<atmosphere_restart_data_pat><time period>.nc\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"accw_ co2_ echam_\"\n"
printf "\t${b}--climatologies_path${n} ${u}PATH${n}\n"
printf "\t\tpath to root directory, where to store performed climatologies.\n"
printf "\t\tdefault: \"/work/<project_id>/\${USER}/<mpiesm_id>/experiments/"
printf "means/<experiment_id>\"\n"
printf "\t${b}--coupler_model_component${n} ${u}COMPONENT${n}\n"
printf "\t\tmodel component of file patterns to select restart data of\n"
printf "\t\tthe coupler for processing, see option coupler_restart_data_pat.\n"
printf "\t\tdefault: \"oasis3mct\"\n"
printf "\t${b}--coupler_restart_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select restart data of\n"
printf "\t\tthe coupler model component for processing, see options\n"
printf "\t\tlcoupler and larchive_restart:\n"
printf "\t\t<experiment_path>/restart/<coupler_model_component>/\n"
printf "\t\t<coupler_restart_data_pat>i<experiment_id>_<time period>.tar\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"flxatmos_ sstocean_\"\n"
printf "\t${b}--experiment_id, -e${n} ${u}ID${n}\n"
printf "\t\tmandatory experiment ID for default paths to temporary,\n"
printf "\t\texperiment's, climatologies, local and remote archive\n"
printf "\t\tdata (see options tmp_path, experiment_path,\n"
printf "\t\tclimatologies_path, local_archive_path,and\n"
printf "\t\tremote_archive_path). Additionally used for file patterns\n"
printf "\t\tto select raw, restart, and/or logging data for processing.\n"
printf "\t${b}--experiment_path${n} ${u}PATH${n}\n"
printf "\t\tpath to directory with experiment's raw, restart, and\n"
printf "\t\tlogging data.\n"
printf "\t\tdefault: \"/work/<project_id>/\${USER}/<mpiesm_id>/experiments/"
printf "<experiment_id>\"\n"
printf "\t${b}--firstyear, -f${n} ${u}FIRSTYEAR${n}\n"
printf "\t\tmandatory year to start data processing (in format YYYY).\n"
printf "\t\tTogether with last year, see option lastyear, and the\n"
printf "\t\tincrement, see option incrementyear, it sets the period and\n"
printf "\t\tthe list of years for the file patterns to select raw,\n"
printf "\t\trestart, and/or logging data for processing.\n"
printf "\t${b}--help, -h${n}\n"
printf "\t\tdisplay this built-in help text and exit.\n"
printf "\t${b}--incrementyear, -f${n} ${u}INCREMENT${n}\n"
printf "\t\tincrement of processing's time period in years. Together\n"
printf "\t\twith first and last year, see option firstyear and lastyear,\n"
printf "\t\tit sets the list of years for the file patterns to select\n"
printf "\t\traw, restart, and/or logging data for processing.\n"
printf "\t\tdefault: 1\n"
printf "\t${b}--land_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select raw data of the\n"
printf "\t\tland model component for processing, see options lland and\n"
printf "\t\tlarchive_data and/or lclimatologies:\n"
printf "\t\t<experiment_path>/outdata/<land_model_component>/\n"
printf "\t\t<experiment_id>_<land_model_component>_<land_data_pat><time period>.grb\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"jsbach_ jsbach_mm_ land_ land_mm_ surf_ surf_mm_\n"
printf "\t\t\t\tveg_ veg_mm_ yasso_ yasso_mm_\"\n"
printf "\t${b}--land_data_type${n} ${u}TYPE${n}\n"
printf "\t\ttype of raw data of land model component to control\n"
printf "\t\tperforming climatologies (daily means = dm, monthly means = mm,\n"
printf "\t\tyearly means = ym, no climatologies desired = none).\n"
printf "\t\tdefault: \"none mm none mm none mm none mm none mm\"\n"
printf "\t${b}--land_model_component${n} ${u}COMPONENT${n}\n"
printf "\t\tmodel component of file patterns to select raw and restart\n"
printf "\t\tdata of the land model component for processing, see option\n"
printf "\t\tland_data_pat and land_restart_data_pat.\n"
printf "\t\tdefault: \"jsbach\"\n"
printf "\t${b}--land_restart_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select restart data of\n"
printf "\t\tthe land model component for processing, see options lland\n"
printf "\t\tand larchive_restart:\n"
printf "\t\t<experiment_path>/restart/<land_model_component>/\n"
printf "\t\trestart_<experiment_id>_<land_restart_data_pat><time period>.nc\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"hd_ jsbach_ surf_ veg_ yasso_\"\n"
printf "\t${b}--larchive_data${n} ${u}LOGICAL${n}\n"
printf "\t\tenable archiving raw data and climatologies of enabled model\n"
printf "\t\tcomponents.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--larchive_log${n} ${u}LOGICAL${n}\n"
printf "\t\tenable archiving experiment's logging data.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--larchive_restart${n} ${u}LOGICAL${n}\n"
printf "\t\tenable archiving restart data of enabled model components.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--latmoshere${n} ${u}LOGICAL${n}\n"
printf "\t\tenable processing data of the atmosphere model component.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--lastyear, -l${n} ${u}LASTYEAR${n}\n"
printf "\t\tmandatory year to end data processing (in format YYYY).\n"
printf "\t\tTogether with first year, see option firstyear, and the\n"
printf "\t\tincrement, see option incrementyear, it sets the period and\n"
printf "\t\tthe list of years for the file patterns to select raw,\n"
printf "\t\trestart, and/or logging data for processing.\n"
printf "\t${b}--lclimatologies${n} ${u}LOGICAL${n}\n"
printf "\t\tenable processing climatologies of raw data of enabled model\n"
printf "\t\tcomponents.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--lcoupler${n} ${u}LOGICAL${n}\n"
printf "\t\tenable processing data of coupler component.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--lland${n} ${u}LOGICAL${n}\n"
printf "\t\tenable processing data of land model component.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--llog${n} ${u}LOGICAL${n}\n"
printf "\t\tenable processing experiment's logging data.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--lobgc${n} ${u}LOGICAL${n}\n"
printf "\t\tenable processing data of ocean's biogeochemistry model\n"
printf "\t\tcomponent.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--local_archive_path${n} ${u}PATH${n}\n"
printf "\t\tpath to archive data on local machine.\n"
printf "\t\tdefault: \"/work/<project_id>/\${USER}/<mpiesm_id>/experiments/"
printf "tars/<experiment_id>\"\n"
printf "\t${b}--locean${n} ${u}LOGICAL${n}\n"
printf "\t\tenable processing data of ocean model component.\n"
printf "\t\tdefault: true\n"
printf "\t${b}--log_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select logging data\n"
printf "\t\tfor processing:\n"
printf "\t\t<experiment_path>/log/"
printf "<experiment_id>_<log_data_pat><time period>.log\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"run_ store_ \"\n"
printf "\t\tif latmosphere == true : <log_data_pat> + echam6_atmout_\n"
printf "\t\tif locean == true : <log_data_pat> + mpiom_oceout_\n"
printf "\t\tif lobgc == true : <log_data_pat> + hamocc_bgcout_\n"
printf "\t${b}--lprofiling${n} ${u}LOGICAL${n}\n"
printf "\t\tenable profiling.\n"
printf "\t\tdefault: false\n"
printf "\t${b}--ltidying${n} ${u}LOGICAL${n}\n"
printf "\t\tenable tidying up: move/copy data files from temporary\n"
printf "\t\tdirectory to where they come from. By the setup you set the\n"
printf "\t\ttemporary files and where they come from. No more archiving\n"
printf "\t\tand/or climatologies are performed.\n"
printf "\t\tdefault: false\n"
printf "\t${b}--mpiesm_id, -m${n} ${u}ID${n}\n"
printf "\t\tmandatory mpiesm ID for default paths to experiment's,\n"
printf "\t\tclimatologies, local and remote archive data (see options\n"
printf "\t\texperiment_path, climatologies_path, local_archive_path,\n"
printf "\t\tand remote_archive_path).\n"
printf "\t${b}--obgc_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select raw data of the\n"
printf "\t\tocean's biogeochemistry model component for processing, see\n"
printf "\t\toptions lobgc and larchive_data and/or lclimatologies:\n"
printf "\t\t<experiment_path>/outdata/<obgc_model_component>/\n"
printf "\t\t<experiment_id>_<obgc_model_component>_<obgc_data_pat><time period>.grb\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"co2_ data_2d_mm_ data_3d_ym_ data_eu_mm_\n"
printf "\t\t\t\tdata_sedi_ym_ monitoring_ym_\"\n"
printf "\t${b}--obgc_data_type${n} ${u}TYPE${n}\n"
printf "\t\ttype of raw data of ocean's biogeochemistry model component\n"
printf "\t\tto control performing climatologies (daily means = dm,\n"
printf "\t\tmonthly means = mm, yearly means = ym, \n"
printf "\t\tno climatologies desired = none).\n"
printf "\t\tdefault: \"dm mm ym mm ym ym\"\n"
printf "\t${b}--obgc_model_component${n} ${u}COMPONENT${n}\n"
printf "\t\tmodel component of file patterns to select raw and restart\n"
printf "\t\tdata of the ocean's biogeochemistry model component for\n"
printf "\t\tprocessing, see option obgc_data_pat and obgc_restart_data_pat.\n"
printf "\t\tdefault: \"hamocc\"\n"
printf "\t${b}--obgc_restart_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select restart data of\n"
printf "\t\tthe ocean's biogeochemistry model component for processing,\n"
printf "\t\tsee options lobgc and larchive_restart:\n"
printf "\t\t<experiment_path>/restart/<obgc_model_component>/\n"
printf "\t\trerun_<experiment_id>_<obgc_restart_data_pat><time period>.nc\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"hamocc_\"\n"
printf "\t${b}--ocean_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select raw data of the\n"
printf "\t\tocean model component for processing, see options locean and\n"
printf "\t\tlarchive_data and/or lclimatologies:\n"
printf "\t\t<experiment_path>/outdata/<ocean_model_component>/\n"
printf "\t\t<experiment_id>_<ocean_model_component>_<ocean_data_pat><time period>.grb\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"data_2d_mm_ data_3d_mm_ data_moc_mm_ "
printf "monitoring_ym_ timeser_mm_\"\n"
printf "\t${b}--ocean_data_type${n} ${u}TYPE${n}\n"
printf "\t\ttype of raw data of the ocean model component to control\n"
printf "\t\tperforming climatologies (daily means = dm, monthly means = mm,\n"
printf "\t\tyearly means = ym, no climatologies desired = none).\n"
printf "\t\tdefault: \"mm mm mm ym mm\"\n"
printf "\t${b}--ocean_model_component${n} ${u}COMPONENT${n}\n"
printf "\t\tmodel component of file patterns to select raw and restart\n"
printf "\t\tdata of the ocean model component for processing, see option\n"
printf "\t\tocean_data_pat and obgc_restart_data_pat.\n"
printf "\t\tdefault: \"mpiom\"\n"
printf "\t${b}--ocean_restart_data_pat${n} ${u}PATTERN${n}\n"
printf "\t\tdata indicators of file patterns to select restart data of\n"
printf "\t\tthe ocean model component for processing, see options locean\n"
printf "\t\tand larchive_restart:\n"
printf "\t\t<experiment_path>/restart/<ocean_model_component>/\n"
printf "\t\trerun_<experiment_id>_<ocean_restart_data_pat><time period>.nc\n"
printf "\t\twith time period between first and last year.\n"
printf "\t\tdefault: \"mpiom_\"\n"
printf "\t${b}--project_id, -p ${n} ${u}ID${n}\n"
printf "\t\tmandatory project ID for default paths to experiment's,\n"
printf "\t\tclimatologies, local and remote archive data (see options\n"
printf "\t\texperiment_path, climatologies_path, local_archive_path,\n"
printf "\t\tand remote_archive_path).\n"
printf "\t${b}--remote_archive_path${n} ${u}PATH${n}\n"
printf "\t\tpath to archive data on remote archiving host.\n"
printf "\t\tdefault: \"<project_id>/\${USER}/<mpiesm_id>/<experiment_id>\"\n"
printf "\t${b}--tmp_path${n} ${u}PATH${n}\n"
printf "\t\tpath to temporary data and processing.\n"
printf "\t\tdefault: \"/scratch/m/\${USER}/tmp/<experiment_id>_<first_year>_<last_year>_\$\$\"\n"
printf "\t${b}--verbose, -v${n} ${u}INT${n}\n"
printf "\t\tenable verbose log.\n"
printf "\t\tdefault: 0 (no log info) | >=2 print command info\n"
printf "${b}\nEXAMPLES ${n}\n\n"
printf "\t${b}./$(basename $0) --project_id xx0000 --mpiesm_id mpiesm_rev_0\n"
printf "\t\t--experiment_id xxx0123 --firstyear 3800 --lastyear 3899${n}\n"
printf "\t\tarchives experiment's xxx0123 default raw, restart, and\n"
printf "\t\tlogging data of all model components and performs and\n"
printf "\t\tarchives the default climatologies for the time period\n"
printf "\t\t3800 - 3899. The data are expected in and the processed\n"
printf "\t\tdata are put into the default directories.\n\n"
printf "\t${b}./$(basename $0) --project_id xx0000 --mpiesm_id mpiesm_rev_0\n"
printf "\t\t--experiment_id xxx0123 --firstyear 3800 --lastyear 3899\n"
printf "\t\t--lobgc false${n}\n"
printf "\t\tarchives experiment's xxx0123 default raw, restart, and\n"
printf "\t\tlogging data of all model components except the ocean's\n"
printf "\t\tbiogeochemical one and performs and archives the default\n"
printf "\t\tclimatologies for the time period 3800 - 3899. The data are\n"
printf "\t\texpected in and the processed data are put into the\n"
printf "\t\tdefault directories.\n\n"
printf "\t${b}./$(basename $0) --project_id xx0000 --mpiesm_id mpiesm_rev_0\n"
printf "\t\t--experiment_id xxx0123 --firstyear 3800 --lastyear 3899\n"
printf "\t\t--latmosphere false --lland false --lobgc false --locean false\n"
printf "\t\t--lcoupler false ${n}\n"
printf "\t\tarchives experiment's xxx0123 default logging data for the\n"
printf "\t\ttime period 3800 - 3899. The data are expected in and the\n"
printf "\t\tprocessed data are put into the default directories.\n\n"
printf "\t${b}./$(basename $0) --project_id xx0000 --mpiesm_id mpiesm_rev_0\n"
printf "\t\t--experiment_id xxx0123 --firstyear 3800 --lastyear 3899\n"
printf "\t\t--larchive_restart false --larchive_log false ${n}\n"
printf "\t\tarchives experiment's xxx0123 default raw data of all model\n"
printf "\t\tcomponents and performs and archives the default climatologies\n"
printf "\t\tfor the time period 3800 - 3899. The data are expected in and\n"
printf "\t\tthe processed data are put into the default directories.\n\n"
printf "\t${b}./$(basename $0) --project_id xx0000 --mpiesm_id mpiesm_rev_0\n"
printf "\t\t--experiment_id xxx0123 --firstyear 3809 --lastyear 3899\n"
printf "\t\t--incrementyear 10 --larchive_data false --larchive_log false\n"
printf "\t\t--lclimatologies false${n}\n"
printf "\t\tarchives experiment's xxx0123 default restart data of all model\n"
printf "\t\tcomponents for the time period 3809 - 3899 with an increment of\n"
printf "\t\t10 years. The data are expected in and the processed data are\n"
printf "\t\tput into the default directories.\n\n"
printf "\n"
}
#-------------------------------------------------------------------------#
#set -x
#dir="/work/mh0110/m211003/mpiesm-flo-dev/experiments/uwe0010/outdata/echam6"
## Get file pattern of model compoments experiment's raw data directory
## Twice delete up to the first "_" (incl.),
## 3rd delete all after last "_", then sort and find uniques
#ls $dir | sed -n 's/_/&\n/;s/.*\n//p' | sed -n 's/_/&\n/;s/.*\n//p' | sed 's/\(.*\_\).*/\1/g' | sort | uniq
#exit
#-------------------------------------------------------------------------#
# ---- Get options and setup ---------------------------------------------#
while [[ -n $1 ]]; do
case $1 in
# data indicators of file patterns for atmosphere raw data
--atmosphere_data_pat )
get_option_arg atmos_dat $@ ;;
# type of atmosphere raw data to control performing climatologies
--atmosphere_data_type )
get_option_arg atmos_dat_type $@ ;;
# model component for the atmosphere
--atmosphere_model_component )
get_option_arg atmos_mod_com $@ ;;
# data indicators of file patterns for atmosphere restart data
--atmosphere_restart_data_pat )
get_option_arg atmos_rst $@ ;;
# path to root directory, where to store performed climatologies
--climatologies_path )
get_option_arg cli_path $@ ;;
# model component for the coupler
--coupler_model_component )
get_option_arg coupl_mod_com $@ ;;
# data indicators of file patterns for coupler restart data
--coupler_restart_data_pat )
get_option_arg coupl_rst $@ ;;
# mandatory experiment ID for default root directories and
# file patterns to select data for processing
--experiment_id | -e )
get_option_arg exp_id $@ ;;
# path to experiment's root directory
--experiment_path )
get_option_arg exp_path $@ ;;
# mandatory first model year to process (in format YYYY)
--firstyear | -f )
get_option_arg first_year $@ ;;
# print built-in help and exit
--help | -h )
usage; exit ;;
# increment of time period in years
--incrementyear )
get_option_arg increment_year $@ ;;
# data indicators of file patterns for land raw data
--land_data_pat )
get_option_arg land_dat $@ ;;
# type of land raw data to control processing climatologies
--land_data_type )
get_option_arg land_dat_type $@ ;;
# model component for the land
--land_model_component )
get_option_arg land_mod_com $@ ;;
# data indicators of file patterns for land restart data
--land_restart_data_pat )
get_option_arg land_rst $@ ;;
# enable archiving raw data and climatologies
--larchive_data )
get_option_arg larchive_data $@ ;;
# enable archiving logging data
--larchive_log )
get_option_arg larchive_log $@ ;;
# enable archiving restart data
--larchive_restart )
get_option_arg larchive_restart $@ ;;
# enable processing atmosphere data
--latmosphere )
get_option_arg latmos $@ ;;
# mandatory last model year to process (in format YYYY)
--lastyear | -l )
get_option_arg last_year $@ ;;
# enable performing climatologies
--lclimatologies )
get_option_arg lclimat $@ ;;
# enable processing coupler data
--lcoupler )
get_option_arg lcoup $@ ;;
# enable processing land data
--lland )
get_option_arg lland $@ ;;
# enable processing logging data
--llog )
get_option_arg llog $@ ;;
# enable processing ocean biogeochemical data
--lobgc )
get_option_arg lobgc $@ ;;
# path to archive data on local machine
--local_archive_path )
get_option_arg loc_arc_path $@ ;;
# enable processing ocean data
--locean )
get_option_arg locean $@ ;;
# data indicators of file patterns for logging data
--log_data_pat )
get_option_arg log_dat $@ ;;
# enable profiling
--lprofiling )
get_option_arg lprofiling $@ ;;
# enable tidying up only
--ltidying )
get_option_arg ltidying $@ ;;
# mandatory mpiesm ID for default root directories
--mpiesm_id | -m )
get_option_arg esm_id $@ ;;
# data indicators of file patterns for ocean biogeochemical raw data
--obgc_data_pat )
get_option_arg obgc_dat $@ ;;
# type of ocean biogeochemical raw data to control processing climatologies
--obgc_data_type )
get_option_arg obgc_dat_type $@ ;;
# model component for the ocean biogeochemistry
--obgc_model_component )
get_option_arg obgc_mod_com $@ ;;
# data indicators of file patterns for ocean biogeochemical restart data
--obgc_restart_data_pat )
get_option_arg obgc_rst $@ ;;
# data indicators of file patterns for ocean raw data
--ocean_data_pat )
get_option_arg ocean_dat $@ ;;
# type of ocean raw data to control processing climatologies
--ocean_data_type )