Output format & combining string/numbers

Output format & combining string/numbers

HI,
I've treid to look through all the help and newsgrups but I was not able to find the solution to my probelm.

Regarding numeric output to file, if I have a real variable and I want it to write to file. I used F8.5 as the format and by default it is right justified. What if I want left justified?
if _ = space
default _0.00500 want 0.00500_

also, if I want the following output:
There is 1 item(s)
There is 2 item(s)
There is 3 item(s)
........

The way I've implemented is
write(*,*) "there is ", variable, " item(s)"

can I combine the 2 strings & the variable to 1 String
so that i can just write(*,*) combinedString?

is there an equal cmd to variable.toString in Fortran?
how do you take a numeric variable and turn it into string? Also, how do you concatenate strings together?

Thanks!

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

For left justifying use the ADJUSTL intrinsic. For the output you specified normally you would just use the format (a,i0,a) or you could concatenate three strings including one of the converted integer. Here is an example that should cover your questions:

program test
implicit none
real(4) x
integer i
character(16) string

x = .005
write(string,'(f8.5)') x
type *, string ! right justified
string = ADJUSTL (string)
type *, string ! left justified

do i = 1, 3
write(string,'(i0)') i
! output concatenated string
type *, 'There is '//TRIM(string)//' one item(s)'
end do

end program test

James

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen