|
|
help with convert real value to character
Hi...
I've a real value,
real :: damp
the value can be anything in the range "0.0001, 0.001, 0.01, ..........
1000.00"
What I want is to include this real value also into the output file
name.
like,..
outfile=out_path // damp // '_outfile_name.txt'
The real value of the 'damp' variable has to be converted to a
character to insert into the output file name.
I know in Matlab as, "damp_char=num2str(damp)"
Is there a way to do the same in fortran 95...?
Thank u.
|
|
0
|
|
|
|
Reply
|
ezeepraveen4u (27)
|
10/15/2010 7:23:30 AM |
|
Hi,
Fortran_follower wrote:
> Hi...
>
> I've a real value,
> real :: damp
> the value can be anything in the range "0.0001, 0.001, 0.01, ..........
> 1000.00"
>
> What I want is to include this real value also into the output file
> name.
> like,..
>
> outfile=out_path // damp // '_outfile_name.txt'
>
> The real value of the 'damp' variable has to be converted to a
> character to insert into the output file name.
>
> I know in Matlab as, "damp_char=num2str(damp)"
> Is there a way to do the same in fortran 95...?
>
We really need a FAQ ...
Find a book and look up internal files. An example:
Wot now ? cat if.f90
Program internal
Implicit None
Real :: a
Character( Len = 10 ) :: ca
Read( *, * ) a
Write( ca, '( f0.4 )' ) a
Write( *, * ) 'Character rep is ', Trim( ca )
End Program internal
Wot now ? nagfor -C=all if.f90
NAG Fortran Compiler Release 5.2(721)
[NAG Fortran Compiler normal termination]
Wot now ? ./a.out
2376.234432
Character rep is 2376.2344
Wot now ?
Ian
|
|
0
|
|
|
|
Reply
|
Ian
|
10/15/2010 7:35:26 AM
|
|
Fortran_follower <ezeepraveen4u@gmail.com> wrote:
> Hi...
>
> I've a real value,
> real :: damp
> the value can be anything in the range "0.0001, 0.001, 0.01, ..........
> 1000.00"
>
> What I want is to include this real value also into the output file
> name.
> like,..
>
> outfile=out_path // damp // '_outfile_name.txt'
>
> The real value of the 'damp' variable has to be converted to a
> character to insert into the output file name.
>
> I know in Matlab as, "damp_char=num2str(damp)"
> Is there a way to do the same in fortran 95...?
You can use
write(damp_char,'(f10.4)') damp
as in
program test
real :: damp
character(72) :: damp_char,line
damp = 0.001
write(damp_char,'(f10.4)') damp
line = trim(adjustl(damp_char))//'_outfile_name.txt'
write(6,*) line
end program
|
|
0
|
|
|
|
Reply
|
Aris
|
10/15/2010 9:05:02 AM
|
|
|
2 Replies
4030 Views
(page loaded in 0.016 seconds)
|
|
|
|
|
|
|
|
|