Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2006, 05:04 PM
gaanee gaanee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 163 gaanee User rank is Sergeant (500 - 2000 Reputation Level)gaanee User rank is Sergeant (500 - 2000 Reputation Level)gaanee User rank is Sergeant (500 - 2000 Reputation Level)gaanee User rank is Sergeant (500 - 2000 Reputation Level)gaanee User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 12 h 37 m 29 sec
Reputation Power: 25
Concatenate integer with a character data type

Is there any way in Fortran77 to concatenate an integer with a character data type?
Basically, I'm trying to create filenames in a loop like:
file01.out
file02.out
file03.out
....
.......
for this I need to concatenate 'file' which is a character with 01 which is an integer, and I cannot simply do file//01, since the data types are different.
Is there a way to get around this issue in Fortran77.
is there any function similar to sprintf in F77.

Reply With Quote
  #2  
Old October 20th, 2006, 07:23 AM
mawe mawe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 394 mawe User rank is Sergeant Major (2000 - 5000 Reputation Level)mawe User rank is Sergeant Major (2000 - 5000 Reputation Level)mawe User rank is Sergeant Major (2000 - 5000 Reputation Level)mawe User rank is Sergeant Major (2000 - 5000 Reputation Level)mawe User rank is Sergeant Major (2000 - 5000 Reputation Level)mawe User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 10 h 6 m 47 sec
Reputation Power: 50
Hi!

fortran Code:
Original - fortran Code
    program concat implicit none integer intvar, i character string*2 intvar = 10 do i=1, 10   write(unit=string, fmt='(I2)') intvar   write(*,*) "file" // string // ".out"   intvar = intvar + 1 end do end program concat

I leave the numbers 01 - 09 as an exercise to you (to be honest I have no idea how to do that )

Regards, mawe

Reply With Quote
  #3  
Old January 23rd, 2007, 12:54 PM
rahu rahu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 1 rahu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 37 sec
Reputation Power: 0
Re:Concatenate integer with a character data type

Hi,

I hope it might work.

PROGRAM concatinating_int_char

IMPLICIT NONE
CHARACTER(LEN = 20 ) :: file_name
CHARACTER(LEN = 20 ) :: file_char
INTEGER :: i

file_char = '010203040506070809'
DO i = 1,18,2
file_name = 'output'// file_char(i:i+1)//'.dat'
WRITE(*,*) file_name
END DO

END PROGRAM concatinating_int_char

Enjoy,
Rahu.

Reply With Quote
  #4  
Old March 1st, 2012, 12:31 PM
kdmais kdmais is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 1 kdmais User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 12 sec
Reputation Power: 0
Send a message via MSN to kdmais
Read Files with diferente end names

Next, the solution for you

First yo need create three files: data1.txt, data2.txt, data3.txt.
Each file have one integer number, i.e: 1 ,2, 3. The content of each file is saved in V1(. Enjoy it


subroutine readata
implicit none

integer :: i,n,j
CHARACTER (LEN=4) :: fname1,fname3
CHARACTER (LEN=9) :: fullname
CHARACTER (LEN=1) :: num
integer, allocatable::V1(
fname1='data' !nome principal do arquivo
fname3='.txt' !tipo de arquivo que vai ser lido

n=3 !numero de arquivos para ler
allocate (V1(n)) !variavel onde vai ser guardado os dados do arquivo lido
V1=0
do j=1,n
write(num,'(i1)') j !numeracao do arquivo
fullname=fname1//num//fname3 !gera nome completo do arquivo
open(unit=1,file=fullname,STATUS="OLD", ACTION="READ")
read(unit=1,fmt=300) V1(j)
close(unit=1)
enddo

300 format((i2))
end subroutine readata

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Concatenate integer with a character data type

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap