anchor.diff:  !          >0 if name is a number and a node with ID=name is in myrank
   
   function get_local_member_index( hecMESH, type_name, name, local_id )
  -        implicit none
  -        integer(kind=kint) :: get_local_member_index
  -        type (hecmwST_local_mesh),target :: hecMESH
  -        character(len=*) :: type_name
  -        character(len=*) :: name
  -        integer(kind=kint) :: local_id
  -
  -        integer(kind=kint) :: i, n, stat, no, fg
  -        integer(kind=kint),pointer :: global_item(:)
  -
  -        if( .not. fstr_str2index(name, no) ) then
  -                get_local_member_index = -1
  -                return
  -        end if
  -
  -        if( type_name == 'node' ) then
  -                fg = 1
  -                n  =  hecMESH%n_node
  -                global_item => hecMESH%global_node_ID
  -        else if( type_name == 'element' ) then
  -                fg = 2
  -                n  =  hecMESH%n_elem
  -                global_item => hecMESH%global_elem_ID
  -        else
  -                STOP 'assert in get_local_member_index: unknown type_name'
  -        end if
  -
  -        do i = 1, n
  -                if( no == global_item(i)) then
  -                        local_id = i
  -                        get_local_member_index = local_id
  -                        return
  -                end if
  -        end do
  -        local_id = 0
  -        get_local_member_index = 0
  -        return
  +  implicit none
  +  integer(kind=kint) :: get_local_member_index
  +  type (hecmwST_local_mesh),target :: hecMESH
  +  character(len=*) :: type_name
  +  character(len=*) :: name
  +  integer(kind=kint) :: local_id
  +  integer(kind=kint) :: i, n, stat, no, fg
  +  integer(kind=kint),pointer :: global_item(:)
  +
  +  if( .not. fstr_str2index(name, no) ) then
  +    get_local_member_index = -1
  +    return
  +  end if
  +
  +  if( type_name == 'node' ) then
  +    fg = 1
  +    n  =  hecMESH%n_node
  +    global_item => hecMESH%global_node_ID
  +  else if( type_name == 'element' ) then
  +    fg = 2
  +    n  =  hecMESH%n_elem
  +    global_item => hecMESH%global_elem_ID
  +  else
  +    STOP 'assert in get_local_member_index: unknown type_name'
  +  end if
  +
  +  do i = 1, n
  +    if( no == global_item(i)) then
  +      local_id = i
  +      get_local_member_index = local_id
  +      return
  +    end if
  +  end do
  +  local_id = 0
  +  get_local_member_index = 0
  +  return
   end function get_local_member_index
   
   !-----------------------------------------------------------------------------!
   !
   
   function get_sorted_local_member_index( hecMESH, hecPARAM, type_name, name, local_id )
  -        implicit none
  -        integer(kind=kint) :: get_sorted_local_member_index
  -        type (hecmwST_local_mesh),target :: hecMESH
  -        type(fstr_param), target         :: hecPARAM
  -        character(len=*) :: type_name
  -        character(len=*) :: name
  -        integer(kind=kint) :: local_id, idx
  -
  -        integer(kind=kint) :: i, n, stat, no, fg
  -        integer(kind=kint),pointer :: item(:)
  -
  -        if( .not. fstr_str2index(name, no) ) then
  -                get_sorted_local_member_index = -1
  -                return
  -        end if
  -
  -        if( type_name == 'node' ) then
  -                fg = 1
  -                n  =  hecMESH%nn_internal
  -!                item => hecMESH%global_node_ID
  -!        else if( type_name == 'element' ) then
  -!                fg = 2
  -!                n  =  hecMESH%n_elem
  -!                item => hecMESH%global_elem_ID
  -        else
  -                STOP 'assert in get_sorted_local_member_index: unknown type_name'
  -        end if
  -
  -        call bsearch_int_array(hecPARAM%global_local_ID(1,:), 1, n, no, idx)
  -        if(idx > 0)then
  -          get_sorted_local_member_index = hecPARAM%global_local_ID(2,idx)
  -          local_id = get_sorted_local_member_index
  -          return
  -        endif
  -
  -        get_sorted_local_member_index = 0
  -        return
  +  implicit none
  +  integer(kind=kint) :: get_sorted_local_member_index
  +  type (hecmwST_local_mesh),target :: hecMESH
  +  type(fstr_param), target         :: hecPARAM
  +  character(len=*) :: type_name
  +  character(len=*) :: name
  +  integer(kind=kint) :: local_id, idx
  +  integer(kind=kint) :: i, n, stat, no, fg
  +  integer(kind=kint),pointer :: item(:)
  +
  +  if( .not. fstr_str2index(name, no) ) then
  +    get_sorted_local_member_index = -1
  +    return
  +  end if
  +
  +  if( type_name == 'node' ) then
  +    fg = 1
  +    n  =  hecMESH%nn_internal
  +!   item => hecMESH%global_node_ID
  +! else if( type_name == 'element' ) then
  +!   fg = 2
  +!   n  =  hecMESH%n_elem
  +!   item => hecMESH%global_elem_ID
  +  else
  +    STOP 'assert in get_sorted_local_member_index: unknown type_name'
  +  end if
  +
  +  call bsearch_int_array(hecPARAM%global_local_ID(1,:), 1, n, no, idx)
  +  if(idx > 0)then
  +    get_sorted_local_member_index = hecPARAM%global_local_ID(2,idx)
  +    local_id = get_sorted_local_member_index
  +    return
  +  endif
  +
  +  get_sorted_local_member_index = 0
  +  return
   end function get_sorted_local_member_index
   !-----------------------------------------------------------------------------!
   
   !-----------------------------------------------------------------------------!
   !~/FrontISTR/hecmw1/src/solver/matrix/hecmw_matrix_reorder.f90
  +
   subroutine bsearch_int_array(array, istart, iend, val, idx)
     implicit none
     integer(kind=kint), intent(in) :: array(:)
  
positive.code: use hecmw
  include 'fstr_ctrl_util_f.inc'
  
          !> container of character array pointer, because of gfortran's bug
          type fstr_str_arr
                  character(len=HECMW_NAME_LEN), pointer :: s(:)
          end type fstr_str_arr
  
          !> private parameter and pointers to group members in hecMESH
  
          integer(kind=kint),private :: grp_type     ! 1:node_grp, 2:elem_grp, 3:surf_grp
          integer(kind=kint),pointer,private :: n_grp
          integer(kind=kint),pointer,private :: n_index(:)
          integer(kind=kint),pointer,private :: grp_index(:)
          integer(kind=kint),pointer,private :: grp_item(:)
          type(fstr_str_arr),private :: grp_name
          ! character(len=HECMW_NAME_LEN),pointer,private :: grp_name(:)
  
          ! private subroutines ------------
  
          private :: set_group_pointers
          private :: append_single_group
  
  contains
  
  
  !------------------------------------------------------------------------------
  
  function fstr_str2index( s, x )
          implicit none
          logical fstr_str2index
          character(*) :: s
          integer :: i, n, a, i0,i9, m, x, b
          logical :: fg
  
          fstr_str2index = .false.
          i0 = iachar('0')
          i9 = iachar('9')
          n = len_trim(s)
          x = 0
          b = 1
          fg = .true.
          do i=n,1,-1
                  fg = .false.
                  a = iachar(s(i:i))
                  if( a < i0 .or. a > i9 ) return
                  m = a-i0
                  x = x + b * m
                  b = b*10
          end do
          fstr_str2index = .true.
  end function fstr_str2index
  
  
  subroutine fstr_strupr( s )
    implicit none
  
negative.code: !------------------------------------------------------------------------------
  
  subroutine fstr_ctrl_err_stop
    implicit none
    character(len=256) :: msg
  
    call fstr_ctrl_get_err_msg( msg, 256 )
    write(*,*) msg
    write(imsg,*) msg
    call hecmw_abort( hecmw_comm_get_comm())
  end subroutine fstr_ctrl_err_stop
  
  !------------------------------------------------------------------------------
  
  subroutine fstr_setup_util_err_stop( msg )
    implicit none
    character(*) :: msg
  
    write(*,*) msg
    write(imsg,*) msg
    call hecmw_abort( hecmw_comm_get_comm())
  end subroutine fstr_setup_util_err_stop
  
  !------------------------------------------------------------------------------
  
  ! grp_type_name : 'node_grp', 'elem_grp' or 'surf_grp'
  
  subroutine set_group_pointers( hecMESH, grp_type_name )
    type (hecmwST_local_mesh),target :: hecMESH
    character(len=*) :: grp_type_name
  
    if( grp_type_name == 'node_grp' ) then
      grp_type = 1
      n_grp      => hecMESH%node_group%n_grp
      grp_name%s => hecMESH%node_group%grp_name
      grp_index  => hecMESH%node_group%grp_index
      grp_item   => hecMESH%node_group%grp_item
    else if( grp_type_name == 'elem_grp' ) then
      grp_type = 2
      n_grp      => hecMESH%elem_group%n_grp
      grp_name%s => hecMESH%elem_group%grp_name
      grp_index  => hecMESH%elem_group%grp_index
      grp_item   => hecMESH%elem_group%grp_item
    else if( grp_type_name == 'surf_grp' ) then
      grp_type = 3
      n_grp      => hecMESH%surf_group%n_grp
      grp_name%s => hecMESH%surf_group%grp_name
      grp_index  => hecMESH%surf_group%grp_index
      grp_item   => hecMESH%surf_group%grp_item
    else
      STOP 'assert in set_group_pointers'
    end if
  end subroutine set_group_pointers
  
  subroutine backset_group_pointers( hecMESH, grp_type_name )
    type (hecmwST_local_mesh),target :: hecMESH
    character(len=*) :: grp_type_name
  
    if( grp_type_name == 'node_grp' ) then
      grp_type = 1
      hecMESH%node_group%grp_name => grp_name%s
      hecMESH%node_group%grp_index => grp_index
      hecMESH%node_group%grp_item => grp_item
    else if( grp_type_name == 'elem_grp' ) then
      grp_type = 2
      hecMESH%elem_group%grp_name => grp_name%s
      hecMESH%elem_group%grp_index => grp_index
      hecMESH%elem_group%grp_item => grp_item
    else if( grp_type_name == 'surf_grp' ) then
      grp_type = 3
      hecMESH%surf_group%grp_name => grp_name%s
      hecMESH%surf_group%grp_index => grp_index
      hecMESH%surf_group%grp_item => grp_item
    else
      STOP 'assert in set_group_pointers'
    end if
  end subroutine backset_group_pointers
  
  function node_global_to_local( hecMESH, list, n )
    implicit none
    type (hecmwST_local_mesh), target :: hecMESH
    integer(kind=kint) :: list(:)
    integer(kind=kint) :: n, i, j
    logical:: fg
    integer(kind=kint):: node_global_to_local
  
    node_global_to_local = 0
    do j=1, n
      fg = .false.
      do i=1, hecMESH%n_node
        if( hecMESH%global_node_ID(i) == list(j)) then
          list(j) = i
          fg = .true.
          node_global_to_local = node_global_to_local +1
          exit
        endif
      end do
      if( .not. fg ) then
        list(j) = -list(j) ! not exist node
      endif
    end do
  end function node_global_to_local
  
  function elem_global_to_local( hecMESH, list, n )
    implicit none
    type (hecmwST_local_mesh), target :: hecMESH
    integer(kind=kint), pointer :: list(:)
    integer(kind=kint) :: n, i, j
    logical :: fg
    integer(kind=kint) :: elem_global_to_local
  
    elem_global_to_local = 0
    do j=1, n
      fg = .false.
      do i=1, hecMESH%n_elem
        if( hecMESH%global_elem_ID(i) == list(j)) then
          list(j) = i
          fg = .true.
          elem_global_to_local = elem_global_to_local+1
          exit
        endif
      end do
      if( .not. fg ) then
        list(j) = -list(j)
      endif
    end do
  end function elem_global_to_local
  
  function append_single_group( hecMESH, grp_type_name, no_count, no_list )
    implicit none
    type (hecmwST_local_mesh), target :: hecMESH
    character(len=*) :: grp_type_name
    integer(kind=kint) :: no_count
    integer(kind=kint),pointer :: no_list(:)
    integer(kind=kint):: append_single_group
    integer(kind=kint) :: old_grp_number, new_grp_number
    integer(kind=kint) :: old_item_number, new_item_number
    integer(kind=kint) :: i,j,k, exist_n
    integer(kind=kint), save :: grp_count = 1
    character(50) :: grp_name_s
  
    call set_group_pointers( hecMESH, grp_type_name )
    if( grp_type_name == 'node_grp') then
      exist_n = node_global_to_local( hecMESH, no_list, no_count )
    else if( grp_type_name == 'elem_grp') then
      exist_n = elem_global_to_local( hecMESH, no_list, no_count )
    endif
  
    old_grp_number = n_grp
    new_grp_number = old_grp_number + no_count
  
    old_item_number = grp_index(n_grp)
    new_item_number = old_item_number + exist_n
  
    call fstr_expand_name_array( grp_name, old_grp_number, new_grp_number )
    call fstr_expand_index_array( grp_index, old_grp_number + 1, new_grp_number+1)
    call fstr_expand_integer_array( grp_item, old_item_number, new_item_number )
  
    n_grp = new_grp_number
  
    j = old_grp_number + 1
    k = old_item_number + 1
    do i = 1, no_count
      write( grp_name_s, '(a,i0,a,i0)') 'FSTR_', grp_count, '_', i
      grp_name%s(j) = grp_name_s
      if( no_list(i) >= 0) then
        grp_item(k) = no_list(i)
        grp_index(j) = grp_index(j-1)+1
        k = k + 1
      else
        grp_index(j) = grp_index(j-1)
      endif
      j = j + 1
    end do
    grp_count = grp_count + 1
    call backset_group_pointers( hecMESH, grp_type_name )
    append_single_group = exist_n
  end function append_single_group
  
  !------------------------------------------------------------------------------
  