Reading Files in Co-array Fortran
Our first example demonstrates how to read files in Co-array Fortran. Reading files is a basic task needed for many programs. Let’s look at several ways to read files.
This program demonstrates various file reading operations in Co-array Fortran:
We start by reading the entire contents of a file using a subroutine
read_entire_file
.Then we open the file and perform several read operations:
- Read the first 5 bytes.
- Seek to a specific position (7th byte) and read from there.
- Use
inquire
to get the current position and read from a relative position.
We also demonstrate using internal read for parsing string data.
Finally, we close the file.
To run the program, compile it and execute:
This example showcases basic file operations in Co-array Fortran. While Co-array Fortran doesn’t have exact equivalents for all Go features (like bufio
), it provides robust file I/O capabilities through standard Fortran procedures.