source: flexpart.git/preprocessing/flex_extract_ecgate_V6.0/flex_ecmwf_HAIYAN @ 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 <>, 4 years ago

add preprocessing routines flex_extract_ecgate_V6.0

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