Fortran Fortran 90 command to write only specific lines

AI Thread Summary
The discussion centers on a programming challenge involving the output of data files at specific intervals. The user seeks to generate files from a program that produces 3000 outputs, each 200MB in size, but wants to save storage by only writing every tenth file (e.g., 1.dat, 10.dat, 20.dat, etc.). Participants suggest using an if statement to control the output frequency, specifically recommending the use of the "mod" function to determine when to write files. A sample code snippet is provided, illustrating how to format output file names and write data conditionally, resulting in filenames formatted as 0000.dat, 0001.dat, up to 1000.dat. The conversation emphasizes practical coding solutions for efficient data management.
s_hy
Messages
57
Reaction score
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
I don't understand what is complicated here. Can't you simply use an if statement around the part where the output is done?
 
well, yes, then write every 10th time through the loops...look into function "mod" to get you an idea.
 
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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
5
Views
3K
Replies
3
Views
4K
Replies
19
Views
6K
Replies
4
Views
2K
Replies
4
Views
6K
Replies
6
Views
16K
Replies
3
Views
4K
Replies
4
Views
4K
Back
Top