New Reply

converting integer data to string in fortran 90

 
Share Thread Thread Tools
Mar13-12, 12:22 AM   #1
 

converting integer data to string in fortran 90


hi all,

i have the following code:

Code:
do n = ninit,nlast  
character(len=20) :: filename
integer :: n
do n = 1,600
  write (filename, "I0") n
  open (unit=110,file='wave'//trim(filename)//'.dat',action = 'write',status = 'old')
  do i = iinit+1,ilast-1
   !boundary condition
     u(iinit,n+1) = 0
     u(ilast,n+1) = 0
     !end of boundary condition
     u(i,n+1) = 2*(1-(alpha**2))*u(i,n)-u(i,n-1) + (alpha**2)*(u(i+1,n)+u(i-1,n))

   Print*,'i,n,u(i,n+1)=',i,' ', n,' ', u(i,n+1)  
   Write (110,*)'i,n,u(i,n+1)=',i,' ', n,' ', u(i,n+1) 
   close  (unit = 110)
   end do !i
end do !n
what actually i want is to produce automatically a file at a time in the loop with the name ending in a counter, for example: wave1.dat, wave2.dat,wave3.dat,.......,wave599.dat,wave600.dat...but, my programming didn't run properly. Can anyone advice what is wrong with my code.

thanks
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Ants and carnivorous plants conspire for mutualistic feeding
>> Forecast for Titan: Wild weather could be ahead
>> Researchers stitch defects into the world's thinnest semiconductor
Mar13-12, 11:28 AM   #2

Math 2012
 
Recognitions:
Science Advisor Science Advisor
If you say status='old', the file you want to open must already exist. Therefore your program problably won't work the first time your run it. (But it would work the second time, except that it didn't work the first time ... catch 22!)

You don't really need action='write' either, but it won't do any harm.
Mar13-12, 07:57 PM   #3
 
I personally would pad the numbers with zeroes on the left so that when you do a directory listing they actually show up in order :-)

Code:
program zzz
character(len=20) :: filename
integer :: n
do n = 1,100
  write (filename, "('wave',I3.3,'.dat')") n
  open (unit=110,file=filename,status = 'new')
  do i = iinit+1,ilast-1
   write (110,*)' whatever ' 
   close  (unit = 110)
   end do !i
  end do !n
end program zzz
this works.
Mar13-12, 09:49 PM   #4
 

converting integer data to string in fortran 90


thank you gsal....it's work...
New Reply
Thread Tools


Similar Threads for: converting integer data to string in fortran 90
Thread Forum Replies
Converting integer into array of single digits in C#? Programming & Comp Sci 4
Converting VBA to Fortran Programming & Comp Sci 2
Converting string to integer using atoi in C++ Programming & Comp Sci 6
Converting equations to Fortran code Programming & Comp Sci 1
C code, converting float into integer Programming & Comp Sci 16