For Programmers: Free Programming Magazines  


Home > Archive > Fortran > September 2004 > how to output to multiple files?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to output to multiple files?
joel GUERRERO

2004-09-25, 8:57 pm

I need to output the data to multiple files. That's, it's a time
dependant execution and I want to dump the data to each timestep. For
example:

test_1.dat
test_2.dat
test_3.dat
test_4.dat
and so on.

Any guideline on how to do this,

Greetings,

Joe
beliavsky@aol.com

2004-09-25, 8:57 pm


joegi.geo@yahoo.com (joel GUERRERO) wrote:
>I need to output the data to multiple files. That's, it's a time
>dependant execution and I want to dump the data to each timestep. For
>example:
>
>test_1.dat
>test_2.dat
>test_3.dat
>test_4.dat
>and so on.


Put the file name into a string using an "internal write", OPEN the file,
WRITE to it, and CLOSE it, as shown below:

program xfile_name
implicit none
integer :: i
integer, parameter :: out_unit=20,num_files=4
character (len=20) :: file_name
do i=1,num_files
write (file_name,"('test_',i1,'.dat')") i
open (unit=out_unit,file=file_name,action="write",status="replace")
write (out_unit,*) i,i**2
close (out_unit)
write (*,*) trim(file_name)
end do
end program xfile_name

To write to more than 9 files, the format string "('test_',i1,'.dat')" must
be changed.



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jim Backus

2004-09-26, 9:07 am

On Sat, 25 Sep 2004 22:08:40 UTC, joegi.geo@yahoo.com (joel GUERRERO)
wrote:

> I need to output the data to multiple files. That's, it's a time
> dependant execution and I want to dump the data to each timestep. For
> example:
>
> test_1.dat
> test_2.dat
> test_3.dat
> test_4.dat
> and so on.
>
> Any guideline on how to do this,
>


I think you can do this by having the unchanging part of your output
as a variable and adding the time dependent parts.

--
Jim Backus OS/2 user since 1994
bona fide replies to j <dot> backus <the circle thingy> jita <dot>
demon <dot> co <dot> uk

jan van oosterwijk

2004-09-27, 4:01 pm

"beliavsky@aol.com" <beliavsky@127.0.0.1:7501> wrote in message news:<4155f81c$1_1@127.0.0.1>...
> joegi.geo@yahoo.com (joel GUERRERO) wrote:
>
> Put the file name into a string using an "internal write", OPEN the file,
> WRITE to it, and CLOSE it, as shown below:
>
> program xfile_name
> implicit none
> integer :: i
> integer, parameter :: out_unit=20, num_files=4
> character (len=20) :: file_name
> do i=1,num_files
> write (file_name,"('test_',i1,'.dat')") i
> open (unit=out_unit,file=file_name,action="write",status="replace")
> write (out_unit,*) i,i**2
> close (out_unit)
> write (*,*) trim(file_name)
> end do
> end program xfile_name
>
> To write to more than 9 files, the format string "('test_',i1,'.dat')" must
> be changed.


Changing (Fortran 95)

write (file_name,"('test_',i1,'.dat')") i

to

write (file_name, "('test_', i0, '.dat')") i

gives you "unlimited" number of output files.

[JvO]
Ken Plotkin

2004-09-27, 4:01 pm

On 27 Sep 2004 06:33:31 -0700, jvo_36@hotmail.com (jan van oosterwijk)
wrote:

[snip]
> write (file_name, "('test_', i0, '.dat')") i
>
>gives you "unlimited" number of output files.


My preference would be to use something like i3.3 or i4.4, so the
files collate in sequence. Not unlimited, but it can be made as wide
as expected - maybe i20.20?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com