!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|
!                                                                              |
!              ||===\\                                                         | 
!              ||    \\                                                        |
!              ||     ||   //==\\   ||  ||   //==||  ||/==\\                   |
!              ||     ||  ||    ||  ||  ||  ||   ||  ||    ||                  |
!              ||    //   ||    ||  ||  ||  ||   ||  ||                        |
!              ||===//     \\==//    \\==\\  \\==\\  ||                        |
!                                                                              |
!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|
!                                                                              |
!              ISCANFILE    Nov. 2006                                          |
!              DSCANFILE    Nov. 2006                                          |
!              CSCANFILE    Nov. 2006                                          |
!                                                                              |
!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|

subroutine iscanfile (fnme,text,res,ires)

!------------------------------------------------------------------------------|
!(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
!---------------------------------------------------------------------------
! subroutine to read the value of an integer parameter whose name is stored in 
! text from file fnme the result is stored in res and the flag ires is set 
! to 1 if all went well.

!use mpi

implicit none

include 'mpif.h'

!------------------------------------------------------------------------------|
!((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
!------------------------------------------------------------------------------|

character*(*) fnme,text
integer,intent(out)::res,ires

!------------------------------------------------------------------------------|
!(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
!------------------------------------------------------------------------------|
character line*256,record*256
integer ios,nproc,iproc,ierr,ieq,nrec

!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|

call mpi_comm_size (mpi_comm_world,nproc,ierr)
call mpi_comm_rank (mpi_comm_world,iproc,ierr)
 
ires=0
open (7,file=fnme(1:len_trim(fnme)),status='old',iostat=ios) 
if (ios/=0) write(*,*) 'pb opening <',fnme(1:len_trim(fnme)),'> in iscanfile'

111 continue

read (7,'(a)',end=112) line

ieq=scan(line,'=')
if (ieq/=0) then
   if (trim(adjustl(line(1:ieq-1))).eq.text(1:len_trim(text)))  then
      nrec=len_trim(adjustl(line(ieq+1:len_trim(line))))
      record(1:nrec)=trim(adjustl(line(ieq+1:len_trim(line))))
      read (record(1:nrec),*) res
      if (iproc.eq.0) write (8,*) 'Non-default value for '//text//': '//record(1:nrec)
      ires=1
   end if
end if

goto 111

112 close (7)

return
end subroutine iscanfile



!---------------------------------------------------------------------------
!---------------------------------------------------------------------------


subroutine dscanfile (fnme,text,res,ires)

!------------------------------------------------------------------------------|
!(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
!------------------------------------------------------------------------------|
! subroutine to read the value of a double precision  parameter whose name 
! is stored in  text  from file fnme the result is stored in res and the flag 
! ires is set  to 1 if all went well.

!use mpi

implicit none

include 'mpif.h'

!------------------------------------------------------------------------------|
!((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
!------------------------------------------------------------------------------|

character*(*) fnme,text
double precision res
integer ires

!------------------------------------------------------------------------------|
!(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
!------------------------------------------------------------------------------|

character line*256,record*256
integer ios,nproc,iproc,ierr,ieq,nrec

!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|

call mpi_comm_size (mpi_comm_world,nproc,ierr)
call mpi_comm_rank (mpi_comm_world,iproc,ierr)


ires=0

open (7,file=fnme(1:len_trim(fnme)),status='old',iostat=ios) 
if (ios/=0) write(*,*) 'pb opening <',fnme(1:len_trim(fnme)),'> in dscanfile'

111     continue

read (7,'(a)',end=112) line

ieq=scan(line,'=')
if (ieq/=0) then
   if (trim(adjustl(line(1:ieq-1))).eq.text(1:len_trim(text))) then
      nrec=len_trim(adjustl(line(ieq+1:len_trim(line))))
      record(1:nrec)=trim(adjustl(line(ieq+1:len_trim(line))))
      read (record(1:nrec),*) res
      if (iproc.eq.0) write (8,*) 'Non-default value for '//text//': '//record(1:nrec)
      ires=1
   endif
end if

goto 111

112   close (7)

return
end subroutine dscanfile



!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|


subroutine cscanfile (fnme,text,res,ires)

!------------------------------------------------------------------------------|
!(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
!------------------------------------------------------------------------------|
! subroutine to read the value of a character string parameter whose name 
! is stored in  text  from file fnme the result is stored in res and the flag 
! ires is set  to 1 if all went well.

!use mpi

implicit none

include 'mpif.h'

!------------------------------------------------------------------------------|
!((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
!------------------------------------------------------------------------------|
      
character*(*) fnme,text,res
integer ires

!------------------------------------------------------------------------------|
!(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
!------------------------------------------------------------------------------|

character line*256,record*256
integer ios,nproc,iproc,ierr,ieq,nrec

!------------------------------------------------------------------------------|
!------------------------------------------------------------------------------|

call mpi_comm_size (mpi_comm_world,nproc,ierr)
call mpi_comm_rank (mpi_comm_world,iproc,ierr)

ires=0

open (7,file=fnme(1:len_trim(fnme)),status='old',iostat=ios) 
if (ios/=0) write(*,*) 'pb opening <',fnme(1:len_trim(fnme)),'> in cscanfile'

111     continue

read (7,'(a)',end=112) line

ieq=scan(line,'=')
if (ieq/=0) then
   if (trim(adjustl(line(1:ieq-1))).eq.text(1:len_trim(text))) then
      nrec=len_trim(adjustl(line(ieq+1:len_trim(line))))
      record(1:nrec)=trim(adjustl(line(ieq+1:len_trim(line))))
      res=record(1:nrec)
      if (iproc.eq.0) write (8,*) 'Non-default value for '//text//': '//record(1:nrec)
      ires=1
   endif
end if

goto 111

112   close (7)

return
end subroutine cscanfile


!---------------------------------------------------------------------------
!---------------------------------------------------------------------------
