Results 1 to 8 of 8

Thread: Error reading file in fortran

  1. #1
    Join Date
    Aug 2010
    Posts
    41

    Error reading file in fortran

    Hello,
    I have a little problem reading the file, my program open a file of the form:
    2 0.00 ...
    5 0.23 ...
    10 0.333
    ......

    I then put these values in tables

    read (12, *)
    do i = 1, line - 1.1
    write (*,*) u (i), v (i)
    end do

    and as I get the error message:
    Code:
    "Fortran runtime error End of file"
    Here I do not really know how to fix it. Please help me with this. Thank you.

  2. #2
    Join Date
    Mar 2010
    Posts
    197

    Re: Error reading file in fortran

    Fortran is very very far for me but I wonder if after counting the records should not close the file and reopen it, the order read (12, *) of the second loop arriving the eof. If you are not clear with the basics of the language then I recommend you to read the input output functions .

  3. #3
    Join Date
    Aug 2010
    Posts
    41

    Re: Error reading file in fortran

    Here is my code
    Code:
    if (ok = 0) then 
    write (*,*) 'Error 1 file xko.dat' 
    stop 
    end if 
    
    do while (ok == 0)! loop to count the number of online file 
    read (12, *, iostat = ok) 
    if (ok == 0) line = line + 1 
    
    end do 
    write (*,*) 'number line', line 
    
    rewind (unit = 12, iostat = ok) ! repositioning at the beginning of the file for reading 
    if (ok = 0) then 
    write (*,*) 'error 2 file xko.dat' 
    stop 
    end if
    Please check where I am wrong and correct me.

  4. #4
    Join Date
    Mar 2010
    Posts
    338

    Re: Error reading file in fortran

    Check out this part of the code

    read (12, *)
    do i = 1, line 1
    write (*,*) u (i), v (i)
    end do

    You read the file is not the result is nowhere you can display variables on Console we even know where they have been initialized. So, it does not surprise me that you write anything.

  5. #5
    Join Date
    Mar 2010
    Posts
    197

    Re: Error reading file in fortran

    IOSTAT sets The Value of iostat to-1 if end-of-file IS Encountered, to -2 if end-of-year record IS Encountered, and to the run-time error number (a positive integer) year if error occurs. (See Run-time Error Messages for a list of error numbers and Their Meaning.) If none of conditions OCCURS thesis, iostat IS set to 0. IOSTAT Can Be Used With Any I / O EXCEPT PRINT statement.

  6. #6
    Join Date
    Mar 2010
    Posts
    338

    Re: Error reading file in fortran

    iostat
    (Output) Default integer (INTEGER (4) UNLESS changed by The User). Zero if no error rolling stock, a negative integer if year end-of-file record Encountered IS, Or The Number Of The error message. See Errors, End-of-File and End-of-Record Handling (= IOSTAT, ERR =, END =, EOR =). I guess I am correct here.

  7. #7
    Join Date
    Aug 2010
    Posts
    37

    Re: Error reading file in fortran

    Up to this point it was assumed that all output is on the screen, and all input - the keyboard. Consider the program of calculation of complex engineering products (eg, LA). The input data for it are dozens of parameters, output - several thousand. If you want to calculate with the help of this program are different versions of the product will need to run the program several times, each time the keyboard, all input data, although the change only 1-2 parameters. In order to avoid unnecessary work, it is enough to keep somewhere the input data and when the program starts to indicate where to get the data. That place could be a file store. File - is a collection of information related to a task that is stored in a logical one place. The actual location of data in the file depends on the OS. In Fortran-e has the ability to save data to a file and read from a file. This file should be opened and "connect" with a certain number of your device. This is historical - before commissioning was carried out with external devices with different numbers, inserting in them the deck of punched cards. Now the files are stored on magnetic media - disk, tape or in memory.

  8. #8
    Join Date
    Aug 2010
    Posts
    37

    Re: Error reading file in fortran

    Operator open (12, FILE = 'result') "opens" the file named 'result' , and allows further write to it or read of him referring to the number (12). Programmer sets the number at random. write (12, *) produces output to an open file, enter the number in parentheses. close (12) closes the file, ie program will not be after the close contact to the content file will not open again until its operator open. If the program needs to read information from the file must use the input statement READ, again in parentheses instead of the first stars of an open file number, for example:

    Code:
    READ (12, *) a, b, c

Similar Threads

  1. Error Reading File - Photo Editor
    By BoanHed in forum MS Office Support
    Replies: 1
    Last Post: 04-02-2013, 11:47 AM
  2. The license file(s) provided is not valid for Fortran Compiler
    By Strangers in forum Software Development
    Replies: 6
    Last Post: 27-09-2010, 07:39 AM
  3. Replies: 5
    Last Post: 09-01-2010, 08:00 PM
  4. Error: problem opening file for reading
    By Digamber in forum Operating Systems
    Replies: 3
    Last Post: 26-08-2009, 07:03 PM
  5. Replies: 3
    Last Post: 01-07-2009, 03:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,782,888.30264 seconds with 17 queries