meteo.F90 287 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715
  1. !### macro's #####################################################
  2. !
  3. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  4. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  5. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  6. !
  7. #include "tm5.inc"
  8. #include "tmm.inc"
  9. !
  10. !------------------------------------------------------------------------------
  11. ! TM5 !
  12. !------------------------------------------------------------------------------
  13. !BOP
  14. !
  15. ! !MODULE: METEO
  16. !
  17. ! !DESCRIPTION: Routines to initialize/finalize meteo grids and data, allocate
  18. ! datasets, and fill them. Include wrappers around read/write
  19. ! meteo files.
  20. ! Perform some meteo dependend calculations (omega, gph,
  21. ! mass <=> pressure, ...)
  22. !
  23. !
  24. ! !REVISION HISTORY:
  25. !
  26. ! 09 Jun 2010 - P. Le Sager
  27. ! - Fix in METEO_SETUP_MASS when reading restart files.
  28. ! - Added some (protex) doc.
  29. ! - Merge updates from EC-Earth project.
  30. !
  31. ! 10 Aug 2010 - Arjo Segers
  32. ! - Reset previous fix since it gives differences after a restart.
  33. ! - Use 'pw_dat' instead of 'mfw_dat' for massflux balancing;
  34. ! otherwise 'mfw_dat' is changed by matching its values in a zoom
  35. ! region with the parent, and this would give tiny differences
  36. ! between a long run and two smaller runs with a restart in between.
  37. ! - Reformatted protex comments.
  38. !
  39. ! 10 Nov 2011 - Ph. Le Sager - adapted for lon-lat MPI domain decomposition
  40. ! 24 Oct 2013 - Ph. Le Sager - 6 new routines for parallel I/O
  41. !
  42. ! !REMARKS:
  43. !
  44. ! (1) Several surface pressure fields are used:
  45. !
  46. ! sp1,sp2 : Surface pressures at begin and end of dynamic time step.
  47. ! Their values are interpolated between surface pressures
  48. ! read from the meteorological archive (in real(4) !)
  49. ! or received from the meteorological model.
  50. ! Fields from the meteorological archive are stored into
  51. ! the 'sp2' structure, and copied from there into 'sp1'.
  52. !
  53. ! sp : Actual surface pressure due to advection.
  54. ! In theory this field is equal to 'sp1' at the begin of a timestep,
  55. ! but due to numerical inacuracies ( real(4) vs real(8) )
  56. ! tiny differeces occur.
  57. ! Therefore, this field is stored and restored in case of restart.
  58. !
  59. ! spm Surface pressure for the mid of the time interval,
  60. ! thus in between 'sp1' and 'sp2' .
  61. !
  62. ! (2) FIXME ZOOM : already coded, just need to check if it works as expected
  63. !
  64. ! !INTERFACE:
  65. !
  66. MODULE METEO
  67. !
  68. ! !USES:
  69. !
  70. use GO, only : gol, goErr, goPr, goLabel
  71. use GO, only : TDate
  72. use partools, only : isRoot
  73. use grid, only : TllGridInfo, TLevelInfo
  74. use tmm, only : TtmMeteo
  75. !
  76. use dims, only : nregions, nregions_all, okdebug
  77. use tm5_distgrid, only : dgrid, Get_DistGrid, GATHER, SCATTER, UPDATE_HALO
  78. use tm5_distgrid, only : SCATTER_J_BAND, SCATTER_I_BAND
  79. USE METEODATA
  80. IMPLICIT NONE
  81. PRIVATE
  82. !
  83. ! !PUBLIC MEMBER FUNCTIONS:
  84. !
  85. public :: Meteo_Init_Grids, Meteo_Done_Grids
  86. public :: Meteo_Init, Meteo_Done, Meteo_Alloc
  87. public :: Meteo_Setup_Mass, Meteo_Setup_Other
  88. public :: Set, Check
  89. public :: TimeInterpolation
  90. !
  91. ! !PRIVATE TYPES:
  92. !
  93. type TMeteoField ! storage for a single meteo field:
  94. logical :: used
  95. character(len=16) :: name
  96. character(len=16) :: unit
  97. integer :: is(2), js(2), ls(2) ! shapes
  98. real, pointer :: data(:,:,:)
  99. end type TMeteoField
  100. !
  101. ! !INTERFACE:
  102. !
  103. #ifdef with_parallel_io_meteo
  104. interface Setup
  105. module procedure Setup_2d_parallel_io
  106. module procedure Setup_3d_parallel_io
  107. end interface
  108. #else
  109. interface Setup
  110. module procedure Setup_2d
  111. module procedure Setup_3d
  112. end interface
  113. #endif
  114. ! Following are not striclty needed, since called here only once each
  115. interface Setup_MFUV
  116. module procedure Setup_MFUV_parallel_io
  117. module procedure Setup_MFUV_serial_io
  118. end interface
  119. interface Setup_MFW
  120. module procedure Setup_MFW_parallel_io
  121. module procedure Setup_MFW_serial_io
  122. end interface
  123. interface Setup_CONVEC
  124. module procedure Setup_CONVEC_parallel_io
  125. module procedure Setup_CONVEC_serial_io
  126. end interface
  127. interface Setup_CLOUDCOVERS
  128. module procedure Setup_CLOUDCOVERS_parallel_io
  129. module procedure Setup_CLOUDCOVERS_serial_io
  130. end interface
  131. interface Setup_DIFFUS
  132. module procedure Setup_DIFFUS_parallel_io
  133. module procedure Setup_DIFFUS_serial_io
  134. end interface
  135. !
  136. ! !PRIVATE DATA MEMBERS:
  137. !
  138. character(len=*), parameter :: mname = 'Meteo'
  139. type(TtmMeteo), save :: tmmd ! interface to TM meteo data
  140. real :: sp_region0(1,1) ! single cell global surface pressure (region 0)
  141. #ifdef with_tmm_tm5
  142. logical, save :: use_tiedtke
  143. #endif
  144. !
  145. !EOP
  146. !------------------------------------------------------------------------
  147. CONTAINS
  148. !--------------------------------------------------------------------------
  149. ! TM5 !
  150. !--------------------------------------------------------------------------
  151. !BOP
  152. !
  153. ! !IROUTINE: METEO_INIT_GRIDS
  154. !
  155. ! !DESCRIPTION: initialize grids and levels for each region. Grids on the
  156. ! local domain are simply copied from the DistGrid object.
  157. !\\
  158. !\\
  159. ! !INTERFACE:
  160. !
  161. SUBROUTINE METEO_INIT_GRIDS( status )
  162. !
  163. ! !USES:
  164. !
  165. use Grid, only : Init
  166. use dims, only : region_name
  167. use dims, only : xbeg, xend, dx, xref, im
  168. use dims, only : ybeg, yend, dy, yref, jm
  169. use dims, only : echlevs, lme, a_ec, b_ec
  170. use geometry, only : geomtryv
  171. !
  172. ! !OUTPUT PARAMETERS:
  173. !
  174. integer, intent(out) :: status
  175. !
  176. ! !REVISION HISTORY:
  177. ! 19 Oct 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  178. !
  179. !EOP
  180. !------------------------------------------------------------------------
  181. !BOC
  182. character(len=*), parameter :: rname = mname//'/Meteo_Init_Grids'
  183. integer :: n
  184. real :: dlon, dlat
  185. ! --- begin ----------------------------
  186. if (okdebug) call goLabel(rname)
  187. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188. ! setup horizontal grids for the 0th one-cell grid
  189. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  190. ! grid spacing:
  191. dlon = real(xend(0)-xbeg(0))/im(0)
  192. dlat = real(yend(0)-ybeg(0))/jm(0)
  193. ! define grid:
  194. call Init( lli(0), xbeg(0)+dlon/2.0, dlon, im(0), &
  195. ybeg(0)+dlat/2.0, dlat, jm(0), status, &
  196. name=trim(region_name(0)) )
  197. IF_NOTOK_RETURN(status=1)
  198. ! zonal grids
  199. dlat = real(yend(0)-ybeg(0))/jm(0)
  200. call Init( lli_z(0), 0.0, 360.0, 1, &
  201. ybeg(0)+dlat/2.0, dlat, jm(0), status, &
  202. name=trim(region_name(0))//'_z' )
  203. IF_NOTOK_RETURN(status=1)
  204. global_lli(0) = lli(0)
  205. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206. ! local horizontal grid : get info from Distributed Grid
  207. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  208. do n=1, nregions_all
  209. call Get_DistGrid( dgrid(n), lli=lli(n), lli_z=lli_z(n), global_lli=global_lli(n) )
  210. ! correct name (it defines file to read data)
  211. lli(n)%name = trim(region_name(n))
  212. lli_z(n)%name = trim(region_name(n))//'_z'
  213. global_lli(n)%name = trim(region_name(n))
  214. end do
  215. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  216. ! level definition
  217. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. ! setup parent level definition:
  219. call Init( levi_ec, lme, a_ec, b_ec, status ) ! ecmwf levels
  220. IF_NOTOK_RETURN(status=1)
  221. ! setup level definition:
  222. call Init( levi, levi_ec, echlevs, status ) ! tm half level selection
  223. IF_NOTOK_RETURN(status=1)
  224. ! determine "old" at, bt of dims module
  225. call geomtryv( )
  226. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  227. ! done
  228. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  229. status = 0
  230. if (okdebug) call goLabel()
  231. END SUBROUTINE METEO_INIT_GRIDS
  232. !EOC
  233. !--------------------------------------------------------------------------
  234. ! TM5 !
  235. !--------------------------------------------------------------------------
  236. !BOP
  237. !
  238. ! !IROUTINE: METEO_DONE_GRIDS
  239. !
  240. ! !DESCRIPTION: finalize all grids and levels used for met fields.
  241. !\\
  242. !\\
  243. ! !INTERFACE:
  244. !
  245. SUBROUTINE METEO_DONE_GRIDS( status )
  246. !
  247. ! !USES:
  248. !
  249. use Grid, only : Done
  250. !
  251. ! !OUTPUT PARAMETERS:
  252. !
  253. integer, intent(out) :: status
  254. !
  255. ! !REVISION HISTORY:
  256. ! 19 Oct 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  257. !
  258. !EOP
  259. !------------------------------------------------------------------------
  260. !BOC
  261. character(len=*), parameter :: rname = mname//'/Meteo_Done_Grids'
  262. integer :: n
  263. ! --- begin --------------------------------
  264. if (okdebug) call goLabel(rname)
  265. ! horizontal (local) and zonal grids
  266. do n = 0, nregions_all
  267. call Done( lli(n), status )
  268. IF_NOTOK_RETURN(status=1)
  269. call Done( lli_z(n), status )
  270. IF_NOTOK_RETURN(status=1)
  271. end do
  272. ! horizontal (global) grids
  273. do n = 1, nregions_all
  274. call Done( global_lli(n), status )
  275. IF_NOTOK_RETURN(status=1)
  276. end do
  277. ! done parent level definition:
  278. call Done( levi_ec, status )
  279. IF_NOTOK_RETURN(status=1)
  280. ! level definition:
  281. call Done( levi, status )
  282. IF_NOTOK_RETURN(status=1)
  283. ! done
  284. status = 0
  285. if (okdebug) call goLabel()
  286. END SUBROUTINE METEO_DONE_GRIDS
  287. !EOC
  288. !--------------------------------------------------------------------------
  289. ! TM5 !
  290. !--------------------------------------------------------------------------
  291. !BOP
  292. !
  293. ! !IROUTINE: METEO_INIT
  294. !
  295. ! !DESCRIPTION: Init met fields, i.e. nullify pointers, store shape, and set
  296. ! if needed (ie used) according to meteo.rc.
  297. !\\
  298. !\\
  299. ! !INTERFACE:
  300. !
  301. SUBROUTINE METEO_INIT( status )
  302. !
  303. ! !USES:
  304. !
  305. use GO, only : TrcFile, Init, Done, ReadRc
  306. use Binas, only : p_global
  307. use TMM, only : Init
  308. use dims, only : im, jm, lm, lmax_conv
  309. use meteodata, only : Init
  310. use global_data, only : rcfile
  311. !
  312. ! !OUTPUT PARAMETERS:
  313. !
  314. integer, intent(out) :: status
  315. !
  316. ! !REVISION HISTORY:
  317. ! 9 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  318. !
  319. !EOP
  320. !------------------------------------------------------------------------
  321. !BOC
  322. character(len=*), parameter :: rname = mname//'/Meteo_Init'
  323. ! --- local -----------------------------
  324. integer :: region, n
  325. integer :: imr, jmr, lmr
  326. integer :: halo
  327. type(TrcFile) :: rcF
  328. integer :: iveg
  329. character(len=4) :: sveg
  330. integer :: i01, i02, j01, j02
  331. ! --- begin ----------------------------
  332. if (okdebug) call goLabel(rname)
  333. ! open rcfile:
  334. call Init( rcF, rcfile, status )
  335. IF_NOTOK_RETURN(status=1)
  336. #ifdef with_tmm_tm5
  337. ! are convection fluxes derived (Tiedtke, sub files) or from IFS (convec files)?
  338. call ReadRc( rcF, 'tiedtke', use_tiedtke, status )
  339. IF_NOTOK_RETURN(status=1)
  340. #endif
  341. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  342. ! meteo database
  343. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  344. ! setup interface to TM meteo:
  345. call Init( tmmd, rcF, status )
  346. IF_NOTOK_RETURN(status=1)
  347. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  348. ! define meteo data
  349. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  350. ! global mean surface pressure
  351. sp_region0 = p_global
  352. ! setup meteo fields: not in use, not allocated:
  353. do region = 1, nregions_all
  354. call Get_DistGrid( dgrid(region), I_STRT=i01, I_STOP=i02, J_STRT=j01, J_STOP=j02 )
  355. lmr = lm(region)
  356. !
  357. ! ** surface pressure *************************************
  358. !
  359. ! two extra horizontal cells
  360. halo = 2
  361. ! end of interval; also reads for sp1 and spm :
  362. call Init_MeteoData( sp2_dat(region), 'sp', 'Pa', &
  363. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  364. rcF, (/'* ','ml','sp'/), region, status )
  365. IF_NOTOK_RETURN(status=1)
  366. ! check time interpolation:
  367. if ( sp2_dat(region)%tinterp(1:6) /= 'interp' ) then
  368. write (gol,'("surface pressure should be interpolated:")'); call goErr
  369. write (gol,'(" requested tinterp : ",a)') trim(sp2_dat(region)%tinterp); call goErr
  370. call goErr; status=1; return
  371. end if
  372. ! start of interval (copied from sp2_dat):
  373. call Init( sp1_dat(region), 'sp', 'Pa', 'computed', &
  374. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  375. 'no-sourcekey', .false., 'no-destkey', status )
  376. IF_NOTOK_RETURN(status=1)
  377. ! current pressure:
  378. call Init( sp_dat(region), 'sp', 'Pa', 'computed', &
  379. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  380. 'no-sourcekey', .false., 'no-destkey', status )
  381. IF_NOTOK_RETURN(status=1)
  382. ! surface pressure at mid of dynamic time interval:
  383. call Init( spm_dat(region), 'sp', 'Pa', 'computed', &
  384. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  385. 'no-sourcekey', .false., 'no-destkey', status )
  386. IF_NOTOK_RETURN(status=1)
  387. !
  388. ! ** 3D pressure and mass **************************
  389. !
  390. ! two extra horizontal cells (same as surface pressures)
  391. halo = 2
  392. ! pressure at half levels (lm+1):
  393. call Init( phlb_dat(region), 'phlb', 'Pa', 'computed', &
  394. (/i01,i02/), (/j01,j02/), halo, (/1,lmr+1/), &
  395. 'no-sourcekey', .false., 'no-destkey', status )
  396. IF_NOTOK_RETURN(status=1)
  397. ! air mass:
  398. call Init( m_dat(region), 'm', 'kg', 'computed', &
  399. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  400. 'no-sourcekey', .false., 'no-destkey', status )
  401. IF_NOTOK_RETURN(status=1)
  402. !
  403. ! ** massfluxes *************************************
  404. !
  405. ! ~~ vertical
  406. ! no extra cells
  407. halo = 0
  408. ! vertical flux (kg/s)
  409. call Init_MeteoData( mfw_dat(region), 'mfw', 'kg/s', &
  410. (/i01,i02/), (/j01,j02/), halo, (/0,lmr/), &
  411. rcF, (/'* ','ml ','mflux_w'/), region, status )
  412. IF_NOTOK_RETURN(status=1)
  413. ! vertical flux (kg/s) : BALANCED
  414. ! NOTE: data is copied from mfw, thus use same tinterp
  415. ! for correct allocation of data arrays
  416. call Init( pw_dat(region), 'pw', 'kg/s', mfw_dat(region)%tinterp, &
  417. (/i01,i02/), (/j01,j02/), halo, (/0,lmr/), &
  418. 'no-sourcekey', .false., 'no-destkey', status )
  419. IF_NOTOK_RETURN(status=1)
  420. ! tendency of surface pressure:
  421. call Init_MeteoData( tsp_dat(region), 'tsp', 'Pa/s', &
  422. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  423. rcF, (/'* ','ml ','mflux_w'/), region, status )
  424. IF_NOTOK_RETURN(status=1)
  425. ! ~~ horizontal
  426. ! NOTE: strange old indexing:
  427. ! pu_tmpp --> pu(0:imr,1:jmr ,1:lmr) in pu_t(0:imr+1,0:jmr+1,0:lmr)
  428. ! ^ ^ ^ ^ too large !
  429. ! pv_tmpp --> pv(1:imr,1:jmr+1,1:lmr) in pv_t(0:imr+1,0:jmr+1,0:lmr)
  430. ! ^ ^ ^ ^ too large !
  431. ! The extra cells are implemented below as halo cells.
  432. ! one extra cell
  433. halo = 1
  434. !! east/west flux (kg/s)
  435. !call Init( mfu_dat(region), 'mfu', 'kg/s', tinterp_curr, &
  436. ! (/0,imr/), (/1,jmr/), halo, (/1,lmr/), &
  437. ! sourcekey_curr, write_meteo, status, default=destkey_curr )
  438. !IF_NOTOK_RETURN(status=1)
  439. !! south/north flux (kg/s)
  440. !call Init( mfv_dat(region), 'mfv', 'kg/s', tinterp_curr, &
  441. ! (/1,imr/), (/0,jmr/), halo, (/1,lmr/), &
  442. ! sourcekey_curr, write_meteo, status, default=destkey_curr )
  443. !IF_NOTOK_RETURN(status=1)
  444. ! east/west flux (kg/s)
  445. call Init_MeteoData( mfu_dat(region), 'mfu', 'kg/s', &
  446. (/i01,i02/), (/j01,j02/), halo, (/0,lmr/), &
  447. rcF, (/'* ','ml ','mflux_uv'/), region, status )
  448. IF_NOTOK_RETURN(status=1)
  449. ! south/north flux (kg/s)
  450. call Init_MeteoData( mfv_dat(region), 'mfv', 'kg/s', &
  451. (/i01,i02/), (/j01,j02/), halo, (/0,lmr/), &
  452. rcF, (/'* ','ml ','mflux_uv'/), region, status )
  453. IF_NOTOK_RETURN(status=1)
  454. !! east/west flux (kg/s) : BALANCED
  455. !call Init( pu_dat(region), 'pu', 'kg/s', 'computed', &
  456. ! (/0,imr/), (/1,jmr/), halo, (/1,lmr/), &
  457. ! 'no-sourcekey', .false., 'no-destkey', status )
  458. !IF_NOTOK_RETURN(status=1)
  459. !
  460. !! south/north flux (kg/s) : BALANCED
  461. !call Init( pv_dat(region), 'pv', 'kg/s', 'computed', &
  462. ! (/1,imr/), (/0,jmr/), halo, (/1,lmr/), &
  463. ! 'no-sourcekey', .false., 'no-destkey', status )
  464. !IF_NOTOK_RETURN(status=1)
  465. halo = 1
  466. ! east/west flux (kg/s) : BALANCED
  467. ! NOTE: data is copied from mfu, thus use same tinterp
  468. ! for correct allocation of data arrays
  469. call Init( pu_dat(region), 'pu', 'kg/s', mfu_dat(region)%tinterp, &
  470. (/i01,i02/), (/j01,j02/), halo, (/0,lmr/), &
  471. 'no-sourcekey', .false., 'no-destkey', status )
  472. IF_NOTOK_RETURN(status=1)
  473. ! south/north flux (kg/s) : BALANCED
  474. ! NOTE: data is copied from mfv, thus use same tinterp
  475. ! for correct allocation of data arrays
  476. call Init( pv_dat(region), 'pv', 'kg/s', mfv_dat(region)%tinterp, &
  477. (/i01,i02/), (/j01,j02/), halo, (/0,lmr/), &
  478. 'no-sourcekey', .false., 'no-destkey', status )
  479. IF_NOTOK_RETURN(status=1)
  480. !
  481. ! ** temperature *************************************
  482. !
  483. ! no extra cells
  484. halo = 0
  485. ! temperature (K) (halo=0)
  486. call Init_MeteoData( temper_dat(region), 'T', 'K', &
  487. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  488. rcF, (/'* ','ml ','temper'/), region, status )
  489. IF_NOTOK_RETURN(status=1)
  490. !
  491. ! ** humidity *************************************
  492. !
  493. ! no extra cells
  494. halo = 0
  495. ! humidity (kg/kg) (halo = 0)
  496. call Init_MeteoData( humid_dat(region), 'Q', 'kg/kg', &
  497. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  498. rcF, (/'* ','ml ','humid'/), region, status )
  499. IF_NOTOK_RETURN(status=1)
  500. !
  501. ! ** computed *************************************
  502. !
  503. halo = 1 ! halo needed for station output in USER_OUTPUT_AEROCOM
  504. ! geopotential height(m) (lm+1, halo=0)
  505. call Init( gph_dat(region), 'gph', 'm', 'computed', &
  506. (/i01,i02/), (/j01,j02/), halo, (/1,lmr+1/), &
  507. 'no-sourcekey', .false., 'no-destkey', status )
  508. IF_NOTOK_RETURN(status=1)
  509. ! no extra cells
  510. halo = 0
  511. ! vertical velocity (Pa/s) (lm+1, halo=0)
  512. call Init( omega_dat(region), 'omega', 'Pa/s', 'computed', &
  513. (/i01,i02/), (/j01,j02/), halo, (/1,lmr+1/), &
  514. 'no-sourcekey', .false., 'no-destkey', status )
  515. IF_NOTOK_RETURN(status=1)
  516. !
  517. ! ** clouds *************************************
  518. !
  519. ! no extra cells
  520. halo = 0
  521. ! lwc liquid water content (kg/kg) (halo=0)
  522. call Init_MeteoData( lwc_dat(region), 'CLWC', 'kg/kg', &
  523. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  524. rcF, (/'* ','ml ','cloud'/), region, status )
  525. IF_NOTOK_RETURN(status=1)
  526. ! iwc ice water content (kg/kg) (halo=0)
  527. call Init_MeteoData( iwc_dat(region), 'CIWC', 'kg/kg', &
  528. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  529. rcF, (/'* ','ml ','cloud'/), region, status )
  530. IF_NOTOK_RETURN(status=1)
  531. ! cc cloud cover (fraction) (halo=0)
  532. call Init_MeteoData( cc_dat(region), 'CC', '1', &
  533. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  534. rcF, (/'* ','ml ','cloud'/), region, status )
  535. IF_NOTOK_RETURN(status=1)
  536. ! cco cloud cover overhead = above bottom of box (fraction) (halo=0)
  537. call Init_MeteoData( cco_dat(region), 'CCO', '1', &
  538. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  539. rcF, (/'* ','ml ','cloud'/), region, status )
  540. IF_NOTOK_RETURN(status=1)
  541. ! ccu cloud cover underfeet = below top of box (fraction) (halo=0)
  542. call Init_MeteoData( ccu_dat(region), 'CCU', '1', &
  543. (/i01,i02/), (/j01,j02/), halo, (/1,lmr/), &
  544. rcF, (/'* ','ml ','cloud'/), region, status )
  545. IF_NOTOK_RETURN(status=1)
  546. !
  547. ! ** convection *************************************
  548. !
  549. ! no extra cells
  550. halo = 0
  551. ! entu entrainement updraft
  552. call Init_MeteoData( entu_dat(region), 'eu', 'kg/m2/s', &
  553. (/i01,i02/), (/j01,j02/), halo, (/1,lmax_conv/), &
  554. rcF, (/'* ','ml ','convec'/), region, status )
  555. IF_NOTOK_RETURN(status=1)
  556. #ifdef with_tmm_tm5
  557. if (.not. use_tiedtke .and.(entu_dat(region)%tinterp(1:4) /= 'aver')) then
  558. write(gol,'("unexpected time interpolation ''",a,"''")') trim(entu_dat(region)%tinterp)
  559. call goErr
  560. TRACEBACK; status=1; return
  561. endif
  562. #endif
  563. ! entd entrainement downdraft (im,jm,lmax_conv)
  564. call Init_MeteoData( entd_dat(region), 'ed', 'kg/m2/s', &
  565. (/i01,i02/), (/j01,j02/), halo, (/1,lmax_conv/), &
  566. rcF, (/'* ','ml ','convec'/), region, status )
  567. IF_NOTOK_RETURN(status=1)
  568. ! detu detrainement updraft
  569. call Init_MeteoData( detu_dat(region), 'du', 'kg/m2/s', &
  570. (/i01,i02/), (/j01,j02/), halo, (/1,lmax_conv/), &
  571. rcF, (/'* ','ml ','convec'/), region, status )
  572. IF_NOTOK_RETURN(status=1)
  573. ! detd detrainement downdraft
  574. call Init_MeteoData( detd_dat(region), 'dd', 'kg/m2/s', &
  575. (/i01,i02/), (/j01,j02/), halo, (/1,lmax_conv/), &
  576. rcF, (/'* ','ml ','convec'/), region, status )
  577. IF_NOTOK_RETURN(status=1)
  578. !
  579. ! ** diffusion *************************************
  580. !
  581. ! no extra cells
  582. halo = 0
  583. ! turbulent diffusion coefficient for heat:
  584. ! dT/dt = d/dz ( Kz dT/dz )
  585. ! defined half levels,
  586. ! probably top of layer is archived (0,..,L-1), implicit zero for surface:
  587. call Init_MeteoData( kzz_dat(region), 'K', 'm2/s', &
  588. (/i01,i02/), (/j01,j02/), halo, (/1,lmr+1/), &
  589. rcF, (/'* ','ml ','diffus'/), region, status )
  590. IF_NOTOK_RETURN(status=1)
  591. !
  592. ! *** surface fields
  593. !
  594. ! no extra cells
  595. halo = 0
  596. ! orography (m*[g])
  597. call Init_MeteoData( oro_dat(region), 'oro', 'm m/s2', &
  598. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  599. rcF, (/'* ','sfc ','sfc.const','sfc.an ','oro '/), region, status )
  600. IF_NOTOK_RETURN(status=1)
  601. ! land/sea mask (%)
  602. call Init_MeteoData( lsmask_dat(region), 'lsm', '%', &
  603. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  604. rcF, (/'* ','sfc ','sfc.const','sfc.an ','lsm '/), region, status )
  605. IF_NOTOK_RETURN(status=1)
  606. ! ~~~ instantaneous fields
  607. ! sea surface temperatue:
  608. call Init_MeteoData( sst_dat(region), 'sst', 'K', &
  609. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  610. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','sst '/), region, status )
  611. IF_NOTOK_RETURN(status=1)
  612. ! 10m u wind (m/s)
  613. call Init_MeteoData( u10m_dat(region), 'u10m', 'm/s', &
  614. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  615. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','u10m '/), region, status )
  616. IF_NOTOK_RETURN(status=1)
  617. ! 10m v wind (m/s)
  618. call Init_MeteoData( v10m_dat(region), 'v10m', 'm/s', &
  619. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  620. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','v10m '/), region, status )
  621. IF_NOTOK_RETURN(status=1)
  622. ! skin reservoir content (m water) ; instant
  623. call Init_MeteoData( src_dat(region), 'src', 'm', &
  624. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  625. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','src '/), region, status )
  626. IF_NOTOK_RETURN(status=1)
  627. ! 2 meter dewpoint temperature (K) ; instant
  628. call Init_MeteoData( d2m_dat(region), 'd2m', 'K', &
  629. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  630. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','d2m '/), region, status )
  631. IF_NOTOK_RETURN(status=1)
  632. ! 2 meter temperature (K) ; instant
  633. call Init_MeteoData( t2m_dat(region), 't2m', 'K', &
  634. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  635. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','t2m '/), region, status )
  636. IF_NOTOK_RETURN(status=1)
  637. ! skin temperature (K) ; instant
  638. call Init_MeteoData( skt_dat(region), 'skt', 'K', &
  639. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  640. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','skt '/), region, status )
  641. IF_NOTOK_RETURN(status=1)
  642. ! boundary layer height (m) ; instant
  643. call Init_MeteoData( blh_dat(region), 'blh', 'm', &
  644. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  645. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','blh '/), region, status )
  646. IF_NOTOK_RETURN(status=1)
  647. ! ~~~ average field (accumulated)
  648. ! surface sensible heat flux (W/m2) ; time aver
  649. call Init_MeteoData( sshf_dat(region), 'sshf', 'W/m2', &
  650. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  651. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','sshf '/), region, status )
  652. IF_NOTOK_RETURN(status=1)
  653. ! surface latent heat flux (W/m2) ; time aver
  654. call Init_MeteoData( slhf_dat(region), 'slhf', 'W/m2', &
  655. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  656. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','slhf '/), region, status )
  657. IF_NOTOK_RETURN(status=1)
  658. ! east-west surface stress (N/m2); time aver
  659. call Init_MeteoData( ewss_dat(region), 'ewss', 'N/m2', &
  660. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  661. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','ewss '/), region, status )
  662. IF_NOTOK_RETURN(status=1)
  663. ! north-south surface stress (N/m2) ; time aver
  664. call Init_MeteoData( nsss_dat(region), 'nsss', 'N/m2', &
  665. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  666. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','nsss '/), region, status )
  667. IF_NOTOK_RETURN(status=1)
  668. halo = 1 ! halo needed for station output in USER_OUTPUT_AEROCOM
  669. ! convective precipitation (m/s) ; time aver
  670. call Init_MeteoData( cp_dat(region), 'cp', 'm/s', &
  671. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  672. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','cp '/), region, status )
  673. IF_NOTOK_RETURN(status=1)
  674. ! large scale stratiform precipitation (m/s) ; time aver
  675. call Init_MeteoData( lsp_dat(region), 'lsp', 'm/s', &
  676. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  677. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','lsp '/), region, status )
  678. IF_NOTOK_RETURN(status=1)
  679. ! no extra cells
  680. halo = 0
  681. ! surface solar radiation ( W/m2 ) ; time aver
  682. call Init_MeteoData( ssr_dat(region), 'ssr', 'W/m2', &
  683. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  684. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','ssr '/), region, status )
  685. IF_NOTOK_RETURN(status=1)
  686. ! surface solar radiation downwards ( W/m2 ) ; time aver
  687. call Init_MeteoData( ssrd_dat(region), 'ssrd', 'W/m2', &
  688. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  689. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','ssrd '/), region, status )
  690. IF_NOTOK_RETURN(status=1)
  691. ! surface thermal radiation ( W/m2 ) ; time aver
  692. call Init_MeteoData( str_dat(region), 'str', 'W/m2', &
  693. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  694. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','str '/), region, status )
  695. IF_NOTOK_RETURN(status=1)
  696. ! surface thermal radiation downwards ( W/m2 ) ; time aver
  697. call Init_MeteoData( strd_dat(region), 'strd', 'W/m2', &
  698. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  699. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','strd '/), region, status )
  700. IF_NOTOK_RETURN(status=1)
  701. ! snow fall (m water eqv); time aver
  702. call Init_MeteoData( sf_dat(region), 'sf', 'm', &
  703. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  704. rcF, (/'* ','sfc ','sfc.aver','sfc.fc ','sf '/), region, status )
  705. IF_NOTOK_RETURN(status=1)
  706. ! ~~~ time averages in grib files tfc+[12,15] etc
  707. ! 10m wind gust (m/s)
  708. call Init_MeteoData( g10m_dat(region), 'g10m', 'm/s', &
  709. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  710. rcF, (/'* ','sfc ','sfc.inst','sfc.fc ','g10m '/), region, status )
  711. IF_NOTOK_RETURN(status=1)
  712. ! ~~~ in tmpp daily averages
  713. ! sea ice:
  714. call Init_MeteoData( ci_dat(region), 'ci', '1', &
  715. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  716. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.fc ','ci '/), region, status )
  717. IF_NOTOK_RETURN(status=1)
  718. ! snow depth (m water eqv); day aver ?
  719. call Init_MeteoData( sd_dat(region), 'sd', 'm', &
  720. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  721. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.fc ','sd '/), region, status )
  722. IF_NOTOK_RETURN(status=1)
  723. ! volumetric soil water layer 1 ( m3 water / m3 soil) ; day aver ?
  724. call Init_MeteoData( swvl1_dat(region), 'swvl1', '1', &
  725. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  726. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.fc ','swvl1 '/), region, status )
  727. IF_NOTOK_RETURN(status=1)
  728. ! soil temperature layer 1 (K)
  729. call Init_MeteoData( stl1_dat(region), 'stl1', 'K', &
  730. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  731. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.fc ','stl1 '/), region, status )
  732. IF_NOTOK_RETURN(status=1)
  733. ! vegetation type (%) ; day aver
  734. do iveg = 1, nveg
  735. write (sveg,'("tv",i2.2)') iveg
  736. call Init_MeteoData( tv_dat(region,iveg), sveg, '%', &
  737. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  738. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.an ','veg '/), region, status )
  739. IF_NOTOK_RETURN(status=1)
  740. end do
  741. ! low vegetation cover (0-1) ; day aver
  742. call Init_MeteoData( cvl_dat(region), 'cvl', '1', &
  743. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  744. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.an ','veg '/), region, status )
  745. IF_NOTOK_RETURN(status=1)
  746. ! high vegetation cover (0-1) ; day aver
  747. call Init_MeteoData( cvh_dat(region), 'cvh', '1', &
  748. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  749. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.an ','veg '/), region, status )
  750. IF_NOTOK_RETURN(status=1)
  751. ! albedo ; daily average
  752. call Init_MeteoData( albedo_dat(region), 'albedo', '1', &
  753. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  754. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.an ','albedo '/), region, status )
  755. IF_NOTOK_RETURN(status=1)
  756. ! surface roughness (ecmwf,ncep)
  757. call Init_MeteoData( sr_ecm_dat(region), 'sr', 'm', &
  758. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  759. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.an ','sr '/), region, status )
  760. IF_NOTOK_RETURN(status=1)
  761. ! ~~~ monthly data
  762. ! surface roughness (olsson) ; monthly
  763. call Init_MeteoData( sr_ols_dat(region), 'srols', 'm', &
  764. (/i01,i02/), (/j01,j02/), halo, (/1,1/), &
  765. rcF, (/'* ','sfc ','sfc.inst','sfc.day ','sfc.an ','srols '/), region, status )
  766. IF_NOTOK_RETURN(status=1)
  767. end do ! regions
  768. ! allocate work arrays for gather/scatter for I/O on grid #1
  769. ! Note : COULD BE that large on ROOT only, and simply (1,1,1) on other
  770. ! processors. Just have to be careful with the setup routines. Commented for zoom.
  771. !PLS allocate( rwork1( im(1), jm(1), 0:lmr+1 ) )
  772. !PLS allocate( rwork2( im(1), jm(1), 0:lmr+1 ) )
  773. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  774. ! done
  775. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  776. ! close rcfile:
  777. call Done( rcF, status )
  778. IF_NOTOK_RETURN(status=1)
  779. ! ok
  780. status = 0
  781. if (okdebug) call goLabel()
  782. END SUBROUTINE METEO_INIT
  783. !EOC
  784. !
  785. ! Read multiple keys in rcfile to setup meteodata structure.
  786. ! The following keys are read:
  787. !
  788. ! meteo.tinterp.<param> <-- time interpolation
  789. ! tmm.sourcekey.<grid>.<param> <-- input file name description
  790. ! tmm.output.<grid>.<param> <-- write meteo ?
  791. ! tmm.destkey.<grid>.<param> <-- output file name description
  792. !
  793. ! where <grid> is first '*' and then set to the grid name,
  794. ! and <param> is set to each of the provided keys.
  795. !
  796. ! Called for region=1..nregions_all
  797. SUBROUTINE INIT_METEODATA( md, name, unit, is, js, halo, ls, &
  798. rcF, rcs, region, status )
  799. use GO, only : TRcFile, ReadRc
  800. use Dims, only : nregions, nregions_max
  801. use MeteoData, only : TMeteoData, Init, Set
  802. ! --- in/out -------------------------------------
  803. type(TMeteoData), intent(out) :: md
  804. character(len=*), intent(in) :: name, unit
  805. integer, intent(in) :: is(2), js(2)
  806. integer, intent(in) :: halo
  807. integer, intent(in) :: ls(2)
  808. type(TRcFile), intent(inout) :: rcF
  809. character(len=*), intent(in) :: rcs(:)
  810. integer, intent(in) :: region
  811. integer, intent(out) :: status
  812. ! --- const --------------------------------------
  813. character(len=*), parameter :: rname = mname//'/Init_MeteoData'
  814. ! --- local -------------------------------------
  815. character(len=10) :: tinterp
  816. character(len=256) :: sourcekey
  817. logical :: write_meteo
  818. character(len=256) :: destkey
  819. logical :: used
  820. ! --- begin -------------------------------------
  821. ! time interpolation :
  822. call ReadRc( rcF, 'meteo.tinterp', rcs, tinterp, status )
  823. IF_NOTOK_RETURN(status=1)
  824. ! source filenames:
  825. call ReadRc( rcF, 'tmm.sourcekey.*', rcs, sourcekey, status, default='no-sourcekey' )
  826. IF_ERROR_RETURN(status=1)
  827. call ReadRc( rcF, 'tmm.sourcekey.'//trim(lli(region)%name), rcs, sourcekey, status, default=sourcekey )
  828. IF_ERROR_RETURN(status=1)
  829. ! write flag:
  830. call ReadRc( rcF, 'tmm.output.*', rcs, write_meteo, status, default=.false. )
  831. IF_ERROR_RETURN(status=1)
  832. call ReadRc( rcF, 'tmm.output.'//trim(lli(region)%name), rcs, write_meteo, status, default=write_meteo )
  833. IF_ERROR_RETURN(status=1)
  834. ! destination filenames:
  835. if ( write_meteo ) then
  836. call ReadRc( rcF, 'tmm.destkey.*', rcs, destkey, status, default='no-destkey' )
  837. IF_ERROR_RETURN(status=1)
  838. call ReadRc( rcF, 'tmm.destkey.'//trim(lli(region)%name), rcs, destkey, status, default=destkey )
  839. IF_ERROR_RETURN(status=1)
  840. else
  841. destkey = 'no-destkey'
  842. end if
  843. ! define meteo data,
  844. ! but should be marked as 'used' to be allocated and filled:
  845. call Init( md, name, unit, tinterp, is, js, halo, ls, &
  846. sourcekey, write_meteo, destkey, status )
  847. IF_NOTOK_RETURN(status=1)
  848. ! read this type of meteo ?
  849. ! only regions 1..nregions or the extra fiels above nregions_max
  850. ! could be in use:
  851. ! [all regions, but do "if test", because nregions may be different from nregions_max]
  852. if ( (region <= nregions) .or. (region > nregions_max) ) then
  853. call ReadRc( rcF, 'meteo.read.*', rcs, used, status, default=.false. )
  854. IF_ERROR_RETURN(status=1)
  855. call ReadRc( rcF, 'meteo.read.'//trim(lli(region)%name), rcs, used, status, default=used )
  856. IF_ERROR_RETURN(status=1)
  857. else
  858. used = .false.
  859. end if
  860. ! in use ?
  861. call Set( md, status, used=used )
  862. IF_NOTOK_RETURN(status=1)
  863. ! ok
  864. status = 0
  865. END SUBROUTINE INIT_METEODATA
  866. ! ***
  867. SUBROUTINE METEO_DONE( status )
  868. use TMM, only : Done
  869. use Dims, only : nregions_all
  870. use meteodata, only : Done
  871. ! --- in/out -------------------------------
  872. integer, intent(out) :: status
  873. ! --- const --------------------------------------
  874. character(len=*), parameter :: rname = mname//'/Meteo_Done'
  875. ! --- local -----------------------------
  876. integer :: n
  877. integer :: iveg
  878. ! --- begin --------------------------------
  879. if (okdebug) call goLabel(rname)
  880. ! interface to TM meteo:
  881. call Done( tmmd, status )
  882. IF_NOTOK_RETURN(status=1)
  883. !
  884. ! done meteo data
  885. !
  886. ! destroy meteo fields:
  887. do n = 1, nregions_all
  888. ! ***
  889. call Done( sp1_dat(n), status )
  890. IF_NOTOK_RETURN(status=1)
  891. call Done( sp2_dat(n), status )
  892. IF_NOTOK_RETURN(status=1)
  893. call Done( sp_dat(n), status )
  894. IF_NOTOK_RETURN(status=1)
  895. call Done( spm_dat(n), status )
  896. IF_NOTOK_RETURN(status=1)
  897. ! ***
  898. call Done( phlb_dat(n), status )
  899. IF_NOTOK_RETURN(status=1)
  900. call Done( m_dat(n), status )
  901. IF_NOTOK_RETURN(status=1)
  902. ! ***
  903. call Done( mfu_dat(n), status )
  904. IF_NOTOK_RETURN(status=1)
  905. call Done( mfv_dat(n), status )
  906. IF_NOTOK_RETURN(status=1)
  907. call Done( mfw_dat(n), status )
  908. IF_NOTOK_RETURN(status=1)
  909. call Done( tsp_dat(n), status )
  910. IF_NOTOK_RETURN(status=1)
  911. call Done( pu_dat(n), status )
  912. IF_NOTOK_RETURN(status=1)
  913. call Done( pv_dat(n), status )
  914. IF_NOTOK_RETURN(status=1)
  915. call Done( pw_dat(n), status )
  916. IF_NOTOK_RETURN(status=1)
  917. ! ***
  918. call Done( temper_dat(n), status )
  919. IF_NOTOK_RETURN(status=1)
  920. call Done( humid_dat(n), status )
  921. IF_NOTOK_RETURN(status=1)
  922. call Done( gph_dat(n), status )
  923. IF_NOTOK_RETURN(status=1)
  924. call Done( omega_dat(n), status )
  925. IF_NOTOK_RETURN(status=1)
  926. ! ***
  927. call Done( lwc_dat(n), status )
  928. IF_NOTOK_RETURN(status=1)
  929. call Done( iwc_dat(n), status )
  930. IF_NOTOK_RETURN(status=1)
  931. call Done( cc_dat(n), status )
  932. IF_NOTOK_RETURN(status=1)
  933. call Done( cco_dat(n), status )
  934. IF_NOTOK_RETURN(status=1)
  935. call Done( ccu_dat(n), status )
  936. IF_NOTOK_RETURN(status=1)
  937. ! ***
  938. call Done( entu_dat(n), status )
  939. IF_NOTOK_RETURN(status=1)
  940. call Done( entd_dat(n), status )
  941. IF_NOTOK_RETURN(status=1)
  942. call Done( detu_dat(n), status )
  943. IF_NOTOK_RETURN(status=1)
  944. call Done( detd_dat(n), status )
  945. IF_NOTOK_RETURN(status=1)
  946. ! ***
  947. call Done( kzz_dat(n), status )
  948. IF_NOTOK_RETURN(status=1)
  949. ! ***
  950. call Done( oro_dat(n), status )
  951. IF_NOTOK_RETURN(status=1)
  952. call Done( lsmask_dat(n), status )
  953. IF_NOTOK_RETURN(status=1)
  954. call Done( albedo_dat(n), status )
  955. IF_NOTOK_RETURN(status=1)
  956. call Done( sr_ecm_dat(n), status )
  957. IF_NOTOK_RETURN(status=1)
  958. call Done( sr_ols_dat(n), status )
  959. IF_NOTOK_RETURN(status=1)
  960. call Done( ci_dat(n), status )
  961. IF_NOTOK_RETURN(status=1)
  962. call Done( sst_dat(n), status )
  963. IF_NOTOK_RETURN(status=1)
  964. call Done( u10m_dat(n), status )
  965. IF_NOTOK_RETURN(status=1)
  966. call Done( v10m_dat(n), status )
  967. IF_NOTOK_RETURN(status=1)
  968. call Done( g10m_dat(n), status )
  969. IF_NOTOK_RETURN(status=1)
  970. call Done( src_dat(n), status )
  971. IF_NOTOK_RETURN(status=1)
  972. call Done( d2m_dat(n), status )
  973. IF_NOTOK_RETURN(status=1)
  974. call Done( t2m_dat(n), status )
  975. IF_NOTOK_RETURN(status=1)
  976. call Done( blh_dat(n), status )
  977. IF_NOTOK_RETURN(status=1)
  978. call Done( sshf_dat(n), status )
  979. IF_NOTOK_RETURN(status=1)
  980. call Done( slhf_dat(n), status )
  981. IF_NOTOK_RETURN(status=1)
  982. call Done( ewss_dat(n), status )
  983. IF_NOTOK_RETURN(status=1)
  984. call Done( nsss_dat(n), status )
  985. IF_NOTOK_RETURN(status=1)
  986. call Done( cp_dat(n), status )
  987. IF_NOTOK_RETURN(status=1)
  988. call Done( lsp_dat(n), status )
  989. IF_NOTOK_RETURN(status=1)
  990. call Done( ssr_dat(n), status )
  991. IF_NOTOK_RETURN(status=1)
  992. call Done( ssrd_dat(n), status )
  993. IF_NOTOK_RETURN(status=1)
  994. call Done( str_dat(n), status )
  995. IF_NOTOK_RETURN(status=1)
  996. call Done( strd_dat(n), status )
  997. IF_NOTOK_RETURN(status=1)
  998. call Done( skt_dat(n), status )
  999. IF_NOTOK_RETURN(status=1)
  1000. call Done( sd_dat(n), status )
  1001. IF_NOTOK_RETURN(status=1)
  1002. call Done( sf_dat(n), status )
  1003. IF_NOTOK_RETURN(status=1)
  1004. call Done( swvl1_dat(n), status )
  1005. IF_NOTOK_RETURN(status=1)
  1006. call Done( stl1_dat(n), status )
  1007. IF_NOTOK_RETURN(status=1)
  1008. do iveg = 1, nveg
  1009. call Done( tv_dat(n,iveg), status )
  1010. IF_NOTOK_RETURN(status=1)
  1011. end do
  1012. call Done( cvl_dat(n), status )
  1013. IF_NOTOK_RETURN(status=1)
  1014. call Done( cvh_dat(n), status )
  1015. IF_NOTOK_RETURN(status=1)
  1016. ! ***
  1017. end do ! regions
  1018. ! work arrays
  1019. !PLS deallocate(rwork1, rwork2)
  1020. ! ok
  1021. status = 0
  1022. if (okdebug) call goLabel()
  1023. END SUBROUTINE METEO_DONE
  1024. ! ***
  1025. SUBROUTINE METEO_ALLOC( status )
  1026. use dims, only : nregions_all
  1027. use meteodata, only : Alloc
  1028. ! --- in/out -------------------------------
  1029. integer, intent(out) :: status
  1030. ! --- const --------------------------------------
  1031. character(len=*), parameter :: rname = mname//'/Meteo_Alloc'
  1032. ! --- local -----------------------------
  1033. integer :: region
  1034. integer :: iveg
  1035. ! --- begin --------------------------------
  1036. if (okdebug) call goLabel(rname)
  1037. ! allocate meteo fields if in use:
  1038. do region = 1, nregions_all
  1039. ! ***
  1040. call Alloc( sp1_dat(region), status )
  1041. IF_NOTOK_RETURN(status=1)
  1042. call Alloc( sp2_dat(region), status )
  1043. IF_NOTOK_RETURN(status=1)
  1044. call Alloc( sp_dat(region), status )
  1045. IF_NOTOK_RETURN(status=1)
  1046. call Alloc( spm_dat(region), status )
  1047. IF_NOTOK_RETURN(status=1)
  1048. ! ***
  1049. call Alloc( phlb_dat(region), status )
  1050. IF_NOTOK_RETURN(status=1)
  1051. call Alloc( m_dat(region), status )
  1052. IF_NOTOK_RETURN(status=1)
  1053. ! ***
  1054. call Alloc( mfu_dat(region), status )
  1055. IF_NOTOK_RETURN(status=1)
  1056. call Alloc( mfv_dat(region), status )
  1057. IF_NOTOK_RETURN(status=1)
  1058. call Alloc( mfw_dat(region), status )
  1059. IF_NOTOK_RETURN(status=1)
  1060. call Alloc( tsp_dat(region), status )
  1061. IF_NOTOK_RETURN(status=1)
  1062. call Alloc( pu_dat(region), status )
  1063. IF_NOTOK_RETURN(status=1)
  1064. call Alloc( pv_dat(region), status )
  1065. IF_NOTOK_RETURN(status=1)
  1066. call Alloc( pw_dat(region), status )
  1067. IF_NOTOK_RETURN(status=1)
  1068. ! ***
  1069. call Alloc( temper_dat(region), status )
  1070. IF_NOTOK_RETURN(status=1)
  1071. call Alloc( humid_dat(region), status )
  1072. IF_NOTOK_RETURN(status=1)
  1073. call Alloc( gph_dat(region), status )
  1074. IF_NOTOK_RETURN(status=1)
  1075. call Alloc( omega_dat(region), status )
  1076. IF_NOTOK_RETURN(status=1)
  1077. ! ***
  1078. call Alloc( lwc_dat(region), status )
  1079. IF_NOTOK_RETURN(status=1)
  1080. call Alloc( iwc_dat(region), status )
  1081. IF_NOTOK_RETURN(status=1)
  1082. call Alloc( cc_dat(region), status )
  1083. IF_NOTOK_RETURN(status=1)
  1084. call Alloc( cco_dat(region), status )
  1085. IF_NOTOK_RETURN(status=1)
  1086. call Alloc( ccu_dat(region), status )
  1087. IF_NOTOK_RETURN(status=1)
  1088. ! ***
  1089. call Alloc( entu_dat(region), status )
  1090. IF_NOTOK_RETURN(status=1)
  1091. call Alloc( entd_dat(region), status )
  1092. IF_NOTOK_RETURN(status=1)
  1093. call Alloc( detu_dat(region), status )
  1094. IF_NOTOK_RETURN(status=1)
  1095. call Alloc( detd_dat(region), status )
  1096. IF_NOTOK_RETURN(status=1)
  1097. ! ***
  1098. call Alloc( kzz_dat(region), status )
  1099. IF_NOTOK_RETURN(status=1)
  1100. ! ***
  1101. call Alloc( oro_dat(region), status )
  1102. IF_NOTOK_RETURN(status=1)
  1103. call Alloc( lsmask_dat(region), status )
  1104. IF_NOTOK_RETURN(status=1)
  1105. call Alloc( albedo_dat(region), status )
  1106. IF_NOTOK_RETURN(status=1)
  1107. call Alloc( sr_ecm_dat(region), status )
  1108. IF_NOTOK_RETURN(status=1)
  1109. call Alloc( sr_ols_dat(region), status )
  1110. IF_NOTOK_RETURN(status=1)
  1111. call Alloc( ci_dat(region), status )
  1112. IF_NOTOK_RETURN(status=1)
  1113. call Alloc( sst_dat(region), status )
  1114. IF_NOTOK_RETURN(status=1)
  1115. call Alloc( u10m_dat(region), status )
  1116. IF_NOTOK_RETURN(status=1)
  1117. call Alloc( v10m_dat(region), status )
  1118. IF_NOTOK_RETURN(status=1)
  1119. call Alloc( src_dat(region), status )
  1120. IF_NOTOK_RETURN(status=1)
  1121. call Alloc( d2m_dat(region), status )
  1122. IF_NOTOK_RETURN(status=1)
  1123. call Alloc( t2m_dat(region), status )
  1124. IF_NOTOK_RETURN(status=1)
  1125. call Alloc( skt_dat(region), status )
  1126. IF_NOTOK_RETURN(status=1)
  1127. call Alloc( blh_dat(region), status )
  1128. IF_NOTOK_RETURN(status=1)
  1129. call Alloc( sshf_dat(region), status )
  1130. IF_NOTOK_RETURN(status=1)
  1131. call Alloc( slhf_dat(region), status )
  1132. IF_NOTOK_RETURN(status=1)
  1133. call Alloc( ewss_dat(region), status )
  1134. IF_NOTOK_RETURN(status=1)
  1135. call Alloc( nsss_dat(region), status )
  1136. IF_NOTOK_RETURN(status=1)
  1137. call Alloc( cp_dat(region), status )
  1138. IF_NOTOK_RETURN(status=1)
  1139. call Alloc( lsp_dat(region), status )
  1140. IF_NOTOK_RETURN(status=1)
  1141. call Alloc( ssr_dat(region), status )
  1142. IF_NOTOK_RETURN(status=1)
  1143. call Alloc( ssrd_dat(region), status )
  1144. IF_NOTOK_RETURN(status=1)
  1145. call Alloc( str_dat(region), status )
  1146. IF_NOTOK_RETURN(status=1)
  1147. call Alloc( strd_dat(region), status )
  1148. IF_NOTOK_RETURN(status=1)
  1149. call Alloc( sd_dat(region), status )
  1150. IF_NOTOK_RETURN(status=1)
  1151. call Alloc( sf_dat(region), status )
  1152. IF_NOTOK_RETURN(status=1)
  1153. call Alloc( g10m_dat(region), status )
  1154. IF_NOTOK_RETURN(status=1)
  1155. call Alloc( swvl1_dat(region), status )
  1156. IF_NOTOK_RETURN(status=1)
  1157. call Alloc( stl1_dat(region), status )
  1158. IF_NOTOK_RETURN(status=1)
  1159. do iveg = 1, nveg
  1160. call Alloc( tv_dat(region,iveg), status )
  1161. IF_NOTOK_RETURN(status=1)
  1162. end do
  1163. call Alloc( cvl_dat(region), status )
  1164. IF_NOTOK_RETURN(status=1)
  1165. call Alloc( cvh_dat(region), status )
  1166. IF_NOTOK_RETURN(status=1)
  1167. ! ***
  1168. end do ! regions
  1169. ! ok
  1170. status = 0
  1171. if (okdebug) call goLabel()
  1172. END SUBROUTINE METEO_ALLOC
  1173. !------------------------------------------------------------------------------
  1174. ! TM5 !
  1175. !------------------------------------------------------------------------------
  1176. !BOP
  1177. !
  1178. ! !IROUTINE: METEO_SETUP_MASS
  1179. !
  1180. ! !DESCRIPTION: Set up Mass FLuxes and Surface Pressures
  1181. !\\
  1182. !\\
  1183. ! !INTERFACE:
  1184. !
  1185. SUBROUTINE METEO_SETUP_MASS( tr1, tr2, status, isfirst, check_pressure )
  1186. !
  1187. ! !USES:
  1188. !
  1189. use go, only : TDate, rTotal, operator(-), wrtgol
  1190. use go, only : IncrDate, operator(+), Get
  1191. use grid, only : Match, TllGridInfo, assignment(=), Done
  1192. use Grid, only : FillMassChange, BalanceMassFluxes, CheckMassBalance
  1193. use dims, only : nregions, im, jm, lm, parent
  1194. use dims, only : xcyc
  1195. use meteodata, only : SetData ! to copy %data and %tr from one MD to another
  1196. #ifdef with_prism
  1197. use meteodata, only : TimeInterpolation
  1198. #endif
  1199. use restart, only : Restart_Read
  1200. !
  1201. ! !INPUT PARAMETERS:
  1202. !
  1203. type(TDate), intent(in) :: tr1, tr2
  1204. !
  1205. ! !OUTPUT PARAMETERS:
  1206. !
  1207. integer, intent(out) :: status
  1208. logical, intent(in), optional :: check_pressure
  1209. logical, intent(in), optional :: isfirst
  1210. !
  1211. ! !REVISION HISTORY:
  1212. !
  1213. ! 12 Mar 2010 - P. Le Sager - Fix when reading restart files. Added
  1214. ! protex doc. Added comments.
  1215. ! 9 Jun 2010 - P. Le Sager - Merged with updates for EC-Earth project.
  1216. !
  1217. ! 10 Aug 2010, Arjo Segers
  1218. ! Reset previous fix since it makes a restart different from a long run.
  1219. ! Use 'pw_dat' instead of 'mfw_dat' since otherwise the later changed
  1220. ! while matching a zoom region with its parent, and this would give
  1221. ! tiny differences during a restart of a zoomed run.
  1222. !
  1223. ! 9 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  1224. !
  1225. ! !REMARKS:
  1226. !
  1227. ! push of Surf Press is done with sp2 (the only one on which we call
  1228. ! setup -ie the only one for which %data1 and %data2 matter). Only %data
  1229. ! of SP and SP1 are updated and used, and not their %data1 and %data2.
  1230. !
  1231. !------------------------------------------------------------------------------
  1232. !EOP
  1233. character(len=*), parameter :: rname = mname//'/Meteo_Setup_Mass'
  1234. logical :: do_check_pressure, WestBorder, NorthBorder
  1235. logical :: do_isfirst
  1236. integer :: n, p
  1237. integer :: idater(6)
  1238. real, allocatable :: dm_dt(:,:,:)
  1239. real :: dt_sec
  1240. integer :: l, i0, i1, j0, j1, is, js, ie, je
  1241. real :: tol_rms, tol_diff
  1242. type(TllGridInfo) :: L_lli
  1243. real, pointer :: field(:,:), field_parent(:,:) ! work arrays
  1244. real, allocatable :: islice(:,:), jslice(:,:), bigIslice(:,:), bigJslice(:,:)
  1245. real, allocatable :: full_pu(:,:,:), full_pv(:,:,:), full_pw(:,:,:), full_dm_dt(:,:,:)
  1246. #ifdef with_prism
  1247. integer :: hour1, dhour
  1248. #endif
  1249. ! only for zoom regions (and only if with advection), when matching wih parents:
  1250. real, allocatable :: field3D_cur(:,:,:), field3D_par(:,:,:),wrkarr1(:,:,:),wrkarr2(:,:,:)
  1251. ! --- begin --------------------------------
  1252. if (okdebug) call goLabel(rname)
  1253. ! check pressure ?
  1254. if ( present(check_pressure) ) then
  1255. do_check_pressure = check_pressure
  1256. else
  1257. do_check_pressure = .false.
  1258. end if
  1259. ! initial call ?
  1260. if ( present(isfirst) ) then
  1261. do_isfirst = isfirst
  1262. else
  1263. do_isfirst = .false.
  1264. end if
  1265. !
  1266. ! ** HORIZONTAL MASS FLUXES *************************************
  1267. !
  1268. do n = 1, nregions_all
  1269. L_lli = global_lli(n)
  1270. ! update horizontal u flux (unbalanced) -
  1271. #ifdef with_parallel_io_meteo
  1272. call Setup_MFUV( n, mfu_dat(n), mfv_dat(n), (/tr1,tr2/), levi, status)
  1273. IF_NOTOK_RETURN(status=1)
  1274. #else
  1275. call Setup_MFUV( n, mfu_dat(n), mfv_dat(n), (/tr1,tr2/), L_lli, levi, status)
  1276. IF_NOTOK_RETURN(status=1)
  1277. #endif
  1278. end do
  1279. !
  1280. ! ** VERTICAL MASS FLUX *************************************
  1281. !
  1282. do n = 1, nregions_all
  1283. L_lli = global_lli(n)
  1284. ! update vertical flux;
  1285. ! tendency of surface pressure is by-product of vertical flux from spectral fields
  1286. ! or filled with zero's
  1287. #ifdef with_parallel_io_meteo
  1288. call Setup_MFW( n, mfw_dat(n), tsp_dat(n), (/tr1,tr2/), 'n', levi, 'w', status)
  1289. IF_NOTOK_RETURN(status=1)
  1290. #else
  1291. call Setup_MFW( n, mfw_dat(n), tsp_dat(n), (/tr1,tr2/), L_lli, 'n', levi, 'w', status)
  1292. IF_NOTOK_RETURN(status=1)
  1293. #endif
  1294. end do
  1295. !
  1296. ! ** SURFACE PRESSURES : SP1, SP *****************************
  1297. !
  1298. REG: do n = 1, nregions_all
  1299. ! skip ?
  1300. if ( .not. sp1_dat(n)%used ) cycle
  1301. L_lli = global_lli(n)
  1302. ! Advance 'next' surface pressure (a/k/a sp2%data) to start of
  1303. ! new interval tr1. If start of a new meteo interval, then data
  1304. ! is automatically read from file, or recieved from coupler
  1305. ! with OASIS/prism
  1306. call Setup( n, sp2_dat(n), (/tr1,tr1/), L_lli, 'n', status )
  1307. IF_NOTOK_RETURN(status=1)
  1308. ! copy SP2 into SP1 (%data and %tr)
  1309. call SetData( sp1_dat(n), sp2_dat(n), status )
  1310. IF_NOTOK_RETURN(status=1)
  1311. ! GATHER sp1 array (dummy if not root)
  1312. !-----------------
  1313. ! ...of parent region, if any:
  1314. if ( n /= 1 ) then
  1315. p = parent(n)
  1316. if (isRoot) then
  1317. allocate( field_parent(im(p), jm(p)) )
  1318. else
  1319. allocate( field_parent(1,1) )
  1320. end if
  1321. call GATHER( dgrid(p), sp1_dat(p)%data(:,:,1), field_parent, sp1_dat(p)%halo, status )
  1322. IF_NOTOK_RETURN(status=1)
  1323. end if
  1324. ! ...of current region:
  1325. if (isRoot) then
  1326. allocate( field(im(n), jm(n)) )
  1327. else
  1328. allocate( field(1,1) )
  1329. end if
  1330. call GATHER( dgrid(n), sp1_dat(n)%data(:,:,1), field, sp1_dat(n)%halo, status )
  1331. IF_NOTOK_RETURN(status=1)
  1332. ! MATCH surface pressures to ensure mass balance
  1333. !-----------------
  1334. if (isRoot) then
  1335. ! IF global field (i.e first region) : match global region with one-cell
  1336. ! world value (average global surface pressure), ELSE match with parent
  1337. if ( n == 1 ) then
  1338. call Match( 'area-aver', 'n', lli(0), sp_region0, &
  1339. global_lli(n), field, status )
  1340. IF_NOTOK_RETURN(status=1)
  1341. else
  1342. call Match( 'area-aver', 'n', global_lli(p), field_parent, &
  1343. global_lli(n), field, status )
  1344. IF_NOTOK_RETURN(status=1)
  1345. endif
  1346. end if
  1347. ! SCATTER sp1 array, and clean
  1348. !-----------------
  1349. call SCATTER( dgrid(n), sp1_dat(n)%data(:,:,1), field, sp1_dat(n)%halo, status )
  1350. IF_NOTOK_RETURN(status=1)
  1351. deallocate(field)
  1352. if (n/=1) deallocate(field_parent)
  1353. ! Set SP
  1354. !-----------------
  1355. ! Initial call ? then set current surface pressure to just
  1356. ! read/advanced sp1.
  1357. ! otherwise, sp remains filled with the advected pressure.
  1358. if ( do_isfirst ) then
  1359. !write (gol,'(" copy SP1 to SP ...")'); call goPr
  1360. !pls ! PLS - (not working in the current OASIS/IFS setup. Kept for reference.
  1361. !pls ! If no_restart and is_first then sp2 is filled with
  1362. !pls ! t+dhour sp. Get SP from SP2 then:
  1363. !pls #ifdef with_prism
  1364. !pls
  1365. !pls select case ( sp2_dat(n)%tinterp )
  1366. !pls case ( 'interp6' ) ; dhour = 6
  1367. !pls case ( 'interp3' ) ; dhour = 3
  1368. !pls case ( 'interp2' ) ; dhour = 2
  1369. !pls case ( 'interp1' ) ; dhour = 1
  1370. !pls case default
  1371. !pls write (gol,'("unsupported time interpolation:")'); call goErr
  1372. !pls write (gol,'(" md%tinterp : ",a)') trim(sp2_dat(n)%tinterp); call goErr
  1373. !pls TRACEBACK; status=1; return
  1374. !pls end select
  1375. !pls dt_sec = dhour * 3600.0 ! sec
  1376. !pls
  1377. !pls sp_dat(n)%data(1:im(n),1:jm(n),1) = &
  1378. !pls sp2_dat(n)%data(1:im(n),1:jm(n),1) - &
  1379. !pls tsp_dat(n)%data(1:im(n),1:jm(n),1) * dt_sec
  1380. !pls
  1381. !pls sp_dat(n)%tr = tr1
  1382. !pls
  1383. !pls ! copy sp into sp1 :
  1384. !pls call SetData( sp1_dat(n), sp_dat(n), status )
  1385. !pls IF_NOTOK_RETURN(status=1)
  1386. !pls
  1387. !pls #else
  1388. ! copy sp1 into sp :
  1389. call SetData( sp_dat(n), sp1_dat(n), status )
  1390. IF_NOTOK_RETURN(status=1)
  1391. !pls #endif
  1392. ! fill pressure and mass from sp
  1393. call Pressure_to_Mass( n, status )
  1394. IF_NOTOK_RETURN(status=1)
  1395. ! eventually replace by fields in restart file, since meteo
  1396. ! from hdf meteo files is in real(4) while computed
  1397. ! pressures and mass are probably in real(8) ;
  1398. ! not for coupled run, since this receives pressures from
  1399. ! ifs.
  1400. #ifndef oasis4
  1401. !#ifndef with_prism
  1402. call Restart_Read( status, surface_pressure=.true., pressure=.true., air_mass=.true. )
  1403. IF_NOTOK_RETURN(status=1)
  1404. !AJS>>> don't do this! sp1 contains data interpolated between
  1405. ! fields received from the archive or the coupled model,
  1406. ! while sp contains the actual pressure after advection.
  1407. !! copy sp into sp1 (PLS, 29-3-2010)
  1408. !call SetData( sp1_dat(n), sp_dat(n), status )
  1409. !IF_NOTOK_RETURN(status=1)
  1410. !<<<
  1411. #endif
  1412. end if ! end first
  1413. !! fill initial pressure and mass arrays,
  1414. !! eventually apply cyclic boundaries to mass
  1415. !call Meteo_SetupMass( n, status )
  1416. !IF_NOTOK_RETURN(status=1)
  1417. ! check 'advected' pressure ?
  1418. if ( do_check_pressure) then
  1419. ! compare 'advected' pressure still in sp with just read
  1420. ! pressure sp1 : diff b/w sp%data and sp1%data
  1421. call Meteo_CheckPressure( n, status )
  1422. IF_NOTOK_RETURN(status=1)
  1423. end if
  1424. END DO REG ! regions
  1425. !
  1426. ! ** SURFACE PRESSURES : SP2 *****************************
  1427. !
  1428. REG2: do n = 1, nregions_all
  1429. ! skip ?
  1430. if ( .not. sp2_dat(n)%used ) cycle
  1431. !write (gol,'("sp2 ",a)') trim(lli(n)%name); call goPr
  1432. ! grid and bounds
  1433. L_lli = global_lli(n)
  1434. i0 = sp2_dat(n)%is(1)
  1435. i1 = sp2_dat(n)%is(2)
  1436. j0 = sp2_dat(n)%js(1)
  1437. j1 = sp2_dat(n)%js(2)
  1438. #ifdef with_prism
  1439. ! sp2 for prism coupler is computed from : sp(t2) = sp(t1) + tsp*(t2-t1)
  1440. if ( sp2_dat(n)%sourcekey(1:6) == 'prism:' ) then
  1441. select case ( sp2_dat(n)%tinterp )
  1442. case ( 'interp6' ) ; dhour = 6
  1443. case ( 'interp3' ) ; dhour = 3
  1444. case ( 'interp2' ) ; dhour = 2
  1445. case ( 'interp1' ) ; dhour = 1
  1446. case default
  1447. write (gol,'("unsupported time interpolation:")'); call goErr
  1448. write (gol,'(" md%tinterp : ",a)') trim(sp2_dat(n)%tinterp); call goErr
  1449. TRACEBACK; status=1; return
  1450. end select
  1451. ! current interval [tr1,tr2] at begin of dhour interval ?
  1452. call Get( tr1, hour=hour1 )
  1453. if ( modulo(hour1,dhour) == 0 ) then
  1454. ! reset sp2_dat%data1 and sp2_dat%data2:
  1455. !PLS ---- original code -----
  1456. !PLS
  1457. !PLS ! o data1 : surface pressure received for tr1
  1458. !PLS write (gol,'(" fill sp2%data1 with prism received field ...")'); call goPr
  1459. !PLS ! set filled flags to false to force re-reading if necessary;
  1460. !PLS ! prism received lnsp fields are stored in cache
  1461. !PLS ! thus re-reading is fast and error-free
  1462. !PLS sp2_dat(n)%filled1 = .false.
  1463. !PLS sp2_dat(n)%filled2 = .false.
  1464. !PLS ! now (re)read :
  1465. !PLS write (gol,'("PLS - (re)setup SP2_dat at ",i2)') tr1%hour; call goPr
  1466. !PLS call Setup( sp2_dat(n), (/tr1,tr1/), lli(n), 'n', status )
  1467. !PLS IF_NOTOK_RETURN(status=1)
  1468. !PLS
  1469. !PLS ! o data2 : data1 + tsp * dhour*3600.0 with dhour 3 or 1 hour
  1470. !PLS write (gol,'(" compute sp2%data2 from sp2%data1 and sp tendency ...")'); call goPr
  1471. !PLS dt_sec = dhour * 3600.0 ! sec
  1472. !PLS sp2_dat(n)%data2(1:im(n),1:jm(n),1) = &
  1473. !PLS sp2_dat(n)%data1(1:im(n),1:jm(n),1) + tsp_dat(n)%data(1:im(n),1:jm(n),1) * dt_sec
  1474. !PLS sp2_dat(n)%tr2 = tr1 + IncrDate(sec=nint(dt_sec))
  1475. !PLS
  1476. !PLS ! o data : interpolation between data1 and data2
  1477. !PLS call wrtgol( ' interpolate sp2%data to : ', tr2 ); call goPr
  1478. !PLS call TimeInterpolation( sp2_dat(n), (/tr2,tr2/), status )
  1479. !PLS IF_NOTOK_RETURN(status=1)
  1480. ! Read into sp2%data1 : surface pressure received for
  1481. ! tr1 (truly tr1+dhour)
  1482. !write (gol,'(" fill sp2%data1 with prism received field ...")'); call goPr
  1483. ! set filled flags to false to force re-reading if necessary;
  1484. ! prism received lnsp fields are stored in cache
  1485. ! thus re-reading is fast and error-free
  1486. !PLS: read sp from prism for t=tr1 into SP2%DATA1. This
  1487. ! is truly sp at t = tr1 + dhour, according to the
  1488. ! coupler settings.
  1489. sp2_dat(n)%filled1 = .false.
  1490. sp2_dat(n)%filled2 = .false.
  1491. call Setup( n, sp2_dat(n), (/tr1,tr1/), L_lli, 'n', status )
  1492. IF_NOTOK_RETURN(status=1)
  1493. ! move %data1 to %data2, and get %data1 from %data2:
  1494. ! data1 = data2 - tsp * dhour*3600.0
  1495. !write (gol,'(" compute sp2%data1 from sp2%data2 and sp tendency ...")'); call goPr
  1496. dt_sec = dhour * 3600.0 ! sec
  1497. sp2_dat(n)%data2(i0:i1,j0:j1,1) = sp2_dat(n)%data1(i0:i1,j0:j1,1)
  1498. sp2_dat(n)%tr2 = tr1 + IncrDate(sec=nint(dt_sec))
  1499. sp2_dat(n)%data1(i0:i1,j0:j1,1) = &
  1500. sp2_dat(n)%data2(i0:i1,j0:j1,1) - tsp_dat(n)%data(i0:i1,j0:j1,1) * dt_sec
  1501. endif ! endif "it is beginning of coupling interval"
  1502. ! Once SP2_DAT contains data1 and data2 valid for a dhour
  1503. ! interval, %data is simply interpolated between %data1 and
  1504. ! %data2:
  1505. !call wrtgol( ' interpolate sp2%data to : ', tr2 ); call goPr
  1506. call TimeInterpolation( sp2_dat(n), (/tr2,tr2/), status )
  1507. IF_NOTOK_RETURN(status=1)
  1508. !pls else
  1509. !pls
  1510. !pls ! sp2_dat contains data1 and data2 valid for a dhour interval;
  1511. !pls ! set %data to interpolation between %data1 and %data2:
  1512. !pls call wrtgol( ' interpolate sp2%data to : ', tr2 ); call goPr
  1513. !pls call TimeInterpolation( sp2_dat(n), (/tr2,tr2/), status )
  1514. !pls IF_NOTOK_RETURN(status=1)
  1515. !pls
  1516. !pls end if
  1517. else
  1518. ! PLS: this one is never used apparently...
  1519. ! AJS: it might be used in a partial coupling with only some fields
  1520. ! exchanged and others read; this was often the case during the
  1521. ! first coupling experiments, and might be useful for testing
  1522. ! advance 'next' surface pressure to end of interval:
  1523. call Setup( n, sp2_dat(n), (/tr2,tr2/), L_lli, 'n', status )
  1524. IF_NOTOK_RETURN(status=1)
  1525. end if ! endif "it is prism sourcekey"
  1526. #else
  1527. ! advance 'next' surface pressure to end of interval:
  1528. call Setup( n, sp2_dat(n), (/tr2,tr2/), L_lli, 'n', status )
  1529. IF_NOTOK_RETURN(status=1)
  1530. #endif /* WITH_PRISM */
  1531. ! GATHER sp2 array (dummy if not root)
  1532. !-----------------
  1533. ! ...of parent region, if any:
  1534. if ( n /= 1 ) then
  1535. p = parent(n)
  1536. if (isRoot) then
  1537. allocate( field_parent(im(p), jm(p)) )
  1538. else
  1539. allocate( field_parent(1,1) )
  1540. end if
  1541. call GATHER( dgrid(p), sp2_dat(p)%data(:,:,1), field_parent, sp2_dat(p)%halo, status )
  1542. IF_NOTOK_RETURN(status=1)
  1543. end if
  1544. ! ...of current region:
  1545. if (isRoot) then
  1546. allocate( field(im(n), jm(n)) )
  1547. else
  1548. allocate( field(1,1) )
  1549. end if
  1550. call GATHER( dgrid(n), sp2_dat(n)%data(:,:,1), field, sp2_dat(n)%halo, status )
  1551. IF_NOTOK_RETURN(status=1)
  1552. ! MATCH surface pressures to ensure mass balance
  1553. !-----------------
  1554. if (isRoot) then
  1555. ! IF global field (i.e first region) : match global region with one-cell
  1556. ! world value (average global surface pressure), ELSE match with parent
  1557. if ( n == 1 ) then
  1558. call Match( 'area-aver', 'n', lli(0), sp_region0, &
  1559. global_lli(n), field, status )
  1560. IF_NOTOK_RETURN(status=1)
  1561. else
  1562. call Match( 'area-aver', 'n', global_lli(p), field_parent, &
  1563. global_lli(n), field, status )
  1564. IF_NOTOK_RETURN(status=1)
  1565. endif
  1566. end if
  1567. ! SCATTER sp2 array, and clean
  1568. !-----------------
  1569. call SCATTER( dgrid(n), sp2_dat(n)%data(:,:,1), field, sp2_dat(n)%halo, status )
  1570. IF_NOTOK_RETURN(status=1)
  1571. deallocate(field)
  1572. if (n/=1) deallocate(field_parent)
  1573. END DO REG2 ! regions
  1574. #ifndef without_advection
  1575. !
  1576. ! ** MASS BALANCE *****************************
  1577. !
  1578. ! NOTE: since only the surface pressure gradient is used,
  1579. ! it is not necessary to use the data1 and data2 arrays
  1580. do n = 1, nregions_all
  1581. ! skip ?
  1582. if ( .not. pu_dat(n)%used ) cycle
  1583. if ( .not. pv_dat(n)%used ) cycle
  1584. if ( .not. pw_dat(n)%used ) cycle
  1585. L_lli = global_lli(n)
  1586. i0 = sp2_dat(n)%is(1)
  1587. i1 = sp2_dat(n)%is(2)
  1588. j0 = sp2_dat(n)%js(1)
  1589. j1 = sp2_dat(n)%js(2)
  1590. ! local indices and tile location (is, ie, js, je must be equal to i0, i1, j0, j1 BTW)
  1591. CALL GET_DISTGRID( dgrid(n), &
  1592. I_STRT=is, I_STOP=ie, &
  1593. J_STRT=js, J_STOP=je, &
  1594. hasWestBorder=WestBorder, hasNorthBorder=NorthBorder)
  1595. ! length of time step between sp1 and sp2:
  1596. dt_sec = rTotal( sp2_dat(n)%tr(1) - sp1_dat(n)%tr(1), 'sec' )
  1597. ! allocate temporary array:
  1598. allocate(dm_dt(i0:i1,j0:j1,lm(n)))
  1599. ! mass change (kg) :
  1600. call FillMassChange( dm_dt, lli(n), levi, &
  1601. sp1_dat(n)%data(i0:i1,j0:j1,1), &
  1602. sp2_dat(n)%data(i0:i1,j0:j1,1), &
  1603. status )
  1604. IF_NOTOK_RETURN(status=1)
  1605. ! mass tendency (kg/s) :
  1606. dm_dt = dm_dt / dt_sec ! kg/s
  1607. ! >>> data1 >>>
  1608. ! initial guess for balanced fluxes are unbalanced fluxes:
  1609. pu_dat(n)%data1 = mfu_dat(n)%data1
  1610. pu_dat(n)%filled1 = mfu_dat(n)%filled1
  1611. pu_dat(n)%tr1 = mfu_dat(n)%tr1
  1612. pv_dat(n)%data1 = mfv_dat(n)%data1
  1613. pv_dat(n)%filled1 = mfv_dat(n)%filled1
  1614. pv_dat(n)%tr1 = mfv_dat(n)%tr1
  1615. pw_dat(n)%data1 = mfw_dat(n)%data1
  1616. pw_dat(n)%filled1 = mfw_dat(n)%filled1
  1617. pw_dat(n)%tr1 = mfw_dat(n)%tr1
  1618. ! MATCH WITH PARENT GRID IF NECESSARY
  1619. ! -----------------------------------
  1620. ! note strange indexing:
  1621. ! pu_dat(n)%data1( 0:im(n), 1:jm(n) , 1:lm(n) )
  1622. ! pv_dat(n)%data1( 1:im(n), 1:jm(n)+1, 1:lm(n) )
  1623. if ( n >1 ) then
  1624. p = parent(n)
  1625. ! gather whole-region arrays
  1626. if (isRoot) then
  1627. allocate(field3D_cur(0:im(n),1:jm(n)+1,lm(n)))
  1628. allocate(field3D_par(0:im(p),1:jm(p)+1,lm(p)))
  1629. allocate(wrkarr1(im(n),jm(n),lm(n)))
  1630. allocate(wrkarr2(im(p),jm(p),lm(p)))
  1631. else
  1632. allocate( field3D_cur(1,1,1) )
  1633. allocate( field3D_par(1,1,1) )
  1634. allocate( wrkarr1(1,1,1) )
  1635. allocate( wrkarr2(1,1,1) )
  1636. end if
  1637. !for slice scattering
  1638. allocate(islice(j0:j1,lm(n)))
  1639. allocate(jslice(i0:i1,lm(n)))
  1640. if (isRoot) then
  1641. allocate(bigIslice(1:jm(n),lm(n)))
  1642. allocate(bigJslice(1:im(n),lm(n)))
  1643. else
  1644. allocate(bigIslice(1,1))
  1645. allocate(bigJslice(1,1))
  1646. end if
  1647. !------- U ----------------
  1648. call GATHER( dgrid(n), pu_dat(n)%data1, wrkarr1, pu_dat(n)%halo, status )
  1649. IF_NOTOK_RETURN(status=1)
  1650. call GATHER( dgrid(p), pu_dat(p)%data1, wrkarr2, pu_dat(p)%halo, status )
  1651. IF_NOTOK_RETURN(status=1)
  1652. if (isRoot) then
  1653. field3D_cur(1:im(n),1:jm(n),:) = wrkarr1
  1654. field3D_cur( 0,1:jm(n),:) = field3D_cur(im(n),1:jm(n),:) ! E-W periodicity
  1655. field3D_par(1:im(p),1:jm(p),:) = wrkarr2
  1656. field3D_par( 0,1:jm(p),:) = field3D_par(im(p),1:jm(p),:) ! E-W periodicity
  1657. do l = 1, lm(n)
  1658. call Match( 'sum', 'u', global_lli(p), field3D_par(0:im(p),1:jm(p),l), &
  1659. global_lli(n), field3D_cur(0:im(n),1:jm(n),l), status )
  1660. IF_NOTOK_RETURN(status=1)
  1661. end do
  1662. end if
  1663. if(isRoot) wrkarr1 = field3D_cur(1:im(n),1:jm(n),:)
  1664. call SCATTER( dgrid(n), pu_dat(n)%data1, wrkarr1, pu_dat(n)%halo, status )
  1665. ! scatter extra column field3D_cur(0,:,:) - needed only for noncyclic
  1666. ! zoom-region, for others update_halo takes care of it [FIXME: could had a
  1667. ! test around these 3 lines ]
  1668. if(isRoot) bigIslice = field3D_cur(0,1:jm(n),:)
  1669. CALL SCATTER_I_BAND( dgrid(n), islice, bigIslice, status, iref=1)
  1670. if(WestBorder)pu_dat(n)%data1(0,j0:j1,:) = islice
  1671. !------- V ----------------
  1672. call GATHER( dgrid(n), pv_dat(n)%data1, wrkarr1, pv_dat(n)%halo, status )
  1673. IF_NOTOK_RETURN(status=1)
  1674. call GATHER( dgrid(p), pv_dat(p)%data1, wrkarr2, pv_dat(p)%halo, status )
  1675. IF_NOTOK_RETURN(status=1)
  1676. if (isRoot) then
  1677. field3D_cur(1:im(n),1:jm(n),:) = wrkarr1
  1678. field3D_cur(1:im(n),jm(n)+1,:) = field3D_cur(1:im(n),1,:) ! donnut periodicity
  1679. field3D_par(1:im(p),1:jm(p),:) = wrkarr2
  1680. field3D_par(1:im(p),jm(p)+1,:) = field3D_par(1:im(p),1,:) ! donnut periodicity
  1681. do l = 1, lm(n)
  1682. call Match( 'sum', 'v', global_lli(p), field3D_par(1:im(p),1:jm(p)+1,l), &
  1683. global_lli(n), field3D_cur(1:im(n),1:jm(n)+1,l), status )
  1684. IF_NOTOK_RETURN(status=1)
  1685. end do
  1686. end if
  1687. if(isRoot) wrkarr1 = field3D_cur(1:im(n),1:jm(n),:)
  1688. call SCATTER( dgrid(n), pv_dat(n)%data1, wrkarr1, pv_dat(n)%halo, status )
  1689. ! scatter extra north row field3D_cur(:,j1+1,:)
  1690. if(isRoot)bigJslice = field3D_cur(:,jm(n)+1,:)
  1691. CALL SCATTER_J_BAND( dgrid(n), jslice, bigJslice, status, jref=jm(n))
  1692. if(NorthBorder)pv_dat(n)%data1(i0:i1,jm(n)+1,:)= jslice
  1693. !------- W ----------------
  1694. call GATHER( dgrid(n), pw_dat(n)%data1, wrkarr1, pw_dat(n)%halo, status )
  1695. IF_NOTOK_RETURN(status=1)
  1696. call GATHER( dgrid(p), pw_dat(p)%data1, wrkarr2, pw_dat(p)%halo, status )
  1697. IF_NOTOK_RETURN(status=1)
  1698. if (isRoot) then
  1699. do l = 0, lm(n)
  1700. call Match( 'sum', 'v', global_lli(p), wrkarr2(1:im(p),1:jm(p),l), &
  1701. global_lli(n), wrkarr1(1:im(n),1:jm(n),l), status )
  1702. IF_NOTOK_RETURN(status=1)
  1703. end do
  1704. end if
  1705. call SCATTER( dgrid(n), pw_dat(n)%data1, wrkarr1, pw_dat(n)%halo, status )
  1706. !----- Done
  1707. deallocate(field3D_cur, field3d_par, wrkarr1, wrkarr2, bigJslice,&
  1708. bigIslice, jslice, islice)
  1709. end if
  1710. !#ifdef with_prism
  1711. ! skip initial mass balance; relative large differences might exist
  1712. ! between pressure imposed by mass fluxes and pressure according to
  1713. ! surface pressure tendencies since the later is based on:
  1714. !
  1715. ! sp(t-1)+tsp(t-1) _ *
  1716. ! _ - o-------* sp(t), sp(t)+tsp(t)
  1717. ! sp(t-1) o
  1718. !
  1719. ! PLS : I do not understand that diagram... tsp is for an
  1720. ! interval, and sp for a point in time. This may be
  1721. ! wrong then. What we had at the first time step was:
  1722. !
  1723. ! sp(t+1)+tsp(t:t+1) _ *
  1724. ! _ - => sp(t) to sp(t)+tsp(t:t+1)
  1725. ! sp(t+1) o
  1726. !
  1727. ! AJS : This describes what the CTM received before the above
  1728. ! described update. The 'tsp' was *not* for an interval but
  1729. ! an instantaneous field describing the 'direction' of the surface
  1730. ! pressure in time (you might call this 'tendency', but that is a
  1731. ! dangerous word in GEMS IFS-CTM coupling context).
  1732. ! Thus, at time 't-1' the only estimate of 'sp(t)' we could make was:
  1733. ! sp(t-1)+tsp(t-1)
  1734. ! At time 't' we received the actual 'sp(t)' and this was of course
  1735. ! different from the initial guess.
  1736. !
  1737. ! PLS : Just need to be sure that we have the correct sp to start
  1738. ! with. Code above has been modified, so that we have:
  1739. !
  1740. ! sp(t)+tsp(t:t+1) _ *
  1741. ! _ - => sp(t) to sp(t)+tsp(t:t+1)
  1742. ! sp(t) o
  1743. !
  1744. !#else
  1745. ! CHECK INITIAL MASS BALANCE:
  1746. ! -----------------------------------
  1747. ! NOTE: strange old indexing:
  1748. ! pu_tmpp --> pu(0:im(n),1:jm(n) ,1:lm(n)) in pu_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1749. ! pv_tmpp --> pv(1:im(n),1:jm(n)+1,1:lm(n)) in pv_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1750. ! tolerance for difference between sp from mass fluxes and sp from tendency:
  1751. tol_rms = 1.0e-4 ! max rms
  1752. tol_diff = 1.0e-3 ! max absolute difference
  1753. CALL UPDATE_HALO( dgrid(n), pu_dat(n)%data1, pu_dat(n)%halo, status)
  1754. IF_NOTOK_RETURN(status=1)
  1755. CALL UPDATE_HALO( dgrid(n), pv_dat(n)%data1, pv_dat(n)%halo, status)
  1756. IF_NOTOK_RETURN(status=1)
  1757. call CheckMassBalance( lli(n), &
  1758. pu_dat(n)%data1(i0-1:i1, j0:j1 , 1:lm(n) ), &
  1759. pv_dat(n)%data1( i0:i1, j0:j1+1, 1:lm(n) ), &
  1760. sp1_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  1761. sp2_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  1762. dt_sec, tol_rms, tol_diff, status )
  1763. if (status/=0) then
  1764. write (gol,'("initial mass imbalance too large for region ",i2)') n; call goErr
  1765. call goErr; status=1; return
  1766. end if
  1767. !#endif
  1768. ! BALANCE HORIZONTAL FLUXES
  1769. ! -----------------------------------
  1770. ! NOTE: strange old indexing:
  1771. ! pu_tmpp --> pu(0:im(n),1:jm(n) ,1:lm(n)) in pu_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1772. ! pv_tmpp --> pv(1:im(n),1:jm(n)+1,1:lm(n)) in pv_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1773. ! needs to be done globally... so gather data
  1774. if (isRoot) then
  1775. allocate(full_pu( 0:im(n), 1:jm(n), 0:lm(n)) ) ! must have same number of levels as mfu
  1776. allocate(full_pv( 1:im(n), 1:jm(n)+1, 0:lm(n)) )
  1777. allocate(full_pw( 1:im(n), 1:jm(n), 0:lm(n)) ) ! used also as temp arr in comm
  1778. allocate(full_dm_dt(im(n), jm(n), lm(n)) )
  1779. else
  1780. allocate( full_pu(1,1,1) )
  1781. allocate( full_pv(1,1,1) )
  1782. allocate( full_pw(1,1,1) )
  1783. allocate( full_dm_dt(1,1,1))
  1784. end if
  1785. !for slice scattering
  1786. allocate(islice(j0:j1,0:lm(n)))
  1787. allocate(jslice(i0:i1,0:lm(n)))
  1788. if (isRoot) then
  1789. allocate(bigIslice(1:jm(n),0:lm(n)))
  1790. allocate(bigJslice(1:im(n),0:lm(n)))
  1791. else
  1792. allocate(bigIslice(1,1))
  1793. allocate(bigJslice(1,1))
  1794. end if
  1795. call GATHER( dgrid(n), pu_dat(n)%data1, full_pw, pu_dat(n)%halo, status )
  1796. IF_NOTOK_RETURN(status=1)
  1797. if (isRoot) then
  1798. full_pu(1:im(n),1:jm(n),:) = full_pw
  1799. full_pu(0,:,:) = full_pu(im(n),:,:) ! East-West periodicity
  1800. end if
  1801. call GATHER( dgrid(n), pv_dat(n)%data1, full_pw, pv_dat(n)%halo, status )
  1802. IF_NOTOK_RETURN(status=1)
  1803. if (isRoot) then
  1804. full_pv(1:im(n),1:jm(n),:) = full_pw
  1805. full_pv(:,jm(n)+1,:) = full_pv(:,1,:) ! donut periodicity
  1806. end if
  1807. call GATHER( dgrid(n), dm_dt, full_dm_dt, 0, status )
  1808. IF_NOTOK_RETURN(status=1)
  1809. call GATHER( dgrid(n), pw_dat(n)%data1, full_pw, pw_dat(n)%halo, status )
  1810. IF_NOTOK_RETURN(status=1)
  1811. if (isRoot) then
  1812. ! PRINT*, "BEFORE BMF:"
  1813. ! print*, minval(full_pu(0:im(n),1:jm(n) ,1:lm(n))), maxval(full_pu(0:im(n),1:jm(n) ,1:lm(n)))
  1814. ! print*, minval(full_pv(1:im(n),1:jm(n)+1,1:lm(n))), maxval(full_pv(1:im(n),1:jm(n)+1,1:lm(n)))
  1815. ! print*, minval(full_pw), maxval(full_pw)
  1816. call BalanceMassFluxes( global_lli(n), &
  1817. full_pu(0:im(n),1:jm(n) ,1:lm(n)), &
  1818. full_pv(1:im(n),1:jm(n)+1,1:lm(n)), &
  1819. full_pw, full_dm_dt, global_lli(parent(n)), dt_sec, status )
  1820. IF_NOTOK_RETURN(status=1)
  1821. ! PRINT*, "AFTER BMF:"
  1822. ! print*, minval(full_pu(0:im(n),1:jm(n) ,1:lm(n))), maxval(full_pu(0:im(n),1:jm(n) ,1:lm(n)))
  1823. ! print*, minval(full_pv(1:im(n),1:jm(n)+1,1:lm(n))), maxval(full_pv(1:im(n),1:jm(n)+1,1:lm(n)))
  1824. ! print*, minval(full_pw), maxval(full_pw)
  1825. end if
  1826. call SCATTER( dgrid(n), pw_dat(n)%data1, full_pw, pw_dat(n)%halo, status )
  1827. IF_NOTOK_RETURN(status=1)
  1828. if(isRoot) full_pw = full_pu(1:im(n),1:jm(n),:)
  1829. call SCATTER( dgrid(n), pu_dat(n)%data1, full_pw, pu_dat(n)%halo, status )
  1830. IF_NOTOK_RETURN(status=1)
  1831. ! scatter extra column full_pu(0,:,:) - needed only for noncyclic zoom
  1832. ! region, for others update_halo takes care of it [FIXME: could had a
  1833. ! test around these 3 lines ]
  1834. if(isRoot) bigIslice = full_pu(0,1:jm(n),:)
  1835. CALL SCATTER_I_BAND( dgrid(n), islice, bigIslice, status, iref=1)
  1836. if(WestBorder)pu_dat(n)%data1(0,j0:j1,0:lm(n)) = islice
  1837. if(isRoot) full_pw = full_pv(1:im(n),1:jm(n),:)
  1838. call SCATTER( dgrid(n), pv_dat(n)%data1, full_pw, pv_dat(n)%halo, status )
  1839. IF_NOTOK_RETURN(status=1)
  1840. ! Scatter PV(:,jm+1,:)
  1841. if(isroot) bigJslice=full_pv(1:im(n),jm(n)+1,:)
  1842. CALL SCATTER_J_BAND( dgrid(n), jslice, bigJslice, status, jref=jm(n))
  1843. if(NorthBorder)pv_dat(n)%data1(i0:i1,jm(n)+1,0:lm(n))=jslice
  1844. ! CHECK FINAL MASS BALANCE:
  1845. ! -----------------------------------
  1846. ! NOTE: strange old indexing:
  1847. ! pu_tmpp --> pu(0:im(n),1:jm(n) ,1:lm(n)) in pu_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1848. ! pv_tmpp --> pv(1:im(n),1:jm(n)+1,1:lm(n)) in pv_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1849. ! tolerance for difference between sp from mass fluxes and sp from tendency:
  1850. tol_rms = 1.0e-7 ! max rms
  1851. tol_diff = 1.0e-6 ! max absolute difference
  1852. CALL UPDATE_HALO( dgrid(n), pu_dat(n)%data1, pu_dat(n)%halo, status)
  1853. IF_NOTOK_RETURN(status=1)
  1854. CALL UPDATE_HALO( dgrid(n), pv_dat(n)%data1, pv_dat(n)%halo, status)
  1855. IF_NOTOK_RETURN(status=1)
  1856. ! print*, "sum before 4", sum(pv_dat(n)%data1(i0:i1, j0+1:j1+1, 1:lm(n)))
  1857. call CheckMassBalance( lli(n), &
  1858. pu_dat(n)%data1(i0-1:i1, j0:j1 , 1:lm(n) ), &
  1859. pv_dat(n)%data1( i0:i1, j0:j1+1, 1:lm(n) ), &
  1860. sp1_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  1861. sp2_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  1862. dt_sec, tol_rms, tol_diff, status )
  1863. if (status/=0) then
  1864. write (gol,'("final mass imbalance too large for region ",i2)') n; call goErr
  1865. call goErr; status=1; return
  1866. end if
  1867. !done
  1868. deallocate(full_pw, full_pu, full_pv, full_dm_dt, bigJslice, bigIslice,&
  1869. jslice, islice)
  1870. ! >>> data2 >>>
  1871. if ( any((/mfu_dat%filled2,mfv_dat%filled2,mfw_dat%filled2/)) ) then
  1872. ! check ...
  1873. if ( .not. all((/mfu_dat(n)%filled2,mfv_dat(n)%filled2,mfw_dat(n)%filled2/)) ) then
  1874. write (gol,'("either none or all secondary data should be in use:")'); call goErr
  1875. write (gol,'(" mfu_dat%filled2 : ",l1)') mfu_dat(n)%filled2; call goErr
  1876. write (gol,'(" mfv_dat%filled2 : ",l1)') mfv_dat(n)%filled2; call goErr
  1877. write (gol,'(" mfw_dat%filled2 : ",l1)') mfw_dat(n)%filled2; call goErr
  1878. call goErr; status=1; return
  1879. end if
  1880. ! initial guess for balanced fluxes are unbalanced fluxes:
  1881. pu_dat(n)%data2 = mfu_dat(n)%data2
  1882. pu_dat(n)%filled2 = .true.
  1883. pu_dat(n)%tr2 = mfu_dat(n)%tr2
  1884. pv_dat(n)%data2 = mfv_dat(n)%data2
  1885. pv_dat(n)%filled2 = .true.
  1886. pv_dat(n)%tr2 = mfv_dat(n)%tr2
  1887. pw_dat(n)%data2 = mfw_dat(n)%data2
  1888. pw_dat(n)%filled2 = .true.
  1889. pw_dat(n)%tr2 = mfw_dat(n)%tr2
  1890. ! MATCH WITH PARENT GRID IF NECESSARY
  1891. ! -----------------------------------
  1892. ! note strange indexing:
  1893. ! pu_dat(n)%data2( 0:im(n), 1:jm(n) , 1:lm(n) )
  1894. ! pv_dat(n)%data2( 1:im(n), 1:jm(n)+1, 1:lm(n) )
  1895. if ( n >1 ) then
  1896. p = parent(n)
  1897. ! gather whole-region arrays
  1898. if (isRoot) then
  1899. allocate(field3D_cur(0:im(n),1:jm(n)+1,lm(n)))
  1900. allocate(field3D_par(0:im(p),1:jm(p)+1,lm(p)))
  1901. allocate(wrkarr1(im(n),jm(n),lm(n)))
  1902. allocate(wrkarr2(im(p),jm(p),lm(p)))
  1903. else
  1904. allocate( field3D_cur(1,1,1) )
  1905. allocate( field3D_par(1,1,1) )
  1906. allocate( wrkarr1(1,1,1) )
  1907. allocate( wrkarr2(1,1,1) )
  1908. end if
  1909. !for slice scattering
  1910. allocate(islice(j0:j1,lm(n)))
  1911. allocate(jslice(i0:i1,lm(n)))
  1912. if (isRoot) then
  1913. allocate(bigIslice(1:jm(n),lm(n)))
  1914. allocate(bigJslice(1:im(n),lm(n)))
  1915. else
  1916. allocate(bigIslice(1,1))
  1917. allocate(bigJslice(1,1))
  1918. end if
  1919. !------- U ----------------
  1920. call GATHER( dgrid(n), pu_dat(n)%data2, wrkarr1, pu_dat(n)%halo, status )
  1921. IF_NOTOK_RETURN(status=1)
  1922. call GATHER( dgrid(p), pu_dat(p)%data2, wrkarr2, pu_dat(p)%halo, status )
  1923. IF_NOTOK_RETURN(status=1)
  1924. if (isRoot) then
  1925. field3D_cur(1:im(n),1:jm(n),:) = wrkarr1
  1926. field3D_cur( 0,1:jm(n),:) = field3D_cur(im(n),1:jm(n),:) ! E-W periodicity
  1927. field3D_par(1:im(p),1:jm(p),:) = wrkarr2
  1928. field3D_par( 0,1:jm(p),:) = field3D_par(im(p),1:jm(p),:) ! E-W periodicity
  1929. do l = 1, lm(n)
  1930. call Match( 'sum', 'u', global_lli(p), field3D_par(0:im(p),1:jm(p),l), &
  1931. global_lli(n), field3D_cur(0:im(n),1:jm(n),l), status )
  1932. IF_NOTOK_RETURN(status=1)
  1933. end do
  1934. end if
  1935. if(isRoot) wrkarr1 = field3D_cur(1:im(n),1:jm(n),:)
  1936. call SCATTER( dgrid(n), pu_dat(n)%data2, wrkarr1, pu_dat(n)%halo, status )
  1937. ! scatter extra column field3D_cur(0,:,:) - needed only for non-cyclic
  1938. ! zoom-region, for others update_halo takes care of it [FIXME: could had a
  1939. ! test around these 3 lines ]
  1940. if(isRoot) bigIslice = field3D_cur(0,1:jm(n),:)
  1941. CALL SCATTER_I_BAND( dgrid(n), islice, bigIslice, status, iref=1)
  1942. if(WestBorder)pu_dat(n)%data2(0,j0:j1,:) = islice
  1943. !------- V ----------------
  1944. call GATHER( dgrid(n), pv_dat(n)%data2, wrkarr1, pv_dat(n)%halo, status )
  1945. IF_NOTOK_RETURN(status=1)
  1946. call GATHER( dgrid(p), pv_dat(p)%data2, wrkarr2, pv_dat(p)%halo, status )
  1947. IF_NOTOK_RETURN(status=1)
  1948. if (isRoot) then
  1949. field3D_cur(1:im(n),1:jm(n),:) = wrkarr1
  1950. field3D_cur(1:im(n),jm(n)+1,:) = field3D_cur(1:im(n),1,:) ! donnut periodicity
  1951. field3D_par(1:im(p),1:jm(p),:) = wrkarr2
  1952. field3D_par(1:im(p),jm(p)+1,:) = field3D_par(1:im(p),1,:) ! donnut periodicity
  1953. do l = 1, lm(n)
  1954. call Match( 'sum', 'v', global_lli(p), field3D_par(1:im(p),1:jm(p)+1,l), &
  1955. global_lli(n), field3D_cur(1:im(n),1:jm(n)+1,l), status )
  1956. IF_NOTOK_RETURN(status=1)
  1957. end do
  1958. end if
  1959. if(isRoot) wrkarr1 = field3D_cur(1:im(n),1:jm(n),:)
  1960. call SCATTER( dgrid(n), pv_dat(n)%data2, wrkarr1, pv_dat(n)%halo, status )
  1961. ! scatter extra north row field3D_cur(:,j1+1,:)
  1962. if(isRoot)bigJslice = field3D_cur(:,jm(n)+1,:)
  1963. CALL SCATTER_J_BAND( dgrid(n), jslice, bigJslice, status, jref=jm(n))
  1964. if(NorthBorder)pv_dat(n)%data2(i0:i1,jm(n)+1,:)= jslice
  1965. !------- W ----------------
  1966. call GATHER( dgrid(n), pw_dat(n)%data2, wrkarr1, pw_dat(n)%halo, status )
  1967. IF_NOTOK_RETURN(status=1)
  1968. call GATHER( dgrid(p), pw_dat(p)%data2, wrkarr2, pw_dat(p)%halo, status )
  1969. IF_NOTOK_RETURN(status=1)
  1970. if (isRoot) then
  1971. do l = 0, lm(n)
  1972. call Match( 'sum', 'v', global_lli(p), wrkarr2(1:im(p),1:jm(p),l), &
  1973. global_lli(n), wrkarr1(1:im(n),1:jm(n),l), status )
  1974. IF_NOTOK_RETURN(status=1)
  1975. end do
  1976. end if
  1977. call SCATTER( dgrid(n), pw_dat(n)%data2, wrkarr1, pw_dat(n)%halo, status )
  1978. !----- Done
  1979. deallocate(field3D_cur, field3d_par, wrkarr1, wrkarr2, bigJslice,&
  1980. bigIslice, jslice, islice)
  1981. end if
  1982. ! CHECK INITIAL MASS BALANCE:
  1983. ! -----------------------------------
  1984. ! NOTE: strange old indexing:
  1985. ! pu_tmpp --> pu(0:im(n),1:jm(n) ,1:lm(n)) in pu_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1986. ! pv_tmpp --> pv(1:im(n),1:jm(n)+1,1:lm(n)) in pv_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  1987. CALL UPDATE_HALO( dgrid(n), pu_dat(n)%data2, pu_dat(n)%halo, status)
  1988. IF_NOTOK_RETURN(status=1)
  1989. CALL UPDATE_HALO( dgrid(n), pv_dat(n)%data2, pv_dat(n)%halo, status)
  1990. IF_NOTOK_RETURN(status=1)
  1991. call CheckMassBalance( lli(n), &
  1992. pu_dat(n)%data2(i0-1:i1, j0:j1 , 1:lm(n) ), &
  1993. pv_dat(n)%data2( i0:i1, j0:j1+1, 1:lm(n) ), &
  1994. sp1_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  1995. sp2_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  1996. dt_sec, 1.0e-4, 1.0e-3, status )
  1997. if (status/=0) then
  1998. write (gol,'("initial mass imbalance too large for region ",i2)') n; call goErr
  1999. call goErr; status=1; return
  2000. end if
  2001. ! BALANCE HORIZONTAL FLUXES
  2002. ! -----------------------------------
  2003. ! balance horizontal fluxes:
  2004. ! NOTE: strange old indexing:
  2005. ! pu_tmpp --> pu(0:im(n),1:jm(n) ,1:lm(n)) in pu_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  2006. ! pv_tmpp --> pv(1:im(n),1:jm(n)+1,1:lm(n)) in pv_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  2007. if (isRoot) then
  2008. allocate(full_pu( 0:im(n), 1:jm(n), 0:lm(n)) ) ! must have same number of levels as mfu
  2009. allocate(full_pv( 1:im(n), 1:jm(n)+1, 0:lm(n)) )
  2010. allocate(full_pw( 1:im(n), 1:jm(n), 0:lm(n)) ) ! used also as temp arr in comm
  2011. allocate(full_dm_dt(im(n), jm(n), lm(n)) )
  2012. else
  2013. allocate( full_pu(1,1,1) )
  2014. allocate( full_pv(1,1,1) )
  2015. allocate( full_pw(1,1,1) )
  2016. allocate( full_dm_dt(1,1,1))
  2017. end if
  2018. !for slice scattering
  2019. allocate(islice(j0:j1,0:lm(n)))
  2020. allocate(jslice(i0:i1,0:lm(n)))
  2021. if (isRoot) then
  2022. allocate(bigIslice(1:jm(n),0:lm(n)))
  2023. allocate(bigJslice(1:im(n),0:lm(n)))
  2024. else
  2025. allocate(bigIslice(1,1))
  2026. allocate(bigJslice(1,1))
  2027. end if
  2028. call GATHER( dgrid(n), pu_dat(n)%data2, full_pw, pu_dat(n)%halo, status )
  2029. IF_NOTOK_RETURN(status=1)
  2030. if (isRoot) then
  2031. full_pu(1:im(n),1:jm(n),:) = full_pw
  2032. full_pu(0,:,:) = full_pu(im(n),:,:) ! East-West periodicity
  2033. end if
  2034. call GATHER( dgrid(n), pv_dat(n)%data2, full_pw, pv_dat(n)%halo, status )
  2035. IF_NOTOK_RETURN(status=1)
  2036. if (isRoot) then
  2037. full_pv(1:im(n),1:jm(n),:) = full_pw
  2038. full_pv(:,jm(n)+1,:) = full_pv(:,1,:) ! donut periodicity
  2039. end if
  2040. call GATHER( dgrid(n), dm_dt, full_dm_dt, 0, status )
  2041. IF_NOTOK_RETURN(status=1)
  2042. call GATHER( dgrid(n), pw_dat(n)%data2, full_pw, pw_dat(n)%halo, status )
  2043. IF_NOTOK_RETURN(status=1)
  2044. if (isRoot) then
  2045. call BalanceMassFluxes( global_lli(n), &
  2046. full_pu(0:im(n),1:jm(n) ,1:lm(n)), &
  2047. full_pv(1:im(n),1:jm(n)+1,1:lm(n)), &
  2048. full_pw, full_dm_dt, global_lli(parent(n)), dt_sec, status )
  2049. IF_NOTOK_RETURN(status=1)
  2050. end if
  2051. call SCATTER( dgrid(n), pw_dat(n)%data2, full_pw, pw_dat(n)%halo, status )
  2052. IF_NOTOK_RETURN(status=1)
  2053. if(isRoot) full_pw = full_pu(1:im(n),1:jm(n),:)
  2054. call SCATTER( dgrid(n), pu_dat(n)%data2, full_pw, pu_dat(n)%halo, status )
  2055. IF_NOTOK_RETURN(status=1)
  2056. ! scatter extra column full_pu(0,:,:) - needed only for noncyclic zoom
  2057. ! regions, for others update_halo takes care of it [FIXME: could had a
  2058. ! test around these 3 lines ]
  2059. if(isRoot) bigIslice = full_pu(0,1:jm(n),:)
  2060. CALL SCATTER_I_BAND( dgrid(n), islice, bigIslice, status, iref=1)
  2061. if(WestBorder) pu_dat(n)%data2(0,j0:j1,:) = islice
  2062. if(isRoot) full_pw = full_pv(1:im(n),1:jm(n),:)
  2063. call SCATTER( dgrid(n), pv_dat(n)%data2, full_pw, pv_dat(n)%halo, status )
  2064. IF_NOTOK_RETURN(status=1)
  2065. ! Scatter PV(:,jm+1,:)
  2066. if(isroot) bigJslice=full_pv(1:im(n),jm(n)+1,:)
  2067. CALL SCATTER_J_BAND( dgrid(n), jslice, bigJslice, status, jref=jm(n))
  2068. if(NorthBorder)pv_dat(n)%data2(i0:i1,jm(n)+1,:)=jslice
  2069. ! CHECK FINAL MASS BALANCE:
  2070. ! -----------------------------------
  2071. ! NOTE: strange old indexing:
  2072. ! pu_tmpp --> pu(0:im(n),1:jm(n) ,1:lm(n)) in pu_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  2073. ! pv_tmpp --> pv(1:im(n),1:jm(n)+1,1:lm(n)) in pv_t(0:im(n)+1,0:jm(n)+1,0:lm(n))
  2074. CALL UPDATE_HALO( dgrid(n), pu_dat(n)%data2, pu_dat(n)%halo, status)
  2075. IF_NOTOK_RETURN(status=1)
  2076. CALL UPDATE_HALO( dgrid(n), pv_dat(n)%data2, pv_dat(n)%halo, status)
  2077. IF_NOTOK_RETURN(status=1)
  2078. call CheckMassBalance( lli(n), &
  2079. pu_dat(n)%data2(i0-1:i1, j0:j1 , 1:lm(n) ), &
  2080. pv_dat(n)%data2( i0:i1, j0:j1+1, 1:lm(n) ), &
  2081. sp1_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  2082. sp2_dat(n)%data ( i0:i1, j0:j1 , 1 ), &
  2083. dt_sec, 1.0e-7, 1.0e-6, status )
  2084. if (status/=0) then
  2085. write (gol,'("final mass imbalance too large for region ",i2)') n; call goErr
  2086. call goErr; status=1; return
  2087. end if
  2088. deallocate(full_pw, full_pu, full_pv, full_dm_dt, bigJslice, bigIslice,&
  2089. jslice, islice)
  2090. end if ! filled2
  2091. ! >>>
  2092. ! clear
  2093. deallocate( dm_dt )
  2094. end do ! regions
  2095. #endif /* ADVECTION */
  2096. !------------
  2097. ! Done
  2098. !------------
  2099. call done(l_lli, status)
  2100. IF_NOTOK_RETURN(status=1)
  2101. status = 0
  2102. if (okdebug) call goLabel()
  2103. END SUBROUTINE METEO_SETUP_MASS
  2104. !--------------------------------------------------------------------------
  2105. ! TM5 !
  2106. !--------------------------------------------------------------------------
  2107. !BOP
  2108. !
  2109. ! !IROUTINE: METEO_SETUP_OTHER
  2110. !
  2111. ! !DESCRIPTION:
  2112. !\\
  2113. !\\
  2114. ! !INTERFACE:
  2115. !
  2116. SUBROUTINE METEO_SETUP_OTHER( tr1, tr2, status, isfirst )
  2117. !
  2118. ! !USES:
  2119. !
  2120. use GO, only : TDate, NewDate, rTotal, wrtgol
  2121. use GO, only : operator(-), operator(+), operator(/)
  2122. use GO, only : InterpolFractions
  2123. use dims, only : nregions, im, jm, lm
  2124. use dims, only : lmax_conv
  2125. use dims, only : xcyc
  2126. use Dims, only : czeta
  2127. use global_data, only : region_dat
  2128. #ifndef without_convection
  2129. use global_data, only : conv_dat
  2130. #endif
  2131. use Phys, only : ConvCloudDim
  2132. !
  2133. ! !INPUT PARAMETERS:
  2134. !
  2135. type(TDate), intent(in) :: tr1, tr2
  2136. logical, intent(in), optional :: isfirst
  2137. !
  2138. ! !OUTPUT PARAMETERS:
  2139. !
  2140. integer, intent(out) :: status
  2141. !
  2142. ! !REVISION HISTORY:
  2143. ! 9 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  2144. !
  2145. !EOP
  2146. !------------------------------------------------------------------------
  2147. !BOC
  2148. character(len=*), parameter :: rname = mname//'/Meteo_Setup_Other'
  2149. logical :: do_isfirst
  2150. integer :: n, p
  2151. integer :: i, j, l
  2152. integer :: lsave, i0, i1, j0, j1
  2153. real :: tote, totd, maxe
  2154. real, pointer :: dxyp(:)
  2155. type(TDate) :: tmid
  2156. real :: alfa1, alfa2
  2157. integer :: iveg
  2158. ! --- begin --------------------------------
  2159. if (okdebug) call goLabel(rname)
  2160. ! initial call ?
  2161. if ( present(isfirst) ) then
  2162. do_isfirst = isfirst
  2163. else
  2164. do_isfirst = .false.
  2165. end if
  2166. !
  2167. ! ** orography *****************************
  2168. !
  2169. ! read orographies (if necessary):
  2170. do n = 1, nregions_all
  2171. call setup( n, oro_dat(n), (/tr1,tr2/), global_lli(n), 'n', status )
  2172. IF_NOTOK_RETURN(status=1)
  2173. end do
  2174. !
  2175. ! ** spm **************************************
  2176. !
  2177. ! loop over regions:
  2178. do n = 1, nregions
  2179. ! skip ?
  2180. if ( .not. spm_dat(n)%used ) cycle
  2181. !write (gol,'("spm ",a)') trim(lli(n)%name); call goPr
  2182. ! mid time:
  2183. tmid = tr1 + ( tr2 - tr1 )/2
  2184. ! deterimine weights to sp1 and sp2 :
  2185. call InterpolFractions( tmid, sp1_dat(n)%tr(1), sp2_dat(n)%tr(1), alfa1, alfa2, status )
  2186. IF_NOTOK_RETURN(status=1)
  2187. call Get_DistGrid( dgrid(n), I_STRT=i0, I_STOP=i1, J_STRT=j0, J_STOP=j1 )
  2188. ! interpolate:
  2189. spm_dat(n)%data(i0:i1,j0:j1,1) = alfa1 * sp1_dat(n)%data(i0:i1,j0:j1,1) + &
  2190. alfa2 * sp2_dat(n)%data(i0:i1,j0:j1,1)
  2191. ! store time:
  2192. spm_dat(n)%tr = (/tr1,tr2/)
  2193. end do ! regions
  2194. !
  2195. ! ** omega **************************************
  2196. !
  2197. ! loop over regions:
  2198. do n = 1, nregions_all
  2199. !if (omega_dat(n)%used) then; write (gol,'("omega ",a)') trim(lli(n)%name); call goPr; end if
  2200. ! re-compute omega from vertical mass flux:
  2201. call Compute_Omega( omega_dat(n), lli(n), mfw_dat(n), status )
  2202. IF_NOTOK_RETURN(status=1)
  2203. end do ! regions
  2204. !
  2205. ! ** temperature and humid **************************************
  2206. !
  2207. ! loop over regions:
  2208. do n = 1, nregions_all
  2209. ! ncep meteo requires conversion of virtual temperature using humidity ...
  2210. if ( (temper_dat(n)%sourcekey(1:4) == 'ncep') .or. (humid_dat(n)%sourcekey(1:4) == 'ncep') ) then
  2211. !write (gol,'("temper and humid ",a)') trim(lli(n)%name); call goPr
  2212. ! read temperature and humidity (if necessary):
  2213. ! #ifdef with_parallel_io_meteo [COMMENTED SINCE NOT TM5-NC SOURCEKEY]
  2214. ! call setup_TQ( n, temper_dat(n), humid_dat(n), (/tr1,tr2/), levi, status)
  2215. ! IF_NOTOK_RETURN(status=1)
  2216. ! #else
  2217. call setup_TQ( n, temper_dat(n), humid_dat(n), (/tr1,tr2/), global_lli(n), levi, status)
  2218. IF_NOTOK_RETURN(status=1)
  2219. ! #endif
  2220. else
  2221. !if (temper_dat(n)%used) then; write (gol,'("temper ",a)') trim(lli(n)%name); call goPr; end if
  2222. ! read temperature (if necessary):
  2223. call setup( n, temper_dat(n), (/tr1,tr2/), global_lli(n), 'n', levi, 'n', status)
  2224. IF_NOTOK_RETURN(status=1)
  2225. !if (humid_dat(n)%used) then; write (gol,'("humid ",a)') trim(lli(n)%name); call goPr; end if
  2226. ! read humidity (if necessary):
  2227. call setup( n, humid_dat(n), (/tr1,tr2/), global_lli(n), 'n', levi, 'n', status)
  2228. IF_NOTOK_RETURN(status=1)
  2229. end if
  2230. end do ! regions
  2231. !
  2232. ! ** gph **************************************
  2233. !
  2234. ! loop over regions:
  2235. do n = 1, nregions_all
  2236. !write (gol,'("gph for region ",a," (#",i1,") ", l2)') trim(lli(n)%name), n, gph_dat(n)%used; call goPr
  2237. ! re-compute gph from pressure, temperature, and humidity:
  2238. call compute_gph( n, status )
  2239. IF_NOTOK_RETURN(status=1)
  2240. end do ! regions
  2241. !
  2242. ! ** clouds **************************************
  2243. !
  2244. ! loop over regions:
  2245. do n = 1, nregions
  2246. !if (any((/lwc_dat(n)%used,iwc_dat(n)%used,cc_dat(n)%used,cco_dat(n)%used,ccu_dat(n)%used/))) then
  2247. ! write (gol,'("clouds ",a)') trim(lli(n)%name); call goPr
  2248. !end if
  2249. call setup( n, lwc_dat(n), (/tr1,tr2/), global_lli(n), 'n', levi, 'n', status)
  2250. IF_NOTOK_RETURN(status=1)
  2251. call setup( n, iwc_dat(n), (/tr1,tr2/), global_lli(n), 'n', levi, 'n', status)
  2252. IF_NOTOK_RETURN(status=1)
  2253. #ifdef with_parallel_io_meteo
  2254. call setup_CloudCovers( n, cc_dat(n), cco_dat(n), ccu_dat(n), (/tr1,tr2/), levi, status)
  2255. IF_NOTOK_RETURN(status=1)
  2256. #else
  2257. call setup_CloudCovers( n, cc_dat(n), cco_dat(n), ccu_dat(n), (/tr1,tr2/), global_lli(n), levi, status)
  2258. IF_NOTOK_RETURN(status=1)
  2259. #endif
  2260. end do
  2261. !
  2262. ! ** convection **************************************
  2263. !
  2264. ! loop over regions:
  2265. do n = 1, nregions
  2266. !if (entu_dat(n)%used) then; write (gol,'("convection ",a)') trim(lli(n)%name); call goPr; end if
  2267. ! read (if necessary):
  2268. #ifdef with_parallel_io_meteo
  2269. call setup_Convec( n, entu_dat(n), entd_dat(n), detu_dat(n), detd_dat(n), &
  2270. omega_dat(n), gph_dat(n), (/tr1,tr2/), levi, status )
  2271. IF_NOTOK_RETURN(status=1)
  2272. #else
  2273. call setup_Convec( n, entu_dat(n), entd_dat(n), detu_dat(n), detd_dat(n), &
  2274. omega_dat(n), gph_dat(n), (/tr1,tr2/), global_lli(n), levi, status )
  2275. IF_NOTOK_RETURN(status=1)
  2276. #endif
  2277. end do
  2278. #ifndef without_convection
  2279. ! ~~ convective clouds
  2280. ! loop over regions:
  2281. do n = 1, nregions
  2282. ! skip ?
  2283. if ( .not. entu_dat(n)%used ) cycle
  2284. if ( .not. entd_dat(n)%used ) cycle
  2285. ! update necessary ?
  2286. if ( any((/entu_dat(n)%changed,entd_dat(n)%changed/)) ) then
  2287. call Get_DistGrid( dgrid(n), I_STRT=i0, I_STOP=i1, J_STRT=j0, J_STOP=j1 )
  2288. ! loop over grid cells
  2289. do j = j0, j1
  2290. do i = i0, i1
  2291. ! compute convective cloud dimensions for this column:
  2292. call ConvCloudDim( 'u', size(detu_dat(n)%data,3), &
  2293. detu_dat(n)%data(i,j,:), entd_dat(n)%data(i,j,:),&
  2294. conv_dat(n)%cloud_base(i,j), &
  2295. conv_dat(n)%cloud_top (i,j), &
  2296. conv_dat(n)%cloud_lfs (i,j), &
  2297. status )
  2298. IF_NOTOK_RETURN(status=1)
  2299. end do ! i
  2300. end do ! j
  2301. end if ! changed
  2302. end do ! regions
  2303. #endif
  2304. ! ~~ unit conversion
  2305. ! loop over regions:
  2306. do n = 1, nregions
  2307. ! skip ?
  2308. if ( .not. entu_dat(n)%used ) cycle
  2309. if ( .not. entd_dat(n)%used ) cycle
  2310. if ( .not. detu_dat(n)%used ) cycle
  2311. if ( .not. detd_dat(n)%used ) cycle
  2312. ! update necessary ?
  2313. if ( any((/ entu_dat(n)%changed, entd_dat(n)%changed, &
  2314. detu_dat(n)%changed, detd_dat(n)%changed /)) ) then
  2315. call Get_DistGrid( dgrid(n), I_STRT=i0, I_STOP=i1, J_STRT=j0, J_STOP=j1 )
  2316. !cmk calculate the rates in kg/gridbox and scale with czeta
  2317. dxyp => region_dat(n)%dxyp
  2318. do j = j0, j1
  2319. do i = i0, i1
  2320. ! kg/m2/s -> kg/gridbox/s * scale_factor
  2321. entu_dat(n)%data(i,j,:) = entu_dat(n)%data(i,j,:)*dxyp(j)*czeta
  2322. detu_dat(n)%data(i,j,:) = detu_dat(n)%data(i,j,:)*dxyp(j)*czeta
  2323. ! ensure netto zero tracer transport by updraught in column
  2324. ! (add difference between total entrement and detrement
  2325. ! to level where entrement reaches maximum):
  2326. tote = sum( entu_dat(n)%data(i,j,:) )
  2327. totd = sum( detu_dat(n)%data(i,j,:) )
  2328. maxe = entu_dat(n)%data(i,j,1) ! changed: reported by PB feb 2003
  2329. lsave = 1
  2330. do l = 2, lmax_conv
  2331. if ( entu_dat(n)%data(i,j,l) > maxe ) then
  2332. maxe = entu_dat(n)%data(i,j,l)
  2333. lsave = l
  2334. end if
  2335. end do
  2336. entu_dat(n)%data(i,j,lsave) = entu_dat(n)%data(i,j,lsave) - tote + totd
  2337. ! kg/m2/s -> kg/gridbox/s * scale_factor
  2338. entd_dat(n)%data(i,j,:) = entd_dat(n)%data(i,j,:)*dxyp(j)*czeta
  2339. detd_dat(n)%data(i,j,:) = detd_dat(n)%data(i,j,:)*dxyp(j)*czeta
  2340. ! ensure netto zero tracer transport by downdraught in column
  2341. ! (add difference between total entrement and detrement
  2342. ! to level where entrement reaches maximum):
  2343. tote = sum( entd_dat(n)%data(i,j,:) ) ! total entrainement
  2344. totd = sum( detd_dat(n)%data(i,j,:) ) ! total detrainement
  2345. maxe = 0.0
  2346. lsave = lmax_conv
  2347. do l = 1, lmax_conv
  2348. if ( entd_dat(n)%data(i,j,l) > maxe ) then
  2349. maxe = entd_dat(n)%data(i,j,l)
  2350. lsave = l
  2351. end if
  2352. end do
  2353. entd_dat(n)%data(i,j,lsave) = entd_dat(n)%data(i,j,lsave) - tote + totd
  2354. end do
  2355. end do
  2356. end if ! changed ?
  2357. end do ! regions
  2358. !
  2359. ! ** diffusion **************************************
  2360. !
  2361. ! loop over regions:
  2362. do n = 1, nregions
  2363. #ifdef with_parallel_io_meteo
  2364. call Setup_Diffus( n, kzz_dat(n), (/tr1,tr2/), levi, status )
  2365. IF_NOTOK_RETURN(status=1)
  2366. #else
  2367. call Setup_Diffus( n, kzz_dat(n), (/tr1,tr2/), global_lli(n), levi, status )
  2368. IF_NOTOK_RETURN(status=1)
  2369. #endif
  2370. end do ! regions
  2371. !
  2372. ! ** surface fields *****************************
  2373. !
  2374. do n = 1, nregions_all
  2375. !write (gol,'("surface fields ",a)') trim(lli(n)%name); call goPr
  2376. ! * lsmask
  2377. call setup( n, lsmask_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2378. IF_NOTOK_RETURN(status=1)
  2379. ! * albedo
  2380. call setup( n, albedo_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2381. IF_NOTOK_RETURN(status=1)
  2382. ! * sr_ecm
  2383. call setup( n, sr_ecm_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2384. IF_NOTOK_RETURN(status=1)
  2385. ! * sr_ols
  2386. call setup( n, sr_ols_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2387. IF_NOTOK_RETURN(status=1)
  2388. ! * sea ice
  2389. call setup( n, ci_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2390. IF_NOTOK_RETURN(status=1)
  2391. ! * sea surface temperature
  2392. call setup( n, sst_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2393. IF_NOTOK_RETURN(status=1)
  2394. ! * u10m
  2395. call setup( n, u10m_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2396. IF_NOTOK_RETURN(status=1)
  2397. ! * v10m
  2398. call setup( n, v10m_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2399. IF_NOTOK_RETURN(status=1)
  2400. ! * skin reservoir content
  2401. call setup( n, src_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2402. IF_NOTOK_RETURN(status=1)
  2403. ! * 2m dewpoint temperature
  2404. call setup( n, d2m_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2405. IF_NOTOK_RETURN(status=1)
  2406. ! * 2m temperature
  2407. call setup( n, t2m_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2408. IF_NOTOK_RETURN(status=1)
  2409. ! * slhf
  2410. call setup( n, slhf_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2411. IF_NOTOK_RETURN(status=1)
  2412. ! * sshf
  2413. call setup( n, sshf_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2414. IF_NOTOK_RETURN(status=1)
  2415. ! * surface stress
  2416. call setup( n, ewss_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2417. IF_NOTOK_RETURN(status=1)
  2418. call setup( n, nsss_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2419. IF_NOTOK_RETURN(status=1)
  2420. ! * convective precipitation
  2421. call setup( n, cp_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2422. IF_NOTOK_RETURN(status=1)
  2423. ! * large scale stratiform precipitation
  2424. call setup( n, lsp_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2425. IF_NOTOK_RETURN(status=1)
  2426. ! * surface solar radiation
  2427. call setup( n, ssr_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2428. IF_NOTOK_RETURN(status=1)
  2429. call setup( n, ssrd_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2430. IF_NOTOK_RETURN(status=1)
  2431. ! * surface thermal radiation
  2432. call setup( n, str_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2433. IF_NOTOK_RETURN(status=1)
  2434. call setup( n, strd_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2435. IF_NOTOK_RETURN(status=1)
  2436. ! * skin temperature
  2437. call setup( n, skt_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2438. IF_NOTOK_RETURN(status=1)
  2439. ! * boundary layer height
  2440. call setup( n, blh_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2441. IF_NOTOK_RETURN(status=1)
  2442. ! * snow fall and depth
  2443. call setup( n, sf_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2444. IF_NOTOK_RETURN(status=1)
  2445. call setup( n, sd_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2446. IF_NOTOK_RETURN(status=1)
  2447. ! * g10m
  2448. call setup( n, g10m_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2449. IF_NOTOK_RETURN(status=1)
  2450. ! * soil water level 1
  2451. call setup( n, swvl1_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2452. IF_NOTOK_RETURN(status=1)
  2453. ! * soil temperature level 1
  2454. call setup( n, stl1_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2455. IF_NOTOK_RETURN(status=1)
  2456. ! * vegetation types
  2457. do iveg = 1, nveg
  2458. select case ( iveg )
  2459. case ( 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 16, 17, 18, 19 )
  2460. call setup( n, tv_dat(n,iveg), (/tr1,tr2/), global_lli(n), 'n', status)
  2461. IF_NOTOK_RETURN(status=1)
  2462. case ( 8, 12, 14, 15, 20 )
  2463. if ( tv_dat(n,iveg)%used ) tv_dat(n,iveg)%data = 0.0
  2464. case default
  2465. write (gol,'("do not know how to setup vegetation type ",i2)') iveg
  2466. call goErr; status=1; return
  2467. end select
  2468. end do
  2469. ! * low vegetation cover
  2470. call setup( n, cvl_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2471. IF_NOTOK_RETURN(status=1)
  2472. ! * high vegetation cover
  2473. call setup( n, cvh_dat(n), (/tr1,tr2/), global_lli(n), 'n', status)
  2474. IF_NOTOK_RETURN(status=1)
  2475. end do ! regions
  2476. !
  2477. ! ** done ********************************************
  2478. !
  2479. ! ok
  2480. status = 0
  2481. if (okdebug) call goLabel()
  2482. END SUBROUTINE METEO_SETUP_OTHER
  2483. !EOC
  2484. !------------------------------------------------------------------------------
  2485. ! TM5 !
  2486. !------------------------------------------------------------------------------
  2487. !BOP
  2488. !
  2489. ! !IROUTINE: SETUPSETUP
  2490. !
  2491. ! !DESCRIPTION: for one met data MD and one time range TR, returns the dates
  2492. ! at begining and end of the met field interval that
  2493. ! encompasses TR, and if the data for these dates (%data1 and
  2494. ! %data2, resp.) must be read or copied.
  2495. !\\
  2496. !\\
  2497. ! !INTERFACE:
  2498. !
  2499. SUBROUTINE SETUPSETUP( md, tr, &
  2500. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  2501. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  2502. status )
  2503. !
  2504. ! !USES:
  2505. !
  2506. use GO, only : TDate, NewDate, IncrDate, AnyDate, IsAnyDate, Get, Set, wrtgol
  2507. use GO, only : rTotal, iTotal
  2508. use GO, only : operator(+), operator(-), operator(/)
  2509. use GO, only : operator(==), operator(/=), operator(<), operator(<=)
  2510. use meteodata, only : TMeteoData
  2511. use global_data, only : fcmode, tfcday0
  2512. !
  2513. ! !INPUT/OUTPUT PARAMETERS:
  2514. !
  2515. type(TMeteoData), intent(inout) :: md
  2516. !
  2517. ! !INPUT PARAMETERS:
  2518. !
  2519. type(TDate), intent(in) :: tr(2)
  2520. !
  2521. ! !OUTPUT PARAMETERS:
  2522. !
  2523. logical, intent(out) :: data1_read, data1_copy
  2524. type(TDate), intent(out) :: data1_tref, data1_t1, data1_t2
  2525. logical, intent(out) :: data2_read, data2_copy
  2526. type(TDate), intent(out) :: data2_tref, data2_t1, data2_t2
  2527. integer, intent(out) :: status
  2528. !
  2529. ! !REVISION HISTORY:
  2530. ! 29 Mar 2010 - P. Le Sager -
  2531. !
  2532. !EOP
  2533. !------------------------------------------------------------------------------
  2534. !BOC
  2535. character(len=*), parameter :: rname = mname//'/SetupSetup'
  2536. integer :: dth, baseh
  2537. integer :: year, month, day, hour, minu
  2538. type(TDate) :: tmid
  2539. type(TDate) :: tc(2)
  2540. integer :: dth_int
  2541. type(TDate) :: tprev, tnext
  2542. real :: dhr
  2543. ! --- begin -----------------------------
  2544. if (okdebug) call goLabel(rname)
  2545. ! default output:
  2546. data1_read = .false.
  2547. data1_copy = .false.
  2548. data2_read = .false.
  2549. data2_copy = .false.
  2550. !
  2551. ! trap constant fields ...
  2552. !
  2553. ! constant and already filled ? then leave
  2554. if ( (md%tinterp == 'const') .and. md%filled1 ) then
  2555. if (okdebug) call goLabel()
  2556. status = 0; return
  2557. end if
  2558. !
  2559. ! fc stuff
  2560. !
  2561. ! 3 hourly data only available up to 72h, then 6 hourly
  2562. if ( fcmode ) then
  2563. ! number of hours from fcday 00:00 to end of requested interval:
  2564. dhr = rTotal( tr(2) - tfcday0, 'hour' )
  2565. ! lower time resolution after a while ...
  2566. if ( tfcday0 < NewDate(year=2006,month=03,day=14) ) then
  2567. ! after 12+72 hour ?
  2568. if ( dhr > 12.0 + 72.0 ) then
  2569. ! convert time interpolation:
  2570. select case ( md%tinterp )
  2571. case ( 'aver3' )
  2572. write (gol,'("WARNING - convert time interpolation from `aver3` to `aver6`")'); call goPr
  2573. md%tinterp = 'aver6'
  2574. case ( 'interp3' )
  2575. write (gol,'("WARNING - convert time interpolation from `interp3` to `interp6`")'); call goPr
  2576. md%tinterp = 'interp6'
  2577. end select
  2578. end if ! > 72 hour
  2579. else
  2580. ! after 12+96 hour ?
  2581. if ( dhr > 12.0 + 96.0 ) then
  2582. ! convert time interpolation:
  2583. select case ( md%tinterp )
  2584. case ( 'aver3' )
  2585. write (gol,'("WARNING - convert time interpolation from `aver3` to `aver6`")'); call goPr
  2586. md%tinterp = 'aver6'
  2587. case ( 'interp3' )
  2588. write (gol,'("WARNING - convert time interpolation from `interp3` to `interp6`")'); call goPr
  2589. md%tinterp = 'interp6'
  2590. end select
  2591. end if ! > 96 hour
  2592. end if ! change in fc resolution
  2593. end if ! fcmode
  2594. !
  2595. ! time stuff
  2596. !
  2597. ! basic time resolution in hours
  2598. select case ( md%tinterp )
  2599. case ( 'const', 'month' )
  2600. ! nothing to be set here ...
  2601. case ( 'aver24' )
  2602. ! constant fields produced valid for [00,24]
  2603. dth = 24
  2604. baseh = 00
  2605. case ( 'aver24_3' )
  2606. ! constant fields produced by tmpp valid for [21,21] = [09-12,09+12]
  2607. dth = 24
  2608. baseh = -3
  2609. case ( 'const3', 'interp3', 'aver3', 'cpl3' )
  2610. dth = 3
  2611. baseh = 0
  2612. case ( 'interp2', 'cpl2' )
  2613. dth = 2
  2614. baseh = 0
  2615. case ( 'const1', 'interp1', 'aver1', 'cpl1' )
  2616. dth = 1
  2617. baseh = 0
  2618. case ( 'const6', 'interp6', 'aver6', 'cpl6' )
  2619. dth = 6
  2620. baseh = 0
  2621. case ( 'interp6_3' )
  2622. dth = 6
  2623. baseh = 3
  2624. case default
  2625. write (gol,'("unsupported time interpolation : ",a)') md%tinterp; call goErr
  2626. call goErr; status=1; return
  2627. end select
  2628. ! set time parameters for field to be read:
  2629. select case ( md%tinterp )
  2630. !
  2631. ! ** constant fields
  2632. !
  2633. case ( 'const' )
  2634. ! read main field ?
  2635. data1_read = .not. md%filled1
  2636. ! read or leave ?
  2637. if ( data1_read ) then
  2638. data1_tref = tr(1) ! <--- used for file names
  2639. data1_t1 = AnyDate()
  2640. data1_t2 = AnyDate()
  2641. else
  2642. ! field valid around requested interval, thus leave:
  2643. if (okdebug) call goLabel()
  2644. status=0; return
  2645. end if
  2646. !
  2647. ! ** constant fields, valid for complete month
  2648. !
  2649. case ( 'month' )
  2650. ! extract time values for begin of current interval:
  2651. call Get( tr(1), year=year, month=month )
  2652. ! interval for this month:
  2653. tc(1) = NewDate( year=year, month=month, day=01, hour=00 )
  2654. month = month + 1
  2655. if ( month > 12 ) then
  2656. month = 1
  2657. year = year + 1
  2658. end if
  2659. tc(2) = NewDate( year=year, month=month, day=01, hour=00 )
  2660. ! check for strange values:
  2661. if ( (tr(1) < tc(1)) .or. (tc(2) < tr(2)) ) then
  2662. write (gol,'("determined invalid constant interval:")'); call goErr
  2663. call wrtgol( ' requested : ', tr(1), ' - ', tr(2) ); call goErr
  2664. call wrtgol( ' guessed : ', tc(1), ' - ', tc(2) ); call goErr
  2665. write (gol,'(" for tinterp : ",a)') md%tinterp; call goErr
  2666. call goErr; status=1; return
  2667. !write (gol,'(" WARNING - requested interval exceeds meteo interval; should be improved")')
  2668. end if
  2669. ! read main field ?
  2670. if ( md%filled1 ) then
  2671. data1_read = md%tr1(1) /= tc(1)
  2672. else
  2673. data1_read = .true.
  2674. end if
  2675. ! read or leave ?
  2676. if ( data1_read ) then
  2677. data1_tref = tr(1)
  2678. data1_t1 = tc(1)
  2679. data1_t2 = tc(2)
  2680. else
  2681. ! field valid around requested interval, thus leave:
  2682. if (okdebug) call goLabel()
  2683. status=0; return
  2684. end if
  2685. !
  2686. ! ** constant fields, valid for 24hr intervals [21:00,21:00]
  2687. ! constant fields, valid for 6hr intervals [21:00,03:00] etc
  2688. ! constant fields, valid for 3hr intervals [22:30,01:30] etc
  2689. !
  2690. case ( 'const6', 'const3' )
  2691. ! extract time values for begin of current interval:
  2692. call Get( tr(1), year, month, day, hour, minu )
  2693. ! round hour to 00/06/12/18 or 00/03/06/09/12/15/18/21 or 09
  2694. hour = dth * nint(real(hour+minu/60.0-baseh)/real(dth)) + baseh
  2695. ! set mid of 3 or 6 hour interval:
  2696. tmid = NewDate( year, month, day, hour )
  2697. ! interval with constant field
  2698. tc(1) = tmid - IncrDate(hour=dth)/2
  2699. tc(2) = tmid + IncrDate(hour=dth)/2
  2700. ! check for strange values:
  2701. if ( (tr(1) < tc(1)) .or. (tc(2) < tr(2)) ) then
  2702. write (gol,'("determined invalid constant interval:")'); call goErr
  2703. call wrtgol( ' requested : ', tr(1), ' - ', tr(2) ); call goErr
  2704. call wrtgol( ' guessed : ', tc(1), ' - ', tc(2) ); call goErr
  2705. write (gol,'(" for tinterp : ",a)') md%tinterp; call goErr
  2706. call goErr; status=1; return
  2707. end if
  2708. ! read main field ?
  2709. if ( md%filled1 ) then
  2710. data1_read = md%tr1(1) /= tmid
  2711. else
  2712. data1_read = .true.
  2713. end if
  2714. ! read or leave ?
  2715. if ( data1_read ) then
  2716. data1_tref = tmid
  2717. data1_t1 = tmid
  2718. data1_t2 = tmid
  2719. else
  2720. ! field valid around requested interval, thus leave:
  2721. if (okdebug) call goLabel()
  2722. status=0; return
  2723. end if
  2724. !
  2725. ! ** couple fields, valid for 3hr intervals [00:00,03:00] etc
  2726. ! input filed valid for BEGIN of interval !
  2727. !
  2728. case ( 'cpl6', 'cpl3', 'cpl2', 'cpl1' )
  2729. ! extract time values for begin of current interval:
  2730. call Get( tr(1), year, month, day, hour, minu )
  2731. ! round hour to previous baseh + 00/03/06/09/12/15/18/21
  2732. hour = dth * floor(real(hour-baseh)/real(dth)) + baseh
  2733. ! interval with constant field
  2734. tc(1) = NewDate( year, month, day, hour )
  2735. tc(2) = tc(1) + IncrDate(hour=dth)
  2736. ! check for strange values:
  2737. if ( (tr(1) < tc(1)) .or. (tc(2) < tr(1)) ) then
  2738. write (gol,'("determined invalid first interval:")'); call goErr
  2739. call wrtgol( ' requested : ', tr(1), ' - ', tr(2) ); call goErr
  2740. call wrtgol( ' guessed : ', tc(1), ' - ', tc(2) ); call goErr
  2741. write (gol,'(" for tinterp : ",a)') md%tinterp; call goErr
  2742. call goErr; status=1; return
  2743. end if
  2744. ! read primary field ?
  2745. if ( md%filled1 ) then
  2746. ! read new field if times are different:
  2747. data1_read = (md%tr1(1) /= tc(1)) .or. (md%tr1(2) /= tc(1))
  2748. else
  2749. ! not filled yet, thus must read:
  2750. data1_read = .true.
  2751. end if
  2752. ! read or leave ?
  2753. if ( data1_read ) then
  2754. data1_tref = tc(1) ! begin of time interval
  2755. data1_t1 = tc(1)
  2756. data1_t2 = tc(1)
  2757. end if
  2758. !
  2759. ! ** average fields, valid for 3hr intervals [00:00,03:00] etc
  2760. ! average fields, valid for 3hr intervals [00:00,06:00] etc
  2761. !
  2762. case ( 'aver1', 'aver3', 'aver6', 'aver24', 'aver24_3' )
  2763. ! extract time values for begin of current interval:
  2764. call Get( tr(1), year, month, day, hour, minu )
  2765. ! round hour to previous baseh + 00/03/06/09/12/15/18/21
  2766. hour = dth * floor(real(hour-baseh)/real(dth)) + baseh
  2767. ! interval with constant field
  2768. tc(1) = NewDate( year, month, day, hour )
  2769. tc(2) = tc(1) + IncrDate(hour=dth)
  2770. ! check for strange values:
  2771. if ( (tr(1) < tc(1)) .or. (tc(2) < tr(1)) ) then
  2772. write (gol,'("determined invalid first interval:")'); call goErr
  2773. call wrtgol( ' requested : ', tr(1), ' - ', tr(2) ); call goErr
  2774. call wrtgol( ' guessed : ', tc(1), ' - ', tc(2) ); call goErr
  2775. write (gol,'(" for tinterp : ",a)') md%tinterp; call goErr
  2776. call goErr; status=1; return
  2777. end if
  2778. ! read primary field ?
  2779. if ( md%filled1 ) then
  2780. ! read new field if times are different:
  2781. data1_read = (md%tr1(1) /= tc(1)) .or. (md%tr1(2) /= tc(2))
  2782. else
  2783. ! not filled yet, thus must read:
  2784. data1_read = .true.
  2785. end if
  2786. if ( data1_read ) then
  2787. data1_tref = tc(1)
  2788. data1_t1 = tc(1)
  2789. data1_t2 = tc(2)
  2790. end if
  2791. ! setup reading of secondary data only if end of requested
  2792. ! interval is later than primary interval:
  2793. if ( tc(2) < tr(2) ) then
  2794. ! extract time values for end of requested interval:
  2795. call Get( tr(2), year, month, day, hour, minu )
  2796. ! round hour to next baseh + 00/03/06/09/12/15/18/21
  2797. hour = dth * floor(real(hour+minu/60.0-baseh)/real(dth)) + baseh
  2798. ! interval with constant field
  2799. tc(1) = NewDate( year, month, day ) + IncrDate(hour=hour)
  2800. tc(2) = tc(1) + IncrDate(hour=dth)
  2801. ! check for strange values:
  2802. if ( (tr(2) < tc(1)) .or. (tc(2) < tr(2)) ) then
  2803. write (gol,'("determined invalid second interval:")'); call goErr
  2804. call wrtgol( ' requested : ', tr(1), ' - ', tr(2) ); call goErr
  2805. call wrtgol( ' guessed : ', tc(1), ' - ', tc(2) ); call goErr
  2806. write (gol,'(" for tinterp : ",a)') md%tinterp; call goErr
  2807. call goErr; status=1; return
  2808. end if
  2809. ! read secondary field ?
  2810. if ( md%filled2 ) then
  2811. ! read new field if times are different;
  2812. data2_read = (md%tr2(1) /= tc(1)) .or. (md%tr2(2) /= tc(2))
  2813. else
  2814. ! not filled yet, thus must read:
  2815. data2_read = .true.
  2816. end if
  2817. if ( data2_read ) then
  2818. data2_tref = tc(1)
  2819. data2_t1 = tc(1)
  2820. data2_t2 = tc(2)
  2821. end if
  2822. end if ! tr partly after primary interval
  2823. !
  2824. ! ** interpolated between 6 hourly times 00/06/12/18
  2825. ! interpolated between 6 hourly times 03/09/15/21
  2826. ! interpolated between 3 hourly times 00/03/06/09/12/15/18/21
  2827. !
  2828. case ( 'interp6', 'interp6_3', 'interp3', 'interp2', 'interp1' )
  2829. ! extract time values for begin of current interval:
  2830. call Get( tr(1), year, month, day, hour, minu )
  2831. ! truncate hour to previous 00/06/12/18, 03/09/15/21,
  2832. ! or 00/03/06/09/12/15/18/21
  2833. hour = dth * floor(real(hour+minu/60.0-baseh)/real(dth)) + baseh
  2834. ! set begin of 3 or 6 hour interval:
  2835. tprev = NewDate( year, month, day, hour )
  2836. ! extract time values for end of current interval:
  2837. call Get( tr(2), year, month, day, hour, minu )
  2838. ! truncate hour to previous 00/06/12/18
  2839. hour = dth * ceiling(real(hour+minu/60.0-baseh)/real(dth)) + baseh
  2840. ! set end of 3 or 6 hour interval:
  2841. tnext = NewDate( year, month, day, hour )
  2842. ! checks:
  2843. ! [tprev,tmax] should be dth hours
  2844. ! [tprev,tmax] should contain [tr(1),tr(2)]
  2845. dth_int = iTotal(tnext-tprev,'hour')
  2846. if ( (tr(1) < tprev) .or. (tnext < tr(2)) .or. &
  2847. ( (dth_int /= 0) .and. (dth_int /= dth) ) ) then
  2848. write (gol,'("determined invalid interpolation interval:")'); call goErr
  2849. call wrtgol( ' requested : ', tr(1), ' - ', tr(2) ); call goErr
  2850. call wrtgol( ' guessed : ', tprev, ' - ', tnext ); call goErr
  2851. write (gol,'(" for tinterp : ",a)') md%tinterp; call goErr
  2852. call goErr; status=1; return
  2853. end if
  2854. !
  2855. ! . <-- previous field at dth hours
  2856. ! o <-- latest interpolated field
  2857. ! x <-- target
  2858. ! o <-- next field at dth hours
  2859. ! tr1 tr tr2
  2860. ! --+--------------+------
  2861. ! tprev tnext
  2862. !
  2863. ! read main field ?
  2864. if ( md%filled1 ) then
  2865. ! md%data should be defined in [tprev,tr]
  2866. data1_read = (md%tr1(1) < tprev) .or. (tr(2) < md%tr1(1))
  2867. else
  2868. data1_read = .true.
  2869. end if
  2870. if ( data1_read ) then
  2871. data1_tref = tprev
  2872. data1_t1 = tprev
  2873. data1_t2 = tprev
  2874. end if
  2875. ! read second field ?
  2876. if ( md%filled2 ) then
  2877. ! md%data should be defined for tnext
  2878. data2_read = md%tr2(1) /= tnext
  2879. else
  2880. data2_read = .true.
  2881. end if
  2882. if ( data2_read ) then
  2883. data2_tref = tnext
  2884. data2_t1 = tnext
  2885. data2_t2 = tnext
  2886. end if
  2887. !
  2888. ! ** error ...
  2889. !
  2890. case default
  2891. write (gol,'("unsupported time interpolation : ",a)') md%tinterp ; call goErr
  2892. call goErr; status=1; return
  2893. end select
  2894. !
  2895. ! set ref times
  2896. !
  2897. if ( fcmode ) then
  2898. ! in forecast mode, tfcday0 is 00:00 at the day the forecast starts;
  2899. data1_tref = tfcday0
  2900. data2_tref = tfcday0
  2901. else
  2902. ! dummy tref's : begin of day in which [data?_t1,data?_t2] starts:
  2903. data1_tref = data1_t1
  2904. if ( IsAnyDate(data1_tref) ) data1_tref = tr(1)
  2905. call Set( data1_tref, hour=0, min=0, sec=0, mili=0 )
  2906. data2_tref = data2_t1
  2907. if ( IsAnyDate(data2_tref) ) data2_tref = tr(1)
  2908. call Set( data2_tref, hour=0, min=0, sec=0, mili=0 )
  2909. end if
  2910. !
  2911. ! trap double reading
  2912. !
  2913. ! data already in data2 ?
  2914. if ( data1_read .and. md%filled2 ) then
  2915. if ( (data1_t1 == md%tr2(1)) .and. (data1_t2 == md%tr2(2)) ) then
  2916. data1_read = .false.
  2917. data1_copy = .true.
  2918. end if
  2919. end if
  2920. ! data2 just read ?
  2921. if ( data2_read .and. data1_read ) then
  2922. ! data2 is same as data ?
  2923. if ( (data2_tref == data1_tref) .and. &
  2924. (data2_t1 == data1_t1) .and. (data2_t2 == data1_t2) ) then
  2925. data2_read = .false.
  2926. data2_copy = .true.
  2927. end if
  2928. end if
  2929. !write (gol,'("SetupSetup:")'); call goPr
  2930. !write (gol,'(" fcmode : ",l1)') fcmode; call goPr
  2931. !call wrtgol( ' tfcday0 : ', tfcday0 ); call goPr
  2932. !write (gol,'(" md%tinterp : ",a)') trim(md%tinterp); call goPr
  2933. !call wrtgol( ' tr(1) : ', tr(1) ); call goPr
  2934. !call wrtgol( ' tr(2) : ', tr(2) ); call goPr
  2935. !write (gol,'(" 1 read,copy : ",2l2)') data1_read, data1_copy; call goPr
  2936. !call wrtgol( ' 1 tref : ', data1_tref ); call goPr
  2937. !call wrtgol( ' 1 t1 : ', data1_t1 ); call goPr
  2938. !call wrtgol( ' 1 t2 : ', data1_t2 ); call goPr
  2939. !write (gol,'(" 2 read,copy : ",2l2)') data2_read, data2_copy; call goPr
  2940. !call wrtgol( ' 2 tref : ', data2_tref ); call goPr
  2941. !call wrtgol( ' 2 t1 : ', data2_t1 ); call goPr
  2942. !call wrtgol( ' 2 t2 : ', data2_t2 ); call goPr
  2943. ! ok
  2944. status = 0
  2945. if (okdebug) call goLabel()
  2946. end subroutine SetupSetup
  2947. !EOC
  2948. !------------------------------------------------------------------------------
  2949. ! TM5 !
  2950. !------------------------------------------------------------------------------
  2951. !BOP
  2952. !
  2953. ! !IROUTINE: SETUP_2D
  2954. !
  2955. ! !DESCRIPTION: Fill md%data1 and md%data2 of a 2D met field type (md), with
  2956. ! data for date tr(1) and tr(2) respectively (and if needed)
  2957. ! through reading or copying. Also write to disk the met field
  2958. ! if requested.
  2959. !
  2960. ! Then set md%data according to its type of interpolation (see
  2961. ! TimeInterpolation in meteodata.F90).
  2962. ! For constant type, %data => %data1.
  2963. !\\
  2964. !\\
  2965. ! !INTERFACE:
  2966. !
  2967. SUBROUTINE SETUP_2D( region, md, tr, lli, nuv, status )
  2968. !
  2969. ! !USES:
  2970. !
  2971. use GO, only : TDate, wrtgol
  2972. use Grid, only : TllGridInfo
  2973. use TMM, only : ReadField, Read_SP, Read_SR_OLS, WriteField
  2974. use meteodata, only : TMeteoData, TimeInterpolation
  2975. use dims, only : im, jm
  2976. !
  2977. ! !INPUT/OUTPUT PARAMETERS:
  2978. !
  2979. type(TMeteoData), intent(inout) :: md ! met field
  2980. !
  2981. ! !INPUT PARAMETERS:
  2982. !
  2983. integer, intent(in) :: region ! region number
  2984. type(TDate), intent(in) :: tr(2) ! dates
  2985. type(TllGridInfo), intent(in) :: lli ! grid (GLOBAL)
  2986. character(len=1), intent(in) :: nuv ! staggering
  2987. !
  2988. ! !OUTPUT PARAMETERS:
  2989. !
  2990. integer, intent(out) :: status ! return code
  2991. !
  2992. ! !REVISION HISTORY:
  2993. ! 4 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  2994. !
  2995. !EOP
  2996. !------------------------------------------------------------------------------
  2997. !BOC
  2998. character(len=*), parameter :: rname = mname//'/Setup_2d'
  2999. logical :: data1_read, data1_copy
  3000. type(TDate) :: data1_tref, data1_t1, data1_t2
  3001. logical :: data2_read, data2_copy
  3002. type(TDate) :: data2_tref, data2_t1, data2_t2
  3003. real, pointer :: field(:,:) ! work array
  3004. ! --- begin -----------------------------
  3005. if (okdebug) call goLabel(rname)
  3006. ! leave if not in use:
  3007. if ( .not. md%used ) then
  3008. if (okdebug) call goLabel()
  3009. status=0; return
  3010. end if
  3011. ! debug
  3012. !write (gol,'(a," @ ",a)') trim(md%name),trim(lli%name); call goPr
  3013. ! not changed by default
  3014. md%changed = .false.
  3015. !------------------
  3016. ! time stuff
  3017. !------------------
  3018. ! get time interval of met field and check if data from start and/or end
  3019. ! of interval must be read or copy
  3020. call SetupSetup( md, tr, &
  3021. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  3022. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  3023. status )
  3024. IF_NOTOK_RETURN(status=1)
  3025. ! -------------------------
  3026. ! Read/write primary field
  3027. ! -------------------------
  3028. if ( data1_read ) then
  3029. ! test
  3030. if ( md%ls(1) /= md%ls(2) ) then
  3031. write (gol,'("SETUP_2D called instead of SETUP_3D, field is 3D:")'); call goErr
  3032. write (gol, '(" md%ls(1:2) : ",2i3)') md%ls; call goErr
  3033. status=1; IF_NOTOK_RETURN(status=1)
  3034. end if
  3035. ! Need whole region for I/O on root. Dummy else.
  3036. IF (isRoot) THEN
  3037. ALLOCATE( field( im(region), jm(region)) )
  3038. ELSE
  3039. ALLOCATE( field(1,1) )
  3040. END IF
  3041. ! Read/write
  3042. IOroot : IF (isRoot) THEN
  3043. select case ( md%name )
  3044. case ( 'sp', 'sps' )
  3045. ! special routine for surface pressure
  3046. call Read_SP( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3047. data1_tref, data1_t1, data1_t2, &
  3048. lli, FIELD, md%tmi1, status )
  3049. IF_NOTOK_RETURN(status=1)
  3050. case ( 'srols' )
  3051. ! special routine for Olsson surface roughness:
  3052. call Read_SR_OLS( tmmd, md%sourcekey, &
  3053. data1_tref, data1_t1, data1_t2, &
  3054. lli, FIELD, md%tmi1, status )
  3055. IF_NOTOK_RETURN(status=1)
  3056. case default
  3057. ! general field
  3058. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3059. data1_tref, data1_t1, data1_t2, lli, &
  3060. nuv, FIELD, md%tmi1, status )
  3061. IF_NOTOK_RETURN(status=1)
  3062. end select
  3063. ! write meteofiles
  3064. if ( md%putout ) then
  3065. call WriteField( tmmd, md%destkey, &
  3066. md%tmi1, trim(md%name), trim(md%unit), &
  3067. data1_tref, data1_t1, data1_t2, &
  3068. lli, nuv, FIELD, status )
  3069. IF_NOTOK_RETURN(status=1)
  3070. end if
  3071. END IF IOroot
  3072. CALL SCATTER( dgrid(region), md%data1(:,:,1), FIELD, md%halo, status)
  3073. IF_NOTOK_RETURN(status=1)
  3074. DEALLOCATE( FIELD )
  3075. ! data array is filled now:
  3076. md%filled1 = .true.
  3077. md%tr1(1) = data1_t1
  3078. md%tr1(2) = data1_t2
  3079. md%changed = .true.
  3080. else if ( data1_copy ) then
  3081. ! copy data from secondary array:
  3082. md%data1 = md%data2
  3083. ! data array is filled now:
  3084. md%filled1 = .true.
  3085. md%tr1(1) = data1_t1
  3086. md%tr1(2) = data1_t2
  3087. md%changed = .true.
  3088. end if
  3089. ! -------------------------
  3090. ! Read/write (or copy or nothing) secondary field
  3091. ! -------------------------
  3092. if ( data2_read ) then
  3093. ! Need whole region for I/O on root. Dummy else.
  3094. IF (isRoot) THEN
  3095. ALLOCATE( field( im(region), jm(region)) )
  3096. ELSE
  3097. ALLOCATE( field(1,1) )
  3098. END IF
  3099. ! Read/write
  3100. IOroot2: IF (isRoot) THEN
  3101. select case ( md%name )
  3102. case ( 'sp', 'sps' )
  3103. ! special routine for surface pressure
  3104. call Read_SP( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3105. data2_tref, data2_t1, data2_t2, &
  3106. lli, FIELD, md%tmi2, status )
  3107. IF_NOTOK_RETURN(status=1)
  3108. case default
  3109. ! general field
  3110. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3111. data2_tref, data2_t1, data2_t2, lli, &
  3112. nuv, FIELD, md%tmi2, status )
  3113. IF_NOTOK_RETURN(status=1)
  3114. end select
  3115. ! write meteo files
  3116. if ( md%putout ) then
  3117. call WriteField( tmmd, md%destkey, &
  3118. md%tmi2, trim(md%name), trim(md%unit), &
  3119. data2_tref, data2_t1, data2_t2, &
  3120. lli, nuv, FIELD, status )
  3121. IF_NOTOK_RETURN(status=1)
  3122. end if
  3123. END IF IOroot2
  3124. CALL SCATTER( dgrid(region), md%data2(:,:,1), FIELD, md%halo, status)
  3125. IF_NOTOK_RETURN(status=1)
  3126. DEALLOCATE( FIELD )
  3127. ! data array is filled now
  3128. md%filled2 = .true.
  3129. md%tr2(1) = data2_t1
  3130. md%tr2(2) = data2_t2
  3131. else if ( data2_copy ) then
  3132. ! copy data from secondary array
  3133. md%data2 = md%data1
  3134. ! data array is filled now
  3135. md%filled2 = .true.
  3136. md%tr2(1) = data2_t1
  3137. md%tr2(2) = data2_t2
  3138. end if
  3139. ! -------------------------
  3140. ! time interpolation
  3141. ! -------------------------
  3142. call TimeInterpolation( md, tr, status )
  3143. IF_NOTOK_RETURN(status=1)
  3144. ! -------------------------
  3145. ! done
  3146. ! -------------------------
  3147. status = 0
  3148. if (okdebug) call goLabel()
  3149. END SUBROUTINE SETUP_2D
  3150. !EOC
  3151. !------------------------------------------------------------------------------
  3152. ! TM5 !
  3153. !------------------------------------------------------------------------------
  3154. !BOP
  3155. !
  3156. ! !IROUTINE: SETUP_2D_PARALLEL_IO
  3157. !
  3158. ! !DESCRIPTION: Same as SETUP_2D, except reading is done by every processes.
  3159. !\\
  3160. !\\
  3161. ! !INTERFACE:
  3162. !
  3163. SUBROUTINE SETUP_2D_PARALLEL_IO( region, md, tr, tdlli, nuv, status )
  3164. !
  3165. ! !USES:
  3166. !
  3167. use GO, only : TDate, wrtgol
  3168. use Grid, only : TllGridInfo
  3169. use TMM, only : ReadField, Read_SP, Read_SR_OLS, WriteField
  3170. ! use meteodata, only : TMeteoData, TimeInterpolation
  3171. use dims, only : im, jm
  3172. !
  3173. ! !INPUT/OUTPUT PARAMETERS:
  3174. !
  3175. type(TMeteoData), intent(inout) :: md ! met field
  3176. !
  3177. ! !INPUT PARAMETERS:
  3178. !
  3179. integer, intent(in) :: region ! region number
  3180. type(TDate), intent(in) :: tr(2) ! dates
  3181. type(TllGridInfo), intent(in) :: tdlli ! dummy.. grid is already determined by the region
  3182. character(len=1), intent(in) :: nuv ! staggering
  3183. !
  3184. ! !OUTPUT PARAMETERS:
  3185. !
  3186. integer, intent(out) :: status ! return code
  3187. !
  3188. ! !REVISION HISTORY:
  3189. ! 18 Oct 2013 - Ph. Le Sager - v0
  3190. !
  3191. !EOP
  3192. !------------------------------------------------------------------------------
  3193. !BOC
  3194. character(len=*), parameter :: rname = mname//'/Setup_2d_parallel_io'
  3195. logical :: data1_read, data1_copy
  3196. type(TDate) :: data1_tref, data1_t1, data1_t2
  3197. logical :: data2_read, data2_copy
  3198. type(TDate) :: data2_tref, data2_t1, data2_t2
  3199. integer :: i1, i2, j1, j2
  3200. real, pointer :: field(:,:) ! work array
  3201. ! --- begin -----------------------------
  3202. if (okdebug) call goLabel(rname)
  3203. ! leave if not in use:
  3204. if ( .not. md%used ) then
  3205. if (okdebug) call goLabel()
  3206. status=0; return
  3207. end if
  3208. ! not changed by default
  3209. md%changed = .false.
  3210. !------------------
  3211. ! time stuff
  3212. !------------------
  3213. ! get time interval of met field and check if data from start and/or end
  3214. ! of interval must be read or copy
  3215. call SetupSetup( md, tr, &
  3216. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  3217. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  3218. status )
  3219. IF_NOTOK_RETURN(status=1)
  3220. ! -------------------------
  3221. ! Read/write primary field
  3222. ! -------------------------
  3223. if ( data1_read ) then
  3224. ! test
  3225. if ( md%ls(1) /= md%ls(2) ) then
  3226. write (gol,'("SETUP_2D called instead of SETUP_3D, field is 3D:")'); call goErr
  3227. write (gol, '(" md%ls(1:2) : ",2i3)') md%ls; call goErr
  3228. status=1; IF_NOTOK_RETURN(status=1)
  3229. end if
  3230. ! could get those bounds from md% directly
  3231. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  3232. allocate( field( i1:i2, j1:j2) ) !! bonds are not strictly required, could as well do (i2-i1+1, ..)
  3233. ! Read/write
  3234. select case ( md%name )
  3235. case ( 'sp', 'sps' )
  3236. ! special routine for surface pressure
  3237. call Read_SP( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3238. data1_tref, data1_t1, data1_t2, &
  3239. lli(region), FIELD, md%tmi1, status )
  3240. IF_NOTOK_RETURN(status=1)
  3241. case ( 'srols' )
  3242. ! special routine for Olsson surface roughness:
  3243. call Read_SR_OLS( tmmd, md%sourcekey, &
  3244. data1_tref, data1_t1, data1_t2, &
  3245. lli(region), FIELD, md%tmi1, status )
  3246. IF_NOTOK_RETURN(status=1)
  3247. case default
  3248. ! general field
  3249. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3250. data1_tref, data1_t1, data1_t2, lli(region), &
  3251. nuv, FIELD, md%tmi1, status )
  3252. IF_NOTOK_RETURN(status=1)
  3253. end select
  3254. md%data1(i1:i2, j1:j2, 1) = field
  3255. deallocate( field )
  3256. ! write meteofiles
  3257. if ( md%putout ) then
  3258. write(gol,*)"writing of remapped met field not tested yet.. SKIPPED." ; call goErr
  3259. TRACEBACK; status=1; return
  3260. !!!!! NEED SOMETHING SIMILAR FOR DATA2 BELOW
  3261. ! ! Need whole region for I/O on root. Dummy else.
  3262. ! IF (isRoot) THEN
  3263. ! ALLOCATE( field( im(region), jm(region)) )
  3264. ! ELSE
  3265. ! ALLOCATE( field(1,1) )
  3266. ! END IF
  3267. !
  3268. ! CALL GATHER( dgrid(region), md%data1(:,:,1), FIELD_GLOBAL, md%halo, status)
  3269. !
  3270. ! IF (isRoot) THEN
  3271. !
  3272. ! call WriteField( tmmd, md%destkey, &
  3273. ! md%tmi1, trim(md%name), trim(md%unit), &
  3274. ! data1_tref, data1_t1, data1_t2, &
  3275. ! GLOBAL_lli(region), nuv, FIELD, status )
  3276. ! IF_NOTOK_RETURN(status=1)
  3277. !
  3278. ! END IF
  3279. ! DEALLOCATE( FIELD )
  3280. end if
  3281. ! data array is filled now:
  3282. md%filled1 = .true.
  3283. md%tr1(1) = data1_t1
  3284. md%tr1(2) = data1_t2
  3285. md%changed = .true.
  3286. else if ( data1_copy ) then
  3287. ! copy data from secondary array:
  3288. md%data1 = md%data2
  3289. ! data array is filled now:
  3290. md%filled1 = .true.
  3291. md%tr1(1) = data1_t1
  3292. md%tr1(2) = data1_t2
  3293. md%changed = .true.
  3294. end if
  3295. ! -------------------------
  3296. ! Read/write (or copy or nothing) secondary field
  3297. ! -------------------------
  3298. if ( data2_read ) then
  3299. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  3300. allocate( field( i1:i2, j1:j2) )
  3301. select case ( md%name )
  3302. case ( 'sp', 'sps' )
  3303. ! special routine for surface pressure
  3304. call Read_SP( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3305. data2_tref, data2_t1, data2_t2, &
  3306. lli(region), FIELD, md%tmi2, status )
  3307. IF_NOTOK_RETURN(status=1)
  3308. case default
  3309. ! general field
  3310. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3311. data2_tref, data2_t1, data2_t2, lli(region), &
  3312. nuv, FIELD, md%tmi2, status )
  3313. IF_NOTOK_RETURN(status=1)
  3314. end select
  3315. md%data2(i1:i2, j1:j2, 1) = FIELD
  3316. deallocate( field )
  3317. ! write meteo files
  3318. !TODO if ( md%putout ) then
  3319. !TODO
  3320. !TODO end if
  3321. !TODO
  3322. ! data array is filled now
  3323. md%filled2 = .true.
  3324. md%tr2(1) = data2_t1
  3325. md%tr2(2) = data2_t2
  3326. else if ( data2_copy ) then
  3327. ! copy data from secondary array
  3328. md%data2 = md%data1
  3329. ! data array is filled now
  3330. md%filled2 = .true.
  3331. md%tr2(1) = data2_t1
  3332. md%tr2(2) = data2_t2
  3333. end if
  3334. ! -------------------------
  3335. ! time interpolation
  3336. ! -------------------------
  3337. call TimeInterpolation( md, tr, status )
  3338. IF_NOTOK_RETURN(status=1)
  3339. ! -------------------------
  3340. ! done
  3341. ! -------------------------
  3342. status = 0
  3343. if (okdebug) call goLabel()
  3344. END SUBROUTINE SETUP_2D_PARALLEL_IO
  3345. !EOC
  3346. !--------------------------------------------------------------------------
  3347. ! TM5 !
  3348. !--------------------------------------------------------------------------
  3349. !BOP
  3350. !
  3351. ! !IROUTINE: SETUP_3D
  3352. !
  3353. ! !DESCRIPTION: same as SETUP_2D, but for 3D fields by accounting for levels
  3354. !\\
  3355. !\\
  3356. ! !INTERFACE:
  3357. !
  3358. SUBROUTINE SETUP_3D( region, md, tr, lli, nuv, levi, nw, status )
  3359. !
  3360. ! !USES:
  3361. !
  3362. use GO, only : TDate, wrtgol, operator(/=)
  3363. use Grid, only : TllGridInfo, TLevelInfo
  3364. use TMM, only : TMeteoInfo, ReadField, WriteField
  3365. use dims, only : im, jm
  3366. !
  3367. ! !INPUT/OUTPUT PARAMETERS:
  3368. !
  3369. type(TMeteoData), intent(inout) :: md ! met field
  3370. !
  3371. ! !INPUT PARAMETERS:
  3372. !
  3373. integer, intent(in) :: region ! region number
  3374. type(TDate), intent(in) :: tr(2) ! dates
  3375. type(TllGridInfo), intent(in) :: lli ! grid
  3376. character(len=1), intent(in) :: nuv ! horiz. staggering
  3377. type(TLevelInfo), intent(in) :: levi ! levels
  3378. character(len=1), intent(in) :: nw ! vertical staggering
  3379. !
  3380. ! !OUTPUT PARAMETERS:
  3381. !
  3382. integer, intent(out) :: status ! return code
  3383. !
  3384. ! !REVISION HISTORY:
  3385. ! 4 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  3386. !
  3387. !EOP
  3388. !------------------------------------------------------------------------
  3389. !BOC
  3390. character(len=*), parameter :: rname = mname//'/Setup_3d'
  3391. logical :: data1_read, data1_copy
  3392. type(TDate) :: data1_tref, data1_t1, data1_t2
  3393. logical :: data2_read, data2_copy
  3394. type(TDate) :: data2_tref, data2_t1, data2_t2
  3395. real, allocatable :: tmp_sp(:,:)
  3396. real, pointer :: field(:,:,:) ! work array (data)
  3397. integer :: is(2), js(2) ! work arrays (bounds)
  3398. ! --- begin -----------------------------
  3399. if (okdebug) call goLabel(rname)
  3400. ! leave if not in use:
  3401. if ( .not. md%used ) then
  3402. if (okdebug) call goLabel()
  3403. status=0; return
  3404. end if
  3405. ! debug
  3406. !write (gol,'(a," @ ",a)') trim(md%name),trim(lli%name); call goPr
  3407. ! not changed by default
  3408. md%changed = .false.
  3409. !------------------
  3410. ! time stuff
  3411. !------------------
  3412. ! get time interval of met field and check if data from start and/or end
  3413. ! of interval must be read or copy
  3414. call SetupSetup( md, tr, &
  3415. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  3416. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  3417. status )
  3418. IF_NOTOK_RETURN(status=1)
  3419. ! -------------------------
  3420. ! Read/write primary field
  3421. ! -------------------------
  3422. if ( data1_read ) then
  3423. ! Need whole region for I/O on root. Dummy else. Allocate global array for I/O
  3424. is = (/1,im(region)/)
  3425. js = (/1,jm(region)/)
  3426. IF (isRoot) THEN
  3427. ALLOCATE( FIELD( is(1):is(2), js(1):js(2), md%ls(1):md%ls(2) ))
  3428. ELSE
  3429. ALLOCATE( FIELD(1,1,1) )
  3430. END IF
  3431. ! Read/write on root
  3432. IOroot : IF (isRoot) THEN
  3433. ! safety check
  3434. if ( data1_t2 /= data1_t1 ) then
  3435. ! write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  3436. ! call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  3437. ! call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  3438. ! write (gol,'("please decide what to do with surface pressures ... ")'); call goErr
  3439. ! call goErr; status=1; return
  3440. write (gol,'("WARNING - using instant surface pressure for regridding temporal averaged 3D field ...")'); call goPr
  3441. end if
  3442. ! surface pressure
  3443. allocate( tmp_sp( is(1):is(2), js(1):js(2) ) )
  3444. ! fill data
  3445. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3446. data1_tref, data1_t1, data1_t2, &
  3447. lli, nuv, levi, nw, &
  3448. tmp_sp, FIELD, md%tmi1, status )
  3449. IF_NOTOK_RETURN(status=1)
  3450. ! write meteo file
  3451. if ( md%putout ) then
  3452. call WriteField( tmmd, md%destkey, &
  3453. md%tmi1, 'sp', trim(md%name), trim(md%unit), &
  3454. data1_tref, data1_t1, data1_t2, &
  3455. lli, nuv, levi, nw, &
  3456. tmp_sp, FIELD, status )
  3457. IF_NOTOK_RETURN(status=1)
  3458. end if
  3459. ! clear
  3460. deallocate( tmp_sp )
  3461. END IF IOroot
  3462. CALL SCATTER( dgrid(region), md%data1, FIELD, md%halo, status)
  3463. IF_NOTOK_RETURN(status=1)
  3464. DEALLOCATE( FIELD )
  3465. ! data array is filled now
  3466. md%filled1 = .true.
  3467. md%tr1(1) = data1_t1
  3468. md%tr1(2) = data1_t2
  3469. md%changed = .true.
  3470. else if ( data1_copy ) then
  3471. ! copy data from secondary array:
  3472. md%data1 = md%data2
  3473. ! data array is filled now:
  3474. md%filled1 = .true.
  3475. md%tr1(1) = data1_t1
  3476. md%tr1(2) = data1_t2
  3477. md%changed = .true.
  3478. end if
  3479. !--------------------------
  3480. ! read/write secondary field
  3481. !--------------------------
  3482. if ( data2_read ) then
  3483. ! Need whole region for I/O on root. Dummy else.
  3484. is = (/1,im(region)/)
  3485. js = (/1,jm(region)/)
  3486. IF (isRoot) THEN
  3487. ALLOCATE(field(im(region), jm(region), md%ls(1):md%ls(2)))
  3488. ELSE
  3489. ALLOCATE(field(1,1,1))
  3490. END IF
  3491. ! Read/write
  3492. IOroot2 : IF (isRoot) THEN
  3493. ! safety check ...
  3494. if ( data2_t2 /= data2_t1 ) then
  3495. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  3496. call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  3497. call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  3498. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  3499. call goErr; status=1; return
  3500. end if
  3501. ! surface pressure
  3502. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  3503. ! fill data
  3504. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3505. data2_tref, data2_t1, data2_t2, &
  3506. lli, nuv, levi, nw, &
  3507. tmp_sp, FIELD, md%tmi2, status )
  3508. IF_NOTOK_RETURN(status=1)
  3509. ! write meteofiles
  3510. if ( md%putout ) then
  3511. call WriteField( tmmd, md%destkey, &
  3512. md%tmi2, 'sp', trim(md%name), trim(md%unit), &
  3513. data2_tref, data2_t1, data2_t2, &
  3514. lli, nuv, levi, nw, &
  3515. tmp_sp, FIELD, status )
  3516. IF_NOTOK_RETURN(status=1)
  3517. end if
  3518. ! clear
  3519. deallocate( tmp_sp )
  3520. END IF IOroot2
  3521. CALL SCATTER( dgrid(region), md%data2, FIELD, md%halo, status)
  3522. IF_NOTOK_RETURN(status=1)
  3523. DEALLOCATE( FIELD )
  3524. ! data array is filled now
  3525. md%filled2 = .true.
  3526. md%tr2(1) = data2_t1
  3527. md%tr2(2) = data2_t2
  3528. else if ( data2_copy ) then
  3529. ! copy data from secondary array
  3530. md%data2 = md%data1
  3531. ! data array is filled now
  3532. md%filled2 = .true.
  3533. md%tr2(1) = data2_t1
  3534. md%tr2(2) = data2_t2
  3535. end if
  3536. ! -------------------------
  3537. ! time interpolation
  3538. ! -------------------------
  3539. call TimeInterpolation( md, tr, status )
  3540. IF_NOTOK_RETURN(status=1)
  3541. ! -------------------------
  3542. ! done
  3543. ! -------------------------
  3544. status = 0
  3545. if (okdebug) call goLabel()
  3546. END SUBROUTINE SETUP_3D
  3547. !EOC
  3548. !--------------------------------------------------------------------------
  3549. ! TM5 !
  3550. !--------------------------------------------------------------------------
  3551. !BOP
  3552. !
  3553. ! !IROUTINE: SETUP_3D_PARALLEL_IO
  3554. !
  3555. ! !DESCRIPTION: same as SETUP_3D, except reading is done by every processes.
  3556. !\\
  3557. !\\
  3558. ! !INTERFACE:
  3559. !
  3560. SUBROUTINE SETUP_3D_PARALLEL_IO( region, md, tr, tdlli, nuv, levi, nw, status )
  3561. !
  3562. ! !USES:
  3563. !
  3564. use GO, only : TDate, wrtgol, operator(/=)
  3565. use Grid, only : TllGridInfo, TLevelInfo
  3566. use TMM, only : TMeteoInfo, ReadField, WriteField
  3567. use meteodata, only : TMeteoData, TimeInterpolation
  3568. use dims, only : im, jm
  3569. !
  3570. ! !INPUT/OUTPUT PARAMETERS:
  3571. !
  3572. type(TMeteoData), intent(inout) :: md ! met field
  3573. !
  3574. ! !INPUT PARAMETERS:
  3575. !
  3576. integer, intent(in) :: region ! region number
  3577. type(TDate), intent(in) :: tr(2) ! dates
  3578. type(TllGridInfo), intent(in) :: tdlli ! dummy.. grid is already determined by the region
  3579. character(len=1), intent(in) :: nuv ! horiz. staggering
  3580. type(TLevelInfo), intent(in) :: levi ! levels
  3581. character(len=1), intent(in) :: nw ! vertical staggering
  3582. !
  3583. ! !OUTPUT PARAMETERS:
  3584. !
  3585. integer, intent(out) :: status ! return code
  3586. !
  3587. ! !REVISION HISTORY:
  3588. ! 18 Oct 2013 - Ph. Le Sager - v0
  3589. !
  3590. !EOP
  3591. !------------------------------------------------------------------------
  3592. !BOC
  3593. character(len=*), parameter :: rname = mname//'/Setup_3d_parallel_io'
  3594. logical :: data1_read, data1_copy
  3595. type(TDate) :: data1_tref, data1_t1, data1_t2
  3596. logical :: data2_read, data2_copy
  3597. type(TDate) :: data2_tref, data2_t1, data2_t2
  3598. integer :: i1, i2, j1, j2
  3599. real, allocatable :: tmp_sp(:,:)
  3600. real, pointer :: field(:,:,:) ! work array
  3601. ! --- begin -----------------------------
  3602. if (okdebug) call goLabel(rname)
  3603. ! leave if not in use:
  3604. if ( .not. md%used ) then
  3605. if (okdebug) call goLabel()
  3606. status=0; return
  3607. end if
  3608. ! not changed by default
  3609. md%changed = .false.
  3610. !------------------
  3611. ! time stuff
  3612. !------------------
  3613. ! get time interval of met field and check if data from start and/or end
  3614. ! of interval must be read or copy
  3615. call SetupSetup( md, tr, &
  3616. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  3617. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  3618. status )
  3619. IF_NOTOK_RETURN(status=1)
  3620. ! -------------------------
  3621. ! Read/write primary field
  3622. ! -------------------------
  3623. if ( data1_read ) then
  3624. ! could get those bounds from md% directly
  3625. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  3626. allocate( field( i1:i2, j1:j2, md%ls(1):md%ls(2)))
  3627. ! safety check
  3628. if ( data1_t2 /= data1_t1 ) then
  3629. ! write (gol,'("not sure that this routine is correct for time intervals:")') ; call goErr
  3630. ! call wrtgol( ' data1_t1 : ', data1_t1 ) ; call goErr
  3631. ! call wrtgol( ' data1_t2 : ', data1_t2 ) ; call goErr
  3632. ! write (gol,'("please decide what to do with surface pressures ... ")') ; call goErr
  3633. ! TRACEBACK; status=1; return
  3634. write (gol,'("WARNING - using instant surface pressure for regridding temporal averaged 3D field ...")'); call goPr
  3635. end if
  3636. ! surface pressure
  3637. allocate( tmp_sp( i1:i2, j1:j2 ) )
  3638. ! read data
  3639. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3640. data1_tref, data1_t1, data1_t2, &
  3641. lli(region), nuv, levi, nw, &
  3642. tmp_sp, FIELD, md%tmi1, status )
  3643. IF_NOTOK_RETURN(status=1)
  3644. md%data1(i1:i2, j1:j2, md%ls(1):md%ls(2)) = field
  3645. ! write meteo file
  3646. if ( md%putout ) then
  3647. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  3648. TRACEBACK; status=1; return
  3649. ! IF (isRoot) THEN
  3650. ! ALLOCATE(field(im(region), jm(region), md%ls(1):md%ls(2)))
  3651. ! ELSE
  3652. ! ALLOCATE(field(1,1,1))
  3653. ! END IF
  3654. !
  3655. !
  3656. ! CALL gather( dgrid(region), md%data1, FIELD, md%halo, status)
  3657. ! IF_NOTOK_RETURN(status=1)
  3658. !
  3659. ! !! NEED global_lli and to also gather SP
  3660. !
  3661. ! if (isRoot) then
  3662. ! call WriteField( tmmd, md%destkey, &
  3663. ! md%tmi1, 'sp', trim(md%name), trim(md%unit), &
  3664. ! data1_tref, data1_t1, data1_t2, &
  3665. ! GLOBAL_lli(region), nuv, levi, nw, &
  3666. ! tmp_sp, FIELD, status )
  3667. ! IF_NOTOK_RETURN(status=1)
  3668. ! end if
  3669. !
  3670. endif
  3671. DEALLOCATE( TMP_SP )
  3672. DEALLOCATE( FIELD )
  3673. ! data array is filled now
  3674. md%filled1 = .true.
  3675. md%tr1(1) = data1_t1
  3676. md%tr1(2) = data1_t2
  3677. md%changed = .true.
  3678. else if ( data1_copy ) then
  3679. ! copy data from secondary array:
  3680. md%data1 = md%data2
  3681. ! data array is filled now:
  3682. md%filled1 = .true.
  3683. md%tr1(1) = data1_t1
  3684. md%tr1(2) = data1_t2
  3685. md%changed = .true.
  3686. end if
  3687. !--------------------------
  3688. ! read/write secondary field
  3689. !--------------------------
  3690. if ( data2_read ) then
  3691. ! could get those bounds from md% directly
  3692. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  3693. allocate( field( i1:i2, j1:j2, md%ls(1):md%ls(2)))
  3694. ! safety check ...
  3695. if ( data2_t2 /= data2_t1 ) then
  3696. write (gol,'("not sure that this routine is correct for time intervals:")') ; call goErr
  3697. call wrtgol( ' data2_t1 : ', data2_t1 ) ; call goErr
  3698. call wrtgol( ' data2_t2 : ', data2_t2 ) ; call goErr
  3699. write (gol,'("please deceide what to do with surface pressures ... ")') ; call goErr
  3700. TRACEBACK; status=1; return
  3701. end if
  3702. ! surface pressure
  3703. allocate( tmp_sp( i1:i2, j1:j2 ) )
  3704. ! read data
  3705. call ReadField( tmmd, md%sourcekey, trim(md%name), trim(md%unit), &
  3706. data2_tref, data2_t1, data2_t2, &
  3707. lli(region), nuv, levi, nw, &
  3708. tmp_sp, FIELD, md%tmi2, status )
  3709. IF_NOTOK_RETURN(status=1)
  3710. md%data2(i1:i2, j1:j2, md%ls(1):md%ls(2)) = field
  3711. ! write meteofiles
  3712. if ( md%putout ) then
  3713. write(gol,*)"writing of remapped met field not finished yet.. Sorry. SKIPPED." ; call goErr
  3714. TRACEBACK; status=1; return
  3715. ! IF (isRoot) THEN
  3716. ! ALLOCATE(field(im(region), jm(region), md%ls(1):md%ls(2)))
  3717. ! ELSE
  3718. ! ALLOCATE(field(1,1,1))
  3719. ! END IF
  3720. !
  3721. ! CALL gather( dgrid(region), md%data2, FIELD, md%halo, status)
  3722. ! IF_NOTOK_RETURN(status=1)
  3723. !
  3724. ! !! NEED to also gather SP
  3725. !
  3726. ! if(isroot)then
  3727. ! call WriteField( tmmd, md%destkey, &
  3728. ! md%tmi2, 'sp', trim(md%name), trim(md%unit), &
  3729. ! data2_tref, data2_t1, data2_t2, &
  3730. ! global_lli(region), nuv, levi, nw, &
  3731. ! tmp_sp, FIELD, status )
  3732. ! IF_NOTOK_RETURN(status=1)
  3733. ! END IF
  3734. !
  3735. end if
  3736. ! clear
  3737. DEALLOCATE( TMP_SP )
  3738. DEALLOCATE( FIELD )
  3739. ! data array is filled now
  3740. md%filled2 = .true.
  3741. md%tr2(1) = data2_t1
  3742. md%tr2(2) = data2_t2
  3743. else if ( data2_copy ) then
  3744. ! copy data from secondary array
  3745. md%data2 = md%data1
  3746. ! data array is filled now
  3747. md%filled2 = .true.
  3748. md%tr2(1) = data2_t1
  3749. md%tr2(2) = data2_t2
  3750. end if
  3751. ! -------------------------
  3752. ! time interpolation
  3753. ! -------------------------
  3754. call TimeInterpolation( md, tr, status )
  3755. IF_NOTOK_RETURN(status=1)
  3756. ! -------------------------
  3757. ! done
  3758. ! -------------------------
  3759. status = 0
  3760. if (okdebug) call goLabel()
  3761. END SUBROUTINE SETUP_3D_PARALLEL_IO
  3762. !EOC
  3763. ! **************************************************************
  3764. ! ***
  3765. ! *** Specific SETUP routines for MASS FLUXES
  3766. ! ***
  3767. ! **************************************************************
  3768. SUBROUTINE SETUP_MFUV_SERIAL_IO( region, md_mfu, md_mfv, tr, lli, levi, status )
  3769. ! Set up MFU and MFV (horizontal fluxes)
  3770. ! Read or copy %data1 and %data2, and get %data through time interpolation
  3771. use GO, only : TDate, wrtgol, operator(/=)
  3772. use Grid, only : TllGridInfo, TLevelInfo
  3773. use TMM, only : TMeteoInfo, Read_MFUV, WriteField
  3774. use meteodata, only : TMeteoData, TimeInterpolation
  3775. use dims, only : im, jm
  3776. ! --- in/out ----------------------------------
  3777. integer, intent(in) :: region ! region number
  3778. type(TMeteoData), intent(inout) :: md_mfu
  3779. type(TMeteoData), intent(inout) :: md_mfv
  3780. type(TDate), intent(in) :: tr(2) ! time range
  3781. type(TllGridInfo), intent(in) :: lli
  3782. type(TLevelInfo), intent(in) :: levi
  3783. integer, intent(out) :: status
  3784. ! --- const --------------------------------------
  3785. character(len=*), parameter :: rname = mname//'/SETUP_MFUV_SERIAL_IO'
  3786. ! --- local ----------------------------------
  3787. logical :: data1_read, data1_copy
  3788. type(TDate) :: data1_tref, data1_t1, data1_t2
  3789. logical :: data2_read, data2_copy
  3790. type(TDate) :: data2_tref, data2_t1, data2_t2
  3791. logical :: NorthBorder, WestBorder ! tile location
  3792. real, allocatable :: tmp_spu(:,:)
  3793. real, allocatable :: tmp_spv(:,:)
  3794. ! to read the entire region
  3795. real, pointer :: wrld_u(:,:,:), wrld_v(:,:,:), wrkarr(:,:,:)
  3796. integer, dimension(2) :: is, js, ls
  3797. integer :: halo, i1, i2, j1, j2
  3798. real, allocatable :: bigIslice(:,:), bigJslice(:,:), Islice(:,:), Jslice(:,:)
  3799. ! --- begin -----------------------------
  3800. if (okdebug) call goLabel(rname)
  3801. ! leave if not in use:
  3802. if ( md_mfu%used .neqv. md_mfv%used ) then
  3803. write (gol,'("either none or both mfu and mfv should be in use")'); call goErr
  3804. call goErr; status=1; return
  3805. end if
  3806. if ( .not. md_mfu%used ) then
  3807. if (okdebug) call goLabel()
  3808. status=0; return
  3809. end if
  3810. ! not changed by default
  3811. md_mfu%changed = .false.
  3812. md_mfv%changed = .false.
  3813. ! local indices and tile location
  3814. CALL GET_DISTGRID( dgrid(region), &
  3815. I_STRT=i1, I_STOP=i2, &
  3816. J_STRT=j1, J_STOP=j2, &
  3817. hasWestBorder=WestBorder, hasNorthBorder=NorthBorder)
  3818. !------------------
  3819. ! time stuff
  3820. !------------------
  3821. ! get time interval of met field and check if data from start and/or end
  3822. ! of interval must be read (sufficient to setup from mfu only)
  3823. call SetupSetup( md_mfu, tr, &
  3824. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  3825. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  3826. status )
  3827. IF_NOTOK_RETURN(status=1)
  3828. !--------------------------
  3829. ! read/write primary field
  3830. !--------------------------
  3831. if ( data1_read ) then
  3832. ! Use fact that mfu and mfv have been allocated with the same bounds and halo
  3833. ! Need whole region for I/O on root. Dummy else.
  3834. is = (/1,im(region)/)
  3835. js = (/1,jm(region)/)
  3836. ls = md_mfu%ls
  3837. halo = md_mfu%halo
  3838. IF (isRoot) THEN
  3839. ALLOCATE( wrld_u( is(1)-halo:is(2)+halo, js(1)-halo:js(2)+halo, ls(1):ls(2)) )
  3840. ALLOCATE( wrld_v( is(1)-halo:is(2)+halo, js(1)-halo:js(2)+halo, ls(1):ls(2)) )
  3841. ALLOCATE( wrkarr( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  3842. wrld_v = 0.
  3843. wrld_u = 0.
  3844. allocate( bigIslice(jm(region),ls(1):ls(2)))
  3845. allocate( bigJslice(im(region),ls(1):ls(2)))
  3846. ELSE
  3847. ALLOCATE(wrld_u(1,1,1), wrld_v(1,1,1), wrkarr(1,1,1))
  3848. ALLOCATE( bigIslice(1,1), bigJslice(1,1) )
  3849. END IF
  3850. ALLOCATE( Islice(j1:j2,ls(1):ls(2)) )
  3851. ALLOCATE( Jslice(i1:i2,ls(1):ls(2)) )
  3852. if (isRoot) then ! only root does IO
  3853. ! safety check ...
  3854. if ( data1_t2 /= data1_t1 ) then
  3855. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  3856. call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  3857. call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  3858. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  3859. call goErr; status=1; return
  3860. end if
  3861. ! surface pressure field:
  3862. allocate( tmp_spu(is(1)-1:is(2),js(1):js(2) ) )
  3863. allocate( tmp_spv(is(1) :is(2),js(1):js(2)+1) )
  3864. ! NOTE: strange old indexing:
  3865. ! pu_tmpp --> pu(0:imr,1:jmr ,1:lmr) in pu_t(0:imr+1,0:jmr+1,0:lmr)
  3866. ! pv_tmpp --> pv(1:imr,1:jmr+1,1:lmr) in pv_t(0:imr+1,0:jmr+1,0:lmr)
  3867. ! fill data:
  3868. call Read_MFUV( tmmd, md_mfu%sourcekey, &
  3869. data1_tref, data1_t1, data1_t2, lli, levi, &
  3870. tmp_spu, &
  3871. wrld_u( is(1)-1:is(2), js(1):js(2), ls(1)+1:ls(2) ), &
  3872. md_mfu%tmi1, &
  3873. tmp_spv, &
  3874. wrld_v( is(1):is(2), js(1):js(2)+1, ls(1)+1:ls(2) ), &
  3875. md_mfv%tmi1, &
  3876. status )
  3877. IF_NOTOK_RETURN(status=1)
  3878. ! write meteofiles
  3879. if ( md_mfu%putout ) then
  3880. call WriteField( tmmd, md_mfu%destkey, &
  3881. md_mfu%tmi1, 'spu', trim(md_mfu%name), trim(md_mfu%unit), &
  3882. data1_tref, data1_t1, data1_t2, &
  3883. lli, 'u', levi, 'n', &
  3884. tmp_spu, wrld_u(is(1)-1:is(2), js(1):js(2), ls(1)+1:ls(2) ), &
  3885. status )
  3886. IF_NOTOK_RETURN(status=1)
  3887. end if
  3888. if ( md_mfv%putout ) then
  3889. call WriteField( tmmd, md_mfv%destkey, &
  3890. md_mfv%tmi1, 'spv', trim(md_mfv%name), trim(md_mfv%unit), &
  3891. data1_tref, data1_t1, data1_t2, &
  3892. lli, 'v', levi, 'n', &
  3893. tmp_spv, wrld_v(is(1):is(2), js(1):js(2)+1, ls(1)+1:ls(2) ), &
  3894. status )
  3895. IF_NOTOK_RETURN(status=1)
  3896. end if
  3897. ! clear
  3898. deallocate( tmp_spu )
  3899. deallocate( tmp_spv )
  3900. end if ! root ?
  3901. ! Scatter U
  3902. if(isRoot) wrkarr = wrld_u(is(1):is(2),js(1):js(2),:)
  3903. CALL SCATTER( dgrid(region), md_mfu%data1, wrkarr, md_mfu%halo, status)
  3904. IF_NOTOK_RETURN(status=1)
  3905. ! manually scatter wrld_u(is(1)-1,:,:). This is needed only with non-cyclic
  3906. ! zoom regions, since any update_halo will overwrite is(1)-1. [FIXME: could had a
  3907. ! test around these 3 lines ]
  3908. if(isRoot) bigIslice = wrld_u(0,js(1):js(2),:)
  3909. CALL SCATTER_I_BAND( dgrid(region), islice, bigIslice, status, iref=1)
  3910. if (WestBorder) md_mfu%data1(0,j1:j2,:) = islice
  3911. ! Scatter V
  3912. if(isRoot) wrkarr = wrld_v(is(1):is(2),js(1):js(2),:)
  3913. CALL SCATTER( dgrid(region), md_mfv%data1, wrkarr, md_mfv%halo, status)
  3914. IF_NOTOK_RETURN(status=1)
  3915. ! manually SCATTER wrld_v( :, js(2)+1 , :) : NORTH POLE HALO
  3916. if(isroot) bigJslice=wrld_v(is(1):is(2),jm(region)+1,:)
  3917. CALL SCATTER_J_BAND( dgrid(region), jslice, bigJslice, status, jref=jm(region))
  3918. if (NorthBorder) md_mfv%data1(i1:i2,jm(region)+1,:)=jslice
  3919. deallocate(wrld_u, wrld_v, wrkarr, bigIslice, bigJslice, Islice, Jslice)
  3920. ! data array is filled now:
  3921. md_mfu%filled1 = .true.
  3922. md_mfu%tr1(1) = data1_t1
  3923. md_mfu%tr1(2) = data1_t2
  3924. md_mfu%changed = .true.
  3925. md_mfv%filled1 = .true.
  3926. md_mfv%tr1(1) = data1_t1
  3927. md_mfv%tr1(2) = data1_t2
  3928. md_mfv%changed = .true.
  3929. else if ( data1_copy ) then
  3930. ! copy data from secondary array:
  3931. md_mfu%data1 = md_mfu%data2
  3932. md_mfv%data1 = md_mfv%data2
  3933. ! data array is filled now:
  3934. md_mfu%filled1 = .true.
  3935. md_mfu%tr1(1) = data1_t1
  3936. md_mfu%tr1(2) = data1_t2
  3937. md_mfu%changed = .true.
  3938. md_mfv%filled1 = .true.
  3939. md_mfv%tr1(1) = data1_t1
  3940. md_mfv%tr1(2) = data1_t2
  3941. md_mfv%changed = .true.
  3942. end if
  3943. !--------------------------
  3944. ! read/write secondary field
  3945. !--------------------------
  3946. if ( data2_read ) then
  3947. ! Need whole region for I/O on root. Dummy else.
  3948. is = (/1,im(region)/)
  3949. js = (/1,jm(region)/)
  3950. ls = md_mfu%ls
  3951. halo = md_mfu%halo
  3952. IF (isRoot) THEN
  3953. allocate( wrld_u( is(1)-halo:is(2)+halo, js(1)-halo:js(2)+halo, ls(1):ls(2)) )
  3954. allocate( wrld_v( is(1)-halo:is(2)+halo, js(1)-halo:js(2)+halo, ls(1):ls(2)) )
  3955. allocate( wrkarr( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  3956. wrld_v = 0.
  3957. wrld_u = 0.
  3958. allocate( bigIslice(jm(region),ls(1):ls(2)))
  3959. allocate( bigJslice(im(region),ls(1):ls(2)))
  3960. ELSE
  3961. ALLOCATE(wrld_u(1,1,1), wrld_v(1,1,1), wrkarr(1,1,1))
  3962. ALLOCATE( bigIslice(1,1), bigJslice(1,1) )
  3963. END IF
  3964. ALLOCATE( Islice(j1:j2,ls(1):ls(2)) )
  3965. ALLOCATE( Jslice(i1:i2,ls(1):ls(2)) )
  3966. if (isRoot) then ! only root does IO
  3967. ! safety check ...
  3968. if ( data2_t2 /= data2_t1 ) then
  3969. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  3970. call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  3971. call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  3972. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  3973. call goErr; status=1; return
  3974. end if
  3975. ! surface pressure field:
  3976. allocate( tmp_spu(is(1)-1:is(2),js(1):js(2) ) )
  3977. allocate( tmp_spv(is(1) :is(2),js(1):js(2)+1) )
  3978. ! NOTE: strange old indexing:
  3979. ! pu_tmpp --> pu(0:imr,1:jmr ,1:lmr) in pu_t(0:imr+1,0:jmr+1,0:lmr)
  3980. ! pv_tmpp --> pv(1:imr,1:jmr+1,1:lmr) in pv_t(0:imr+1,0:jmr+1,0:lmr)
  3981. ! fill data:
  3982. call Read_MFUV( tmmd, md_mfu%sourcekey, &
  3983. data2_tref, data2_t1, data2_t2, lli, levi, &
  3984. tmp_spu, &
  3985. wrld_u( is(1)-1:is(2), js(1):js(2), ls(1)+1:ls(2) ), &
  3986. md_mfu%tmi2, &
  3987. tmp_spv, &
  3988. wrld_v( is(1):is(2), js(1):js(2)+1, ls(1)+1:ls(2) ), &
  3989. md_mfv%tmi2, &
  3990. status )
  3991. IF_NOTOK_RETURN(status=1)
  3992. ! write meteofiles
  3993. if ( md_mfu%putout ) then
  3994. call WriteField( tmmd, md_mfu%destkey, &
  3995. md_mfu%tmi2, 'spu', trim(md_mfu%name), trim(md_mfu%unit), &
  3996. data2_tref, data2_t1, data2_t2, &
  3997. lli, 'u', levi, 'n', &
  3998. tmp_spu, wrld_u( is(1)-1:is(2), js(1):js(2), ls(1)+1:ls(2) ), &
  3999. status )
  4000. IF_NOTOK_RETURN(status=1)
  4001. endif
  4002. if ( md_mfv%putout ) then
  4003. call WriteField( tmmd, md_mfv%destkey, &
  4004. md_mfv%tmi2, 'spv', trim(md_mfv%name), trim(md_mfv%unit), &
  4005. data2_tref, data2_t1, data2_t2, &
  4006. lli, 'v', levi, 'n', &
  4007. tmp_spv, wrld_v( is(1):is(2), js(1):js(2)+1, ls(1)+1:ls(2) ), &
  4008. status )
  4009. IF_NOTOK_RETURN(status=1)
  4010. end if
  4011. ! clear
  4012. deallocate( tmp_spu )
  4013. deallocate( tmp_spv )
  4014. end if ! root
  4015. ! Scatter U
  4016. if(isRoot) wrkarr = wrld_u(is(1):is(2),js(1):js(2),:)
  4017. CALL SCATTER( dgrid(region), md_mfu%data2, wrkarr, md_mfu%halo, status)
  4018. IF_NOTOK_RETURN(status=1)
  4019. ! important for zoom regions only, since any update_halo will overwrite is(1)-1. [FIXME: could had a
  4020. ! test around these 3 lines ]
  4021. if(isRoot) bigIslice = wrld_u(0,js(1):js(2),:)
  4022. CALL SCATTER_I_BAND( dgrid(region), islice, bigIslice, status, iref=1)
  4023. if (WestBorder) md_mfu%data2(0,j1:j2,:) = islice
  4024. ! Scatter V
  4025. if(isRoot) wrkarr = wrld_v(is(1):is(2),js(1):js(2),:)
  4026. CALL SCATTER( dgrid(region), md_mfv%data2, wrkarr, md_mfv%halo, status)
  4027. IF_NOTOK_RETURN(status=1)
  4028. ! manually SCATTER wrld_v( :, js(2)+1 , :) : NORTH POLE HALO
  4029. if(isroot) bigJslice=wrld_v(is(1):is(2),jm(region)+1,:)
  4030. CALL SCATTER_J_BAND( dgrid(region), jslice, bigJslice, status, jref=jm(region))
  4031. if (NorthBorder) md_mfv%data2(i1:i2,jm(region)+1,:)=jslice
  4032. DEALLOCATE(wrld_u, wrld_v, wrkarr, bigIslice, bigJslice, Islice, Jslice)
  4033. ! data array is filled now:
  4034. md_mfu%filled2 = .true.
  4035. md_mfu%tr2(1) = data2_t1
  4036. md_mfu%tr2(2) = data2_t2
  4037. md_mfv%filled2 = .true.
  4038. md_mfv%tr2(1) = data2_t1
  4039. md_mfv%tr2(2) = data2_t2
  4040. else if ( data2_copy ) then
  4041. ! copy data from primary array:
  4042. md_mfu%data2 = md_mfu%data
  4043. md_mfv%data2 = md_mfv%data
  4044. ! data array is filled now:
  4045. md_mfu%filled2 = .true.
  4046. md_mfu%tr2(1) = data2_t1
  4047. md_mfu%tr2(2) = data2_t2
  4048. md_mfv%filled2 = .true.
  4049. md_mfv%tr2(1) = data2_t1
  4050. md_mfv%tr2(2) = data2_t2
  4051. end if
  4052. !------------------
  4053. ! time interpolation
  4054. !------------------
  4055. call TimeInterpolation( md_mfu, tr, status )
  4056. IF_NOTOK_RETURN(status=1)
  4057. call TimeInterpolation( md_mfv, tr, status )
  4058. IF_NOTOK_RETURN(status=1)
  4059. !------------------
  4060. ! done
  4061. !------------------
  4062. status = 0
  4063. if (okdebug) call goLabel()
  4064. END SUBROUTINE SETUP_MFUV_SERIAL_IO
  4065. !--------------------------------------------------------------------------
  4066. ! TM5 !
  4067. !--------------------------------------------------------------------------
  4068. !BOP
  4069. !
  4070. ! !IROUTINE: SETUP_MFUV_PARALLEL_IO
  4071. !
  4072. ! !DESCRIPTION: same as setup_mfuv, but with parallel I/O.
  4073. !\\
  4074. !\\
  4075. ! !INTERFACE:
  4076. !
  4077. SUBROUTINE SETUP_MFUV_PARALLEL_IO( region, md_mfu, md_mfv, tr, levi, status )
  4078. !
  4079. ! !USES:
  4080. !
  4081. use GO, only : TDate, wrtgol, operator(/=)
  4082. use Grid, only : TllGridInfo, TLevelInfo
  4083. use TMM, only : TMeteoInfo, Read_MFUV, WriteField
  4084. use dims, only : im, jm
  4085. !
  4086. ! !INPUT PARAMETERS:
  4087. !
  4088. integer, intent(in) :: region ! region number
  4089. !
  4090. ! !INPUT/OUTPUT PARAMETERS:
  4091. !
  4092. type(TMeteoData), intent(inout) :: md_mfu
  4093. type(TMeteoData), intent(inout) :: md_mfv
  4094. type(TDate), intent(in) :: tr(2) ! time range
  4095. type(TLevelInfo), intent(in) :: levi
  4096. !
  4097. ! !OUTPUT PARAMETERS:
  4098. !
  4099. integer, intent(out) :: status
  4100. !
  4101. ! !REVISION HISTORY:
  4102. ! 24 Oct 2013 - Ph. Le Sager - v0
  4103. !
  4104. ! !REMARKS:
  4105. !
  4106. !EOP
  4107. !------------------------------------------------------------------------
  4108. !BOC
  4109. character(len=*), parameter :: rname = mname//'/SETUP_MFUV_PARALLEL_IO'
  4110. logical :: data1_read, data1_copy
  4111. type(TDate) :: data1_tref, data1_t1, data1_t2
  4112. logical :: data2_read, data2_copy
  4113. type(TDate) :: data2_tref, data2_t1, data2_t2
  4114. logical :: NorthBorder, WestBorder ! tile location
  4115. real, allocatable :: tmp_spu(:,:)
  4116. real, allocatable :: tmp_spv(:,:)
  4117. real, pointer :: wrld_u(:,:,:), wrld_v(:,:,:)
  4118. integer, dimension(2) :: ls
  4119. integer :: halo, i1, i2, j1, j2
  4120. ! --- begin -----------------------------
  4121. if (okdebug) call goLabel(rname)
  4122. ! leave if not in use:
  4123. if ( md_mfu%used .neqv. md_mfv%used ) then
  4124. write (gol,'("either none or both mfu and mfv should be in use")'); call goErr
  4125. TRACEBACK; status=1; return
  4126. end if
  4127. if ( .not. md_mfu%used ) then
  4128. if (okdebug) call goLabel()
  4129. status=0; return
  4130. end if
  4131. ! not changed by default
  4132. md_mfu%changed = .false.
  4133. md_mfv%changed = .false.
  4134. ! local indices and tile location
  4135. CALL GET_DISTGRID( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2, &
  4136. hasWestBorder=WestBorder, hasNorthBorder=NorthBorder)
  4137. !-------------------------
  4138. ! time stuff & work arrays
  4139. !-------------------------
  4140. ! get time interval of met field and check if data from start and/or end
  4141. ! of interval must be read (sufficient to setup from mfu only)
  4142. call SetupSetup( md_mfu, tr, &
  4143. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  4144. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  4145. status )
  4146. IF_NOTOK_RETURN(status=1)
  4147. if (data2_read .or. data1_read) then
  4148. ls = md_mfu%ls
  4149. halo = md_mfu%halo
  4150. ALLOCATE( wrld_u( i1-halo:i2+halo, j1-halo:j2+halo, ls(1):ls(2)) )
  4151. ALLOCATE( wrld_v( i1-halo:i2+halo, j1-halo:j2+halo, ls(1):ls(2)) )
  4152. wrld_v = 0.
  4153. wrld_u = 0.
  4154. ! surface pressure field:
  4155. allocate( tmp_spu(i1-1:i2, j1:j2 ) )
  4156. allocate( tmp_spv(i1 :i2, j1:j2+1) )
  4157. end if
  4158. !--------------------------
  4159. ! read/write primary field
  4160. !--------------------------
  4161. if ( data1_read ) then
  4162. ! safety check
  4163. if ( data1_t2 /= data1_t1 ) then
  4164. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  4165. call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  4166. call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  4167. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  4168. TRACEBACK; status=1; return
  4169. end if
  4170. ! NOTE: strange old indexing:
  4171. ! pu_tmpp --> pu(0:imr,1:jmr ,1:lmr) in pu_t(0:imr+1,0:jmr+1,0:lmr)
  4172. ! pv_tmpp --> pv(1:imr,1:jmr+1,1:lmr) in pv_t(0:imr+1,0:jmr+1,0:lmr)
  4173. call Read_MFUV( tmmd, md_mfu%sourcekey, &
  4174. data1_tref, data1_t1, data1_t2, lli(region), levi, &
  4175. tmp_spu, &
  4176. wrld_u( i1-1:i2, j1:j2, ls(1)+1:ls(2) ), &
  4177. md_mfu%tmi1, &
  4178. tmp_spv, &
  4179. wrld_v( i1:i2, j1:j2+1, ls(1)+1:ls(2) ), &
  4180. md_mfv%tmi1, &
  4181. status )
  4182. IF_NOTOK_RETURN(status=1)
  4183. ! write meteofiles
  4184. if ( md_mfu%putout ) then
  4185. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4186. TRACEBACK; status=1; return
  4187. ! call WriteField( tmmd, md_mfu%destkey, &
  4188. ! md_mfu%tmi1, 'spu', trim(md_mfu%name), trim(md_mfu%unit), &
  4189. ! data1_tref, data1_t1, data1_t2, &
  4190. ! lli, 'u', levi, 'n', &
  4191. ! tmp_spu, wrld_u(is(1)-1:is(2), js(1):js(2), ls(1)+1:ls(2) ), &
  4192. ! status )
  4193. ! IF_NOTOK_RETURN(status=1)
  4194. end if
  4195. if ( md_mfv%putout ) then
  4196. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4197. TRACEBACK; status=1; return
  4198. ! call WriteField( tmmd, md_mfv%destkey, &
  4199. ! md_mfv%tmi1, 'spv', trim(md_mfv%name), trim(md_mfv%unit), &
  4200. ! data1_tref, data1_t1, data1_t2, &
  4201. ! lli, 'v', levi, 'n', &
  4202. ! tmp_spv, wrld_v(is(1):is(2), js(1):js(2)+1, ls(1)+1:ls(2) ), &
  4203. ! status )
  4204. ! IF_NOTOK_RETURN(status=1)
  4205. end if
  4206. md_mfu%data1( i1-1:i2, j1:j2, ls(1):ls(2)) = wrld_u(i1-1:i2, j1:j2, :)
  4207. md_mfv%data1( i1 :i2, j1:j2+1, ls(1):ls(2)) = wrld_v(i1 :i2, j1:j2+1, :)
  4208. ! data array is filled now:
  4209. md_mfu%filled1 = .true.
  4210. md_mfu%tr1(1) = data1_t1
  4211. md_mfu%tr1(2) = data1_t2
  4212. md_mfu%changed = .true.
  4213. md_mfv%filled1 = .true.
  4214. md_mfv%tr1(1) = data1_t1
  4215. md_mfv%tr1(2) = data1_t2
  4216. md_mfv%changed = .true.
  4217. else if ( data1_copy ) then
  4218. ! copy data from secondary array:
  4219. md_mfu%data1 = md_mfu%data2
  4220. md_mfv%data1 = md_mfv%data2
  4221. ! data array is filled now:
  4222. md_mfu%filled1 = .true.
  4223. md_mfu%tr1(1) = data1_t1
  4224. md_mfu%tr1(2) = data1_t2
  4225. md_mfu%changed = .true.
  4226. md_mfv%filled1 = .true.
  4227. md_mfv%tr1(1) = data1_t1
  4228. md_mfv%tr1(2) = data1_t2
  4229. md_mfv%changed = .true.
  4230. end if
  4231. !--------------------------
  4232. ! read/write secondary field
  4233. !--------------------------
  4234. if ( data2_read ) then
  4235. ! safety check
  4236. if ( data2_t2 /= data2_t1 ) then
  4237. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  4238. call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  4239. call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  4240. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  4241. TRACEBACK; status=1; return
  4242. end if
  4243. ! fill data
  4244. call Read_MFUV( tmmd, md_mfu%sourcekey, &
  4245. data2_tref, data2_t1, data2_t2, lli(region), levi, &
  4246. tmp_spu, &
  4247. wrld_u( i1-1:i2, j1:j2, ls(1)+1:ls(2) ), &
  4248. md_mfu%tmi2, &
  4249. tmp_spv, &
  4250. wrld_v( i1:i2, j1:j2+1, ls(1)+1:ls(2) ), &
  4251. md_mfv%tmi2, &
  4252. status )
  4253. IF_NOTOK_RETURN(status=1)
  4254. md_mfu%data2( i1-1:i2, j1:j2, ls(1):ls(2)) = wrld_u(i1-1:i2, j1:j2, :)
  4255. md_mfv%data2( i1 :i2, j1:j2+1, ls(1):ls(2)) = wrld_v(i1 :i2, j1:j2+1, :)
  4256. ! write meteofiles
  4257. if ( md_mfu%putout ) then
  4258. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4259. TRACEBACK; status=1; return
  4260. ! call WriteField( tmmd, md_mfu%destkey, &
  4261. ! md_mfu%tmi2, 'spu', trim(md_mfu%name), trim(md_mfu%unit), &
  4262. ! data2_tref, data2_t1, data2_t2, &
  4263. ! lli, 'u', levi, 'n', &
  4264. ! tmp_spu, wrld_u( is(1)-1:is(2), js(1):js(2), ls(1)+1:ls(2) ), &
  4265. ! status )
  4266. ! IF_NOTOK_RETURN(status=1)
  4267. endif
  4268. if ( md_mfv%putout ) then
  4269. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4270. TRACEBACK; status=1; return
  4271. ! call WriteField( tmmd, md_mfv%destkey, &
  4272. ! md_mfv%tmi2, 'spv', trim(md_mfv%name), trim(md_mfv%unit), &
  4273. ! data2_tref, data2_t1, data2_t2, &
  4274. ! lli, 'v', levi, 'n', &
  4275. ! tmp_spv, wrld_v( is(1):is(2), js(1):js(2)+1, ls(1)+1:ls(2) ), &
  4276. ! status )
  4277. ! IF_NOTOK_RETURN(status=1)
  4278. end if
  4279. ! data array is filled now:
  4280. md_mfu%filled2 = .true.
  4281. md_mfu%tr2(1) = data2_t1
  4282. md_mfu%tr2(2) = data2_t2
  4283. md_mfv%filled2 = .true.
  4284. md_mfv%tr2(1) = data2_t1
  4285. md_mfv%tr2(2) = data2_t2
  4286. else if ( data2_copy ) then
  4287. ! copy data from primary array:
  4288. md_mfu%data2 = md_mfu%data
  4289. md_mfv%data2 = md_mfv%data
  4290. ! data array is filled now:
  4291. md_mfu%filled2 = .true.
  4292. md_mfu%tr2(1) = data2_t1
  4293. md_mfu%tr2(2) = data2_t2
  4294. md_mfv%filled2 = .true.
  4295. md_mfv%tr2(1) = data2_t1
  4296. md_mfv%tr2(2) = data2_t2
  4297. end if
  4298. ! Clean
  4299. if (data2_read .or. data1_read) then
  4300. deallocate( tmp_spu )
  4301. deallocate( tmp_spv )
  4302. deallocate( wrld_u, wrld_v )
  4303. end if
  4304. !------------------
  4305. ! time interpolation
  4306. !------------------
  4307. call TimeInterpolation( md_mfu, tr, status )
  4308. IF_NOTOK_RETURN(status=1)
  4309. call TimeInterpolation( md_mfv, tr, status )
  4310. IF_NOTOK_RETURN(status=1)
  4311. !------------------
  4312. ! done
  4313. !------------------
  4314. status = 0
  4315. if (okdebug) call goLabel()
  4316. END SUBROUTINE SETUP_MFUV_PARALLEL_IO
  4317. !EOC
  4318. ! ***
  4319. subroutine Setup_MFW_serial_io( region, md_mfw, md_tsp, tr, lli, nuv, levi, nw, status )
  4320. ! Set up MFW (vertical flux) and TSP (tendency surface pressure)
  4321. ! Read or copy %data1 and %data2, and get %data through time interpolation
  4322. use GO, only : TDate, wrtgol, operator(/=)
  4323. use Grid, only : TllGridInfo, TLevelInfo
  4324. use TMM, only : TMeteoInfo, ReadField, Read_MFW, WriteField
  4325. use meteodata, only : TMeteoData, TimeInterpolation
  4326. use dims, only : im, jm
  4327. ! --- in/out ----------------------------------
  4328. integer, intent(in) :: region ! region number
  4329. type(TMeteoData), intent(inout) :: md_mfw
  4330. type(TMeteoData), intent(inout) :: md_tsp
  4331. type(TDate), intent(in) :: tr(2)
  4332. type(TllGridInfo), intent(in) :: lli
  4333. character(len=1), intent(in) :: nuv
  4334. type(TLevelInfo), intent(in) :: levi
  4335. character(len=1), intent(in) :: nw
  4336. integer, intent(out) :: status
  4337. ! --- const --------------------------------------
  4338. character(len=*), parameter :: rname = mname//'/Setup_MFW_serial_io'
  4339. ! --- local ----------------------------------
  4340. logical :: data1_read, data1_copy
  4341. type(TDate) :: data1_tref, data1_t1, data1_t2
  4342. logical :: data2_read, data2_copy
  4343. type(TDate) :: data2_tref, data2_t1, data2_t2
  4344. real, allocatable :: tmp_sp(:,:)
  4345. real, pointer :: mfw(:,:,:), tsp(:,:) ! work arrays (data)
  4346. integer :: is(2), js(2), ls(2), halo ! work arrays (bounds)
  4347. ! --- begin -----------------------------
  4348. if (okdebug) call goLabel(rname)
  4349. ! leave if not in use:
  4350. if ( .not. md_mfw%used ) then
  4351. if (okdebug) call goLabel()
  4352. status=0; return
  4353. end if
  4354. ! error if tsp is not in use ...
  4355. if ( .not. md_tsp%used ) then
  4356. write (gol,'("mfw is in use but tsp not ..")'); call goErr
  4357. if (okdebug) call goLabel()
  4358. status=1; return
  4359. end if
  4360. ! not changed by default
  4361. md_mfw%changed = .false.
  4362. md_tsp%changed = .false.
  4363. !------------------
  4364. ! time stuff
  4365. !------------------
  4366. ! get time interval of met field and check if data from start and/or end
  4367. ! of interval must be read
  4368. call SetupSetup( md_mfw, tr, &
  4369. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  4370. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  4371. status )
  4372. IF_NOTOK_RETURN(status=1)
  4373. !--------------------------
  4374. ! read/write primary field
  4375. !--------------------------
  4376. if ( data1_read ) then
  4377. ! Need whole region for I/O on root. Dummy else.
  4378. is = (/1,im(region)/)
  4379. js = (/1,jm(region)/)
  4380. ls = md_mfw%ls
  4381. IF (isRoot) THEN
  4382. allocate( mfw(is(1):is(2), js(1):js(2), ls(1):ls(2) ))
  4383. allocate( tsp(is(1):is(2), js(1):js(2)) )
  4384. ELSE
  4385. allocate( mfw(1,1,1), tsp(1,1) )
  4386. END IF
  4387. if (isRoot) then ! only root does I/O
  4388. ! safety check ...
  4389. if ( data1_t2 /= data1_t1 ) then
  4390. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  4391. call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  4392. call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  4393. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  4394. call goErr; status=1; return
  4395. end if
  4396. ! surface pressure field:
  4397. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  4398. ! fill data:
  4399. call Read_MFW( tmmd, md_mfw%sourcekey, &
  4400. data1_tref, data1_t1, data1_t2, &
  4401. lli, levi, &
  4402. tmp_sp, mfw, &
  4403. tsp, &
  4404. md_mfw%tmi1, status )
  4405. IF_NOTOK_RETURN(status=1)
  4406. ! write meteofiles ?
  4407. if ( md_mfw%putout ) then
  4408. call WriteField( tmmd, md_mfw%destkey, &
  4409. md_mfw%tmi1, 'sp', trim(md_mfw%name), trim(md_mfw%unit), &
  4410. data1_tref, data1_t1, data1_t2, &
  4411. lli, nuv, levi, nw, &
  4412. tmp_sp, mfw, status )
  4413. IF_NOTOK_RETURN(status=1)
  4414. end if
  4415. if ( md_tsp%putout ) then
  4416. ! use history from mfw ...
  4417. call WriteField( tmmd, md_tsp%destkey, &
  4418. md_mfw%tmi1, trim(md_tsp%name), trim(md_tsp%unit), &
  4419. data1_tref, data1_t1, data1_t2, &
  4420. lli, nuv, tsp, status )
  4421. IF_NOTOK_RETURN(status=1)
  4422. end if
  4423. ! clear
  4424. deallocate( tmp_sp )
  4425. end if ! root
  4426. CALL SCATTER( dgrid(region), md_mfw%data1, MFW, md_mfw%halo, status)
  4427. IF_NOTOK_RETURN(status=1)
  4428. CALL SCATTER( dgrid(region), md_tsp%data1(:,:,1), TSP, md_tsp%halo, status)
  4429. IF_NOTOK_RETURN(status=1)
  4430. DEALLOCATE(MFW, TSP)
  4431. ! data array is filled now:
  4432. md_mfw%filled1 = .true.
  4433. md_mfw%tr1(1) = data1_t1
  4434. md_mfw%tr1(2) = data1_t2
  4435. md_mfw%changed = .true.
  4436. !
  4437. md_tsp%filled1 = .true.
  4438. md_tsp%tr1(1) = data1_t1
  4439. md_tsp%tr1(2) = data1_t2
  4440. md_tsp%changed = .true.
  4441. else if ( data1_copy ) then
  4442. ! copy data from secondary array:
  4443. md_mfw%data1 = md_mfw%data2
  4444. ! data array is filled now:
  4445. md_mfw%filled1 = .true.
  4446. md_mfw%tr1(1) = data1_t1
  4447. md_mfw%tr1(2) = data1_t2
  4448. md_mfw%changed = .true.
  4449. !
  4450. md_tsp%filled1 = .true.
  4451. md_tsp%tr1(1) = data1_t1
  4452. md_tsp%tr1(2) = data1_t2
  4453. md_tsp%changed = .true.
  4454. end if
  4455. !--------------------------
  4456. ! read/write secondary field
  4457. !--------------------------
  4458. if ( data2_read ) then
  4459. ! Need whole region for I/O on root. Dummy else.
  4460. is = (/1,im(region)/)
  4461. js = (/1,jm(region)/)
  4462. ls = md_mfw%ls
  4463. IF (isRoot) THEN
  4464. allocate( mfw(is(1):is(2), js(1):js(2), ls(1):ls(2) ))
  4465. allocate( tsp(is(1):is(2), js(1):js(2)) )
  4466. ELSE
  4467. allocate( mfw(1,1,1), tsp(1,1) )
  4468. END IF
  4469. if (isRoot) then ! only root does IO
  4470. ! safety check ...
  4471. if ( data2_t2 /= data2_t1 ) then
  4472. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  4473. call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  4474. call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  4475. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  4476. call goErr; status=1; return
  4477. end if
  4478. ! surface pressure field:
  4479. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  4480. ! fill data:
  4481. call Read_MFW( tmmd, md_mfw%sourcekey, &
  4482. data2_tref, data2_t1, data2_t2, &
  4483. lli, levi, tmp_sp, MFW, TSP, md_mfw%tmi2, status )
  4484. IF_NOTOK_RETURN(status=1)
  4485. ! write meteofiles ?
  4486. if ( md_mfw%putout ) then
  4487. call WriteField( tmmd, md_mfw%destkey, &
  4488. md_mfw%tmi2, 'sp', trim(md_mfw%name), trim(md_mfw%unit), &
  4489. data2_tref, data2_t1, data2_t2, &
  4490. lli, nuv, levi, nw, &
  4491. tmp_sp, MFW, status )
  4492. IF_NOTOK_RETURN(status=1)
  4493. end if
  4494. if ( md_tsp%putout ) then
  4495. ! use history from mfw ...
  4496. call WriteField( tmmd, md_tsp%destkey, &
  4497. md_mfw%tmi2, trim(md_tsp%name), trim(md_tsp%unit), &
  4498. data2_tref, data2_t1, data2_t2, &
  4499. lli, nuv, TSP, status )
  4500. IF_NOTOK_RETURN(status=1)
  4501. end if
  4502. ! clear
  4503. deallocate( tmp_sp )
  4504. end if ! root
  4505. CALL SCATTER( dgrid(region), md_mfw%data2, MFW, md_mfw%halo, status)
  4506. IF_NOTOK_RETURN(status=1)
  4507. CALL SCATTER( dgrid(region), md_tsp%data2(:,:,1), TSP, md_tsp%halo, status)
  4508. IF_NOTOK_RETURN(status=1)
  4509. DEALLOCATE(MFW, TSP)
  4510. ! data array is filled now:
  4511. md_mfw%filled2 = .true.
  4512. md_mfw%tr2(1) = data2_t1
  4513. md_mfw%tr2(2) = data2_t2
  4514. !
  4515. md_tsp%filled2 = .true.
  4516. md_tsp%tr2(1) = data2_t1
  4517. md_tsp%tr2(2) = data2_t2
  4518. else if ( data2_copy ) then
  4519. ! copy data from secondary array:
  4520. md_mfw%data2 = md_mfw%data1
  4521. ! data array is filled now:
  4522. md_mfw%filled2 = .true.
  4523. md_mfw%tr2(1) = data2_t1
  4524. md_mfw%tr2(2) = data2_t2
  4525. !
  4526. md_tsp%filled2 = .true.
  4527. md_tsp%tr2(1) = data2_t1
  4528. md_tsp%tr2(2) = data2_t2
  4529. end if
  4530. !------------------
  4531. ! time interpolation
  4532. !------------------
  4533. call TimeInterpolation( md_mfw, tr, status )
  4534. IF_NOTOK_RETURN(status=1)
  4535. !
  4536. call TimeInterpolation( md_tsp, tr, status )
  4537. IF_NOTOK_RETURN(status=1)
  4538. !------------------
  4539. ! done
  4540. !------------------
  4541. status = 0
  4542. if (okdebug) call goLabel()
  4543. end subroutine Setup_MFW_serial_io
  4544. !--------------------------------------------------------------------------
  4545. ! TM5 !
  4546. !--------------------------------------------------------------------------
  4547. !BOP
  4548. !
  4549. ! !IROUTINE: SETUP_MFW_PARALLEL_IO
  4550. !
  4551. ! !DESCRIPTION: Same as SETUP_MFW_SERIAL_IO, but with parallel I/O :
  4552. !
  4553. ! Set up MFW (vertical flux) and TSP (tendency surface pressure)
  4554. ! Read or copy %data1 and %data2, and get %data through time interpolation
  4555. !
  4556. !\\
  4557. !\\
  4558. ! !INTERFACE:
  4559. !
  4560. SUBROUTINE SETUP_MFW_PARALLEL_IO( region, md_mfw, md_tsp, tr, nuv, levi, nw, status )
  4561. !
  4562. ! !USES:
  4563. !
  4564. use GO, only : TDate, wrtgol, operator(/=)
  4565. use Grid, only : TllGridInfo, TLevelInfo
  4566. use TMM, only : TMeteoInfo, ReadField, Read_MFW, WriteField
  4567. use dims, only : im, jm
  4568. !
  4569. ! !INPUT PARAMETERS:
  4570. !
  4571. integer, intent(in) :: region ! region number
  4572. !
  4573. ! !INPUT/OUTPUT PARAMETERS:
  4574. !
  4575. type(TMeteoData), intent(inout) :: md_mfw
  4576. type(TMeteoData), intent(inout) :: md_tsp
  4577. type(TDate), intent(in) :: tr(2)
  4578. character(len=1), intent(in) :: nuv
  4579. type(TLevelInfo), intent(in) :: levi
  4580. character(len=1), intent(in) :: nw
  4581. !
  4582. ! !OUTPUT PARAMETERS:
  4583. !
  4584. integer, intent(out) :: status
  4585. !
  4586. ! !REVISION HISTORY:
  4587. ! 24 Oct 2013 - Ph. Le Sager - v0
  4588. !
  4589. ! !REMARKS:
  4590. !
  4591. !EOP
  4592. !------------------------------------------------------------------------
  4593. !BOC
  4594. character(len=*), parameter :: rname = mname//'/Setup_MFW_PARALLEL_io'
  4595. logical :: data1_read, data1_copy
  4596. type(TDate) :: data1_tref, data1_t1, data1_t2
  4597. logical :: data2_read, data2_copy
  4598. type(TDate) :: data2_tref, data2_t1, data2_t2
  4599. real, allocatable :: tmp_sp(:,:)
  4600. real, pointer :: mfw(:,:,:), tsp(:,:) ! work arrays (data)
  4601. integer :: is(2), js(2), ls(2), halo ! work arrays (bounds)
  4602. integer :: i1, i2, j1, j2
  4603. ! --- begin -----------------------------
  4604. if (okdebug) call goLabel(rname)
  4605. ! leave if not in use:
  4606. if ( .not. md_mfw%used ) then
  4607. if (okdebug) call goLabel()
  4608. status=0; return
  4609. end if
  4610. ! error if tsp is not in use ...
  4611. if ( .not. md_tsp%used ) then
  4612. write (gol,'("mfw is in use but tsp not ..")'); call goErr
  4613. if (okdebug) call goLabel()
  4614. status=1; return
  4615. end if
  4616. ! not changed by default
  4617. md_mfw%changed = .false.
  4618. md_tsp%changed = .false.
  4619. !------------------
  4620. ! time stuff
  4621. !------------------
  4622. ! get time interval of met field and check if data from start and/or end
  4623. ! of interval must be read
  4624. call SetupSetup( md_mfw, tr, &
  4625. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  4626. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  4627. status )
  4628. IF_NOTOK_RETURN(status=1)
  4629. ! work arrays
  4630. if (data1_read .or. data2_read) then
  4631. CALL GET_DISTGRID( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  4632. is = (/i1,i2/)
  4633. js = (/j1,j2/)
  4634. ls = md_mfw%ls
  4635. allocate( mfw (is(1):is(2), js(1):js(2), ls(1):ls(2) ))
  4636. allocate( tsp (is(1):is(2), js(1):js(2) ))
  4637. allocate( tmp_sp(is(1):is(2), js(1):js(2) ))
  4638. end if
  4639. !--------------------------
  4640. ! read/write primary field
  4641. !--------------------------
  4642. if ( data1_read ) then
  4643. ! safety check
  4644. if ( data1_t2 /= data1_t1 ) then
  4645. write (gol,'("not sure that this routine is correct for time intervals:")') ; call goErr
  4646. call wrtgol( ' data1_t1 : ', data1_t1 ) ; call goErr
  4647. call wrtgol( ' data1_t2 : ', data1_t2 ) ; call goErr
  4648. write (gol,'("please deceide what to do with surface pressures ... ")') ; call goErr
  4649. TRACEBACK; status=1; return
  4650. end if
  4651. ! fill data
  4652. call Read_MFW( tmmd, md_mfw%sourcekey, &
  4653. data1_tref, data1_t1, data1_t2, &
  4654. lli(region), levi, &
  4655. tmp_sp, mfw, &
  4656. tsp, &
  4657. md_mfw%tmi1, status )
  4658. IF_NOTOK_RETURN(status=1)
  4659. ! write meteofiles
  4660. if ( md_mfw%putout ) then
  4661. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4662. TRACEBACK; status=1; return
  4663. ! call WriteField( tmmd, md_mfw%destkey, &
  4664. ! md_mfw%tmi1, 'sp', trim(md_mfw%name), trim(md_mfw%unit), &
  4665. ! data1_tref, data1_t1, data1_t2, &
  4666. ! lli(region), nuv, levi, nw, &
  4667. ! tmp_sp, mfw, status )
  4668. ! IF_NOTOK_RETURN(status=1)
  4669. end if
  4670. if ( md_tsp%putout ) then
  4671. ! use history from mfw ...
  4672. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4673. ! TRACEBACK; status=1; return
  4674. ! call WriteField( tmmd, md_tsp%destkey, &
  4675. ! md_mfw%tmi1, trim(md_tsp%name), trim(md_tsp%unit), &
  4676. ! data1_tref, data1_t1, data1_t2, &
  4677. ! lli(region), nuv, tsp, status )
  4678. ! IF_NOTOK_RETURN(status=1)
  4679. end if
  4680. md_mfw%data1( i1:i2, j1:j2, ls(1):ls(2)) = mfw
  4681. md_tsp%data1( i1:i2, j1:j2, 1 ) = tsp
  4682. ! data array is filled now:
  4683. md_mfw%filled1 = .true.
  4684. md_mfw%tr1(1) = data1_t1
  4685. md_mfw%tr1(2) = data1_t2
  4686. md_mfw%changed = .true.
  4687. !
  4688. md_tsp%filled1 = .true.
  4689. md_tsp%tr1(1) = data1_t1
  4690. md_tsp%tr1(2) = data1_t2
  4691. md_tsp%changed = .true.
  4692. else if ( data1_copy ) then
  4693. ! copy data from secondary array:
  4694. md_mfw%data1 = md_mfw%data2
  4695. ! data array is filled now:
  4696. md_mfw%filled1 = .true.
  4697. md_mfw%tr1(1) = data1_t1
  4698. md_mfw%tr1(2) = data1_t2
  4699. md_mfw%changed = .true.
  4700. !
  4701. md_tsp%filled1 = .true.
  4702. md_tsp%tr1(1) = data1_t1
  4703. md_tsp%tr1(2) = data1_t2
  4704. md_tsp%changed = .true.
  4705. end if
  4706. !--------------------------
  4707. ! read/write secondary field
  4708. !--------------------------
  4709. if ( data2_read ) then
  4710. ! safety check
  4711. if ( data2_t2 /= data2_t1 ) then
  4712. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  4713. call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  4714. call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  4715. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  4716. call goErr; status=1; return
  4717. end if
  4718. ! fill data:
  4719. call Read_MFW( tmmd, md_mfw%sourcekey, &
  4720. data2_tref, data2_t1, data2_t2, &
  4721. lli(region), levi, tmp_sp, MFW, TSP, md_mfw%tmi2, status )
  4722. IF_NOTOK_RETURN(status=1)
  4723. ! write meteofiles ?
  4724. if ( md_mfw%putout ) then
  4725. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4726. TRACEBACK; status=1; return
  4727. ! call WriteField( tmmd, md_mfw%destkey, &
  4728. ! md_mfw%tmi2, 'sp', trim(md_mfw%name), trim(md_mfw%unit), &
  4729. ! data2_tref, data2_t1, data2_t2, &
  4730. ! lli, nuv, levi, nw, &
  4731. ! tmp_sp, MFW, status )
  4732. ! IF_NOTOK_RETURN(status=1)
  4733. end if
  4734. if ( md_tsp%putout ) then
  4735. write(gol,*)"writing of remapped met field not finished yet.. Sorry." ; call goErr
  4736. TRACEBACK; status=1; return
  4737. ! ! use history from mfw ...
  4738. ! call WriteField( tmmd, md_tsp%destkey, &
  4739. ! md_mfw%tmi2, trim(md_tsp%name), trim(md_tsp%unit), &
  4740. ! data2_tref, data2_t1, data2_t2, &
  4741. ! lli, nuv, TSP, status )
  4742. ! IF_NOTOK_RETURN(status=1)
  4743. end if
  4744. md_mfw%data2( i1:i2, j1:j2, ls(1):ls(2)) = mfw
  4745. md_tsp%data2( i1:i2, j1:j2, 1 ) = tsp
  4746. ! data array is filled now:
  4747. md_mfw%filled2 = .true.
  4748. md_mfw%tr2(1) = data2_t1
  4749. md_mfw%tr2(2) = data2_t2
  4750. !
  4751. md_tsp%filled2 = .true.
  4752. md_tsp%tr2(1) = data2_t1
  4753. md_tsp%tr2(2) = data2_t2
  4754. else if ( data2_copy ) then
  4755. ! copy data from secondary array:
  4756. md_mfw%data2 = md_mfw%data1
  4757. ! data array is filled now:
  4758. md_mfw%filled2 = .true.
  4759. md_mfw%tr2(1) = data2_t1
  4760. md_mfw%tr2(2) = data2_t2
  4761. !
  4762. md_tsp%filled2 = .true.
  4763. md_tsp%tr2(1) = data2_t1
  4764. md_tsp%tr2(2) = data2_t2
  4765. end if
  4766. !------------------
  4767. ! time interpolation
  4768. !------------------
  4769. call TimeInterpolation( md_mfw, tr, status )
  4770. IF_NOTOK_RETURN(status=1)
  4771. !
  4772. call TimeInterpolation( md_tsp, tr, status )
  4773. IF_NOTOK_RETURN(status=1)
  4774. !------------------
  4775. ! done
  4776. !------------------
  4777. if (data1_read .or. data2_read) then
  4778. deallocate(mfw, tsp)
  4779. deallocate( tmp_sp )
  4780. end if
  4781. status = 0
  4782. if (okdebug) call goLabel()
  4783. END SUBROUTINE SETUP_MFW_PARALLEL_IO
  4784. !EOC
  4785. ! **************************************************************
  4786. ! ***
  4787. ! *** temperature and humidity
  4788. ! ***
  4789. ! **************************************************************
  4790. subroutine Setup_TQ( region, md_T, md_Q, tr, lli, levi, status)
  4791. use GO, only : TDate, wrtgol, operator(/=)
  4792. use Grid, only : TllGridInfo, TLevelInfo
  4793. use TMM, only : TMeteoInfo, Read_TQ, WriteField
  4794. use meteodata, only : TMeteoData, TimeInterpolation
  4795. use dims, only : im, jm
  4796. ! --- in/out ----------------------------------
  4797. integer, intent(in) :: region ! region number
  4798. type(TMeteoData), intent(inout) :: md_T
  4799. type(TMeteoData), intent(inout) :: md_Q
  4800. type(TDate), intent(in) :: tr(2)
  4801. type(TllGridInfo), intent(in) :: lli
  4802. type(TLevelInfo), intent(in) :: levi
  4803. integer, intent(out) :: status
  4804. ! --- const --------------------------------------
  4805. character(len=*), parameter :: rname = mname//'/Setup_TQ'
  4806. ! --- local ----------------------------------
  4807. logical :: data1_read, data1_copy
  4808. type(TDate) :: data1_tref, data1_t1, data1_t2
  4809. logical :: data2_read, data2_copy
  4810. type(TDate) :: data2_tref, data2_t1, data2_t2
  4811. real, allocatable :: tmp_sp(:,:)
  4812. real, pointer :: T(:,:,:), Q(:,:,:) ! work array
  4813. integer :: is(2), js(2) ! work arrays (bounds)
  4814. ! --- begin -----------------------------
  4815. if (okdebug) call goLabel(rname)
  4816. ! leave if not in use:
  4817. if ( md_T%used .neqv. md_Q%used ) then
  4818. write (gol,'("either none or both T and Q should be in use")'); call goErr
  4819. call goErr; status=1; return
  4820. end if
  4821. if ( .not. md_T%used ) then
  4822. if (okdebug) call goLabel()
  4823. status=0; return
  4824. end if
  4825. ! not changed by default
  4826. md_T%changed = .false.
  4827. md_Q%changed = .false.
  4828. !------------------
  4829. ! time stuff
  4830. !------------------
  4831. ! get time interval of met field and check if data from start and/or end
  4832. ! of interval must be read (sufficient to setup from T only)
  4833. call SetupSetup( md_T, tr, &
  4834. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  4835. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  4836. status )
  4837. IF_NOTOK_RETURN(status=1)
  4838. !--------------------------
  4839. ! read/write primary field
  4840. !--------------------------
  4841. if ( data1_read ) then
  4842. ! Need whole region for I/O on root. Dummy else.
  4843. is = (/1,im(region)/)
  4844. js = (/1,jm(region)/)
  4845. IF (isRoot) THEN
  4846. ALLOCATE( T(is(1):is(2), js(1):js(2), md_T%ls(1):md_T%ls(2) ))
  4847. ALLOCATE( Q(is(1):is(2), js(1):js(2), md_Q%ls(1):md_Q%ls(2) ))
  4848. ELSE
  4849. ALLOCATE( T(1,1,1), Q(1,1,1) )
  4850. END IF
  4851. if (isRoot) then ! only root does IO
  4852. ! safety check ...
  4853. if ( data1_t2 /= data1_t1 ) then
  4854. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  4855. call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  4856. call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  4857. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  4858. call goErr; status=1; return
  4859. end if
  4860. ! surface pressure field:
  4861. allocate( tmp_sp( is(1):is(2), js(1):js(2) ) )
  4862. ! fill data:
  4863. call Read_TQ( tmmd, md_T%sourcekey, md_Q%sourcekey, &
  4864. data1_tref, data1_t1, data1_t2, lli, levi, &
  4865. tmp_sp, &
  4866. T, md_T%tmi1, &
  4867. Q, md_Q%tmi1, status )
  4868. IF_NOTOK_RETURN(status=1)
  4869. ! write meteofiles ?
  4870. if ( md_T%putout ) then
  4871. call WriteField( tmmd, md_T%destkey, &
  4872. md_T%tmi1, 'sp', trim(md_T%name), trim(md_T%unit), &
  4873. data1_tref, data1_t1, data1_t2, &
  4874. lli, 'n', levi, 'n', &
  4875. tmp_sp, T, status )
  4876. IF_NOTOK_RETURN(status=1)
  4877. end if
  4878. if ( md_Q%putout ) then
  4879. call WriteField( tmmd, md_Q%destkey, &
  4880. md_Q%tmi1, 'sp', trim(md_Q%name), trim(md_Q%unit), &
  4881. data1_tref, data1_t1, data1_t2, &
  4882. lli, 'n', levi, 'n', &
  4883. tmp_sp, Q, status )
  4884. IF_NOTOK_RETURN(status=1)
  4885. end if
  4886. ! clear
  4887. deallocate( tmp_sp )
  4888. end if ! root ?
  4889. ! Distribute
  4890. CALL SCATTER( dgrid(region), md_T%data1, T, md_T%halo, status)
  4891. IF_NOTOK_RETURN(status=1)
  4892. CALL SCATTER( dgrid(region), md_Q%data1, Q, md_Q%halo, status)
  4893. IF_NOTOK_RETURN(status=1)
  4894. DEALLOCATE(T, Q)
  4895. ! data array is filled now:
  4896. md_T%filled1 = .true.
  4897. md_T%tr1(1) = data1_t1
  4898. md_T%tr1(2) = data1_t2
  4899. md_T%changed = .true.
  4900. md_Q%filled1 = .true.
  4901. md_Q%tr1(1) = data1_t1
  4902. md_Q%tr1(2) = data1_t2
  4903. md_Q%changed = .true.
  4904. else if ( data1_copy ) then
  4905. ! copy data from secondary array:
  4906. md_T%data1 = md_T%data2
  4907. md_Q%data1 = md_Q%data2
  4908. ! data array is filled now:
  4909. md_T%filled1 = .true.
  4910. md_T%tr1(1) = data1_t1
  4911. md_T%tr1(2) = data1_t2
  4912. md_T%changed = .true.
  4913. md_Q%filled1 = .true.
  4914. md_Q%tr1(1) = data1_t1
  4915. md_Q%tr1(2) = data1_t2
  4916. md_Q%changed = .true.
  4917. end if
  4918. !--------------------------
  4919. ! read/write secondary field
  4920. !--------------------------
  4921. if ( data2_read ) then
  4922. ! Need whole region for I/O on root. Dummy else.
  4923. is = (/1,im(region)/)
  4924. js = (/1,jm(region)/)
  4925. IF (isRoot) THEN
  4926. allocate( T(is(1):is(2), js(1):js(2), md_T%ls(1):md_T%ls(2) ))
  4927. allocate( Q(is(1):is(2), js(1):js(2), md_Q%ls(1):md_Q%ls(2) ))
  4928. ELSE
  4929. allocate( T(1,1,1), Q(1,1,1) )
  4930. END IF
  4931. if (isRoot) then ! only root does IO
  4932. ! safety check ...
  4933. if ( data2_t2 /= data2_t1 ) then
  4934. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  4935. call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  4936. call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  4937. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  4938. call goErr; status=1; return
  4939. end if
  4940. ! surface pressure field:
  4941. allocate( tmp_sp( is(1):is(2), js(1):js(2)) )
  4942. ! fill data:
  4943. call Read_TQ( tmmd, md_T%sourcekey, md_Q%sourcekey, &
  4944. data2_tref, data2_t1, data2_t2, lli, levi, &
  4945. tmp_sp, &
  4946. T, md_T%tmi2, &
  4947. Q, md_Q%tmi2, status )
  4948. IF_NOTOK_RETURN(status=1)
  4949. ! write meteofiles ?
  4950. if ( md_T%putout ) then
  4951. call WriteField( tmmd, md_T%destkey, &
  4952. md_T%tmi2, 'sp', trim(md_T%name), trim(md_T%unit), &
  4953. data2_tref, data2_t1, data2_t2, &
  4954. lli, 'n', levi, 'n', &
  4955. tmp_sp, T, status )
  4956. IF_NOTOK_RETURN(status=1)
  4957. endif
  4958. if ( md_Q%putout ) then
  4959. call WriteField( tmmd, md_Q%destkey, &
  4960. md_Q%tmi2, 'sp', trim(md_Q%name), trim(md_Q%unit), &
  4961. data2_tref, data2_t1, data2_t2, &
  4962. lli, 'n', levi, 'n', &
  4963. tmp_sp, Q, status )
  4964. IF_NOTOK_RETURN(status=1)
  4965. end if
  4966. ! clear
  4967. deallocate( tmp_sp )
  4968. end if ! root
  4969. CALL SCATTER( dgrid(region), md_T%data2, T, md_T%halo, status)
  4970. IF_NOTOK_RETURN(status=1)
  4971. CALL SCATTER( dgrid(region), md_Q%data2, Q, md_Q%halo, status)
  4972. IF_NOTOK_RETURN(status=1)
  4973. DEALLOCATE(T, Q)
  4974. ! data array is filled now:
  4975. md_T%filled2 = .true.
  4976. md_T%tr2(1) = data2_t1
  4977. md_T%tr2(2) = data2_t2
  4978. md_Q%filled2 = .true.
  4979. md_Q%tr2(1) = data2_t1
  4980. md_Q%tr2(2) = data2_t2
  4981. else if ( data2_copy ) then
  4982. ! copy data from primary array:
  4983. md_T%data2 = md_T%data1
  4984. md_Q%data2 = md_Q%data1
  4985. ! data array is filled now:
  4986. md_T%filled2 = .true.
  4987. md_T%tr2(1) = data2_t1
  4988. md_T%tr2(2) = data2_t2
  4989. md_Q%filled2 = .true.
  4990. md_Q%tr2(1) = data2_t1
  4991. md_Q%tr2(2) = data2_t2
  4992. end if
  4993. !------------------
  4994. ! time interpolation
  4995. !------------------
  4996. call TimeInterpolation( md_T, tr, status )
  4997. IF_NOTOK_RETURN(status=1)
  4998. call TimeInterpolation( md_Q, tr, status )
  4999. IF_NOTOK_RETURN(status=1)
  5000. !------------------
  5001. ! done
  5002. !------------------
  5003. status = 0
  5004. if (okdebug) call goLabel()
  5005. end subroutine Setup_TQ
  5006. ! ***
  5007. ! subroutine Meteo_SetupMass( n, status )
  5008. !
  5009. ! use global_data, only : mass_dat
  5010. ! use dims, only : newsrun
  5011. ! use dims, only : xcyc, im, jm
  5012. ! use geometry, only : geomtryv
  5013. !
  5014. ! ! --- in/out -----------------------------
  5015. !
  5016. ! integer, intent(in) :: n ! region
  5017. ! integer, intent(out) :: status
  5018. !
  5019. ! ! --- const --------------------------------------
  5020. !
  5021. ! character(len=*), parameter :: rname = mname//'/Meteo_SetupMass'
  5022. !
  5023. ! ! --- begin ------------------------------
  5024. !
  5025. ! call goLabel(rname)
  5026. !
  5027. ! ! compute initial pressure levels and mass ?
  5028. ! if ( newsrun ) then
  5029. ! call geomtryv( n )
  5030. ! end if
  5031. !
  5032. ! ! periodic boundary for m
  5033. ! ! NOTE: m has been advected or created by geomtryv
  5034. ! if ( xcyc(n) == 1 ) then
  5035. ! mass_dat(n)%m_t(0 ,:,:) = mass_dat(n)%m_t(im(n),:,:)
  5036. ! mass_dat(n)%m_t(im(n)+1,:,:) = mass_dat(n)%m_t(1 ,:,:)
  5037. ! end if
  5038. !
  5039. ! ! ok
  5040. ! status = 0
  5041. ! call goLabel()
  5042. !
  5043. ! end subroutine Meteo_SetupMass
  5044. ! ***
  5045. !--------------------------------------------------------------------------
  5046. ! TM5 !
  5047. !--------------------------------------------------------------------------
  5048. !BOP
  5049. !
  5050. ! !IROUTINE: METEO_CHECKPRESSURE
  5051. !
  5052. ! !DESCRIPTION: Compute difference b/w sp1_dat (read) and sp_dat (advected),
  5053. ! and compare to threshold.
  5054. !\\
  5055. !\\
  5056. ! !INTERFACE:
  5057. !
  5058. SUBROUTINE METEO_CHECKPRESSURE( n, status )
  5059. !
  5060. ! !USES:
  5061. !
  5062. use ParTools, only : Par_Reduce
  5063. use dims, only : idate, newsrun
  5064. use dims, only : xcyc, im, jm
  5065. use redgridZoom, only : calc_pdiff
  5066. #ifdef with_hdf4
  5067. use io_hdf, only : io_write2d_32d, DFACC_CREATE
  5068. #endif
  5069. !
  5070. ! !INPUT PARAMETERS:
  5071. !
  5072. integer, intent(in) :: n ! region
  5073. !
  5074. ! !OUTPUT PARAMETERS:
  5075. !
  5076. integer, intent(out) :: status
  5077. !
  5078. ! !REVISION HISTORY:
  5079. ! 7 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  5080. !
  5081. ! !REMARKS:
  5082. !
  5083. !EOP
  5084. !------------------------------------------------------------------------
  5085. !BOC
  5086. character(len=*), parameter :: rname = mname//'/Meteo_CheckPressure'
  5087. ! maximum accepted pressure difference:
  5088. real, parameter :: pdiffmax_treshold = 1.0e2 ! Pa
  5089. ! --- external -------------------------
  5090. integer(4), external :: sfStart, sfEnd
  5091. ! --- local -----------------------------
  5092. real :: pdiffmax, pdiffmax_l
  5093. integer(4) :: io
  5094. ! --- begin ------------------------------
  5095. if (okdebug) call goLabel(rname)
  5096. ! compare 'advected' pressure with read pressure
  5097. if ( .not. newsrun ) then
  5098. ! compute difference between 'advected' pressure sp and read pressure
  5099. ! sp1, accounting for reduce grid if any
  5100. call calc_pdiff( n, pdiffmax_l )
  5101. ! compute maximum over all pe's
  5102. call Par_Reduce( pdiffmax_l, 'max', pdiffmax, status, all=.true. )
  5103. IF_NOTOK_RETURN(status=1)
  5104. ! check ...
  5105. if ( pdiffmax > pdiffmax_treshold ) then
  5106. write (gol,'("difference between advected and read-in pressure exceeds treshold :")'); call goErr
  5107. write (gol,'(" max diff. : ",es9.2," [Pa]")') pdiffmax; call goErr
  5108. write (gol,'(" treshold : ",es9.2," [Pa]")') pdiffmax_treshold; call goErr
  5109. write (gol,'("pressure arrays saved to local `pressure.hdf`")'); call goErr
  5110. #ifdef with_hdf4
  5111. if (isRoot) then
  5112. io = sfStart( 'pressure.hdf', DFACC_CREATE )
  5113. if ( io > 0 ) then
  5114. call io_write2d_32d( io, im(n)+4, 'LON', jm(n)+4, 'LAT', sp1_dat(n)%data(:,:,1), 'p' , idate )
  5115. call io_write2d_32d( io, im(n)+4, 'LON', jm(n)+4, 'LAT', sp_dat(n)%data(:,:,1), 'pold', idate )
  5116. status = sfend(io)
  5117. else
  5118. write (gol,'("writing pressures")'); call goErr
  5119. end if
  5120. end if ! root
  5121. #endif
  5122. TRACEBACK; status=1; return
  5123. end if ! max diff
  5124. end if ! no newsrun
  5125. ! ok
  5126. status = 0
  5127. if (okdebug) call goLabel()
  5128. END SUBROUTINE METEO_CHECKPRESSURE
  5129. !EOC
  5130. ! **************************************************************
  5131. ! ***
  5132. ! *** vertical velocity
  5133. ! ***
  5134. ! **************************************************************
  5135. subroutine Compute_Omega( omega, lli, mfw, status )
  5136. use binas, only : grav
  5137. use grid, only : TllGridInfo, AreaOper
  5138. use meteodata, only : TMeteoData
  5139. use tmm, only : SetHistory, AddHistory
  5140. ! --- in/out ----------------------------------
  5141. type(TMeteoData), intent(inout) :: omega ! Pa/s downward
  5142. type(TllGridInfo), intent(in) :: lli
  5143. type(TMeteoData), intent(in) :: mfw ! kg/s upward
  5144. integer, intent(out) :: status
  5145. ! --- const -----------------------------------
  5146. character(len=*), parameter :: rname = mname//'/Compute_Omega'
  5147. ! --- local ----------------------------------
  5148. integer :: l
  5149. ! --- begin ----------------------------------
  5150. ! not in use ?
  5151. if ( .not. omega%used ) return
  5152. ! leave if not in use:
  5153. if ( .not. mfw%used ) then
  5154. write (gol,'("omega (Pa/s) requires mfw (kg/s)")'); call goErr
  5155. call goErr; status=1; return
  5156. end if
  5157. if (okdebug) call goLabel(rname)
  5158. ! Pa/s = kg/s / m2 * g
  5159. ! init with mass flux; revert sign from upward to downard, divide by
  5160. ! gravity accelaration
  5161. omega%data = - mfw%data * grav ! Pa/s m2
  5162. ! loop over levels and divide by cell area (m2)
  5163. do l = 1, size(omega%data,3)
  5164. call AreaOper( lli, omega%data(:,:,l), '/', 'm2', status )
  5165. IF_NOTOK_RETURN(status=1)
  5166. end do
  5167. ! info ..
  5168. !call SetHistory( omega%tmi, mfw%tmi, status )
  5169. !call AddHistory( omega%tmi, 'convert to Pa/s', status )
  5170. ! ok
  5171. status = 0
  5172. if (okdebug) call goLabel()
  5173. end subroutine Compute_Omega
  5174. ! **************************************************************
  5175. ! ***
  5176. ! *** Specific SETUP routine for CONVECTIVE FLUXES
  5177. ! ***
  5178. ! **************************************************************
  5179. subroutine Setup_Convec_serial_io( region, entu, entd, detu, detd, omega, gph, &
  5180. tr, lli, levi, status)
  5181. use GO, only : TDate, wrtgol, operator(/=)
  5182. use Grid, only : TllGridInfo, TLevelInfo
  5183. use TMM, only : TMeteoInfo, Read_Convec, WriteField
  5184. use meteodata, only : TMeteoData, TimeInterpolation
  5185. use dims, only : im, jm
  5186. ! --- in/out ----------------------------------
  5187. integer, intent(in) :: region ! region number
  5188. type(TMeteoData), intent(inout) :: entu, entd, detu, detd
  5189. type(TMeteoData), intent(in) :: omega, gph
  5190. type(TDate), intent(in) :: tr(2)
  5191. type(TllGridInfo), intent(in) :: lli
  5192. type(TLevelInfo), intent(in) :: levi
  5193. integer, intent(out) :: status
  5194. ! --- const --------------------------------------
  5195. character(len=*), parameter :: rname = mname//'/Setup_Convec_serial_io'
  5196. ! --- local ----------------------------------
  5197. logical :: data1_read, data1_copy
  5198. type(TDate) :: data1_tref, data1_t1, data1_t2
  5199. logical :: data2_read, data2_copy
  5200. type(TDate) :: data2_tref, data2_t1, data2_t2
  5201. real, allocatable :: tmp_sp(:,:)
  5202. ! to differentiate b/w local and global data set
  5203. real, pointer, dimension(:,:,:) :: L_entu, L_entd, L_detu, L_detd
  5204. real, pointer :: L_omega(:,:,:), L_gph(:,:,:)
  5205. integer, dimension(2) :: is, js, ls, auxls
  5206. integer :: halo
  5207. ! --- begin -----------------------------
  5208. ! leave if not in use:
  5209. if ( (.not. all((/entu%used,entd%used,detu%used,detd%used/)) ) &
  5210. .and. any((/entu%used,entd%used,detu%used,detd%used/)) ) then
  5211. write (gol,'("either none or all of entu/entd/detu/detd should be in use")'); call goErr
  5212. call goErr; status=1; return
  5213. end if
  5214. if ( .not. entu%used ) then
  5215. if (okdebug) call goLabel()
  5216. status=0; return
  5217. end if
  5218. ! gph is required as input:
  5219. if (.not. gph%used) then
  5220. write (gol,'("gph should be in use to compute convective stuff from EC convective fluxes")'); call goErr
  5221. call goErr; status=1; return
  5222. end if
  5223. ! omega is required as input:
  5224. if ( .not. omega%used ) then
  5225. write (gol,'("omega should be in use to compute convective stuff")'); call goErr
  5226. call goErr; status=1; return
  5227. end if
  5228. ! not changed by default
  5229. entu%changed = .false.
  5230. entd%changed = .false.
  5231. detu%changed = .false.
  5232. detd%changed = .false.
  5233. !------------------
  5234. ! time stuff
  5235. !------------------
  5236. ! get time interval of met field and check if data from start and/or end
  5237. ! of interval must be read (sufficient to setup from entu only)
  5238. call SetupSetup( entu, tr, &
  5239. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  5240. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  5241. status )
  5242. IF_NOTOK_RETURN(status=1)
  5243. !--------------------------
  5244. ! read/write primary field
  5245. !--------------------------
  5246. if ( data1_read ) then
  5247. ! Need whole region for I/O on root. Dummy else.
  5248. is = (/1,im(region)/)
  5249. js = (/1,jm(region)/)
  5250. ls = entu%ls
  5251. auxls = gph%ls
  5252. IF (isRoot) THEN
  5253. ! Use the fact that entu, entd, detu, and detd have been allocated with the same bounds and halo=0
  5254. allocate( L_entu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5255. allocate( L_entd( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5256. allocate( L_detu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5257. allocate( L_detd( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5258. allocate(L_gph (im(region), jm(region), auxls(1):auxls(2)) )
  5259. allocate(L_omega(im(region), jm(region), auxls(1):auxls(2)) )
  5260. ELSE
  5261. allocate( L_entu(1,1,1), L_entd(1,1,1), L_detu(1,1,1), L_detd(1,1,1))
  5262. allocate(L_gph (1,1,1))
  5263. allocate(L_omega(1,1,1))
  5264. END IF
  5265. CALL GATHER( dgrid(region), gph%data, L_gph, gph%halo, status)
  5266. IF_NOTOK_RETURN(status=1)
  5267. CALL GATHER( dgrid(region), omega%data, L_omega, omega%halo, status)
  5268. IF_NOTOK_RETURN(status=1)
  5269. ! Read/write on root
  5270. IOroot : if (isRoot) then
  5271. !AJS ! safety check ...
  5272. !AJS if ( data1_t2 /= data1_t1 ) then
  5273. !AJS !write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  5274. !AJS !call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  5275. !AJS !call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  5276. !AJS !write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  5277. !AJS !call goErr; status=1; return
  5278. !AJS write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  5279. !AJS end if
  5280. ! surface pressure field:
  5281. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  5282. ! fill data
  5283. call Read_Convec( tmmd, entu%sourcekey, &
  5284. data1_tref, data1_t1, data1_t2, lli, levi, &
  5285. L_omega, omega%tmi, &
  5286. L_gph, gph%tmi, &
  5287. tmp_sp, &
  5288. L_entu, entu%tmi1, L_entd, entd%tmi1, &
  5289. L_detu, detu%tmi1, L_detd, detd%tmi1, &
  5290. status )
  5291. IF_NOTOK_RETURN(status=1)
  5292. ! write meteofiles
  5293. if ( entu%putout ) then
  5294. call WriteField( tmmd, entu%destkey, &
  5295. entu%tmi1, 'sp', trim(entu%name), trim(entu%unit), &
  5296. data1_tref, data1_t1, data1_t2, &
  5297. lli, 'n', levi, '*', &
  5298. tmp_sp, L_entu, status )
  5299. IF_NOTOK_RETURN(status=1)
  5300. end if
  5301. if ( entd%putout ) then
  5302. call WriteField( tmmd, entd%destkey, &
  5303. entd%tmi1, 'sp', trim(entd%name), trim(entd%unit), &
  5304. data1_tref, data1_t1, data1_t2, &
  5305. lli, 'n', levi, '*', &
  5306. tmp_sp, L_entd, status )
  5307. IF_NOTOK_RETURN(status=1)
  5308. end if
  5309. if ( detu%putout ) then
  5310. call WriteField( tmmd, detu%destkey, &
  5311. detu%tmi1, 'sp', trim(detu%name), trim(detu%unit), &
  5312. data1_tref, data1_t1, data1_t2, &
  5313. lli, 'n', levi, '*', &
  5314. tmp_sp, L_detu, status )
  5315. IF_NOTOK_RETURN(status=1)
  5316. end if
  5317. if ( detd%putout ) then
  5318. call WriteField( tmmd, detd%destkey, &
  5319. detd%tmi1, 'sp', trim(detd%name), trim(detd%unit), &
  5320. data1_tref, data1_t1, data1_t2, &
  5321. lli, 'n', levi, '*', &
  5322. tmp_sp, L_detd, status )
  5323. IF_NOTOK_RETURN(status=1)
  5324. end if
  5325. ! clear
  5326. deallocate( tmp_sp )
  5327. end if IOroot
  5328. ! Scatter & clean up
  5329. CALL SCATTER( dgrid(region), entu%data1, L_entu, entu%halo, status)
  5330. IF_NOTOK_RETURN(status=1)
  5331. CALL SCATTER( dgrid(region), entd%data1, L_entd, entd%halo, status)
  5332. IF_NOTOK_RETURN(status=1)
  5333. CALL SCATTER( dgrid(region), detu%data1, L_detu, detu%halo, status)
  5334. IF_NOTOK_RETURN(status=1)
  5335. CALL SCATTER( dgrid(region), detd%data1, L_detd, detd%halo, status)
  5336. IF_NOTOK_RETURN(status=1)
  5337. deallocate(L_entu, L_entd, L_detu, L_detd, L_gph, L_omega)
  5338. ! data array is filled now:
  5339. entu%filled1 = .true.
  5340. entu%tr1(1) = data1_t1
  5341. entu%tr1(2) = data1_t2
  5342. entu%changed = .true.
  5343. entd%filled1 = .true.
  5344. entd%tr1(1) = data1_t1
  5345. entd%tr1(2) = data1_t2
  5346. entd%changed = .true.
  5347. detu%filled1 = .true.
  5348. detu%tr1(1) = data1_t1
  5349. detu%tr1(2) = data1_t2
  5350. detu%changed = .true.
  5351. detd%filled1 = .true.
  5352. detd%tr1(1) = data1_t1
  5353. detd%tr1(2) = data1_t2
  5354. detd%changed = .true.
  5355. else if ( data1_copy ) then
  5356. ! copy data from secondary array:
  5357. entu%data1 = entu%data2
  5358. entd%data1 = entd%data2
  5359. detu%data1 = detu%data2
  5360. detd%data1 = detd%data2
  5361. ! data array is filled now:
  5362. entu%filled1 = .true.
  5363. entu%tr1(1) = data1_t1
  5364. entu%tr1(2) = data1_t2
  5365. entu%changed = .true.
  5366. entd%filled1 = .true.
  5367. entd%tr1(1) = data1_t1
  5368. entd%tr1(2) = data1_t2
  5369. entd%changed = .true.
  5370. detu%filled1 = .true.
  5371. detu%tr1(1) = data1_t1
  5372. detu%tr1(2) = data1_t2
  5373. detu%changed = .true.
  5374. detd%filled1 = .true.
  5375. detd%tr1(1) = data1_t1
  5376. detd%tr1(2) = data1_t2
  5377. detd%changed = .true.
  5378. end if
  5379. !--------------------------
  5380. ! read/write secondary field
  5381. !--------------------------
  5382. if ( data2_read ) then
  5383. ! Need whole region for I/O on root. Dummy else
  5384. is = (/1,im(1)/)
  5385. js = (/1,jm(1)/)
  5386. ls = entu%ls
  5387. auxls = gph%ls
  5388. IF (isRoot) THEN
  5389. ! Use the fact that entu, entd, detu, and detd have been allocated with the same bounds and halo
  5390. ALLOCATE( L_entu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5391. ALLOCATE( L_entd( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5392. ALLOCATE( L_detu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5393. ALLOCATE( L_detd( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5394. ALLOCATE(L_gph (im(region),jm(region),auxls(1):auxls(2)))
  5395. ALLOCATE(L_omega (im(region),jm(region),auxls(1):auxls(2)))
  5396. ELSE
  5397. ALLOCATE( L_entu(1,1,1), L_entd(1,1,1), L_detu(1,1,1), L_detd(1,1,1))
  5398. ALLOCATE( L_gph(1,1,1), L_omega(1,1,1) )
  5399. END IF
  5400. CALL GATHER( dgrid(region), gph%data, L_gph, gph%halo, status)
  5401. IF_NOTOK_RETURN(status=1)
  5402. CALL GATHER( dgrid(region), omega%data, L_omega, omega%halo, status)
  5403. IF_NOTOK_RETURN(status=1)
  5404. ! Read/write on root
  5405. IOroot2 : if (isRoot) then
  5406. !AJS ! safety check ...
  5407. !AJS if ( data2_t2 /= data2_t1 ) then
  5408. !AJS !write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  5409. !AJS !call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  5410. !AJS !call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  5411. !AJS !write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  5412. !AJS !call goErr; status=1; return
  5413. !AJS write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  5414. !AJS end if
  5415. ! surface pressure field:
  5416. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  5417. ! fill data2
  5418. call Read_Convec( tmmd, entu%sourcekey, &
  5419. data2_tref, data2_t1, data2_t2, lli, levi, &
  5420. L_omega, omega%tmi, &
  5421. L_gph, gph%tmi, &
  5422. tmp_sp, &
  5423. L_entu, entu%tmi2, L_entd, entd%tmi2, &
  5424. L_detu, detu%tmi2, L_detd, detd%tmi2, &
  5425. status )
  5426. IF_NOTOK_RETURN(status=1)
  5427. ! write meteofiles ?
  5428. if ( entu%putout ) then
  5429. call WriteField( tmmd, entu%destkey, &
  5430. entu%tmi2, 'sp', trim(entu%name), trim(entu%unit), &
  5431. data2_tref, data2_t1, data2_t2, &
  5432. lli, 'n', levi, '*', &
  5433. tmp_sp, L_entu, status )
  5434. IF_NOTOK_RETURN(status=1)
  5435. end if
  5436. if ( entd%putout ) then
  5437. call WriteField( tmmd, entd%destkey, &
  5438. entd%tmi2, 'sp', trim(entd%name), trim(entd%unit), &
  5439. data2_tref, data2_t1, data2_t2, &
  5440. lli, 'n', levi, '*', &
  5441. tmp_sp, L_entd, status )
  5442. IF_NOTOK_RETURN(status=1)
  5443. end if
  5444. if ( detu%putout ) then
  5445. call WriteField( tmmd, detu%destkey, &
  5446. detu%tmi2, 'sp', trim(detu%name), trim(detu%unit), &
  5447. data2_tref, data2_t1, data2_t2, &
  5448. lli, 'n', levi, '*', &
  5449. tmp_sp, L_detu, status )
  5450. IF_NOTOK_RETURN(status=1)
  5451. end if
  5452. if ( detd%putout ) then
  5453. call WriteField( tmmd, detd%destkey, &
  5454. detd%tmi2, 'sp', trim(detd%name), trim(detd%unit), &
  5455. data2_tref, data2_t1, data2_t2, &
  5456. lli, 'n', levi, '*', &
  5457. tmp_sp, L_detd, status )
  5458. IF_NOTOK_RETURN(status=1)
  5459. end if
  5460. ! clear
  5461. deallocate( tmp_sp )
  5462. end if IOroot2
  5463. CALL SCATTER( dgrid(region), entu%data2, L_entu, entu%halo, status)
  5464. IF_NOTOK_RETURN(status=1)
  5465. CALL SCATTER( dgrid(region), entd%data2, L_entd, entd%halo, status)
  5466. IF_NOTOK_RETURN(status=1)
  5467. CALL SCATTER( dgrid(region), detu%data2, L_detu, detu%halo, status)
  5468. IF_NOTOK_RETURN(status=1)
  5469. CALL SCATTER( dgrid(region), detd%data2, L_detd, detd%halo, status)
  5470. IF_NOTOK_RETURN(status=1)
  5471. DEALLOCATE( L_entu, L_entd, L_detu, L_detd, L_gph, L_omega )
  5472. ! data2 array is filled now:
  5473. entu%filled2 = .true.
  5474. entu%tr2(1) = data2_t1
  5475. entu%tr2(2) = data2_t2
  5476. entd%filled2 = .true.
  5477. entd%tr2(1) = data2_t1
  5478. entd%tr2(2) = data2_t2
  5479. detu%filled2 = .true.
  5480. detu%tr2(1) = data2_t1
  5481. detu%tr2(2) = data2_t2
  5482. detd%filled2 = .true.
  5483. detd%tr2(1) = data2_t1
  5484. detd%tr2(2) = data2_t2
  5485. else if ( data2_copy ) then
  5486. ! copy data2 from primary array:
  5487. entu%data2 = entu%data1
  5488. entd%data2 = entd%data1
  5489. detu%data2 = detu%data1
  5490. detd%data2 = detd%data1
  5491. ! data2 array is filled now:
  5492. entu%filled2 = .true.
  5493. entu%tr2(1) = data2_t1
  5494. entu%tr2(2) = data2_t2
  5495. entd%filled2 = .true.
  5496. entd%tr2(1) = data2_t1
  5497. entd%tr2(2) = data2_t2
  5498. detu%filled2 = .true.
  5499. detu%tr2(1) = data2_t1
  5500. detu%tr2(2) = data2_t2
  5501. detd%filled2 = .true.
  5502. detd%tr2(1) = data2_t1
  5503. detd%tr2(2) = data2_t2
  5504. end if
  5505. !------------------
  5506. ! time interpolation
  5507. !------------------
  5508. call TimeInterpolation( entu, tr, status )
  5509. IF_NOTOK_RETURN(status=1)
  5510. call TimeInterpolation( entd, tr, status )
  5511. IF_NOTOK_RETURN(status=1)
  5512. call TimeInterpolation( detu, tr, status )
  5513. IF_NOTOK_RETURN(status=1)
  5514. call TimeInterpolation( detd, tr, status )
  5515. IF_NOTOK_RETURN(status=1)
  5516. !------------------
  5517. ! done
  5518. !------------------
  5519. status = 0
  5520. if (okdebug) call goLabel()
  5521. END SUBROUTINE SETUP_CONVEC_SERIAL_IO
  5522. !--------------------------------------------------------------------------
  5523. ! TM5 !
  5524. !--------------------------------------------------------------------------
  5525. !BOP
  5526. !
  5527. ! !IROUTINE: SETUP_CONVEC_PARALLEL_IO
  5528. !
  5529. ! !DESCRIPTION: same as setup_convec_serial_io but with parallel i/o
  5530. !\\
  5531. !\\
  5532. ! !INTERFACE:
  5533. !
  5534. SUBROUTINE SETUP_CONVEC_PARALLEL_IO( region, entu, entd, detu, detd, omega, gph, &
  5535. tr, levi, status )
  5536. !
  5537. ! !USES:
  5538. !
  5539. use GO, only : TDate, wrtgol, operator(/=)
  5540. use Grid, only : TllGridInfo, TLevelInfo
  5541. use TMM, only : TMeteoInfo, Read_Convec, WriteField
  5542. !
  5543. ! !INPUT PARAMETERS:
  5544. !
  5545. integer, intent(in) :: region ! region number
  5546. !
  5547. ! !INPUT/OUTPUT PARAMETERS:
  5548. !
  5549. type(TMeteoData), intent(inout) :: entu, entd, detu, detd
  5550. type(TMeteoData), intent(in) :: omega, gph
  5551. type(TDate), intent(in) :: tr(2)
  5552. type(TLevelInfo), intent(in) :: levi
  5553. !
  5554. ! !OUTPUT PARAMETERS:
  5555. !
  5556. integer, intent(out) :: status
  5557. !
  5558. ! !REVISION HISTORY:
  5559. ! 24 Oct 2013 - Ph. Le Sager - v0
  5560. !
  5561. ! !REMARKS:
  5562. !
  5563. !EOP
  5564. !------------------------------------------------------------------------
  5565. !BOC
  5566. character(len=*), parameter :: rname = mname//'/SETUP_CONVEC_PARALLEL_IO'
  5567. logical :: data1_read, data1_copy
  5568. type(TDate) :: data1_tref, data1_t1, data1_t2
  5569. logical :: data2_read, data2_copy
  5570. type(TDate) :: data2_tref, data2_t1, data2_t2
  5571. real, allocatable :: tmp_sp(:,:)
  5572. ! to differentiate b/w local and global data set
  5573. real, pointer, dimension(:,:,:) :: L_entu, L_entd, L_detu, L_detd
  5574. real, pointer :: L_omega(:,:,:), L_gph(:,:,:)
  5575. integer, dimension(2) :: is, js, ls, auxls
  5576. integer :: halo
  5577. integer :: i1, i2, j1, j2
  5578. ! --- begin -----------------------------
  5579. if (okdebug) call goLabel(rname)
  5580. ! leave if not in use:
  5581. if ( (.not. all((/entu%used,entd%used,detu%used,detd%used/)) ) &
  5582. .and. any((/entu%used,entd%used,detu%used,detd%used/)) ) then
  5583. write (gol,'("either none or all of entu/entd/detu/detd should be in use")'); call goErr
  5584. call goErr; status=1; return
  5585. end if
  5586. if ( .not. entu%used ) then
  5587. if (okdebug) call goLabel()
  5588. status=0; return
  5589. end if
  5590. ! gph is required as input:
  5591. if ( .not. gph%used ) then
  5592. write (gol,'("gph should be in use to compute convective stuff from EC convective fluxes")'); call goErr
  5593. call goErr; status=1; return
  5594. end if
  5595. ! omega is required as input:
  5596. if ( .not. omega%used ) then
  5597. write (gol,'("omega should be in use to compute convective stuff")'); call goErr
  5598. call goErr; status=1; return
  5599. end if
  5600. ! not changed by default
  5601. entu%changed = .false.
  5602. entd%changed = .false.
  5603. detu%changed = .false.
  5604. detd%changed = .false.
  5605. !------------------
  5606. ! time stuff
  5607. !------------------
  5608. ! get time interval of met field and check if data from start and/or end
  5609. ! of interval must be read (sufficient to setup from entu only)
  5610. call SetupSetup( entu, tr, &
  5611. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  5612. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  5613. status )
  5614. IF_NOTOK_RETURN(status=1)
  5615. ! work arrays
  5616. if (data1_read .or. data2_read) then
  5617. CALL GET_DISTGRID( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  5618. is = (/i1,i2/)
  5619. js = (/j1,j2/)
  5620. ls = entu%ls
  5621. auxls = gph%ls
  5622. ! Use the fact that entu, entd, detu, and detd have been allocated with the same bounds and halo=0
  5623. allocate( L_entu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5624. allocate( L_entd( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5625. allocate( L_detu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5626. allocate( L_detd( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5627. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  5628. L_gph => gph%data
  5629. L_omega => omega%data
  5630. end if
  5631. !--------------------------
  5632. ! read/write primary field
  5633. !--------------------------
  5634. if ( data1_read ) then
  5635. !AJS if ( data1_t2 /= data1_t1 ) then
  5636. !AJS write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  5637. !AJS end if
  5638. call Read_Convec( tmmd, entu%sourcekey, &
  5639. data1_tref, data1_t1, data1_t2, lli(region), levi, &
  5640. L_omega, omega%tmi, &
  5641. L_gph, gph%tmi, &
  5642. tmp_sp, &
  5643. L_entu, entu%tmi1, L_entd, entd%tmi1, &
  5644. L_detu, detu%tmi1, L_detd, detd%tmi1, &
  5645. status )
  5646. IF_NOTOK_RETURN(status=1)
  5647. ! write meteofiles
  5648. if ( entu%putout ) then
  5649. ! call WriteField( tmmd, entu%destkey, &
  5650. ! entu%tmi1, 'sp', trim(entu%name), trim(entu%unit), &
  5651. ! data1_tref, data1_t1, data1_t2, &
  5652. ! lli, 'n', levi, '*', &
  5653. ! tmp_sp, L_entu, status )
  5654. ! IF_NOTOK_RETURN(status=1)
  5655. end if
  5656. if ( entd%putout ) then
  5657. ! call WriteField( tmmd, entd%destkey, &
  5658. ! entd%tmi1, 'sp', trim(entd%name), trim(entd%unit), &
  5659. ! data1_tref, data1_t1, data1_t2, &
  5660. ! lli, 'n', levi, '*', &
  5661. ! tmp_sp, L_entd, status )
  5662. ! IF_NOTOK_RETURN(status=1)
  5663. end if
  5664. if ( detu%putout ) then
  5665. ! call WriteField( tmmd, detu%destkey, &
  5666. ! detu%tmi1, 'sp', trim(detu%name), trim(detu%unit), &
  5667. ! data1_tref, data1_t1, data1_t2, &
  5668. ! lli, 'n', levi, '*', &
  5669. ! tmp_sp, L_detu, status )
  5670. ! IF_NOTOK_RETURN(status=1)
  5671. end if
  5672. if ( detd%putout ) then
  5673. ! call WriteField( tmmd, detd%destkey, &
  5674. ! detd%tmi1, 'sp', trim(detd%name), trim(detd%unit), &
  5675. ! data1_tref, data1_t1, data1_t2, &
  5676. ! lli, 'n', levi, '*', &
  5677. ! tmp_sp, L_detd, status )
  5678. ! IF_NOTOK_RETURN(status=1)
  5679. end if
  5680. entu%data1(i1:i2,j1:j2,:) = L_entu
  5681. entd%data1(i1:i2,j1:j2,:) = L_entd
  5682. detu%data1(i1:i2,j1:j2,:) = L_detu
  5683. detd%data1(i1:i2,j1:j2,:) = L_detd
  5684. ! data array is filled now:
  5685. entu%filled1 = .true.
  5686. entu%tr1(1) = data1_t1
  5687. entu%tr1(2) = data1_t2
  5688. entu%changed = .true.
  5689. entd%filled1 = .true.
  5690. entd%tr1(1) = data1_t1
  5691. entd%tr1(2) = data1_t2
  5692. entd%changed = .true.
  5693. detu%filled1 = .true.
  5694. detu%tr1(1) = data1_t1
  5695. detu%tr1(2) = data1_t2
  5696. detu%changed = .true.
  5697. detd%filled1 = .true.
  5698. detd%tr1(1) = data1_t1
  5699. detd%tr1(2) = data1_t2
  5700. detd%changed = .true.
  5701. else if ( data1_copy ) then
  5702. ! copy data from secondary array:
  5703. entu%data1 = entu%data2
  5704. entd%data1 = entd%data2
  5705. detu%data1 = detu%data2
  5706. detd%data1 = detd%data2
  5707. ! data array is filled now:
  5708. entu%filled1 = .true.
  5709. entu%tr1(1) = data1_t1
  5710. entu%tr1(2) = data1_t2
  5711. entu%changed = .true.
  5712. entd%filled1 = .true.
  5713. entd%tr1(1) = data1_t1
  5714. entd%tr1(2) = data1_t2
  5715. entd%changed = .true.
  5716. detu%filled1 = .true.
  5717. detu%tr1(1) = data1_t1
  5718. detu%tr1(2) = data1_t2
  5719. detu%changed = .true.
  5720. detd%filled1 = .true.
  5721. detd%tr1(1) = data1_t1
  5722. detd%tr1(2) = data1_t2
  5723. detd%changed = .true.
  5724. end if
  5725. !--------------------------
  5726. ! read/write secondary field
  5727. !--------------------------
  5728. if ( data2_read ) then
  5729. !AJS if ( data2_t2 /= data2_t1 ) then
  5730. !AJS write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  5731. !AJS end if
  5732. call Read_Convec( tmmd, entu%sourcekey, &
  5733. data2_tref, data2_t1, data2_t2, lli(region), levi, &
  5734. L_omega, omega%tmi, &
  5735. L_gph, gph%tmi, &
  5736. tmp_sp, &
  5737. L_entu, entu%tmi2, L_entd, entd%tmi2, &
  5738. L_detu, detu%tmi2, L_detd, detd%tmi2, &
  5739. status )
  5740. IF_NOTOK_RETURN(status=1)
  5741. ! write meteofiles ?
  5742. ! if ( entu%putout ) then
  5743. ! call WriteField( tmmd, entu%destkey, &
  5744. ! entu%tmi2, 'sp', trim(entu%name), trim(entu%unit), &
  5745. ! data2_tref, data2_t1, data2_t2, &
  5746. ! lli, 'n', levi, '*', &
  5747. ! tmp_sp, L_entu, status )
  5748. ! IF_NOTOK_RETURN(status=1)
  5749. ! end if
  5750. ! if ( entd%putout ) then
  5751. ! call WriteField( tmmd, entd%destkey, &
  5752. ! entd%tmi2, 'sp', trim(entd%name), trim(entd%unit), &
  5753. ! data2_tref, data2_t1, data2_t2, &
  5754. ! lli, 'n', levi, '*', &
  5755. ! tmp_sp, L_entd, status )
  5756. ! IF_NOTOK_RETURN(status=1)
  5757. ! end if
  5758. ! if ( detu%putout ) then
  5759. ! call WriteField( tmmd, detu%destkey, &
  5760. ! detu%tmi2, 'sp', trim(detu%name), trim(detu%unit), &
  5761. ! data2_tref, data2_t1, data2_t2, &
  5762. ! lli, 'n', levi, '*', &
  5763. ! tmp_sp, L_detu, status )
  5764. ! IF_NOTOK_RETURN(status=1)
  5765. ! end if
  5766. ! if ( detd%putout ) then
  5767. ! call WriteField( tmmd, detd%destkey, &
  5768. ! detd%tmi2, 'sp', trim(detd%name), trim(detd%unit), &
  5769. ! data2_tref, data2_t1, data2_t2, &
  5770. ! lli, 'n', levi, '*', &
  5771. ! tmp_sp, L_detd, status )
  5772. ! IF_NOTOK_RETURN(status=1)
  5773. ! end if
  5774. entu%data2(i1:i2,j1:j2,:) = L_entu
  5775. entd%data2(i1:i2,j1:j2,:) = L_entd
  5776. detu%data2(i1:i2,j1:j2,:) = L_detu
  5777. detd%data2(i1:i2,j1:j2,:) = L_detd
  5778. ! data2 array is filled now:
  5779. entu%filled2 = .true.
  5780. entu%tr2(1) = data2_t1
  5781. entu%tr2(2) = data2_t2
  5782. entd%filled2 = .true.
  5783. entd%tr2(1) = data2_t1
  5784. entd%tr2(2) = data2_t2
  5785. detu%filled2 = .true.
  5786. detu%tr2(1) = data2_t1
  5787. detu%tr2(2) = data2_t2
  5788. detd%filled2 = .true.
  5789. detd%tr2(1) = data2_t1
  5790. detd%tr2(2) = data2_t2
  5791. else if ( data2_copy ) then
  5792. ! copy data2 from primary array:
  5793. entu%data2 = entu%data1
  5794. entd%data2 = entd%data1
  5795. detu%data2 = detu%data1
  5796. detd%data2 = detd%data1
  5797. ! data2 array is filled now:
  5798. entu%filled2 = .true.
  5799. entu%tr2(1) = data2_t1
  5800. entu%tr2(2) = data2_t2
  5801. entd%filled2 = .true.
  5802. entd%tr2(1) = data2_t1
  5803. entd%tr2(2) = data2_t2
  5804. detu%filled2 = .true.
  5805. detu%tr2(1) = data2_t1
  5806. detu%tr2(2) = data2_t2
  5807. detd%filled2 = .true.
  5808. detd%tr2(1) = data2_t1
  5809. detd%tr2(2) = data2_t2
  5810. end if
  5811. !------------------
  5812. ! time interpolation
  5813. !------------------
  5814. call TimeInterpolation( entu, tr, status )
  5815. IF_NOTOK_RETURN(status=1)
  5816. call TimeInterpolation( entd, tr, status )
  5817. IF_NOTOK_RETURN(status=1)
  5818. call TimeInterpolation( detu, tr, status )
  5819. IF_NOTOK_RETURN(status=1)
  5820. call TimeInterpolation( detd, tr, status )
  5821. IF_NOTOK_RETURN(status=1)
  5822. !------------------
  5823. ! done
  5824. !------------------
  5825. if (data1_read .or. data2_read) then
  5826. deallocate(L_entu, L_entd, L_detu, L_detd)
  5827. deallocate( tmp_sp )
  5828. nullify(L_gph, L_omega)
  5829. end if
  5830. status = 0
  5831. if (okdebug) call goLabel()
  5832. END SUBROUTINE SETUP_CONVEC_PARALLEL_IO
  5833. !EOC
  5834. ! **************************************************************
  5835. ! ***
  5836. ! *** diffusive fluxes
  5837. ! ***
  5838. ! **************************************************************
  5839. SUBROUTINE SETUP_DIFFUS_SERIAL_IO( region, Kzz, tr, lli, levi, status )
  5840. use GO, only : TDate, wrtgol, operator(/=)
  5841. use Grid, only : TllGridInfo, TLevelInfo
  5842. use TMM, only : TMeteoInfo, Read_Diffus, WriteField
  5843. use meteodata, only : TMeteoData, TimeInterpolation
  5844. use dims, only : im, jm
  5845. ! --- in/out ----------------------------------
  5846. integer, intent(in) :: region ! region number
  5847. type(TMeteoData), intent(inout) :: Kzz
  5848. type(TDate), intent(in) :: tr(2)
  5849. type(TllGridInfo), intent(in) :: lli
  5850. type(TLevelInfo), intent(in) :: levi
  5851. integer, intent(out) :: status
  5852. ! --- const --------------------------------------
  5853. character(len=*), parameter :: rname = mname//'/SETUP_DIFFUS_SERIAL_IO'
  5854. ! --- local ----------------------------------
  5855. logical :: data1_read, data1_copy
  5856. type(TDate) :: data1_tref, data1_t1, data1_t2
  5857. logical :: data2_read, data2_copy
  5858. type(TDate) :: data2_tref, data2_t1, data2_t2
  5859. real, allocatable :: tmp_sp(:,:)
  5860. real, pointer, dimension(:,:,:) :: L_kzz ! work arrays (data)
  5861. integer :: is(2), js(2), ls(2) ! work arrays (bounds)
  5862. ! --- begin -----------------------------
  5863. ! not in use ?
  5864. if ( .not. Kzz%used ) then
  5865. status=0; return
  5866. end if
  5867. if (okdebug) then
  5868. call goLabel(rname)
  5869. write(gol,'(" ",a,": ",a,l2)') rname, "Diffus", Kzz%used; call goPr
  5870. end if
  5871. ! not changed by default
  5872. Kzz%changed = .false.
  5873. !------------------
  5874. ! time stuff
  5875. !------------------
  5876. ! get time interval of met field and check if data from start and/or end
  5877. ! of interval must be read
  5878. call SetupSetup( Kzz, tr, &
  5879. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  5880. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  5881. status )
  5882. IF_NOTOK_RETURN(status=1)
  5883. !--------------------------
  5884. ! read/write primary field
  5885. !--------------------------
  5886. if ( data1_read ) then
  5887. ! Allocate global arrays for I/O
  5888. is = (/1,im(region)/)
  5889. js = (/1,jm(region)/)
  5890. ls = Kzz%ls
  5891. IF (isRoot) THEN
  5892. ALLOCATE( L_kzz( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5893. ELSE
  5894. ALLOCATE( L_kzz(1,1,1) )
  5895. END IF
  5896. IOroot : if (isRoot) then
  5897. !! safety check ...
  5898. !if ( data1_t2 /= data1_t1 ) then
  5899. ! !write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  5900. ! !call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  5901. ! !call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  5902. ! !write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  5903. ! !call goErr; status=1; return
  5904. ! write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  5905. !end if
  5906. ! surface pressure field:
  5907. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  5908. ! fill data:
  5909. call Read_Diffus( tmmd, Kzz%sourcekey, &
  5910. data1_tref, data1_t1, data1_t2, lli, levi, &
  5911. tmp_sp, &
  5912. L_Kzz, Kzz%tmi1, &
  5913. status )
  5914. IF_NOTOK_RETURN(status=1)
  5915. ! write meteofiles ?
  5916. if ( Kzz%putout ) then
  5917. call WriteField( tmmd, Kzz%destkey, &
  5918. Kzz%tmi1, 'sp', trim(Kzz%name), trim(Kzz%unit), &
  5919. data1_tref, data1_t1, data1_t2, &
  5920. lli, 'n', levi, 'w', &
  5921. tmp_sp, L_Kzz, status )
  5922. IF_NOTOK_RETURN(status=1)
  5923. end if
  5924. ! clear
  5925. deallocate( tmp_sp )
  5926. end if IOroot
  5927. ! Wrap up
  5928. CALL SCATTER( dgrid(region), Kzz%data1, L_kzz, kzz%halo, status)
  5929. IF_NOTOK_RETURN(status=1)
  5930. DEALLOCATE(L_kzz)
  5931. ! data array is filled now:
  5932. Kzz%filled1 = .true.
  5933. Kzz%tr1(1) = data1_t1
  5934. Kzz%tr1(2) = data1_t2
  5935. Kzz%changed = .true.
  5936. else if ( data1_copy ) then
  5937. ! copy data from secondary array:
  5938. Kzz%data1 = Kzz%data2
  5939. ! data array is filled now:
  5940. Kzz%filled1 = .true.
  5941. Kzz%tr1(1) = data1_t1
  5942. Kzz%tr1(2) = data1_t2
  5943. Kzz%changed = .true.
  5944. end if
  5945. ! secondary field ?
  5946. if ( data2_read ) then
  5947. ! Allocate global arrays for I/O
  5948. is = (/1,im(region)/)
  5949. js = (/1,jm(region)/)
  5950. ls = kzz%ls
  5951. IF (isRoot) THEN
  5952. ALLOCATE( L_kzz( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  5953. ELSE
  5954. ALLOCATE( L_kzz(1,1,1) )
  5955. END IF
  5956. ! Read/write
  5957. IOroot2 : IF (isRoot) THEN
  5958. !! safety check ...
  5959. !if ( data2_t2 /= data2_t1 ) then
  5960. ! !write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  5961. ! !call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  5962. ! !call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  5963. ! !write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  5964. ! !call goErr; status=1; return
  5965. ! write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  5966. !end if
  5967. ! surface pressure field:
  5968. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  5969. ! fill data2:
  5970. call Read_Diffus( tmmd, Kzz%sourcekey, &
  5971. data2_tref, data2_t1, data2_t2, lli, levi, &
  5972. tmp_sp, &
  5973. L_Kzz, Kzz%tmi2, &
  5974. status )
  5975. IF_NOTOK_RETURN(status=1)
  5976. ! write meteofiles ?
  5977. if ( Kzz%putout ) then
  5978. call WriteField( tmmd, Kzz%destkey, &
  5979. Kzz%tmi2, 'sp', trim(Kzz%name), trim(Kzz%unit), &
  5980. data2_tref, data2_t1, data2_t2, &
  5981. lli, 'n', levi, 'w', &
  5982. tmp_sp, L_Kzz, status )
  5983. IF_NOTOK_RETURN(status=1)
  5984. end if
  5985. ! clear
  5986. deallocate( tmp_sp )
  5987. end if IOroot2
  5988. CALL SCATTER( dgrid(region), Kzz%data2, L_kzz, kzz%halo, status)
  5989. IF_NOTOK_RETURN(status=1)
  5990. DEALLOCATE(L_kzz)
  5991. ! data2 array is filled now:
  5992. Kzz%filled2 = .true.
  5993. Kzz%tr2(1) = data2_t1
  5994. Kzz%tr2(2) = data2_t2
  5995. else if ( data2_copy ) then
  5996. ! copy data2 from primary array:
  5997. Kzz%data2 = Kzz%data1
  5998. ! data2 array is filled now:
  5999. Kzz%filled2 = .true.
  6000. Kzz%tr2(1) = data2_t1
  6001. Kzz%tr2(2) = data2_t2
  6002. end if
  6003. !------------------
  6004. ! time interpolation
  6005. !------------------
  6006. call TimeInterpolation( Kzz, tr, status )
  6007. IF_NOTOK_RETURN(status=1)
  6008. !------------------
  6009. ! done
  6010. !------------------
  6011. status = 0
  6012. if (okdebug) call goLabel()
  6013. END SUBROUTINE SETUP_DIFFUS_SERIAL_IO
  6014. !--------------------------------------------------------------------------
  6015. ! TM5 !
  6016. !--------------------------------------------------------------------------
  6017. !BOP
  6018. !
  6019. ! !IROUTINE: SETUP_DIFFUS_PARALLEL_IO
  6020. !
  6021. ! !DESCRIPTION:
  6022. !\\
  6023. !\\
  6024. ! !INTERFACE:
  6025. !
  6026. SUBROUTINE SETUP_DIFFUS_PARALLEL_IO( region, Kzz, tr, levi, status )
  6027. !
  6028. ! !USES:
  6029. !
  6030. use GO, only : TDate, wrtgol, operator(/=)
  6031. use Grid, only : TllGridInfo, TLevelInfo
  6032. use TMM, only : TMeteoInfo, Read_Diffus, WriteField
  6033. !
  6034. ! !INPUT/OUTPUT PARAMETERS:
  6035. !
  6036. integer, intent(in) :: region ! region number
  6037. type(TMeteoData), intent(inout) :: Kzz
  6038. type(TDate), intent(in) :: tr(2)
  6039. type(TLevelInfo), intent(in) :: levi
  6040. !
  6041. ! !OUTPUT PARAMETERS:
  6042. !
  6043. integer, intent(out) :: status
  6044. !
  6045. ! !REVISION HISTORY:
  6046. ! 3 Dec 2013 - Ph. Le Sager -
  6047. !
  6048. ! !REMARKS:
  6049. !
  6050. !EOP
  6051. !------------------------------------------------------------------------
  6052. !BOC
  6053. character(len=*), parameter :: rname = mname//'/SETUP_DIFFUS_PARALLEL_IO'
  6054. logical :: data1_read, data1_copy
  6055. type(TDate) :: data1_tref, data1_t1, data1_t2
  6056. logical :: data2_read, data2_copy
  6057. type(TDate) :: data2_tref, data2_t1, data2_t2
  6058. real, allocatable :: tmp_sp(:,:)
  6059. real, pointer, dimension(:,:,:) :: L_kzz ! work arrays (data)
  6060. integer :: is(2), js(2), ls(2) ! work arrays (bounds)
  6061. integer :: i1, i2, j1, j2
  6062. ! --- begin -----------------------------
  6063. ! not in use ?
  6064. if ( .not. Kzz%used ) then
  6065. status=0; return
  6066. end if
  6067. if (okdebug) then
  6068. call goLabel(rname)
  6069. write(gol,'(" ",a,": ",a,l2)') rname, "Diffus", Kzz%used; call goPr
  6070. end if
  6071. ! not changed by default
  6072. Kzz%changed = .false.
  6073. !------------------
  6074. ! time stuff
  6075. !------------------
  6076. ! get time interval of met field and check if data from start and/or end
  6077. ! of interval must be read
  6078. call SetupSetup( Kzz, tr, &
  6079. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  6080. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  6081. status )
  6082. IF_NOTOK_RETURN(status=1)
  6083. ! work arrays
  6084. IF (data1_read .OR. data2_read) THEN
  6085. CALL GET_DISTGRID( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  6086. is = (/i1,i2/)
  6087. js = (/j1,j2/)
  6088. ls = kzz%ls
  6089. ALLOCATE( L_kzz( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6090. ALLOCATE( tmp_sp(is(1):is(2), js(1):js(2) ) )
  6091. ENDIF
  6092. !--------------------------
  6093. ! read/write primary field
  6094. !--------------------------
  6095. if ( data1_read ) then
  6096. !! safety check ...
  6097. !if ( data1_t2 /= data1_t1 ) then
  6098. ! !write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  6099. ! !call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  6100. ! !call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  6101. ! !write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  6102. ! !call goErr; status=1; return
  6103. ! write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  6104. !end if
  6105. call Read_Diffus( tmmd, Kzz%sourcekey, &
  6106. data1_tref, data1_t1, data1_t2, lli(region), levi, &
  6107. tmp_sp, &
  6108. L_Kzz, Kzz%tmi1, &
  6109. status )
  6110. IF_NOTOK_RETURN(status=1)
  6111. !TODO ! write meteofiles ?
  6112. !TODO if ( Kzz%putout ) then
  6113. !TODO call WriteField( tmmd, Kzz%destkey, &
  6114. !TODO Kzz%tmi1, 'sp', trim(Kzz%name), trim(Kzz%unit), &
  6115. !TODO data1_tref, data1_t1, data1_t2, &
  6116. !TODO lli, 'n', levi, 'w', &
  6117. !TODO tmp_sp, L_Kzz, status )
  6118. !TODO IF_NOTOK_RETURN(status=1)
  6119. !TODO end if
  6120. !TODO
  6121. kzz%data1(i1:i2,j1:j2,:) = L_Kzz
  6122. ! data array is filled now:
  6123. Kzz%filled1 = .true.
  6124. Kzz%tr1(1) = data1_t1
  6125. Kzz%tr1(2) = data1_t2
  6126. Kzz%changed = .true.
  6127. else if ( data1_copy ) then
  6128. ! copy data from secondary array:
  6129. Kzz%data1 = Kzz%data2
  6130. ! data array is filled now:
  6131. Kzz%filled1 = .true.
  6132. Kzz%tr1(1) = data1_t1
  6133. Kzz%tr1(2) = data1_t2
  6134. Kzz%changed = .true.
  6135. end if
  6136. ! secondary field ?
  6137. if ( data2_read ) then
  6138. !! safety check ...
  6139. !if ( data2_t2 /= data2_t1 ) then
  6140. ! !write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  6141. ! !call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  6142. ! !call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  6143. ! !write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  6144. ! !call goErr; status=1; return
  6145. ! write (gol,'("WARNING - convec for interval, but pressure/gph/etc instant ...")'); call goPr
  6146. !end if
  6147. ! fill data2:
  6148. call Read_Diffus( tmmd, Kzz%sourcekey, &
  6149. data2_tref, data2_t1, data2_t2, lli(region), levi, &
  6150. tmp_sp, &
  6151. L_Kzz, Kzz%tmi2, &
  6152. status )
  6153. IF_NOTOK_RETURN(status=1)
  6154. !TODO ! write meteofiles ?
  6155. !TODO if ( Kzz%putout ) then
  6156. !TODO call WriteField( tmmd, Kzz%destkey, &
  6157. !TODO Kzz%tmi2, 'sp', trim(Kzz%name), trim(Kzz%unit), &
  6158. !TODO data2_tref, data2_t1, data2_t2, &
  6159. !TODO lli, 'n', levi, 'w', &
  6160. !TODO tmp_sp, L_Kzz, status )
  6161. !TODO IF_NOTOK_RETURN(status=1)
  6162. !TODO end if
  6163. !TODO
  6164. Kzz%data1(i1:i2,j1:j2,:) = L_Kzz
  6165. ! data2 array is filled now:
  6166. Kzz%filled2 = .true.
  6167. Kzz%tr2(1) = data2_t1
  6168. Kzz%tr2(2) = data2_t2
  6169. else if ( data2_copy ) then
  6170. ! copy data2 from primary array:
  6171. Kzz%data2 = Kzz%data1
  6172. ! data2 array is filled now:
  6173. Kzz%filled2 = .true.
  6174. Kzz%tr2(1) = data2_t1
  6175. Kzz%tr2(2) = data2_t2
  6176. end if
  6177. !------------------
  6178. ! time interpolation
  6179. !------------------
  6180. call TimeInterpolation( Kzz, tr, status )
  6181. IF_NOTOK_RETURN(status=1)
  6182. !------------------
  6183. ! done
  6184. !------------------
  6185. if (data1_read .or. data2_read) then
  6186. deallocate( tmp_sp, L_Kzz)
  6187. end if
  6188. status = 0
  6189. if (okdebug) call goLabel()
  6190. END SUBROUTINE SETUP_DIFFUS_PARALLEL_IO
  6191. !EOC
  6192. ! **************************************************************
  6193. ! ***
  6194. ! *** Specific SETUP routine for CLOUD COVER
  6195. ! ***
  6196. ! **************************************************************
  6197. SUBROUTINE SETUP_CLOUDCOVERS_serial_io( region, cc, cco, ccu, tr, lli, levi, status )
  6198. use GO, only : TDate, wrtgol, operator(/=)
  6199. use Grid, only : TllGridInfo, TLevelInfo
  6200. use TMM, only : TMeteoInfo, Read_CloudCovers, WriteField
  6201. use meteodata, only : TMeteoData, TimeInterpolation
  6202. use dims, only : im, jm
  6203. ! --- in/out ----------------------------------
  6204. integer, intent(in) :: region ! region number
  6205. type(TMeteoData), intent(inout) :: cc, cco, ccu
  6206. type(TDate), intent(in) :: tr(2)
  6207. type(TllGridInfo), intent(in) :: lli
  6208. type(TLevelInfo), intent(in) :: levi
  6209. integer, intent(out) :: status
  6210. ! --- const --------------------------------------
  6211. character(len=*), parameter :: rname = mname//'/SETUP_CLOUDCOVERS_serial_io'
  6212. ! --- local ----------------------------------
  6213. logical :: data1_read, data1_copy
  6214. type(TDate) :: data1_tref, data1_t1, data1_t2
  6215. logical :: data2_read, data2_copy
  6216. type(TDate) :: data2_tref, data2_t1, data2_t2
  6217. real, allocatable :: tmp_sp(:,:) ! surface pressure
  6218. real, pointer, dimension(:,:,:) :: L_cc, L_cco, L_ccu ! work arrays (data)
  6219. integer :: is(2), js(2), ls(2) ! work arrays (bounds)
  6220. ! --- begin -----------------------------
  6221. if (okdebug) call goLabel(rname)
  6222. ! leave if not in use:
  6223. if ( (.not. all((/cc%used,cco%used,ccu%used/)) ) .and. any((/cc%used,cco%used,ccu%used/)) ) then
  6224. write (gol,'("either none or all of cc/cco/ccu should be in use")'); call goErr
  6225. call goErr; status=1; return
  6226. end if
  6227. if ( .not. cc%used ) then
  6228. if (okdebug) call goLabel()
  6229. status=0; return
  6230. end if
  6231. ! not changed by default
  6232. cc%changed = .false.
  6233. cco%changed = .false.
  6234. ccu%changed = .false.
  6235. !------------------
  6236. ! time stuff
  6237. !------------------
  6238. ! get time interval of met field and check if data from start and/or end
  6239. ! of interval must be read (sufficient to setup from cc only)
  6240. call SetupSetup( cc, tr, &
  6241. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  6242. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  6243. status )
  6244. IF_NOTOK_RETURN(status=1)
  6245. !--------------------------
  6246. ! read/write primary field
  6247. !--------------------------
  6248. if ( data1_read ) then
  6249. ! Allocate global arrays for I/O
  6250. is = (/1,im(region)/)
  6251. js = (/1,jm(region)/)
  6252. ls = cc%ls
  6253. IF (isRoot) THEN
  6254. ALLOCATE( L_cc( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6255. ALLOCATE( L_cco( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6256. ALLOCATE( L_ccu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6257. ELSE
  6258. ALLOCATE( L_cc(1,1,1), L_cco(1,1,1), L_ccu(1,1,1) )
  6259. END IF
  6260. ! Read/write on root
  6261. IOroot : if (isRoot) then
  6262. ! safety check ...
  6263. if ( data1_t2 /= data1_t1 ) then
  6264. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  6265. call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  6266. call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  6267. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  6268. call goErr; status=1; return
  6269. end if
  6270. ! surface pressure field:
  6271. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  6272. ! fill data:
  6273. call Read_CloudCovers( tmmd, cc%sourcekey, &
  6274. data1_tref, data1_t1, data1_t2, lli, levi, &
  6275. tmp_sp, &
  6276. L_cc, cc%tmi1, &
  6277. L_cco, cco%tmi1, &
  6278. L_ccu, ccu%tmi1, &
  6279. status )
  6280. IF_NOTOK_RETURN(status=1)
  6281. ! write meteofiles
  6282. if ( cc%putout ) then
  6283. call WriteField( tmmd, cc%destkey, &
  6284. cc%tmi1, 'sp', trim(cc%name), trim(cc%unit), &
  6285. data1_tref, data1_t1, data1_t2, &
  6286. lli, 'n', levi, 'n', &
  6287. tmp_sp, L_cc, status )
  6288. IF_NOTOK_RETURN(status=1)
  6289. end if
  6290. if ( cco%putout ) then
  6291. call WriteField( tmmd, cco%destkey, &
  6292. cco%tmi1, 'sp', trim(cco%name), trim(cco%unit), &
  6293. data1_tref, data1_t1, data1_t2, &
  6294. lli, 'n', levi, 'n', &
  6295. tmp_sp, L_cco, status )
  6296. IF_NOTOK_RETURN(status=1)
  6297. end if
  6298. if ( ccu%putout ) then
  6299. call WriteField( tmmd, ccu%destkey, &
  6300. ccu%tmi1, 'sp', trim(ccu%name), trim(ccu%unit), &
  6301. data1_tref, data1_t1, data1_t2, &
  6302. lli, 'n', levi, 'n', &
  6303. tmp_sp, L_ccu, status )
  6304. IF_NOTOK_RETURN(status=1)
  6305. end if
  6306. ! clear
  6307. deallocate( tmp_sp )
  6308. end if IOroot
  6309. ! Wrap up
  6310. CALL SCATTER( dgrid(region), cc%data1, L_cc, cc%halo, status)
  6311. IF_NOTOK_RETURN(status=1)
  6312. CALL SCATTER( dgrid(region), cco%data1, L_cco, cco%halo, status)
  6313. IF_NOTOK_RETURN(status=1)
  6314. CALL SCATTER( dgrid(region), ccu%data1, L_ccu, ccu%halo, status)
  6315. IF_NOTOK_RETURN(status=1)
  6316. DEALLOCATE(L_cc, L_cco, L_ccu)
  6317. ! data array is filled now:
  6318. cc%filled1 = .true.
  6319. cc%tr1(1) = data1_t1
  6320. cc%tr1(2) = data1_t2
  6321. cc%changed = .true.
  6322. cco%filled1 = .true.
  6323. cco%tr1(1) = data1_t1
  6324. cco%tr1(2) = data1_t2
  6325. cco%changed = .true.
  6326. ccu%filled1 = .true.
  6327. ccu%tr1(1) = data1_t1
  6328. ccu%tr1(2) = data1_t2
  6329. ccu%changed = .true.
  6330. else if ( data1_copy ) then
  6331. ! copy data from secondary array:
  6332. cc%data1 = cc%data2
  6333. cco%data1 = cco%data2
  6334. ccu%data1 = ccu%data2
  6335. ! data array is filled now:
  6336. cc%filled1 = .true.
  6337. cc%tr1(1) = data1_t1
  6338. cc%tr1(2) = data1_t2
  6339. cc%changed = .true.
  6340. cco%filled1 = .true.
  6341. cco%tr1(1) = data1_t1
  6342. cco%tr1(2) = data1_t2
  6343. cco%changed = .true.
  6344. ccu%filled1 = .true.
  6345. ccu%tr1(1) = data1_t1
  6346. ccu%tr1(2) = data1_t2
  6347. ccu%changed = .true.
  6348. end if
  6349. !--------------------------
  6350. ! read/write secondary field
  6351. !--------------------------
  6352. if ( data2_read ) then
  6353. ! Allocate global arrays for I/O
  6354. is = (/1,im(region)/)
  6355. js = (/1,jm(region)/)
  6356. ls = cc%ls
  6357. IF (isRoot) THEN
  6358. ! Use the fact that entu, entd, detu, and detd have been allocated with the same bounds and halo
  6359. ALLOCATE( L_cc( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6360. ALLOCATE( L_cco( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6361. ALLOCATE( L_ccu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6362. ELSE
  6363. ALLOCATE( L_cc(1,1,1), L_cco(1,1,1), L_ccu(1,1,1) )
  6364. END IF
  6365. ! Read/write
  6366. IOroot2 : IF (isRoot) THEN
  6367. ! safety check ...
  6368. if ( data2_t2 /= data2_t1 ) then
  6369. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  6370. call wrtgol( ' data2_t1 : ', data2_t1 ); call goErr
  6371. call wrtgol( ' data2_t2 : ', data2_t2 ); call goErr
  6372. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  6373. call goErr; status=1; return
  6374. end if
  6375. ! surface pressure field:
  6376. allocate( tmp_sp(is(1):is(2),js(1):js(2)) )
  6377. ! fill data2:
  6378. call Read_CloudCovers( tmmd, cc%sourcekey, data2_tref, &
  6379. data2_t1, data2_t2, lli, levi, &
  6380. tmp_sp, &
  6381. L_cc, cc%tmi2, &
  6382. L_cco, cco%tmi2, &
  6383. L_ccu, ccu%tmi2, &
  6384. status )
  6385. IF_NOTOK_RETURN(status=1)
  6386. ! write meteofiles ?
  6387. if ( cc%putout ) then
  6388. call WriteField( tmmd, cc%destkey, &
  6389. cc%tmi2, 'sp', trim( cc%name), trim( cc%unit), &
  6390. data2_tref, data2_t1, data2_t2, &
  6391. lli, 'n', levi, 'n', &
  6392. tmp_sp, L_cc, status )
  6393. IF_NOTOK_RETURN(status=1)
  6394. end if
  6395. if ( cco%putout ) then
  6396. call WriteField( tmmd, cco%destkey, &
  6397. cco%tmi2, 'sp', trim(cco%name), trim(cco%unit), &
  6398. data2_tref, data2_t1, data2_t2, &
  6399. lli, 'n', levi, 'n', &
  6400. tmp_sp, L_cco, status )
  6401. IF_NOTOK_RETURN(status=1)
  6402. end if
  6403. if ( ccu%putout ) then
  6404. call WriteField( tmmd, ccu%destkey, &
  6405. ccu%tmi2, 'sp', trim(ccu%name), trim(ccu%unit), &
  6406. data2_tref, data2_t1, data2_t2, &
  6407. lli, 'n', levi, 'n', &
  6408. tmp_sp, L_ccu, status )
  6409. IF_NOTOK_RETURN(status=1)
  6410. end if
  6411. ! clear
  6412. deallocate( tmp_sp )
  6413. end if IOroot2
  6414. ! Wrap up
  6415. CALL SCATTER( dgrid(region), cc%data2, L_cc, cc%halo, status)
  6416. IF_NOTOK_RETURN(status=1)
  6417. CALL SCATTER( dgrid(region), cco%data2, L_cco, cco%halo, status)
  6418. IF_NOTOK_RETURN(status=1)
  6419. CALL SCATTER( dgrid(region), ccu%data2, L_ccu, ccu%halo, status)
  6420. IF_NOTOK_RETURN(status=1)
  6421. DEALLOCATE(L_cc, L_cco, L_ccu)
  6422. ! data2 array is filled now:
  6423. cc%filled2 = .true.
  6424. cc%tr2(1) = data2_t1
  6425. cc%tr2(2) = data2_t2
  6426. cco%filled2 = .true.
  6427. cco%tr2(1) = data2_t1
  6428. cco%tr2(2) = data2_t2
  6429. ccu%filled2 = .true.
  6430. ccu%tr2(1) = data2_t1
  6431. ccu%tr2(2) = data2_t2
  6432. else if ( data2_copy ) then
  6433. ! copy data2 from primary array:
  6434. cc%data2 = cc%data1
  6435. cco%data2 = cco%data1
  6436. ccu%data2 = ccu%data1
  6437. ! data2 array is filled now:
  6438. cc%filled2 = .true.
  6439. cc%tr2(1) = data2_t1
  6440. cc%tr2(2) = data2_t2
  6441. cco%filled2 = .true.
  6442. cco%tr2(1) = data2_t1
  6443. cco%tr2(2) = data2_t2
  6444. ccu%filled2 = .true.
  6445. ccu%tr2(1) = data2_t1
  6446. ccu%tr2(2) = data2_t2
  6447. end if
  6448. !------------------
  6449. ! time interpolation
  6450. !------------------
  6451. call TimeInterpolation( cc, tr, status )
  6452. IF_NOTOK_RETURN(status=1)
  6453. call TimeInterpolation( cco, tr, status )
  6454. IF_NOTOK_RETURN(status=1)
  6455. call TimeInterpolation( ccu, tr, status )
  6456. IF_NOTOK_RETURN(status=1)
  6457. !------------------
  6458. ! done
  6459. !------------------
  6460. status = 0
  6461. if (okdebug) call goLabel()
  6462. END SUBROUTINE SETUP_CLOUDCOVERS_SERIAL_IO
  6463. !--------------------------------------------------------------------------
  6464. ! TM5 !
  6465. !--------------------------------------------------------------------------
  6466. !BOP
  6467. !
  6468. ! !IROUTINE: SETUP_CLOUDCOVERS_PARALLEL_IO
  6469. !
  6470. ! !DESCRIPTION:
  6471. !\\
  6472. !\\
  6473. ! !INTERFACE:
  6474. !
  6475. SUBROUTINE SETUP_CLOUDCOVERS_PARALLEL_IO( region, cc, cco, ccu, tr, levi, status )
  6476. !
  6477. ! !USES:
  6478. !
  6479. use GO, only : TDate, wrtgol, operator(/=)
  6480. use Grid, only : TllGridInfo, TLevelInfo
  6481. use TMM, only : TMeteoInfo, Read_CloudCovers, WriteField
  6482. use dims, only : im, jm
  6483. !
  6484. ! !INPUT PARAMETERS:
  6485. !
  6486. integer, intent(in) :: region ! region number
  6487. !
  6488. ! !INPUT/OUTPUT PARAMETERS:
  6489. !
  6490. type(TMeteoData), intent(inout) :: cc, cco, ccu
  6491. type(TDate), intent(in) :: tr(2)
  6492. type(TLevelInfo), intent(in) :: levi
  6493. !
  6494. ! !OUTPUT PARAMETERS:
  6495. !
  6496. integer, intent(out) :: status
  6497. !
  6498. ! !REVISION HISTORY:
  6499. ! 24 Oct 2013 - Ph. Le Sager - v0
  6500. !
  6501. ! !REMARKS:
  6502. !
  6503. !EOP
  6504. !------------------------------------------------------------------------
  6505. !BOC
  6506. character(len=*), parameter :: rname = mname//'/SETUP_CLOUDCOVERS_PARALLEL_IO'
  6507. logical :: data1_read, data1_copy
  6508. type(TDate) :: data1_tref, data1_t1, data1_t2
  6509. logical :: data2_read, data2_copy
  6510. type(TDate) :: data2_tref, data2_t1, data2_t2
  6511. real, allocatable :: tmp_sp(:,:) ! surface pressure
  6512. real, pointer, dimension(:,:,:) :: L_cc, L_cco, L_ccu ! work arrays (data)
  6513. integer :: is(2), js(2), ls(2) ! work arrays (bounds)
  6514. integer :: i1, i2, j1, j2
  6515. ! --- begin -----------------------------
  6516. if (okdebug) call goLabel(rname)
  6517. ! leave if not in use:
  6518. if ( (.not. all((/cc%used,cco%used,ccu%used/)) ) .and. any((/cc%used,cco%used,ccu%used/)) ) then
  6519. write (gol,'("either none or all of cc/cco/ccu should be in use")'); call goErr
  6520. call goErr; status=1; return
  6521. end if
  6522. if ( .not. cc%used ) then
  6523. if (okdebug) call goLabel()
  6524. status=0; return
  6525. end if
  6526. ! not changed by default
  6527. cc%changed = .false.
  6528. cco%changed = .false.
  6529. ccu%changed = .false.
  6530. !------------------
  6531. ! time stuff
  6532. !------------------
  6533. ! get time interval of met field and check if data from start and/or end
  6534. ! of interval must be read (sufficient to setup from cc only)
  6535. call SetupSetup( cc, tr, &
  6536. data1_read, data1_copy, data1_tref, data1_t1, data1_t2, &
  6537. data2_read, data2_copy, data2_tref, data2_t1, data2_t2, &
  6538. status )
  6539. IF_NOTOK_RETURN(status=1)
  6540. ! work arrays
  6541. IF (data1_read .OR. data2_read) THEN
  6542. CALL GET_DISTGRID( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  6543. is = (/i1,i2/)
  6544. js = (/j1,j2/)
  6545. ls = cc%ls
  6546. ALLOCATE( L_cc( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6547. ALLOCATE( L_cco( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6548. ALLOCATE( L_ccu( is(1):is(2), js(1):js(2), ls(1):ls(2)) )
  6549. ALLOCATE( tmp_sp(is(1):is(2),js(1):js(2)) )
  6550. ENDIF
  6551. !--------------------------
  6552. ! read/write primary field
  6553. !--------------------------
  6554. if ( data1_read ) then
  6555. ! safety check
  6556. if ( data1_t2 /= data1_t1 ) then
  6557. write (gol,'("not sure that this routine is correct for time intervals:")'); call goErr
  6558. call wrtgol( ' data1_t1 : ', data1_t1 ); call goErr
  6559. call wrtgol( ' data1_t2 : ', data1_t2 ); call goErr
  6560. write (gol,'("please deceide what to do with surface pressures ... ")'); call goErr
  6561. TRACEBACK; status=1; return
  6562. end if
  6563. call Read_CloudCovers( tmmd, cc%sourcekey, &
  6564. data1_tref, data1_t1, data1_t2, lli(region), levi, &
  6565. tmp_sp, &
  6566. L_cc, cc%tmi1, &
  6567. L_cco, cco%tmi1, &
  6568. L_ccu, ccu%tmi1, &
  6569. status )
  6570. IF_NOTOK_RETURN(status=1)
  6571. ! ! write meteofiles
  6572. ! if ( cc%putout ) then
  6573. ! call WriteField( tmmd, cc%destkey, &
  6574. ! cc%tmi1, 'sp', trim(cc%name), trim(cc%unit), &
  6575. ! data1_tref, data1_t1, data1_t2, &
  6576. ! lli, 'n', levi, 'n', &
  6577. ! tmp_sp, L_cc, status )
  6578. ! IF_NOTOK_RETURN(status=1)
  6579. ! end if
  6580. ! if ( cco%putout ) then
  6581. ! call WriteField( tmmd, cco%destkey, &
  6582. ! cco%tmi1, 'sp', trim(cco%name), trim(cco%unit), &
  6583. ! data1_tref, data1_t1, data1_t2, &
  6584. ! lli, 'n', levi, 'n', &
  6585. ! tmp_sp, L_cco, status )
  6586. ! IF_NOTOK_RETURN(status=1)
  6587. ! end if
  6588. ! if ( ccu%putout ) then
  6589. ! call WriteField( tmmd, ccu%destkey, &
  6590. ! ccu%tmi1, 'sp', trim(ccu%name), trim(ccu%unit), &
  6591. ! data1_tref, data1_t1, data1_t2, &
  6592. ! lli, 'n', levi, 'n', &
  6593. ! tmp_sp, L_ccu, status )
  6594. ! IF_NOTOK_RETURN(status=1)
  6595. ! end if
  6596. cc%data1(i1:i2,j1:j2,:) = L_cc
  6597. cco%data1(i1:i2,j1:j2,:) = L_cco
  6598. ccu%data1(i1:i2,j1:j2,:) = L_ccu
  6599. ! data array is filled now:
  6600. cc%filled1 = .true.
  6601. cc%tr1(1) = data1_t1
  6602. cc%tr1(2) = data1_t2
  6603. cc%changed = .true.
  6604. cco%filled1 = .true.
  6605. cco%tr1(1) = data1_t1
  6606. cco%tr1(2) = data1_t2
  6607. cco%changed = .true.
  6608. ccu%filled1 = .true.
  6609. ccu%tr1(1) = data1_t1
  6610. ccu%tr1(2) = data1_t2
  6611. ccu%changed = .true.
  6612. else if ( data1_copy ) then
  6613. ! copy data from secondary array:
  6614. cc%data1 = cc%data2
  6615. cco%data1 = cco%data2
  6616. ccu%data1 = ccu%data2
  6617. ! data array is filled now:
  6618. cc%filled1 = .true.
  6619. cc%tr1(1) = data1_t1
  6620. cc%tr1(2) = data1_t2
  6621. cc%changed = .true.
  6622. cco%filled1 = .true.
  6623. cco%tr1(1) = data1_t1
  6624. cco%tr1(2) = data1_t2
  6625. cco%changed = .true.
  6626. ccu%filled1 = .true.
  6627. ccu%tr1(1) = data1_t1
  6628. ccu%tr1(2) = data1_t2
  6629. ccu%changed = .true.
  6630. end if
  6631. !--------------------------
  6632. ! read/write secondary field
  6633. !--------------------------
  6634. if ( data2_read ) then
  6635. ! safety check ...
  6636. if ( data2_t2 /= data2_t1 ) then
  6637. write (gol,'("not sure that this routine is correct for time intervals:")') ; call goErr
  6638. call wrtgol( ' data2_t1 : ', data2_t1 ) ; call goErr
  6639. call wrtgol( ' data2_t2 : ', data2_t2 ) ; call goErr
  6640. write (gol,'("please deceide what to do with surface pressures ... ")') ; call goErr
  6641. call goErr; status=1; return
  6642. end if
  6643. call Read_CloudCovers( tmmd, cc%sourcekey, data2_tref, &
  6644. data2_t1, data2_t2, lli(region), levi, &
  6645. tmp_sp, &
  6646. L_cc, cc%tmi2, &
  6647. L_cco, cco%tmi2, &
  6648. L_ccu, ccu%tmi2, &
  6649. status )
  6650. IF_NOTOK_RETURN(status=1)
  6651. ! ! write meteofiles ?
  6652. ! if ( cc%putout ) then
  6653. ! call WriteField( tmmd, cc%destkey, &
  6654. ! cc%tmi2, 'sp', trim( cc%name), trim( cc%unit), &
  6655. ! data2_tref, data2_t1, data2_t2, &
  6656. ! lli, 'n', levi, 'n', &
  6657. ! tmp_sp, L_cc, status )
  6658. ! IF_NOTOK_RETURN(status=1)
  6659. ! end if
  6660. ! if ( cco%putout ) then
  6661. ! call WriteField( tmmd, cco%destkey, &
  6662. ! cco%tmi2, 'sp', trim(cco%name), trim(cco%unit), &
  6663. ! data2_tref, data2_t1, data2_t2, &
  6664. ! lli, 'n', levi, 'n', &
  6665. ! tmp_sp, L_cco, status )
  6666. ! IF_NOTOK_RETURN(status=1)
  6667. ! end if
  6668. ! if ( ccu%putout ) then
  6669. ! call WriteField( tmmd, ccu%destkey, &
  6670. ! ccu%tmi2, 'sp', trim(ccu%name), trim(ccu%unit), &
  6671. ! data2_tref, data2_t1, data2_t2, &
  6672. ! lli, 'n', levi, 'n', &
  6673. ! tmp_sp, L_ccu, status )
  6674. ! IF_NOTOK_RETURN(status=1)
  6675. ! end if
  6676. cc%data2(i1:i2,j1:j2,:) = L_cc
  6677. cco%data2(i1:i2,j1:j2,:) = L_cco
  6678. ccu%data2(i1:i2,j1:j2,:) = L_ccu
  6679. ! data2 array is filled now:
  6680. cc%filled2 = .true.
  6681. cc%tr2(1) = data2_t1
  6682. cc%tr2(2) = data2_t2
  6683. cco%filled2 = .true.
  6684. cco%tr2(1) = data2_t1
  6685. cco%tr2(2) = data2_t2
  6686. ccu%filled2 = .true.
  6687. ccu%tr2(1) = data2_t1
  6688. ccu%tr2(2) = data2_t2
  6689. else if ( data2_copy ) then
  6690. ! copy data2 from primary array:
  6691. cc%data2 = cc%data1
  6692. cco%data2 = cco%data1
  6693. ccu%data2 = ccu%data1
  6694. ! data2 array is filled now:
  6695. cc%filled2 = .true.
  6696. cc%tr2(1) = data2_t1
  6697. cc%tr2(2) = data2_t2
  6698. cco%filled2 = .true.
  6699. cco%tr2(1) = data2_t1
  6700. cco%tr2(2) = data2_t2
  6701. ccu%filled2 = .true.
  6702. ccu%tr2(1) = data2_t1
  6703. ccu%tr2(2) = data2_t2
  6704. end if
  6705. !------------------
  6706. ! time interpolation
  6707. !------------------
  6708. call TimeInterpolation( cc, tr, status )
  6709. IF_NOTOK_RETURN(status=1)
  6710. call TimeInterpolation( cco, tr, status )
  6711. IF_NOTOK_RETURN(status=1)
  6712. call TimeInterpolation( ccu, tr, status )
  6713. IF_NOTOK_RETURN(status=1)
  6714. !------------------
  6715. ! done
  6716. !------------------
  6717. if (data1_read .or. data2_read) then
  6718. deallocate( tmp_sp )
  6719. deallocate(L_cc, L_cco, L_ccu)
  6720. end if
  6721. status = 0
  6722. if (okdebug) call goLabel()
  6723. END SUBROUTINE SETUP_CLOUDCOVERS_PARALLEL_IO
  6724. !EOC
  6725. !--------------------------------------------------------------------------
  6726. ! TM5 !
  6727. !--------------------------------------------------------------------------
  6728. !BOP
  6729. !
  6730. ! !IROUTINE: PRESSURE_TO_MASS
  6731. !
  6732. ! !DESCRIPTION: Get Air Mass: from surface pressure (sp), get pressure at
  6733. ! box boundaries (so-called half-levels, phlb), and then air
  6734. ! mass (m_dat).
  6735. !\\
  6736. !\\
  6737. ! !INTERFACE:
  6738. !
  6739. SUBROUTINE PRESSURE_TO_MASS( region, status )
  6740. !
  6741. ! !USES:
  6742. !
  6743. use Binas, only : grav
  6744. use Grid, only : HPressure
  6745. !use Grid, only : FillMass
  6746. use Grid, only : AreaOper
  6747. use dims, only : im, jm, lm
  6748. use dims, only : xcyc
  6749. !
  6750. ! !INPUT PARAMETERS:
  6751. !
  6752. integer, intent(in) :: region
  6753. !
  6754. ! !OUTPUT PARAMETERS:
  6755. !
  6756. integer, intent(out) :: status
  6757. !
  6758. ! !REVISION HISTORY:
  6759. ! 7 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  6760. !
  6761. ! !REMARKS: (old remark: "assume that halo cells in sp have been filled
  6762. ! correctly..." still valid???)
  6763. !
  6764. !EOP
  6765. !------------------------------------------------------------------------
  6766. !BOC
  6767. character(len=*), parameter :: rname = mname//'/Pressure_to_Mass'
  6768. integer :: l, i0, i1, j0, j1, lmr
  6769. ! --- begin ----------------------------------
  6770. ! Local grid size
  6771. i0 = sp_dat(region)%is(1)
  6772. i1 = sp_dat(region)%is(2)
  6773. j0 = sp_dat(region)%js(1)
  6774. j1 = sp_dat(region)%js(2)
  6775. lmr = lm(region)
  6776. ! Fill pressure boundaries (Pa)
  6777. if ( phlb_dat(region)%used ) then
  6778. call HPressure( levi, sp_dat(region)%data(i0:i1, j0:j1, 1), &
  6779. phlb_dat(region)%data(i0:i1, j0:j1, :), status )
  6780. IF_NOTOK_RETURN(status=0)
  6781. end if
  6782. ! Fill air mass (kg)
  6783. if ( m_dat(region)%used ) then
  6784. !call FillMass( m_dat(region)%data(1:imr,1:jmr,:), lli(region), levi, &
  6785. ! sp_dat(region)%data(1:imr,1:jmr,1), status )
  6786. !IF_NOTOK_RETURN(status=0)
  6787. ! Pressure difference between top and bottom of layer
  6788. do l = 1, lmr
  6789. m_dat(region)%data(:,:,l) = phlb_dat(region)%data(:,:,l) - phlb_dat(region)%data(:,:,l+1) ! Pa
  6790. end do
  6791. ! Convert to kg/m2
  6792. m_dat(region)%data = m_dat(region)%data / grav ! Pa/g = kg/m2
  6793. ! Convert to kg
  6794. call AreaOper( lli(region), m_dat(region)%data(i0:i1, j0:j1, :), '*', 'm2', status ) ! kg
  6795. IF_NOTOK_RETURN(status=0)
  6796. end if
  6797. ! ok
  6798. status = 0
  6799. END SUBROUTINE PRESSURE_TO_MASS
  6800. !EOC
  6801. !--------------------------------------------------------------------------
  6802. ! TM5 !
  6803. !--------------------------------------------------------------------------
  6804. !BOP
  6805. !
  6806. ! !IROUTINE: MASS_TO_PRESSURE
  6807. !
  6808. ! !DESCRIPTION: get 3D and surface (spm) pressures from 3D Air Mass.
  6809. !\\
  6810. !\\
  6811. ! !INTERFACE:
  6812. !
  6813. SUBROUTINE MASS_TO_PRESSURE( region, status )
  6814. !
  6815. ! !USES:
  6816. !
  6817. use Binas, only : grav
  6818. use Grid, only : AreaOper
  6819. use dims, only : lm
  6820. !
  6821. ! !INPUT PARAMETERS:
  6822. !
  6823. integer, intent(in) :: region
  6824. !
  6825. ! !OUTPUT PARAMETERS:
  6826. !
  6827. integer, intent(out) :: status
  6828. !
  6829. ! !REVISION HISTORY:
  6830. ! 7 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  6831. !
  6832. !EOP
  6833. !------------------------------------------------------------------------
  6834. !BOC
  6835. character(len=*), parameter :: rname = mname//'/Mass_to_Pressure'
  6836. integer :: l, i0, i1, j0, j1, lmr
  6837. ! --- begin ----------------------------------
  6838. ! Local grid size
  6839. i0 = sp_dat(region)%is(1)
  6840. i1 = sp_dat(region)%is(2)
  6841. j0 = sp_dat(region)%js(1)
  6842. j1 = sp_dat(region)%js(2)
  6843. lmr = lm(region)
  6844. ! Fill pressure at half level boundaries:
  6845. ! o zero in space:
  6846. phlb_dat(region)%data(:,:,lmr+1) = 0.0 ! kg m/s2 = Pa m2
  6847. ! o add for each level pressure gradient:
  6848. do l = lmr, 1, -1
  6849. phlb_dat(region)%data(i0:i1, j0:j1, l) = phlb_dat(region)%data(i0:i1, j0:j1, l+1) &
  6850. + m_dat(region)%data(i0:i1, j0:j1, l ) * grav ! kg m/s2 = Pa m2
  6851. end do
  6852. ! Divide by grid cell area
  6853. call AreaOper( lli(region), phlb_dat(region)%data(i0:i1, j0:j1, :), '/', 'm2', status ) ! Pa
  6854. IF_NOTOK_RETURN(status=0)
  6855. ! copy surface pressure
  6856. spm_dat(region)%data(i0:i1, j0:j1, 1) = phlb_dat(region)%data(i0:i1, j0:j1, 1) ! Pa
  6857. ! ok
  6858. status = 0
  6859. END SUBROUTINE MASS_TO_PRESSURE
  6860. !EOC
  6861. !--------------------------------------------------------------------------
  6862. ! TM5 !
  6863. !--------------------------------------------------------------------------
  6864. !BOP
  6865. !
  6866. ! !IROUTINE: COMPUTE_GPH
  6867. !
  6868. ! !DESCRIPTION: compute geopotential height
  6869. !\\
  6870. !\\
  6871. ! !INTERFACE:
  6872. !
  6873. SUBROUTINE COMPUTE_GPH( region, status )
  6874. !
  6875. ! !USES:
  6876. !
  6877. use Dims, only : itau, lm
  6878. use Dims, only : at, bt
  6879. use binas, only : grav
  6880. use datetime, only : tstamp
  6881. !
  6882. ! !INPUT PARAMETERS:
  6883. !
  6884. integer, intent(in) :: region
  6885. !
  6886. ! !OUTPUT PARAMETERS:
  6887. !
  6888. integer, intent(out) :: status
  6889. !
  6890. ! !REVISION HISTORY:
  6891. ! 10 Nov 2011 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  6892. !
  6893. !EOP
  6894. !------------------------------------------------------------------------
  6895. !BOC
  6896. character(len=*), parameter :: rname = mname//'/compute_gph'
  6897. ! --- local ----------------------------------
  6898. real,dimension(:,:,:),pointer :: gph, t, q
  6899. real,dimension(:,:,:),pointer :: ps
  6900. integer :: i,j,l,i0,i1,j0,j1
  6901. real :: tv,pdown,pup
  6902. ! --- begin -----------------------------
  6903. ! leave if not in use:
  6904. if ( .not. gph_dat(region)%used ) then
  6905. if (okdebug) then
  6906. write (gol,'(a," not used on : ",i2)') trim(gph_dat(region)%name),region; call goPr
  6907. endif
  6908. status=0; return
  6909. end if
  6910. ! other meteo required:
  6911. if ( (.not. temper_dat(region)%used) .or. (.not. humid_dat(region)%used) &
  6912. .or. (.not. sp_dat(region)%used) .or. (.not. oro_dat(region)%used)) then
  6913. write (gol,'("computation of gph requires temper, humid, sp, and oro")'); call goErr
  6914. TRACEBACK; status=1; return
  6915. end if
  6916. ! leave if input did not change:
  6917. if ( (.not. sp_dat(region)%changed) .and. &
  6918. (.not. temper_dat(region)%changed) .and. &
  6919. (.not. humid_dat(region)%changed) ) then
  6920. if (okdebug) then
  6921. write (gol,'(a,": not changed for region ",i2)') rname, region; call goErr
  6922. endif
  6923. status=0
  6924. return
  6925. end if
  6926. ! field will be changed ...
  6927. gph_dat(region)%changed = .true.
  6928. ! pointers to meteo field
  6929. ps => sp_dat(region)%data
  6930. t => temper_dat(region)%data
  6931. q => humid_dat(region)%data
  6932. gph => gph_dat(region)%data
  6933. ! bounds w/o halo (same as: call Get_DistGrid( dgrid(region), I_STRT=i01, I_STOP=i02, J_STRT=j01, J_STOP=j02 )
  6934. i0 = gph_dat(region)%is(1)
  6935. i1 = gph_dat(region)%is(2)
  6936. j0 = gph_dat(region)%js(1)
  6937. j1 = gph_dat(region)%js(2)
  6938. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6939. ! compute geo potential height
  6940. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6941. gph(i0:i1,j0:j1,1) = oro_dat(region)%data(i0:i1,j0:j1,1)/grav ! oro is stored in g*m
  6942. do l=1,lm(region)-1
  6943. do j=j0,j1
  6944. do i=i0,i1
  6945. tv = t(i,j,l)*(1. + 0.608*q(i,j,l))
  6946. pdown = at(l) + bt(l)*ps(i,j,1)
  6947. pup = at(l+1) + bt(l+1)*ps(i,j,1)
  6948. ! rgas in different units!
  6949. gph(i,j,l+1) = gph(i,j,l) + tv*287.05*alog(pdown/pup)/grav
  6950. ! note dec 2002 (MK) gph now from 1--->lm+1
  6951. end do
  6952. end do
  6953. end do
  6954. !set top of atmosphere at 200 km
  6955. gph(:,:,lm(region)+1) = 200000.0
  6956. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6957. ! done
  6958. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6959. nullify( ps )
  6960. nullify( t )
  6961. nullify( q )
  6962. nullify( gph )
  6963. status = 0
  6964. END SUBROUTINE COMPUTE_GPH
  6965. !EOC
  6966. END MODULE METEO