Hey guys,
been stuck with this file naming routines and would greatly appreciate
you help on this. I am trying the following (after watching a thread
through this blog but still couldn't figure it out for my case):
!------------------------------Record all molecular
Positions------------------------------
!Output properties from simulation output to file
subroutine visualiseparticles
use physical_constants
use computational_constants
use arrays
use calculated_properties
implicit none
integer :: n, k
character(80) :: file_name=''
!Write final position matrix to output file
write(file_name,'(a,i5.5,a)')'LoCo',iter,'.txt'
do n=1,np
write(file_name,'(f10.5,a,f10.5)')&
r(n,1), char(9), r(n,2)
end do
end subroutine visualiseparticles
!---------------------------------
*end*---------------------------------------
I would like to record the r(n,1) and r(n,2) for all of the n=1,np in
the format specified by the second write command but I would like to
do that for every iteration (iter) I am running in consecutive text
files.
Any ideas?
Thanks
Antonis
|
|
0
|
|
|
|
Reply
|
antss
|
2/28/2011 5:32:42 PM |
|
antss <antonissergis@gmail.com> wrote:
....
> write(file_name,'(a,i5.5,a)')'LoCo',iter,'.txt'
That looks plausible. file_name will have a value like "LoCo00012.txt"
for the 12th iteration for example.
> write(file_name,'(f10.5,a,f10.5)')&
>
> r(n,1), char(9), r(n,2)
(I hope there isn't really a blank line in there like it looks in the
posting. That won't work, but I'll assume it might be an artifact of
posting. If you do have a blank line tyere in the actual code, you'll
have to get rid of that in addition to the other fixes).
Note the similarity between the two write statements quoted above. In
particular, note how file_name appears in the same way in both
statements. That means they will both do the same thing in regards to
file_name. In particular, they will both write their output into the
character variable file_name. For the first write, that's presumably
what you want. But for the second write, you presumably want the output
to go to a file of that name. It won't. Instead, it will just write over
the character variable again.
You need to OPEN a file using your file_name string. Something like
open(lun,file=file_name, form='formatted', status='replace')
(Or whatever status seems appropriate for your case). Lun here is an
integer variable with a suitable unit number as a value. Selecting unit
numbers is an old Fortran oddity with much that can be said about it. I
suggest using a value between 10 and 99; the exact value really doesn't
much matter as long as it is a value not used for any other file in your
program. Avoid values less than 10 as potentially conflicting with
special system values, and avoid ones greater than 99 as potentially not
being supported. (I think almost all current compilers support larger
values, but I'd stick to that range anyway).
Then your write statemenst should use the same LUN, as in
write (lun,...
Finally, don't forget to close the file when you are done with the
iteration, as in
close(lun)
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam
|
2/28/2011 5:59:16 PM
|
|
|
1 Replies
560 Views
(page loaded in 0.049 seconds)
|