read and write .dat file in f90

1,112 views
Skip to first unread message

Alekhya vvl

unread,
Oct 24, 2013, 5:06:15 AM10/24/13
to g95_frotran
hi,
 i have a .dat file which contains 8 parameters data in ASCII format. how to read and display those 8 parameters from that .dat file.

I have written following code:


program array
      real, dimension(:), allocatable :: x
      integer :: n
 
      open (unit=99, file='492.dat', status='old', action='read')
      read(99, *), n
      allocate(x(n))
      read(99,*) x
 
      write(*,*) x
end



The program was compiled properly but at run time it is showing an error like:

traceback: not available, compile with -ftrace= frame or -ftrace=full
--
with best regards,

V V L Padma Alekhya,
Junior Research fellow,
National Remote sensing Centre,
Indian Space Research Organisation
Department of space,Govt. of India
Balanagar,Hyderabad.

Jimmy

unread,
Oct 24, 2013, 7:07:50 AM10/24/13
to gg...@googlegroups.com

Works okay on my Windows 7 system, with data
8
1.132
2
3.987643
4
5.1009897675654343
45
6.68
8.99
Check your data file.

Jimmy
 

Alekhya vvl

unread,
Oct 24, 2013, 7:18:03 AM10/24/13
to g95_frotran
oh great.
 can you plz tell how you have complied the program


--
You received this message because you are subscribed to the Google Groups "gg95" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gg95+uns...@googlegroups.com.
To post to this group, send email to gg...@googlegroups.com.
Visit this group at http://groups.google.com/group/gg95.
For more options, visit https://groups.google.com/groups/opt_out.

ziggy76

unread,
Oct 24, 2013, 11:30:56 AM10/24/13
to gg...@googlegroups.com

Hello,
Tested OK on my Windows 7 with gfortran 64 bits and data
8
12.5
13.5
23.5
26.5
45.3
56.2
75.2
78.4

- please show us your data file and the complete error message.

Jimmy

unread,
Oct 25, 2013, 8:34:44 AM10/25/13
to gg...@googlegroups.com

Jimmy

unread,
Oct 25, 2013, 8:43:15 AM10/25/13
to gg...@googlegroups.com


On Thursday, 24 October 2013 10:06:15 UTC+1, Alekhya vvl wrote:
I used 'g95 array.f95'  to give 'a.exe'.  Other compile instructions also work. I note that there is an unnecessary comma after the closing bracket of the 'read(99, *), n' statement. G95 accepts this but Silverfrost does not - needs a 'standards' expert to pronounce on whether or not it is a G95 bug.

As ziggy76 says, please attach details of your data file and the complete error message, and I would add details of how you compiled it.

     
 

Alekhya Vvl

unread,
Oct 28, 2013, 5:50:35 AM10/28/13
to g95_frotran
I am unable to run the program, Plz help me in reading and writing this file

here,  i am sending my .dat file and program
In .dat file all items are written in real number with single precision (4-bytes), and file format is FORTRAN binary data.

program array
      real, dimension(:), allocatable :: x
   Integer :: n
 
      open (unit=99, file='492.dat', access='sequential', format='unformatted')
      read(99, *) n
      
      write(*,*) n
end program



I am getting the run time error as:

E;\f90_del> g95 array.f95 -o a.out
E:\f90_del>a.out
 File array.f95 (Unit 99 "492.dat")
Traceback: not available, compile with -ftrace=frame or -ftrac
Fortran runtime error: Bad integer for item 1 in list input





--
You received this message because you are subscribed to the Google Groups "gg95" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gg95+uns...@googlegroups.com.
To post to this group, send email to gg...@googlegroups.com.
Visit this group at http://groups.google.com/group/gg95.
For more options, visit https://groups.google.com/groups/opt_out.
492.dat

ziggy76

unread,
Oct 28, 2013, 10:09:06 AM10/28/13
to gg...@googlegroups.com

Hello,
If you use binary data, you should not put a format indicator in the READ statement :
READ(99) n
and not
READ(99,*) n
The star is for standard format ...

I think this is your problem.

Regards.

jfh

unread,
Dec 3, 2013, 5:23:53 PM12/3/13
to gg...@googlegroups.com
We were not told what was in the data file. It matters. The program worked for me if n is on a line by itself in 492.dat and the values of x are on later lines, either all on the same line or spread over more than one. But if all the numbers are on the same line, the first read statement gets only the value of n from that line and expects the values of x from lines 2 and onwards, and I suspect there was no line 2. Either fix the data file or learn about BACKSPACE and REWIND. For example the following variation on the program, in which I have put the amendments in UPPER case, works with either form of 492.dat at the cost of reading n twice.
.

program array
      real, dimension(:), allocatable :: x
      integer :: n
 
      open (unit=99, file='492.dat', status='old', action='read')
      read(99, *), n
      allocate(x(n))
      BACKSPACE 99 ! new statement
      read(99,*) N,x     ! modified statement
 
      write(*,*) x
end


Reply all
Reply to author
Forward
0 new messages