tm5-tmm-setup 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  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' )
  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. 'od-fc' | 'e4-fc' | 'ei-fc' )
  999. # ~~~~~~~~~~~~~~~~~~
  1000. # forecast mode ?
  1001. if [ "${fcmode}" ]; then
  1002. # in forecast mode, the date is when the forecast started:
  1003. dates="${fcday00}"
  1004. # determine forecast periode range 0 .. 10
  1005. fcp1=`${bindir}/date_diff ${fcday00} ${ccyymmdd}`
  1006. fcp2=`${bindir}/date_diff ${fcday00} ${ccyymmdd2}`
  1007. if [ ${fcp1} -lt 0 -o ${fcp1} -gt 10 -o ${fcp2} -lt 0 -o ${fcp2} -gt 10 ]; then
  1008. err "$prog - ERROR - found obscure forecast period range: ${fcp1} ${fcp2}"
  1009. err "$prog - ERROR - fcday0 : ${fcday00}"
  1010. err "$prog - ERROR - ccyymmdd : ${ccyymmdd}"
  1011. err "$prog - ERROR - ccyymmdd2 : ${ccyymmdd2}"
  1012. errit 1
  1013. fi
  1014. else
  1015. # forecast day '0'
  1016. dates="${ccyymmdd}"
  1017. # no forecast perode range:
  1018. fcp1=0
  1019. fcp2=0
  1020. fi
  1021. # fc periode '0' uses the 00:00 and 12:00 forecast,
  1022. # fc periode 1, 2, ... use the 12:00 forecast only
  1023. if [ ${fcp1} -eq 0 -a ${fcp2} -eq 0 ] ; then
  1024. # single mars request for first day:
  1025. times="0000/1200"
  1026. steps="003/006/009/012"
  1027. expvers="${expver}"
  1028. # for surface fields, also read step 015 since we need
  1029. # accumulated surface heat fluxes for convection for the
  1030. # 3-hourly intervals around 12:00 and 24:00:
  1031. test "${levs}" = "sfc" && steps="003/006/009/012/015"
  1032. # adhoc for ml91 test suit:
  1033. if [ "${class}" = "od" -a ${expver} -eq 29 ]; then
  1034. if [ ${ccyymmdd} -eq 20050930 ] ; then
  1035. times="1200"
  1036. steps="003/006/009/012"
  1037. test "${levs}" = "sfc" && steps="003/006/009/012/015"
  1038. fi
  1039. if [ ${ccyymmdd} -eq 20060201 ] ; then
  1040. times="0000 1200"
  1041. steps="003/006/009/012 003/006/009/012/"
  1042. test "${levs}" = "sfc" && steps="003/006/009/012/015 003/006/009/012/015"
  1043. expvers="29 1"
  1044. fi
  1045. fi
  1046. # adhoc for era2003:
  1047. if [ "${class}" = "e4" -a ${expver} -eq 500 ]; then
  1048. # experimental fields up to step 12 only:
  1049. steps="003/006/009/012"
  1050. fi
  1051. else
  1052. # multiple forecast days, or one forecast day after day 0
  1053. # retrieve day 0 ?
  1054. if [ ${fcp1} -eq 0 ] ; then
  1055. # two mars requests needed:
  1056. # (also step 015 for accum fields around 12:00 and 24:00)
  1057. times="0000 1200"
  1058. steps="003/006/009/012/015 003/006/009/012/015"
  1059. # now
  1060. # steps="003/006/009/012 003/006/009/012/015"
  1061. # test "${levs}" = "sfc" && steps="003/006/009/012/015 003/006/009/012/015"
  1062. expvers="${expver} ${expver}"
  1063. # adhoc ...
  1064. test ${expver} -eq 29 -a ${ccyymmdd} -eq 20060201 && expvers="29 1"
  1065. else
  1066. # one mars request for 12:00 forecast only:
  1067. times="1200"
  1068. steps=""
  1069. expvers="${expver}"
  1070. # adhoc ...
  1071. test ${expver} -eq 29 -a ${ccyymmdd} -eq 20060201 && expvers="1"
  1072. fi
  1073. # add other steps; for fcp 0 already filled above ...
  1074. fcp=${fcp1}
  1075. test ${fcp} -eq 0 && fcp=1
  1076. while [ ${fcp} -le ${fcp2} ]; do
  1077. # add seperation / if necessary:
  1078. test "${steps}" && steps="${steps}/"
  1079. # add steps (015 already added above)
  1080. if [ ${ccyymmdd} -lt 20060314 ]; then
  1081. case ${fcp} in
  1082. 1 ) steps="${steps}018/021/024/027/030/033/036" ;;
  1083. 2 ) steps="${steps}039/042/045/048/051/054/057/060" ;;
  1084. 3 ) steps="${steps}063/066/069/072/078/084" ;;
  1085. 4 ) steps="${steps}090/096/102/108" ;;
  1086. 5 ) steps="${steps}114/120/126/132" ;;
  1087. 6 ) steps="${steps}138/144/150/156" ;;
  1088. 7 ) steps="${steps}162/168/174/180" ;;
  1089. 8 ) steps="${steps}186/192/198/204" ;;
  1090. 9 ) steps="${steps}210/216/222/228" ;;
  1091. 10 ) steps="${steps}234/240" ;;
  1092. * )
  1093. err "$prog - ERROR - forecast periode ${fcp} not supported for steps"
  1094. errit 1 ;;
  1095. esac
  1096. else
  1097. case ${fcp} in
  1098. # 30 Nov 2010 - P. Le Sager -
  1099. # before:
  1100. # 1 ) steps="${steps}018/021/024/027/030/033/036" ;;
  1101. # 2 ) steps="${steps}039/042/045/048/051/054/057/060" ;;
  1102. # 3 ) steps="${steps}063/066/069/072/075/078/081/084" ;;
  1103. # 4 ) steps="${steps}087/090/093/096/102/108" ;;
  1104. # 5 ) steps="${steps}114/120/126/132" ;;
  1105. # 6 ) steps="${steps}138/144/150/156" ;;
  1106. # 7 ) steps="${steps}162/168/174/180" ;;
  1107. # 8 ) steps="${steps}186/192/198/204" ;;
  1108. # 9 ) steps="${steps}210/216/222/228" ;;
  1109. # 10 ) steps="${steps}234/240" ;;
  1110. # now:
  1111. 1 ) steps="${steps}018/021/024/027/030/033/036/039" ;;
  1112. 2 ) steps="${steps}042/045/048/051/054/057/060/063" ;;
  1113. 3 ) steps="${steps}066/069/072/075/078/081/084/087" ;;
  1114. 4 ) steps="${steps}090/093/096/102/108" ;;
  1115. 5 ) steps="${steps}114/120/126/132" ;;
  1116. 6 ) steps="${steps}138/144/150/156" ;;
  1117. 7 ) steps="${steps}162/168/174/180" ;;
  1118. 8 ) steps="${steps}186/192/198/204" ;;
  1119. 9 ) steps="${steps}210/216/222/228" ;;
  1120. 10 ) steps="${steps}234/240" ;;
  1121. * )
  1122. err "$prog - ERROR - forecast periode ${fcp} not supported for steps"
  1123. errit 1 ;;
  1124. esac
  1125. fi
  1126. # next fc periode:
  1127. fcp=`/usr/bin/expr ${fcp} + 1`
  1128. done
  1129. fi # fcp 0 only or one or forecast periode range
  1130. ;;
  1131. # ~~~~~~~~~~~~~~~~~~
  1132. 'rd-fc' )
  1133. # ~~~~~~~~~~~~~~~~~~
  1134. # a keyword 'tres' should be used ..
  1135. if [ -z "${tres}" ] ; then
  1136. err "$prog - ERROR - sources definition line should contain a 'tres' value"
  1137. errit 1
  1138. fi
  1139. # fill per tres:
  1140. case ${tres} in
  1141. '_fc000up24tr1' )
  1142. expvers="${expver}"
  1143. dates="${ccyymmdd}"
  1144. 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"
  1145. steps="000"
  1146. ;;
  1147. '_fc000up1tr24' )
  1148. expvers="${expver}"
  1149. dates="${ccyymmdd}"
  1150. times="1200"
  1151. steps="000"
  1152. ;;
  1153. * )
  1154. err "$prog - ERROR - tres value '${tres}' not supported for class-type : ${class}-${type}"
  1155. errit 1 ;;
  1156. esac
  1157. ;;
  1158. # ~~~~~~~~~~~~~~~~~~
  1159. * )
  1160. # ~~~~~~~~~~~~~~~~~~
  1161. err "$prog - unsupported class-type for mars data : ${class}-${type}"
  1162. errit 1
  1163. ;;
  1164. esac
  1165. # levels
  1166. case ${levs} in
  1167. sfc )
  1168. levtype='sfc'
  1169. ;;
  1170. ml* )
  1171. nlev=`echo ${levs} | /usr/bin/tr -d 'ml'`
  1172. levtype="ml,levelist=1/to/${nlev}"
  1173. ;;
  1174. * )
  1175. err "$prog - levs '${levs}' not supported ..."
  1176. errit 1
  1177. ;;
  1178. esac
  1179. # parameters to retrieve:
  1180. params=${mfile}
  1181. # horizontal grid
  1182. case ${grid} in
  1183. T* )
  1184. resol=`echo ${grid} | /usr/bin/tr -d 'T'`
  1185. repres="sh,resol=${resol},grid=off"
  1186. ;;
  1187. N* )
  1188. resol=`echo ${grid} | /usr/bin/tr -d 'N'`
  1189. repres="gg,grid=${resol},gaussian=reduced"
  1190. ;;
  1191. R0.5 )
  1192. # regular lon/lat grid, retrieve as archived,
  1193. # therfore limit area to the centers of first/last rows/columns ;
  1194. # explicitly define area for [-180,180], otherwise the
  1195. # default [0,360] is returned:
  1196. #repres="ll,area=89.75/-179.75/-89.75/179.75,qgrid=0.5/0.5"
  1197. # mars seems to return always the archived field,
  1198. # thus [0,360] ...
  1199. repres="ll,grid=off,resol=off,gaussian=off"
  1200. ;;
  1201. * )
  1202. err "$prog - grid '${grid}' not supported ..."
  1203. errit 1
  1204. ;;
  1205. esac
  1206. # define target file including fields expanded by mars:
  1207. targets="${class}-${type}-[date]-[time]-${levs}-[param]-${grid}.gb"
  1208. # To have param numbers including table (173.128 instead of 173)
  1209. # and times in 4 digits (0000 and 0600 instead of 0 and 600),
  1210. # use the following trick given by the mars info messages:
  1211. #
  1212. # In order to get filenames according to MARS values,
  1213. # please, set env. var. MARS_MULTITARGET_STRICT_FORMAT=1
  1214. # before executing your MARS request
  1215. #
  1216. export MARS_MULTITARGET_STRICT_FORMAT=1
  1217. #
  1218. # request could be skipped if all target files are already present;
  1219. # expand the 'targets' to indvidual file and test existence:
  1220. #
  1221. # initially not found:
  1222. notfound=0
  1223. #
  1224. # loop over dates:
  1225. for date in `echo ${dates} | /usr/bin/tr '/' ' '` ; do
  1226. # loop over times:
  1227. for time in `echo ${times} | /usr/bin/tr '/' ' '` ; do
  1228. # adhoc: era2003 (expver=500) starts at 2002-10-31 12:00
  1229. test "${class}-${expver}" = "e4-500" -a ${date} -lt 20021031 && continue
  1230. # adhoc: ml91 spin-up (expver=29) between 2005-09-30 12:00 and 2006-02-01 00:00
  1231. test "${class}-${expver}" = "od-29" -a ${date}${time} -lt 200509301200 && continue
  1232. # adhoc fix to be able to read an fields over [00,24] :
  1233. if [ "${time}" = "2400" ]; then
  1234. xdate=`${bindir}/date_add ${date} 1`
  1235. xtime='0000'
  1236. else
  1237. xdate=${date}
  1238. xtime=${time}
  1239. fi
  1240. # loop over parameters:
  1241. for param in `echo ${params} | /usr/bin/tr '/' ' '` ; do
  1242. # translate param name to grib code:
  1243. mars_param=${param}
  1244. case ${param} in
  1245. CVL ) mars_param=27.128 ;;
  1246. CVH ) mars_param=28.128 ;;
  1247. TVL ) mars_param=29.128 ;;
  1248. TVH ) mars_param=30.128 ;;
  1249. CI ) mars_param=31.128 ;;
  1250. SSTK ) mars_param=34.128 ;;
  1251. SWVL1 ) mars_param=39.128 ;;
  1252. SWVL2 ) mars_param=40.128 ;;
  1253. SWVL3 ) mars_param=41.128 ;;
  1254. SWVL4 ) mars_param=42.128 ;;
  1255. 10FG )
  1256. mars_param=49.128
  1257. # check
  1258. if [ "${class}" == 'od' -a ${date} -ge 20111115 ] ; then
  1259. echo " WARNING : unless you have modified TM5 code, "
  1260. echo " WARNING : you are supposed to request 10FG3. "
  1261. echo " WARNING : It replaces 10FG as variable name for"
  1262. echo " WARNING : the 3-hourly accumulated gust wind."
  1263. exit 1
  1264. fi
  1265. ;;
  1266. 10FG3 )
  1267. mars_param=28.228
  1268. # check
  1269. if [ "${class}" == 'od' -a ${date} -lt 20111115 ] ; then
  1270. echo " WARNING : unless you have modified TM5 code, "
  1271. echo " WARNING : you are supposed to request 10FG. "
  1272. echo " WARNING : It was the variable name for the 3-hourly"
  1273. echo " WARNING : accumulated gust wind before 2011/11/15."
  1274. exit 1
  1275. fi
  1276. ;;
  1277. Z ) mars_param=129.128 ;;
  1278. T ) mars_param=130.128 ;;
  1279. Q ) mars_param=133.128 ;;
  1280. SP ) mars_param=134.128 ;;
  1281. W ) mars_param=135.128 ;;
  1282. VO ) mars_param=138.128 ;;
  1283. STL1 ) mars_param=139.128 ;;
  1284. SD ) mars_param=141.128 ;;
  1285. LSP ) mars_param=142.128 ;;
  1286. CP ) mars_param=143.128 ;;
  1287. SF ) mars_param=144.128 ;;
  1288. SSHF ) mars_param=146.128 ;;
  1289. SLHF ) mars_param=147.128 ;;
  1290. LNSP ) mars_param=152.128 ;;
  1291. D ) mars_param=155.128 ;;
  1292. BLH ) mars_param=159.128 ;;
  1293. 10U ) mars_param=165.128 ;;
  1294. 10V ) mars_param=166.128 ;;
  1295. 2T ) mars_param=167.128 ;;
  1296. 2D ) mars_param=168.128 ;;
  1297. SSRD ) mars_param=169.128 ;;
  1298. STL2 ) mars_param=170.128 ;;
  1299. LSM ) mars_param=172.128 ;;
  1300. SR ) mars_param=173.128 ;;
  1301. AL ) mars_param=174.128 ;;
  1302. STRD ) mars_param=175.128 ;;
  1303. SSR ) mars_param=176.128 ;;
  1304. STR ) mars_param=177.128 ;;
  1305. EWSS ) mars_param=180.128 ;;
  1306. NSSS ) mars_param=181.128 ;;
  1307. STL3 ) mars_param=183.128 ;;
  1308. SRC ) mars_param=198.128 ;;
  1309. TP ) mars_param=228.128 ;;
  1310. LSRH ) mars_param=234.128 ;;
  1311. SKT ) mars_param=235.128 ;;
  1312. STL4 ) mars_param=236.128 ;;
  1313. CLWC ) mars_param=246.128 ;;
  1314. CIWC ) mars_param=247.128 ;;
  1315. CC ) mars_param=248.128 ;;
  1316. # e4 convective fields, local table should have been 162 ...
  1317. 104.128 ) mars_param=104.128 ;;
  1318. 105.128 ) mars_param=105.128 ;;
  1319. 106.128 ) mars_param=106.128 ;;
  1320. 107.128 ) mars_param=107.128 ;;
  1321. # ei convective fields:
  1322. 104.162 ) mars_param=104.162 ;;
  1323. 105.162 ) mars_param=105.162 ;;
  1324. 106.162 ) mars_param=106.162 ;;
  1325. 107.162 ) mars_param=107.162 ;;
  1326. # ei diffusion:
  1327. 109.162 ) mars_param=109.162 ;;
  1328. # macc emissions:
  1329. CH4FIRE ) mars_param='82.210' ;;
  1330. # not supported yet ...
  1331. * )
  1332. err "$prog - no grib code implemented for param '${param}'"
  1333. errit 1
  1334. ;;
  1335. esac
  1336. # target file name:
  1337. fname=`echo ${targets} | /usr/bin/sed -e "s^\[date\]^${xdate}^" -e "s^\[time\]^${xtime}^" -e "s^\[param\]^${mars_param}^"`
  1338. # found ?
  1339. if [ -f ${fname} ]; then
  1340. echo "$prog - found ${fname}"
  1341. # touch to prevent removal because of quota
  1342. test -w ${fname} && touch ${fname}
  1343. else
  1344. echo "$prog - missing ${fname}"
  1345. # at least one file is not found yet,
  1346. # so further testing is not necessary
  1347. notfound=1
  1348. break
  1349. fi
  1350. done # loop over params
  1351. test ${notfound} -gt 0 && break
  1352. done # loop over times
  1353. test ${notfound} -gt 0 && break
  1354. done # loop over dates
  1355. # add mars request ?
  1356. if [ ${notfound} -gt 0 ]; then
  1357. # add line to mars job for each time:
  1358. istep=0
  1359. for time in ${times} ; do
  1360. # next step:
  1361. istep=`/usr/bin/expr ${istep} + 1`
  1362. # corresponding steps etc:
  1363. stepi=`echo ${steps} | /usr/bin/cut -d ' ' -f ${istep}`
  1364. expveri=`echo ${expvers} | /usr/bin/cut -d ' ' -f ${istep}`
  1365. # adhoc fix to be able to read an fields over [00,24] :
  1366. if [ "${time}" = "2400" ]; then
  1367. # next day, one time only:
  1368. xdate=`${bindir}/date_add ${date} 1`
  1369. xtime='0000'
  1370. else
  1371. # just copy:
  1372. xdate=${dates}
  1373. xtime=${time}
  1374. fi
  1375. # add line:
  1376. echo "$prog - add line to mars job for ${xdate} ${xtime} ..."
  1377. echo "retrieve,class=${class},stream=${stream},expver=${expveri},type=${type},date=${xdate},time=${xtime},step=${stepi},levtype=${levtype},param=${params},repres=${repres},target="'"'"${targets}"'"' >> ${mars_jb}
  1378. done
  1379. else
  1380. # all found ...
  1381. echo "$prog - all found for ${ccyymmdd} ..."
  1382. fi
  1383. # next day:
  1384. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  1385. done # loop over days
  1386. set +x
  1387. ;;
  1388. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1389. ncep-cdc:* ) # NCEP RA NetCDF files
  1390. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1391. # year files, valid for valid for [00,24)
  1392. # retrieve previous year if necessary
  1393. case ${mfile} in
  1394. 'lhtfl' )
  1395. test "${mm1}${dd1}${hh1}" -eq "010100" && ccyy1=`/usr/bin/expr ${ccyy1} - 1`
  1396. ;;
  1397. esac
  1398. # loop over years
  1399. ccyy=${ccyy1}
  1400. while [ ${ccyy} -le ${ccyy2} ]; do
  1401. #
  1402. # define filename etc
  1403. #
  1404. #
  1405. # spectral /div .spec .2000.nc
  1406. # spectral /pres.nlog.sfc.spec .2000.nc
  1407. # spectral /vort .spec .2000.nc
  1408. # surface_gauss/lhtfl.sfc .gauss.2000.nc
  1409. # pressure /omega .2000.nc
  1410. #
  1411. ## split in 'ncep-cdc' and keys :
  1412. ##keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1413. #
  1414. ## evaluate keys : mdir=spectral
  1415. ##eval ${keys}
  1416. # file and directory name:
  1417. case ${mfile} in
  1418. 'hgt' | 'land' )
  1419. meteodir='surface_gauss'
  1420. meteofile="${mfile}.sfc.gauss.nc" ;;
  1421. 'sfcr' | 'pres' | 'icec' | 'skt' | 'lhtfl' | 'shtfl' | 'ugwd' | 'vgwd' | 'prate' | 'cprat' )
  1422. meteodir='surface_gauss'
  1423. meteofile="${mfile}.sfc.gauss.${ccyy}.nc" ;;
  1424. 'uwnd.10m' | 'vwnd.10m' )
  1425. meteodir='surface_gauss'
  1426. meteofile="${mfile}.gauss.${ccyy}.nc" ;;
  1427. 'pres.nlog' )
  1428. meteodir='spectral'
  1429. meteofile="${mfile}.sfc.spec.${ccyy}.nc" ;;
  1430. 'vort' | 'div' | 'vair' | 'shum' )
  1431. meteodir='spectral'
  1432. meteofile="${mfile}.spec.${ccyy}.nc" ;;
  1433. * )
  1434. err "$prog - ERROR - unsupported ncep file '${mfile}' ..."
  1435. errit 1 ;;
  1436. esac
  1437. # expand directory:
  1438. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1439. # expand day file:
  1440. meteofile_full="${meteodir}/${meteofile}"
  1441. meteofile_long="${meteodir_long}-${meteofile}"
  1442. # not found yet ...
  1443. found=''
  1444. #
  1445. # present in buffer ?
  1446. #
  1447. # not found yet ?
  1448. if [ -z "${found}" ]; then
  1449. fname=./${meteofile_long}
  1450. #test ${verbose} && echo "$prog - try ${fname}"
  1451. if [ -f ${fname} ]; then
  1452. #test ${verbose} && echo "$prog - found ..."
  1453. test -w ${fname} && touch ${fname}
  1454. found='true'
  1455. fi
  1456. fi # not found yet ...
  1457. #
  1458. # search locations
  1459. #
  1460. # not found yet ?
  1461. if [ -z "${found}" ]; then
  1462. # loop over search locations
  1463. for loc in ${search_locs} ; do
  1464. # *** full file
  1465. fname=${loc}/${meteofile_full}
  1466. test ${verbose} && echo "$prog - try ${fname} ..."
  1467. if ${bindir}/gss exist ${fname} ; then
  1468. # create link in buffer:
  1469. test ${verbose} && echo "$prog - link ..."
  1470. bname=./${meteofile_long}
  1471. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1472. # found !
  1473. found='true'
  1474. break
  1475. fi
  1476. # *** long file
  1477. fname=${loc}/${meteofile_long}
  1478. test ${verbose} && echo "$prog - try ${fname} ..."
  1479. if ${bindir}/gss exist ${fname} ; then
  1480. # create link in buffer:
  1481. test ${verbose} && echo "$prog - link ..."
  1482. bname=./${meteofile_long}
  1483. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1484. # found !
  1485. found='true'
  1486. break
  1487. fi
  1488. done # loop over locations
  1489. fi # not found yet ...
  1490. # not found: error ...
  1491. if [ -z "${found}" ]; then
  1492. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1493. err "$prog - ERROR : directory : `/bin/pwd`"
  1494. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1495. errit 1
  1496. fi
  1497. # next year:
  1498. ccyy=`/usr/bin/expr ${ccyy} + 1`
  1499. done # loop over years
  1500. ;;
  1501. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1502. ncep-gfs:* ) # NCEP GFS binary and grib files
  1503. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1504. # files in directory <ccyymmdd> valid for [12,12]
  1505. test ${hh1} -lt 12 && ccyymmdd1=`${bindir}/date_add ${ccyymmdd1} -1`
  1506. test ${hh2} -lt 12 && ccyymmdd2=`${bindir}/date_add ${ccyymmdd2} -1`
  1507. # loop over days
  1508. ccyymmdd=${ccyymmdd1}
  1509. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  1510. # split current day:
  1511. ccyy=`echo ${ccyymmdd} | /usr/bin/cut -c 1-4`
  1512. mm=`echo ${ccyymmdd} | /usr/bin/cut -c 5-6`
  1513. dd=`echo ${ccyymmdd} | /usr/bin/cut -c 7-8`
  1514. # hour list:
  1515. hours='12.00 12.03 12.06 12.09 12.12 12.15 12.18 12.21 12.24'
  1516. # loop over hours
  1517. for hour in ${hours} ; do
  1518. #
  1519. # define filename etc
  1520. #
  1521. #
  1522. # 20040614/20040614.00.00.SF
  1523. # 20040614/20040614.00.00.SFLUXGrbF
  1524. #
  1525. # split in 'ncep-gfs' and keys :
  1526. #keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1527. # evaluate keys : mdir=spectral
  1528. #eval ${keys}
  1529. # file and directory name:
  1530. meteodir="${ccyy}${mm}${dd}"
  1531. meteofile="${ccyy}${mm}${dd}.${hour}.${mfile}"
  1532. # expand directory:
  1533. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1534. # expand day file:
  1535. meteofile_full="${meteodir}/${meteofile}"
  1536. meteofile_long="${meteodir_long}-${meteofile}"
  1537. # not found yet ...
  1538. found=''
  1539. #
  1540. # present in buffer ?
  1541. #
  1542. # not found yet ?
  1543. if [ -z "${found}" ]; then
  1544. fname=./${meteofile_long}
  1545. #test ${verbose} && echo "$prog - try ${fname}"
  1546. if [ -f ${fname} ]; then
  1547. #test ${verbose} && echo "$prog - found ..."
  1548. test -w ${fname} && touch ${fname}
  1549. found='true'
  1550. fi
  1551. fi # not found yet ...
  1552. #
  1553. # search locations
  1554. #
  1555. # not found yet ?
  1556. if [ -z "${found}" ]; then
  1557. # loop over search locations
  1558. for loc in ${search_locs} ; do
  1559. # *** full file
  1560. fname=${loc}/${meteofile_full}
  1561. test ${verbose} && echo "$prog - try ${fname} ..."
  1562. if ${bindir}/gss exist ${fname} ; then
  1563. # create link in buffer:
  1564. test ${verbose} && echo "$prog - link ..."
  1565. bname=./${meteofile_long}
  1566. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1567. # found !
  1568. found='true'
  1569. break
  1570. fi
  1571. # *** long file
  1572. fname=${loc}/${meteofile_long}
  1573. test ${verbose} && echo "$prog - try ${fname} ..."
  1574. if ${bindir}/gss exist ${fname} ; then
  1575. # create link in buffer:
  1576. test ${verbose} && echo "$prog - link ..."
  1577. bname=./${meteofile_long}
  1578. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1579. # found !
  1580. found='true'
  1581. break
  1582. fi
  1583. done # loop over locations
  1584. fi # not found yet ...
  1585. # not found: error ...
  1586. if [ -z "${found}" ]; then
  1587. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1588. err "$prog - ERROR : directory : `/bin/pwd`"
  1589. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1590. errit 1
  1591. fi
  1592. done # hours
  1593. # next day:
  1594. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  1595. done # loop over days
  1596. ;;
  1597. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1598. msc-data:* ) # MSC data files
  1599. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1600. # loop over days
  1601. ccyymmdd=${ccyymmdd1}
  1602. while [ ${ccyymmdd} -le ${ccyymmdd2} ]; do
  1603. # split current day:
  1604. ccyy=`echo ${ccyymmdd} | /usr/bin/cut -c 1-4`
  1605. mm=`echo ${ccyymmdd} | /usr/bin/cut -c 5-6`
  1606. dd=`echo ${ccyymmdd} | /usr/bin/cut -c 7-8`
  1607. #
  1608. # define filename etc
  1609. #
  1610. # example: msc-data:nlev=71;sh=47;mdir=cmam;tres=_1dag_6hrly
  1611. # default keys:
  1612. mdir='<mdir>'
  1613. tres='<tres>'
  1614. # split in 'msc-data' and keys :
  1615. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1616. # evaluate keys : form=tm5; mdir=od-fc-etc; tres=_21p06
  1617. eval ${keys}
  1618. # define directory and file:
  1619. meteodir=${mdir}'/'${type}
  1620. meteofile="${mfile}_${ccyymmdd}${tres}.dat"
  1621. # expand directory:
  1622. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1623. # expand day file:
  1624. meteofile_full="${meteodir}/${meteofile}"
  1625. meteofile_long="${meteodir_long}-${meteofile}"
  1626. # not found yet ...
  1627. found=''
  1628. #
  1629. # present in buffer ?
  1630. #
  1631. # not found yet ?
  1632. if [ -z "${found}" ]; then
  1633. fname=./${meteofile_long}
  1634. #test ${verbose} && echo "$prog - try ${fname}"
  1635. if [ -f ${fname} ]; then
  1636. #test ${verbose} && echo "$prog - found ..."
  1637. test -w ${fname} && touch ${fname}
  1638. found='true'
  1639. fi
  1640. fi # not found yet ...
  1641. #
  1642. # search locations
  1643. #
  1644. # not found yet ?
  1645. if [ -z "${found}" ]; then
  1646. # loop over search locations
  1647. for loc in ${search_locs} ; do
  1648. # *** full file
  1649. fname=${loc}/${meteofile_full}
  1650. test ${verbose} && echo "$prog - try ${fname} ..."
  1651. if ${bindir}/gss exist ${fname} ; then
  1652. # create link in buffer:
  1653. test ${verbose} && echo "$prog - link ..."
  1654. bname=./${meteofile_long}
  1655. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1656. # found !
  1657. found='true'
  1658. break
  1659. fi
  1660. # *** long file
  1661. fname=${loc}/${meteofile_long}
  1662. test ${verbose} && echo "$prog - try ${fname} ..."
  1663. if ${bindir}/gss exist ${fname} ; then
  1664. # create link in buffer:
  1665. test ${verbose} && echo "$prog - link ..."
  1666. bname=./${meteofile_long}
  1667. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1668. # found !
  1669. found='true'
  1670. break
  1671. fi
  1672. done # loop over locations
  1673. fi # not found yet ...
  1674. # not found: error ...
  1675. if [ -z "${found}" ]; then
  1676. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1677. err "$prog - ERROR : directory : `/bin/pwd`"
  1678. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1679. errit 1
  1680. fi
  1681. # next day:
  1682. ccyymmdd=`${bindir}/date_add ${ccyymmdd} 1`
  1683. done # loop over days
  1684. ;;
  1685. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1686. olsson:* ) # Olsson sr files
  1687. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1688. # month files
  1689. # loop over months
  1690. ccyy=${ccyy1}
  1691. mm=${mm1}
  1692. while [ ${ccyy}${mm} -le ${ccyy2}${mm2} ]; do
  1693. #
  1694. # define filename etc
  1695. #
  1696. # example: olsson:mdir=SR_OLSSON
  1697. # default keys:
  1698. mdir='OLSSON'
  1699. # split in 'olsson' and keys :
  1700. keys=`echo ${msource} | /usr/bin/cut -d ':' -f 2-`
  1701. # evaluate keys : mdir=oSR_OLSSON
  1702. eval ${keys}
  1703. # define directory and file:
  1704. meteodir="${mdir}"
  1705. meteofile="${mfile}_OLSSON_360_180_${mm}.d"
  1706. # expand directory:
  1707. meteodir_long=`echo ${meteodir} | /usr/bin/tr '/' '-'`
  1708. # expand day file:
  1709. meteofile_full="${meteodir}/${meteofile}"
  1710. meteofile_long="${meteodir_long}-${meteofile}"
  1711. # not found yet ...
  1712. found=''
  1713. #
  1714. # present in buffer ?
  1715. #
  1716. # not found yet ?
  1717. if [ -z "${found}" ]; then
  1718. fname=./${meteofile_long}
  1719. #test ${verbose} && echo "$prog - try ${fname}"
  1720. if [ -f ${fname} ]; then
  1721. #test ${verbose} && echo "$prog - found ..."
  1722. test -w ${fname} && touch ${fname}
  1723. found='true'
  1724. fi
  1725. fi # not found yet ...
  1726. #
  1727. # search locations
  1728. #
  1729. # not found yet ?
  1730. if [ -z "${found}" ]; then
  1731. # loop over search locations
  1732. for loc in ${search_locs} ; do
  1733. # *** just file (ie not assumption on parent dir)
  1734. fname=${loc}/${meteofile}
  1735. test ${verbose} && echo "$prog - try ${fname} ..."
  1736. if ${bindir}/gss exist ${fname} ; then
  1737. # create link in buffer:
  1738. test ${verbose} && echo "$prog - link ..."
  1739. bname=./${meteofile_long}
  1740. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1741. # found !
  1742. found='true'
  1743. break
  1744. fi
  1745. # *** full file
  1746. fname=${loc}/${meteofile_full}
  1747. test ${verbose} && echo "$prog - try ${fname} ..."
  1748. if ${bindir}/gss exist ${fname} ; then
  1749. # create link in buffer:
  1750. test ${verbose} && echo "$prog - link ..."
  1751. bname=./${meteofile_long}
  1752. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1753. # found !
  1754. found='true'
  1755. break
  1756. fi
  1757. # *** long file
  1758. fname=${loc}/${meteofile_long}
  1759. test ${verbose} && echo "$prog - try ${fname} ..."
  1760. if ${bindir}/gss exist ${fname} ; then
  1761. # create link in buffer:
  1762. test ${verbose} && echo "$prog - link ..."
  1763. bname=./${meteofile_long}
  1764. ${bindir}/gss ${transfermode} ${fname} ${bname}
  1765. # found !
  1766. found='true'
  1767. break
  1768. fi
  1769. done # loop over locations
  1770. fi # not found yet ...
  1771. # not found: error ...
  1772. if [ -z "${found}" ]; then
  1773. err "$prog - ERROR : do not know how to retrieve meteo file:"
  1774. err "$prog - ERROR : directory : `/bin/pwd`"
  1775. err "$prog - ERROR : meteofile : ${meteofile_long}"
  1776. errit 1
  1777. fi
  1778. # next month:
  1779. mm=`/usr/bin/expr ${mm} + 1`
  1780. if [ ${mm} -gt 12 ]; then
  1781. ccyy=`/usr/bin/expr ${ccyy} + 1`
  1782. mm=1
  1783. fi
  1784. # 2 digits ...
  1785. mm=`/usr/bin/printf '%2.2i' ${mm}`
  1786. done # loop over days
  1787. ;;
  1788. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1789. * ) # unsupported ...
  1790. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1791. err "$prog - ERROR - unsupported source:"
  1792. err "$prog - ERROR - ${msource}"
  1793. errit 1
  1794. ;;
  1795. esac # setup given source
  1796. done # loop over sources
  1797. done # loop over files
  1798. done # loop over sets
  1799. # *************************************
  1800. # step 3 : post
  1801. # *************************************
  1802. # retrieve files from mars ?
  1803. if [ -f ${mars_jb} ]; then
  1804. # clean up ?
  1805. mars_clean='false'
  1806. # mars output file:
  1807. mars_out="`/bin/pwd`/mars.out"
  1808. ## adhoc: keep output files for profiling:
  1809. mars_out="${mars_out}.$$"
  1810. mars_clean=''
  1811. echo "$prog - retrieve files from mars ..."
  1812. echo "$prog - start at `/bin/date`"
  1813. if ( /usr/bin/sort ${mars_jb} | mars > ${mars_out} 2>&1 ) ; then
  1814. echo "$prog - end at `/bin/date`"
  1815. test "${mars_clean}" && /bin/rm -f ${mars_jb} ${mars_out}
  1816. # # force conversion from grib2 to grib1 until grib_api is implemented in TM5
  1817. # if ( hostname | grep c2 ); then
  1818. # echo " editionNumber=1;" > gb2to1
  1819. # for i in *.gb; do
  1820. # # if (grib_dump $i | grep "editionNumber.*=.*2"); then
  1821. # grib_convert -M -G -7 gb2to1 $i dummy
  1822. # mv -f dummy $i
  1823. # # fi
  1824. # done
  1825. # fi
  1826. else
  1827. err "$prog - error from mars request; see:"
  1828. err "$prog - ${mars_out}"
  1829. errit 1
  1830. fi
  1831. fi
  1832. # *************************************
  1833. # step 4 : clean
  1834. # *************************************
  1835. # clean flag ?
  1836. if [ "${tmm_dir_clean}" = "T" ]; then
  1837. # limit disk usage:
  1838. ${bindir}/gss ${verbose} limit ${tmm_dir_size} ${tmm_dir}
  1839. fi
  1840. #
  1841. # back to origin
  1842. #
  1843. cd ${owd}
  1844. # -----------------------------------------------------
  1845. # end
  1846. # -----------------------------------------------------
  1847. test ${verbose} && echo "$prog - end"
  1848. # ok
  1849. exit 0