p_sanity_check.F90 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980
  1. PROGRAM sanity_check_LIM3
  2. ! Checks if a LIM3 restart is physically consistent and outputs the updated
  3. ! version. Strongly based on limupdate.F90, and on sanity_check_LIM2
  4. ! (c) Original from Chris König Beatty
  5. ! (c) Re-written by Francois Massonnet, November 2012,
  6. ! (c) Refreshed for NEMO3.6, Francois Massonnet, April 2016
  7. ! francois.massonnet@uclouvain.be
  8. !
  9. !
  10. ! TODO: create subroutines to automaticate the extraction of NetCDF!
  11. ! **************************************************************************************************
  12. ! PLAN of the program
  13. !
  14. !
  15. ! 0. Header
  16. ! 1. Check existence of NetCDF files, grab command line args
  17. ! 1) Ice analysis file
  18. ! 2) Ice forecast file
  19. ! 3) Oce analysis file
  20. ! 4) Oce forecast file
  21. ! 5) Mask file
  22. ! 6) Mesh file
  23. ! 2. Get dimensions, nb ice categories, nb ice/snow layers, allocate, get ice thickness bounds
  24. ! 3. Load ice+oce and mask+mesh variables from files
  25. ! 4. Ice analysis sanity check
  26. ! 1) Regularize ice concentration and adapt other variables
  27. ! accordingly
  28. ! 2) Manually update the snow and ice heat content according to volume
  29. ! changes
  30. ! 3) Rebin categories with thickness out of bounds (CALL itd_reb() )
  31. ! Note that itd_reb() calls shift_ice if a shift needs be done
  32. ! 4) Several ice corrections
  33. ! For example, set volume to zero where concentration is zero.
  34. ! 5) Shrink ice (CALL shrink_ice() )
  35. ! If sum(a_i) > 1 or < 0 or some a_i > 1 or < 0, then ice is shrunk
  36. ! or reset to zero.
  37. ! 6) Rebin categories with thickness out of bounds (CALL itd_reb() )
  38. ! We do it once again as thickness may have changed
  39. ! during processes 2) and 3)
  40. ! 7) Final concentration check (CALL conc_check() )
  41. ! The program stops if > 1 or < 0 occurs in sum or individual categories
  42. ! This can ultimately cause trouble in the code as a term (1-sum(a_i))^0.6
  43. ! occurs in a routine => negative power 0.6 is very baaaad
  44. ! If ice concentration is just above 1 or just below zero (numerics) then
  45. ! the program resets to zero or one.
  46. ! 5. Oce analysis sanity check
  47. ! 1) Compute the difference between forecast and analyzed sea salinity
  48. ! If larger than XXX PSU, bound variations by that value
  49. ! Also update the sea surface salinity variable accordingly
  50. ! 2) Same for sea temperature; replace analysed temperature by forecast if
  51. ! less than -2°C
  52. ! 3) Limit ocean velocities to [-2,2] m/s
  53. ! 6. Record the files. The original file is copied and the variables are dumped
  54. ! in it
  55. ! 1) Ice analysis file
  56. ! 2) Oce analysis file
  57. !***************************************************************************************************
  58. !
  59. ! 0. Header
  60. ! ---------
  61. USE netcdf
  62. USE my_variables
  63. IMPLICIT NONE
  64. ! Dummy variables
  65. INTEGER :: jl, ji, jj, jk
  66. !
  67. ! 1. Grab Command Line Arguments
  68. ! ------------------------------
  69. IF (iargc()==4) THEN
  70. CALL getarg(1, cfile_analysis_ice)
  71. CALL getarg(2, cfile_forecast_ice)
  72. CALL getarg(3, cfile_analysis_oce)
  73. CALL getarg(4, cfile_forecast_oce)
  74. ! Check if files exist
  75. ! 1) Ice analysis file
  76. INQUIRE(FILE=TRIM(cfile_analysis_ice), EXIST=l_ex)
  77. IF ( .NOT. l_ex ) THEN
  78. WRITE(*,*) "(sanity_check_lim3) File does not exist: " //&
  79. &TRIM(cfile_analysis_ice)
  80. STOP
  81. END IF
  82. ! 2) Ice forecast file
  83. INQUIRE(FILE=TRIM(cfile_forecast_ice), EXIST=l_ex)
  84. IF ( .NOT. l_ex ) THEN
  85. WRITE(*,*) "(sanity_check_lim3) File does not exist: " //&
  86. &TRIM(cfile_forecast_ice)
  87. STOP
  88. END IF
  89. ! 3) Oce analysis file
  90. INQUIRE(FILE=TRIM(cfile_analysis_oce), EXIST=l_ex)
  91. IF ( .NOT. l_ex ) THEN
  92. WRITE(*,*) "(sanity_check_lim3) File does not exist: " //&
  93. &TRIM(cfile_analysis_oce)
  94. STOP
  95. END IF
  96. ! 4) Oce forecast file
  97. INQUIRE(FILE=TRIM(cfile_forecast_oce), EXIST=l_ex)
  98. IF ( .NOT. l_ex ) THEN
  99. WRITE(*,*) "(sanity_check_lim3) File does not exist: " //&
  100. &TRIM(cfile_forecast_oce)
  101. STOP
  102. END IF
  103. ! 5) Mask file
  104. INQUIRE(FILE=TRIM(cmaskfile), EXIST=l_ex)
  105. IF ( .NOT. l_ex ) THEN
  106. WRITE(*,*) "(sanity_check_lim3) File does not exist: " //&
  107. &TRIM(cmaskfile)
  108. STOP
  109. END IF
  110. ! 6) Mesh file
  111. INQUIRE(FILE=TRIM(cmeshfile), EXIST=l_ex)
  112. IF ( .NOT. l_ex ) THEN
  113. WRITE(*,*) "(sanity_check_lim3) File does not exist: " //&
  114. &TRIM(cmeshfile)
  115. STOP
  116. END IF
  117. ! Everything went OK:
  118. WRITE(*,*) "(sanity_check_lim3) Starting ..."
  119. ELSE
  120. ! Write info
  121. WRITE(*,*)
  122. WRITE(*,*) " sanity_check_LIM3 needs arguments: "
  123. WRITE(*,*) " -analysis_file_ice "
  124. WRITE(*,*) " -forecast_file_ice "
  125. WRITE(*,*) " -analysis_file_oce "
  126. WRITE(*,*) " -forecast_file_oce "
  127. WRITE(*,*) " Checks NEMO-LIM3 ice and ocean analyses restarst (netcdf) file for sanity and fixes&
  128. &them if necessary."
  129. WRITE(*,*)
  130. WRITE(*,*) " Sanity means for now:"
  131. WRITE(*,*) " Strongly follow limupdate.F90"
  132. WRITE(*,*) " Files mask.nc and mesh_hgr.nc need to be in the current directory"
  133. WRITE(*,*)
  134. WRITE(*,*) " Hope to see you again soon."
  135. WRITE(*,*)
  136. WRITE(*,*) " Chris König Beatty "
  137. WRITE(*,*) " Francois Massonnet -- francois.massonnet@uclouvain.be"
  138. WRITE(*,*) " Last update: 2013"
  139. WRITE(*,*) " Last update: 2016 (to work with NEMO3.6)"
  140. STOP "(sanity_check): Stopped."
  141. END IF ! iargc
  142. ! 2. Get dimensions, and allocate the variables
  143. ! ---------------------------------------------
  144. CALL get_dimensions()
  145. ! Get number of ice categories
  146. CALL get_nb_cat()
  147. ! Get number of ice layers
  148. CALL get_nb_il()
  149. ! Get number of snow layers
  150. CALL get_nb_sl()
  151. ! Allocate variables
  152. CALL allocate_variables()
  153. ! Register ice thickness limits
  154. ! See Clement Rousset LIM3 paper or LIM3 doc:
  155. ! http://www.geosci-model-dev.net/8/2991/2015/gmd-8-2991-2015.pdf
  156. ! or the routine sbcice_lim.F90
  157. !
  158. !
  159. !
  160. !
  161. zalpha = 0.05 ! exponent of the transform function
  162. rn_himean = 2.0 ! the expected mean thickness over the domain
  163. zhmax = 3.*rn_himean
  164. DO jl = 1, jpl
  165. znum = jpl * ( zhmax+1 )**zalpha
  166. zden = ( jpl - jl ) * ( zhmax+1 )**zalpha + jl
  167. hi_max(jl) = ( znum / zden )**(1./zalpha) - 1
  168. END DO
  169. ! Set hi_max(jpl) to a big value to ensure that all ice is thinner than hi_max(jpl)
  170. hi_max(jpl) = 99._wp
  171. WRITE(*,*), "Ice categories boundaries [m] are", hi_max
  172. ! 3. Load variables
  173. ! -----------------
  174. CALL load_variables()
  175. WRITE(*,*), "babysit after load_variables:"
  176. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  177. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,1,2)
  178. ! 4. Ice analysis sanity check
  179. ! ----------------------------
  180. ! 1) Regularize ice concentration and other variables based on that
  181. CALL regularize()
  182. WRITE(*,*), "babysit after regularize:"
  183. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  184. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,1,2)
  185. WRITE(*,*), " "
  186. ! 2) Heat content update
  187. ! F. Massonnet - test CALL update_hc()
  188. ! CALL update_hc()
  189. ! 3) Rebin categories with thickness out of bounds
  190. ! The code here follows closely the contents of subroutine limi_itd_th_reb
  191. CALL itd_reb()
  192. WRITE(*,*), "babysit after itd_reb #1:"
  193. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  194. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,1,2)
  195. WRITE(*,*), " "
  196. ! 4) Several ice corrections
  197. CALL several_ice_corrections()
  198. WRITE(*,*), "babysit several ice corrections:"
  199. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  200. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,1,2)
  201. WRITE(*,*), " "
  202. ! 5) Shrink ice
  203. CALL shrink_ice()
  204. WRITE(*,*), "babysit after shrink_ice:"
  205. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  206. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,1,2)
  207. WRITE(*,*), " "
  208. ! 6) Rebin categories with thickness out of bounds
  209. CALL itd_reb()
  210. WRITE(*,*), "babysit after itd_reb #2:"
  211. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  212. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,1,2)
  213. WRITE(*,*), " "
  214. ! 7) Final check.
  215. ! Stops if total conc > 1 or < 0, same for inidividual conc
  216. ! If exceeds 1 or is below zero for numerical reasons, reset.
  217. CALL conc_check()
  218. WRITE(*,*), "babysit after conc check:"
  219. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  220. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,1,2)
  221. WRITE(*,*), " "
  222. ! 5. Ocean analysis sanity check
  223. ! ------------------------------
  224. ! 1) Salinity
  225. CALL salinity_check()
  226. ! 2) Temperature
  227. CALL temperature_check()
  228. ! 3) Velocity
  229. CALL velocity_check()
  230. ! 6. Record NetCDF
  231. ! ----------------
  232. ! 1) Ice variables
  233. CALL record_ice()
  234. WRITE(*,*), "babysit after record ice:"
  235. WRITE(*,*), "e_s_l01 i j", e_s(jiindx,jjindx,1,1)
  236. WRITE(*,*), "e_s_l02 i j", e_s(jiindx,jjindx,2,1)
  237. WRITE(*,*), "found negative val"
  238. DO jk = 1, nlay_s
  239. DO jl = 1, jpl
  240. DO ji = 1, jpi
  241. DO jj = 1 , jpj
  242. IF ( e_s(ji,jj,jl,jk) < rzero ) THEN
  243. WRITE(*,*), "e_s < 0.0 in i=",ji," j=",jj
  244. ENDIF
  245. END DO ! jj
  246. END DO ! ji
  247. END DO ! jl
  248. END DO ! jk
  249. ! 2) Oce variables
  250. CALL record_oce()
  251. END PROGRAM sanity_check_LIM3
  252. ! SUBROUTINES
  253. ! ¨¨¨¨¨¨¨¨¨¨¨
  254. SUBROUTINE itd_reb()
  255. ! --------------------------------------------------------
  256. ! This routine is strongly inspired from lim_itd_th_reb
  257. ! When in situ thickness exceeds bounds, it transfers ice
  258. ! to neighbouring categories
  259. ! This routine calls shiftice() defined below
  260. ! --------------------------------------------------------
  261. USE my_variables
  262. IMPLICIT NONE
  263. ! Dummy variables
  264. INTEGER :: ji, jj, jl
  265. WRITE(*,*) 'Entering itd_reb()'
  266. ! 4.2.1 Compute in situ ice thickness in the categories (if there's ice)
  267. DO jl = 1, jpl
  268. DO ji = 1, jpi
  269. DO jj = 1 , jpj
  270. IF ( a_i(ji,jj,jl) > epsi10 ) THEN
  271. ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
  272. ELSE
  273. ht_i(ji,jj,jl) = rzero
  274. ENDIF
  275. END DO ! jj
  276. END DO ! ji
  277. END DO ! jl
  278. ! Print data at particular location before rebinning
  279. !WRITE(*,*) 'Before rebinning: '
  280. !WRITE(*,*) 'a_i : ',a_i(jiindx,jjindx,:)
  281. !WRITE(*,*) 'ht_i : ',ht_i(jiindx,jjindx,:)
  282. !WRITE(*,*) 'Total concentration: ', SUM(a_i(jiindx,jjindx,:))
  283. !WRITE(*,*) 'Total volume : ', SUM(v_i(jiindx,jjindx,:))
  284. ! 4.2.2 Make sure thickness of first category is at least hi_max_typ
  285. ! Not sure to understand what to do here
  286. ! 4.2.3. If a category is not in bounds, shift the entire area, volume and
  287. ! energy to the neighbouring category
  288. ! Initialize shift arrays
  289. DO jl = 1, jpl
  290. idonor(:,:,jl) = 0
  291. ! idonor is the index of the category that is giving ice with respect to
  292. ! the running category.
  293. ! Example: we are looping over categories. When jl = 3 (third category),
  294. ! we notice that this category has way too much ice. Then idonor(ji,jj,3)
  295. ! will be 3. Example 2 (jl=3): The fourth category has too much ice
  296. ! Then idonor(ji,jj,3) = 4
  297. zdaice(:,:,jl) = 0
  298. zdvice(:,:,jl) = 0
  299. END DO
  300. ! 4.2.3.1 Move thin categories up
  301. ! Strategy: -loop over all categories up to the last-but-one
  302. ! -identify thicknesses in the current category that are too big
  303. ! -if applicable, transfer all volume, area and energy to the
  304. ! jpl + 1 category
  305. DO jl = 1, jpl - 1
  306. zshiftflag = 0
  307. DO ji = 1, jpi
  308. DO jj= 1, jpj
  309. IF ( a_i(ji,jj,jl) > epsi10 .AND. ht_i(ji,jj,jl) > hi_max(jl) ) THEN
  310. IF ( ldebug ) THEN
  311. WRITE(*,*), "Found excessive ice thickness in category",jl
  312. WRITE(*,*), ht_i(ji,jj,jl), "larger than" , hi_max(jl)
  313. WRITE(*,*), "At grid point" , ji, jj
  314. END IF
  315. zshiftflag = 1 ! There's at least one point in the domain
  316. ! with too thick a sea ice in this category
  317. idonor(ji,jj,jl) = jl ! The running category is then donor
  318. zdaice(ji,jj,jl) = a_i(ji,jj,jl) ! Amount of ice to be transferred
  319. zdvice(ji,jj,jl) = v_i(ji,jj,jl) ! (everything)
  320. END IF
  321. END DO! jj
  322. END DO ! ji
  323. IF (zshiftflag == 1) THEN ! this is the case if there was at least one
  324. ! excessive thickness in the running category
  325. ! somewhere on the domain
  326. CALL shiftice()
  327. idonor(:,:,jl) = 0 ! Reset before we move to next category
  328. zdaice(:,:,jl) = rzero
  329. zdvice(:,:,jl) = rzero
  330. END IF
  331. END DO ! jl, categories
  332. ! 4.2.3.2 Move thick categories down
  333. ! Strategy: -loop over all categories starting from last-but-one
  334. ! to the first one
  335. ! -identify if the thickness of the category above is smaller
  336. ! than the upper limit for the running category
  337. ! -if so, transfer everything to the running category
  338. DO jl = jpl-1, 1, -1 ! first, last, step
  339. zshiftflag = 0
  340. DO ji = 1, jpi
  341. DO jj= 1, jpj
  342. IF ( a_i(ji,jj,jl+1) > epsi10 .AND. ht_i(ji,jj,jl+1) <= hi_max(jl) ) THEN
  343. IF ( ldebug ) THEN
  344. WRITE(*,*), "Found too small ice thickness in category",jl+1
  345. WRITE(*,*), ht_i(ji,jj,jl+1), "smaller than" , hi_max(jl)
  346. END IF
  347. zshiftflag = 1 ! There's at least one point in the domain
  348. ! with too thin a sea ice in this category
  349. idonor(ji,jj,jl) = jl+1 ! The jl+1 category is then donor
  350. zdaice(ji,jj,jl) = a_i(ji,jj,jl+1) ! Amount of ice to be transferred
  351. zdvice(ji,jj,jl) = v_i(ji,jj,jl+1) ! (everything)
  352. END IF
  353. END DO! jj
  354. END DO ! ji
  355. IF (zshiftflag == 1) THEN ! this is the case if there was at least one
  356. ! too small thickness in the jl+1 category
  357. CALL shiftice()
  358. idonor(:,:,jl) = rzero ! Reset before we move to next category
  359. zdaice(:,:,jl) = rzero
  360. zdvice(:,:,jl) = rzero
  361. END IF
  362. END DO ! jl, categories
  363. ! 4.2.3.3 Conservation check
  364. ! Print data at particular location after rebinning
  365. !WRITE(*,*) 'After rebinning: '
  366. !WRITE(*,*) 'a_i : ',a_i(jiindx,jjindx,:)
  367. !WRITE(*,*) 'ht_i : ',ht_i(jiindx,jjindx,:)
  368. !WRITE(*,*) 'Total concentration: ', SUM(a_i(jiindx,jjindx,:))
  369. !WRITE(*,*) 'Total volume : ', SUM(v_i(jiindx,jjindx,:))
  370. WRITE(*,*) 'Leaving itd_reb()'
  371. END SUBROUTINE itd_reb
  372. SUBROUTINE shiftice()
  373. !-------------------------------------------------------------
  374. ! This routine is (strongly) inspired by lim_itd_shiftice
  375. ! It re-arranges ice thickness in the categories
  376. !
  377. ! This routine can potentially be called 2*4 times,
  378. ! for the first jpl-1 categories to upgrade their too thick ice
  379. ! and for the jpl-1 last categories to downgrade their too thin ice
  380. !
  381. !
  382. ! Francois Massonnet UCL 2012 francois.massonnet@uclouvain.be
  383. !-------------------------------------------------------------
  384. ! Variable declaration and importation
  385. USE my_variables
  386. IMPLICIT NONE
  387. LOGICAL :: zdaice_negative, zdvice_negative, zdaice_greater_aicen,&
  388. &zdvice_greater_vicen
  389. ! Number of cells with ice to transfer
  390. REAL(wp), DIMENSION(jpi,jpj) :: zworka
  391. REAL(wp), DIMENSION(jpi,jpj,jpl) :: zaTsfn
  392. REAL(wp) :: zdvsnow, zdesnow, zdo_aice
  393. ! Volume of snow transferred,
  394. ! Snow heat, ice age
  395. ! local variables
  396. REAL(wp) :: zdsm_vice, zdaTsf, zdeice
  397. ! ice age, surface temperature,
  398. ! ice heat content
  399. ! local variables
  400. ! Dummy variables
  401. INTEGER :: ji, jj, jl, jk, jl1, jl2
  402. ! End definitions
  403. ! ----------------------------------------------------------------------
  404. ! Welcome the user
  405. WRITE(*,*) 'Entering SUBROUTINE shiftice'
  406. ! Define surface temperature times concentration
  407. ! This has more dimensions like energy. It will be used
  408. ! when surface temperature will be "transferred" after rebinning
  409. DO jl = 1 , jpl
  410. zaTsfn(:,:,jl) = a_i(:,:,jl) * t_su(:,:,jl)
  411. END DO
  412. ! Subroutine
  413. DO jl = 1 , jpl - 1
  414. zdaice_negative = .FALSE.
  415. zdvice_negative = .FALSE.
  416. zdaice_greater_aicen = .FALSE.
  417. zdvice_greater_vicen = .FALSE.
  418. DO ji = 1 , jpi
  419. DO jj = 1 , jpj
  420. !---------------------------------------------------------------------
  421. ! 1) Check for daice or dvice out of bounds and reset if necessary
  422. !---------------------------------------------------------------------
  423. IF ( idonor(ji,jj,jl) .GT. 0 ) THEN ! If the running category is giving
  424. jl1=idonor(ji,jj,jl) ! record the donor category
  425. !WRITE(*,*), "At grid point ", ji, jj, "category", jl1, "is giving ice"
  426. ! Tackle the cases with problems. Normally, zdaice and zdvice should
  427. ! be positive, but ...
  428. ! Check for negative transfers of ice given in input
  429. ! 1. Ice area
  430. IF (zdaice(ji,jj,jl) .LT. rzero ) THEN
  431. IF (zdaice(ji,jj,jl) .GT. -epsi10 ) THEN
  432. WRITE(*,*)," zdaice is negative but artificial"
  433. IF ( ( jl1 .EQ. jl .AND. ht_i(ji,jj,jl1) .GT. hi_max(jl) )&
  434. &.OR.&
  435. &( jl1 .EQ. jl+1 .AND. ht_i(ji,jj,jl1) .LE. hi_max(jl) )) THEN
  436. ! You are here if one of these 2 conditions are verified
  437. ! 1) The running category is the donor and has too thick a
  438. ! sea ice
  439. ! 2) The running category is one category below the donor,
  440. ! which has too thin a sea ice
  441. !
  442. ! If you still with me, it means that a transfer needs to be
  443. ! done but the amount of ice is negative due to roundoff
  444. ! error or something. Let us reset zdaice and zdvice to the
  445. ! value of a_i and v_i in the category for the transfer
  446. zdaice(ji,jj,jl) = a_i(ji,jj,jl1)
  447. zdvice(ji,jj,jl) = v_i(ji,jj,jl1)
  448. ELSE ! None of the two conditions above is verified
  449. ! That is,
  450. ! 1) The running category is not the donor or has a correct
  451. ! ice
  452. ! AND
  453. ! 2) The category above the running one is not the donor, or
  454. ! the ice is correct in this above category
  455. !
  456. ! Since everything is fine, nothing should be done
  457. zdaice(ji,jj,jl) = rzero
  458. zdvice(ji,jj,jl) = rzero
  459. END IF
  460. ELSE ! zdaice < - eps10
  461. WRITE(*,*) "zdaice is really negative"
  462. zdaice_negative = .TRUE.
  463. END IF
  464. END IF ! zdaice < 0
  465. ! 2. Repeat for ice volume
  466. IF (zdvice(ji,jj,jl) .LT. rzero ) THEN
  467. IF (zdvice(ji,jj,jl) .GT. -epsi10 ) THEN
  468. WRITE(*,*)," zdvice is negative but artificial"
  469. IF ( ( jl1 .EQ. jl .AND. ht_i(ji,jj,jl1) .GT. hi_max(jl) )&
  470. &.OR.&
  471. &( jl1 .EQ. jl+1 .AND. ht_i(ji,jj,jl1) .LE. hi_max(jl) )) THEN
  472. ! You are here if one of these 2 conditions are verified
  473. ! 1) The running category is the donor and has too thick a
  474. ! sea ice
  475. ! 2) The running category is one category below the donor,
  476. ! which has too thin a sea ice
  477. !
  478. ! If you still with me, it means that a transfer needs to be
  479. ! done but the amount of ice is negative due to roundoff
  480. ! error or something. Let us reset zdaice and zdvice to the
  481. ! value of a_i and v_i in the category for the transfer
  482. zdaice(ji,jj,jl) = a_i(ji,jj,jl1)
  483. zdvice(ji,jj,jl) = v_i(ji,jj,jl1)
  484. ELSE ! None of the two conditions above is verified
  485. ! That is,
  486. ! 1) The running category is not the donor or has a correct
  487. ! ice
  488. ! AND
  489. ! 2) The category above the running one is not the donor, or
  490. ! the ice is correct in this above category
  491. !
  492. ! Since everything is fine, nothing should be done
  493. zdaice(ji,jj,jl) = rzero
  494. zdvice(ji,jj,jl) = rzero
  495. END IF
  496. ELSE ! zdvice < - eps10
  497. WRITE(*,*) "zdvice is really negative"
  498. zdvice_negative = .TRUE.
  499. END IF
  500. END IF ! zdvice < 0
  501. ! 3.A. If the area to be transferred equals the area in the running
  502. ! category, then just update it to the exact value
  503. ! (i.e. round it )
  504. IF ( zdaice(ji,jj,jl) .GT. a_i(ji,jj,jl1) - epsi10 .AND.&
  505. & zdaice(ji,jj,jl) .LT. a_i(ji,jj,jl1) + epsi10 ) THEN
  506. ! if concentration to be transferred is "equal"
  507. ! to the concentration of the donor. This is obviously the case
  508. ! if the running category is the donor
  509. zdaice(ji,jj,jl) = a_i(ji,jj,jl1)
  510. zdvice(ji,jj,jl) = v_i(ji,jj,jl1)
  511. ELSE
  512. ! Otherwise, set the switch to true
  513. zdaice_greater_aicen = .TRUE.
  514. END IF ! zdaice "=" a_i
  515. ! 3.B. (Repeat for volume)
  516. ! If the volume to be transferred equals the volume in the running
  517. ! category, then keep it as is
  518. IF ( zdvice(ji,jj,jl) .GT. v_i(ji,jj,jl1) - epsi10 .AND.&
  519. & zdvice(ji,jj,jl) .LT. v_i(ji,jj,jl1) + epsi10 ) THEN
  520. ! if volume to be transferred is "equal"
  521. ! to the volume of the donor. This is obviously the case
  522. ! if the running category is the donor
  523. zdaice(ji,jj,jl) = a_i(ji,jj,jl1)
  524. zdvice(ji,jj,jl) = v_i(ji,jj,jl1)
  525. ELSE
  526. zdvice_greater_vicen = .TRUE.
  527. END IF ! zdaice "=" a_i
  528. ELSE ! if idonor
  529. ! Nothing happens since this category is not giving ice
  530. END IF ! if idonor
  531. END DO ! jj
  532. END DO ! ji
  533. END DO ! jl, category
  534. !-------------------------------------------------
  535. ! 2) Transfer volume and energy between categories
  536. !-------------------------------------------------
  537. DO jl = 1, jpl - 1
  538. DO ji = 1, jpi
  539. DO jj = 1, jpj
  540. IF (zdaice(ji,jj,jl) .GT. rzero ) THEN
  541. jl1 = idonor(ji,jj,jl)
  542. ! Define proportionality factor.
  543. ! zworka will be the ratio between transferred volume of ice and
  544. ! actual volume of ice in the category. Auxiliary quantities (snow volume, snow
  545. ! heat content, ice age, salinity, etc.) will be transferred following
  546. ! this ratio. Indeed, if out of 4 m of ice, 1 m is transferred, then
  547. ! 1/4 of the snow volume will be transferred, too.
  548. zindb = MAX( rzero , SIGN( rone , v_i(ji,jj,jl1) - epsi10 ) )
  549. ! Thus zindb is equal to 1 if the donor has positive and not artificially
  550. ! close to zero ice volume to give, to zero otherwise
  551. zworka(ji,jj) = zdvice(ji,jj,jl) / MAX( v_i(ji,jj,jl1), epsi10 ) *&
  552. &zindb
  553. ! zworka is zero where the donor has no ice, otherwise
  554. ! equal to zdvice/vice of the current category
  555. ! We have a donor, but who is the benefiter? who will receive ice?
  556. IF ( jl1 == jl ) THEN ! If the donor is the current category, then
  557. jl2=jl1+1 ! the receiver is the one above
  558. ELSE ! Otherwise (the donor is the above categ)
  559. jl2=jl ! then it's the current category!
  560. END IF
  561. ! -----------------------
  562. ! Go for the transfers!!!
  563. ! -----------------------
  564. ! A. Ice areas
  565. ! ------------
  566. a_i(ji,jj,jl1) = a_i(ji,jj,jl1) - zdaice(ji,jj,jl)
  567. a_i(ji,jj,jl2) = a_i(ji,jj,jl2) + zdaice(ji,jj,jl)
  568. ! The donor loses , the receiver gains
  569. ! B. Ice volumes
  570. ! --------------
  571. v_i(ji,jj,jl1) = v_i(ji,jj,jl1) - zdvice(ji,jj,jl)
  572. v_i(ji,jj,jl2) = v_i(ji,jj,jl2) + zdvice(ji,jj,jl)
  573. ! C. Snow volumes
  574. ! ---------------
  575. zdvsnow = v_s(ji,jj,jl1) * zworka(ji,jj)
  576. v_s(ji,jj,jl1) = v_s(ji,jj,jl1) - zdvsnow
  577. v_s(ji,jj,jl2) = v_s(ji,jj,jl2) + zdvsnow
  578. ! D. Snow heat content
  579. ! --------------------
  580. IF ( ldebug .AND. ( ji == jiindx ) .AND. ( jj == jjindx ) ) THEN
  581. WRITE(*,*) 'Before itd_reb e_s_l01:' , e_s(ji,jj,1,jl)
  582. END IF
  583. DO jk = 1 , nlay_s
  584. zdesnow = e_s(ji,jj,jk,jl1) * zworka(ji,jj)
  585. e_s(ji,jj,jk,jl1) = e_s(ji,jj,jk,jl1) - zdesnow
  586. e_s(ji,jj,jk,jl2) = e_s(ji,jj,jk,jl2) + zdesnow
  587. IF ( ldebug .AND. ( ji == jiindx ) .AND. ( jj == jjindx ) ) THEN
  588. WRITE(*,*) 'Res shrink jl1:' , e_s(ji,jj,jk,jl1)
  589. WRITE(*,*) 'Res shrink jl2:' , e_s(ji,jj,jk,jl2)
  590. END IF
  591. END DO
  592. IF ( ldebug .AND. ( ji == jiindx ) .AND. ( jj == jjindx ) ) THEN
  593. WRITE(*,*) 'after itd_reb e_s_l01:' , e_s(ji,jj,1,jl)
  594. END IF
  595. ! E. Ice age
  596. ! ----------
  597. ! Ice age is defined as areal. If 1/2 of the area
  598. ! is transferred then 1/2 of the age too
  599. ! Wat een cromme definitie!
  600. zdo_aice = oa_i(ji,jj,jl1) * zdaice(ji,jj,jl)
  601. oa_i(ji,jj,jl1) = oa_i(ji,jj,jl1) - zdo_aice
  602. oa_i(ji,jj,jl2) = oa_i(ji,jj,jl2) + zdo_aice
  603. ! F. Ice salinity
  604. ! ---------------
  605. zdsm_vice = smv_i(ji,jj,jl1) * zworka(ji,jj)
  606. smv_i(ji,jj,jl1) = smv_i(ji,jj,jl1) - zdsm_vice
  607. smv_i(ji,jj,jl2) = smv_i(ji,jj,jl2) + zdsm_vice
  608. ! G. Surface temperature
  609. ! ----------------------
  610. zdaTsf = t_su(ji,jj,jl1) * zdaice(ji,jj,jl)
  611. zaTsfn(ji,jj,jl1) = zaTsfn(ji,jj,jl1) - zdaTsf
  612. zaTsfn(ji,jj,jl2) = zaTsfn(ji,jj,jl2) + zdaTsf
  613. ! H. Ice heat content
  614. ! -------------------
  615. DO jk = 1 , nlay_i
  616. zdeice = e_i(ji,jj,jk,jl1) * zworka(ji,jj)
  617. e_i(ji,jj,jk,jl1) = e_i(ji,jj,jk,jl1) - zdeice
  618. e_i(ji,jj,jk,jl2) = e_i(ji,jj,jk,jl2) + zdeice
  619. END DO
  620. ELSE
  621. ! WRITE(*,*),"Nothing to transfer"
  622. END IF
  623. END DO ! jpj
  624. END DO ! jpi
  625. END DO ! jl, category
  626. ! ---------------------------------------
  627. ! 3) Update ice thickness and temperature
  628. ! ---------------------------------------
  629. DO jl = 1 , jpl
  630. DO ji = 1 , jpi
  631. DO jj = 1 , jpj
  632. IF ( a_i(ji,jj,jl) > epsi10 ) THEN
  633. ht_i(ji,jj,jl) = v_i(ji,jj,jl) / a_i(ji,jj,jl)
  634. t_su(ji,jj,jl) = zaTsfn(ji,jj,jl) / a_i(ji,jj,jl)
  635. ELSE
  636. ht_i(ji,jj,jl) = rzero
  637. t_su(ji,jj,jl) = rtt ! If no ice then set "ice" temperature to
  638. ! freezing point
  639. END IF
  640. END DO ! jj
  641. END DO !ji
  642. END DO ! jl
  643. WRITE(*,*) 'Leaving SUBROUTINE shiftice'
  644. END SUBROUTINE shiftice
  645. SUBROUTINE conc_check()
  646. USE my_variables
  647. IMPLICIT NONE
  648. ! Dummy variables
  649. INTEGER :: ji, jj, jl
  650. DO ji=1,jpi
  651. DO jj = 1,jpj
  652. DO jl=1,jpl
  653. ! 1. Individual concentrations greater than zero
  654. IF ( a_i(ji,jj,jl) .LT. rzero ) THEN
  655. IF (a_i(ji,jj,jl) .LT. -epsi10) THEN ! We have a "true" negative conc
  656. WRITE(*,*) 'ERROR: final check: a_i negative at ',ji,jj
  657. WRITE(*,*) 'for category ',jl
  658. WRITE(*,*) 'Value: ', a_i(ji,jj,jl)
  659. WRITE(*,*) 'ABORT'
  660. STOP
  661. ELSE ! We have a fake negative conc
  662. a_i(ji,jj,jl) = rzero
  663. ENDIF
  664. ENDIF
  665. ! 2. Individual concentrations less than one
  666. IF ( a_i(ji,jj,jl) .GT. zamax ) THEN
  667. IF (a_i(ji,jj,jl) - zamax .GT. epsi10) THEN ! We have a "true" positive conc
  668. WRITE(*,*) 'ERROR: final check: a_i more than zamax at ',ji,jj
  669. WRITE(*,*) 'for category ',jl
  670. WRITE(*,*) 'Value: ', a_i(ji,jj,jl)
  671. WRITE(*,*) 'ABORT'
  672. STOP
  673. ELSE ! We have a fake more than one conc
  674. a_i(ji,jj,jl) = zamax
  675. ENDIF
  676. ENDIF
  677. END DO ! jl
  678. ! 3. Total concentration greater than zero
  679. IF ( SUM(a_i(ji,jj,:)) .LT. rzero ) THEN
  680. IF (SUM(a_i(ji,jj,:)) .LT. -epsi10) THEN ! We have a "true" negative total conc
  681. WRITE(*,*) 'ERROR: final check: at_i negative at ',ji,jj
  682. WRITE(*,*) 'Value: ', SUM(a_i(ji,jj,:))
  683. WRITE(*,*) 'ABORT'
  684. STOP
  685. ELSE ! We have a fake negative conc
  686. ! Let's reset all categories to zero
  687. DO jl = 1, jpl
  688. a_i(ji,jj,jl)=rzero
  689. END DO
  690. ENDIF
  691. ENDIF
  692. ! 4. Total concentration less than one
  693. IF ( SUM(a_i(ji,jj,:)) .GT. zamax ) THEN
  694. IF (SUM(a_i(ji,jj,:)) - zamax .GT. epsi10) THEN ! We have a "true"positive conc
  695. WRITE(*,*) 'ERROR: final check: at_i more than one at ',ji,jj
  696. WRITE(*,*) 'Value: ', SUM(a_i(ji,jj,:))
  697. WRITE(*,*) 'Individual: ', a_i(ji,jj,:)
  698. WRITE(*,*) 'ABORT'
  699. STOP
  700. ELSE ! We have a fake more than one conc
  701. ! Define the excess, which is by definition negligible
  702. zda_i = SUM(a_i(ji,jj,:)) - zamax ! (positive)
  703. ! Give this excess to the first category than can accept it, i.e. that
  704. ! has less than zamax - zda_i
  705. l_adjust = .TRUE.
  706. DO jl = 1, jpl
  707. IF ( ( a_i(ji,jj,jl) .GT. zda_i ) .AND. l_adjust ) THEN
  708. a_i(ji,jj,jl) = a_i(ji,jj,jl) - zda_i
  709. l_adjust = .FALSE.
  710. END IF
  711. ENDDO ! jl
  712. IF ( l_adjust ) THEN
  713. WRITE(*,*) 'It was not possible to give the excess of ice.'
  714. WRITE(*,*) 'At grid point ',ji,jj
  715. WRITE(*,*) 'Category', jl
  716. WRITE(*,*) 'The excess is ', zda_i
  717. WRITE(*,*) 'The conc. in categories are ', a_i(ji,jj,:)
  718. WRITE(*,*) ' ABORT'
  719. STOP
  720. END IF
  721. ENDIF
  722. ENDIF
  723. END DO !jj
  724. END DO !ji
  725. END SUBROUTINE conc_check
  726. SUBROUTINE get_dimensions()
  727. USE my_variables
  728. USE netcdf
  729. IMPLICIT NONE
  730. ! Dummy variables
  731. WRITE(*,*), 'Entering get_dimensions()'
  732. ! 2.A Get dimensions
  733. ! ------------------
  734. ! Open the oce restart file
  735. ierr = nf90_open(TRIM(cfile_analysis_oce),nf90_Write,incid_oce_an_in)
  736. IF (ierr .NE. nf90_noerr ) THEN
  737. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Opening. Abort"
  738. WRITE(*,*), "File :" // TRIM(cfile_analysis_oce)
  739. STOP
  740. END IF
  741. ! Inquire variable id (here the variable does not matter!)
  742. ierr = nf90_inq_varid(incid_oce_an_in, "sn", ivarid)
  743. IF (ierr .NE. nf90_noerr ) THEN
  744. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Variable ID Inquiring. Abort"
  745. WRITE(*,*), "File :"//TRIM(cfile_analysis_oce)
  746. WRITE(*,*), "Variable: sn"
  747. STOP
  748. END IF
  749. ! Inquire variable
  750. ierr = nf90_inquire_variable(incid_oce_an_in, ivarid, dimids=idimid)
  751. IF (ierr .NE. nf90_noerr ) THEN
  752. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Variable Inquiring. Abort"
  753. WRITE(*,*), "File :"//TRIM(cfile_analysis_oce)
  754. WRITE(*,*), "Variable: sn"
  755. STOP
  756. END IF
  757. ! Get dimensions
  758. ierr = nf90_inquire_dimension(incid_oce_an_in, idimid(1), len=jpi)
  759. ierr = nf90_inquire_dimension(incid_oce_an_in, idimid(2), len=jpj)
  760. ierr = nf90_inquire_dimension(incid_oce_an_in, idimid(3), len=jpk)
  761. IF (ierr .NE. nf90_noerr ) THEN
  762. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF dimensions Inquiring. Abort"
  763. WRITE(*,*), "File :"//TRIM(cfile_analysis_oce)
  764. STOP
  765. END IF
  766. WRITE(*,*), "The model horizontal dimensions are" , jpi, "by",jpj
  767. WRITE(*,*), "The model vertical dimension is" , jpk
  768. WRITE(*,*), 'Leaving get_dimensions()'
  769. END SUBROUTINE get_dimensions
  770. SUBROUTINE get_nb_cat()
  771. USE my_variables
  772. USE netcdf
  773. IMPLICIT NONE
  774. ! Dummy variables
  775. INTEGER :: jl
  776. WRITE(*,*) 'Entering get_nb_cat()'
  777. ! Open file
  778. ierr = nf90_open(trim(cfile_analysis_ice),nf90_NoWrite,incid_ice_an_in)
  779. IF (ierr .NE. nf90_noerr ) THEN
  780. WRITE(*,*), "(sanity_check_SI3) Error NetCDF Ice file. Abort"
  781. WRITE(*,*), TRIM(cfile_analysis_ice)
  782. STOP
  783. END IF
  784. ! Get number of ice categories
  785. ! (2024-NEMOv4.2.1-SI3) Categories are now a dimension of variable, changes in consequence (Alison Delhasse)
  786. !cvarroot="a_i_htc"
  787. !jl=1
  788. !WRITE(cinteger,"(i1)") jl
  789. !ierr = nf90_inq_varid(incid_ice_an_in, TRIM(cvarroot)//TRIM(cinteger), ivarid)
  790. !jl=jl+1
  791. !
  792. !DO WHILE (ierr == nf90_noerr)
  793. ! WRITE(cinteger,"(i1)") jl
  794. ! !WRITE(*,*),"Checking existence of " // TRIM(cconcroot)//TRIM(cinteger)
  795. ! ierr = nf90_inq_varid(incid_ice_an_in, TRIM(cvarroot)//TRIM(cinteger), ivarid)
  796. ! jl=jl+1
  797. !ENDDO
  798. !
  799. !jpl=jl-2
  800. !WRITE(*,*), "There are ", jpl, "ice categories"
  801. ! Inquire variable id (here the variable does not matter!)
  802. ierr = nf90_inq_varid(incid_ice_an_in, "a_i", ivarid)
  803. IF (ierr .NE. nf90_noerr ) THEN
  804. WRITE(*,*), "(sanity_check_SI3) Error NetCDF Variable ID Inquiring. Abort"
  805. WRITE(*,*), "File :"//TRIM(cfile_analysis_ice)
  806. WRITE(*,*), "Variable: a_i"
  807. STOP
  808. END IF
  809. ! Inquire variable
  810. ierr = nf90_inquire_variable(incid_ice_an_in, ivarid, dimids=idimid)
  811. IF (ierr .NE. nf90_noerr ) THEN
  812. WRITE(*,*), "(sanity_check_SI3) Error NetCDF Variable Inquiring. Abort"
  813. WRITE(*,*), "File :"//TRIM(cfile_analysis_ice)
  814. WRITE(*,*), "Variable: a_i"
  815. STOP
  816. END IF
  817. ! Get dimensions
  818. ierr = nf90_inquire_dimension(incid_ice_an_in, idimid(3), len=jpl)
  819. !ierr = nf90_inquire_dimension(incid_oce_an_in, idimid(2), len=jpj)
  820. !ierr = nf90_inquire_dimension(incid_oce_an_in, idimid(3), len=jpk)
  821. IF (ierr .NE. nf90_noerr ) THEN
  822. WRITE(*,*), "(sanity_check_SI3) Error NetCDF dimensions Inquiring. Abort"
  823. WRITE(*,*), "File :"//TRIM(cfile_analysis_ice)
  824. STOP
  825. END IF
  826. WRITE(*,*), "There are ", jpl, "ice categories"
  827. ! Close
  828. ierr = nf90_close(incid_ice_an_in);
  829. IF (ierr .NE. nf90_noerr ) THEN
  830. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice close file. Abort"
  831. WRITE(*,*), TRIM(cfile_analysis_ice)
  832. STOP
  833. END IF
  834. WRITE(*,*) 'Leaving get_nb_cat()'
  835. END SUBROUTINE get_nb_cat
  836. SUBROUTINE get_nb_il()
  837. USE my_variables
  838. USE netcdf
  839. IMPLICIT NONE
  840. ! Dummy variables
  841. INTEGER :: jk
  842. WRITE(*,*) 'Entering get_nb_il()'
  843. ! Open file
  844. ierr = nf90_open(trim(cfile_analysis_ice),nf90_NoWrite,incid_ice_an_in)
  845. IF (ierr .NE. nf90_noerr ) THEN
  846. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file. Abort"
  847. WRITE(*,*), TRIM(cfile_analysis_ice)
  848. STOP
  849. END IF
  850. ! Changes in variables names in SI3 (2024) - changes in the subroutines Alison Delhasse
  851. ! cvarroot="tempt_il"
  852. cvarroot="e_i"
  853. jk=1
  854. WRITE(cinteger,"(i1)") jk
  855. ierr = nf90_inq_varid(incid_ice_an_in, TRIM(cvarroot)//'_l0'//TRIM(cinteger), ivarid)
  856. jk=jk+1
  857. DO WHILE (ierr == nf90_noerr)
  858. WRITE(cinteger,"(i1)") jk
  859. ierr = nf90_inq_varid(incid_ice_an_in, TRIM(cvarroot)//'_l0'//TRIM(cinteger), ivarid)
  860. jk=jk+1
  861. ENDDO
  862. nlay_i = jk-2
  863. WRITE(*,*), "There are ", nlay_i, "ice layers"
  864. ! Close
  865. ierr = nf90_close(incid_ice_an_in);
  866. IF (ierr .NE. nf90_noerr ) THEN
  867. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice close file. Abort"
  868. WRITE(*,*), TRIM(cfile_analysis_ice)
  869. STOP
  870. END IF
  871. WRITE(*,*) 'Leaving get_nb_il()'
  872. END SUBROUTINE get_nb_il
  873. SUBROUTINE get_nb_sl()
  874. USE my_variables
  875. USE netcdf
  876. IMPLICIT NONE
  877. ! Dummy variables
  878. INTEGER :: jk
  879. WRITE(*,*) 'Entering get_nb_sl()'
  880. ! Open file
  881. ierr = nf90_open(trim(cfile_analysis_ice),nf90_NoWrite,incid_ice_an_in)
  882. IF (ierr .NE. nf90_noerr ) THEN
  883. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file. Abort"
  884. WRITE(*,*), TRIM(cfile_analysis_ice)
  885. STOP
  886. END IF
  887. ! Changes in variables names in SI3 (2024) - changes in the subroutines Alison Delhasse
  888. cvarroot="e_s"
  889. jk=1
  890. WRITE(cinteger,"(i1)") jk
  891. ierr = nf90_inq_varid(incid_ice_an_in, TRIM(cvarroot)//'_l0'//TRIM(cinteger), ivarid)
  892. jk=jk+1
  893. DO WHILE (ierr == nf90_noerr)
  894. WRITE(cinteger,"(i1)") jk
  895. ierr = nf90_inq_varid(incid_ice_an_in, TRIM(cvarroot)//'_l0'//TRIM(cinteger),ivarid)
  896. jk=jk+1
  897. ENDDO
  898. nlay_s = jk-2
  899. WRITE(*,*), "There are ", nlay_s, "snow layers"
  900. ! Close
  901. ierr = nf90_close(incid_ice_an_in);
  902. IF (ierr .NE. nf90_noerr ) THEN
  903. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice close file. Abort"
  904. WRITE(*,*), TRIM(cfile_analysis_ice)
  905. STOP
  906. END IF
  907. WRITE(*,*) 'Leaving get_nb_sl()'
  908. END SUBROUTINE get_nb_sl
  909. SUBROUTINE allocate_variables()
  910. USE my_variables
  911. IMPLICIT NONE
  912. WRITE(*,*), 'Entering allocate_variables()'
  913. ALLOCATE( ilandmask(jpi, jpj) )
  914. ALLOCATE( a_i( jpi, jpj, jpl) ,&
  915. &v_i( jpi, jpj, jpl) ,&
  916. &v_i_fc( jpi, jpj, jpl) ,&
  917. &v_s( jpi, jpj, jpl) ,&
  918. &v_s_fc( jpi, jpj, jpl) ,&
  919. &oa_i ( jpi, jpj, jpl) ,&
  920. &smv_i( jpi, jpj, jpl) ,&
  921. &t_su( jpi, jpj, jpl) )
  922. ALLOCATE( ht_i( jpi, jpj, jpl) )
  923. ALLOCATE( e_i( jpi, jpj,nlay_i,jpl) )
  924. ALLOCATE( e_s( jpi, jpj,nlay_s,jpl) )
  925. ALLOCATE( sss_m_an( jpi, jpj ) ,&
  926. sss_m_fc( jpi, jpj ) ,&
  927. sst_m_an( jpi, jpj ) ,&
  928. sst_m_fc( jpi, jpj ) )
  929. ALLOCATE( sn_an ( jpi, jpj,jpk ) ,&
  930. sn_fc ( jpi, jpj,jpk ) ,&
  931. tn_an ( jpi, jpj,jpk ) ,&
  932. tn_fc ( jpi, jpj,jpk ) ,&
  933. un_an ( jpi, jpj,jpk ) ,&
  934. un_fc ( jpi, jpj,jpk ) ,&
  935. ub_an ( jpi, jpj,jpk ) ,&
  936. ub_fc ( jpi, jpj,jpk ) ,&
  937. vn_an ( jpi, jpj,jpk ) ,&
  938. vn_fc ( jpi, jpj,jpk ) ,&
  939. vb_an ( jpi, jpj,jpk ) ,&
  940. vb_fc ( jpi, jpj,jpk ) )
  941. ALLOCATE( ssu_m_an( jpi, jpj ) ,&
  942. ssu_m_fc( jpi, jpj ) ,&
  943. ssv_m_an( jpi, jpj ) ,&
  944. ssv_m_fc( jpi, jpj ) )
  945. ALLOCATE( hi_max( jpl) )
  946. ALLOCATE( idonor( jpi, jpj, jpl) )
  947. ALLOCATE( internal_melt(jpi, jpj, jpl) )
  948. ALLOCATE( zdaice( jpi, jpj, jpl) ,&
  949. &zdvice( jpi, jpj, jpl) )
  950. ALLOCATE( ze1t( jpi, jpj ) ,&
  951. &ze2t( jpi, jpj ) ,&
  952. &zcellarea(jpi, jpj ) )
  953. ALLOCATE(zheat_res( jpi, jpj ) ,&
  954. &zdmsnif( jpi, jpj ) )
  955. ALLOCATE(at_i( jpi, jpj ) ,&
  956. snwice_mass(jpi,jpj ) ,&
  957. snwice_mass_b(jpi,jpj ) )
  958. WRITE(*,*) 'Leaving allocate_variables()'
  959. END SUBROUTINE allocate_variables
  960. SUBROUTINE load_variables()
  961. USE my_variables
  962. USE netcdf
  963. IMPLICIT NONE
  964. ! Dummy variables
  965. INTEGER :: jl, jk
  966. WRITE(*,*) 'Entering load_variables()'
  967. ! 3.A Mask
  968. ! --------
  969. ! Open
  970. ierr = nf90_open(TRIM(cmaskfile),nf90_NoWrite,incid_mask)
  971. IF (ierr .NE. nf90_noerr ) THEN
  972. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Mask file. Abort"
  973. WRITE(*,*), TRIM(cmaskfile)
  974. STOP
  975. END IF
  976. ! Request variable ID
  977. ierr = nf90_inq_varid(incid_mask, cmaskvar, ivarid)
  978. IF (ierr .NE. nf90_noerr ) THEN
  979. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Inquire varID . Abort"
  980. WRITE(*,*), TRIM(cmaskfile)
  981. STOP
  982. END IF
  983. ! Get the NetCDF variable and put it in the Fortran variable
  984. ierr = nf90_get_var(incid_mask, ivarid, ilandmask)
  985. IF (ierr .NE. nf90_noerr ) THEN
  986. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF getVar varID . Abort"
  987. WRITE(*,*), TRIM(cmaskfile)
  988. STOP
  989. END IF
  990. ! Close mask file
  991. ierr = nf90_close(incid_mask)
  992. IF (ierr .NE. nf90_noerr ) THEN
  993. WRITE(*,*), "(sanity_check_LIM3) Error Closing NetCDF . Abort"
  994. WRITE(*,*), TRIM(cmaskfile)
  995. STOP
  996. END IF
  997. ! 3.B Mesh file
  998. ! -------------
  999. ! Open
  1000. ierr = nf90_open(TRIM(cmeshfile),nf90_NoWrite,incid_mesh)
  1001. IF (ierr .NE. nf90_noerr ) THEN
  1002. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Mask file. Abort"
  1003. WRITE(*,*), TRIM(cmeshfile)
  1004. STOP
  1005. END IF
  1006. WRITE(*,*), "Mesh loaded"
  1007. ! Request variable ID
  1008. ierr = nf90_inq_varid(incid_mesh, ce1tvar, ivarid)
  1009. IF (ierr .NE. nf90_noerr ) THEN
  1010. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Inquire varID . Abort"
  1011. WRITE(*,*), TRIM(cmeshfile)
  1012. STOP
  1013. END IF
  1014. ! Get the NetCDF variable and put it in the Fortran variable
  1015. ierr = nf90_get_var(incid_mesh, ivarid, ze1t)
  1016. IF (ierr .NE. nf90_noerr ) THEN
  1017. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF getVar varID . Abort"
  1018. WRITE(*,*), TRIM(cmeshfile)
  1019. STOP
  1020. END IF
  1021. ! Repeat for e2t
  1022. ! Request variable ID
  1023. ierr = nf90_inq_varid(incid_mesh, ce2tvar, ivarid)
  1024. IF (ierr .NE. nf90_noerr ) THEN
  1025. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Inquire varID . Abort"
  1026. WRITE(*,*), TRIM(cmeshfile)
  1027. STOP
  1028. END IF
  1029. ! Get the NetCDF variable and put it in the Fortran variable
  1030. ierr = nf90_get_var(incid_mesh, ivarid, ze2t)
  1031. IF (ierr .NE. nf90_noerr ) THEN
  1032. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF getVar varID . Abort"
  1033. WRITE(*,*), TRIM(cmeshfile)
  1034. STOP
  1035. END IF
  1036. ! Close mesh file
  1037. ierr = nf90_close(incid_mesh)
  1038. IF (ierr .NE. nf90_noerr ) THEN
  1039. WRITE(*,*), "(sanity_check_LIM3) Error Closing NetCDF . Abort"
  1040. WRITE(*,*), TRIM(cmeshfile)
  1041. STOP
  1042. END IF
  1043. ! Computing zcellarea
  1044. zcellarea(:,:) = ze1t(:,:) * ze2t(:,:)
  1045. ! 3.C Ocean variables
  1046. ! -------------------
  1047. !
  1048. ! 3.C.1 Open analysis
  1049. ierr = nf90_open(trim(cfile_analysis_oce),nf90_NoWrite,incid_oce_an_in)
  1050. IF (ierr .NE. nf90_noerr ) THEN
  1051. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file. Abort"
  1052. WRITE(*,*), TRIM(cfile_analysis_oce)
  1053. STOP
  1054. END IF
  1055. ! The following lines commented out because SSS does not appear anymore
  1056. ! as restart variable (2020)
  1057. !! 3.C.1.A Sea surface salinity
  1058. !! Request variable ID
  1059. !ierr = nf90_inq_varid(incid_oce_an_in, csss_m, ivarid)
  1060. !IF (ierr .NE. nf90_noerr ) THEN
  1061. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1062. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1063. ! STOP
  1064. !END IF
  1065. !
  1066. !! Get variable
  1067. !ierr = nf90_get_var(incid_oce_an_in, ivarid, sss_m_an)
  1068. !IF (ierr .NE. nf90_noerr ) THEN
  1069. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1070. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1071. ! STOP
  1072. !END IF
  1073. !
  1074. ! 3.C.1.B Salinity
  1075. ! Request variable ID
  1076. ierr = nf90_inq_varid(incid_oce_an_in, csn, ivarid)
  1077. IF (ierr .NE. nf90_noerr ) THEN
  1078. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1079. WRITE(*,*), TRIM(cfile_analysis_oce)
  1080. STOP
  1081. END IF
  1082. ! Get variable
  1083. ierr = nf90_get_var(incid_oce_an_in, ivarid, sn_an)
  1084. IF (ierr .NE. nf90_noerr ) THEN
  1085. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1086. WRITE(*,*), TRIM(cfile_analysis_oce)
  1087. STOP
  1088. END IF
  1089. ! The following lines commented out because SST does not longer
  1090. ! appear as restart file (2020)
  1091. !! 3.C.1.C Sea surface temperature
  1092. !! Request variable ID
  1093. !ierr = nf90_inq_varid(incid_oce_an_in, csst_m, ivarid)
  1094. !IF (ierr .NE. nf90_noerr ) THEN
  1095. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1096. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1097. ! STOP
  1098. !END IF
  1099. !
  1100. !! Get variable
  1101. !ierr = nf90_get_var(incid_oce_an_in, ivarid, sst_m_an)
  1102. !IF (ierr .NE. nf90_noerr ) THEN
  1103. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1104. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1105. ! STOP
  1106. !END IF
  1107. ! 3.C.1.D. Temperature
  1108. ierr = nf90_inq_varid(incid_oce_an_in, ctn, ivarid)
  1109. IF (ierr .NE. nf90_noerr ) THEN
  1110. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1111. WRITE(*,*), TRIM(cfile_analysis_oce)
  1112. STOP
  1113. END IF
  1114. ! Get variable
  1115. ierr = nf90_get_var(incid_oce_an_in, ivarid, tn_an)
  1116. IF (ierr .NE. nf90_noerr ) THEN
  1117. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1118. WRITE(*,*), TRIM(cfile_analysis_oce)
  1119. STOP
  1120. END IF
  1121. ! 3.C.1.E U-velocity ("un")
  1122. ierr = nf90_inq_varid(incid_oce_an_in, cun, ivarid)
  1123. IF (ierr .NE. nf90_noerr ) THEN
  1124. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1125. WRITE(*,*), TRIM(cfile_analysis_oce)
  1126. STOP
  1127. END IF
  1128. ! Get variable
  1129. ierr = nf90_get_var(incid_oce_an_in, ivarid, un_an)
  1130. IF (ierr .NE. nf90_noerr ) THEN
  1131. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1132. WRITE(*,*), TRIM(cfile_analysis_oce)
  1133. STOP
  1134. END IF
  1135. ! 3.C.1.F U-velocity ("ub")
  1136. ierr = nf90_inq_varid(incid_oce_an_in, cub, ivarid)
  1137. IF (ierr .NE. nf90_noerr ) THEN
  1138. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1139. WRITE(*,*), TRIM(cfile_analysis_oce)
  1140. STOP
  1141. END IF
  1142. ! Get variable
  1143. ierr = nf90_get_var(incid_oce_an_in, ivarid, ub_an)
  1144. IF (ierr .NE. nf90_noerr ) THEN
  1145. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1146. WRITE(*,*), TRIM(cfile_analysis_oce)
  1147. STOP
  1148. END IF
  1149. ! 3.C.1.G V-velocity ("vn")
  1150. ierr = nf90_inq_varid(incid_oce_an_in, cvn, ivarid)
  1151. IF (ierr .NE. nf90_noerr ) THEN
  1152. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1153. WRITE(*,*), TRIM(cfile_analysis_oce)
  1154. STOP
  1155. END IF
  1156. ! Get variable
  1157. ierr = nf90_get_var(incid_oce_an_in, ivarid, vn_an)
  1158. IF (ierr .NE. nf90_noerr ) THEN
  1159. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1160. WRITE(*,*), TRIM(cfile_analysis_oce)
  1161. STOP
  1162. END IF
  1163. ! 3.C.1.H V-velocity ("vb")
  1164. ierr = nf90_inq_varid(incid_oce_an_in, cvb, ivarid)
  1165. IF (ierr .NE. nf90_noerr ) THEN
  1166. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1167. WRITE(*,*), TRIM(cfile_analysis_oce)
  1168. STOP
  1169. END IF
  1170. ! Get variable
  1171. ierr = nf90_get_var(incid_oce_an_in, ivarid, vb_an)
  1172. IF (ierr .NE. nf90_noerr ) THEN
  1173. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1174. WRITE(*,*), TRIM(cfile_analysis_oce)
  1175. STOP
  1176. END IF
  1177. ! The following lines commented out because surface velocities no longer
  1178. ! appear as restart variables (2020)
  1179. !! 3.C.1.I SSU-velocity ("ssu_m")
  1180. !ierr = nf90_inq_varid(incid_oce_an_in, cssu_m, ivarid)
  1181. !IF (ierr .NE. nf90_noerr ) THEN
  1182. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1183. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1184. ! STOP
  1185. !END IF
  1186. !
  1187. !! Get variable
  1188. !ierr = nf90_get_var(incid_oce_an_in, ivarid, ssu_m_an)
  1189. !IF (ierr .NE. nf90_noerr ) THEN
  1190. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1191. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1192. ! STOP
  1193. !END IF
  1194. !
  1195. !! 3.C.1.J SSV-velocity ("ssv_m")
  1196. !ierr = nf90_inq_varid(incid_oce_an_in, cssv_m, ivarid)
  1197. !IF (ierr .NE. nf90_noerr ) THEN
  1198. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1199. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1200. ! STOP
  1201. !END IF
  1202. !
  1203. !! Get variable
  1204. !ierr = nf90_get_var(incid_oce_an_in, ivarid, ssv_m_an)
  1205. !IF (ierr .NE. nf90_noerr ) THEN
  1206. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1207. ! WRITE(*,*), TRIM(cfile_analysis_oce)
  1208. ! STOP
  1209. !END IF
  1210. ! Close analysis
  1211. ierr = nf90_close(incid_oce_an_in);
  1212. IF (ierr .NE. nf90_noerr ) THEN
  1213. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean close file. Abort"
  1214. WRITE(*,*), TRIM(cfile_analysis_oce)
  1215. STOP
  1216. END IF
  1217. ! 3.C.2. Open forecast
  1218. ierr = nf90_open(trim(cfile_forecast_oce),nf90_NoWrite,incid_oce_fc_in)
  1219. IF (ierr .NE. nf90_noerr ) THEN
  1220. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file. Abort"
  1221. WRITE(*,*), TRIM(cfile_forecast_oce)
  1222. STOP
  1223. END IF
  1224. ! Following lines commented out as the variable no longer appears
  1225. ! in the restart files (2020
  1226. !! 3.C.2.A Sea surface salinity
  1227. !! Request variable ID
  1228. !ierr = nf90_inq_varid(incid_oce_fc_in, csss_m, ivarid)
  1229. !IF (ierr .NE. nf90_noerr ) THEN
  1230. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1231. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1232. ! STOP
  1233. !END IF
  1234. !
  1235. !! Get variable
  1236. !ierr = nf90_get_var(incid_oce_fc_in, ivarid, sss_m_fc)
  1237. !IF (ierr .NE. nf90_noerr ) THEN
  1238. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1239. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1240. ! STOP
  1241. !END IF
  1242. ! 3.C.2.B. Salinity
  1243. ! Request variable ID
  1244. ierr = nf90_inq_varid(incid_oce_fc_in, csn, ivarid)
  1245. IF (ierr .NE. nf90_noerr ) THEN
  1246. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1247. WRITE(*,*), TRIM(cfile_forecast_oce)
  1248. STOP
  1249. END IF
  1250. ! Get variable
  1251. ierr = nf90_get_var(incid_oce_fc_in, ivarid, sn_fc)
  1252. IF (ierr .NE. nf90_noerr ) THEN
  1253. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1254. WRITE(*,*), TRIM(cfile_forecast_oce)
  1255. STOP
  1256. END IF
  1257. ! Following lines commented out as the variable no longer appears
  1258. ! in the restart files (2020)
  1259. !! 3.C.2.C Sea surface temperature
  1260. !! Request variable ID
  1261. !ierr = nf90_inq_varid(incid_oce_fc_in, csst_m, ivarid)
  1262. !IF (ierr .NE. nf90_noerr ) THEN
  1263. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1264. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1265. ! STOP
  1266. !END IF
  1267. !
  1268. !! Get variable
  1269. !ierr = nf90_get_var(incid_oce_fc_in, ivarid, sst_m_fc)
  1270. !IF (ierr .NE. nf90_noerr ) THEN
  1271. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1272. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1273. ! STOP
  1274. !END IF
  1275. ! 3.C.2.D. Temperature
  1276. ! Request variable ID
  1277. ierr = nf90_inq_varid(incid_oce_fc_in, ctn, ivarid)
  1278. IF (ierr .NE. nf90_noerr ) THEN
  1279. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1280. WRITE(*,*), TRIM(cfile_forecast_oce)
  1281. STOP
  1282. END IF
  1283. ! Get variable
  1284. ierr = nf90_get_var(incid_oce_fc_in, ivarid, tn_fc)
  1285. IF (ierr .NE. nf90_noerr ) THEN
  1286. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1287. WRITE(*,*), TRIM(cfile_forecast_oce)
  1288. STOP
  1289. END IF
  1290. ! 3.C.2.E U-velocity ("un")
  1291. ierr = nf90_inq_varid(incid_oce_fc_in, cun, ivarid)
  1292. IF (ierr .NE. nf90_noerr ) THEN
  1293. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1294. WRITE(*,*), TRIM(cfile_forecast_oce)
  1295. STOP
  1296. END IF
  1297. ! Get variable
  1298. ierr = nf90_get_var(incid_oce_fc_in, ivarid, un_fc)
  1299. IF (ierr .NE. nf90_noerr ) THEN
  1300. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1301. WRITE(*,*), TRIM(cfile_forecast_oce)
  1302. STOP
  1303. END IF
  1304. ! 3.C.2.F U-velocity ("ub")
  1305. ierr = nf90_inq_varid(incid_oce_fc_in, cub, ivarid)
  1306. IF (ierr .NE. nf90_noerr ) THEN
  1307. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1308. WRITE(*,*), TRIM(cfile_forecast_oce)
  1309. STOP
  1310. END IF
  1311. ! Get variable
  1312. ierr = nf90_get_var(incid_oce_fc_in, ivarid, ub_fc)
  1313. IF (ierr .NE. nf90_noerr ) THEN
  1314. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1315. WRITE(*,*), TRIM(cfile_forecast_oce)
  1316. STOP
  1317. END IF
  1318. ! 3.C.2.G V-velocity ("vn")
  1319. ierr = nf90_inq_varid(incid_oce_fc_in, cvn, ivarid)
  1320. IF (ierr .NE. nf90_noerr ) THEN
  1321. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1322. WRITE(*,*), TRIM(cfile_forecast_oce)
  1323. STOP
  1324. END IF
  1325. ! Get variable
  1326. ierr = nf90_get_var(incid_oce_fc_in, ivarid, vn_fc)
  1327. IF (ierr .NE. nf90_noerr ) THEN
  1328. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1329. WRITE(*,*), TRIM(cfile_forecast_oce)
  1330. STOP
  1331. END IF
  1332. ! 3.C.2.H V-velocity ("vb")
  1333. ierr = nf90_inq_varid(incid_oce_fc_in, cvb, ivarid)
  1334. IF (ierr .NE. nf90_noerr ) THEN
  1335. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1336. WRITE(*,*), TRIM(cfile_forecast_oce)
  1337. STOP
  1338. END IF
  1339. ! Get variable
  1340. ierr = nf90_get_var(incid_oce_fc_in, ivarid, vb_fc)
  1341. IF (ierr .NE. nf90_noerr ) THEN
  1342. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1343. WRITE(*,*), TRIM(cfile_forecast_oce)
  1344. STOP
  1345. END IF
  1346. ! Following lines commented out as the variable no longer appears
  1347. ! in the restart files (2020)
  1348. !! 3.C.2.I SSU-velocity ("ssu_m")
  1349. !ierr = nf90_inq_varid(incid_oce_fc_in, cssu_m, ivarid)
  1350. !IF (ierr .NE. nf90_noerr ) THEN
  1351. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1352. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1353. ! STOP
  1354. !END IF
  1355. !
  1356. !! Get variable
  1357. !ierr = nf90_get_var(incid_oce_fc_in, ivarid, ssu_m_fc)
  1358. !IF (ierr .NE. nf90_noerr ) THEN
  1359. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1360. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1361. ! STOP
  1362. !END IF
  1363. !! 3.C.2.J SSV-velocity ("ssv_m")
  1364. !ierr = nf90_inq_varid(incid_oce_fc_in, cssv_m, ivarid)
  1365. !IF (ierr .NE. nf90_noerr ) THEN
  1366. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file var. inquiry. Abort"
  1367. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1368. ! STOP
  1369. !END IF
  1370. !
  1371. ! Get variable
  1372. !ierr = nf90_get_var(incid_oce_fc_in, ivarid, ssv_m_fc)
  1373. !IF (ierr .NE. nf90_noerr ) THEN
  1374. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file get. Abort"
  1375. ! WRITE(*,*), TRIM(cfile_forecast_oce)
  1376. ! STOP
  1377. !END IF
  1378. ! Close forecast
  1379. ierr = nf90_close(incid_oce_fc_in);
  1380. IF (ierr .NE. nf90_noerr ) THEN
  1381. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean close file. Abort"
  1382. WRITE(*,*), TRIM(cfile_forecast_oce)
  1383. STOP
  1384. END IF
  1385. WRITE(*,*), "Ocean variables loaded"
  1386. ! 3.D Ice variables
  1387. ! -----------------
  1388. !#################!
  1389. !# Open forecast #
  1390. !#################!
  1391. ierr = nf90_open(trim(cfile_forecast_ice),nf90_NoWrite,incid_ice_fc_in)
  1392. IF (ierr .NE. nf90_noerr ) THEN
  1393. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file. Abort"
  1394. WRITE(*,*), TRIM(cfile_forecast_ice)
  1395. STOP
  1396. END IF
  1397. ! (2024) ice category is now a dimension of the variables. No need to loop with the cat index to load variables.
  1398. !DO jl = 1 , jpl
  1399. ! Read ice volume forecast
  1400. cvarroot='v_i'
  1401. cvarname = TRIM(cvarroot)
  1402. ! Inquire variable ID
  1403. ierr = nf90_inq_varid(incid_ice_fc_in, cvarname, ivarid)
  1404. IF (ierr .NE. nf90_noerr ) THEN
  1405. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1406. WRITE(*,*), TRIM(cfile_forecast_ice)
  1407. WRITE(*,*), cvarname
  1408. STOP
  1409. END IF
  1410. ! Read variable
  1411. ierr = nf90_get_var(incid_ice_fc_in, ivarid, v_i_fc)
  1412. IF (ierr .NE. nf90_noerr ) THEN
  1413. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1414. WRITE(*,*), TRIM(cfile_forecast_ice)
  1415. WRITE(*,*), cvarname
  1416. STOP
  1417. END IF
  1418. ! Read snow volume forecast
  1419. cvarroot='v_s'
  1420. cvarname = TRIM(cvarroot)
  1421. ! Inquire variable ID
  1422. ierr = nf90_inq_varid(incid_ice_fc_in, cvarname, ivarid)
  1423. IF (ierr .NE. nf90_noerr ) THEN
  1424. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1425. WRITE(*,*), TRIM(cfile_forecast_ice)
  1426. WRITE(*,*), cvarname
  1427. STOP
  1428. END IF
  1429. ! Read variable
  1430. ierr = nf90_get_var(incid_ice_fc_in, ivarid, v_s_fc)
  1431. IF (ierr .NE. nf90_noerr ) THEN
  1432. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1433. WRITE(*,*), TRIM(cfile_forecast_ice)
  1434. WRITE(*,*), cvarname
  1435. STOP
  1436. END IF
  1437. !END DO ! jl
  1438. ! Close forecast
  1439. ierr = nf90_close(incid_ice_fc_in);
  1440. IF (ierr .NE. nf90_noerr ) THEN
  1441. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice close file. Abort"
  1442. WRITE(*,*), TRIM(cfile_forecast_ice)
  1443. STOP
  1444. END IF
  1445. WRITE(*,*), "Ice forecast variables loaded"
  1446. !!!!---------------------------------------------------------------------!!!
  1447. !#################!
  1448. !# Open analysis #!
  1449. !#################!
  1450. ierr = nf90_open(trim(cfile_analysis_ice),nf90_NoWrite,incid_ice_an_in)
  1451. IF (ierr .NE. nf90_noerr ) THEN
  1452. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file. Abort"
  1453. WRITE(*,*), TRIM(cfile_analysis_ice)
  1454. STOP
  1455. END IF
  1456. ! Time counter
  1457. ! Request variable id
  1458. cvarname = 'time_counter'
  1459. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1460. IF (ierr .NE. nf90_noerr ) THEN
  1461. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1462. WRITE(*,*), TRIM(cfile_analysis_ice)
  1463. WRITE(*,*), cvarname
  1464. STOP
  1465. END IF
  1466. ! Get variable
  1467. ierr = nf90_get_var(incid_ice_an_in, ivarid, ztime_counter )
  1468. IF (ierr .NE. nf90_noerr ) THEN
  1469. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1470. WRITE(*,*), TRIM(cfile_analysis_ice)
  1471. WRITE(*,*), cvarname
  1472. STOP
  1473. END IF
  1474. ! Strategy: Loop over categories, and for specific variables over layers
  1475. ! (2024) Categories as dim now!
  1476. !DO jl = 1 , jpl
  1477. ! 3.D.1. Ice concentration
  1478. cvarroot='a_i'
  1479. cvarname = TRIM(cvarroot)
  1480. ! WRITE(*,*), "Working with variable " // cvarname
  1481. ! Request variable ID
  1482. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1483. IF (ierr .NE. nf90_noerr ) THEN
  1484. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1485. WRITE(*,*), TRIM(cfile_analysis_ice)
  1486. WRITE(*,*), cvarname
  1487. STOP
  1488. END IF
  1489. ! Get variable
  1490. ierr = nf90_get_var(incid_ice_an_in, ivarid, a_i)
  1491. IF (ierr .NE. nf90_noerr ) THEN
  1492. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1493. WRITE(*,*), TRIM(cfile_analysis_ice)
  1494. WRITE(*,*), cvarname
  1495. STOP
  1496. END IF
  1497. ! 3.D.2. Ice volume per surface area
  1498. cvarroot='v_i'
  1499. cvarname = TRIM(cvarroot)
  1500. ! WRITE(*,*), "Working with variable " // cvarname
  1501. ! Request variable ID
  1502. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1503. IF (ierr .NE. nf90_noerr ) THEN
  1504. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1505. WRITE(*,*), TRIM(cfile_analysis_ice)
  1506. WRITE(*,*), cvarname
  1507. STOP
  1508. END IF
  1509. ! Get variable
  1510. ierr = nf90_get_var(incid_ice_an_in, ivarid, v_i)
  1511. IF (ierr .NE. nf90_noerr ) THEN
  1512. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1513. WRITE(*,*), TRIM(cfile_analysis_ice)
  1514. WRITE(*,*), cvarname
  1515. STOP
  1516. END IF
  1517. ! 3.D.3. Snow volume per surface area
  1518. cvarroot='v_s'
  1519. cvarname = TRIM(cvarroot)
  1520. WRITE(*,*), "Working with variable " // cvarname
  1521. ! Request variable ID
  1522. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1523. IF (ierr .NE. nf90_noerr ) THEN
  1524. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1525. WRITE(*,*), TRIM(cfile_analysis_ice)
  1526. WRITE(*,*), cvarname
  1527. STOP
  1528. END IF
  1529. ! Get variable
  1530. ierr = nf90_get_var(incid_ice_an_in, ivarid, v_s)
  1531. IF (ierr .NE. nf90_noerr ) THEN
  1532. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1533. WRITE(*,*), TRIM(cfile_analysis_ice)
  1534. WRITE(*,*), cvarname
  1535. STOP
  1536. END IF
  1537. ! 3.D.4. Ice age
  1538. cvarroot='oa_i'
  1539. cvarname = TRIM(cvarroot)
  1540. ! WRITE(*,*), "Working with variable " // cvarname
  1541. ! Request variable ID
  1542. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1543. IF (ierr .NE. nf90_noerr ) THEN
  1544. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1545. WRITE(*,*), TRIM(cfile_analysis_ice)
  1546. WRITE(*,*), cvarname
  1547. STOP
  1548. END IF
  1549. ! Get variable
  1550. ierr = nf90_get_var(incid_ice_an_in, ivarid, oa_i)
  1551. IF (ierr .NE. nf90_noerr ) THEN
  1552. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1553. WRITE(*,*), TRIM(cfile_analysis_ice)
  1554. WRITE(*,*), cvarname
  1555. STOP
  1556. END IF
  1557. ! 3.D.5. Ice salinity
  1558. cvarroot='sv_i'
  1559. cvarname = TRIM(cvarroot)
  1560. ! WRITE(*,*), "Working with variable " // cvarname
  1561. ! Request variable ID
  1562. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1563. IF (ierr .NE. nf90_noerr ) THEN
  1564. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1565. WRITE(*,*), TRIM(cfile_analysis_ice)
  1566. WRITE(*,*), cvarname
  1567. STOP
  1568. END IF
  1569. ! Get variable
  1570. ierr = nf90_get_var(incid_ice_an_in, ivarid, smv_i)
  1571. IF (ierr .NE. nf90_noerr ) THEN
  1572. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1573. WRITE(*,*), TRIM(cfile_analysis_ice)
  1574. WRITE(*,*), cvarname
  1575. STOP
  1576. END IF
  1577. ! 3.D.5. Ice surface temperature
  1578. !cvarroot='t_su_htc'
  1579. !WRITE(cinteger,'(i1)') jl
  1580. !cvarname = TRIM(cvarroot) // TRIM(cinteger)
  1581. ! ! WRITE(*,*), "Working with variable " // cvarname
  1582. !! Request variable ID
  1583. !ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1584. !IF (ierr .NE. nf90_noerr ) THEN
  1585. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1586. ! WRITE(*,*), TRIM(cfile_analysis_ice)
  1587. ! WRITE(*,*), cvarname
  1588. ! STOP
  1589. !END IF
  1590. !! Get variable
  1591. !ierr = nf90_get_var(incid_ice_an_in, ivarid, t_su(:,:,jl) )
  1592. !IF (ierr .NE. nf90_noerr ) THEN
  1593. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1594. ! WRITE(*,*), TRIM(cfile_analysis_ice)
  1595. ! WRITE(*,*), cvarname
  1596. ! STOP
  1597. !END IF
  1598. cvarroot='t_su'
  1599. cvarname = TRIM(cvarroot)
  1600. WRITE(*,*), "Working with variable " // cvarname
  1601. ! Request variable ID
  1602. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1603. IF (ierr .NE. nf90_noerr ) THEN
  1604. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1605. WRITE(*,*), TRIM(cfile_analysis_ice)
  1606. WRITE(*,*), cvarname
  1607. STOP
  1608. END IF
  1609. ! Get variable
  1610. ierr = nf90_get_var(incid_ice_an_in, ivarid, t_su)
  1611. IF (ierr .NE. nf90_noerr ) THEN
  1612. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1613. WRITE(*,*), TRIM(cfile_analysis_ice)
  1614. WRITE(*,*), cvarname
  1615. STOP
  1616. END IF
  1617. ! 3.D.X Variables that are defined on several ice layers
  1618. DO jk = 1 , nlay_i
  1619. ! Ice enthalpy in layers
  1620. cvarroot='e_i_l0'
  1621. WRITE(cinteger2,'(i1)') jk
  1622. cvarname = TRIM(cvarroot)//TRIM(cinteger2)
  1623. ! WRITE(*,*),"Working with variable " // cvarname
  1624. ! Request variable ID
  1625. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1626. IF (ierr .NE. nf90_noerr ) THEN
  1627. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1628. WRITE(*,*), TRIM(cfile_analysis_ice)
  1629. WRITE(*,*), cvarname
  1630. STOP
  1631. END IF
  1632. ! Get variable
  1633. ierr = nf90_get_var(incid_ice_an_in, ivarid, e_i(:,:,jk,:) )
  1634. IF (ierr .NE. nf90_noerr ) THEN
  1635. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1636. WRITE(*,*), TRIM(cfile_analysis_ice)
  1637. WRITE(*,*), cvarname
  1638. STOP
  1639. END IF
  1640. ENDDO ! jk, layers
  1641. DO jk = 1 , nlay_s
  1642. ! Snow enthalpy in layers
  1643. cvarroot='e_s_l0'
  1644. WRITE(cinteger2,'(i1)') jk
  1645. cvarname = TRIM(cvarroot)// TRIM(cinteger2)
  1646. ! WRITE(*,*),"Working with variable " // cvarname
  1647. ! Request variable ID
  1648. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1649. IF (ierr .NE. nf90_noerr ) THEN
  1650. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1651. WRITE(*,*), TRIM(cfile_analysis_ice)
  1652. WRITE(*,*), cvarname
  1653. STOP
  1654. END IF
  1655. ! Get variable
  1656. ierr = nf90_get_var(incid_ice_an_in, ivarid, e_s(:,:,jk,:) )
  1657. IF (ierr .NE. nf90_noerr ) THEN
  1658. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1659. WRITE(*,*), TRIM(cfile_analysis_ice)
  1660. WRITE(*,*), cvarname
  1661. STOP
  1662. END IF
  1663. ENDDO ! jk, layers
  1664. !ENDDO ! jl, categories
  1665. ! Load data that don't depend on categories
  1666. WRITE(*,*), "Ice analyse 3-D variables loaded (category and layers)"
  1667. ! Snow ice mass
  1668. cvarname = 'snwice_mass'
  1669. ! Request variable ID
  1670. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1671. IF (ierr .NE. nf90_noerr ) THEN
  1672. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1673. WRITE(*,*), TRIM(cfile_analysis_ice)
  1674. WRITE(*,*), cvarname
  1675. STOP
  1676. END IF
  1677. ! Get variable
  1678. ierr = nf90_get_var(incid_ice_an_in, ivarid, snwice_mass(:,:) )
  1679. IF (ierr .NE. nf90_noerr ) THEN
  1680. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1681. WRITE(*,*), TRIM(cfile_analysis_ice)
  1682. WRITE(*,*), cvarname
  1683. STOP
  1684. END IF
  1685. ! Snow ice mass_b
  1686. cvarname = 'snwice_mass_b'
  1687. ! Request variable ID
  1688. ierr = nf90_inq_varid(incid_ice_an_in, cvarname, ivarid)
  1689. IF (ierr .NE. nf90_noerr ) THEN
  1690. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file var. inquiry. Abort"
  1691. WRITE(*,*), TRIM(cfile_analysis_ice)
  1692. WRITE(*,*), cvarname
  1693. STOP
  1694. END IF
  1695. ! Get variable
  1696. ierr = nf90_get_var(incid_ice_an_in, ivarid, snwice_mass_b(:,:) )
  1697. IF (ierr .NE. nf90_noerr ) THEN
  1698. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice file get. Abort"
  1699. WRITE(*,*), TRIM(cfile_analysis_ice)
  1700. WRITE(*,*), cvarname
  1701. STOP
  1702. END IF
  1703. ! Close ice analysis file
  1704. ierr = nf90_close(incid_ice_an_in);
  1705. IF (ierr .NE. nf90_noerr ) THEN
  1706. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ice close file. Abort"
  1707. WRITE(*,*), TRIM(cfile_analysis_ice)
  1708. STOP
  1709. END IF
  1710. WRITE(*,*), "Ice forecast without category dim variables loaded"
  1711. WRITE(*,*) 'Leaving load_variables'
  1712. END SUBROUTINE load_variables
  1713. SUBROUTINE several_ice_corrections()
  1714. USE my_variables
  1715. IMPLICIT NONE
  1716. ! Dummy variables
  1717. INTEGER :: ji, jj, jl, jk
  1718. WRITE(*,*), 'Entering several_ice_corrections()'
  1719. DO ji = 1 , jpi
  1720. DO jj = 1 , jpj
  1721. DO jl = 1 , jpl
  1722. ! Define switches (masks)
  1723. !zindb = MAX( rzero , SIGN( zamax , a_i(ji,jj,jl) - epsi06) )
  1724. !zindsn = MAX(rzero , SIGN( zamax , v_s(ji,jj,jl) - epsi06) )
  1725. !zindic = MAX(rzero , SIGN( zamax , v_i(ji,jj,jl) - epsi04) )
  1726. zindb = MAX( rzero , SIGN( rone , a_i(ji,jj,jl) - epsi06) )
  1727. zindsn = MAX(rzero , SIGN( rone , v_s(ji,jj,jl) - epsi06) )
  1728. zindic = MAX(rzero , SIGN( rone , v_i(ji,jj,jl) - epsi04) )
  1729. zindb = zindb * zindic ! Mask where there is conc. AND volume
  1730. ! A. Corrections to ice age
  1731. ![AD] test without modifing age, so analysis = forecast
  1732. !IF ( ( oa_i(ji,jj,jl) - rone ) * 86400.0 .GT. ( rdt_ice*ztime_counter*a_i(ji,jj,jl) ) )&
  1733. !&THEN
  1734. !WRITE(*,*) 'Correction on ice age'
  1735. ! oa_i(ji,jj,jl) = rdt_ice * ztime_counter / 86400.0 * a_i(ji,jj,jl)
  1736. !END IF
  1737. !oa_i(ji,jj,jl) = zindb*oa_i(ji,jj,jl)
  1738. ! B. Corrections to snow thickness
  1739. v_s(ji,jj,jl) = zindsn*zindb*v_s(ji,jj,jl)
  1740. ! C. Corrections to ice thickness
  1741. v_i(ji,jj,jl) = MAX( zindb * v_i(ji,jj,jl) , rzero )
  1742. v_i(ji,jj,jl) = zindic*v_i(ji,jj,jl)
  1743. ! D. Snow transformed to ice if original ice cover disappears
  1744. zindg = REAL(ilandmask(ji,jj) ) * MAX (rzero, SIGN( rone , - v_i (ji,jj,jl) ) )
  1745. ! (is it possible to have zindg not zero??)
  1746. v_i(ji,jj,jl) = v_i(ji,jj,jl) + zindg * zrhosn * v_s(ji,jj,jl) / zrho0
  1747. ! The last term of the above equation is the water volume equivalent to the snow
  1748. ! volume I guess
  1749. v_s(ji,jj,jl) = (rone - zindg ) * v_s(ji,jj,jl) + &
  1750. & zindg * v_i(ji,jj,jl) * (zrho0 - zrhoic ) / zrhosn
  1751. ! E. Correction to ice concentration
  1752. a_i(ji,jj,jl) = zindb * MAX(zindsn, zindic) * MAX(a_i(ji,jj,jl), epsi06)
  1753. ! F. Correction to snow heat contenti
  1754. ![AD] Add loop on layer also for e_s to test!
  1755. IF ( ldebug .AND. ( ji == jiindx ) .AND. ( jj == jjindx ) ) THEN
  1756. WRITE(*,*) 'Before i=307 j=307 e_s_l01:' , e_s(ji,jj,1,jl)
  1757. END IF
  1758. DO jk = 1 , nlay_s
  1759. e_s(ji,jj,jk,jl) = zindsn * &
  1760. & ( MIN ( MAX ( rzero, e_s(ji,jj,jk,jl) ), zbigvalue ) ) + &
  1761. & ( rone - zindsn ) * rzero
  1762. END DO
  1763. IF ( ldebug .AND. ( ji == jiindx ) .AND. ( jj == jjindx ) ) THEN
  1764. WRITE(*,*) 'After i=307 j=307 e_s_l010:' , e_s(ji,jj,1,jl)
  1765. END IF
  1766. ! G. Correction to ice heat content
  1767. DO jk = 1 , nlay_i
  1768. e_i(ji,jj,jk,jl) = zindic * &
  1769. &( MIN( MAX( rzero, e_i(ji,jj,jk,jl) ), zbigvalue ) ) &
  1770. & + (rone - zindic ) * rzero
  1771. END DO ! nlay_i
  1772. ! H. Correction to ice salinity
  1773. IF ( (num_sal .EQ. 2) .OR. (num_sal .EQ. 4) ) THEN
  1774. ! If we are in salinity profile mode
  1775. ! Salinity stays in bounds
  1776. smv_i(ji,jj,jl) = MAX( MIN( (zrhoic-zrhosn)/zrhoic * &
  1777. & sss_m_an(ji,jj) , smv_i(ji,jj,jl) ) , &
  1778. 0.1 * v_i(ji,jj,jl) )
  1779. ENDIF
  1780. ! I. Thickness of first category above 5cm
  1781. IF ( jl == 1) THEN
  1782. ht_i(ji,jj,jl) = zindb * v_i(ji,jj,jl) / MAX(a_i(ji,jj,jl),epsi06)
  1783. zh = MAX(rone , zindb*zhiclim/ &
  1784. & MAX(ht_i(ji,jj,jl),epsi20 ) )
  1785. ! This is a correction factor equal to zhiclim/h_insitu, i.e. the ratio
  1786. ! between minimal and actual in situ thickness.
  1787. ! Something to do for the snow
  1788. ! The ice concentration is shrunk so that the ice thickness is at least
  1789. ! zhiclim
  1790. a_i(ji,jj,jl) = a_i(ji,jj,jl) / zh
  1791. END IF
  1792. END DO ! jl
  1793. ! Reset snowice to zero if necessary
  1794. IF ( (snwice_mass(ji,jj) .LT. rzero) .OR. (snwice_mass_b(ji,jj) .LT. rzero) ) THEN
  1795. snwice_mass(ji,jj) = rzero
  1796. snwice_mass_b(ji,jj)=rzero
  1797. END IF
  1798. END DO ! jj
  1799. END DO ! ji
  1800. WRITE(*,*), 'Leaving several_ice_corrections()'
  1801. END SUBROUTINE several_ice_corrections
  1802. SUBROUTINE shrink_ice()
  1803. USE my_variables
  1804. IMPLICIT NONE
  1805. ! Dummy variables
  1806. INTEGER :: ji, jj, jl
  1807. WRITE(*,*), 'Entering shrink_ice()'
  1808. ! Total concentration cannot exceed zamax
  1809. at_i(:,:) = rzero
  1810. DO jl = 1 , jpl
  1811. at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
  1812. END DO
  1813. DO ji = 1 , jpi
  1814. DO jj = 1 , jpj
  1815. ! Define the excessive concentration
  1816. zda_ex = MAX( at_i(ji,jj) - zamax , rzero )
  1817. ! (i.e. rzero, except if excess)
  1818. DO jl = 1 , jpl
  1819. zindb = MAX( rzero , SIGN( rone , v_i(ji,jj,jl) ) )
  1820. ! (zindb is a mask)
  1821. ! Spread the excess over the different categories with weight equal
  1822. ! to concentration in each of them
  1823. zda_i = a_i(ji,jj,jl) * zda_ex / MAX(at_i(ji,jj),epsi06) * zindb
  1824. ! Correction of limupdate after Antoine Barthélemy
  1825. ! Indeed the volume should not be changed.
  1826. !! zdv_i = v_i(ji,jj,jl) * zda_i / MAX(at_i(ji,jj),epsi06)
  1827. ! We take out the excess of ice and put it as volume
  1828. a_i(ji,jj,jl) = a_i(ji,jj,jl) - zda_i
  1829. !! v_i(ji,jj,jl) = v_i(ji,jj,jl) + zdv_i
  1830. END DO
  1831. END DO
  1832. END DO
  1833. WRITE(*,*), 'Leaving shrink_ice()'
  1834. END SUBROUTINE shrink_ice
  1835. SUBROUTINE record_ice()
  1836. USE my_variables
  1837. USE netcdf
  1838. IMPLICIT NONE
  1839. ! Dummy variables
  1840. INTEGER :: jl, jk
  1841. WRITE(*,*) 'Entering record_ice()'
  1842. WRITE(*,*) 'Recording the NetCDF'
  1843. ! 8.1 Record ice variables
  1844. ! We copy the input file and store everything into this copy
  1845. CALL system('cp -f '//trim(cfile_analysis_ice)//' '//trim(cfileout_ice) )
  1846. ierr = nf90_open(trim(cfileout_ice),nf90_Write,incid_ice_an_out)
  1847. IF (ierr .NE. nf90_noerr ) THEN
  1848. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file. Abort"
  1849. WRITE(*,*), TRIM(cfileout_ice)
  1850. STOP
  1851. END IF
  1852. ! Loop over categories
  1853. ! (2024) Categories as dimension now, no need for the loop anymore.
  1854. ! I also change the var names to correspond with the current nemo restarts.
  1855. !DO jl = 1 , jpl
  1856. ! 8.1.1 a_i
  1857. !~~~~~~~~
  1858. cvarroot='a_i'
  1859. !WRITE(cinteger,'(i1)') jl
  1860. cvarname = TRIM(cvarroot)
  1861. WRITE(*,*), "Recording variable " // cvarname
  1862. ! Request variable ID
  1863. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  1864. IF (ierr .NE. nf90_noerr ) THEN
  1865. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  1866. WRITE(*,*), TRIM(cfileout_ice)
  1867. STOP
  1868. END IF
  1869. ! Put variable
  1870. ierr = nf90_put_var(incid_ice_an_out, ivarid, a_i)
  1871. IF (ierr .NE. nf90_noerr ) THEN
  1872. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. put. Abort"
  1873. WRITE(*,*), TRIM(cfileout_ice)
  1874. STOP
  1875. END IF
  1876. ! 8.1.2 v_i
  1877. !~~~~~~~~
  1878. cvarroot='v_i'
  1879. cvarname = TRIM(cvarroot)
  1880. WRITE(*,*), "Recording variable " // cvarname
  1881. ! Request variable ID
  1882. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  1883. IF (ierr .NE. nf90_noerr ) THEN
  1884. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  1885. WRITE(*,*), TRIM(cfileout_ice)
  1886. STOP
  1887. END IF
  1888. ! Put variable
  1889. ierr = nf90_put_var(incid_ice_an_out, ivarid, v_i)
  1890. IF (ierr .NE. nf90_noerr ) THEN
  1891. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. put. Abort"
  1892. WRITE(*,*), TRIM(cfileout_ice)
  1893. STOP
  1894. END IF
  1895. ! 8.1.3 v_s
  1896. !~~~~~~~~
  1897. cvarroot='v_s'
  1898. cvarname = TRIM(cvarroot)
  1899. WRITE(*,*), "Recording variable " // cvarname
  1900. ! Request variable ID
  1901. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  1902. IF (ierr .NE. nf90_noerr ) THEN
  1903. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  1904. WRITE(*,*), TRIM(cfileout_ice)
  1905. STOP
  1906. END IF
  1907. ! Put variable
  1908. ierr = nf90_put_var(incid_ice_an_out, ivarid, v_s)
  1909. IF (ierr .NE. nf90_noerr ) THEN
  1910. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. put. Abort"
  1911. WRITE(*,*), TRIM(cfileout_ice)
  1912. STOP
  1913. END IF
  1914. ! 8.1.4 smv_i
  1915. !~~~~~~~~~~
  1916. cvarroot='sv_i'
  1917. cvarname = TRIM(cvarroot)
  1918. WRITE(*,*), "Recording variable " // cvarname
  1919. ! Request variable ID
  1920. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  1921. IF (ierr .NE. nf90_noerr ) THEN
  1922. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  1923. WRITE(*,*), TRIM(cfileout_ice)
  1924. STOP
  1925. END IF
  1926. ! Put variable
  1927. ierr = nf90_put_var(incid_ice_an_out, ivarid, smv_i)
  1928. IF (ierr .NE. nf90_noerr ) THEN
  1929. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. smv_i put. Abort"
  1930. WRITE(*,*), TRIM(cfileout_ice)
  1931. STOP
  1932. END IF
  1933. ! 8.1.5 oa_i
  1934. ! ~~~~~~~~
  1935. cvarroot='oa_i'
  1936. cvarname = TRIM(cvarroot)
  1937. WRITE(*,*), "Recording variable " // cvarname
  1938. ! Request variable ID
  1939. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  1940. IF (ierr .NE. nf90_noerr ) THEN
  1941. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  1942. WRITE(*,*), TRIM(cfileout_ice)
  1943. STOP
  1944. END IF
  1945. ! Put variable
  1946. ierr = nf90_put_var(incid_ice_an_out, ivarid, oa_i)
  1947. IF (ierr .NE. nf90_noerr ) THEN
  1948. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. put. Abort"
  1949. WRITE(*,*), TRIM(cfileout_ice)
  1950. STOP
  1951. END IF
  1952. ! 8.1.6 t_su
  1953. ! ~~~~~~~~
  1954. cvarroot='t_su'
  1955. cvarname = TRIM(cvarroot)
  1956. WRITE(*,*), "Recording variable " // cvarname
  1957. ! Request variable ID
  1958. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  1959. IF (ierr .NE. nf90_noerr ) THEN
  1960. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  1961. WRITE(*,*), TRIM(cfileout_ice)
  1962. STOP
  1963. END IF
  1964. ! Put variable
  1965. ierr = nf90_put_var(incid_ice_an_out, ivarid, t_su)
  1966. IF (ierr .NE. nf90_noerr ) THEN
  1967. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. put. Abort"
  1968. WRITE(*,*), TRIM(cfileout_ice)
  1969. STOP
  1970. END IF
  1971. ! 8.1.7 Ice enthalpy (layers)
  1972. ! ~~~~~~~~~~~~~~~~~~~~~~~~~
  1973. cvarroot='e_i_l0'
  1974. DO jk = 1 , nlay_i
  1975. WRITE(cinteger2,'(i1)') jk
  1976. cvarname = TRIM(cvarroot) // TRIM(cinteger2)
  1977. WRITE(*,*),"Recording variable " // cvarname
  1978. ! Request variable ID
  1979. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  1980. IF (ierr .NE. nf90_noerr ) THEN
  1981. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  1982. WRITE(*,*), TRIM(cfileout_ice)
  1983. STOP
  1984. END IF
  1985. ! Put variable
  1986. ierr = nf90_put_var(incid_ice_an_out, ivarid, e_i(:,:,jk,:))
  1987. IF (ierr .NE. nf90_noerr ) THEN
  1988. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. e_i put. Abort"
  1989. WRITE(*,*), TRIM(cfileout_ice)
  1990. STOP
  1991. END IF
  1992. END DO !jk
  1993. ! 8.1.8 Snow enthalpy (layers)
  1994. ! ~~~~~~~~~~~~~~~~~~~~~~~~~
  1995. cvarroot='e_s_l0'
  1996. DO jk = 1 , nlay_s
  1997. WRITE(cinteger2,'(i1)') jk
  1998. cvarname = TRIM(cvarroot) // TRIM(cinteger2)
  1999. WRITE(*,*),"Recording variable " // cvarname
  2000. ! Request variable ID
  2001. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  2002. IF (ierr .NE. nf90_noerr ) THEN
  2003. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  2004. WRITE(*,*), TRIM(cfileout_ice)
  2005. STOP
  2006. END IF
  2007. ! Put variable
  2008. ierr = nf90_put_var(incid_ice_an_out, ivarid, e_s(:,:,jk,:))
  2009. IF (ierr .NE. nf90_noerr ) THEN
  2010. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. e_s put. Abort"
  2011. WRITE(*,*), TRIM(cfileout_ice)
  2012. STOP
  2013. END IF
  2014. END DO !jk
  2015. !END DO ! jl, categories
  2016. ! Put variables that don't depend on categories
  2017. ! Snow ice mass
  2018. ! Request variable id
  2019. cvarname = 'snwice_mass'
  2020. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  2021. IF (ierr .NE. nf90_noerr ) THEN
  2022. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  2023. WRITE(*,*), TRIM(cfileout_ice)
  2024. STOP
  2025. END IF
  2026. ! Put variable
  2027. ierr = nf90_put_var(incid_ice_an_out, ivarid, snwice_mass(:,:))
  2028. IF (ierr .NE. nf90_noerr ) THEN
  2029. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. put. Abort"
  2030. WRITE(*,*), TRIM(cfileout_ice)
  2031. STOP
  2032. END IF
  2033. cvarname = 'snwice_mass_b'
  2034. ierr = nf90_inq_varid(incid_ice_an_out, cvarname, ivarid)
  2035. IF (ierr .NE. nf90_noerr ) THEN
  2036. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. inquiry. Abort"
  2037. WRITE(*,*), TRIM(cfileout_ice)
  2038. STOP
  2039. END IF
  2040. ! Put variable
  2041. ierr = nf90_put_var(incid_ice_an_out, ivarid, snwice_mass_b(:,:))
  2042. IF (ierr .NE. nf90_noerr ) THEN
  2043. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF ice file var. put. Abort"
  2044. WRITE(*,*), TRIM(cfileout_ice)
  2045. STOP
  2046. END IF
  2047. ! Close the NetCDF file
  2048. ierr = nf90_close(incid_ice_an_out)
  2049. IF (ierr .NE. nf90_noerr ) THEN
  2050. WRITE(*,*), "(sanity_check_LIM3) Error Closing NetCDF . Abort"
  2051. WRITE(*,*), TRIM(cfileout_ice)
  2052. STOP
  2053. END IF
  2054. WRITE(*,*) 'Leaving record_ice()'
  2055. END SUBROUTINE record_ice
  2056. SUBROUTINE record_oce()
  2057. USE my_variables
  2058. USE netcdf
  2059. IMPLICIT NONE
  2060. WRITE(*,*) 'Entering record_oce()'
  2061. ! Record oce variables
  2062. ! We copy the input file and store everything into this copy
  2063. CALL system('cp -f '//trim(cfile_analysis_oce)//' '//trim(cfileout_oce) )
  2064. ! Open the file
  2065. ierr = nf90_open(trim(cfileout_oce),nf90_Write,incid_oce_an_out)
  2066. IF (ierr .NE. nf90_noerr ) THEN
  2067. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF Ocean file. Abort"
  2068. WRITE(*,*), TRIM(cfileout_oce)
  2069. STOP
  2070. END IF
  2071. ! A. sn (salinity)
  2072. cvarname= csn
  2073. ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2074. IF (ierr .NE. nf90_noerr ) THEN
  2075. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2076. WRITE(*,*), TRIM(cfileout_oce)
  2077. STOP
  2078. END IF
  2079. ! Put variable
  2080. ierr = nf90_put_var(incid_oce_an_out, ivarid, sn_an(:,:,:))
  2081. IF (ierr .NE. nf90_noerr ) THEN
  2082. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2083. WRITE(*,*), TRIM(cfileout_oce)
  2084. STOP
  2085. END IF
  2086. ! Following lines commented out as the variable no longer appears
  2087. ! in the restart files (2020)
  2088. !! B. sss_m (sea surface salinity)
  2089. !cvarname= csss_m
  2090. !ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2091. !IF (ierr .NE. nf90_noerr ) THEN
  2092. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2093. ! WRITE(*,*), TRIM(cfileout_oce)
  2094. ! STOP
  2095. !END IF
  2096. !! Put variable
  2097. !ierr = nf90_put_var(incid_oce_an_out, ivarid, sss_m_an(:,:))
  2098. !IF (ierr .NE. nf90_noerr ) THEN
  2099. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2100. ! WRITE(*,*), TRIM(cfileout_oce)
  2101. ! STOP
  2102. !END IF
  2103. ! C. tn (temperature)
  2104. cvarname= ctn
  2105. ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2106. IF (ierr .NE. nf90_noerr ) THEN
  2107. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2108. WRITE(*,*), TRIM(cfileout_oce)
  2109. STOP
  2110. END IF
  2111. ! Put variable
  2112. ierr = nf90_put_var(incid_oce_an_out, ivarid, tn_an(:,:,:))
  2113. IF (ierr .NE. nf90_noerr ) THEN
  2114. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2115. WRITE(*,*), TRIM(cfileout_oce)
  2116. STOP
  2117. END IF
  2118. ! Following lines commented out as the variable no longer appears
  2119. ! in the restart files (2020)
  2120. !! D. sst_m (sea surface temperature)
  2121. !cvarname= csst_m
  2122. !ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2123. !IF (ierr .NE. nf90_noerr ) THEN
  2124. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2125. ! WRITE(*,*), TRIM(cfileout_oce)
  2126. ! STOP
  2127. !END IF
  2128. !! Put variable
  2129. !ierr = nf90_put_var(incid_oce_an_out, ivarid, sst_m_an(:,:))
  2130. !IF (ierr .NE. nf90_noerr ) THEN
  2131. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2132. ! WRITE(*,*), TRIM(cfileout_oce)
  2133. ! STOP
  2134. !END IF
  2135. ! E. un (sea velocity, "un")
  2136. cvarname= cun
  2137. ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2138. IF (ierr .NE. nf90_noerr ) THEN
  2139. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2140. WRITE(*,*), TRIM(cfileout_oce)
  2141. STOP
  2142. END IF
  2143. ! Put variable
  2144. ierr = nf90_put_var(incid_oce_an_out, ivarid, un_an(:,:,:))
  2145. IF (ierr .NE. nf90_noerr ) THEN
  2146. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2147. WRITE(*,*), TRIM(cfileout_oce)
  2148. STOP
  2149. END IF
  2150. ! F. ub (sea velocity, "ub")
  2151. cvarname= cub
  2152. ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2153. IF (ierr .NE. nf90_noerr ) THEN
  2154. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2155. WRITE(*,*), TRIM(cfileout_oce)
  2156. STOP
  2157. END IF
  2158. ! Put variable
  2159. ierr = nf90_put_var(incid_oce_an_out, ivarid, ub_an(:,:,:))
  2160. IF (ierr .NE. nf90_noerr ) THEN
  2161. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2162. WRITE(*,*), TRIM(cfileout_oce)
  2163. STOP
  2164. END IF
  2165. ! G. vn (sea velocity, "vn")
  2166. cvarname= cvn
  2167. ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2168. IF (ierr .NE. nf90_noerr ) THEN
  2169. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2170. WRITE(*,*), TRIM(cfileout_oce)
  2171. STOP
  2172. END IF
  2173. ! Put variable
  2174. ierr = nf90_put_var(incid_oce_an_out, ivarid, vn_an(:,:,:))
  2175. IF (ierr .NE. nf90_noerr ) THEN
  2176. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2177. WRITE(*,*), TRIM(cfileout_oce)
  2178. STOP
  2179. END IF
  2180. ! H. vb (sea velocity, "vb")
  2181. cvarname= cvb
  2182. ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2183. IF (ierr .NE. nf90_noerr ) THEN
  2184. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2185. WRITE(*,*), TRIM(cfileout_oce)
  2186. STOP
  2187. END IF
  2188. ! Put variable
  2189. ierr = nf90_put_var(incid_oce_an_out, ivarid, vb_an(:,:,:))
  2190. IF (ierr .NE. nf90_noerr ) THEN
  2191. WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2192. WRITE(*,*), TRIM(cfileout_oce)
  2193. STOP
  2194. END IF
  2195. ! Following lines commented out as the variable no longer appears
  2196. ! in the restart files (2020)
  2197. !! I. ssu_m (sea surface velocity, "ssu_m")
  2198. !cvarname= cssu_m
  2199. !ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2200. !IF (ierr .NE. nf90_noerr ) THEN
  2201. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2202. ! WRITE(*,*), TRIM(cfileout_oce)
  2203. ! STOP
  2204. !END IF
  2205. !
  2206. !! Put variable
  2207. !ierr = nf90_put_var(incid_oce_an_out, ivarid, ssu_m_an(:,:))
  2208. !IF (ierr .NE. nf90_noerr ) THEN
  2209. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2210. ! WRITE(*,*), TRIM(cfileout_oce)
  2211. ! STOP
  2212. !END IF
  2213. !
  2214. !! J. ssv_m (sea surface velocity, "ssv_m")
  2215. !cvarname= cssv_m
  2216. !ierr = nf90_inq_varid(incid_oce_an_out, cvarname, ivarid)
  2217. !IF (ierr .NE. nf90_noerr ) THEN
  2218. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. inquiry. Abort"
  2219. ! WRITE(*,*), TRIM(cfileout_oce)
  2220. ! STOP
  2221. !END IF
  2222. !
  2223. !! Put variable
  2224. !ierr = nf90_put_var(incid_oce_an_out, ivarid, ssv_m_an(:,:))
  2225. !IF (ierr .NE. nf90_noerr ) THEN
  2226. ! WRITE(*,*), "(sanity_check_LIM3) Error NetCDF oce file var. put. Abort"
  2227. ! WRITE(*,*), TRIM(cfileout_oce)
  2228. ! STOP
  2229. !END IF
  2230. ! Close file
  2231. ierr = nf90_close(incid_oce_an_out)
  2232. IF (ierr .NE. nf90_noerr ) THEN
  2233. WRITE(*,*), "(sanity_check_LIM3) Error Closing NetCDF . Abort"
  2234. WRITE(*,*), TRIM(cfileout_oce)
  2235. STOP
  2236. END IF
  2237. WRITE(*,*) 'Leaving record_oce'
  2238. END SUBROUTINE record_oce
  2239. SUBROUTINE salinity_check()
  2240. USE my_variables
  2241. USE netcdf
  2242. IMPLICIT NONE
  2243. ! Dummy variables
  2244. INTEGER :: ji, jj, jk
  2245. REAL :: zmaxsaldiff=9999.0
  2246. WRITE(*,*) 'Entering salinity_check() '
  2247. DO ji=1,jpi
  2248. DO jj=1,jpj
  2249. DO jk=1,jpk
  2250. zsaldiff=sn_an(ji,jj,jk) - sn_fc(ji,jj,jk)
  2251. IF (ABS(zsaldiff) .GT. zmaxsaldiff ) THEN
  2252. IF (ABS(zsaldiff) .GT. 100.0 * zmaxsaldiff ) THEN
  2253. WRITE(*,*) "Very large salinity variation"
  2254. WRITE(*,*) "at point ji,jj,jk = ", ji,jj,jk
  2255. WRITE(*,*) "sn_an is ",sn_an(ji,jj,jk)
  2256. WRITE(*,*) "sn_fc is ",sn_fc(ji,jj,jk)
  2257. WRITE(*,*) "diff is", zsaldiff
  2258. END IF
  2259. !WRITE(*,*) "Salinity difference at ji,jj,jk=",ji,jj,jk
  2260. !WRITE(*,*) "Difference is ",ABS(zsaldiff)
  2261. !WRITE(*,*) "sn_an is ",sn_an(ji,jj,jk)
  2262. !WRITE(*,*) "sn_fc is ",sn_fc(ji,jj,jk)
  2263. sn_an(ji,jj,jk) = sn_fc(ji,jj,jk) + SIGN(zmaxsaldiff,zsaldiff)
  2264. !WRITE(*,*) "sn_an is now ",sn_an(ji,jj,jk)
  2265. END IF
  2266. END DO ! jk
  2267. zsaldiff=(sss_m_an(ji,jj) - sss_m_fc(ji,jj)) / REAL( nn_fsbc - 1 )
  2268. IF (ABS(zsaldiff) .GT. zmaxsaldiff ) THEN
  2269. IF (ABS(zsaldiff) .GT. 100.0 * zmaxsaldiff ) THEN
  2270. WRITE(*,*) "Very large SSS variation at ji,jj = ",ji,jj
  2271. WRITE(*,*) "sss_m_an is ", sss_m_an(ji,jj)
  2272. WRITE(*,*) "sss_m_fc is ", sss_m_fc(ji,jj)
  2273. WRITE(*,*) "diff is" , zsaldiff
  2274. END IF
  2275. !WRITE(*,*) "Sea surface salinity difference at ji,jj=",ji,jj
  2276. !WRITE(*,*) "Difference is ",ABS(zsaldiff)
  2277. !WRITE(*,*) "sss_m_an is ",sss_m_an(ji,jj) / REAL( nn_fsbc - 1 )
  2278. !WRITE(*,*) "sss_m_fc is ",sss_m_fc(ji,jj) / REAL( nn_fsbc - 1 )
  2279. sss_m_an(ji,jj) = sss_m_fc(ji,jj) + SIGN(REAL( nn_fsbc - 1 ) * zmaxsaldiff , zsaldiff)
  2280. !WRITE(*,*) "sss_m_an is now ",sss_m_an(ji,jj) / REAL( nn_fsbc - 1 )
  2281. ! Important note
  2282. ! The reason for the nn_fsbc - 1 factor is the following. In the
  2283. ! restarts, the variable sss_m is (nn_fsbc -1) times the first layer of
  2284. ! the sea salinity, where nn_fsbc is the frequency call of the ice to
  2285. ! the ocean. As I understood, this is intended to facilitate the switch
  2286. ! from one frequency call to another. The point is that the variable
  2287. ! sss_m is the cumulative sea surface salinity over the (nn_fsbc-1) time
  2288. ! steps. Stated the other way around, it's nn_fsbc-1 times its mean
  2289. ! value. Hence here we divide sss_m by (nn_fsbc-1), ensure that
  2290. ! variations in salinity are not too strong, and give back the corrected
  2291. ! quantity multiplied by (nn_fsbc-1)
  2292. END IF
  2293. END DO
  2294. END DO
  2295. WRITE(*,*) 'Leaving salinity_check()'
  2296. END SUBROUTINE salinity_check
  2297. SUBROUTINE temperature_check()
  2298. USE my_variables
  2299. USE netcdf
  2300. IMPLICIT NONE
  2301. ! Dummy variables
  2302. INTEGER :: ji, jj, jk
  2303. REAL :: zmaxtempdiff=100.0
  2304. REAL :: ztempmin ! Minimum temperature for surf sea water (fct of salinity)
  2305. WRITE(*,*) 'Entering temperature_check() '
  2306. ! 3D- temperature
  2307. DO ji=1,jpi
  2308. DO jj=1,jpj
  2309. DO jk=1,jpk
  2310. ztempdiff=tn_an(ji,jj,jk) - tn_fc(ji,jj,jk)
  2311. IF (ABS(ztempdiff) .GT. zmaxtempdiff ) THEN
  2312. IF (ABS(ztempdiff) .GT. 100.0 * zmaxtempdiff ) THEN
  2313. WRITE(*,*) "Very large temperature variation detected!!"
  2314. WRITE(*,*) "at point ji,jj,jk = ", ji,jj,jk
  2315. WRITE(*,*) "tn_an is ",tn_an(ji,jj,jk)
  2316. WRITE(*,*) "tn_fc is ",tn_fc(ji,jj,jk)
  2317. END IF
  2318. !WRITE(*,*) "Temperature difference at ji,jj,jk=",ji,jj,jk
  2319. !WRITE(*,*) "Difference is ",ABS(ztempdiff)
  2320. !WRITE(*,*) "tn_an is ",tn_an(ji,jj,jk)
  2321. !WRITE(*,*) "tn_fc is ",tn_fc(ji,jj,jk)
  2322. tn_an(ji,jj,jk) = tn_fc(ji,jj,jk) + SIGN(zmaxtempdiff,ztempdiff)
  2323. !WRITE(*,*) "tn_an is now ",tn_an(ji,jj,jk)
  2324. END IF ! if diff is large
  2325. END DO ! jk
  2326. DO jk =1,1
  2327. ! Reset surface temperature to freezing point if below freezing point
  2328. ! This depends on the formulation chosen in the namelist (nn_eos).
  2329. ! The formula comes from the NEMO code (routine eosbn2.f90)
  2330. !
  2331. ! In the case nn_eos = 0 (UNESCO formulation)
  2332. ! ztempmin= ( - 0.0575_wp + 1.710523e-3_wp * SQRT( sn_an(ji,jj,jk) ) &
  2333. ! & - 2.154996e-4_wp * sn_an(ji,jj,jk) ) * sn_an(ji,jj,jk)
  2334. !
  2335. ! In the case nn_eos = -1 or 1 (TEOS-10 formulation)
  2336. r1_S0 = 0.875_wp/35.16504_wp
  2337. zs = sqrt( abs(sn_an(ji,jj,jk)) * r1_S0)
  2338. ztempmin = ((((1.46873e-03_wp*zs-9.64972e-03_wp)*zs+2.28348e-02_wp)*zs &
  2339. & - 3.12775e-02_wp)*zs+2.07679e-02_wp)*zs-5.87701e-02_wp
  2340. ztempmin = ztempmin * sn_an(ji,jj,jk)
  2341. ! This is the freezing point of sea water at the surface.
  2342. IF ( tn_an(ji,jj,jk) .LT. ztempmin ) THEN
  2343. WRITE(*,*) 'At grid point ', ji,jj,jk
  2344. WRITE(*,*) 'tn_an reset from', tn_an(ji,jj,jk),'to ', ztempmin
  2345. tn_an(ji,jj,jk) = ztempmin
  2346. END IF
  2347. END DO ! jk
  2348. ! SST
  2349. ztempdiff=(sst_m_an(ji,jj) - sst_m_fc(ji,jj)) / REAL( nn_fsbc - 1 )
  2350. IF (ABS(ztempdiff) .GT. zmaxtempdiff ) THEN
  2351. IF (ABS(ztempdiff) .GT. 100.0 * zmaxtempdiff ) THEN
  2352. WRITE(*,*) "Very large SST variation deteced at ji,jj = ",ji,jj
  2353. WRITE(*,*) "sst_m_an is ", sst_m_an(ji,jj)
  2354. WRITE(*,*) "sst_m_fc is ", sst_m_fc(ji,jj)
  2355. WRITE(*,*) "diff is" , ztempdiff
  2356. END IF
  2357. !WRITE(*,*) "Sea surface temperature difference at ji,jj=",ji,jj
  2358. !WRITE(*,*) "Difference is ",ABS(ztempdiff)
  2359. !WRITE(*,*) "sst_m_an is ",sst_m_an(ji,jj) / REAL( nn_fsbc - 1 )
  2360. !WRITE(*,*) "sst_m_fc is ",sst_m_fc(ji,jj) / REAL( nn_fsbc - 1 )
  2361. sst_m_an(ji,jj) = sst_m_fc(ji,jj) + SIGN(REAL( nn_fsbc - 1 ) * zmaxtempdiff , ztempdiff)
  2362. !WRITE(*,*) "sst_m_an is now ",sst_m_an(ji,jj) / REAL( nn_fsbc - 1 )
  2363. ! Important note
  2364. ! The reason for the nn_fsbc - 1 factor is the following. In the
  2365. ! restarts, the variable sst_m is (nn_fsbc -1) times the first layer of
  2366. ! the sea temperature, where nn_fsbc is the frequency call of the ice to
  2367. ! the ocean. As I understood, this is intended to facilitate the switch
  2368. ! from one frequency call to another. The point is that the variable
  2369. ! sst_m is the cumulative sea surface temperature over the (nn_fsbc-1) time
  2370. ! steps. Stated the other way around, it's nn_fsbc-1 times its mean
  2371. ! value. Hence here we divide sst_m by (nn_fsbc-1), ensure that
  2372. ! variations in temperature are not too strong, and give back the corrected
  2373. ! quantity multiplied by (nn_fsbc-1)
  2374. END IF
  2375. ! For nn_eos = 0
  2376. ! ztempmin= ( - 0.0575_wp + 1.710523e-3_wp * SQRT( sn_an(ji,jj,1) ) &
  2377. ! & - 2.154996e-4_wp * sn_an(ji,jj,1) ) * sn_an(ji,jj,1)
  2378. ! For nn_eos = -1 or 1
  2379. r1_S0 = 0.875_wp/35.16504_wp
  2380. zs = sqrt( abs(sn_an(ji,jj,1)) * r1_S0)
  2381. ztempmin = ((((1.46873e-03_wp*zs-9.64972e-03_wp)*zs+2.28348e-02_wp)*zs &
  2382. & - 3.12775e-02_wp)*zs+2.07679e-02_wp)*zs-5.87701e-02_wp
  2383. ztempmin = ztempmin * sn_an(ji,jj,1)
  2384. IF ( ( sst_m_an(ji,jj) / REAL( nn_fsbc - 1 ) ) .LT. ztempmin ) THEN
  2385. WRITE(*,*), 'At grid point ', ji,jj
  2386. WRITE(*,*), 'SST reset from ',sst_m_an(ji,jj)/REAL( nn_fsbc - 1 ),' to ' ,ztempmin
  2387. sst_m_an(ji,jj) = ztempmin * REAL (nn_fsbc - 1)
  2388. END IF
  2389. END DO ! jj
  2390. END DO ! ji
  2391. WRITE(*,*) 'Leaving temperature_check()'
  2392. END SUBROUTINE temperature_check
  2393. SUBROUTINE update_hc()
  2394. USE my_variables
  2395. IMPLICIT NONE
  2396. INTEGER :: ji, jj, jk, jl
  2397. REAL(wp) :: zratio, ztmelts
  2398. REAL(wp), PARAMETER :: t_init = 270.0 ! Initial temperature of ice when it is forming. Inspired from limistate.
  2399. REAL(wp) :: zhc ! Heat content (in ice or snow)
  2400. REAL(wp), PARAMETER :: zunit_fac= 1.0e9! This 1.0e9 is because the e_i and e_s variables are saved in Giga Joules / m2 in
  2401. ! the restart (but in Joules/m2 in the code), I guess because the restart cannot take
  2402. ! numbers with large exponents.
  2403. ! For info: the energy to melt 1 meter of ice at 0°C is
  2404. ! 334 000 [J / kg] * 1 [m] * 1000 [kg/m3] = 0.334 x 10^9 J / m2
  2405. WRITE(*,*) 'Entering update_hc()'
  2406. DO jl = 1, jpl
  2407. DO ji = 1, jpi
  2408. DO jj = 1, jpj
  2409. ! Ice layers
  2410. ! Case 1: there was ice in the forecast
  2411. IF (v_i_fc(ji,jj,jl) .GT. epsi10) THEN
  2412. zratio = v_i(ji,jj,jl) / v_i_fc(ji,jj,jl)
  2413. ! Update the ice heat content by that amount in each layer
  2414. DO jk = 1, nlay_i
  2415. e_i(ji,jj,jk,jl) = zratio * e_i(ji,jj,jk,jl)
  2416. END DO ! jk
  2417. ! Case 2: there was no ice in the forecast
  2418. ELSEIF (v_i(ji,jj,jl) .GT. epsi06 ) THEN
  2419. ztmelts = - tmut * smv_i(ji,jj,jl) + rtt
  2420. zhc = zrhoic * (& ! [kg/m3]
  2421. &zcpic * (ztmelts - t_init)& ! [J/(kg.K) ] * [K ] = J/kg
  2422. &+zlfus* (1- (ztmelts - rtt)/(t_init-rtt) )& ! [J/kg]*[]
  2423. &-zrcp * (ztmelts - rtt)& ! [J/(kg.K)] * [K]
  2424. &)
  2425. ! zhc is in J/m3
  2426. ! The amount of heat in each layer is that divided by the number of
  2427. ! layers, multiplied by the sea ice volume (v_i*cell area) and by
  2428. ! unit_fac (see LIM3 code) to get the units in GigaJoule
  2429. DO jk = 1,nlay_i
  2430. e_i(ji,jj,jk,jl) = zhc * v_i(ji,jj,jl) * zcellarea(ji,jj) / nlay_i / zunit_fac
  2431. END DO
  2432. !WRITE(*,*) "Ice was created by the filter at point ", ji,jj
  2433. !WRITE(*,*) "Ice volume in forecast was",v_i_fc(ji,jj,jl)
  2434. !WRITE(*,*) "Ice volume in analysis is ",v_i(ji,jj,jl)
  2435. !WRITE(*,*) "In category ", jl
  2436. !WRITE(*,*) "New e_i is ",e_i(ji,jj,:,jl)
  2437. END IF
  2438. !IF ( ji ==127 .AND. jj == 124 .AND. jl==5 ) THEN
  2439. ! WRITE(*,*) "ji = ",ji,"jj = ",jj, "jl =", jl
  2440. ! WRITE(*,*) "e_i: ", e_i(ji,jj,:,jl)
  2441. ! WRITE(*,*) "zratio: ",zratio
  2442. ! WRITE(*,*) "v_i", v_i(ji,jj,jl)
  2443. ! WRITE(*,*) "v_i_fc: ", v_i_fc(ji,jj,jl)
  2444. ! WRITE(*,*) "Stop because requested so"
  2445. ! !STOP
  2446. !END IF
  2447. ! Snow layer
  2448. ! Case 1: there was snow in the forecast
  2449. IF (v_s_fc(ji,jj,jl) .GT. epsi06) THEN
  2450. zratio = v_s(ji,jj,jl) / v_s_fc(ji,jj,jl)
  2451. ! Update the ice heat content by that amount in each layer
  2452. DO jk = 1, nlay_s
  2453. e_s(ji,jj,jk,jl) = zratio * e_s(ji,jj,jk,jl)
  2454. END DO ! jk
  2455. ! Case 2: there was no snow in the forecast
  2456. ELSEIF (v_s(ji,jj,jl) .GT. epsi06) THEN
  2457. zhc = zrhosn * (& ! [kg/m3]
  2458. &zcpic * (rtt - t_init)& ! [J/(kg.K) ] * [K ] = J/kg
  2459. &+zlfus& ! [J/(kg)]
  2460. &)
  2461. ! zhc is in J/m3
  2462. ! The amount of heat in each layer is that divided by the number of
  2463. ! layers, multiplied by the snow volume (v_s*cell area)
  2464. DO jk = 1,nlay_s
  2465. e_s(ji,jj,jk,jl) = zhc * v_s(ji,jj,jl) * zcellarea(ji,jj) / nlay_s / zunit_fac
  2466. END DO
  2467. END IF
  2468. END DO! jj
  2469. END DO ! ji
  2470. END DO !jl
  2471. WRITE(*,*) 'Leaving update_hc()'
  2472. END SUBROUTINE update_hc
  2473. SUBROUTINE regularize()
  2474. USE my_variables
  2475. IMPLICIT NONE
  2476. INTEGER :: ji, jj, jk, jl
  2477. ! Resets < 0 concentrations to 0
  2478. ! Resets variables to zero where no ice concentration
  2479. DO ji=1,jpi
  2480. DO jj=1,jpj
  2481. DO jl =1,jpl
  2482. IF ( a_i(ji,jj,jl) .LT. rzero ) THEN
  2483. a_i( ji,jj,jl) = rzero
  2484. v_i( ji,jj,jl) = rzero
  2485. smv_i(ji,jj,jl) = rzero
  2486. v_s( ji,jj,jl) = rzero
  2487. oa_i( ji,jj,jl) = rzero
  2488. DO jk=1,nlay_i
  2489. e_i(ji,jj,jk,jl) = rzero
  2490. END DO
  2491. DO jk=1,nlay_s
  2492. e_s(ji,jj,jk,jl) = rzero
  2493. END DO
  2494. END IF
  2495. END DO
  2496. ! Variables that do not depend on categories
  2497. IF ( SUM(a_i(ji,jj,:)) .LT. rzero ) THEN
  2498. snwice_mass(ji,jj) = rzero
  2499. snwice_mass_b(ji,jj) = rzero
  2500. END IF
  2501. END DO!jj
  2502. END DO ! ji
  2503. END SUBROUTINE regularize
  2504. SUBROUTINE velocity_check()
  2505. USE my_variables
  2506. IMPLICIT NONE
  2507. INTEGER :: ji,jj,jk
  2508. REAL :: zmaxvel = 2.0
  2509. REAL :: zmaxsurfvel= 6.0
  2510. ! Resets ocean velocities to [-2,2] ms-1
  2511. ! Resets sea surface velocities to [-4,4] ms-1
  2512. DO ji=1,jpi
  2513. DO jj = 1,jpj
  2514. DO jk=1,jpk
  2515. IF ( ABS(un_an(ji,jj,jk)) .GT. zmaxvel ) THEN
  2516. WRITE(*,*) "Fast ocean found at ji,jj,jk=",ji,jj,jk
  2517. WRITE(*,*) "un_an is ",un_an(ji,jj,jk)
  2518. !un_an(ji,jj,jk) = un_fc(ji,jj,jk) !zmaxvel * SIGN( rone , un_an(ji,jj,jk) )
  2519. un_an(ji,jj,jk) = zmaxvel * SIGN( rone , un_an(ji,jj,jk) )
  2520. WRITE(*,*) "un_an reset to",un_an(ji,jj,jk)
  2521. END IF
  2522. IF ( ABS(ub_an(ji,jj,jk)) .GT. zmaxvel ) THEN
  2523. WRITE(*,*) "Fast ocean found at ji,jj,jk=",ji,jj,jk
  2524. WRITE(*,*) "ub_an is ",ub_an(ji,jj,jk)
  2525. !ub_an(ji,jj,jk) = ub_fc(ji,jj,jk) !zmaxvel * SIGN( rone , ub_an(ji,jj,jk) )
  2526. ub_an(ji,jj,jk) = zmaxvel * SIGN( rone , ub_an(ji,jj,jk) )
  2527. WRITE(*,*) "ub_an reset to",ub_an(ji,jj,jk)
  2528. END IF
  2529. IF ( ABS(vn_an(ji,jj,jk)) .GT. zmaxvel ) THEN
  2530. WRITE(*,*) "Fast ocean found at ji,jj,jk=",ji,jj,jk
  2531. WRITE(*,*) "vn_an is ",vn_an(ji,jj,jk)
  2532. !vn_an(ji,jj,jk) = vn_fc(ji,jj,jk) !zmaxvel * SIGN( rone , vn_an(ji,jj,jk) )
  2533. vn_an(ji,jj,jk) = zmaxvel * SIGN( rone , vn_an(ji,jj,jk) )
  2534. WRITE(*,*) "vn_an reset to",vn_an(ji,jj,jk)
  2535. END IF
  2536. IF ( ABS(vb_an(ji,jj,jk)) .GT. zmaxvel ) THEN
  2537. WRITE(*,*) "Fast ocean found at ji,jj,jk=",ji,jj,jk
  2538. WRITE(*,*) "vb_an is ",vb_an(ji,jj,jk)
  2539. !vb_an(ji,jj,jk) = vb_fc(ji,jj,jk) !zmaxvel * SIGN( rone , vb_an(ji,jj,jk) )
  2540. vb_an(ji,jj,jk) = zmaxvel * SIGN( rone , vb_an(ji,jj,jk) )
  2541. WRITE(*,*) "vb_an reset to",vb_an(ji,jj,jk)
  2542. END IF
  2543. END DO !jk
  2544. ! Surface velocity
  2545. IF (ABS(ssu_m_an(ji,jj)) .GT. zmaxsurfvel ) THEN
  2546. WRITE(*,*) "Fast sea surface velocity found at ji,jj=" , ji,jj
  2547. WRITE(*,*) "ssu_m_an is ",ssu_m_an(ji,jj)
  2548. !ssu_m_an(ji,jj) = ssu_m_fc(ji,jj) !zmaxsurfvel * SIGN(rone, ssu_m_an(ji,jj) )
  2549. ssu_m_an(ji,jj) = zmaxsurfvel * SIGN(rone, ssu_m_an(ji,jj) )
  2550. WRITE(*,*) "ssu_m_an reset to", ssu_m_an(ji,jj)
  2551. END IF
  2552. IF (ABS(ssv_m_an(ji,jj)) .GT. zmaxsurfvel ) THEN
  2553. WRITE(*,*) "Fast sea surface velocity found at ji,jj=" , ji,jj
  2554. WRITE(*,*) "ssv_m_an is ",ssv_m_an(ji,jj)
  2555. !ssv_m_an(ji,jj) = ssv_m_fc(ji,jj) !zmaxsurfvel * SIGN(rone, ssv_m_an(ji,jj) )
  2556. ssv_m_an(ji,jj) = zmaxsurfvel * SIGN(rone, ssv_m_an(ji,jj) )
  2557. WRITE(*,*) "ssv_m_an reset to", ssv_m_an(ji,jj)
  2558. END IF
  2559. END DO
  2560. END DO
  2561. END SUBROUTINE velocity_check