carra_obsoul_prod.ksh 6.08 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
4
5
#SBATCH --output=/scratch/ms/se/snz/carra_obsoul/obsoul_out/carra_obsoul.out
#SBATCH --error=/scratch/ms/se/snz/carra_obsoul/obsoul_out/carra_obsoul.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
22
23
24
25
26
27
28
29
30

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
#-----------------------------------------------------------------------

31
32
years=2019 ; mons=11 ; days=01 ; hours=03 ; dhour=03
yeare=2019 ; mone=11 ; daye=01 ; houre=03
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
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

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

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

    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'

#----- FI DIRECTORY AT FIRST TIME POINT IN MONTH -----------------------
	if { (( DD_W == 01 )) && (( HH_W == 00 )) } ; then

	    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)
	    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"

	else

	    YYYY_W_FI=$(echo $date_w | cut -c1-4)
	    MM_W_FI=$(echo $date_w | cut -c5-6)
	    DD_W_FI=$(echo $date_w | cut -c7-8)
	    HH_W_FI=$(echo $date_w | cut -c9-10)
	    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"

	fi
#----- FI DIRECTORY AT FIRST POINT IN MONTH ----------------------------

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

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
	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
		FI) dfile="$ddir/inputs/FI/${YYYY_W}/synopCARRA_FMI_${YYYY_W}${MM_W}.txt" ;;
		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
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
	    esac

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

		print "\n\t dfile = $dfile \t Exist"
		print $dfile $land $subset $ITO_W $WIN
		$ddir/carra_obsoul.main.x $dfile $land $subset $ITO_W $WIN
		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)"