c     Copyright (C)
c     2010-2013 Université Bordeaux 1
c     2010-2013 Ecole des Mines d'Albi
c     2014-2018 - Mesostar
c     
c     This program is free software; you can redistribute it and/or modify
c     it under the terms of the GNU General Public License as published by
c     the Free Software Foundation; either version 2, or (at your option)
c     any later version.

c     This program is distributed in the hope that it will be useful,
c     but WITHOUT ANY WARRANTY; without even the implied warranty of
c     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c     GNU General Public License for more details.

c     You should have received a copy of the GNU General Public License
c     along with this program; if not, write to the Free Software
c     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
c     USA.
c
      double precision function dBdLambda(T)

      implicit none

      double precision in,c1,c2,T,lambda
      integer Nb,Nq,band,quad
      common/comfreq/Nb,Nq,band,quad

c     Cette function calcule la dérivée de la luminance de Planck
c     par rapport à la longueur d'onde
c     à une valeur de la température et de la longueur d'onde
c
c     Entrées :
c       + T : température en Kelvin
c       + en common/comfreq : band ; numéro de la bande étroite
c
c     Sorties :
c       + dBdLambda : valeur de la dérivée de la luminance de Planck
c                     par rapprt à la longueur d'onde
c

      include 'max.inc'
      include 'param.inc'
      include 'data.inc'

      c1=2*pi*hPl*c0**2 ! W.m2
      c2=hPl*c0/kBz*1.D+6 ! µm.K
c     ATTENTION ! lambda doit être entrée en micromètres !

c      write(*,*) 'c1=',c1,'W.m2'
c      write(*,*) 'c2=',c2,'µm.K'
      lambda=(lambda_hi(band)+lambda_lo(band))/2.0D+0

      if (T.eq.0) then
         dBdLambda=0.0D+0
      else
         dBdLambda=1.0D+24/pi*(c1*c2/(T*lambda**7)
     &        *dexp(c2/(T*lambda))/(dexp(c2/(T*lambda))
     &        -1.0D+0)**2-5.0D+0*c1/lambda**6/
     &        (dexp(c2/(T*lambda))-1.0D+0))
      endif

      return
      end
