How to Write a Fortran Code to Read a Specific Data File?

  • Fortran
  • Thread starter niloy112
  • Start date
  • Tags
    Code Fortran
In summary: Yes i have a book "Fortran 95/2003 for scientists and engineers by Stephen J. Chapman" but i couldn't find any information about formatted input there...Here is some example code that reads in the data from the input file and outputs it to the console:program read_input implicit none integer :: i, j, num_lines character(73) :: line ! Open the input file open(1, file='text.igs') ! Count the number of lines in the file num_lines = 0 do read(1, *, iostat=j) line if (j /= 0) exit num_lines = num
  • #1
niloy112
11
0
The input file:
---------------------------------------------------------------------------------
S 1
S 2
1H,,1H;,, G 1
70HC: G 2
s, G 3
26HRhinoceros ( Jan 18 2007 ),31HTrout Lake IGES 012 Jan 18 2007, G 4
32,38,6,308,15, G 5
, G 6
1.0D0,6,1HM,1,0.0002540000000000001D0,13H140130.224604, G 7
0.0001D0, G 8
52.0603D0, G 9
, G 10
, G 11
10,0,13H140130.224604; G 12
314 1 0 0 0 0 0 000000200D 1
314 0 1 1 0 0 0 COLOR 0D 2
406 2 0 0 1 0 0 000000300D 3
406 0 -1 1 3 0 0LEVELDEF 0D 4
406 3 0 0 2 0 0 000000300D 5
406 0 -1 1 3 0 0LEVELDEF 0D 6
128 4 0 0 2 0 0 000000000D 7
128 0 -1 634 0 0 0 TrimSrf 0D 8
314,0.0,0.0,0.0,20HRGB( 0, 0, 0 ); 0000001P 1
406,2,1,7HDefault; 0000003P 2
406,2,2,12HIGES level 0; 0000005P 3
128,50,20,3,3,0,0,1,0,0,0.0D0,0.0D0,0.0D0,0.0D0,0.0472D0, 0000007P 4
0.0668D0,0.08409999999999999D0,0.1D0,0.1154D0,0.1314D0,0.1486D0, 0000007P 5
0.1685D0,0.1904D0,0.2141D0,0.2377D0,0.2614D0,0.2851D0,0.3088D0, 0000007P 6
0.3325D0,0.3562D0,0.3799D0,0.4035D0,0.4272D0,0.4509D0,0.4746D0, 0000007P 7
0.4983D0,0.5219D0,0.5456D0,0.5693D0,0.593D0,0.6167D0,0.6403D0, 0000007P 8
0.664D0,0.6877D0,0.7114D0,0.7351D0,0.7588D0,0.7825D0,0.8062D0, 0000007P 9
0.8299D0,0.8537D0,0.8734D0,0.8892D0,0.901D0,0.9131D0,0.9257D0, 0000007P 10
0.9384D0,0.9511D0,0.9632D0,0.9742D0,0.9838D0,1.0D0,1.0D0,1.0D0, 0000007P 11
---------------------------------------------------------------------------------------
Here there is 33 line. I need to make a fortran code which can
1. read the all data.
2. all the data situated between 1st column to 80 column. but it will be better if i can read till column 73(till alphabet P,S,D)
3. i have a code which can read and write only first column but i need to read all data.
_________________________________________________________________

program test
integer::i
character(15),allocatable,dimension(:):: line

!

!
OPEN( 1, FILE='text.igs')
OPEN( 2, FILE='l1.txt')

allocate( line(33))
do i=1,33
read(1,*)line(i)
write(2,*)line(i)
end do

end
_________________________________________________________
is it possible to get a solution in fortran??
Any body can help me please?
 
Technology news on Phys.org
  • #2
Is this homework for a course you are taking?
 
  • #3
Thanks for your response SteamKing.
Ohh no. It is not a homework. i need to read the above described format file for my research. i think if i can read the file then i can write the above described file in my required way.
 
  • #4
How much Fortran programming have you done?
 
  • #5
can do some numerical work but this kind of data processing it is problematic for me...:(
 
  • #6
The best way to solve your input problem is to study Formatted input. Do you have a Fortran textbook available to study?
 

FAQ: How to Write a Fortran Code to Read a Specific Data File?

What is Fortran and why is it used in scientific computing?

Fortran is a high-level programming language designed for scientific and engineering applications. It is particularly well-suited for mathematical and numerical computations, making it a popular choice for scientific computing. Its efficient handling of arrays and mathematical operations make it ideal for complex scientific simulations and modeling.

How do I write a Fortran code?

To write a Fortran code, you will need a text editor and a Fortran compiler. First, you will need to learn the syntax and rules of the language. Then, you can write your code in a text editor and save it with the .f or .f90 extension. Finally, use a Fortran compiler to translate your code into machine-readable instructions.

Can I use Fortran to create graphical user interfaces (GUIs)?

While Fortran is primarily used for numerical and scientific computing, it is possible to create simple GUIs using Fortran. However, it is not as commonly used for GUI development as other programming languages such as Python or Java.

Is Fortran still relevant in modern scientific computing?

Yes, Fortran is still widely used in scientific computing due to its speed and efficiency in handling complex mathematical operations. Many scientific libraries and applications are written in Fortran, making it an important language for researchers and scientists.

Are there any resources available for learning and improving my Fortran skills?

Yes, there are many online resources and tutorials available for learning Fortran. The official Fortran website offers documentation, tutorials, and a forum for users to ask questions and share knowledge. Additionally, there are many books and online courses available for learning Fortran.

Similar threads

Replies
4
Views
2K
Replies
12
Views
2K
Replies
2
Views
2K
Replies
16
Views
2K
Replies
5
Views
4K
Replies
8
Views
1K
Replies
34
Views
3K
Replies
16
Views
2K
Back
Top