p_sanity_check.F90 92 KB

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