25 June 2010

How to parse Fortran command line arguments using NAMELIST

While searching around for a pure Fortran 90+ way to parse command line arguments and/or input files, I stumbled across Exploring NAMELIST by John S. Urban. John's article shows a way to use Fortran's NAMELIST feature to quickly parse arbitrary command line arguments while providing sane default behavior.

Like usual, I decided to overdevelop a simple idea. The complete sample is up on github. Assuming you've got an interface declaration in scope for get_command_arguments, here's what you'd see as an end consumer:

PROGRAM namelist_cli

  IMPLICIT NONE

  CHARACTER(LEN=255) :: string, message
  INTEGER :: status

  ! Declare and initialize a NAMELIST for values of interest
  INTEGER  :: i=1,   j=2
  REAL     :: s=3.3, t=4.4
  NAMELIST /cmd/ i, j, s, t

  ! Get command line arguments as a string ready for NAMELIST
  CALL get_command_arguments(string, "&cmd", "/")
  READ (string, NML=cmd, IOSTAT=status, IOMSG=message)
  IF (status /= 0) THEN
    WRITE (*,*) 'Error:   ', status
    WRITE (*,*) 'Message: ', message
    CALL EXIT (status)
  END IF

  ! Echo the results
  WRITE (*, NML=cmd)

END PROGRAM namelist_cli

With a little mucking around, the same NAMELIST could be used to read an input file from disk, allow the user to override individual options on the command line (say, for parametric studies), and also to dump the full setup into an output file for tracking purposes.

31 May 2010

Summer internship

Following a 2,500 mile motorcycle trip from Austin to the Bay Area with my friend Paul, I'll be starting a summer internship at Lawrence Livermore National Labs tomorrow morning.

Instead of my usual my thesis work, I'll be looking at RANS turbulence models/numerics for Rayleigh-Taylor problems. As preparation, over the past couple of months, I've been spending some time staring at conservation law numerics classics like LeVeque's book as well as lecture notes from Caltech's AE 232 course. On the odd chance it is useful to anyone, I've put my toy code up at http://github.com/RhysU/codefour.

The Fortran 90 code solves inviscid or viscid 1D scalar conservation laws of the form u_t + f(u)_x = 0 or u_t + f(u)_x = \nu u_{xx} using WENO reconstruction and a Lax-Friedrichs flux.

It is based heavily on one provided through Caltech's AE 232 course. Compared to the course's code, the following changes have been made:

  1. Adding 3rd-order WENO reconstruction
  2. Adding 2nd and 4th order viscous capabilities
  3. Adding HDF5-based result output
  4. Adding Doxygen-based documentation
  5. Adding Mathematica-based error analysis against Hopf-Cole-based analytic solutions of the viscid Burger's equation

06 May 2010

Made GSL Committer

24 April 2010

New Toy

Courtesy of the employer, my new Lenovo W510 came in on Thursday.

make -j8 on a laptop is fun: