-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeMIP_makegrid
60 lines (42 loc) · 2.17 KB
/
FeMIP_makegrid
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
#!/bin/bash
# FeMIP_makegrid is intended to be used should the user want to create a custom vertical grid and
# not use the default WOA01 grid employed in FeMIP_regrid. Users must edit FeMIP_makegrid. The output
# of FeMIP_makegrid is three txt files: 'mygrid', 'depth' and 'levels which will contain the neccessary inforamtion required
# by FeMIP_regrid to do the interpolation as well as the later MATLAB scripts
# Written by Jonathan J Rogerson
# 25 February 2020
# Edited 10 December 2020
# Default
INDIR="../MODEL_DATA" # Directory where model outputs are stored
shiftdepth="5" # IMPORTANT: FeMIP_regrid employs a linear interpolation for the vertical grid,
# therefore, it is important that for 'shiftdepth' you put the first depth that
# occurs in your model file. This is neccessary, else, the first depth in
# the processed file, after running FeMIP_regrid, will contain just NaN values.
# So for example, if the first depth of my desired vertical grid begins at 0 m,
# but my model grid starts at 5 m, you must set 'shiftdepth' to 5. FeMIP_regrid
# will shift the grid to start at 0 m and not at the depth of 'shiftdepth'.
# Create the vertical grid file
# When editing the 'mygrid' file, please only edit the 'size' and 'levels' variables
cat > mygrid << EOR
zaxistype = depth_below_sea
size = 31
units = m
levels = 0 5 15 27.5 45 65 87.5 115 147.5 182.5 220 270 340 430 535 650 775 915 1070 1245 1465 1730 2020 2340 2680 3050 3475 3950 4450 4950 5450
EOR
#############################
# END USER INPUTS #
#############################
sed -e 's/[[:blank:]]*=[[:blank:]]*/=/g' -e 's/\(=[[:blank:]]*\)\(.*\)/\1"\2"/' -e 's/\s\+/,/g' mygrid > tmp # Formatting
source tmp
depth=$levels
cat <<< "$depth" > levels
depth="${depth:0:0}$shiftdepth${depth:1}" # Replace first element of levels with shiftdepth
cat <<< "$depth" > depth
chmod 755 mygrid
rm tmp
# Move the files into the correct directory
mv levels $INDIR
mv mygrid $INDIR
mv depth $INDIR
echo "The neccessary process files have been placed in the INDIR - ${INDIR}"
echo "FeMIP_makegrid complete"