Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

How to transfer real vaule to character?

brb36641
Beginner
918 Views
Hello, someone give me any suggestions to find way of transfering real value to character.
My demand is to get character value as using file name, when I get random value with rand function.
How should I do?
I am waiting for any suggestion.
0 Kudos
6 Replies
Les_Neilson
Valued Contributor II
918 Views

use internal write

character(len=10) :: FileName

real :: rv

rv = 3.14159

write(FileName,'(F10.5)') rv

Les

0 Kudos
brb36641
Beginner
918 Views
Thank you for message.
Let me explain my needs more detailed.
I want to use real value as string in file name. Therefore it is need to transfer real as like your exsample to character string.
Could you let me know any way to do this?
0 Kudos
Les_Neilson
Valued Contributor II
918 Views
Do you mean you want the number as "part" of a file name?
(example abc3.14159.txt )
If so then youyouwillneed to remove leading spaces from the string used in theinternal write.
You will also need touseconcatenation, and possibly "trim"
Les
0 Kudos
brb36641
Beginner
918 Views
HI, Thank you for suggestions and Ireconsidered my issue.
CHARACTER*5filename
REAL randnum
random(randnum)
10filename = randnum//'.txt'
....
open (1,file=filename)
....
close(1)

but probably line 10th is not available. It is actually my issue. Therefore how to
transfer real value to character value.
Thanks.
0 Kudos
Les_Neilson
Valued Contributor II
918 Views

I have already shown you in my first post.

character(len=10) ::aString ! This is a character variable.

real :: rv

rv = 1.234

write(aString,'(F10.5)') rv ! This is internal write. Converts real to character representation.

Then you use aString to build your file name.

Les

0 Kudos
brb36641
Beginner
918 Views

Hello, Thank you for suggestions. I will try to do coding according to yours.

Thank you again.

0 Kudos
Reply