- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am using fortran for coding. Now I am going to read more than 1000 data files separately, from the data file folder D\Datas\fortran
And the data filenames are like:
Gstep00001.dat Gstep00002.dat ... Gstep01230.dat
and the contents are like:
-0.0004349421733 1.0583843781537
-0.0004059937166 1.0583825316509
-0.0003770452599 1.0583806851481
-0.0003480968032 1.0583788386453
-0.0003191483465 1.0583769921425
-0.0002901998898 1.0583751456397
-0.0002612514331 1.0583732991369
-0.0002323029764 1.0583714526341
-0.0002033545197 1.0583696061313
-0.0001744060630 1.0583677596285
....
....
So how to accomplish this in fortran, please? Waiting for your help, thanks!
Sinserely
Ren
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will assume that the problem you are facing is opening these 1000 files one by one without having to put these names into the program itself.
One way to do this is to use a so-called internal write statement: you write to a character string instead of a file. Here is a small example:
character(len=20) :: filename do i = 1,1230 write( filename, '(a,i5.5,a)' ) 'Gstep', i, '.dat' open( 10, file = filename ) ... read and process the data ... close( 10 ) enddo
Note the format "i5.5" - it causes the program to insert 0's before the actual number, so that 111 is written as 00111.
I will leave the reading and processing of the actual data to you.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will assume that the problem you are facing is opening these 1000 files one by one without having to put these names into the program itself.
One way to do this is to use a so-called internal write statement: you write to a character string instead of a file. Here is a small example:
character(len=20) :: filename do i = 1,1230 write( filename, '(a,i5.5,a)' ) 'Gstep', i, '.dat' open( 10, file = filename ) ... read and process the data ... close( 10 ) enddo
Note the format "i5.5" - it causes the program to insert 0's before the actual number, so that 111 is written as 00111.
I will leave the reading and processing of the actual data to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much!

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page