tm5-tmm-setup 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  1. #! /bin/sh
  2. # -----------------------------------------------------
  3. # init
  4. # -----------------------------------------------------
  5. # exit on error
  6. set -e
  7. # program name and location:
  8. call="$0 $*"
  9. case $0 in
  10. /* ) script=$0 ;;
  11. * ) script="`/bin/pwd`/$0" ;;
  12. esac
  13. bindir=`/usr/bin/dirname ${script}`
  14. prog=`basename ${script}`
  15. # -----------------------------------------------------
  16. # help
  17. # -----------------------------------------------------
  18. DisplayHelp ()
  19. {
  20. ${PAGER:-less} << EOF
  21. NAME
  22. $prog - setup meteo files for TM5 run
  23. USAGE ('runtm5.py' scripting)
  24. $prog [-v] <rcfile> <ccyymmddhh1> <ccyymmddhh2> [<fcday0>]
  25. USAGE ('pycasso' scripting)
  26. $prog [-v] <rcfile>
  27. DESCRIPTION
  28. Install meteo files for all days covering the requested
  29. time interval.
  30. The horizontal and vertical grids that should be installed
  31. are read from the rcfile, as well as the type of files.
  32. Daily meteo files are installed in a buffer directory,
  33. either as link or unpacked from a monthly tarchive.
  34. ARGUMENTS
  35. -v
  36. Verbose mode; messages about progress are written.
  37. <rcfile>
  38. Text file with settings, see below.
  39. For 'runtm5.py' scripting :
  40. <ccyymmddhh1> <ccyymmddhh2>
  41. Start and end time (day and hour).
  42. <fcday0>
  43. Forecast start day (ccyymmdd).
  44. RCFILE
  45. !
  46. ! Meteo files are linked to or unpacked in a buffer directory.
  47. ! o the clean flag (T|F) such that files that have not been accessed
  48. ! for a long time are removed if a maximum buffer usage is exceeded.
  49. ! o specify a maximum size in Mb
  50. !
  51. tmm.dir : /scratch/TM5/tmm-buf
  52. tmm.dir.clean : T
  53. tmm.dir.size : 500
  54. !
  55. ! Meteo files could be setup before the actual program is started.
  56. ! First set the main switch to apply this or not.
  57. ! If to be applied, specify details for a number of sets;
  58. ! each set can be applied by a seperate flag.
  59. !
  60. tmm.setup.apply : T
  61. ! display progress ?
  62. tmm.setup.verbose : T
  63. ! file permission mode for newly created files:
  64. ! o user archive : 644
  65. ! o archive shared by group : 664
  66. tmm.setup.mode : 664
  67. ! number of sets defined below:
  68. tmm.setup.nset : 6
  69. !
  70. ! setup by TMPP produced hdf files:
  71. tmm.setup.001.apply : T
  72. tmm.setup.001.files : uvsp w spm t q cld sub surf
  73. tmm.setup.001.sources : tmpp:class=od;type=fc;levs=ml60;grid=glb3x2;tres=_21p06
  74. tmm.setup.001.search : ecfs:/nlh/TM/meteo
  75. !
  76. ! setup by TM5 produced hdf files:
  77. tmm.setup.002.apply : T
  78. tmm.setup.002.files : mfuv mfw sp t q cld sub
  79. tmm.setup.002.sources : tm5:mdir=era2003-ml60-glb3x2;tres=_fc012up2tr3
  80. tmm.setup.002.search : ecfs:/nl5/gems/meteo
  81. !
  82. ! extracted from MARS archive
  83. tmm.setup.003.apply : T
  84. tmm.setup.003.files : T/Q/W/CLWC/CIWC/CC
  85. tmm.setup.003.sources : ecmwf-mars:class=od;type=fc;levs=${LEVS};grid=N80
  86. tmm.setup.003.search :
  87. !
  88. ! extracted from MARS archive: MACC fire emissions
  89. tmm.setup.003.apply : T
  90. tmm.setup.003.files : CH4FIRE
  91. tmm.setup.003.sources : ecmwf-mars:class=rd;type=fc;levs=sfc;grid=N80;tres=_fc000up24tr1
  92. tmm.setup.003.search :
  93. !
  94. ! NCEP re-analysis data (cdc)
  95. tmm.setup.004.apply : T
  96. tmm.setup.004.files : pres.nlog vort div vair shum hgt land sfcr pres icec skt uwnd.10m vwnd.10m lhtfl shtfl ugwd vgwd prate cprat
  97. tmm.setup.004.sources : ncep-cdc:
  98. tmm.setup.004.search : /co2/data/ncep.reanalysis
  99. !
  100. ! NCEP operational data (gfs)
  101. tmm.setup.005.apply : T
  102. tmm.setup.005.files : SF SFLUXGrbF
  103. tmm.setup.005.sources : ncep-gfs:
  104. tmm.setup.005.search : /co2/data/ncep.gfs
  105. !
  106. ! Olsson surface roughness files
  107. tmm.setup.006.apply : T
  108. tmm.setup.006.files : SR
  109. tmm.setup.006.sources : olsson:mdir=OLSSON
  110. tmm.setup.006.search : ecfs:/nl5/MARS
  111. EOF
  112. exit 0
  113. }
  114. # err 'help text'
  115. err ()
  116. {
  117. echo "$1" 1>&2
  118. }
  119. # errit <exit-status>
  120. errit ()
  121. {
  122. err "$prog - ERROR - in call : ${call}"
  123. err "$prog - ERROR - use '$prog --help' for more info."
  124. exit $1
  125. }
  126. # -----------------------------------------------------
  127. # arguments
  128. # -----------------------------------------------------
  129. rcfile=''
  130. ccyymmddhh1=''
  131. ccyymmddhh2=''
  132. fcday0=''
  133. verbose=''
  134. # extract settings
  135. for arg in "$@" ; do
  136. case ${arg} in
  137. -h | --help ) DisplayHelp ;;
  138. -* ) # option arguments
  139. options="${options} ${arg}"
  140. case ${arg} in
  141. -v | --verbose ) verbose='true' ;;
  142. esac
  143. ;;
  144. * ) # non-option arguments
  145. if [ -z "${rcfile}" ]; then
  146. rcfile=${arg}
  147. elif [ -z "${ccyymmddhh1}" ]; then
  148. ccyymmddhh1=${arg}
  149. elif [ -z "${ccyymmddhh2}" ]; then
  150. ccyymmddhh2=${arg}
  151. elif [ -z "${fcday0}" ]; then
  152. fcday0=${arg}
  153. else
  154. err "$prog - ERROR - unknown argument : ${arg}"
  155. errit 1
  156. fi
  157. ;;
  158. esac
  159. done
  160. # not complete ?
  161. if [ -z "${rcfile}" ]; then
  162. err "$prog - ERROR - missing arguments"
  163. errit 1
  164. fi
  165. # full path:
  166. case ${rcfile} in
  167. /* ) rcfile=${rcfile} ;;
  168. * ) rcfile="`/bin/pwd`/${rcfile}" ;;
  169. esac
  170. # -----------------------------------------------------
  171. # settings
  172. # -----------------------------------------------------
  173. # info ...
  174. echo "$prog - start"
  175. # should meteo files be setup ?
  176. tmm_setup_apply=`${bindir}/go_readrc ${rcfile} 'tmm.setup.apply' 'F'`
  177. # if not ...
  178. if [ "${tmm_setup_apply}" != "T" ] ; then
  179. # info ...
  180. echo "$prog - flag to setup meteo files is false; return"
  181. # return without problems ...
  182. exit 0
  183. fi
  184. # time range not specified yet ?
  185. if [ -z "${ccyymmddhh1}${ccyymmddhh2}" ]; then
  186. # time range start and end in "ccyy-mm-dd hh:mn:ss' format ; use up to hours only
  187. ccyymmddhh1=`${bindir}/go_readrc $rcfile 'jobstep.timerange.start' | cut -d ':' -f 1 | tr -d '\-/ '`
  188. ccyymmddhh2=`${bindir}/go_readrc $rcfile 'jobstep.timerange.end' | cut -d ':' -f 1 | tr -d '\-/ '`
  189. fi
  190. # no forecast day specified yet ? then try to read from rcfile (pycasso scripting):
  191. if [ -z "${fcday0}" ]; then
  192. # optional forecast day in "ccyy-mm-dd" format; might be missing ..
  193. fcday0=`${bindir}/go_readrc $rcfile 'time.fc.day0' 'None'`
  194. # None specified ?
  195. if [ "${fcday0}" == "None" ]; then
  196. # set empty:
  197. fcday0=''
  198. else
  199. # convert to ccyymmdd format:
  200. fcday0=`echo ${fcday0} | tr -d '\-/'`
  201. fi
  202. fi
  203. # fcmode set in rc file (pls)
  204. fcmode_read=`${bindir}/go_readrc $rcfile 'time.fc' 'F'`
  205. tmm_dir=`${bindir}/go_readrc $rcfile 'tmm.dir'`
  206. tmm_dir_clean=`${bindir}/go_readrc $rcfile 'tmm.dir.clean'`
  207. tmm_dir_size=`${bindir}/go_readrc $rcfile 'tmm.dir.size'`
  208. verboseTF=`${bindir}/go_readrc $rcfile 'tmm.setup.verbose'`
  209. nset=`${bindir}/go_readrc $rcfile 'tmm.setup.nset'`
  210. # file creation mode:
  211. tmm_mode=`${bindir}/go_readrc $rcfile 'tmm.setup.mode' '644'`
  212. # file transfer mode:
  213. transfermode=`${bindir}/go_readrc $rcfile 'tmm.setup.transfermode' 'link -s -f'`
  214. # -----------------------------------------------------
  215. # begin
  216. # -----------------------------------------------------
  217. test "${verbose}" -o "${verboseTF}" = "T" && verbose='--verbose'
  218. test ${verbose} && echo "$prog - Start at `date`"
  219. # info
  220. if [ ${verbose} ]; then
  221. echo "$prog - "
  222. echo "$prog - time range : ${ccyymmddhh1} ${ccyymmddhh2}"
  223. echo "$prog - fc day 0 : ${fcday0}"
  224. fi
  225. # create buffer if not present yet:
  226. test ! -d ${tmm_dir} && /bin/mkdir -p ${tmm_dir}
  227. # change to buffer; store current directory:
  228. owd=`/bin/pwd`
  229. cd ${tmm_dir}
  230. echo "$prog - "
  231. echo "$prog - changed to : ${tmm_dir}"
  232. # create target directory if necessary:
  233. test ! -d ${tmm_dir} && /bin/mkdir -p ${tmm_dir}
  234. # *************************************
  235. # step 1 : pre
  236. # *************************************
  237. # initiate mars requests
  238. mars_jb='./mars.jb'
  239. /bin/rm -f ${mars_jb}
  240. # *************************************
  241. # step 2 : loop over sets
  242. # *************************************
  243. iset=0
  244. while true ; do
  245. # next set
  246. iset=`expr ${iset} + 1`
  247. # leave ?
  248. test ${iset} -gt ${nset} && break
  249. # 001, 002, etc
  250. sset=`/usr/bin/printf '%3.3i' ${iset}`
  251. # skip ?
  252. apply=`${bindir}/go_readrc $rcfile "tmm.setup.${sset}.apply"`
  253. test "${apply}" != "T" && continue
  254. # set specific variables:
  255. mfiles=`${bindir}/go_readrc $rcfile "tmm.setup.${sset}.files"`
  256. msources=`${bindir}/go_readrc $rcfile "tmm.setup.${sset}.sources"`
  257. search_locs=`${bindir}/go_readrc $rcfile "tmm.setup.${sset}.search"`
  258. # skip ?
  259. test "${apply}" != "T" && continue
  260. # info
  261. if [ ${verbose} ]; then
  262. echo "$prog - "
  263. echo "$prog - sources : ${msources}"
  264. echo "$prog - files : ${mfiles}"
  265. fi
  266. # loop over files
  267. for mfile in ${mfiles} ; do
  268. # loop over file sources
  269. for msource in ${msources} ; do
  270. # reset dates to init values;
  271. # days might be changed in order to cover selected time range
  272. # first day
  273. ccyymmdd1=`echo ${ccyymmddhh1} | /usr/bin/cut -c 1-8`
  274. ccyy1=`echo ${ccyymmddhh1} | /usr/bin/cut -c 1-4`
  275. mm1=`echo ${ccyymmddhh1} | /usr/bin/cut -c 5-6`
  276. dd1=`echo ${ccyymmddhh1} | /usr/bin/cut -c 7-8`
  277. hh1=`echo ${ccyymmddhh1} | /usr/bin/cut -c 9-10`
  278. # last day
  279. ccyymmdd2=`echo ${ccyymmddhh2} | /usr/bin/cut -c 1-8`
  280. ccyy2=`echo ${ccyymmddhh2} | /usr/bin/cut -c 1-4`
  281. mm2=`echo ${ccyymmddhh2} | /usr/bin/cut -c 5-6`
  282. dd2=`echo ${ccyymmddhh2} | /usr/bin/cut -c 7-8`
  283. hh2=`echo ${ccyymmddhh2} | /usr/bin/cut -c 9-10`
  284. # setup files given source key:
  285. case ${msource} in
  286. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  287. tmpp:* ) # TMPP hdf files
  288. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  289. # tmpp files: valid for [21,21]
  290. test ${hh1} -ge 21 && ccyymmdd1=`${bindir}/date_add ${ccyymmdd1} 1`
  291. test ${hh2} -ge 21 && ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} 1`
  292. # loop over days
  293. ccyymmdd=${ccyymmdd1}
  294. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  295. # split current day:
  296. ccyy=`echo ${ccyymmdd} | /usr/bin/cut -c 1-4`
  297. mm=`echo ${ccyymmdd} | /usr/bin/cut -c 5-6`
  298. dd=`echo ${ccyymmdd} | /usr/bin/cut -c 7-8`
  299. #
  300. # define filename etc
  301. #
  302. # class=od;type=fc;levs=ml60;grid=glb3x2;tres=_21p06
  303. # default keys:
  304. class='od'
  305. type='fc'
  306. levs='ml60'
  307. grid='glb3x2'
  308. tres='_21p06'
  309. # split in 'tm-hdf' and keys :
  310. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  311. # evaluate keys : form=tm5; mdir=od-fc-etc; tres=_21p06
  312. eval ${keys}
  313. # actual level key
  314. test "${mfile}" = "spm" && levs='ml1'
  315. test "${mfile}" = "surf" && levs='sfc'
  316. # actual grid key
  317. test "${mfile}" = "surf" && grid='glb1x1'
  318. # time resolution:
  319. test "${mfile}" = "spm" && tres='_00p06'
  320. test "${mfile}" = "surf" && tres='_21p03'
  321. # directory:
  322. mdir="${class}/${type}/${ccyy}/${mm}/${levs}/${grid}"
  323. # directory and file names:
  324. meteodir=`echo ${mdir} | /usr/bin/tr '-' '/'`
  325. meteofile="${mfile}_${ccyymmdd}${tres}.hdf"
  326. # try tar files ..
  327. tarfile="${mfile}_${ccyy}${mm}${tres}.tar"
  328. trkfile="${mfile}.tar"
  329. # expand directory:
  330. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  331. # expand day file:
  332. meteofile_full="${meteodir}/${meteofile}"
  333. meteofile_long="${meteodir_long}-${meteofile}"
  334. # expand tar file:
  335. tarfile_full="${meteodir}/${tarfile}"
  336. tarfile_long="${meteodir_long}-${tarfile}"
  337. trkfile_full="${meteodir}/${trkfile}"
  338. trkfile_long="${meteodir_long}-${trkfile}"
  339. # not found yet ...
  340. found=''
  341. #
  342. # present in buffer ?
  343. #
  344. # not found yet ?
  345. if [ -z "${found}" ]; then
  346. fname=./${meteofile_long}
  347. test ${verbose} && echo "$prog - try ${fname}"
  348. if [ -f ${fname} ]; then
  349. test ${verbose} && echo "$prog - found ..."
  350. test -w ${fname} && touch ${fname}
  351. test -O ${fname} && chmod ${tmm_mode} ${fname}
  352. found='true'
  353. fi
  354. fi # not found yet ...
  355. #
  356. # search locations
  357. #
  358. # not found yet ?
  359. if [ -z "${found}" ]; then
  360. # loop over search locations
  361. for loc in ${search_locs} ; do
  362. # *** full file
  363. fname=${loc}/${meteofile_full}
  364. test ${verbose} && echo "$prog - try ${fname} ..."
  365. if ${bindir}/gss exist ${fname} ; then
  366. # create link in buffer:
  367. test ${verbose} && echo "$prog - link ..."
  368. bname=./${meteofile_long}
  369. ${bindir}/gss ${transfermode} ${fname} ${bname}
  370. # found !
  371. test -w ${bname} && touch ${bname}
  372. test -O ${bname} && chmod ${tmm_mode} ${bname}
  373. found='true'
  374. break
  375. fi
  376. # *** long file
  377. fname=${loc}/${meteofile_long}
  378. test ${verbose} && echo "$prog - try ${fname} ..."
  379. if ${bindir}/gss exist ${fname} ; then
  380. # create link in buffer:
  381. test ${verbose} && echo "$prog - link ..."
  382. bname=./${meteofile_long}
  383. ${bindir}/gss ${transfermode} ${fname} ${bname}
  384. # found !
  385. test -w ${bname} && touch ${bname}
  386. test -O ${bname} && chmod ${tmm_mode} ${bname}
  387. found='true'
  388. break
  389. fi
  390. # *** tar file
  391. fname=${loc}/${tarfile_full}
  392. test ${verbose} && echo "$prog - try ${fname} ..."
  393. if ${bindir}/gss exist ${fname} ; then
  394. # create link in buffer:
  395. test ${verbose} && echo "$prog - link ..."
  396. ${bindir}/gss ${transfermode} ${fname} ${tarfile_long}
  397. # extract, rename:
  398. test ${verbose} && echo "$prog - unpack ..."
  399. # create temporary unpacking dir:
  400. ndir=0
  401. while /bin/true ; do
  402. ndir=`/usr/bin/expr ${ndir} + 1`
  403. tmpdir="./tmp.${ndir}"
  404. test ! -d ${tmpdir} && break
  405. done
  406. /bin/mkdir -p ${tmpdir}
  407. cd ${tmpdir}
  408. # unpack
  409. ${bindir}/gss tar-extract ../${tarfile_long}
  410. # move and rename:
  411. for mf in `/bin/ls *.hdf` ; do
  412. /bin/mv ${mf} ../${meteodir_long}-${mf}
  413. done
  414. # remove tmpdir
  415. cd ..
  416. /bin/rm -r -f ${tmpdir}
  417. # remove linked tar file:
  418. ${bindir}/gss unlink ${tarfile_long}
  419. # check ...
  420. bname=./${meteofile_long}
  421. if [ ! -f ${bname} ]; then
  422. err "$prog - ERROR - meteofile not found after unpacking tarfile:"
  423. err "$prog - ERROR - pwd : `/bin/pwd`"
  424. err "$prog - ERROR - tarfile : ${tarfile_long}"
  425. err "$prog - ERROR - meteofile : ${bname}"
  426. errit 1
  427. fi
  428. # found!
  429. test -w ./${meteofile_long} && touch ./${meteofile_long}
  430. test -O ${meteofile_long} && chmod ${tmm_mode} ${meteofile_long}
  431. for file2 in *${class}*${type}*${ccyy}*${mm}*${levs}*${grid}* ; do
  432. test -O ${file2} && chmod ${tmm_mode} ${file2}
  433. done
  434. found='true'
  435. break
  436. fi
  437. # *** Krolse tar file
  438. fname=${loc}/${trkfile_full}
  439. test ${verbose} && echo "$prog - try ${fname} ..."
  440. if ${bindir}/gss exist ${fname} ; then
  441. # create link in buffer:
  442. test ${verbose} && echo "$prog - link ..."
  443. ${bindir}/gss ${transfermode} ${fname} ${trkfile_long}
  444. # extract, rename:
  445. test ${verbose} && echo "$prog - unpack ..."
  446. # create temporary unpacking dir:
  447. ndir=0
  448. while /bin/true ; do
  449. ndir=`/usr/bin/expr ${ndir} + 1`
  450. tmpdir="./tmp.${ndir}"
  451. test ! -d ${tmpdir} && break
  452. done
  453. /bin/mkdir -p ${tmpdir}
  454. cd ${tmpdir}
  455. # unpack
  456. ${bindir}/gss tar-extract ../${trkfile_long}
  457. # move and rename:
  458. for mf in `/bin/ls *.hdf` ; do
  459. /bin/mv ${mf} ../${meteodir_long}-${mf}
  460. done
  461. # remove tmpdir
  462. cd ..
  463. /bin/rm -r -f ${tmpdir}
  464. # remove linked tar file:
  465. ${bindir}/gss unlink ${trkfile_long}
  466. # found!
  467. test -w ./${meteofile_long} && touch ./${meteofile_long}
  468. test -O ${meteofile_long} && chmod ${tmm_mode} ${meteofile_long}
  469. for file2 in *${class}*${type}*${ccyy}*${mm}*${levs}*${grid}* ; do
  470. test -O ${file2} && chmod ${tmm_mode} ${file2}
  471. done
  472. found='true'
  473. break
  474. fi
  475. done # loop over locations
  476. fi # not found yet ...
  477. # not found: error ...
  478. if [ -z "${found}" ]; then
  479. err "$prog - ERROR : do not know how to retrieve meteo file:"
  480. err "$prog - ERROR : directory : `/bin/pwd`"
  481. err "$prog - ERROR : meteofile : ${meteofile_long}"
  482. errit 1
  483. fi
  484. # next day:
  485. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  486. done # loop over days
  487. ;;
  488. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  489. tm5:* | tm5-hdf:* | tm5-nc:* ) # TM5 produced files
  490. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  491. # split in 'tm5' and keys :
  492. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  493. # evaluate keys : form=tm5; mdir=od-fc-etc; tres=_21p06
  494. # surround values with quotes to handle '<' and other strange characters
  495. for keyval in `echo ${keys} | tr ';' ' '` ; do
  496. key=`echo ${keyval} | cut -d '=' -f 1`
  497. val=`echo ${keyval} | cut -d '=' -f 2`
  498. eval "${key}='${val}'"
  499. done
  500. # file extension:
  501. case "${msource}" in
  502. tm5:* | tm5-hdf:* ) mext='hdf' ;;
  503. tm5-nc:* ) mext='nc' ;;
  504. * ) err "$prog - ERROR - could not set meteo file extension for source : ${msource}" ; errit 1 ;;
  505. esac
  506. # extend or limit day range ?
  507. case ${mfile} in
  508. # surface pressure is always interpolated in time,
  509. # thus 00:00 of next day required if end hour is after 18:00 or 21:00
  510. 'sp' )
  511. case ${tres} in
  512. '_00p06' ) test ${hh2} -gt 18 && ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} 1` ;;
  513. '_00p03' ) test ${hh2} -gt 21 && ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} 1` ;;
  514. esac
  515. ;;
  516. # if an surface fields are kept 6 hourly constant around 00/06/12/18,
  517. # next day is required for end times after 21:00
  518. 'albedo' | 'sr' | 'veg' )
  519. case ${tres} in
  520. '_00p06' ) test ${hh2} -gt 18 && ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} 1` ;;
  521. esac
  522. ;;
  523. # midnight is included in accumulated fields, so one day less if ends at 00:00 :
  524. 'cp' | 'lsp' | 'slhf' | 'sshf' | 'ssr' | 'ewss' | 'nsss' )
  525. test ${hh2} -eq 0 && ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} -1`
  526. ;;
  527. esac
  528. # loop over times (days?)
  529. ccyymmdd=${ccyymmdd1}
  530. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  531. # split current day:
  532. ccyy=`echo ${ccyymmdd} | /usr/bin/cut -c 1-4`
  533. mm=`echo ${ccyymmdd} | /usr/bin/cut -c 5-6`
  534. dd=`echo ${ccyymmdd} | /usr/bin/cut -c 7-8`
  535. # longer day parts for tar files:
  536. ccyymm=`echo ${ccyymmdd} | /usr/bin/cut -c 1-6`
  537. ccyymmd=`echo ${ccyymmdd} | /usr/bin/cut -c 1-7`
  538. d=`echo ${ccyymmdd} | /usr/bin/cut -c 8`
  539. #
  540. # define filename etc
  541. #
  542. # trap change from fg to fc data:
  543. if [ "${tres}" = "_fg006up4tr3" ] && [ ${ccyymmdd} -ge 20000912 ] ; then
  544. tres='_fc012up2tr3'
  545. fi
  546. # directory and file names:
  547. meteodir=`echo ${mdir} | /usr/bin/tr '-' '/'`
  548. meteofile="${mfile}_${ccyymmdd}${tres}.${mext}"
  549. # extension of tarfiles :
  550. tarext='tar'
  551. # try tar files ..
  552. # t_200102_00p03.tar : month file
  553. # t_200102?_00p03.tar : 10 days (?0,?1,..,?9)
  554. # t_200102?0_00p03.tar : first five days (?0,?1,?2,?3,?4)
  555. # t_200102?5_00p03.tar : last five days (?5,?6,?7,?8,?9)
  556. tarfiles="${mfile}_${ccyymm}${tres}.${tarext}"
  557. tarfiles="${tarfiles} ${mfile}_${ccyymmd}${tres}.${tarext}"
  558. if [ ${d} -lt 5 ]; then
  559. tarfiles="${tarfiles} ${mfile}_${ccyymmd}0${tres}.${tarext}"
  560. else
  561. tarfiles="${tarfiles} ${mfile}_${ccyymmd}5${tres}.${tarext}"
  562. fi
  563. # specials ...
  564. case ${mfile} in
  565. 'oro' | 'lsm' )
  566. meteofile="${mfile}.${mext}"
  567. tarfiles="${mfile}.tar"
  568. mdir_yyyy='0000'
  569. mdir_mm='00'
  570. ;;
  571. 'srols' )
  572. meteofile="${mfile}_${ccyy}${mm}.${mext}"
  573. tarfiles="${mfile}_${ccyy}${mm}.${tarext}"
  574. mdir_yyyy="${ccyy}"
  575. mdir_mm="${mm}"
  576. ;;
  577. * )
  578. mdir_yyyy="${ccyy}"
  579. mdir_mm="${mm}"
  580. ;;
  581. esac
  582. # replace keys in directory name:
  583. meteodir=`echo ${meteodir} | sed -e "s/<yyyy>/${mdir_yyyy}/"`
  584. meteodir=`echo ${meteodir} | sed -e "s/<mm>/${mdir_mm}/"`
  585. # expand directory:
  586. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  587. # expand day file:
  588. meteofile_full="${meteodir}/${meteofile}"
  589. meteofile_long="${meteodir_long}-${meteofile}"
  590. # not found yet ...
  591. found=''
  592. #
  593. # present in buffer ?
  594. #
  595. # not found yet ?
  596. if [ -z "${found}" ]; then
  597. fname=./${meteofile_long}
  598. test ${verbose} && echo "$prog - try ${fname}"
  599. if [ -f ${fname} ]; then
  600. test ${verbose} && echo "$prog - found ..."
  601. test -w ${fname} && touch ${fname}
  602. found='true'
  603. fi
  604. fi # not found yet ...
  605. #
  606. # search locations
  607. #
  608. # not found yet ?
  609. if [ -z "${found}" ]; then
  610. # loop over search locations
  611. for loc in ${search_locs} ; do
  612. # *** full file
  613. fname=${loc}/${meteofile_full}
  614. test ${verbose} && echo "$prog - try full ${fname} ..."
  615. if ${bindir}/gss exist ${fname} ; then
  616. # create link in buffer:
  617. test ${verbose} && echo "$prog - ${transfermode} ..."
  618. bname=./${meteofile_long}
  619. ${bindir}/gss ${transfermode} ${fname} ${bname}
  620. # found !
  621. test -w ${bname} && touch ${bname}
  622. found='true'
  623. break
  624. fi
  625. # *** long file
  626. fname=${loc}/${meteofile_long}
  627. test ${verbose} && echo "$prog - try long ${fname} ..."
  628. if ${bindir}/gss exist ${fname} ; then
  629. # create link in buffer:
  630. test ${verbose} && echo "$prog - ${transfermode} ..."
  631. bname=./${meteofile_long}
  632. ${bindir}/gss ${transfermode} ${fname} ${bname}
  633. # found !
  634. test -w ${bname} && touch ${bname}
  635. found='true'
  636. break
  637. fi
  638. # *** tar file
  639. # loop over possible tar files:
  640. for tarfile in ${tarfiles} ; do
  641. # expand tar file:
  642. tarfile_full="${meteodir}/${tarfile}"
  643. tarfile_long="${meteodir_long}-${tarfile}"
  644. # file in archive could have full path or long name:
  645. fnames="${loc}/${tarfile_full} ${loc}/${tarfile_long}"
  646. # loop over possible archived files:
  647. for fname in ${fnames} ; do
  648. test ${verbose} && echo "$prog - try tar ${fname} ..."
  649. if ${bindir}/gss exist ${fname} ; then
  650. # create link in buffer:
  651. test ${verbose} && echo "$prog - link ..."
  652. ${bindir}/gss ${transfermode} ${fname} ${tarfile_long}
  653. # extract; tar file contains long names:
  654. test ${verbose} && echo "$prog - unpack ..."
  655. ${bindir}/gss tar-extract ${tarfile_long}
  656. # unzip ?
  657. test -f "${meteofile_long}.gz" && gunzip -f *.gz
  658. test -f "${meteofile_long}.bz2" && bunzip2 -f *.bz2
  659. # check ...
  660. bname=./${meteofile_long}
  661. if [ ! -f ${bname} ]; then
  662. err "$prog - ERROR - meteofile not found after unpacking tarfile:"
  663. err "$prog - ERROR - pwd : `/bin/pwd`"
  664. err "$prog - ERROR - tarfile : ${tarfile_long}"
  665. err "$prog - ERROR - meteofile : ${bname}"
  666. errit 1
  667. fi
  668. # remove linked tar file:
  669. ${bindir}/gss unlink ${tarfile_long}
  670. # found!
  671. test -w ${bname} && touch ${bname}
  672. test -O ${bname} && chmod ${tmm_mode} ${bname}
  673. for file2 in *${mfile}_${ccyymm}* ; do
  674. test -O ${file2} && chmod ${tmm_mode} ${file2}
  675. done
  676. found='true'
  677. break
  678. fi
  679. # found ?
  680. test "${found}" && break
  681. done # full path or long name in archive
  682. # found ?
  683. test "${found}" && break
  684. done # loop over tar files
  685. # found ?
  686. test "${found}" && break
  687. done # loop over locations
  688. fi # not found yet ...
  689. # not found: error ...
  690. if [ -z "${found}" ]; then
  691. err "$prog - ERROR : do not know how to retrieve meteo file:"
  692. err "$prog - ERROR : directory : `/bin/pwd`"
  693. err "$prog - ERROR : meteofile : ${meteofile_long}"
  694. errit 1
  695. fi
  696. # next time
  697. case ${mfile} in
  698. # constant files
  699. 'oro' | 'lsm' )
  700. # exit time loop
  701. break
  702. ;;
  703. # month files
  704. 'srols' )
  705. # next month (don't mind about day part, is not used for this files)
  706. # WP: replaced by one day at a time because adding 31 days could bring
  707. # WP: you to exceed the enddate, and then the next month file would not
  708. # WP: be retrieved.
  709. #ccyymmdd=`${bindir}/date_add ${ccyy}${mm}01 31`
  710. ccyymmdd=`${bindir}/date_add ${ccyy}${mm}${dd} 1`
  711. ;;
  712. # day files
  713. * )
  714. # next day:
  715. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  716. ;;
  717. esac
  718. done # time loop
  719. ;;
  720. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  721. ecmwf:* )
  722. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  723. # valid for (00,24] :
  724. # o if start at 00:00, retrieve file for previous day:
  725. test ${hh1} -eq 00 && ccyymmdd1=`${bindir}/date_add ${ccyymmdd1} -1`
  726. # loop over days
  727. ccyymmdd=${ccyymmdd1}
  728. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  729. # split current day:
  730. ccyy=`echo ${ccyymmdd} | /usr/bin/cut -c 1-4`
  731. mm=`echo ${ccyymmdd} | /usr/bin/cut -c 5-6`
  732. dd=`echo ${ccyymmdd} | /usr/bin/cut -c 7-8`
  733. #
  734. # define filename etc
  735. #
  736. # split in 'grib' and keys :
  737. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  738. # evaluate keys : class=od;type=fc;levs=ml60;sh=T159
  739. class='class'
  740. type='type'
  741. levs='ml60'
  742. sh=0
  743. gg=0
  744. tres='_tres'
  745. eval ${keys}
  746. # actual type
  747. case ${mfile} in
  748. S0 ) type='an' ;;
  749. esac
  750. # set level key
  751. case ${mfile} in
  752. S1 | S0 | Z | LSM ) levs='sfc' ;;
  753. LNSP ) levs='ml1' ;;
  754. esac
  755. # actual grid
  756. case ${mfile} in
  757. Q | CLD | S1 | S0 | Z | LSM ) grid="N${gg}" ;;
  758. * ) grid="T${sh}" ;;
  759. esac
  760. # directory and file names:
  761. case ${mfile} in
  762. Z | LSM )
  763. meteodir="${class}/${type}/0000/00/${levs}/${grid}"
  764. meteofile="${mfile}.gb"
  765. ;;
  766. * )
  767. meteodir="${class}/${type}/${ccyy}/${mm}/${levs}/${grid}"
  768. meteofile="${mfile}_${ccyy}${mm}${dd}${tres}.gb"
  769. ;;
  770. esac
  771. # expand directory:
  772. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  773. # expand day file:
  774. meteofile_full="${meteodir}/${meteofile}"
  775. meteofile_long="${meteodir_long}-${meteofile}"
  776. # not found yet ...
  777. found=''
  778. #
  779. # present in buffer ?
  780. #
  781. # not found yet ?
  782. if [ -z "${found}" ]; then
  783. fname=./${meteofile_long}
  784. test ${verbose} && echo "$prog - try ${fname}"
  785. if [ -f ${fname} ]; then
  786. test ${verbose} && echo "$prog - found ..."
  787. test -w ${fname} && touch ${fname}
  788. found='true'
  789. fi
  790. fi # not found yet ...
  791. #
  792. # search locations
  793. #
  794. # not found yet ?
  795. if [ -z "${found}" ]; then
  796. # loop over search locations
  797. for loc in ${search_locs} ; do
  798. # *** full file
  799. fname=${loc}/${meteofile_full}
  800. test ${verbose} && echo "$prog - try ${fname} ..."
  801. if ${bindir}/gss exist ${fname} ; then
  802. # create link in buffer:
  803. test ${verbose} && echo "$prog - link ..."
  804. bname=./${meteofile_long}
  805. ${bindir}/gss ${transfermode} ${fname} ${bname}
  806. # found !
  807. found='true'
  808. break
  809. fi
  810. # *** long file
  811. fname=${loc}/${meteofile_long}
  812. test ${verbose} && echo "$prog - try ${fname} ..."
  813. if ${bindir}/gss exist ${fname} ; then
  814. # create link in buffer:
  815. test ${verbose} && echo "$prog - link ..."
  816. bname=./${meteofile_long}
  817. ${bindir}/gss ${transfermode} ${fname} ${bname}
  818. # found !
  819. found='true'
  820. break
  821. fi
  822. done # loop over locations
  823. fi # not found yet ...
  824. # not found: error ...
  825. if [ -z "${found}" ]; then
  826. err "$prog - ERROR : do not know how to retrieve meteo file:"
  827. err "$prog - ERROR : directory : `/bin/pwd`"
  828. err "$prog - ERROR : meteofile : ${meteofile_long}"
  829. errit 1
  830. fi
  831. # next day:
  832. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  833. done # loop over days
  834. ;;
  835. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  836. ecmwf-mars:* | ecmwf-tmpp:* | ecmwf-tm5:* )
  837. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  838. # split in 'mars' and keys :
  839. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  840. # evaluate keys : class=od;type=fc;nlev=60;grid=T159
  841. class='class'
  842. stream='oper'
  843. expver=1
  844. type='type'
  845. levs='ml60'
  846. grid='X00'
  847. eval ${keys}
  848. # start at 00:00 ?
  849. if [ ${hh1} -eq 00 ]; then
  850. # fc files will be retrieved for (00,24] or (00,27]
  851. # and therefore include the final midnight already;
  852. # therefor start with the day before:
  853. ccyymmdd1=`${bindir}/date_add ${ccyymmdd1} -1`
  854. fi
  855. #------------------------
  856. # 24 Feb 2011 - P. Le Sager - Commented the following block for
  857. # EI preprocessing. See ecmwf:* case above. Note that, for "ei-an", we
  858. # substract another day, with dates=`${bindir}/date_add ${fcday00}
  859. # -1` further down in the script.
  860. # 13 Apr 2011 - P. Le Sager - Commented also for OD pre-processing to
  861. # work.
  862. if [ "${class}" != 'ei' -a "${class}" != 'od' ]; then
  863. # end at 00:00 ?
  864. if [ ${hh2} -eq 00 ]; then
  865. # fc files will be retrieved for (00,24] or (00,27]
  866. # and therefore include the final midnight already;
  867. # therefor end with the day before:
  868. ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} -1`
  869. fi
  870. fi
  871. #------------------------
  872. ## forecast mode ? then single day only:
  873. #if [ "${fcday0}" ]; then
  874. # ccyymmdd_end=${ccyymmdd1}
  875. #else
  876. # ccyymmdd_end=${ccyymmdd2}
  877. #fi
  878. # loop over days
  879. ccyymmdd=${ccyymmdd1}
  880. fcmode=''
  881. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  882. # forecast series only once ..
  883. test "${fcmode}" && break
  884. # forecast mode ?
  885. if [ "${fcday0}" -a "${fcmode_read}" == "T" ]; then
  886. # older forecast ?
  887. if [ ${ccyymmdd} -lt ${fcday0} ]; then
  888. fcday00=${ccyymmdd}
  889. else
  890. fcday00=${fcday0}
  891. fcmode='true'
  892. fi
  893. else
  894. # dummy
  895. fcday00=${ccyymmdd}
  896. fi
  897. # re-evaluate keys; some might have been changed for previous day ...
  898. eval ${keys}
  899. # adhoc reset of experiment version:
  900. test "${expver}" == "29" -a ${ccyymmdd} -gt 20060201 && expver='1'
  901. #
  902. # od, since 20040628 ?
  903. # ---------------------
  904. #
  905. # ][ forecast day ][ ][ ][ ]
  906. # 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12 15 18 21 0
  907. #
  908. # an an an
  909. # fc 00:00 + 00 03 06 09 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 78 84 90 96 ... 216 222 228 234 240
  910. # -- -- -- -- --
  911. # an an an
  912. # fc 12:00 + 00 03 06 09 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 78 84 ... 204 210 216 222 228 234 240
  913. # -- -- -- -- -- == == == == == == == == ++ ++ ++ ++ ++ ++ ++ ++
  914. #
  915. #
  916. # "--" means "selected for day 0" ; "==" means "selected for day 1" ; "++" means "selected for day 2" ;
  917. #
  918. #
  919. # era2003 (expver=500)
  920. # --------------------
  921. #
  922. # 2002-10-31 ][ 2002-11-01 ][ 2002-11-02 ]
  923. # 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00
  924. #
  925. # an an an
  926. # fc 12:00 + 03 06 09 12
  927. #
  928. # an an an
  929. # fc 00:00 + 03 06 09 12 15 18 21 24 30 36
  930. #
  931. # an an an
  932. # fc 12:00 + 03 06 09 12 15 18 21 24 30 36
  933. #
  934. # ---
  935. # 1) experimenatal data such as e4 convective fields
  936. # are available for fc steps 3/6/9/12 only
  937. #
  938. #
  939. #
  940. # ml91 setup (expver=29)
  941. # ----------------------
  942. #
  943. # 2005-09-30 ][ 2005-10-01 ][ 2005-10-02 ]
  944. # 03 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00
  945. #
  946. # 4v [----------]
  947. # an an an
  948. # fc 12:00 + 00 03 06 09 12 15 18 21 24 ...
  949. #
  950. # 4v [----------]
  951. # an an an
  952. # fc 00:00 + 00 03 06 09 12 15 18 21 24 ...
  953. #
  954. # 4v [----------]
  955. # an an an
  956. # fc 12:00 + 00 03 06 09 12 15 18 21 24 ...
  957. #
  958. # 4v [----------]
  959. # an an an
  960. # fc 00:00 + 00 03 06 09 12 15 18 21 24 ...
  961. #
  962. # [--first-complete-day--]
  963. #
  964. # Last forecast for expver 29 : 2006-02-01 00:00
  965. #
  966. # From 2006-03-14 : 3 hourly upto 96
  967. #
  968. # General notes
  969. # -------------
  970. #
  971. # o 4v data is often chaninging, use an instead
  972. # o SP available for od as fc-sfc, but for e4 only as an-sfc ..
  973. #
  974. # date, time and steps
  975. case ${class}-${type} in
  976. # ~~~~~~~~~~~~~~~~~~
  977. 'od-an' | 'e4-an' | 'ei-an' | 'rd-an' )
  978. # ~~~~~~~~~~~~~~~~~~
  979. # analysed fields are (at least) 24 hours old,
  980. # since not available in forecast mode:
  981. dates=`${bindir}/date_add ${fcday00} -1`
  982. # ensure that all fields within [00,24] are available (from previous day!);
  983. # therefore the time 2400 is added which is treated specially below:
  984. times="0000/0600/1200/1800 2400"
  985. # an fields always have step 000 :
  986. steps="000 000"
  987. # specify the experiment version for each times sequence:
  988. expvers="${expver} ${expver}"
  989. #
  990. # adhoc for ml91 test suit:
  991. if [ "${class}" = "od" -a ${expver} -eq 29 ]; then
  992. if [ ${dates} -eq 20050930 ] ; then
  993. times="0600/1200/1800 2400"
  994. fi
  995. fi
  996. ;;
  997. # ~~~~~~~~~~~~~~~~~~
  998. 'ea-an' )
  999. # ~~~~~~~~~~~~~~~~~~
  1000. # ERA5: retrieve hourly surface fields
  1001. # re-analysis, use curent day:
  1002. dates="${ccyymmdd}"
  1003. # hourly from midnight onwards:
  1004. times="0000/0100/0200/0300/0400/0500/0600/0700/0800/0900/1000/1100/1200/1300/1400/1500/1600/1700/1800/1900/2000/2100/2200/2300"
  1005. # an fields always have step 000 :
  1006. steps="000"
  1007. # specify the experiment version for each times sequence:
  1008. expvers="${expver}"
  1009. ;;
  1010. # ~~~~~~~~~~~~~~~~~~
  1011. 'od-fc' | 'e4-fc' | 'ei-fc' )
  1012. # ~~~~~~~~~~~~~~~~~~
  1013. # forecast mode ?
  1014. if [ "${fcmode}" ]; then
  1015. # in forecast mode, the date is when the forecast started:
  1016. dates="${fcday00}"
  1017. # determine forecast periode range 0 .. 10
  1018. fcp1=`${bindir}/date_diff ${fcday00} ${ccyymmdd}`
  1019. fcp2=`${bindir}/date_diff ${fcday00} ${ccyymmdd2}`
  1020. if [ ${fcp1} -lt 0 -o ${fcp1} -gt 10 -o ${fcp2} -lt 0 -o ${fcp2} -gt 10 ]; then
  1021. err "$prog - ERROR - found obscure forecast period range: ${fcp1} ${fcp2}"
  1022. err "$prog - ERROR - fcday0 : ${fcday00}"
  1023. err "$prog - ERROR - ccyymmdd : ${ccyymmdd}"
  1024. err "$prog - ERROR - ccyymmdd2 : ${ccyymmdd2}"
  1025. errit 1
  1026. fi
  1027. else
  1028. # forecast day '0'
  1029. dates="${ccyymmdd}"
  1030. # no forecast perode range:
  1031. fcp1=0
  1032. fcp2=0
  1033. fi
  1034. # fc periode '0' uses the 00:00 and 12:00 forecast,
  1035. # fc periode 1, 2, ... use the 12:00 forecast only
  1036. if [ ${fcp1} -eq 0 -a ${fcp2} -eq 0 ] ; then
  1037. # single mars request for first day:
  1038. times="0000/1200"
  1039. steps="003/006/009/012"
  1040. expvers="${expver}"
  1041. # for surface fields, also read step 015 since we need
  1042. # accumulated surface heat fluxes for convection for the
  1043. # 3-hourly intervals around 12:00 and 24:00:
  1044. test "${levs}" = "sfc" && steps="003/006/009/012/015"
  1045. # adhoc for ml91 test suit:
  1046. if [ "${class}" = "od" -a ${expver} -eq 29 ]; then
  1047. if [ ${ccyymmdd} -eq 20050930 ] ; then
  1048. times="1200"
  1049. steps="003/006/009/012"
  1050. test "${levs}" = "sfc" && steps="003/006/009/012/015"
  1051. fi
  1052. if [ ${ccyymmdd} -eq 20060201 ] ; then
  1053. times="0000 1200"
  1054. steps="003/006/009/012 003/006/009/012/"
  1055. test "${levs}" = "sfc" && steps="003/006/009/012/015 003/006/009/012/015"
  1056. expvers="29 1"
  1057. fi
  1058. fi
  1059. # adhoc for era2003:
  1060. if [ "${class}" = "e4" -a ${expver} -eq 500 ]; then
  1061. # experimental fields up to step 12 only:
  1062. steps="003/006/009/012"
  1063. fi
  1064. else
  1065. # multiple forecast days, or one forecast day after day 0
  1066. # retrieve day 0 ?
  1067. if [ ${fcp1} -eq 0 ] ; then
  1068. # two mars requests needed:
  1069. # (also step 015 for accum fields around 12:00 and 24:00)
  1070. times="0000 1200"
  1071. steps="003/006/009/012/015 003/006/009/012/015"
  1072. # now
  1073. # steps="003/006/009/012 003/006/009/012/015"
  1074. # test "${levs}" = "sfc" && steps="003/006/009/012/015 003/006/009/012/015"
  1075. expvers="${expver} ${expver}"
  1076. # adhoc ...
  1077. test ${expver} -eq 29 -a ${ccyymmdd} -eq 20060201 && expvers="29 1"
  1078. else
  1079. # one mars request for 12:00 forecast only:
  1080. times="1200"
  1081. steps=""
  1082. expvers="${expver}"
  1083. # adhoc ...
  1084. test ${expver} -eq 29 -a ${ccyymmdd} -eq 20060201 && expvers="1"
  1085. fi
  1086. # add other steps; for fcp 0 already filled above ...
  1087. fcp=${fcp1}
  1088. test ${fcp} -eq 0 && fcp=1
  1089. while [ ${fcp} -le ${fcp2} ]; do
  1090. # add seperation / if necessary:
  1091. test "${steps}" && steps="${steps}/"
  1092. # add steps (015 already added above)
  1093. if [ ${ccyymmdd} -lt 20060314 ]; then
  1094. case ${fcp} in
  1095. 1 ) steps="${steps}018/021/024/027/030/033/036" ;;
  1096. 2 ) steps="${steps}039/042/045/048/051/054/057/060" ;;
  1097. 3 ) steps="${steps}063/066/069/072/078/084" ;;
  1098. 4 ) steps="${steps}090/096/102/108" ;;
  1099. 5 ) steps="${steps}114/120/126/132" ;;
  1100. 6 ) steps="${steps}138/144/150/156" ;;
  1101. 7 ) steps="${steps}162/168/174/180" ;;
  1102. 8 ) steps="${steps}186/192/198/204" ;;
  1103. 9 ) steps="${steps}210/216/222/228" ;;
  1104. 10 ) steps="${steps}234/240" ;;
  1105. * )
  1106. err "$prog - ERROR - forecast periode ${fcp} not supported for steps"
  1107. errit 1 ;;
  1108. esac
  1109. else
  1110. case ${fcp} in
  1111. # 30 Nov 2010 - P. Le Sager -
  1112. # before:
  1113. # 1 ) steps="${steps}018/021/024/027/030/033/036" ;;
  1114. # 2 ) steps="${steps}039/042/045/048/051/054/057/060" ;;
  1115. # 3 ) steps="${steps}063/066/069/072/075/078/081/084" ;;
  1116. # 4 ) steps="${steps}087/090/093/096/102/108" ;;
  1117. # 5 ) steps="${steps}114/120/126/132" ;;
  1118. # 6 ) steps="${steps}138/144/150/156" ;;
  1119. # 7 ) steps="${steps}162/168/174/180" ;;
  1120. # 8 ) steps="${steps}186/192/198/204" ;;
  1121. # 9 ) steps="${steps}210/216/222/228" ;;
  1122. # 10 ) steps="${steps}234/240" ;;
  1123. # now:
  1124. 1 ) steps="${steps}018/021/024/027/030/033/036/039" ;;
  1125. 2 ) steps="${steps}042/045/048/051/054/057/060/063" ;;
  1126. 3 ) steps="${steps}066/069/072/075/078/081/084/087" ;;
  1127. 4 ) steps="${steps}090/093/096/102/108" ;;
  1128. 5 ) steps="${steps}114/120/126/132" ;;
  1129. 6 ) steps="${steps}138/144/150/156" ;;
  1130. 7 ) steps="${steps}162/168/174/180" ;;
  1131. 8 ) steps="${steps}186/192/198/204" ;;
  1132. 9 ) steps="${steps}210/216/222/228" ;;
  1133. 10 ) steps="${steps}234/240" ;;
  1134. * )
  1135. err "$prog - ERROR - forecast periode ${fcp} not supported for steps"
  1136. errit 1 ;;
  1137. esac
  1138. fi
  1139. # next fc periode:
  1140. fcp=`/usr/bin/expr ${fcp} + 1`
  1141. done
  1142. fi # fcp 0 only or one or forecast periode range
  1143. ;;
  1144. # ~~~~~~~~~~~~~~~~~~
  1145. 'ea-fc' )
  1146. # ~~~~~~~~~~~~~~~~~~
  1147. # ERA5: retrieve hourly surface fields, others at 3 hourly
  1148. case "${levs}" in
  1149. 'sfc' )
  1150. expvers="${expver}"
  1151. dates="${ccyymmdd}"
  1152. times="0600/1800"
  1153. steps="001/002/003/004/005/006/007/008/009/010/011/012"
  1154. ;;
  1155. * )
  1156. expvers="${expver}"
  1157. dates="${ccyymmdd}"
  1158. times="0600/1800"
  1159. steps="003/006/009/012"
  1160. ;;
  1161. esac
  1162. ;;
  1163. # ~~~~~~~~~~~~~~~~~~
  1164. 'rd-fc' )
  1165. # ~~~~~~~~~~~~~~~~~~
  1166. # a keyword 'tres' should be used ..
  1167. if [ -z "${tres}" ] ; then
  1168. err "$prog - ERROR - sources definition line should contain a 'tres' value"
  1169. errit 1
  1170. fi
  1171. # fill per tres:
  1172. case ${tres} in
  1173. '_fc000up24tr1' )
  1174. expvers="${expver}"
  1175. dates="${ccyymmdd}"
  1176. times="0030/0130/0230/0330/0430/0530/0630/0730/0830/0930/1030/1130/1230/1330/1430/1530/1630/1730/1830/1930/2030/2130/2230/2330"
  1177. steps="000"
  1178. ;;
  1179. '_fc000up1tr24' )
  1180. expvers="${expver}"
  1181. dates="${ccyymmdd}"
  1182. times="1200"
  1183. steps="000"
  1184. ;;
  1185. * )
  1186. err "$prog - ERROR - tres value '${tres}' not supported for class-type : ${class}-${type}"
  1187. errit 1 ;;
  1188. esac
  1189. ;;
  1190. # ~~~~~~~~~~~~~~~~~~
  1191. * )
  1192. # ~~~~~~~~~~~~~~~~~~
  1193. err "$prog - unsupported class-type for mars data : ${class}-${type}"
  1194. errit 1
  1195. ;;
  1196. esac
  1197. # levels
  1198. case ${levs} in
  1199. sfc )
  1200. levtype='sfc'
  1201. ;;
  1202. ml* )
  1203. nlev=`echo ${levs} | /usr/bin/tr -d 'ml'`
  1204. levtype="ml,levelist=1/to/${nlev}"
  1205. ;;
  1206. * )
  1207. err "$prog - levs '${levs}' not supported ..."
  1208. errit 1
  1209. ;;
  1210. esac
  1211. # parameters to retrieve:
  1212. params=${mfile}
  1213. # horizontal grid
  1214. case ${grid} in
  1215. T* )
  1216. resol=`echo ${grid} | /usr/bin/tr -d 'T'`
  1217. repres="sh,resol=${resol},grid=off"
  1218. ;;
  1219. N* )
  1220. resol=`echo ${grid} | /usr/bin/tr -d 'N'`
  1221. repres="gg,grid=${resol},gaussian=reduced"
  1222. ;;
  1223. R0.5 )
  1224. # regular lon/lat grid, retrieve as archived,
  1225. # therfore limit area to the centers of first/last rows/columns ;
  1226. # explicitly define area for [-180,180], otherwise the
  1227. # default [0,360] is returned:
  1228. #repres="ll,area=89.75/-179.75/-89.75/179.75,qgrid=0.5/0.5"
  1229. # mars seems to return always the archived field,
  1230. # thus [0,360] ...
  1231. repres="ll,grid=off,resol=off,gaussian=off"
  1232. ;;
  1233. * )
  1234. err "$prog - grid '${grid}' not supported ..."
  1235. errit 1
  1236. ;;
  1237. esac
  1238. # define target file including fields expanded by mars:
  1239. targets="${class}-${type}-[date]-[time]-${levs}-[param]-${grid}.gb"
  1240. # To have param numbers including table (173.128 instead of 173)
  1241. # and times in 4 digits (0000 and 0600 instead of 0 and 600),
  1242. # use the following trick given by the mars info messages:
  1243. #
  1244. # In order to get filenames according to MARS values,
  1245. # please, set env. var. MARS_MULTITARGET_STRICT_FORMAT=1
  1246. # before executing your MARS request
  1247. #
  1248. export MARS_MULTITARGET_STRICT_FORMAT=1
  1249. #
  1250. # request could be skipped if all target files are already present;
  1251. # expand the 'targets' to indvidual file and test existence:
  1252. #
  1253. # initially not found:
  1254. notfound=0
  1255. #
  1256. # loop over dates:
  1257. for date in `echo ${dates} | /usr/bin/tr '/' ' '` ; do
  1258. # loop over times:
  1259. for time in `echo ${times} | /usr/bin/tr '/' ' '` ; do
  1260. # adhoc: era2003 (expver=500) starts at 2002-10-31 12:00
  1261. test "${class}-${expver}" = "e4-500" -a ${date} -lt 20021031 && continue
  1262. # adhoc: ml91 spin-up (expver=29) between 2005-09-30 12:00 and 2006-02-01 00:00
  1263. test "${class}-${expver}" = "od-29" -a ${date}${time} -lt 200509301200 && continue
  1264. # adhoc fix to be able to read an fields over [00,24] :
  1265. if [ "${time}" = "2400" ]; then
  1266. xdate=`${bindir}/date_add ${date} 1`
  1267. xtime='0000'
  1268. else
  1269. xdate=${date}
  1270. xtime=${time}
  1271. fi
  1272. # init list of mars parameter numbers "27.128/28.128/..." :
  1273. mars_params=''
  1274. # loop over parameters:
  1275. for param in `echo ${params} | /usr/bin/tr '/' ' '` ; do
  1276. # translate param name to grib code:
  1277. mars_param=${param}
  1278. case ${param} in
  1279. CVL ) mars_param=27.128 ;;
  1280. CVH ) mars_param=28.128 ;;
  1281. TVL ) mars_param=29.128 ;;
  1282. TVH ) mars_param=30.128 ;;
  1283. CI ) mars_param=31.128 ;;
  1284. SSTK ) mars_param=34.128 ;;
  1285. SWVL1 ) mars_param=39.128 ;;
  1286. SWVL2 ) mars_param=40.128 ;;
  1287. SWVL3 ) mars_param=41.128 ;;
  1288. SWVL4 ) mars_param=42.128 ;;
  1289. STL1 ) mars_param=139.128 ;;
  1290. STL2 ) mars_param=170.128 ;;
  1291. STL3 ) mars_param=183.128 ;;
  1292. STL4 ) mars_param=236.128 ;;
  1293. 10FG )
  1294. mars_param=49.128
  1295. # check
  1296. if [ "${class}" == 'od' -a ${date} -ge 20111115 ] ; then
  1297. echo " WARNING : unless you have modified TM5 code, "
  1298. echo " WARNING : you are supposed to request 10FG3. "
  1299. echo " WARNING : It replaces 10FG as variable name for"
  1300. echo " WARNING : the 3-hourly accumulated gust wind."
  1301. exit 1
  1302. fi
  1303. ;;
  1304. 10FG3 )
  1305. mars_param=28.228
  1306. # check
  1307. if [ "${class}" == 'od' -a ${date} -lt 20111115 ] ; then
  1308. echo " WARNING : unless you have modified TM5 code, "
  1309. echo " WARNING : you are supposed to request 10FG. "
  1310. echo " WARNING : It was the variable name for the 3-hourly"
  1311. echo " WARNING : accumulated gust wind before 2011/11/15."
  1312. exit 1
  1313. fi
  1314. ;;
  1315. Z ) mars_param=129.128 ;;
  1316. T ) mars_param=130 ;; #.128 ;;
  1317. Q ) mars_param=133 ;; #.128 ;;
  1318. SP ) mars_param=134.128 ;;
  1319. W ) mars_param=135 ;; #.128 ;;
  1320. VO ) mars_param=138 ;; #.128 ;;
  1321. STL1 ) mars_param=139.128 ;;
  1322. SD ) mars_param=141.128 ;;
  1323. LSP ) mars_param=142.128 ;;
  1324. CP ) mars_param=143.128 ;;
  1325. SF ) mars_param=144.128 ;;
  1326. SSHF ) mars_param=146.128 ;;
  1327. SLHF ) mars_param=147.128 ;;
  1328. LNSP ) mars_param=152 ;; #.128 ;;
  1329. D ) mars_param=155 ;; #.128 ;;
  1330. BLH ) mars_param=159.128 ;;
  1331. 10U ) mars_param=165.128 ;;
  1332. 10V ) mars_param=166.128 ;;
  1333. 2T ) mars_param=167.128 ;;
  1334. 2D ) mars_param=168.128 ;;
  1335. SSRD ) mars_param=169.128 ;;
  1336. STL2 ) mars_param=170.128 ;;
  1337. LSM ) mars_param=172.128 ;;
  1338. SR ) mars_param=173.128 ;;
  1339. AL ) mars_param=174.128 ;;
  1340. STRD ) mars_param=175.128 ;;
  1341. SSR ) mars_param=176.128 ;;
  1342. STR ) mars_param=177.128 ;;
  1343. EWSS ) mars_param=180.128 ;;
  1344. NSSS ) mars_param=181.128 ;;
  1345. STL3 ) mars_param=183.128 ;;
  1346. SRC ) mars_param=198.128 ;;
  1347. TP ) mars_param=228.128 ;;
  1348. LSRH ) mars_param=234.128 ;;
  1349. SKT ) mars_param=235.128 ;;
  1350. STL4 ) mars_param=236.128 ;;
  1351. FAL ) mars_param=243.128 ;;
  1352. FSR ) mars_param=244.128 ;;
  1353. CLWC ) mars_param=246 ;; #.128 ;;
  1354. CIWC ) mars_param=247 ;; #.128 ;;
  1355. CC ) mars_param=248 ;; #.128 ;;
  1356. # ea accumulated surface fields:
  1357. MLSPR ) mars_param=029.235 ;;
  1358. MCPR ) mars_param=030.235 ;;
  1359. MSR ) mars_param=031.235 ;;
  1360. METSS ) mars_param=041.235 ;;
  1361. MNTSS ) mars_param=042.235 ;;
  1362. MSLHF ) mars_param=034.235 ;;
  1363. MSSHF ) mars_param=033.235 ;;
  1364. MSNSWRF ) mars_param=037.235 ;;
  1365. MSDWSWRF ) mars_param=035.235 ;;
  1366. MSNLWRF ) mars_param=038.235 ;;
  1367. MSDWLWRF ) mars_param=036.235 ;;
  1368. # e4 convective fields, local table should have been 162 ...
  1369. 104.128 ) mars_param=104.128 ;;
  1370. 105.128 ) mars_param=105.128 ;;
  1371. 106.128 ) mars_param=106.128 ;;
  1372. 107.128 ) mars_param=107.128 ;;
  1373. # ei convective fields:
  1374. 104.162 ) mars_param=104.162 ;;
  1375. 105.162 ) mars_param=105.162 ;;
  1376. 106.162 ) mars_param=106.162 ;;
  1377. 107.162 ) mars_param=107.162 ;;
  1378. # ei diffusion:
  1379. 109.162 ) mars_param=109.162 ;;
  1380. # ea convective fields, param codes as written by mars:
  1381. MUMF ) mars_param=235009 ;; #mars_param=009.235 ;;
  1382. MDMF ) mars_param=235010 ;; #mars_param=010.235 ;;
  1383. MUDR ) mars_param=235011 ;; #mars_param=011.235 ;;
  1384. MDDR ) mars_param=235012 ;; #mars_param=012.235 ;;
  1385. # ea diffusion, param codes as written by mars:
  1386. MTDCH ) mars_param=235014 ;; #mars_param=014.235 ;;
  1387. # macc emissions:
  1388. CH4FIRE ) mars_param='82.210' ;;
  1389. # not supported yet ...
  1390. * )
  1391. err "$prog - no grib code implemented for param '${param}'"
  1392. errit 1
  1393. ;;
  1394. esac
  1395. # add to list:
  1396. if [ -z "${mars_params}" ]; then
  1397. mars_params="${mars_param}"
  1398. else
  1399. mars_params="${mars_params}/${mars_param}"
  1400. fi
  1401. # target file name:
  1402. fname=`echo ${targets} | /usr/bin/sed -e "s^\[date\]^${xdate}^" -e "s^\[time\]^${xtime}^" -e "s^\[param\]^${mars_param}^"`
  1403. # found ?
  1404. if [ -f ${fname} ]; then
  1405. echo "$prog - found ${fname}"
  1406. # touch to prevent removal because of quota
  1407. test -w ${fname} && touch ${fname}
  1408. else
  1409. echo "$prog - missing ${fname}"
  1410. # at least one file is not found yet,
  1411. # so further testing is not necessary
  1412. notfound=1
  1413. # do not leave the 'param' loop, need to fill 'mars_params' list ...
  1414. #break
  1415. fi
  1416. done # loop over params
  1417. test ${notfound} -gt 0 && break
  1418. done # loop over times
  1419. test ${notfound} -gt 0 && break
  1420. done # loop over dates
  1421. # add mars request ?
  1422. if [ ${notfound} -gt 0 ]; then
  1423. # add line to mars job for each time:
  1424. istep=0
  1425. for time in ${times} ; do
  1426. # next step:
  1427. istep=`/usr/bin/expr ${istep} + 1`
  1428. # corresponding steps etc:
  1429. stepi=`echo ${steps} | /usr/bin/cut -d ' ' -f ${istep}`
  1430. expveri=`echo ${expvers} | /usr/bin/cut -d ' ' -f ${istep}`
  1431. # adhoc fix to be able to read an fields over [00,24] :
  1432. if [ "${time}" = "2400" ]; then
  1433. # next day, one time only:
  1434. xdate=`${bindir}/date_add ${date} 1`
  1435. xtime='0000'
  1436. else
  1437. # just copy:
  1438. xdate=${dates}
  1439. xtime=${time}
  1440. fi
  1441. # add line:
  1442. echo "$prog - add line to mars job for ${xdate} ${xtime} ..."
  1443. echo "retrieve,class=${class},stream=${stream},expver=${expveri},type=${type},date=${xdate},time=${xtime},step=${stepi},levtype=${levtype},param=${mars_params},repres=${repres},target="'"'"${targets}"'"' >> ${mars_jb}
  1444. done
  1445. else
  1446. # all found ...
  1447. echo "$prog - all found for ${ccyymmdd} ..."
  1448. fi
  1449. # next day:
  1450. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  1451. done # loop over days
  1452. set +x
  1453. ;;
  1454. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1455. ncep-cdc:* ) # NCEP RA NetCDF files
  1456. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1457. # year files, valid for valid for [00,24)
  1458. # retrieve previous year if necessary
  1459. case ${mfile} in
  1460. 'lhtfl' )
  1461. test "${mm1}${dd1}${hh1}" -eq "010100" && ccyy1=`/usr/bin/expr ${ccyy1} - 1`
  1462. ;;
  1463. esac
  1464. # loop over years
  1465. ccyy=${ccyy1}
  1466. while [ ${ccyy} -le ${ccyy2} ]; do
  1467. #
  1468. # define filename etc
  1469. #
  1470. #
  1471. # spectral /div .spec .2000.nc
  1472. # spectral /pres.nlog.sfc.spec .2000.nc
  1473. # spectral /vort .spec .2000.nc
  1474. # surface_gauss/lhtfl.sfc .gauss.2000.nc
  1475. # pressure /omega .2000.nc
  1476. #
  1477. ## split in 'ncep-cdc' and keys :
  1478. ##keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1479. #
  1480. ## evaluate keys : mdir=spectral
  1481. ##eval ${keys}
  1482. # file and directory name:
  1483. case ${mfile} in
  1484. 'hgt' | 'land' )
  1485. meteodir='surface_gauss'
  1486. meteofile="${mfile}.sfc.gauss.nc" ;;
  1487. 'sfcr' | 'pres' | 'icec' | 'skt' | 'lhtfl' | 'shtfl' | 'ugwd' | 'vgwd' | 'prate' | 'cprat' )
  1488. meteodir='surface_gauss'
  1489. meteofile="${mfile}.sfc.gauss.${ccyy}.nc" ;;
  1490. 'uwnd.10m' | 'vwnd.10m' )
  1491. meteodir='surface_gauss'
  1492. meteofile="${mfile}.gauss.${ccyy}.nc" ;;
  1493. 'pres.nlog' )
  1494. meteodir='spectral'
  1495. meteofile="${mfile}.sfc.spec.${ccyy}.nc" ;;
  1496. 'vort' | 'div' | 'vair' | 'shum' )
  1497. meteodir='spectral'
  1498. meteofile="${mfile}.spec.${ccyy}.nc" ;;
  1499. * )
  1500. err "$prog - ERROR - unsupported ncep file '${mfile}' ..."
  1501. errit 1 ;;
  1502. esac
  1503. # expand directory:
  1504. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1505. # expand day file:
  1506. meteofile_full="${meteodir}/${meteofile}"
  1507. meteofile_long="${meteodir_long}-${meteofile}"
  1508. # not found yet ...
  1509. found=''
  1510. #
  1511. # present in buffer ?
  1512. #
  1513. # not found yet ?
  1514. if [ -z "${found}" ]; then
  1515. fname=./${meteofile_long}
  1516. #test ${verbose} && echo "$prog - try ${fname}"
  1517. if [ -f ${fname} ]; then
  1518. #test ${verbose} && echo "$prog - found ..."
  1519. test -w ${fname} && touch ${fname}
  1520. found='true'
  1521. fi
  1522. fi # not found yet ...
  1523. #
  1524. # search locations
  1525. #
  1526. # not found yet ?
  1527. if [ -z "${found}" ]; then
  1528. # loop over search locations
  1529. for loc in ${search_locs} ; do
  1530. # *** full file
  1531. fname=${loc}/${meteofile_full}
  1532. test ${verbose} && echo "$prog - try ${fname} ..."
  1533. if ${bindir}/gss exist ${fname} ; then
  1534. # create link in buffer:
  1535. test ${verbose} && echo "$prog - link ..."
  1536. bname=./${meteofile_long}
  1537. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1538. # found !
  1539. found='true'
  1540. break
  1541. fi
  1542. # *** long file
  1543. fname=${loc}/${meteofile_long}
  1544. test ${verbose} && echo "$prog - try ${fname} ..."
  1545. if ${bindir}/gss exist ${fname} ; then
  1546. # create link in buffer:
  1547. test ${verbose} && echo "$prog - link ..."
  1548. bname=./${meteofile_long}
  1549. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1550. # found !
  1551. found='true'
  1552. break
  1553. fi
  1554. done # loop over locations
  1555. fi # not found yet ...
  1556. # not found: error ...
  1557. if [ -z "${found}" ]; then
  1558. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1559. err "$prog - ERROR : directory : `/bin/pwd`"
  1560. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1561. errit 1
  1562. fi
  1563. # next year:
  1564. ccyy=`/usr/bin/expr ${ccyy} + 1`
  1565. done # loop over years
  1566. ;;
  1567. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1568. ncep-gfs:* ) # NCEP GFS binary and grib files
  1569. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1570. # files in directory <ccyymmdd> valid for [12,12]
  1571. test ${hh1} -lt 12 && ccyymmdd1=`${bindir}/date_add ${ccyymmdd1} -1`
  1572. test ${hh2} -lt 12 && ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} -1`
  1573. # loop over days
  1574. ccyymmdd=${ccyymmdd1}
  1575. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  1576. # split current day:
  1577. ccyy=`echo ${ccyymmdd} | /usr/bin/cut -c 1-4`
  1578. mm=`echo ${ccyymmdd} | /usr/bin/cut -c 5-6`
  1579. dd=`echo ${ccyymmdd} | /usr/bin/cut -c 7-8`
  1580. # hour list:
  1581. hours='12.00 12.03 12.06 12.09 12.12 12.15 12.18 12.21 12.24'
  1582. # loop over hours
  1583. for hour in ${hours} ; do
  1584. #
  1585. # define filename etc
  1586. #
  1587. #
  1588. # 20040614/20040614.00.00.SF
  1589. # 20040614/20040614.00.00.SFLUXGrbF
  1590. #
  1591. # split in 'ncep-gfs' and keys :
  1592. #keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1593. # evaluate keys : mdir=spectral
  1594. #eval ${keys}
  1595. # file and directory name:
  1596. meteodir="${ccyy}${mm}${dd}"
  1597. meteofile="${ccyy}${mm}${dd}.${hour}.${mfile}"
  1598. # expand directory:
  1599. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1600. # expand day file:
  1601. meteofile_full="${meteodir}/${meteofile}"
  1602. meteofile_long="${meteodir_long}-${meteofile}"
  1603. # not found yet ...
  1604. found=''
  1605. #
  1606. # present in buffer ?
  1607. #
  1608. # not found yet ?
  1609. if [ -z "${found}" ]; then
  1610. fname=./${meteofile_long}
  1611. #test ${verbose} && echo "$prog - try ${fname}"
  1612. if [ -f ${fname} ]; then
  1613. #test ${verbose} && echo "$prog - found ..."
  1614. test -w ${fname} && touch ${fname}
  1615. found='true'
  1616. fi
  1617. fi # not found yet ...
  1618. #
  1619. # search locations
  1620. #
  1621. # not found yet ?
  1622. if [ -z "${found}" ]; then
  1623. # loop over search locations
  1624. for loc in ${search_locs} ; do
  1625. # *** full file
  1626. fname=${loc}/${meteofile_full}
  1627. test ${verbose} && echo "$prog - try ${fname} ..."
  1628. if ${bindir}/gss exist ${fname} ; then
  1629. # create link in buffer:
  1630. test ${verbose} && echo "$prog - link ..."
  1631. bname=./${meteofile_long}
  1632. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1633. # found !
  1634. found='true'
  1635. break
  1636. fi
  1637. # *** long file
  1638. fname=${loc}/${meteofile_long}
  1639. test ${verbose} && echo "$prog - try ${fname} ..."
  1640. if ${bindir}/gss exist ${fname} ; then
  1641. # create link in buffer:
  1642. test ${verbose} && echo "$prog - link ..."
  1643. bname=./${meteofile_long}
  1644. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1645. # found !
  1646. found='true'
  1647. break
  1648. fi
  1649. done # loop over locations
  1650. fi # not found yet ...
  1651. # not found: error ...
  1652. if [ -z "${found}" ]; then
  1653. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1654. err "$prog - ERROR : directory : `/bin/pwd`"
  1655. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1656. errit 1
  1657. fi
  1658. done # hours
  1659. # next day:
  1660. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  1661. done # loop over days
  1662. ;;
  1663. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1664. msc-data:* ) # MSC data files
  1665. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1666. # loop over days
  1667. ccyymmdd=${ccyymmdd1}
  1668. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  1669. # split current day:
  1670. ccyy=`echo ${ccyymmdd} | /usr/bin/cut -c 1-4`
  1671. mm=`echo ${ccyymmdd} | /usr/bin/cut -c 5-6`
  1672. dd=`echo ${ccyymmdd} | /usr/bin/cut -c 7-8`
  1673. #
  1674. # define filename etc
  1675. #
  1676. # example: msc-data:nlev=71;sh=47;mdir=cmam;tres=_1dag_6hrly
  1677. # default keys:
  1678. mdir='<mdir>'
  1679. tres='<tres>'
  1680. # split in 'msc-data' and keys :
  1681. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1682. # evaluate keys : form=tm5; mdir=od-fc-etc; tres=_21p06
  1683. eval ${keys}
  1684. # define directory and file:
  1685. meteodir=${mdir}'/'${type}
  1686. meteofile="${mfile}_${ccyymmdd}${tres}.dat"
  1687. # expand directory:
  1688. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1689. # expand day file:
  1690. meteofile_full="${meteodir}/${meteofile}"
  1691. meteofile_long="${meteodir_long}-${meteofile}"
  1692. # not found yet ...
  1693. found=''
  1694. #
  1695. # present in buffer ?
  1696. #
  1697. # not found yet ?
  1698. if [ -z "${found}" ]; then
  1699. fname=./${meteofile_long}
  1700. #test ${verbose} && echo "$prog - try ${fname}"
  1701. if [ -f ${fname} ]; then
  1702. #test ${verbose} && echo "$prog - found ..."
  1703. test -w ${fname} && touch ${fname}
  1704. found='true'
  1705. fi
  1706. fi # not found yet ...
  1707. #
  1708. # search locations
  1709. #
  1710. # not found yet ?
  1711. if [ -z "${found}" ]; then
  1712. # loop over search locations
  1713. for loc in ${search_locs} ; do
  1714. # *** full file
  1715. fname=${loc}/${meteofile_full}
  1716. test ${verbose} && echo "$prog - try ${fname} ..."
  1717. if ${bindir}/gss exist ${fname} ; then
  1718. # create link in buffer:
  1719. test ${verbose} && echo "$prog - link ..."
  1720. bname=./${meteofile_long}
  1721. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1722. # found !
  1723. found='true'
  1724. break
  1725. fi
  1726. # *** long file
  1727. fname=${loc}/${meteofile_long}
  1728. test ${verbose} && echo "$prog - try ${fname} ..."
  1729. if ${bindir}/gss exist ${fname} ; then
  1730. # create link in buffer:
  1731. test ${verbose} && echo "$prog - link ..."
  1732. bname=./${meteofile_long}
  1733. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1734. # found !
  1735. found='true'
  1736. break
  1737. fi
  1738. done # loop over locations
  1739. fi # not found yet ...
  1740. # not found: error ...
  1741. if [ -z "${found}" ]; then
  1742. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1743. err "$prog - ERROR : directory : `/bin/pwd`"
  1744. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1745. errit 1
  1746. fi
  1747. # next day:
  1748. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  1749. done # loop over days
  1750. ;;
  1751. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1752. olsson:* ) # Olsson sr files
  1753. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1754. # month files
  1755. # loop over months
  1756. ccyy=${ccyy1}
  1757. mm=${mm1}
  1758. while [ ${ccyy}${mm} -le ${ccyy2}${mm2} ]; do
  1759. #
  1760. # define filename etc
  1761. #
  1762. # example: olsson:mdir=SR_OLSSON
  1763. # default keys:
  1764. mdir='OLSSON'
  1765. # split in 'olsson' and keys :
  1766. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1767. # evaluate keys : mdir=oSR_OLSSON
  1768. eval ${keys}
  1769. # define directory and file:
  1770. meteodir="${mdir}"
  1771. meteofile="${mfile}_OLSSON_360_180_${mm}.d"
  1772. # expand directory:
  1773. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1774. # expand day file:
  1775. meteofile_full="${meteodir}/${meteofile}"
  1776. meteofile_long="${meteodir_long}-${meteofile}"
  1777. # not found yet ...
  1778. found=''
  1779. #
  1780. # present in buffer ?
  1781. #
  1782. # not found yet ?
  1783. if [ -z "${found}" ]; then
  1784. fname=./${meteofile_long}
  1785. #test ${verbose} && echo "$prog - try ${fname}"
  1786. if [ -f ${fname} ]; then
  1787. #test ${verbose} && echo "$prog - found ..."
  1788. test -w ${fname} && touch ${fname}
  1789. found='true'
  1790. fi
  1791. fi # not found yet ...
  1792. #
  1793. # search locations
  1794. #
  1795. # not found yet ?
  1796. if [ -z "${found}" ]; then
  1797. # loop over search locations
  1798. for loc in ${search_locs} ; do
  1799. # *** just file (ie not assumption on parent dir)
  1800. fname=${loc}/${meteofile}
  1801. test ${verbose} && echo "$prog - try ${fname} ..."
  1802. if ${bindir}/gss exist ${fname} ; then
  1803. # create link in buffer:
  1804. test ${verbose} && echo "$prog - link ..."
  1805. bname=./${meteofile_long}
  1806. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1807. # found !
  1808. found='true'
  1809. break
  1810. fi
  1811. # *** full file
  1812. fname=${loc}/${meteofile_full}
  1813. test ${verbose} && echo "$prog - try ${fname} ..."
  1814. if ${bindir}/gss exist ${fname} ; then
  1815. # create link in buffer:
  1816. test ${verbose} && echo "$prog - link ..."
  1817. bname=./${meteofile_long}
  1818. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1819. # found !
  1820. found='true'
  1821. break
  1822. fi
  1823. # *** long file
  1824. fname=${loc}/${meteofile_long}
  1825. test ${verbose} && echo "$prog - try ${fname} ..."
  1826. if ${bindir}/gss exist ${fname} ; then
  1827. # create link in buffer:
  1828. test ${verbose} && echo "$prog - link ..."
  1829. bname=./${meteofile_long}
  1830. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1831. # found !
  1832. found='true'
  1833. break
  1834. fi
  1835. done # loop over locations
  1836. fi # not found yet ...
  1837. # not found: error ...
  1838. if [ -z "${found}" ]; then
  1839. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1840. err "$prog - ERROR : directory : `/bin/pwd`"
  1841. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1842. errit 1
  1843. fi
  1844. # next month:
  1845. mm=`/usr/bin/expr ${mm} + 1`
  1846. if [ ${mm} -gt 12 ]; then
  1847. ccyy=`/usr/bin/expr ${ccyy} + 1`
  1848. mm=1
  1849. fi
  1850. # 2 digits ...
  1851. mm=`/usr/bin/printf '%2.2i' ${mm}`
  1852. done # loop over days
  1853. ;;
  1854. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1855. * ) # unsupported ...
  1856. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1857. err "$prog - ERROR - unsupported source:"
  1858. err "$prog - ERROR - ${msource}"
  1859. errit 1
  1860. ;;
  1861. esac # setup given source
  1862. done # loop over sources
  1863. done # loop over files
  1864. done # loop over sets
  1865. # *************************************
  1866. # step 3 : post
  1867. # *************************************
  1868. # retrieve files from mars ?
  1869. if [ -f ${mars_jb} ]; then
  1870. # clean up ?
  1871. mars_clean='false'
  1872. # mars output file:
  1873. mars_out="`/bin/pwd`/mars.out"
  1874. ## adhoc: keep output files for profiling:
  1875. mars_out="${mars_out}.$$"
  1876. mars_clean=''
  1877. echo "$prog - retrieve files from mars ..."
  1878. echo "$prog - start at `/bin/date`"
  1879. if ( /usr/bin/sort ${mars_jb} | mars > ${mars_out} 2>&1 ) ; then
  1880. echo "$prog - end at `/bin/date`"
  1881. test "${mars_clean}" && /bin/rm -f ${mars_jb} ${mars_out}
  1882. # # force conversion from grib2 to grib1 until grib_api is implemented in TM5
  1883. # if ( hostname | grep c2 ); then
  1884. # echo " editionNumber=1;" > gb2to1
  1885. # for i in *.gb; do
  1886. # # if (grib_dump $i | grep "editionNumber.*=.*2"); then
  1887. # grib_convert -M -G -7 gb2to1 $i dummy
  1888. # mv -f dummy $i
  1889. # # fi
  1890. # done
  1891. # fi
  1892. else
  1893. err "$prog - error from mars request; see:"
  1894. err "$prog - ${mars_out}"
  1895. errit 1
  1896. fi
  1897. fi
  1898. # *************************************
  1899. # step 4 : clean
  1900. # *************************************
  1901. # clean flag ?
  1902. if [ "${tmm_dir_clean}" = "T" ]; then
  1903. # limit disk usage:
  1904. ${bindir}/gss ${verbose} limit ${tmm_dir_size} ${tmm_dir}
  1905. fi
  1906. #
  1907. # back to origin
  1908. #
  1909. cd ${owd}
  1910. # -----------------------------------------------------
  1911. # end
  1912. # -----------------------------------------------------
  1913. test ${verbose} && echo "$prog - end"
  1914. # ok
  1915. exit 0