You can write to a unit, but you can also write to a string program foo character(len=1024) :: filename write (filename, "(A5,I2)") "hello", 10 print *, trim(filename) end program Please note (this is the second trick I was talking about) that you can also build a format string programmatically program foo character(len=1024) :: filename character(len=1024) :: format_string integer :: I do i=1, 10 if (i.
You can write to a unit, but you can also write to a string program foo character(len=1024) :: filename write (filename, "(A5,I2)") "hello", 10 print *, trim(filename) end program Please note (this is the second trick I was talking about) that you can also build a format string programmatically. Program foo character(len=1024) :: filename character(len=1024) :: format_string integer :: I do i=1, 10 if (i.
2 Two comments: - you don't have to discriminate on the value of I; the format (I0) will output an integer without any space; also, if you want a fixed width and padding with zeroes (like "output001. Txt"), you need to used (I0.3) - the format (A5I2) is not valid Fortran according to any norm, as format specifiers are to be separated by commas: (A5,I2) – F'x Aug 12 '09 at 14:47 Well, it was for educational purposes, not intended to be the solution. In general I use the padding zeros (as it sorts nicely), but the I0 thingie I didn't know about.
Thanks! (fixed the commas, I think my style was the old one, still accepted) – Stefano Borini Aug 12 '09 at 15:53.
Here is my subroutine approach to this problem. It transforms an integer in the range 0 : 9999 as a character. For example, the INTEGER 123 is transformed into the character 0123.
Hope it helps. P.S. - sorry for the comments; they make sense in Romanian :P subroutine nume_fisier (i,filename_tot) implicit none integer :: I integer :: integer_zeci,rest_zeci,integer_sute,rest_sute,integer_mii,rest_mii character(1) :: filename1,filename2,filename3,filename4 character(4) :: filename_tot! Subrutina ce transforma un INTEGER de la 0 la 9999 in o serie de CARACTERE cu acelasi numar!
Pentru a fi folosite in numerotarea si denumirea fisierelor de rezultate. If(i=10.and. I=100.and.
I=1000.and. I.
A much easier solution IMHO ................... character(len=8) :: fmt! Format descriptor fmt = '(I5.5)'! An integer of width 5 with zeros at the left i1= 59 write (x1,fmt) i1!
Converting integer to string using a 'internal file' filename='output'//x1//'. Dat'! ====> filename: output00059.dat.
CORRECTION: filename='output'//trim(x1)//'. Dat' – Alejandro Apr 29 at 9:11.
I have a program in Fortran that saves the results to a file. However, I now want to run a loop, and save the results of each iteration to the files 'Output1. Is there an easy way in Fortran to constuct filenames from the loop counter i?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.