-1

I already found the answer to want I wanted to ask here: Looping over variable file names

But the problem is when I run the program it gave me a strange symbol like a smile.

This is the screen: enter image description here

The code is something like this:

  DIMENSION NWGRAIN(NWMAXGRAIN)
  CHARACTER*2  FLABEL

  NWMAXGRAIN=5

$c     GRAINS TO WRITE THE OUTPUT (NW STANDS FOR NUMBER WRITING)
   DO I=1,NWMAXGRAIN
        NWGRAIN(I)=0
   END DO
   NWGRAIN(1)=1
   NWGRAIN(2)=6
   NWGRAIN(3)=100
   NWGRAIN(4)=1000
   NWGRAIN(5)=1500


   DO I=1,NWMAXGRAIN
        IUNIT=901+I
        flabel=char(nwgrain(i))
        OPEN(IUNIT,FILE='DDRX_GRAIN'//FLABEL//'.OUT',
  #      STATUS='UNKNOWN')
   END DO

I want to have several files where I have to write data named 'DDRX_GRAIN1.OUT' , 'DDRX_GRAIN6.OUT' , 'DDRX_GRAIN100.OUT' and so on.

But as you can see it gave me an error where the number is replaced by a smile...

Don't know if it's a joke of my compiler :)

EDIT: I am sorry but I don't understand. As reported in the other topic, I modify my code:

       CHARACTER*2  FLABEL,x1
       character(len=8) fmt ! format descriptor (italo)

       fmt = '(I5.5)' ! an integer of width 5 with zeros at the left
       DO I=1,NWMAXGRAIN
              IUNIT=901+I
              i1=nwgrain(i)
               write (x1,fmt) i1 ! converting integer to string using a 'internal file'
              OPEN(IUNIT,FILE='DDRX_GRAIN'//trim(x1)//'.OUT',
 #      STATUS='UNKNOWN')
        END DO

The new error is:

forrtl: severe (66): output statement overflows record, unit -5, file Internal Formatted Write

Community
  • 1
  • 1

1 Answers1

0

Well, you claim you found your answer at your link, but you did not read it very well.

You should not use

 flabel=char(nwgrain(i))

that just sets flabel to some machine specific character that has number nwgrain(i) in some character table and that character happens to be the smile.

You must use, as the link suggest, the internal write statement. Refer to the link and other duplicated links for the exact solution Convert integers to strings to create output filenames at run time

You will also probably want 'DDRX_GRAIN'//TRIM(FLABEL)//'.OUT'.

Community
  • 1
  • 1