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

Last change on this file since 1934 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
Line 
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
7use ioipsl_getincom, only: getin
8use geometry_mod, only: latitude ! grid point latitudes (rad)
9use surfdat_h, only: TESicealbedo, TESice_Ncoef, TESice_Scoef, &
10                     emisice, albedice, watercaptag, albedo_h2o_ice, &
11                     emissiv, albedodat
12implicit none
13
14include"callkeys.h"
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
29! AS: OK firstcall absolute
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
54  if (latitude(ig).lt.0.) then
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
65      call TES_icecap_albedo(zls,ig,psolaralb(ig,1),icap)
66      psolaralb(ig,2)=psolaralb(ig,1)
67    else
68      psolaralb(ig,1)=albedice(icap)
69      psolaralb(ig,2)=albedice(icap)
70    endif
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
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
88subroutine TES_icecap_albedo(zls,ig,alb,icap)
89
90use geometry_mod, only: latitude, longitude ! in radians
91use surfdat_h, only: albedice, TESice_Ncoef, TESice_Scoef
92use datafile_mod, only: datadir
93use netcdf, only: nf90_open, NF90_NOWRITE, NF90_NOERR, &
94                  nf90_strerror, nf90_inq_varid, nf90_get_var, nf90_close
95                 
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
102integer :: icap ! =1: Northern hemisphere =2: Southern hemisphere
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
153  ierr=nf90_open(trim(datadir)//"/npsc_albedo.nc",NF90_NOWRITE,nid)
154  IF (ierr.NE.NF90_NOERR) THEN
155    write(*,*)'Problem opening npsc_albedo.nc (phymars/albedocaps.F90)'
156    write(*,*)'It should be in :',trim(datadir),'/'
157    write(*,*)'1) You can change this directory address in callfis.def with'
158    write(*,*)'   datadir=/path/to/datafiles'
159    write(*,*)'2) If necessary, npsc_albedo.nc (and other datafiles)'
160    write(*,*)'   can be obtained online on:'
161    write(*,*)'   http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
162    CALL ABORT
163  ELSE
164    write(*,*) "albedocaps: using file ",trim(datadir)//"/npsc_albedo.nc"
165  ENDIF
166 
167  ierr=nf90_inq_varid(nid,"longitude",nvarid)
168  if (ierr.ne.NF90_NOERR) then
169    write(*,*) "Failed to find longitude in file!"
170    write(*,*)trim(nf90_strerror(ierr))
171    stop
172  else
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
179  endif
180 
181  ierr=nf90_inq_varid(nid,"latitude",nvarid)
182  if (ierr.ne.NF90_NOERR) then
183    write(*,*) "Failed to find latitude in file!"
184    write(*,*)trim(nf90_strerror(ierr))
185    stop
186  else
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
193  endif
194 
195  ierr=nf90_inq_varid(nid,"time",nvarid)
196  if (ierr.ne.NF90_NOERR) then
197    write(*,*) "Failed to find time in file!"
198    write(*,*)trim(nf90_strerror(ierr))
199    stop
200  else
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
207  endif
208 
209  ierr=nf90_inq_varid(nid,"albedo",nvarid)
210  if (ierr.ne.NF90_NOERR) then
211    write(*,*) "Failed to find albedo in file!"
212    write(*,*)trim(nf90_strerror(ierr))
213    stop
214  else
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
221  endif
222
223  ierr=nf90_close(nid)
224
225! Load albedoes for Southern Hemisphere
226  ierr=nf90_open(trim(datadir)//"/spsc_albedo.nc",NF90_NOWRITE,nid)
227  IF (ierr.NE.NF90_NOERR) THEN
228    write(*,*)'Problem opening spsc_albedo.nc (phymars/albedocaps.F90)'
229    write(*,*)'It should be in :',trim(datadir),'/'
230    write(*,*)'1) You can change this directory address in callfis.def with'
231    write(*,*)'   datadir=/path/to/datafiles'
232    write(*,*)'2) If necessary, spsc_albedo.nc (and other datafiles)'
233    write(*,*)'   can be obtained online on:'
234    write(*,*)'   http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
235    CALL ABORT
236  ELSE
237    write(*,*) "albedocaps: using file ",trim(datadir)//"/spsc_albedo.nc"
238  ENDIF
239
240  ierr=nf90_inq_varid(nid,"latitude",nvarid)
241  if (ierr.ne.NF90_NOERR) then
242    write(*,*) "Failed to find latitude in file!"
243    write(*,*)trim(nf90_strerror(ierr))
244    stop
245  else
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
252  endif
253
254  ierr=nf90_inq_varid(nid,"albedo",nvarid)
255  if (ierr.ne.NF90_NOERR) then
256    write(*,*) "Failed to find albedo in file!"
257    write(*,*)trim(nf90_strerror(ierr))
258    stop
259  else
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
266  endif
267
268  ierr=nf90_close(nid)
269
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
279! 1. Identify encompassing latitudes
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
283latd=latitude(ig)*radeg ! latitude, in degrees
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
362lond=longitude(ig)*radeg ! east longitude, in degrees
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
422! Make sure that returned albedo is never greater than 0.90
423if (alb.gt.0.90) alb=0.90
424
425end subroutine TES_icecap_albedo
426
Note: See TracBrowser for help on using the repository browser.