- #1
Rems
- 4
- 0
I am trying to read a binary file using fortran.
this is how the binary file looks like.
1901 109.1000 241.4000 284.2000 121.9000
1902 104.0000 283.7000 202.6000 201.9000
1903 114.8000 293.0000 279.6000 204.4000
1904 158.8000 266.4000 210.4000 129.6000
1905 88.70000 252.5000 202.6000 174.6000
1906 176.9000 285.8000 259.8000 179.8000
1907 150.1000 223.5000 311.6000 95.10000
1908 125.4000 331.5000 317.0000 153.8000 and so on
This is my code
PROGRAM read_data
IMPLICIT NONE
integer ::i,j
REAl , dimension(5,110)::a
!a(1,*)=year
!a(2,*)=june
!a(3,*)=july
!a(4,*)=august
!a(5,*)=september
open (55,file='data_ISMR',status='old')
open (66,file='output4.txt',status='new')
read (55,*) a
write(66,*) a
close(55)
END PROGRAM read_data
~
There is no error in the program. But result is not displayed properly. this is how it looks like
1901.000 109.1000 241.4000 284.2000 121.9000 1902.000 104.0000 283.7000 202.6000 201.9000 1903.000 114.8000 293.0000 279.6000 204.4000 1904.000 158.8000 266.4000 210.4000 129.6000 1905.000 88.70000 252.5000 202.6000 174.6000 1906.000 176.9000 285.8000 259.8000 179.8000 1907.000 150.1000 223.5000 311.6000 95.10000 1908.000 125.4000 331.5000 317.0000 153.8000 1909.000 205.0000 and so on
any suggestions how to improve the program?
also i want to find the sum of june,july,august,september for each year and add it all together from year 1901 to 2010.
i am new to fortran. anybody having any suggestions?
this is how the binary file looks like.
1901 109.1000 241.4000 284.2000 121.9000
1902 104.0000 283.7000 202.6000 201.9000
1903 114.8000 293.0000 279.6000 204.4000
1904 158.8000 266.4000 210.4000 129.6000
1905 88.70000 252.5000 202.6000 174.6000
1906 176.9000 285.8000 259.8000 179.8000
1907 150.1000 223.5000 311.6000 95.10000
1908 125.4000 331.5000 317.0000 153.8000 and so on
This is my code
PROGRAM read_data
IMPLICIT NONE
integer ::i,j
REAl , dimension(5,110)::a
!a(1,*)=year
!a(2,*)=june
!a(3,*)=july
!a(4,*)=august
!a(5,*)=september
open (55,file='data_ISMR',status='old')
open (66,file='output4.txt',status='new')
read (55,*) a
write(66,*) a
close(55)
END PROGRAM read_data
~
There is no error in the program. But result is not displayed properly. this is how it looks like
1901.000 109.1000 241.4000 284.2000 121.9000 1902.000 104.0000 283.7000 202.6000 201.9000 1903.000 114.8000 293.0000 279.6000 204.4000 1904.000 158.8000 266.4000 210.4000 129.6000 1905.000 88.70000 252.5000 202.6000 174.6000 1906.000 176.9000 285.8000 259.8000 179.8000 1907.000 150.1000 223.5000 311.6000 95.10000 1908.000 125.4000 331.5000 317.0000 153.8000 1909.000 205.0000 and so on
any suggestions how to improve the program?
also i want to find the sum of june,july,august,september for each year and add it all together from year 1901 to 2010.
i am new to fortran. anybody having any suggestions?