Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing data from shell script to fortran

Status
Not open for further replies.

SuOraiste

Programmer
Sep 23, 2011
5
Hello

i'm trying as a test, to parse some data from a shell script into a fortran script.
I want to do this with a namelist. Here is what I've got so far

SHELL SCRIPT:
#!/bin/bash

cat > CTLFILE <<EOF
&CTLLIST
name="myname",
age="myage" /
EOF

gfortran -ffixed-line-length-none -Wall -o namelist.x namelist.f
./namelist.x < CTLFILE

exit

FORTRAN:
PROGRAM namelist

IMPLICIT NONE

CHARACTER (LEN=6) :: name
CHARACTER (LEN=5) :: age

NAMELIST /CTLLIST/ name, age

PRINT*,name," ",age

END PROGRAM namelist


This procedure should work but the program just simply outputs an empty string, just a space.

any sugestions in what i'm doing wrong.

thanks
SuOraiste
 
You forgot to load the name list in reading firstly the file CTLFILE :

Code:
      ...
      read(*,nml='CTLLIST')
      PRINT*,name,"  ",age
      ...

François Jacq
 
Ok it worked, thanks! BUT only with this syntax

READ(*,CTLLIST)
PRINT*,name," ",age


without the "nml=".
Does your suggestion work for you??
 
Yes it works with nml=... with a recent Fortran compiler (F90 or later). But the keyword nml is effectively optional, probably to maintain a compatibility with older F77 compilers.

François Jacq
 
Ok, now I got it!
It must be NML=CTLIST, without ' or "".

I was wondering because I'm the gfortran version I'm using is the version which comes with the latest ubuntu release, which is pretty recent.

Well, that help me alot anyway. thanks!

SuOraiste
 
Yes you are right the apostrophes have to be deleted... Sorry for the typo.

François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top