Reading data from string
parsing string and chacteres in Fortran 90
==================
program test_read
implicit none
character(60) :: ch1,ch2,ch3
character :: ch
integer :: nch,i,norb
real:: ef
ch1="<norbitals>56</norbitals>"
ch2='<fermi_energy units="eV"> -0.400353744E+01</fermi_energy>'
nch = len(ch1)
do i=1,nch
if ((ch1(i:i) == "<") .or. (ch1(i:i) == ">" )) ch1(i:i)=" "
enddo
nch = len(ch2)
do i=1,nch
if ((ch2(i:i) == "<") .or. (ch2(i:i) == ">" )) ch2(i:i)=" "
enddo
read(ch1,*) ch,norb
print*,norb
read(ch2,*) ch,ch,ef
print*,ef
end
=============
Results
ch1= norbitals 56 /norbitals
ch2 = fermi_energy units="eV" -0.400353744E+01 /fermi_energy
norb = 56
ef=-4.00353765
######################################
Writting data to string (not in file)
subroutine writewave(io,rk,psi,eng,N,ik,wflabel)
complex(8) ,dimension(N,N)::psi
real(8) ,dimension(N)::Eng
real(8),dimension(3)::rk
integer::N,ik,io
character(*)::wflabel
character(50)::fname,ch
if (ik .lt. 10) then
write(ch,'(i1)')ik
elseif (ik .ge. 10 .and. ik .lt. 100)then
write(ch,'(i2)')ik
elseif (ik .ge. 100 .and. ik .lt. 1000) then
write(ch,'(i3)')ik
else
write(6,*) "more than 1000 k points!!"
endif
fname=trim(wflabel)//trim(ch)
open(io,file=trim(fname),status='unknown',form='unformatted',action='write')