carra_obsoul_prod.ksh 6.3 KB
Newer Older
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
1
2
3
#!/bin/ksh
#SBATCH --qos=normal
#SBATCH --job-name=carra_obsoul
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
4
5
#SBATCH --output=/scratch/ms/se/snz/carra_obsoul/carra_obsoul_sbatch.out
#SBATCH --error=/scratch/ms/se/snz/carra_obsoul/carra_obsoul_sbatch.err
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
6
7
8
9
10
11
12
13
14
15
16
17

set -a

print "\n\t CARRA_OBSOUL_PROD.KSH starts at $(date)"

ulimit -c 0

integer datornr
integer iw

dator=ECGATE

18
19
20
hdir=/scratch/ms/se/snz/carra_obsoul/obsoul_out
ddir=/scratch/ms/se/snz/carra_obsoul
odir=/scratch/ms/se/snz/carra_obsoul
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
21

Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
22
[[ -d $hdir ]] || mkdir -p $hdir
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
23
24
25
26
27
28
29
30
31
cd $hdir
print "\n\t Working directory on $dator is   \t $(pwd)"
print "\t Input  data is stored in directory \t $ddir"
print "\t Output data is stored in directory \t $odir"

#-----------------------------------------------------------------------
#  Specify Times of Initial Conditions
#-----------------------------------------------------------------------

Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
32
33
34
#years=2018 ; mons=01 ; days=01 ; hours=00 ; dhour=03
years=2019 ; mons=09 ; days=01 ; hours=00 ; dhour=03
yeare=2020 ; mone=05 ; daye=01 ; houre=21
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
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

print "\n\t years = $years \t mons = $mons \t days = $days \t hours = $hours \t dhour = $dhour"
print "\t yeare = $yeare \t mone = $mone \t daye = $daye \t houre = $houre"

SDATE=$years$mons$days$hours
EDATE=$yeare$mone$daye$houre
print "\t SDATE = $SDATE \t EDATE = $EDATE \t DHOUR = $dhour"

#-----------------------------------------------------------------------
#  CREATE DIRECTORIES IF THEY DO NOT EXIST
#-----------------------------------------------------------------------


########################################################################
#  Loop over Initial Condition Times                                 ITO
########################################################################

date=$SDATE
until (( date > EDATE )) ; do

    YYYY=$(echo $date | cut -c1-4)
    MM=$(echo $date | cut -c5-6)
    DD=$(echo $date | cut -c7-8)
    HH=$(echo $date | cut -c9-10)
    ITO=${YYYY}${MM}${DD}${HH}                 ; print "\n\n\t ITO   = $ITO"


#   Check directory
    [[ -d $hdir/$YYYY/$MM ]] || mkdir -p $hdir/$YYYY/$MM
    cd $hdir/$YYYY/$MM

66
    ofile=obsoul_$date
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
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

    sed "s/year/${YYYY}/" $ddir/OBSOULFILE_template   > OBSOULFILE_template.1
    sed "s/mon/${MM}/"          OBSOULFILE_template.1 > OBSOULFILE_template.2
    sed "s/day/${DD}/"          OBSOULFILE_template.2 > OBSOULFILE_template.3
    sed "s/hour/${HH}/"         OBSOULFILE_template.3 > OBSOULFILE

    mv OBSOULFILE $ofile

#-------------------------------------------------------------------------------
#        HOUSEKEEPING
#-------------------------------------------------------------------------------

    /bin/rm OBSOULFILE_template.1
    /bin/rm OBSOULFILE_template.2
    /bin/rm OBSOULFILE_template.3

########################################################################
#  Loop over 3 time points centered at date ITO                    ITO_W
########################################################################

    for iw in -1 0 1 ; do
	
	date_w=$(dateincr -h $date $iw)

	YYYY_W=$(echo $date_w | cut -c1-4)
	MM_W=$(echo $date_w | cut -c5-6)
	DD_W=$(echo $date_w | cut -c7-8)
	HH_W=$(echo $date_w | cut -c9-10)
	ITO_W=${YYYY_W}${MM_W}${DD_W}${HH_W}

	WIN='OFF'
	(( iw == 0 )) && WIN='CEN'

Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
100
101
102
#----- FI DIRECTORY AT FIRST TIME POINT IN MONTH FOR MONTHS BEFORE OCT 2019 -------
    YYYYMM_FI=${YYYY_W}${MM_W}
	if { (( YYYYMM_FI < 201910 ))  && (( DD_W == 01 )) && (( HH_W == 00 )) } ; then
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
103
104
105
106
107
108

	    date_w_FI=$(dateincr -h $date_w -1)
	    YYYY_W_FI=$(echo $date_w_FI | cut -c1-4)
	    MM_W_FI=$(echo $date_w_FI | cut -c5-6)
	    DD_W_FI=$(echo $date_w_FI | cut -c7-8)
	    HH_W_FI=$(echo $date_w_FI | cut -c9-10)
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
109
        print "\n\t FI data (${ITO_W}): 1st DTG in month, DTG<201910: Applying timeshift"
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
110
111
112

	else

Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
113
114
115
116
	    YYYY_W_FI=${YYYY_W}
	    MM_W_FI=${MM_W}
	    DD_W_FI=${DD_W}
	    HH_W_FI=${HH_W}
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
117
118

	fi
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
119
120
	ITO_W_FI=${YYYY_W_FI}${MM_W_FI}${DD_W_FI}${HH_W_FI}
	print "\n\t ITO_W = $ITO_W \t WIN = $WIN \t ITO_W_FI = $ITO_W_FI"
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
121
122
123
124
125
126
#----- FI DIRECTORY AT FIRST POINT IN MONTH ----------------------------

########################################################################
#  Loop over dataset                                             dataset
########################################################################

127
128
129
130
131
132
133
134
	for dataset in FI IS NO NO_CLIM SE ; do
        land=$(echo $dataset | awk -F_ '{print $1}')
        subset=$(echo $dataset | awk -F_ '{print $2}')
        if [ -z "$subset" ]; then
            subset=None
        fi

	    case $land in
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
135
		FI) dfile="$ddir/inputs/FI/${YYYY_W_FI}/synopCARRA_FMI_${YYYY_W_FI}${MM_W_FI}.txt" ;;
136
137
138
139
140
141
142
143
144
145
146
147
148
149
		IS) dfile="$ddir/inputs/IS/${YYYY_W}/cerra_iceland_${YYYY_W}_${MM_W}.txt" ;;
		SE) dfile="$ddir/inputs/SE/${YYYY_W}/cerra_Sweden_${YYYY_W}${MM_W}.txt" ;;
		NO)
            case $subset in
            None) dfile="$ddir/inputs/NO/${YYYY_W}/carra_Norway_synop_${YYYY_W}${MM_W}.txt" ;;
            CLIM) dfile="$ddir/inputs/NO/${YYYY_W}/carra_Norway_SA_RR24_${YYYY_W}${MM_W}.txt" ;;
            *)
                echo "Subset '$subset' not recognised for land '$land'"
                exit 1;;
            esac
            ;;
		*)
            echo "Dataset '$dataset': Land '$land' not recognised"
            exit 1 ;;
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
150
151
152
153
154
	    esac

	    if [[ -f $dfile && -s $dfile ]] ; then

		print "\n\t dfile = $dfile \t Exist"
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
155
156
157
158
159
160
161
162
163
164
	    case $land in
		FI)
            print $dfile $land $subset $ITO_W_FI $WIN
		    $ddir/carra_obsoul.main.x $dfile $land $subset $ITO_W_FI $WIN
            ;;
		*)
		    print $dfile $land $subset $ITO_W $WIN
		    $ddir/carra_obsoul.main.x $dfile $land $subset $ITO_W $WIN
            ;;
	    esac
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
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
		cat obsoul.txt >> $ofile
		/bin/rm obsoul.txt

	    else

		print "\n\t dfile = $dfile \t Does not exist"

	    fi

########################################################################
	done
#  END        Loop over dataset                                  dataset
########################################################################

########################################################################
    done
#  END        Loop over 3 time points centered at date ITO         ITO_W
########################################################################

########################################################################
    date=$(dateincr -h $date +$dhour)
done
#  END        Loop over Initial Condition Times                      ITO
########################################################################

print "\n\t CARRA_OBSOUL_PROD.KSH ends   at $(date)"