Description
Two possible changes for consideration:
As IOSTAT returns numbers that are programming-environment specific the OPEN statement should
return IOMSG and print it when the user has asked to have the IOSTAT value returned. The message provided by the compiler is often a lot easier to understand than the implementation-specific numbers.
Perhaps it has settled down, but at one time there was a lot of variation in what happened when a blank filename was used on an OPEN. Some systems opened a file with a default name like 'file.10'. I think that particular error should be trapped by the code, or perhaps open a SCRATCH file (I wrote a similar routine in the past where that is what happened, so I have a bias there)
The M_io.f90 module was something I mostly used for prototyping quick utilities except for READ_LINE and SWALLOW. Used to use NOTOPEN a lot before NEWUNIT= was added to OPEN.
But I find it interesting that several discussions in stdlib are about similar routines; just proving we
all are reinventing the wheel all the time -- hopefully stdlib will ultimately eliminate most of that.t
My routine most equivalent to your open() experiment is fileopen(). I played with it a few too many times so it does cute things like allowing '>', '<', '>>' as substitutes for 'r','w','a' for a shell-like feel
that I mostly did as an experiment that several people liked; but in retrospect it should have been kept clean and simple and as much like other common languages as possible; so I like open() so far; but surprised no one felt unconfortable with calling it open instead of fopen since there is already a Fortran directive called OPEN.
The contents of M_io.f90 (definitely not the most evolved module, but it was good for Q&D work):
950 fileclose (3m_io) - [M_io] A simple close of a sequential file(LICENSE:PD)
951 filedelete (3m_io) - [M_io] A simple close of an open file with STATUS='DELETE'(LICENSE:PD)
952 fileopen (3m_io) - [M_io] A simple open of a sequential file(LICENSE:PD)
953 uniq (3m_io) - [M_io] append a number to the end of filename to make a unique name if name exists(LICENSE:PD)
954 rd (3m_io) - [M_io] ask for string from standard input with user-definable prompt(LICENSE:PD)
955 print_inquire (3m_io) - [M_io] Do INQUIRE on file by name/number and print results(LICENSE:PD)
956 notopen (3m_io) - [M_io] Find a FUN/LUN (Fortran-unit-number) that is not in use(LICENSE:PD)
957 M_io (3m_io) - [M_io] Fortran I/O module (LICENSE:PD)
958 read_all (3m_io) - [M_io] read a line from specified LUN into allocatable string up to line length limit(LICENSE:PD)
959 read_line (3m_io) - [M_io] read a line from specified LUN into allocatable string up to line length limit cleaning up input line(LICENSE:PD)
960 read_table (3m_io) - [M_io] read file containing a table of numeric values(LICENSE:PD)
961 slurp (3m_io) - [M_io] read a file into a character array(LICENSE:PD)
962 swallow (3m_io) - [M_io] read a file into a character array line by line(LICENSE:PD)
963 get_tmp (3m_io) - [M_io] Return the name of the scratch directory(LICENSE:PD)
964 scratch (3m_io) - [M_io] Return the name of a scratch file(LICENSE:PD)
965 splitpath (3m_io) - [M_io] split a Unix pathname into components(LICENSE:PD)
966 dirname (3m_io) - [M_io] strip last component from filename(LICENSE:PD)