Step 1: Understanding the Concept:
In programming languages like Fortran, file handling operations require opening a file on the storage disk and linking it to a specific logical unit number inside the program.
This unit number is used in subsequent read and write statements to refer to that file.
Step 2: Detailed Explanation:
In Fortran (such as Fortran 77, 90, or newer standards), the ‘OPEN‘ statement is used to establish this connection.
The general syntax of the ‘OPEN‘ statement is:
‘OPEN(UNIT=number, FILE='filename', STATUS='status', ...)‘
Let us evaluate each of the given options:
- Option A: ‘open(10,test.data)‘ is invalid because the file name ‘test.data‘ is not enclosed in single or double quotes, which would cause the compiler to treat it as an undefined variable.
- Option B: ‘open(10,'test.data')‘ is invalid because Fortran requires the keyword ‘FILE=‘ to specify the file name when positional arguments are not used in a strictly defined order.
- Option C: ‘open(10, file= test.data )‘ is invalid because, despite using the ‘file=‘ specifier, the string ‘test.data‘ lacks quotes.
- Option D: ‘open(10,file='test.data')‘ is correct.
It specifies the unit number ‘10‘, uses the required ‘file=‘ parameter, and encloses the literal file name ‘'test.data'‘ in quotes.
Step 3: Final Answer:
The valid statement to open the file is ‘open(10,file='test.data')‘.