source: trunk/LMDZ.MARS/libf/phymars/albedocaps.F90 @ 2156

Last change on this file since 2156 was 1918, checked in by emillour, 7 years ago

Mars GCM:
Code cleanup:

  • remove "comorbit.h" since it is no longer used.
  • turn "datafile.h" into module datafile_mod.F90 (and rename variable "datafile" as "datadir" since it stores the path to the datafile directory).

EM

File size: 13.4 KB
RevLine 
[38]1subroutine albedocaps(zls,ngrid,piceco2,psolaralb,emisref)
2
3! routine which changes the albedo (and emissivity) of the surface
4! depending on the presence of CO2 ice on the surface
5
6! to use the 'getin' routine
[1047]7use ioipsl_getincom, only: getin
[1543]8use geometry_mod, only: latitude ! grid point latitudes (rad)
[1047]9use surfdat_h, only: TESicealbedo, TESice_Ncoef, TESice_Scoef, &
10                     emisice, albedice, watercaptag, albedo_h2o_ice, &
11                     emissiv, albedodat
[38]12implicit none
13
[1528]14include"callkeys.h"
[38]15
16! arguments:
17real,intent(in) :: zls ! solar longitude (rad)
18integer,intent(in) :: ngrid
19real,intent(in) :: piceco2(ngrid) ! amount of CO2 ice on the surface (kg/m2)
20real,intent(out) :: psolaralb(ngrid,2) ! albedo of the surface
21real,intent(out) :: emisref(ngrid) ! emissivity of the surface
22
23
24! local variables:
25logical,save :: firstcall=.true.
26integer :: ig,icap
27
28! 1. Initializations
[1779]29! AS: OK firstcall absolute
[38]30if (firstcall) then
31  ! find out if user wants to use TES cap albedoes or not
32  TESicealbedo=.false. ! default value
33  write(*,*)" albedocaps: Use TES Cap albedoes ?"
34  call getin("TESicealbedo",TESicealbedo)
35  write(*,*)" albedocaps: TESicealbedo = ",TESicealbedo
36 
37  ! if using TES albedoes, load coeffcients
38  if (TESicealbedo) then
39    write(*,*)" albedocaps: Coefficient for Northern Cap ?"
40    TESice_Ncoef=1.0 ! default value
41    call getin("TESice_Ncoef",TESice_Ncoef)
42    write(*,*)" albedocaps: TESice_Ncoef = ",TESice_Ncoef
43   
44    write(*,*)" albedocaps: Coefficient for Southern Cap ?"
45    TESice_Scoef=1.0 ! default value
46    call getin("TESice_Scoef",TESice_Scoef)
47    write(*,*)" albedocaps: TESice_Scoef = ",TESice_Scoef
48  endif
49 
50  firstcall=.false.
51endif ! of if (firstcall)
52
53do ig=1,ngrid
[1541]54  if (latitude(ig).lt.0.) then
[38]55    icap=2 ! Southern hemisphere
56  else
57    icap=1 ! Northern hemisphere
58  endif
59
60  if (piceco2(ig).gt.0) then
61    ! set emissivity of surface to be the ice emissivity
62    emisref(ig)=emisice(icap)
63    ! set the surface albedo to be the ice albedo
64    if (TESicealbedo) then
[801]65      call TES_icecap_albedo(zls,ig,psolaralb(ig,1),icap)
[38]66      psolaralb(ig,2)=psolaralb(ig,1)
67    else
68      psolaralb(ig,1)=albedice(icap)
69      psolaralb(ig,2)=albedice(icap)
70    endif
[283]71  else if (watercaptag(ig) .and. water) then
72    ! there is a water ice cap: set the surface albedo to the water ice one
73    ! to do : emissivity
74    emisref(ig) = 1
75    psolaralb(ig,1)=albedo_h2o_ice
76    psolaralb(ig,2)=albedo_h2o_ice
[38]77  else
78    ! set emissivity of surface to be bare ground emissivity
79    emisref(ig)=emissiv
80    ! set the surface albedo to bare ground albedo
81    psolaralb(ig,1)=albedodat(ig)
82    psolaralb(ig,2)=albedodat(ig)
83  endif ! of if (piceco2(ig).gt.0)
84enddo ! of ig=1,ngrid
85end subroutine albedocaps
86
87!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[801]88subroutine TES_icecap_albedo(zls,ig,alb,icap)
[38]89
[1543]90use geometry_mod, only: latitude, longitude ! in radians
[1047]91use surfdat_h, only: albedice, TESice_Ncoef, TESice_Scoef
[1918]92use datafile_mod, only: datadir
[1130]93use netcdf, only: nf90_open, NF90_NOWRITE, NF90_NOERR, &
94                  nf90_strerror, nf90_inq_varid, nf90_get_var, nf90_close
95                 
[38]96implicit none
97
98! arguments:
99real,intent(in) :: zls ! solar longitude (rad)
100integer,intent(in) :: ig ! grid point index
101real,intent(out) :: alb ! (interpolated) TES ice albedo at that grid point
[801]102integer :: icap ! =1: Northern hemisphere =2: Southern hemisphere
[38]103
104! local variables:
105logical,save :: firstcall=.true.
106real,save :: zls_old ! value of zls from a previous call
107integer,save :: tinf,tsup ! encompassing time indexes of TES data
108real,save :: reltime ! relative position in-between time indexes (in [0;1])
109integer :: latinf,latsup ! encompassing latitude indexes of TES data
110real :: rellat ! relative position in-between latitude indexes (in[0;1])
111integer :: loninf,lonsup ! encompassing longitude indexes of TES data
112real :: rellon !relative position in-between longitude indexes (in[0;1])
113real,save :: pi,radeg ! to convert radians to degrees
114real :: zlsd ! solar longitude, in degrees
115real :: latd ! latitude, in degrees
116real :: lond ! longitude, in degrees
117integer :: i
118
119! TES datasets: (hard coded fixed length/sizes; for now)
120integer,parameter :: TESlonsize=72
121real,parameter :: TESdeltalon=5.0 ! step in longitude in TES files
122! longitudes, in TES files, in degrees, from TESlon(1)=-177.5 to TESlon(72)=177.5
123real,save :: TESlon(TESlonsize)
124integer,parameter :: TESlatsize=30
125real,parameter :: TESdeltalat=2.0 ! step in latitude in TES files
126! latitudes (north hemisphere file), in degrees, from TESlatn(1)=31,
127! to TESlatn(30)=89 ; TESlatn(8)=45
128real,parameter :: TESlatnmin=45. ! minimum TES latitude (North hemisphere)
129real,parameter :: TESlatsmax=-45. ! maximum TES latitude (South hemisphere)
130real,save :: TESlatn(TESlatsize)
131! latitudes (south hemisphere file), in degrees, from TESlats(1)=-89,
132! to TESlats(30)=-31 ; TESlats(23)=-45
133real,save :: TESlats(TESlatsize)
134integer,parameter :: TESlssize=72
135real,parameter :: TESdeltals=5.0 ! step in solar longitude in TES files
136! Solar longitude in TES files, TESls(1)=2.5 to TESls(72)=357.5
137real,save :: TESls(TESlssize)
138! TES North albedo (=-1 for missing values)
139real,save :: TESalbn(TESlonsize,TESlatsize,TESlssize)
140! TES South albedo (=-1 for missing values)
141real,save :: TESalbs(TESlonsize,TESlatsize,TESlssize)
142! encompassing nodes arranged as follow : 4 3
143real :: val(4)                          ! 1 2
144
145!NetCDF variables:
146integer :: ierr ! NetCDF status
147integer :: nid ! NetCDF file ID
148integer :: nvarid ! NetCDF variable ID
149
150! 0. Preliminary stuff
151if (firstcall) then
152! Load TES albedoes for Northern Hemisphere
[1918]153  ierr=nf90_open(trim(datadir)//"/npsc_albedo.nc",NF90_NOWRITE,nid)
[1130]154  IF (ierr.NE.NF90_NOERR) THEN
[38]155    write(*,*)'Problem opening npsc_albedo.nc (phymars/albedocaps.F90)'
[1918]156    write(*,*)'It should be in :',trim(datadir),'/'
[707]157    write(*,*)'1) You can change this directory address in callfis.def with'
158    write(*,*)'   datadir=/path/to/datafiles'
[38]159    write(*,*)'2) If necessary, npsc_albedo.nc (and other datafiles)'
160    write(*,*)'   can be obtained online on:'
[1381]161    write(*,*)'   http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
[38]162    CALL ABORT
[1130]163  ELSE
[1918]164    write(*,*) "albedocaps: using file ",trim(datadir)//"/npsc_albedo.nc"
[38]165  ENDIF
166 
[1130]167  ierr=nf90_inq_varid(nid,"longitude",nvarid)
168  if (ierr.ne.NF90_NOERR) then
[38]169    write(*,*) "Failed to find longitude in file!"
[1130]170    write(*,*)trim(nf90_strerror(ierr))
171    stop
[38]172  else
[1130]173    ierr=nf90_get_var(nid,nvarid,TESlon)
174    if (ierr.ne.NF90_NOERR) then
175      write(*,*) "Failed loading longitude data from file!"
176      write(*,*)trim(nf90_strerror(ierr))
177      stop
178    endif
[38]179  endif
180 
[1130]181  ierr=nf90_inq_varid(nid,"latitude",nvarid)
182  if (ierr.ne.NF90_NOERR) then
[38]183    write(*,*) "Failed to find latitude in file!"
[1130]184    write(*,*)trim(nf90_strerror(ierr))
185    stop
[38]186  else
[1130]187    ierr=nf90_get_var(nid,nvarid,TESlatn)
188    if (ierr.ne.NF90_NOERR) then
189      write(*,*) "Failed loading latitude data from file!"
190      write(*,*)trim(nf90_strerror(ierr))
191      stop
192    endif
[38]193  endif
194 
[1130]195  ierr=nf90_inq_varid(nid,"time",nvarid)
196  if (ierr.ne.NF90_NOERR) then
[38]197    write(*,*) "Failed to find time in file!"
[1130]198    write(*,*)trim(nf90_strerror(ierr))
199    stop
[38]200  else
[1130]201    ierr=nf90_get_var(nid,nvarid,TESls)
202    if (ierr.ne.NF90_NOERR) then
203      write(*,*) "Failed loading time data from file!"
204      write(*,*)trim(nf90_strerror(ierr))
205      stop
206    endif
[38]207  endif
208 
[1130]209  ierr=nf90_inq_varid(nid,"albedo",nvarid)
210  if (ierr.ne.NF90_NOERR) then
[38]211    write(*,*) "Failed to find albedo in file!"
[1130]212    write(*,*)trim(nf90_strerror(ierr))
213    stop
[38]214  else
[1130]215    ierr=nf90_get_var(nid,nvarid,TESalbn)
216    if (ierr.ne.NF90_NOERR) then
217      write(*,*) "Failed loading albedo data from file!"
218      write(*,*)trim(nf90_strerror(ierr))
219      stop
220    endif
[38]221  endif
222
[1130]223  ierr=nf90_close(nid)
224
[38]225! Load albedoes for Southern Hemisphere
[1918]226  ierr=nf90_open(trim(datadir)//"/spsc_albedo.nc",NF90_NOWRITE,nid)
[1130]227  IF (ierr.NE.NF90_NOERR) THEN
[38]228    write(*,*)'Problem opening spsc_albedo.nc (phymars/albedocaps.F90)'
[1918]229    write(*,*)'It should be in :',trim(datadir),'/'
[707]230    write(*,*)'1) You can change this directory address in callfis.def with'
231    write(*,*)'   datadir=/path/to/datafiles'
[38]232    write(*,*)'2) If necessary, spsc_albedo.nc (and other datafiles)'
233    write(*,*)'   can be obtained online on:'
[1381]234    write(*,*)'   http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
[38]235    CALL ABORT
[1130]236  ELSE
[1918]237    write(*,*) "albedocaps: using file ",trim(datadir)//"/spsc_albedo.nc"
[38]238  ENDIF
239
[1130]240  ierr=nf90_inq_varid(nid,"latitude",nvarid)
241  if (ierr.ne.NF90_NOERR) then
[38]242    write(*,*) "Failed to find latitude in file!"
[1130]243    write(*,*)trim(nf90_strerror(ierr))
244    stop
[38]245  else
[1130]246    ierr=nf90_get_var(nid,nvarid,TESlats)
247    if (ierr.ne.NF90_NOERR) then
248      write(*,*) "Failed loading latitude data from file!"
249      write(*,*)trim(nf90_strerror(ierr))
250      stop
251    endif
[38]252  endif
253
[1130]254  ierr=nf90_inq_varid(nid,"albedo",nvarid)
255  if (ierr.ne.NF90_NOERR) then
[38]256    write(*,*) "Failed to find albedo in file!"
[1130]257    write(*,*)trim(nf90_strerror(ierr))
258    stop
[38]259  else
[1130]260    ierr=nf90_get_var(nid,nvarid,TESalbs)
261    if (ierr.ne.NF90_NOERR) then
262      write(*,*) "Failed loading albedo data from file!"
263      write(*,*)trim(nf90_strerror(ierr))
264      stop
265    endif
[38]266  endif
267
[1130]268  ierr=nf90_close(nid)
269
[38]270! constants:
271  pi=acos(-1.)
272  radeg=180/pi
273
274  zls_old=-999 ! dummy initialization
275
276  firstcall=.false.
277endif ! of if firstcall
278
[801]279! 1. Identify encompassing latitudes
[38]280
281! Check that latitude is such that there is TES data to use
282! (ie: latitude 45 deg and poleward) otherwise use 'default' albedoes
[1541]283latd=latitude(ig)*radeg ! latitude, in degrees
[38]284if (icap.eq.1) then
285 ! North hemisphere
286 if (latd.lt.TESlatnmin) then
287   alb=albedice(1)
288   ! the job is done; quit this routine
289   return
290 else
291   ! find encompassing latitudes
292   if (latd.ge.TESlatn(TESlatsize)) then
293     latinf=TESlatsize
294     latsup=TESlatsize
295     rellat=0.
296   else
297     do i=1,TESlatsize-1
298       if ((latd.ge.TESlatn(i)).and.(latd.lt.TESlatn(i+1))) then
299         latinf=i
300         latsup=i+1
301         rellat=(latd-TESlatn(i))/TESdeltalat
302         exit ! found encompassing indexes; quit loop
303       endif
304     enddo
305   endif
306 endif ! of if (latd.lt.TESlatnmin)
307else ! icap=2
308 ! South hemisphere
309 if (latd.gt.TESlatsmax) then
310   alb=albedice(2)
311   ! the job is done; quit this routine
312   return
313 else
314   ! find encompassing latitudes
315   if (latd.lt.TESlats(1)) then
316     latinf=1
317     latsup=1
318     rellat=0.
319   else
320     do i=1,TESlatsize-1
321       if ((latd.ge.TESlats(i)).and.(latd.lt.TESlats(i+1))) then
322         latinf=i
323         latsup=i+1
324         rellat=(latd-TESlats(i))/TESdeltalat
325         exit ! found encompassing indexes; quit loop
326       endif
327     enddo
328   endif
329 endif ! of if (latd.gt.-45.)
330endif ! of if (icap.eq.1)
331
332! 2. Identify encompassing time indexes
333if (zls.ne.zls_old) then
334  zlsd=zls*radeg ! solar longitude, in degrees
335 
336  if (zlsd.lt.TESls(1)) then
337    tinf=TESlssize
338    tsup=1
339    reltime=0.5+zlsd/TESdeltals
340  else
341    if (zlsd.ge.TESls(TESlssize)) then
342      tinf=TESlssize
343      tsup=1
344      reltime=(360.-zlsd)/TESdeltals
345    else
346      ! look for encompassing indexes
347      do i=1,TESlssize-1
348        if ((zlsd.ge.TESls(i)).and.(zlsd.lt.TESls(i+1))) then
349          tinf=i
350          tsup=i+1
351          reltime=(zlsd-TESls(i))/TESdeltals
352          exit ! quit loop, we found the indexes
353        endif
354      enddo
355    endif
356  endif ! of if (zlsd.lt.TESls(1))
357 
358  zls_old=zls ! store current zls
359endif ! of if (zls.ne.zls_old)
360
361! 3. Identify encompassing longitudes
[1541]362lond=longitude(ig)*radeg ! east longitude, in degrees
[38]363if (lond.lt.TESlon(1)) then
364  loninf=TESlonsize
365  lonsup=1
366  rellon=0.5+(180.+lond)/TESdeltalon
367else
368  if (lond.ge.TESlon(TESlonsize)) then
369    loninf=TESlonsize
370    lonsup=1
371    rellon=(180-lond)/TESdeltalon
372  else
373    do i=1,TESlonsize-1
374      if ((lond.ge.TESlon(i)).and.(lond.lt.TESlon(i+1))) then
375        loninf=i
376        lonsup=i+1
377        rellon=(lond-TESlon(i))/TESdeltalon
378        exit ! quit loop, we found the indexes
379      endif
380    enddo
381  endif ! of if (lond.ge.TESlon(TESlonsize))
382endif ! of if (lond.lt.TESlon(1))
383
384! 4. Use linear interpolation in time to build encompassing nodal values
385!    encompassing nodes are arranged as follow : 4 3
386!                                                1 2
387if (icap.eq.1) then
388  ! Northern hemisphere
389  val(1)=(1.-reltime)*TESalbn(loninf,latinf,tinf) &
390         +reltime*TESalbn(loninf,latinf,tsup)
391  val(2)=(1.-reltime)*TESalbn(lonsup,latinf,tinf) &
392         +reltime*TESalbn(lonsup,latinf,tsup)
393  val(3)=(1.-reltime)*TESalbn(lonsup,latsup,tinf) &
394         +reltime*TESalbn(lonsup,latsup,tsup)
395  val(4)=(1.-reltime)*TESalbn(loninf,latsup,tinf) &
396         +reltime*TESalbn(loninf,latsup,tsup)
397else
398  ! Southern hemisphere
399  val(1)=(1.-reltime)*TESalbs(loninf,latinf,tinf) &
400         +reltime*TESalbs(loninf,latinf,tsup)
401  val(2)=(1.-reltime)*TESalbs(lonsup,latinf,tinf) &
402         +reltime*TESalbs(lonsup,latinf,tsup)
403  val(3)=(1.-reltime)*TESalbs(lonsup,latsup,tinf) &
404         +reltime*TESalbs(lonsup,latsup,tsup)
405  val(4)=(1.-reltime)*TESalbs(loninf,latsup,tinf) &
406         +reltime*TESalbs(loninf,latsup,tsup)
407endif ! of if (icap.eq.1)
408
409! 5. Use bilinear interpolation to compute albedo
410alb=(1.-rellon)*(1.-rellat)*val(1) &
411    +rellon*(1.-rellat)*val(2) &
412    +rellon*rellat*val(3) &
413    +(1.-rellon)*rellat*val(4)
414
415! 6. Apply coefficient to interpolated TES albedo
416if (icap.eq.1) then
417  alb=alb*TESice_Ncoef
418else
419  alb=alb*TESice_Scoef
420endif ! of if (icap.eq.1)
421
[707]422! Make sure that returned albedo is never greater than 0.90
423if (alb.gt.0.90) alb=0.90
424
[38]425end subroutine TES_icecap_albedo
426
Note: See TracBrowser for help on using the repository browser.