!-------------------------------------- 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 --------------------------------------
***s/r itf_chm_getindx
*
#include "model_macros_f.h"
*

      subroutine itf_chm_getindx ( F_vn_S, F_bus_S, F_deb, F_nm, F_init ) 1,1
      implicit none
*
      character*(*) F_vn_S
      character*1   F_bus_S
      integer       F_deb,F_nm,F_init
*
*author 
*     A. Kallaur - arqi - june 2005
*
*revision
* v3_30 - Kallaur A.       - initial version
*
*object
*     Obtain starting index "F_deb", length "F_nm" and init requirement
*     "F_init" for variable "F_vn_S" on bus "F_bus_S".
*
*arguments
*  Name        I/O                 Description
*----------------------------------------------------------------
*  F_vn_S       I            Name of the variable
*  F_bus_S      I            F_bus_S (D,P,V,G)
*  F_deb        O            Starting index on F_bus_S
*  F_nm         O            Length of variable F_vn_S
*  F_init       O            Initialysation requirement (1=yes)
*----------------------------------------------------------------
*
*implicites
#include "itf_chm_bus.cdk"
*
**
      integer i,init
*
*-------------------------------------------------------------------
*
      F_deb = -1
      F_nm  = 0
      if (F_bus_S.eq.'E') then
         do 5 i=1,chm_bent_top
            if (F_vn_S.eq.chmentnm(i)) then
               F_deb = chmentpar(i,1)
               F_nm  = chmentpar(i,2)
               init  = chmentpar(i,3)
               goto 601
            endif
 5       continue 
         if (F_init.lt.0) goto 601
         write (6,910) F_vn_S,'CHM_BUSENT'
      endif
*
      if (F_bus_S.eq.'D') then
         do 10 i=1,chm_bdyn_top
            if (F_vn_S.eq.chmdynnm(i)) then
               F_deb = chmdynpar(i,1)
               F_nm  = chmdynpar(i,2)
               init  = chmdynpar(i,3)
               goto 601
            endif
 10      continue 
         if (F_init.lt.0) goto 601
         write (6,910) F_vn_S,'CHM_BUSDYN'
      endif
*
      if (F_bus_S.eq.'P') then
         do 20 i=1,chm_bper_top
            if (F_vn_S.eq.chmpernm(i)) then
               F_deb = chmperpar(i,1)
               F_nm  = chmperpar(i,2)
               init  = chmperpar(i,3)
               goto 601
            endif
 20      continue 
         if (F_init.lt.0) goto 601
         write (6,910) F_vn_S,'CHM_BUSPER'
      endif
*
      if (F_bus_S.eq.'V') then
         do 30 i=1,chm_bvol_top
            if (F_vn_S.eq.chmvolnm(i)) then
               F_deb = chmvolpar(i,1)
               F_nm  = chmvolpar(i,2)
               init  = chmvolpar(i,3)
               goto 601
            endif
 30      continue 
         if (F_init.lt.0) goto 601
         write (6,910) F_vn_S,'CHM_BUSVOL'
      endif
*
      call stopmpi(-1)
*
 601  if (F_init.ge.0) F_init = init
*
 910  format (/1x,'===> ABORT IN ITF_CHM_GETINDX: COULD NOT FIND'/
     $         1x,"     VARIABLE '",a8,"' ON '",a6,"'."/)
*
*-------------------------------------------------------------------
*
      return
      end