INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

writing multiple arrays to output file

writing multiple arrays to output file

(OP)
I've written a 3D finite difference diffusion code in Microsoft Visual studio Intel Fortran Compiler and I need to output the concentrations at certain time step values. I need an output file that includes the concentration array in the domain for specific time steps throughout the program. The format I have right now is listed below. m is the global indexing scheme.

open(71,file='Conc.out',status='unknown')

if(NumTS.eq.TS)then
do k=1,NZ
do j=1,NY
do i=1,NX
m=i+(j-1)*NX+(k-1)*NX*NY
write (71,*)TS
write (71,*)Cold(m)
end do
end do
end do
end if

close(unit=71)

NumTS is the time step value I wish to output i.e NumTS=100,150,200 etc. TS is the updated time step value that has an increase in time step size added to the previous time step value that is included in the main loop i.e 50 is added each time. How can I output the concentrations for each time step in one file that is column listed. I need the output file to be as seen below. Any help would be awesome! Thanks.

Note: This output command is within a subroutine and Cold(m) is the concentration array

100 150 200 250 etc..

1495.222 12453 16463 13564
1494.811 134546 13658 13565
1494.206 136563 13564 13567
1493.420 114543 16743 13569
******** ******** ******* *******

RE: writing multiple arrays to output file

At this point, I would simply recommend that you transpose the manner you want to output your data and write out one row at a time...at the end, you should have your "column" (row really) headings on the first column, followed by the values of interest.

RE: writing multiple arrays to output file

(OP)
OK I'm fine with having multiple output files that have just one array in them but how would I format that in the code to output multiple files for each desired time step.eg. Conc100.out, Conc150.out, Conc200.out etc?

RE: writing multiple arrays to output file

Quote (raberry22 )


but how would I format that in the code to output multiple files for each desired time step.eg. Conc100.out, Conc150.out, Conc200.out etc?

For each timestep you have to cŕeate the file name, then open that file, write data in it and close the file.
For example something like this:

CODE

program raberry22
  implicit none
  integer :: ts
  character*3 :: ts_char
  character*12 :: fname

  do  ts = 100, 200, 50
    ! create file name
    write(ts_char,'(i3)') ts
    fname = 'conc'//ts_char//'.out'
    write(*,*) 'Creating file: ', fname
    
    ! open file
    open(71, file=fname, status='unknown')
    
    ! write data
    write(71,*) 'writing data for TimeStep =', ts 
    
    ! close file
    close(unit=71)
    write(*,*) '... done.'
  end do

end program raberry22 

The program above creates in your current directory 3 files:
conc100.out
conc150.out
conc200.out

RE: writing multiple arrays to output file

CODE

$ gfortran raberry22.f95 -o raberry22

$ raberry22
 Creating file: conc100.out
 ... done.
 Creating file: conc150.out
 ... done.
 Creating file: conc200.out
 ... done. 

RE: writing multiple arrays to output file

(OP)
I have included below a set of commands that might work as well? NumTS is my main loop counter and I add 50 to each updated TS value. I have approximately 1500 time steps. Tstep=50 and the initial TS=Tstep

if(NumTS.eq.TS)then
! create file name
write(ts_char,'(i4)') TS
fname = 'conc'//ts_char//'.out'

! open file
open(71, file=fname, status='unknown')

! write data
write(71,*) (((Cold(i+(j-1)*NX+(k-1)*NX*NY),i=1,NX),j=1,NY),k=1,NZ)

close(unit=71)

end if

TSS=TS+Tstep
TS=TSS

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close