Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to read data from files and process it?

  1. Aug 28, 2011 #1
    Dear all,

    I want to read data from a file which has four column and process the data for further calculation. After running the code it keeps given me 0.00000 as output. What do i do? Here is the structure of the code

    program new

    Implicit none
    integer,parameter ::Nmax=1000
    Integer :: i,io,max,t
    Real*8,Dimension(Nmax) :: Ev,X,Y,Z
    Real*8, Dimension(Nmax)::Evr,Xr,Yr,Zr


    open(1, File='si.dat',status='old')

    open(16,file='cal.dat',status='unknown')

    max=0
    do i=1,Nmax
    read(1,*,IOSTAT = io)Ev(i),X(i),Y(i),Z(i)
    if (io.eq.0) then
    max = max+1
    else
    goto 677
    endif
    enddo


    677 close(1)

    do t=1,Nmax
    open(1, file='si.dat',status='old')
    do i=1,max

    read(1,*,iostat=io)Ev(i),X(i),Y(i),Z(i)
    enddo
    write(6,*)Ev(t),X(t),Y(t),Z(t)
    enddo
    close(16)

    end program
     
  2. jcsd
  3. Aug 28, 2011 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    On the OPEN statements, if the data is in human readable form (i.e. text), add the additional option FORM=FORMATTED. If the data is binary, then FORM=UNFORMATTED and RECL=xxx should be added, but in any event, you'll need to know what form the data files are in.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook