Can a Fortran read statement handle a namelist as input?

  • Thread starter solarblast
  • Start date
In summary, the conversation is discussing the use of read statements in fortran code. The first statement reads data from a namelist, while the second statement reads data using the nml= option. The speaker expects the second statement to be used, but both are standard fortran. The order of options in the I/O control list can be changed as desired.
  • #1
solarblast
152
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
  • #2
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.
 

Related to Can a Fortran read statement handle a namelist as input?

What is the purpose of passing a namelist to a read?

Passing a namelist to a read is a way to provide a list of variables and values to a program in a specific order, allowing the program to easily read and assign the values to the corresponding variables.

What is the format of a namelist?

A namelist is typically written in a structured format, with a name followed by a list of variables and their corresponding values. The format can vary slightly depending on the programming language, but it is usually easy to understand and follow.

How do you pass a namelist to a read in a program?

To pass a namelist to a read, you need to first define the variables in your program that will receive the values from the namelist. Then, you can use the appropriate syntax for your programming language to read the namelist and assign the values to the variables.

Can you pass multiple namelists to a read?

Yes, it is possible to pass multiple namelists to a read in some programming languages. This can be useful if you have different sets of variables and values that you want to pass to your program at different times.

What are some common errors that can occur when passing a namelist to a read?

Some common errors include misspelling variable names, using incorrect syntax for the programming language, or providing the wrong number or type of variables for the namelist. It is important to carefully check the namelist and the read statement to ensure they are properly formatted and match each other.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
4
Views
8K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
5
Views
13K
Back
Top