Fortran 90 command to write only specific lines

In summary, the conversation discusses the need to run a program with a datafile in 3000 time steps and output every tenth of the file to save storage space. The speaker suggests using an if statement and the "mod" function to achieve this, and provides a code example for generating output names. They clarify that the output name will be in the format of "0000.dat" to "1000.dat".
  • #1
s_hy
61
0
Hi all. I did search in internet but couldn't find the specific answer for my specific problem.I need to run a program with a datafile in 3000 time step and the output will 1.dat to 3000.dat, which is every single data output size 200Mb. To safe the storage, I would like to write only every tenth of file, in example 1.dat,10.dat,20.dat,30.dat,40.dat,...., 2970.dat,2980.dat,2990.dat,3000.dat. How I can write in write statement for this purpose?

thank you in advance
 
Technology news on Phys.org
  • #2
I don't understand what is complicated here. Can't you simply use an if statement around the part where the output is done?
 
  • #3
well, yes, then write every 10th time through the loops...look into function "mod" to get you an idea.
 
  • #4
What's your specific question? Did you mean the output name or big size data generate?
If you mean the output name :

program main
implicit none
integer i
real vars
character(len=255) output_name

do i=1,1000
write(output_name,100) i,"dat"
write(10,file=trim(output_name)) vars
end do

100 FORMAT(I4.4,A3)
end program

The result would be: 0000.dat, 0001.dat, 0002.dat ... 1000.dat
 
Last edited:

Related to Fortran 90 command to write only specific lines

What is the Fortran 90 command to write only specific lines?

The Fortran 90 command for writing specific lines is WRITE (file, format) [input list] [IO control], where file is the name of the file to be written, format is the output format, input list is the list of variables to be written, and IO control is optional control information.

How do I specify which lines to write in Fortran 90?

You can use the IO control argument in the WRITE command to specify which lines to write. For example, you can use IO control = iostat to specify that only lines with a certain iostat value should be written.

Can I write multiple lines with one Fortran 90 command?

Yes, you can use the WRITE command to write multiple lines by using a DO loop or an array of variables in the input list argument. This will allow you to write multiple lines with one command.

How do I write specific lines to a specific file in Fortran 90?

To write specific lines to a specific file in Fortran 90, you can use the WRITE command with the file argument specifying the name of the file. You can also use OPEN and CLOSE commands to open and close the file before and after writing the specific lines.

Are there any other Fortran commands for writing specific lines?

Yes, there are other Fortran commands that can be used to write specific lines, such as WRITE (file, format) [input list] [IO control], PRINT, and FORMAT. It is important to choose the command that best suits your specific needs and the structure of your code.

Similar threads

  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
19
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
6K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
6K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
6
Views
15K
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top