Program M_NEWTON_SYS  
! main pt. Newton_Sys
! n <=99

real, allocatable :: x(:), f(:)
external fcn, jfcn
character(260) nume, fname
character(1) w
character(80) text(-2:2)
integer width
character(6) str_n

!character(132), allocatable :: f_text(:), jf_text(:,:)
!character(132) f_source, jf_source
!character(2) i_char, j_char


text(-2)=' ** Matrice jacobian singulara'
text(-1)=' ** Divergenta'
text(0) =' * XTOL atins'
text(1) =' ** LNIT depasit'
text(2) =' ** Proces stationar'

print '(a, \)', ' Introdu numarul de ecuatii: '
read *, n

! Seek "f_text", "jf_text" and print:
ip6 =seek_and_print_f_jf(n, 6)  ! Console

print '(a, \)', ' Nume fisier de iesire (fara extensie): '
read(*,'(a)') nume
fname =trim(nume)//'.rez'
open(1, file= fname, status ='unknown')

allocate (x(n), f(n))

write(1, '(a)') ' Metoda NEWTON'

ip =seek_and_print_f_jf(n, 1)

!deallocate(f_text)
!deallocate(jf_text)


nrad =1

iwn =width(n)
write(str_n, '(I<iwn>)') n


100 print '(a, \)',' Introdu aproximatia initiala x(1:'//trim(str_n)//'): '

read *,x
print '(a, \)',' Introdu xtol, lnit: '
read *, xtol, lnit
print '(a, \)',' Cod de tiparire=? (0/#0): '
read *, kod

iwnrad =width(nrad); iwlnit =width(lnit);
write(1, '(/, a, I<iwnrad>, a1)') ' Radacina nr.', nrad

write(1,*) 'Aproximatia initiala:', x
!write(1,*) ' lnit, xtol:', lnit, xtol
write(1, '(a, 1pG10.3, a, I<iwlnit>, /)') ' xtol:', xtol, '; lnit: ', lnit

call Newton_Sys(fcn, jfcn, n, x, lnit, xtol, f, kod, n_div)

! Explore divergence:
IF(n_div /=0) THEN
iwn_div =width(n_div)
write(1,'(/, a, I<iwn_div>)') '  * Nr. de divergente locale: ', n_div

ENDIF

write(1,'(/, a)') trim(text(kod))
write(*,'(/, a)') trim(text(kod))

iwlnit =width(lnit)
if(kod ==0) then
write(1,*) ' Solutia X: ', x
write(1,*) ' F(X):      ', f
write(1, '(a, I<iwlnit>)') '  Numar de iteratii = ', lnit

else
write(1, '(a, I<iwlnit>)') '  Iteratia numarul: ', lnit
write(1,*) ' Aproximatia curenta X: ', x
write(1,*) ' F(X): ', f
endif



print'(/, a, \)',' Alta radacina ? (Y, char): '
read'(a)',w

if(w =='Y' .or. w =='y') then
nrad =nrad+1
goto 100
endif

print '(/, a, a, /)', ' * Fisier de rezultate: ', trim(fname)

close(1)

END program M_NEWTON_SYS

