Today, I was introduced to I/O in Fortran. Its a little complex for seemingly simple task. But, its good to have all the bells and whistles known upfront. Here is a sample program on input output.
|
|
In Fortran IO, there are few points to note.
- Each file is represented by a unit number. While opening a file, it can either be specified manually (
open(unit=unit_number)
) or assigned at the time of opening withnewunit
keyword. - Access can be
sequential
direct
orstream
. - action can be
read
,write
orreadwrite
. - status -
old
,new
,replace
orscratch
. - form -
formatted
orunformatted
. - posiition (for writing) -
rewind
orappend
. - iostat - the integer which will contain the exit status of command. If the variable is not equal to zero, the error handling has to be performed.
- iomsg - a string which will carry the error message needs to be passed.
Reading the input follows a similar suite, though for reading from user console, the parameter is unit=input_unit
which is available in iso_fortran_env
.
I still haven’t understood how the format is specified but have left it for future. I have started with the exercises but will post more on that on the upcoming day! Here is a logistic map from the first exercise!