source: flexpart.git/preprocessing/flex_extract_ecgate_V6.0/ecmwf_idc_ops_multi_ecgate @ ba05105

FPv9.3.1FPv9.3.1b_testingFPv9.3.2devfp9.3.1-20161214-nc4grib2nc4_repairrelease-10univie
Last change on this file since ba05105 was ba05105, checked in by flexpart <>, 5 years ago

add preprocessing routines flex_extract_ecgate_V6.0

  • Property mode set to 100644
File size: 21.1 KB
Line 
1#!/bin/ksh
2
3#SBATCH --workdir=/scratch/ms/spatlh00/lh0
4#SBATCH --qos=normal
5#SBATCH --job-name=flex_ecmwf_oper
6#SBATCH --output=ms_sms_output_V6.0/CTBTO_ops.out
7#SBATCH --error=ms_sms_output_V6.0/CTBTO_ops.out
8#SBATCH --mail-type=ALL
9#SBATCH --time=12:00:00
10
11
12set -x
13
14alias ecp='set noglob; $ECFS_SYS_PATH/ecp.p'
15
16export OMP_NUM_HREADS=1
17
18
19
20###########################
21
22# ADD BEGIN AND END HERE  #
23
24###########################
25
26   MSJ_START=2013110700
27   MSJ_END=2013110812
28
29
30###########################
31
32# NO CHANGES BELOW        #
33
34###########################
35
36VERSION=6.0
37JOBNAME=ecmwf_idc_ops_ecgate_V${VERSION}
38CONTROLFILE=${HOME}/flex_extract_ecgate_V${VERSION}/CONTROL_OPS_V${VERSION}
39
40WDAY=$(date +%A)
41[ ! -d $SCRATCH/ms_sms_output_V${VERSION} ] && mkdir $SCRATCH/ms_sms_output_V${VERSION}
42
43LOG_FILE=$SCRATCH/ms_sms_output_V${VERSION}/${JOBNAME}_${WDAY}
44exec 1>${LOG_FILE}
45
46[ -z "$WSHOME" ] && export WSHOME=$HOME
47
48   DAY1=$(($MSJ_START/100))
49   DAY2=$(($MSJ_END/100))
50   TDIFF=$(( (`date +%s -d $DAY2` - `date +%s -d $DAY1` )/86400 ))
51   if [[ $TDIFF -lt 0 || $TDIFF -gt 31 ]] ; then
52     echo invalid difference $TDIFF between dates $1, $2
53     echo difference must be positive and smaller than 32
54     exit
55   fi
56
57
58       MSJ=$MSJ_START
59       MSJ_YEAR=$(( ($MSJ/1000000)))
60       while [ $MSJ -le $MSJ_END ]
61       do
62
63       MSJ_MONTH=$(( ($MSJ%1000000)/10000))
64       MSJ_DAY=$(( ($MSJ%10000)/100))
65       MSJ_BASETIME=$(($MSJ%100))
66
67       if [ $MSJ_MONTH -lt 10 ] ; then
68          MSJ_MONTH='0'$MSJ_MONTH
69       fi
70       if [ $MSJ_DAY -lt 10 ] ; then
71          MSJ_DAY='0'$MSJ_DAY
72       fi
73       if [ $MSJ_BASETIME -lt 10 ] ; then
74          MSJ_BASETIME='0'$MSJ_BASETIME
75       fi
76
77       MSJ=$MSJ_YEAR$MSJ_MONTH$MSJ_DAY$MSJ_BASETIME
78
79       echo 'MSJ_ENVIRONMENT:' $MSJ
80
81       DATEREF=${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}
82
83
84# no changes below
85
86NRW=0
87
88#ksh scripts for date manipulation
89juldate2()
90   {
91    let jc=$1
92    if (( ${#jc} < 8 ))
93    then
94    print "illegal date!"
95    exit 1
96    fi
97    let y=`echo $jc | cut -c1-4`
98    let m1=`echo $jc | cut -c5`
99    let m2=`echo $jc | cut -c6`
100    m=$m1$m2
101    let d1=`echo $jc | cut -c7`
102    let d2=`echo $jc | cut -c8`
103    d=$d1$d2
104    let jd=367*y-7*(y+(m+9)/12)/4+275*m/9+d+1721014
105    let jd=jd+15-3*((y+(m-9)/7)/100+1)/4
106    print $jd
107    }
108
109civildate2()
110   {
111    let jd=$1
112    if (( jd < 1721060 ))
113    then
114       print "Julian date not in AD."
115       exit 1
116    fi
117    let k=jd+68569
118    let n=4*k/146097
119    let k=k-\(146097*n+3\)/4
120    let y=4000*(k+1)/1461001
121    let k=k-1461*y/4+31
122    let m=80*k/2447
123    let d=k-\(2447*m\)/80
124    let k=m/11
125    let m=m+2-12*k
126    let y=100*(n-49)+y+k
127    [ $m -le 9 ] && m=0$m
128    [ $d -le 9 ] && d=0$d
129    print $y$m$d
130    }
131
132date2m1()
133    {
134    let ymd=$1
135    let j1=`juldate2 $ymd`
136    let j0=j1-1
137    civildate2 $j0
138    }
139
140date2p1()
141    {
142    let ymd=$1
143    let j1=`juldate2 $ymd`
144    let j0=j1+1
145    civildate2 $j0
146    }
147
148date2m14()
149    {
150    let ymd=$1
151    let j1=`juldate2 $ymd`
152    let j0=j1-14
153    civildate2 $j0
154    }
155
156marsinst()
157{
158MTYPE="${1}"
159MDAY="${2}"
160MTIME="${3}"
161MSTEP="${4}"
162MPAR="${5}"
163MFN=$6
164MLTY=$7
165MGRID="${8}"
166MLEV="${9}"
167
168#if [[ ${MPAR} == 'LNSP' ]] ; then
169#  MLEV=1
170#else
171#  if [[ ${MLTY} == 'SFC' ]] ; then
172#    MLEV=OFF
173#  else
174#    MLEV=${M_LEVELIST}
175#  fi
176#fi
177
178RED=0
179#if [[ ${MTYPE} != 'AN' ]] ; then
180  MPAR2=`echo ${MPAR} | sed s,160/,,`
181  MPAR2=`echo ${MPAR2} | sed s,27/,,`
182  MPAR2=`echo ${MPAR2} | sed s,28/,,`
183  MPAR2=`echo ${MPAR2} | sed s,173/,,`
184  if [[ ${MPAR2} != ${MPAR} ]] ; then
185    MPAR=${MPAR2}
186    RED=1
187  fi
188#fi
189
190MAREA=${M_AREA}
191if [[ ${10} == 'GAUSSIAN=REDUCED,' ]] ; then
192  MAREA=G
193fi
194
195if [[ -f ${MFN} ]] ; then
196  rm ${MFN}
197fi
198
199cat <<EOF >> marsjob
200RETRIEVE,
201TYPE=${MTYPE},
202CLASS=${M_CLASS},NUMBER=${M_NUMBER},
203EXPVER=${M_EXPVER},STREAM=${M_STREAM},
204PARAM=${MPAR},
205RESOL=${M_RESOL},
206AREA=${MAREA},
207GRID=${MGRID},
208LEVTYPE=${MLTY},
209LEVELIST=${MLEV},
210ACCURACY=${M_ACCURACY},
211DATE=${MDAY},
212TIME=${MTIME},
213STEP=${MSTEP},${10}
214TARGET="${MFN}"
215EOF
216
217if [[ ! -f 'OROLSM' && $RED -eq 1 ]] ; then
218
219cat <<EOF >> marsjob
220RETRIEVE,TYPE=AN,TIME=0,STEP=0,CLASS=OD,
221  PARAM=160/27/28/173,
222  TARGET="OROLSM"
223EOF
224fi
225
226}
227
228marsflux()
229{
230MTYPE="${1}"
231MSTEP="${2}"
232
233#if [[ ! -f "surf_${M_STEP}_ub" ]] ; then
234cat <<EOF >>mars_flux
235RETRIEVE,
236TYPE=${MTYPE},
237CLASS=${M_CLASS},NUMBER=${M_NUMBER},
238EXPVER=${M_EXPVER},STREAM=${M_STREAM},
239PARAM=LSP/CP/SSHF/EWSS/NSSS/SSR,
240AREA=${M_AREA},
241GRID=${D_GRID},
242LEVTYPE=SFC,
243LEVELIST=OFF,
244ACCURACY=${M_ACCURACY}, REPRES=GG,
245DATE=${DAY1M1}/TO/${DAY2P1},
246TIME=00/12,
247AC=N,
248STEP=${MSTEP},
249TARGET="surf_${MSTEP}_ub"
250EOF
251
252if [[ $MSJ_BASETIME == 00 ]] ; then
253  DAY2P2=`date2p1 ${DAY2P1}`
254  cat <<EOF >>mars_flux
255RETRIEVE,
256DATE=${DAY2P2},
257TIME=00,
258TARGET="surf_${MSTEP}_ub"
259EOF
260fi
261#fi
262}
263
264
265myerror()
266  {
267   
268    echo $1
269    echo $2
270    echo $3
271    echo ABORT!
272
273    for MUSER in $MAILFAIL
274    do
275      mailx -s ERROR:${JOBNAME} ${MUSER} <${LOG_FILE}
276    done
277
278    exit 1
279  }
280
281#
282# MAIN SCRIPT CONTINUES HERE
283#
284#read CONTROL file, process specifications
285while read NAME PARA
286do
287
288if [[ $NAME == 'M_TYPE' || $NAME == 'M_TIME' || $NAME == 'M_STEP' ]] ; then
289  eval "set -A $NAME $PARA"
290else
291  eval "export $NAME='$PARA'"
292fi
293echo `echo $NAME`=$PARA
294
295done <${CONTROLFILE}
296
297
298#defaults
299[ -z "$M_EXPVER" ] && M_EXPVER=1
300[ -z "$M_CLASS" ] && M_CLASS=OD
301[ -z "$M_STREAM" ] && M_STREAM=OPER
302[ -z "$M_NUMBER" ] && M_NUMBER=OFF
303[ -z "$M_TYPE" ] && set -A M_TYPE AN FC FC FC FC FC AN FC FC FC FC FC AN FC FC FC FC FC AN FC FC FC FC FC
304[ -z "$M_TIME" ] && set -A M_TIME 00 00 00 00 00 00 06 00 00 00 00 00 12 12 12 12 12 12 18 12 12 12 12 12
305[ -z "$M_STEP" ] && set -A M_STEP 00 01 02 03 04 05 00 07 08 09 10 11 00 01 02 03 04 05 00 07 08 09 10 11
306[ -z "$DTIME" ] && DTIME=6
307[ -z "$M_GRID" ] && M_GRID=1000
308[ -z "$M_LOWER" ] && M_LOWER=-90000
309[ -z "$M_LEFT" ] && M_LEFT=-179000
310[ -z "$M_UPPER" ] && M_UPPER=90000
311[ -z "$M_RIGHT" ] && M_RIGHT=180000
312[ -z "$M_LEVEL" ] && M_LEVEL=91
313[ -z "$M_LEVELIST" ] && M_LEVELIST=1/TO/$M_LEVEL
314[ -z "$M_ADDPAR" ] && M_ADDPAR=''
315[ -z "$M_RESOL" ] &&  M_RESOL=799
316[ -z "$M_GAUSS" ] &&  M_GAUSS=0
317[ -z "$M_SMOOTH" ] &&  M_SMOOTH=0
318[ -z "$M_OMEGA" ] &&  M_OMEGA=0
319[ -z "$M_OMEGADIFF" ] &&  M_OMEGADIFF=0
320[ -z "$M_ETA" ] &&  M_ETA=0
321[ -z "$M_ETADIFF" ] &&  M_ETADIFF=0
322[ -z "$M_ETAPAR" ] &&  M_ETAPAR=77
323[ -z "$M_DPDETA" ] &&  M_DPDETA=1
324[ -z "$M_ACCURACY" ] &&  M_ACCURACY=24
325[ -z "$EXEDIR" ] && EXEDIR=.
326[ -z "$SOURCECODE" ] && SOURCECODE=ecgate:flex_extract_ecgate
327[ -z "$GATEWAY" ] && GATEWAY=''
328[ -z "$DESTINATION" ] && DESTINATION=''
329[ -z "$PREFIX" ] && PREFIX=EN
330[ -z "$COMPRESSION" ] && COMPRESSION=grid_simple
331[ -z "$ECTRANS" ] && ECTRANS=0
332[ -z "$ECSTORAGE" ] && ECSTORAGE=1
333[ -z "$ECFSDIR" ] && ECFSDIR=ectmp:
334[ -z "$MAILOPS" ] && MAILOPS=${USER}
335[ -z "$MAILFAIL" ] && MAILFAIL=${USER}
336
337
338export MARS_MULTITARGET_STRICT_FORMAT=1
339
340if [ $M_GAUSS -eq 1 ] ; then 
341    export SCRATCHDIR=${SCRATCH}/ctbto_run_ecgate-${DTIME}hrs-G_V${VERSION}
342    mkdir $SCRATCHDIR >/dev/null
343else
344  export SCRATCHDIR=${SCRATCH}/ctbto_run_ecgate-${DTIME}hrs-L_V${VERSION}
345    mkdir $SCRATCHDIR >/dev/null
346fi
347
348#
349# cleanup
350#
351#\rm -f $SCRATCHDIR/*
352\rm -f $SCRATCHDIR/fort*
353
354[ ! -d $SCRATCHDIR ] && mkdir $SCRATCHDIR
355cd $SCRATCHDIR
356
357
358DAY1=${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}
359if [ $MSJ_BASETIME -eq 00 ] ; then
360  DAY2=DAY1
361else
362  DAY2=`date2p1 ${DAY1}`
363fi
364
365#additional dates for flux retrievals (polynomial interpolation)
366DAY1M1=`date2m1 ${DAY1}`
367DAY2P1=`date2m1 ${DAY2}`
368
369#julian dates for time loops
370JULDAY1=`juldate2 ${DAY1}`
371JULDAY2=`juldate2 ${DAY1}`
372
373
374#echo 'field date :' $M_DATE_S, $M_TIME_S
375#echo 'flux dates :' $FLXDT1, $FLXT1, $FLXDT2, $FLXT2
376
377#take care of nameing convention
378#M_DATEX=`echo ${M_DATE_S} | cut -c3-8`
379#DATEREFX=`echo ${DATEREF} | cut -c3-8`
380
381# determine number of gridpoints and whether grid is cyclic
382ZYK=`expr \( $M_RIGHT + 360000 \) % 360000 - \( $M_LEFT + 360000 \) % 360000 + $M_GRID`
383
384if [ $M_RIGHT -le $M_LEFT ] ; then
385  if [ $M_RIGHT -le 0 ] ; then
386    M_RIGHT=$(($M_RIGHT+360000))
387  else
388    M_LEFT=$(($M_LEFT-360000))
389  fi
390fi
391
392if [[ $ZYK -ne 0 ]] ; then
393  MAXB=$((($M_UPPER-($M_LOWER))/$M_GRID+1))
394  MAXL=$((($M_RIGHT-($M_LEFT))/$M_GRID+1))
395
396  if [[ $((($M_RIGHT-($M_LEFT))%$M_GRID)) -ne 0 || $((($M_UPPER-($M_LOWER))%$M_GRID)) -ne 0 ]] ; then
397    myerror "ERROR: LAT/LON RANGE MUST BE INTEGER MULTIPLES OF GRID SIZE"     "URLO: $M_UPPER  $M_RIGHT $M_LOWER  $M_LEFT GRID: $M_GRID"     "GRID ASSUMED NON-CYCLIC"
398    exit 1
399  fi
400else
401  MAXL=$((($M_RIGHT-($M_LEFT))/$M_GRID+1))
402  MAXB=$((($M_UPPER-($M_LOWER))/$M_GRID+1))
403  if [[ $((($M_RIGHT-($M_LEFT))%$M_GRID)) -ne 0 || $((($M_UPPER-($M_LOWER))%$M_GRID)) -ne 0 ]] ; then
404    myerror "ERROR: LAT/LON RANGE MUST BE INTEGER MULTIPLES OF GRID SIZE"           "URLO: $M_UPPER  $M_RIGHT $M_LOWER  $M_LEFT GRID: $M_GRID"           "GRID ASSUMED CYCLIC"
405    exit 1
406  fi
407fi
408
409if [ $((180000/$M_GRID-$M_RESOL)) -lt 0 ] ; then
410
411   if [ ${M_SMOOTH} -eq 0 ] ; then
412    echo "WARNING: OUTPUT GRID SPACING OF $((${M_GRID}/1000)).$((${M_GRID}%1000)) DEGREE IS TOO COARSE FOR GIVEN SPECTRAL RESOLUTION ${M_RESOL} " "USE M_SMOOTH FOR SMOOTHING OR FINER OUTPUT GRID"
413#    exit 1
414   else
415    if [ $((180000/$M_GRID-$M_SMOOTH)) -lt 0 ] ; then
416      myerror "ERROR: OUTPUT GRID SPACING OF $((${M_GRID}/1000)).$((${M_GRID}%1000)) DEGREE IS TOO COARSE FOR GIVEN SMOOTHED SPECTRAL RESOLUTION ${M_SMOOTH} " 
417    fi
418   fi
419
420fi
421
422
423# convert lat/lon to MARS format (degrees)
424if [[ $M_LEFT -lt 0 ]] ; then
425  LLLO=$(($M_LEFT / 1000)).$((($M_LEFT)*(-1) % 1000))
426else
427  LLLO=$(($M_LEFT / 1000)).$(($M_LEFT % 1000))
428fi
429if [[ $M_LOWER -lt 0 ]] ; then
430  LLLA=$(($M_LOWER / 1000)).$(($M_LOWER*(-1) % 1000))
431else
432  LLLA=$(($M_LOWER / 1000)).$((($M_LOWER) % 1000))
433fi
434if [[ $M_RIGHT -lt 0 ]] ; then
435  URLO=$(($M_RIGHT / 1000)).$((($M_RIGHT)*(-1) % 1000))
436else
437  URLO=$(($M_RIGHT / 1000)).$(($M_RIGHT % 1000))
438fi
439if [[ $M_UPPER -lt 0 ]] ; then
440  URLA=$(($M_UPPER / 1000)).$((($M_UPPER)*(-1) % 1000))
441else
442  URLA=$(($M_UPPER / 1000)).$(($M_UPPER % 1000))
443fi
444
445M_AREA=${URLA}/${LLLO}/${LLLA}/${URLO}
446
447if [ $M_GAUSS -eq 1 ] ; then
448# Gaussian grid detected
449  D_GRID=$(($M_GRID / 1000)).$(($M_GRID % 1000))
450  G_GRID=OFF
451  QG_GRID=OFF
452  if [ $M_RESOL -le 799 ] ; then
453    QG_GRID=$((($M_RESOL+1)/2))
454  fi
455  D_GRID=${D_GRID}/${D_GRID}
456 
457else
458  D_GRID=$(($M_GRID / 1000)).$(($M_GRID % 1000))
459  G_GRID=$(($M_GRID / 1000)).$(($M_GRID % 1000))
460  G_GRID=${G_GRID}/${G_GRID}
461  D_GRID=${D_GRID}/${D_GRID}
462fi
463
464G_LEVELIST=1/to/${M_LEVEL}
465
466
467#namelist
468cat <<EOF >fort.4
469&NAMGEN
470   MAXL=${MAXL}, MAXB=${MAXB},
471   MLEVEL=${M_LEVEL}, MLEVELIST="${M_LEVELIST}",
472   MNAUF=${M_RESOL},METAPAR=${M_ETAPAR},
473   RLO0=${LLLO}, RLO1=${URLO}, RLA0=${LLLA}, RLA1=${URLA},
474   MOMEGA=${M_OMEGA},MOMEGADIFF=${M_OMEGADIFF},MGAUSS=${M_GAUSS},
475   MSMOOTH=${M_SMOOTH},META=${M_ETA},METADIFF=${M_ETADIFF},
476   MDPDETA=${M_DPDETA}
477/
478&NAMFX2
479   NX=${MAXL}, NY=${MAXB},
480   MAXTIME=400,JPOLY=4,
481   JHRF=${DTIME},
482   RLO0=${LLLO}, RLA0=${LLLA}, DX=${D_GRID}, DY=${D_GRID}
483/
484EOF
485
486
487cp ${SOURCECODE}/source.tar .
488tar -xvf source.tar
489if [[ $OS_VERSION == aix ]] ; then
490  make -f Makefile.IBM FLXACC2 CONVERT2 CHECK
491else
492  make -f Makefile.ecgb FLXACC2 CONVERT2 CHECK
493fi
494
495if [ $? -ne 0 ]; then
496    ls
497    echo 'ERROR: FLXACC2 and CONVERT2 could not be compiled:' ${INFILE}
498    echo ABORT!
499    for MUSER in $MAILFAIL
500    do
501      mailx -s ERROR:${JOBNAME} ${MUSER} <${LOG_FILE}
502    done
503    exit 1
504else
505  echo 'compile worked'
506fi
507
508
509#
510#MARS requests (field)
511#
512imax=6
513set -A PARLIST  U/V  T    Q  LNSP SD/MSL/TCC/10U/10V/2T/2D 129/172/160${M_ADDPAR}
514set -A PARNAME  131/132 130 133 152 SURF OROLSM
515set -A REPR     SH    SH   GG   SH   GG   GG
516set -A UNIT     10    11   17   12   14   20
517set -A LTY      ML    ML   ML   ML   SFC  SFC
518set -A GRID  ${G_GRID} ${D_GRID} ${D_GRID} OFF ${D_GRID} ${D_GRID}
519set -A LEVELIST ${M_LEVELIST} ${M_LEVELIST} ${M_LEVELIST} 1 1 1
520
521set -A FIELD    00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 00
522
523
524if [[ $M_OMEGA -eq 1 || $M_OMEGADIFF -eq 1 ]] ; then
525  M_OMEGA=1
526  PARLIST[imax]=W
527  PARNAME[imax]=135
528  REPR[imax]=SH
529  UNIT[imax]=19
530  LTY[imax]=ML
531  GRID[imax]=${D_GRID}
532  LEVELIST[imax]=${M_LEVELIST}
533  imax=$(($imax+1))
534fi
535if [[ $M_ETA -eq 1 || $M_ETADIFF -eq 1 ]] ; then
536  M_ETA=1
537  PARLIST[imax]=77
538  PARNAME[imax]=77
539  REPR[imax]=SH
540  UNIT[imax]=21
541  LTY[imax]=ML
542  GRID[imax]=${D_GRID}
543  LEVELIST[imax]=${M_LEVELIST}
544  imax=$(($imax+1))
545fi
546
547if [[ $M_GAUSS -eq 2 ]] ; then
548  PARLIST[imax]=VO
549  PARNAME[imax]=138
550  REPR[imax]=SH
551  UNIT[imax]=30
552  LTY[imax]=ML
553  GRID[imax]=${G_GRID}
554  LEVELIST[imax]=${G_LEVELIST}
555  imax=$(($imax+1))
556fi
557if [[ $M_ETA -eq 0 || $M_GAUSS -eq 1 || $M_ETADIFF -eq 1 ]] ; then
558  PARLIST[imax]=D
559  PARNAME[imax]=155
560  REPR[imax]=SH
561  UNIT[imax]=13
562  LTY[imax]=ML
563  GRID[imax]=${G_GRID}
564  LEVELIST[imax]=${G_LEVELIST}
565  LEVELIST[1]=${G_LEVELIST} # U/V needed on all levels for calculating ETA
566  imax=$(($imax+1))
567fi
568
569jmax=$(( ${#M_TYPE[*]}))
570
571# M_TIME needs leading zeros while M_STEP must have leading zeros
572# to be consistent with MARS file naming convention
573# The following loop ensures this
574j=0
575while [[ $j -lt $jmax ]] ; do
576  if [[ ${M_TIME[$j]} -lt 10 ]] ; then
577    M_TIME[$j]=0$((${M_TIME[$j]}))
578  fi
579  if [[ ${M_STEP[$j]} -lt 10 ]] ; then
580    M_STEP[$j]=$((${M_STEP[$j]}))
581  fi
582
583  j=$(($j+1))
584done
585
586echo ${M_TIME[*]}
587echo ${M_STEP[*]}
588
589
590rm mars_flux 2>/dev/null
591j=0
592while [[ $j -lt 24 ]] ; do 
593  marsflux ${M_TYPE[2]} ${FIELD[$j]} 
594  j=$(($j+$DTIME))
595done
596mars mars_flux
597[ $? -ne 0 ] && myerror "Job stopped because of failing MARS request"
598
599
600#
601# FLXACC job
602#
603
604
605${EXEDIR}/FLXACC2
606if [ -f OROLSM ] ; then
607  rm OROLSM
608
609
610fi
611
612#
613# CONVERT job
614#
615
616#loop over DATE and TIME for CONVERT/CHECK/ECtrans job
617
618iter=0
619IJULDAY=${JULDAY1}
620while [ $IJULDAY -le $JULDAY2 ];
621do
622
623MDATE=`civildate2 ${IJULDAY}`
624if [ $MSJ_BASETIME -eq 00 ] ; then
625  MDATE=`date2m1 ${MDATE}`
626fi
627
628MDATEX=`echo ${MDATE} | cut -c3-8`
629
630
631i=0
632rm marsjob 2>/dev/null
633
634#humidity on reduced Gaussian grid for initialization
635#of spectral transformations
636if [ ${M_GAUSS} -eq 1 ] ; then
637  NGRID=$(( ( ${M_RESOL} + 1 ) / 2 ))
638
639  marsinst ${M_TYPE[0]} ${DAY1} 00 00 Q fort.18 ML ${QG_GRID} 1 'GAUSSIAN=REDUCED,'
640
641set -e
642mars marsjob
643[ $? -ne 0 ] && myerror "Job stopped because of failing MARS request"
644rm marsjob
645
646fi
647
648set -e
649
650if [ $MSJ_BASETIME -eq 12 ] ; then
651  j=$(($DTIME))
652  jmax=$(($DTIME+12))
653else
654  j=$(($DTIME+12))
655fi
656if [ $iter -eq 1 ] ; then
657  j=0
658  jmax=1
659fi
660set -A TYPEKEY ${M_TYPE[$j]}
661kmax=0
662while [[ $j -lt $jmax ]] ; do
663  if [[ ${M_TYPE[j]} != ${TYPEKEY[0]} ]] ; then
664    if [[ $kmax == 1 ]] ; then
665      if [[ ${M_TYPE[j]} != ${TYPEKEY[1]} ]] ; then 
666        set -A TYPEKEY ${TYPEKEY[0]} ${TYPEKEY[1]} ${M_TYPE[j]}
667        kmax=2
668      fi
669    else
670      if [[ $kmax == 0 ]] ; then   
671        set -A TYPEKEY ${TYPEKEY[0]} ${M_TYPE[j]}
672        kmax=1
673      else
674        if [[ $kmax == 2 && ${M_TYPE[j]} != ${TYPEKEY[1]}  ]] ; then   
675          if [[ $kmax == 2 && ${M_TYPE[j]} != ${TYPEKEY[2]}  ]] ; then   
676
677            echo ${TYPEKEY[0]} ${TYPEKEY[1]}  ${TYPEKEY[2]} ${M_TYPE[j]}
678            myerror 'More than three different MARS TYPES not supported'
679       
680            exit 1
681          fi
682        fi
683      fi
684    fi
685  fi
686  j=$(($j+$DTIME))
687done
688 
689set -A GRIDKEY $D_GRID
690mmax=1
691i=0
692while [[ $i -lt $imax ]] ; do
693  if [[ ${GRID[$i]} == 'OFF' && ${PARLIST[$i]} != LNSP ]] ; then
694    set -A GRIDKEY $D_GRID OFF
695    mmax=2
696  fi 
697  i=$(($i+1))
698done
699
700k=0
701kmax=$(($kmax+1))
702while [[ $k -lt $kmax ]] ; do
703MMTIME=''
704MMSTEP=''
705TSUFF=''
706SSUFF=''
707j=0
708if [ $MSJ_BASETIME -eq 12 ] ; then
709  j=$(($DTIME))
710  jmax=$(($DTIME+12))
711else
712  j=$(($DTIME+12))
713fi
714if [ $iter -eq 1 ] ; then
715  j=0
716  jmax=1
717fi
718while [[ $j -lt $jmax ]] ; do
719  if [[ ${M_TYPE[$j]} == ${TYPEKEY[$k]} ]] ; then
720    if [[ `echo $MMTIME | grep ${M_TIME[$j]}` == '' ]] ; then
721      MMTIME=${MMTIME}$TSUFF${M_TIME[$j]}
722      TSUFF='/'
723    fi
724    if [[ `echo $MMSTEP | grep ${M_STEP[$j]}` == '' ]] ; then
725      MMSTEP=${MMSTEP}$SSUFF${M_STEP[$j]}
726      SSUFF='/'
727    fi
728  fi
729j=$(($j+$DTIME))
730done
731
732m=0
733while [[ $m -lt $mmax ]] ; do
734MMPAR=''
735PSUFF=''
736i=0
737while [[ $i -lt $imax ]] ; do
738  if [[ ${LTY[$i]} == ML && ${GRID[$i]} == ${GRIDKEY[m]} && ${PARLIST[$i]} != LNSP ]] ; then
739    if [[ `echo $MMPAR | grep ${PARLIST[$i]}` == '' ]] ; then
740      MMPAR=${MMPAR}$PSUFF${PARLIST[$i]}
741      PSUFF='/'
742    fi
743  fi
744i=$(($i+1))
745done
746
747  marsinst ${TYPEKEY[$k]} ${MDATE} ${MMTIME} ${MMSTEP} $MMPAR "[param].[date].[time].[step]" ML ${GRIDKEY[$m]} ${LEVELIST[$m]}
748  mars marsjob
749  [ $? -ne 0 ] && myerror "Job stopped because of failing MARS request"
750  rm marsjob
751
752m=$(($m+1))
753done
754# LNSP treated separately since it exists only on 1 level
755  marsinst ${TYPEKEY[$k]} ${MDATE} ${MMTIME} ${MMSTEP} LNSP "[param].[date].[time].[step]" ML OFF 1
756  mars marsjob
757  [ $? -ne 0 ] && myerror "Job stopped because of failing MARS request"
758  rm marsjob
759
760# For some data classes, MARS adds GRIB table number to parameter number,
761# e.g. for Temperature it is 130.128 instead of just 130
762#
763  set +e
764  TNR=`ls 131*${MDATE}.${M_TIME[00]}00.${M_STEP[00]} | awk -F . '{print $2}' - | grep -v ${MDATE}`.
765  set -e
766  if [[ $TNR != '.' ]] ; then
767    TNR=.$TNR
768  fi
769
770# SURF treated separately since it exists only on 1 level
771  marsinst ${TYPEKEY[$k]} ${MDATE} ${MMTIME} ${MMSTEP} ${PARLIST[4]} "SURF${TNR}[date].[time].[step]" SFC $D_GRID OFF
772  mars marsjob
773  [ $? -ne 0 ] && myerror "Job stopped because of failing MARS request"
774  rm marsjob
775# OROLSM treated separately since it exists only on 1 level
776  marsinst ${TYPEKEY[$k]} ${MDATE} ${MMTIME} ${MMSTEP} ${PARLIST[5]} "OROLSM${TNR}[date].[time].[step]" SFC $D_GRID OFF
777  mars marsjob
778  [ $? -ne 0 ] &&  myerror "Job stopped because of failing MARS request"
779#  if [ -f OROLSM ] ; then
780#    for oro in `ls
781#    cat OROLSM >> OROLSM${TNR}${MDATE}.${MMTIME}00.${MMSTEP}
782#    rm OROLSM
783#    echo 'found'
784#    exit 0
785#  fi
786  rm marsjob
787
788k=$(($k+1))
789done
790
791
792
793
794j=0
795if [ $MSJ_BASETIME -eq 12 ] ; then
796  j=$(($DTIME))
797  jmax=$(($DTIME+12))
798else
799  j=$(($DTIME+12))
800fi
801if [ $iter -eq 1 ] ; then
802  j=0
803  jmax=1
804fi
805while [[ $j -lt $jmax ]] ; do
806
807
808TIME=${FIELD[$j]}
809XTIME=${TIME}00
810
811set +e
812i=0
813while [[ $i -lt $imax ]] ; do 
814  \rm fort.${UNIT[$i]} 2>/dev/null
815  if [[ ${PARLIST[$i]} == U/V ]] ; then
816    cat 131${TNR}${MDATE}.${M_TIME[$j]}00.${M_STEP[$j]} 132${TNR}${MDATE}.${M_TIME[$j]}00.${M_STEP[$j]} > fort.${UNIT[$i]}
817    rm  131${TNR}${MDATE}.${M_TIME[$j]}00.${M_STEP[$j]} 132${TNR}${MDATE}.${M_TIME[$j]}00.${M_STEP[$j]}
818  else
819    mv  ${PARNAME[$i]}${TNR}${MDATE}.${M_TIME[$j]}00.${M_STEP[$j]}  fort.${UNIT[$i]}
820  fi
821  i=$(($i+1))
822done
823
824# flux data need special GRIB conversion
825#if [ ${M_FORMAT} == GRIB2 ] ; then
826#  grib_set -w shortName!=lsp,shortName!=cp,shortName!=ewss,shortName!=nsss  -s edition=2,productDefinitionTemplateNumber=8 flux${MDATE}${TIME} flux${MDATE}${TIME}.grib2
827#
828#else
829# mv flux${MDATE}${TIME} flux${MDATE}${TIME}.grib2
830#fi
831
832${EXEDIR}/CONVERT2
833
834if [ $TIME -eq 00 ]; then
835  MDATE=`date2p1 ${MDATE}`
836  MDATEX=`echo ${MDATE} | cut -c 3-8`
837fi
838 
839INFILE=${PREFIX}${MDATEX}${TIME}
840
841if [ -s fort.15 ]; then
842    cp fort.15                   ${INFILE}
843    cat fort.14              >>  ${INFILE}
844    cat flux${MDATE}${TIME}  >>  ${INFILE}
845    cat OROLSM   >>  ${INFILE}
846    cat fort.20  >>  ${INFILE}
847
848#
849# Convert to GRIB2 if needed
850#
851#  to enable additional compression try
852#  set packingType="grid_jpeg";
853#  this is rather time consuming.
854
855if [ ${M_FORMAT} == GRIB2 ] ; then
856 grib_set -s edition=2,productDefinitionTemplateNumber=8 $INFILE ${INFILE}_2
857 mv ${INFILE}_2 ${INFILE}
858 
859  if [ ${COMPRESSION} != grid_simple ] ; then
860
861cat >rule.filter<<EOF
862set packingType="${COMPRESSION}";
863write "[file]_2";
864EOF
865    grib_filter rule.filter ${INFILE}
866    mv ${INFILE}_2 ${INFILE}
867  fi
868fi
869ls -l ${INFILE}
870
871else 
872    echo ERROR: ENfile ${INFILE} missing!
873    echo ABORT!
874    for MUSER in $MAILFAIL
875    do
876      mailx -s ERROR:${JOBNAME} ${MUSER} <${LOG_FILE}
877    done
878    exit 1
879fi
880
881#check ENxxx file & ECtrans to local gateway
882
883
884\rm fort.15 2>/dev/null
885ln -s ${INFILE} fort.15
886
887[ -s CHECK.SUCCESS ] && rm CHECK.SUCCESS
888
889${EXEDIR}/CHECK
890
891#check fields
892if [ -s CHECK.SUCCESS ]; then
893    SUCCESS=1
894else
895    echo 'ERROR: check on ENfile failed:' ${INFILE}
896    echo ABORT!
897    for MUSER in $MAILFAIL
898    do
899      mailx -s ERROR:${JOBNAME} ${MUSER} <${LOG_FILE}
900    done
901    exit 1
902fi
903
904
905
906#ECtrans
907if [ $SUCCESS -eq 1 -a $ECTRANS -eq 1 ] ; then
908  ectrans -overwrite -gateway ${GATEWAY} -remote ${DESTINATION} -source $INFILE
909fi
910
911#ECFS
912if [ $SUCCESS -eq 1 -a $ECSTORAGE -eq 1 ] ; then
913 ecp -o $INFILE $ECFSDIR
914fi
915
916rm ${INFILE}_2 ${INFILE} fort.15  flux${MDATE}${TIME}*
917
918j=$(($j+$DTIME))
919
920#done TIME
921done
922
923(( IJULDAY = IJULDAY + 1 ))
924(( iter = iter + 1 ))
925
926#done JULDAY
927done
928
929#any warnings ?
930[ $NRW -gt 0 ] && echo There were $NRW warnings !
931
932#mail logfile (list MAILOPS)
933for MUSER in $MAILOPS
934do
935
936mailx -s ${JOBNAME} ${MUSER} <${LOG_FILE}
937done
938
939#
940# cleanup
941#
942cd ${SCRATCH}
943echo $SCRATCHDIR not removed!
944#\rm -fR $SCRATCHDIR
945
946
947# go to next date 12 hours later
948
949       if [ $(($MSJ%100)) -eq 0 ] ; then
950          MSJ=$(($MSJ+12))
951       else
952          MSJ=$(($MSJ+88))
953       fi
954
955       
956          if [ $MSJ_MONTH -eq 2 ]
957          then
958          DDD=28
959          [ `expr \$YYY \% 4` -eq 0 ] && DDD=29
960          elif [ $MSJ_MONTH -eq 4 -o $MSJ_MONTH -eq 6 -o $MSJ_MONTH -eq 9 -o $MSJ_MONTH -eq 11 ]
961          then
962          DDD=30
963          else
964          DDD=31
965          fi
966
967       if [ $MSJ_DAY -gt $DDD ] ; then
968          MSJ_DAY=1
969          MSJ_MONTH=$(($MSJ_MONTH+1))
970       fi
971       if [ $MSJ_MONTH -gt 12 ] ; then
972          MSJ_MONTH=1
973          MSJ_YEAR=$(($MSJ_YEAR+1))
974       fi
975       
976
977
978# close
979done
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG