Can a Fortran read statement handle a namelist as input?

  • Context: Fortran 
  • Thread starter Thread starter solarblast
  • Start date Start date
Click For Summary
SUMMARY

The discussion confirms that a Fortran read statement can indeed handle a namelist as input without explicitly using the "nml=" syntax. The example provided shows that the read statement can function correctly with the unit number and namelist in the first two positions. It emphasizes that while the first two items can be "value" types, all subsequent items must follow the "name=value" format, and options can be specified in any order. This flexibility is a feature of standard Fortran.

PREREQUISITES
  • Understanding of Fortran 90 syntax
  • Familiarity with Fortran I/O operations
  • Knowledge of namelist constructs in Fortran
  • Basic debugging skills in Fortran programming
NEXT STEPS
  • Review Fortran 90 I/O documentation for advanced usage
  • Explore the structure and syntax of Fortran namelists
  • Learn about error handling in Fortran using iostat
  • Investigate the implications of using "random order" in Fortran read statements
USEFUL FOR

This discussion is beneficial for Fortran developers, programmers working with scientific computing, and anyone involved in legacy code maintenance or optimization in Fortran environments.

solarblast
Messages
146
Reaction score
2
I'm looking at someone else''s f90 code, and see:

read ( u_in, instrument, iostat=i )

u_in is an integer, and instrument is a namelist.

Apparently, the read does handle the namelist OK, but I would have expected:
read ( u_in, nml=instrument, iostat=i)

The partial namelist is above as:
! Instrument data
namelist / Instrument / &
Bn, & ! Closures per revolution
Fl, & ! Focal length, mm
...

Comments?
 
Technology news on Phys.org
Both are standard fortran. If the first two items in the I/O control list are just "value" not "name=value", the first item is the unit number and the second is the format or namelist.

All the other items must use the "name=value" format. Unit = and fmt= or nml= are required if those items are not first and second in the list. You can put the options in "random order" like
read(end=100, iostat=i, unit=u, err=200, nml=n)
if you want.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 5 ·
Replies
5
Views
14K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 13 ·
Replies
13
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K