00001 subroutine error_metric(pot,pot_bak,error,flag)
00002   use phys_constant,  only : long
00003   use grid_parameter, only : nrg, ntg, npg, eps
00004   implicit none
00005   real(long), pointer :: pot(:,:,:), pot_bak(:,:,:)
00006   real(long), intent(out) :: error
00007   integer,    intent(out) :: flag
00008   real(long) :: error_pot = 0.0d0, small = 1.0d-14
00009   integer    :: irg, itg, ipg
00010 
00011   error = 0.0d0
00012   flag = 0
00013   do irg = 0, nrg-1
00014     do itg = 0, ntg
00015       do ipg = 0, npg
00016         error_pot = 2.0d0*dabs(pot(irg,itg,ipg) -     pot_bak(irg,itg,ipg)) &
00017       &                 /(dabs(pot(irg,itg,ipg))+dabs(pot_bak(irg,itg,ipg)) &
00018       &                 + small)
00019         if (error_pot > eps) flag = 1
00020         error = dmax1(error,error_pot)
00021       end do
00022     end do
00023   end do
00024 end subroutine error_metric