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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with format?

Status
Not open for further replies.

TheKKK

Technical User
Mar 21, 2009
10
GR
Im trying to write a file as follows:

Code:
  ! create file IN.DAT
  OPEN(UNIT=99,FILE='IN.DAT',STATUS='REPLACE')
  WRITE(UNIT=99,'(/,4(/,A),/,2(I,/),f10.3,2f10.3,2(/,A))')&
          'U','N','N','Y',&
          3,1,uw,&
          0.0,0.0,&
          'N','N'
  CLOSE(UNIT=99)

however the 1 after the 3 appears in the file as a strange number 937186357

what could be the problem??
 
I need to modify 2(I,/) to 2(I1,/), because gfortran delivers the Error: Nonnegative width required in format string at (1).

So my modified source is
fmt.f90
Code:
  [COLOR=#0000ff]! create file IN.DAT[/color]
  [COLOR=#804040][b]OPEN[/b][/color]([COLOR=#ff00ff]99[/color],[COLOR=#804040][b]FILE[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'IN.DAT'[/color])
  [COLOR=#804040][b]WRITE[/b][/color]([COLOR=#ff00ff]99[/color],[COLOR=#ff00ff]'(/,4(/,A),/,2(I1,/),f10.3,2f10.3,2(/,A))'[/color])[highlight #ffff00][COLOR=#0000ff]&[/color][/highlight]
          [COLOR=#ff00ff]'U'[/color],[COLOR=#ff00ff]'N'[/color],[COLOR=#ff00ff]'N'[/color],[COLOR=#ff00ff]'Y'[/color],[highlight #ffff00][COLOR=#0000ff]&[/color][/highlight]
          [COLOR=#ff00ff]3[/color],[COLOR=#ff00ff]1[/color],uw,[highlight #ffff00][COLOR=#0000ff]&[/color][/highlight]
          [COLOR=#ff00ff]0.0[/color],[COLOR=#ff00ff]0.0[/color],[highlight #ffff00][COLOR=#0000ff]&[/color][/highlight]
          [COLOR=#ff00ff]'N'[/color],[COLOR=#ff00ff]'N'[/color]
  [COLOR=#804040][b]CLOSE[/b][/color]([COLOR=#ff00ff]99[/color])
  [COLOR=#a020f0]END[/color]

After compiling and running the program
Code:
$ gfortran fmt.f90 -o fmt
$ fmt

the created file IN.DAT is
Code:
U
N
N
Y
3
1
     0.000     0.000     0.000
N
N
 
I tried this but the file i created was:

U
N
N
Y
3
*
0.000 0.000 0.000
N
N

and i also tried using 2(I1,/) and 2(I2,/) and 2(I5,/)

if that integer is anything but 1 it works.
?

 
I compiled it with g77, gfortran and g95 and the output is as I showed above.

I don't understand why you should have a problem with integer 1? Probably compiler bug? What fortran compiler are you using?

The other thing is that you use in your WRITE after the 1 an uninitialized variable uw. Have you a reason therefore?
 
It is possible that the compiler you're using wants at least 2 characters: one for the sign and one for the number.

As mikrom said, which compiler (on which platform) are you using?
 
I use lahey ED Developer on windows vista

the uw is a real number variable defined before that part of the code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top