I am trying this:
id1=iter/10
id2=iter-id1*10
tfile(3:4)=char(id1+48)//char(id2+48)
I have defined:
data tfile/'nr .res'/
Still i get file like this:
nr .res
I would like to be nr01.res,... and so on.
Where could be a problem?
I don't see any problem even if I would have choose another solution :
Code:
program test
implicit none
character(20) :: tfile="nr .res"
integer :: iter,id1,id2
iter=22
id1=iter/10
id2=iter-10*id1
tfile(3:4)=CHAR(id1+48)//CHAR(id2+48)
write(*,*) tfile
end program
Here is the solution I propose, which provides the same result :
Code:
program test
implicit none
character(20) :: tfile
integer :: iter
iter=22
write(tfile,"(A,I0,A)") "nr",iter,".res"
write(*,*) tfile
end program
This solution is in the same time shorter and more general because it works with any value for iter.
Notice that it is sometimes still more efficient to use the format "I8.8" (or I9.9) rather than "I0". Indeed, with "I8.8", all the file names keep the same length and, more important, are created in respecting the alphabetic order !
Example :
Code:
program test
implicit none
character(20) :: tfile
integer :: iter
iter=22
write(tfile,"(A,I9.9,A)") "nr",iter,".res"
write(*,*) tfile
iter=155
write(tfile,"(A,I9.9,A)") "nr",iter,".res"
write(*,*) tfile
end program
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.