tags:

views:

69

answers:

2

Hi,

I have the following Fortran code. Please explain me..

OPEN(UNIT=4,STATUS='SCRATCH',ACCESS='DIRECT',RECL=2048,IOSTAT=IOCHK)

Here IOCHK is not initialized to 0, it is giving some garbage value so that my code is not working..

IF(IOCHK.NE.0)THEN
// failed code

Can i initialize it separately?

+1  A: 

IOCHK is neither declared nor initialized in your code. You should have something like this before the OPEN statement:

INTEGER IOCHK
IOCHK = 0

The above declares an integer variable and assigns a value to it.

kgiannakakis
+1  A: 

kgiannakakis is correct - you should declare IOCHK as an integer.

However, there are a few other things that I should point out:

  1. After the OPEN statement, IOCHK will hold the status of the I/O operation, whatever that may be. You don't need to set a value of IOCHK beforehand, as it will simply be discarded.
  2. You should use IMPLICIT NONE in your code - this will flag undeclared variables like this as compile-time errors, and make hunting down issues like this much easier.
  3. After reading this and your other questions, are you writing this code or just maintaining it? If you're writing it, you probably shouldn't be writing in a style/language version that's older than I am.
Tim Whitcomb