carra_obsoul_prod.ksh 5.62 KB
Newer Older
Paulo V C Medeiros's avatar
Paulo V C Medeiros committed
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
#!/bin/ksh
#SBATCH --qos=normal
#SBATCH --job-name=carra_obsoul
#SBATCH --output=/scratch/ms/no/fasg/CARRA/local_obs_wrk/obsoul_out/carra_obsoul.out
#SBATCH --error=/scratch/ms/no/fasg/CARRA/local_obs_wrk/obsoul_out/carra_obsoul.err

set -a

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

ulimit -c 0

integer datornr
integer iw

dator=ECGATE

hdir=/scratch/ms/no/fasg/CARRA/local_obs_wrk/obsoul_out
ddir=/scratch/ms/no/fasg/CARRA/local_obs_wrk
odir=/scratch/ms/no/fasg/CARRA/local_obs_wrk

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

years=2005 ; mons=05 ; days=01 ; hours=00 ; dhour=03
yeare=2005 ; mone=07 ; daye=31 ; houre=21

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

    ofile=obsoul$date

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

	for dataset in 1 2 ; do

	    case $dataset in
		1) dfile="$ddir/${YYYY_W}/Asiaq_${YYYY_W}${MM_W}.txt"
		    land=DK
		    subset=None ;;
		2) dfile="$ddir/${YYYY_W}/synop_${YYYY_W}${MM_W}${DD_W}.txt"
		    land=DK
		    subset=None ;;
		*) exit ;;
	    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

#		if (( $dataset == 1 ));then
#		    /bin/mv obsoul.txt obsoul_Asiaq_${date_w}.txt
#		elif (( $dataset == 2 ));then
#		    /bin/mv obsoul.txt obsoul_synop_${date_w}.txt
#  		fi

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