Index: trunk/LMDZ.GENERIC/README
===================================================================
--- trunk/LMDZ.GENERIC/README	(revision 2621)
+++ trunk/LMDZ.GENERIC/README	(revision 2625)
@@ -1711,2 +1711,6 @@
 Minor bug fix for the (rather specific) case when there is no surface and
 inertiedat() is not defined.
+
+== 22/02/2022 == GM
+Minor bug fix for aerave_new.F when input wavelenght in data file are in 
+descending order.
Index: trunk/LMDZ.GENERIC/libf/phystd/aerave_new.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/aerave_new.F	(revision 2621)
+++ trunk/LMDZ.GENERIC/libf/phystd/aerave_new.F	(revision 2625)
@@ -55,6 +55,6 @@
 c.......................................................................
 c
-      INTEGER iir,nirmx
-      PARAMETER (nirmx=100)
+      INTEGER iir
+      INTEGER,PARAMETER :: nirmx=100
       INTEGER idata,ndata
 c
@@ -66,6 +66,6 @@
      &    ,omegdata(ndata),gdata(ndata)
       REAL qextcorrdata(ndata)
-      INTEGER ibande,nbande
-      PARAMETER (nbande=1000)
+      INTEGER ibande
+      INTEGER,PARAMETER :: nbande=1000
       REAL long,deltalong
       INTEGER ilong
@@ -83,124 +83,209 @@
       long=longref
 
-
-      !if(nir.eq.27)then
-      !print*,'long',long
-      !print*,'longdata',longdata
-      !print*,'epdata',epdata
-      !print*,'omegdata',omegdata
-      !print*,'gdata',gdata
-      !print*,'data looks aok!'
-
-      !print*,'ndata=',ndata
-      !print*,'longdata',shape(longdata)
-      !print*,'epdata',shape(epdata)
-      !print*,'omegdata',shape(omegdata)
-      !print*,'gdata',shape(gdata)
-      ! print*,'longref',longref
-      !print*,'epref',epref
-      !print*,'temp',temp
-      !print*,'nir',nir
-      !print*,'longir',longir
-      !print*,'epir',epir
-      !print*,'omegir',gir
-      !print*,'qref',qref
-      !print*,'longir=',longir
-      !stop
-      !endif
+c check ordering of longdata
+      DO idata=1,ndata-1
+        IF (longdata(1).LT.longdata(ndata)) THEN
+          IF (.not.(longdata(idata).LT.longdata(idata+1))) THEN
+           call abort_physic("aerave_new", 
+     &     "Non descending order in longdata",1)
+          ENDIF
+        ELSEIF (longdata(1).GT.longdata(ndata)) THEN
+          IF (.not.(longdata(idata).GT.longdata(idata+1))) THEN
+           call abort_physic("aerave_new",
+     &     "Non ascending order in longdata",1)
+          ENDIF
+        ENDIF
+      ENDDO
+c
+      
+        
 
 
 c********************************************************
 c interpolation
-      ilong=1
-      DO idata=2,ndata
-        IF (long.gt.longdata(idata)) ilong=idata
-      ENDDO
-      i1=ilong
-      i2=ilong+1
-      IF (i2.gt.ndata) i2=ndata
-      IF (long.lt.longdata(1)) i2=1
-      IF (i1.eq.i2) THEN
-        c1=1.E+0
-        c2=0.E+0
-      ELSE
-        c1=(longdata(i2)-long) / (longdata(i2)-longdata(i1))
-        c2=(longdata(i1)-long) / (longdata(i1)-longdata(i2))
+c wavelengths (longdata) from data file in ascending order
+      IF (longdata(1).LT.longdata(ndata)) THEN
+        ilong=1
+        DO idata=2,ndata
+          IF (long.gt.longdata(idata)) ilong=idata
+        ENDDO
+        i1=ilong
+        i2=ilong+1
+        IF (i2.gt.ndata) i2=ndata
+        IF (long.lt.longdata(1)) i2=1
+        IF (i1.eq.i2) THEN
+          c1=1.E+0
+          c2=0.E+0
+        ELSE
+          c1=(longdata(i2)-long) / (longdata(i2)-longdata(i1))
+          c2=(longdata(i1)-long) / (longdata(i1)-longdata(i2))
+        ENDIF
+        qref=c1*epdata(i1)+c2*epdata(i2)
+        omegaref=c1*omegdata(i1)+c2*omegdata(i2)
+        factep=qref/epref
+        DO idata=1,ndata
+          qextcorrdata(idata)=epdata(idata)/factep
+        ENDDO
+c wavelengths (longdata) from data file in descending order
+      ELSEIF (longdata(1).GT.longdata(ndata)) THEN
+        ilong=1
+        DO idata=2,ndata
+          IF (long.lt.longdata(idata)) ilong=idata
+        ENDDO
+        i1=ilong+1
+        i2=ilong
+        IF (i1.gt.ndata) i1=ndata
+        IF (long.gt.longdata(1)) i1=1
+        IF (i1.eq.i2) THEN
+          c1=1.E+0
+          c2=0.E+0
+        ELSE
+          c1=(longdata(i2)-long) / (longdata(i2)-longdata(i1))
+          c2=(longdata(i1)-long) / (longdata(i1)-longdata(i2))
+        ENDIF
+        qref=c1*epdata(i1)+c2*epdata(i2)
+        omegaref=c1*omegdata(i1)+c2*omegdata(i2)
+        factep=qref/epref
+        DO idata=1,ndata
+          qextcorrdata(idata)=epdata(idata)/factep
+        ENDDO
       ENDIF
+
 c********************************************************
-c
-      qref=c1*epdata(i1)+c2*epdata(i2)
-      omegaref=c1*omegdata(i1)+c2*omegdata(i2)
-      factep=qref/epref
-      DO idata=1,ndata
-        qextcorrdata(idata)=epdata(idata)/factep
-      ENDDO
-c
-c.......................................................................
-c
-      DO iir=1,nir
-c
-c.......................................................................
-c
-        deltalong=(longir(iir+1)-longir(iir)) / nbande
-        totalemit(iir)=0.E+0
-        epir(iir)=0.E+0
-        omegir(iir)=0.E+0
-        gir(iir)=0.E+0
-c
-c.......................................................................
-c
-        DO ibande=1,nbande
-c
-c.......................................................................
-c
-          long=longir(iir) + (ibande-0.5E+0) * deltalong
-          CALL blackl(DBLE(long),DBLE(temp),tmp1)
-          emit=REAL(tmp1)
-c
-c.......................................................................
+c.......................................................................
+c wavelengths (longdata) from data file in ascending order
+c.......................................................................
+      IF (longdata(1).LT.longdata(ndata)) THEN 
+        DO iir=1,nir
+c
+c.......................................................................
+c
+          deltalong=(longir(iir+1)-longir(iir)) / nbande
+          totalemit(iir)=0.E+0
+          epir(iir)=0.E+0
+          omegir(iir)=0.E+0
+          gir(iir)=0.E+0
+c
+c.......................................................................
+c
+          DO ibande=1,nbande
+c
+c.......................................................................
+c
+            long=longir(iir) + (ibande-0.5E+0) * deltalong
+            CALL blackl(DBLE(long),DBLE(temp),tmp1)
+            emit=REAL(tmp1)
+c
+c.......................................................................
+c
+c interpolation
+            ilong=1
+            DO idata=2,ndata
+              IF (long.gt.longdata(idata)) ilong=idata
+            ENDDO
+            i1=ilong
+            i2=ilong+1
+            IF (i2.gt.ndata) i2=ndata
+            IF (long.lt.longdata(1)) i2=1
+            IF (i1.eq.i2) THEN
+              c1=1.E+0
+              c2=0.E+0
+            ELSE
+              c1=(longdata(i2)-long) / (longdata(i2)-longdata(i1))
+              c2=(longdata(i1)-long) / (longdata(i1)-longdata(i2))
+            ENDIF
+            qextcorr=c1*qextcorrdata(i1)+c2*qextcorrdata(i2)
+            omeg=c1*omegdata(i1)+c2*omegdata(i2)
+            g=c1*gdata(i1)+c2*gdata(i2)
+c
+c.......................................................................
+c
+            totalemit(iir)=totalemit(iir)+deltalong*emit
+            epir(iir)=epir(iir)+deltalong*emit*qextcorr
+            omegir(iir)=omegir(iir)+deltalong*emit*omeg*qextcorr
+            gir(iir)=gir(iir)+deltalong*emit*omeg*qextcorr*g
+c
+c.......................................................................
+c
+          ENDDO
+c
+c.......................................................................
+c
+          gir(iir)=gir(iir)/omegir(iir)
+          omegir(iir)=omegir(iir)/epir(iir)
+          epir(iir)=epir(iir)/totalemit(iir)
+c
+c.......................................................................
+c
+        ENDDO
+c.......................................................................
+c wavelengths (longdata) from data file in descending order
+c.......................................................................
+      ELSEIF (longdata(1).GT.longdata(ndata)) THEN
+        DO iir=1,nir
+c
+c.......................................................................
+c
+          deltalong=(longir(iir+1)-longir(iir)) / nbande
+          totalemit(iir)=0.E+0
+          epir(iir)=0.E+0
+          omegir(iir)=0.E+0
+          gir(iir)=0.E+0
+c
+c.......................................................................
+c
+          DO ibande=1,nbande
+c
+c.......................................................................
+c
+            long=longir(iir) + (ibande-0.5E+0) * deltalong
+            CALL blackl(DBLE(long),DBLE(temp),tmp1)
+            emit=REAL(tmp1)
+c
+c.......................................................................
+c
+c interpolation
+            ilong=1
+            DO idata=2,ndata
+              IF (long.lt.longdata(idata)) ilong=idata
+            ENDDO
+            i1=ilong+1
+            i2=ilong
+            IF (i1.gt.ndata) i1=ndata
+            IF (long.gt.longdata(1)) i1=1
+            IF (i1.eq.i2) THEN
+              c1=1.E+0
+              c2=0.E+0
+            ELSE
+              c1=(longdata(i2)-long) / (longdata(i2)-longdata(i1))
+              c2=(longdata(i1)-long) / (longdata(i1)-longdata(i2))
+            ENDIF
+            qextcorr=c1*qextcorrdata(i1)+c2*qextcorrdata(i2)
+            omeg=c1*omegdata(i1)+c2*omegdata(i2)
+            g=c1*gdata(i1)+c2*gdata(i2)
+c
+c.......................................................................
+c
+            totalemit(iir)=totalemit(iir)+deltalong*emit
+            epir(iir)=epir(iir)+deltalong*emit*qextcorr
+            omegir(iir)=omegir(iir)+deltalong*emit*omeg*qextcorr
+            gir(iir)=gir(iir)+deltalong*emit*omeg*qextcorr*g
+c
+c.......................................................................
+c
+          ENDDO
+c
+c.......................................................................
+c
+          gir(iir)=gir(iir)/omegir(iir)
+          omegir(iir)=omegir(iir)/epir(iir)
+          epir(iir)=epir(iir)/totalemit(iir)
+c
+c.......................................................................
+c
+        ENDDO
+      ENDIF
 c
 c********************************************************
-c interpolation
-      ilong=1
-      DO idata=2,ndata
-        IF (long.gt.longdata(idata)) ilong=idata
-      ENDDO
-      i1=ilong
-      i2=ilong+1
-      IF (i2.gt.ndata) i2=ndata
-      IF (long.lt.longdata(1)) i2=1
-      IF (i1.eq.i2) THEN
-        c1=1.E+0
-        c2=0.E+0
-      ELSE
-        c1=(longdata(i2)-long) / (longdata(i2)-longdata(i1))
-        c2=(longdata(i1)-long) / (longdata(i1)-longdata(i2))
-      ENDIF
-c********************************************************
-c
-          qextcorr=c1*qextcorrdata(i1)+c2*qextcorrdata(i2)
-          omeg=c1*omegdata(i1)+c2*omegdata(i2)
-          g=c1*gdata(i1)+c2*gdata(i2)
-c
-c.......................................................................
-c
-          totalemit(iir)=totalemit(iir)+deltalong*emit
-          epir(iir)=epir(iir)+deltalong*emit*qextcorr
-          omegir(iir)=omegir(iir)+deltalong*emit*omeg*qextcorr
-          gir(iir)=gir(iir)+deltalong*emit*omeg*qextcorr*g
-c
-c.......................................................................
-c
-        ENDDO
-c
-c.......................................................................
-c
-        gir(iir)=gir(iir)/omegir(iir)
-        omegir(iir)=omegir(iir)/epir(iir)
-        epir(iir)=epir(iir)/totalemit(iir)
-c
-c.......................................................................
-c
-      ENDDO
 c
 c......................................................................
@@ -220,4 +305,3 @@
 c......................................................................
 c
-      RETURN
       END
