Software Archive
Read-only legacy content
17060 Discussions

converting integer data type into string in fortran 77

Intel_C_Intel
Employee
2,921 Views
Good evening Mister/Miss,

I have a program written in Fortran 77 and I am using the compaq visual fortran compiler ver 6.5 in order to run it.

Suppose know that I have generated on my hard disk 1000 input files and that those files are named tango1, tango2,..., tango1000. In order to run my program 1000 times, I need to write a do loops instruction like the following one:

DO 3333 I = 1, 1000
OPEN (UNIT=NI,FILE=FILNAM,STATUS='OLD',ERR=996)
........................
3333 CONTINUE

Where filename is tango1, tango2, ..., tango1000. In order to do this, I have two choices. The first one concatenate the string tango with each integer I. The second choice is to convert an integer into a string then concatenate the two strings together to make the poper filename and open thoses files one by one.

COULD YOU PLEASE GIVE ME AN EXAMPLE HOW TO ACHIVE THAT. DON'T REFER ME TO ONE OF YOUR MANUAL
BECAUSE I AM NOT AN EXPERIENCED PROGRAMMER.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
2,921 Views
character*4 seqstring
integer*4 seqnum
do seqnum=1,1000
  write (seqstring,'(I0)') seqnum
  open (unit=ni,file='TANGO'//trim(seqstring),status='old',err=996)
  !...
  close (unit=ni)
  end do
end


This uses two interesting Fortran features - one is the Internal WRITE statement, which is how you convert numeric to string, and the zero-width I format, which is new to Fortran 95 (CVF 6.5 supports that.) I0 means "use the minimum field width appropriate"

Steve
0 Kudos
Reply