filename using ASCII cherecter set

This is a discussion on filename using ASCII cherecter set within the Fortran forums in Programming Languages category; in my code , i need to read few files named POT_A,POT_B and so on. i was thinking about change the variable part as fi=ACHAR(i+16+48) to get the variable A,B etc. but how can i have the name POT_A etc? can any1 help me on that?...

Go Back   Application Development Forum > Programming Languages > Fortran

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-20-2008, 07:31 AM
rudra
Guest
 
Default filename using ASCII cherecter set

in my code , i need to read few files named POT_A,POT_B and so on.
i was thinking about change the variable part as

fi=ACHAR(i+16+48)

to get the variable A,B etc. but how can i have the name POT_A etc?
can any1 help me on that?
Reply With Quote
  #2  
Old 08-20-2008, 07:44 AM
Arjen Markus
Guest
 
Default Re: filename using ASCII cherecter set

On 20 aug, 13:31, rudra <bnrj.ru...@gmail.com> wrote:
> in my code , i need to read few files named POT_A,POT_B and so on.
> i was thinking about change the variable part as
>
> fi=ACHAR(i+16+48)
>
> to get the variable A,B etc. but how can i have the name POT_A etc?
> can any1 help me on that?


IACHAR('A') gives you the integer value for 'A'.

So:

do i = 1,26
chr = achar(iachar('A')+i-1) ! Successive letters
filename = 'pot_' // chr
enddo

would loop through the alphabet.

Or, perhaps easier:

character(len=26) :: alphabet = 'ABC...'

do i = 1,26
filename = 'pot_' // alphabet(i:i)
enddo

Regards,

Arjen
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:34 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.