module dados

	use portlib

	integer :: N     ! Numero de equacoes
	integer :: itmax ! Numero maximo de iteracoes

	real*8  :: tol   ! tolerancia
	real*8  :: pert	 ! disturbio/perturbacao

	real*8,dimension(:),allocatable :: b     ! Termos independ.
	real*8,dimension(:),allocatable :: x     ! Solucao
	real*8,dimension(:),allocatable :: y     ! Correcao
	real*8,dimension(:),allocatable :: func	 ! Funcoes
	real*8,dimension(:),allocatable :: func2 ! Funcoes (deriv)

	real*8,dimension(:,:),allocatable :: A   ! Matriz coef.
	real*8,dimension(:,:),allocatable :: Jac ! Jacobiano

	integer :: dos, opcao

contains

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

subroutine entradas

	dos = system('notepad dados_iniciais.txt')
	
	open(1,file = 'dados_iniciais.txt')

	read(1,*) N
	read(1,*) opcao

	close(1)

	allocate( b(N), x(N), A(N,N), y(N), Jac(N,N), func(N), func2(N) )

end subroutine entradas

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

subroutine dados_it

	integer :: i

	dos = system('notepad entrada_it.txt')
	
	open(1,file = 'entrada_it.txt')
	read(1,*) itmax
	read(1,*) tol
	read(1,*) pert

	do i = 1, N
		read(1,*) x(i)
	end do

	close(1)

end subroutine dados_it

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

subroutine saida

	integer :: i

	open(1,file = 'saida.txt')

	select case (opcao)
	case(1)
		
		write(1,*) "Metodo de Newton"

	case(2)

		write(1,*) "Metodo de Newton modificado"

	end select

	do i = 1, N
		write(1,2) i, x(i)
	end do

	2 format ("x(", i2, ") = ", 1pe25.15)
	3 format ( <N>(1pe25.15) )

	close(1)

	dos = system('notepad saida.txt')

end subroutine saida

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

end module dados