#if defined(DOC)
!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
#endif
#include "nbvarsurf.cdk"
#include "dimsurf.cdk"

#define INIT_LOCBUS() \
do i=1,nvarsurf ~~\
   if (niveaux(i).gt.1) then ~~\
         quelnivo(i) = nk ~~\
   else if (mul(i).eq.1) then ~~\
      quelnivo(i) = 1 ~~\
   else if(mul(i).gt.1.and.(statut(i,1).eq.statut(i,mul(i)))) then ~~\
      quelnivo(i) = -1 ~~\
   else ~~\
      quelnivo(i) = indx_sfc ~~\
   endif ~~\
end do

#define LOCBUS(_POINTEUR_,_VAR_,_LVL_) \
if (_LVL_.le.0.or._LVL_.eq.quelnivo(_VAR_)) then ~~\
    if (quelnivo(_VAR_).gt.0) then ~~\
      _POINTEUR_ =  LOC(BUS(X(_VAR_,1,quelnivo(_VAR_)))) ~~\
    else ~~\
      write (6,'(1x,//,a,i6,a,a//)') \
      'UNDEFINED LEVEL AT LINE ',__LINE__,' IN FILE ', __FILE__~~\
      call qqexit(1) ~~\
    endif ~~\
else ~~\
    if (_LVL_.gt.0.and._LVL_.le.mul(_VAR_).and.indx_sfc.eq.statut(_VAR_,_LVL_)) then ~~\
       _POINTEUR_ = LOC(BUS(X(_VAR_,1,_LVL_))) ~~\
    else ~~\
       write (6,'(1x,//,a,i6,a,a//)') \
       'WRONG LEVEL AT LINE ',__LINE__,' IN FILE ', __FILE__~~\
       call qqexit(1) ~~\
    endif ~~\
endif

#define LOCBUS_MOS(_POINTEUR_,_VAR_,_LVL_,_MOS_) \
if (_MOS_.gt.(mosaik(_VAR_)-1).or._MOS_.lt.0) then ~~\
   write (6,'(1x,//,a,i6,a,a//)') \
   'WRONG MOSAIC LEVEL AT LINE ',__LINE__,' IN FILE ', __FILE__~~\
   call qqexit(1) ~~\
endif ~~\
if (_LVL_.le.0.or._LVL_.eq.quelnivo(_VAR_)) then ~~\
    if (quelnivo(_VAR_).gt.0) then ~~\
      _POINTEUR_ =  LOC(BUS(X(_VAR_,1,_MOS_*mul(_VAR_)+quelnivo(_VAR_)))) ~~\
    else ~~\
      write (6,'(1x,//,a,i6,a,a//)') \
      'UNDEFINED LEVEL AT LINE ',__LINE__,' IN FILE ', __FILE__~~\
      call qqexit(1) ~~\
    endif ~~\
else ~~\
    if (_LVL_.gt.0.and._LVL_.le.mul(_VAR_).and.indx_sfc.eq.statut(_VAR_,_LVL_)) then ~~\
       _POINTEUR_ = LOC(BUS(X(_VAR_,1,_MOS_*mul(_VAR_)+_LVL_))) ~~\
    else ~~\
       write (6,'(1x,//,a,i6,a,a//)') \
       'WRONG LEVEL AT LINE ',__LINE__,' IN FILE ', __FILE__~~\
       call qqexit(1) ~~\
    endif ~~\
endif